選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

settingsPortForwarding.html 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <!--
  2. Port Forwarding Settings
  3. Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  4. $Id: settingsPortForwarding.html 595 2015-04-17 09:50:36Z imoore76 $
  5. -->
  6. <div id='vboxSettingsPortForwarding' style='height: 100%'>
  7. <table class='vboxInvisible'>
  8. <tr style='vertical-align: top'>
  9. <td style='width: 100%; height: 100%'>
  10. <div id='vboxSettingsPortForwardingListDiv' class='vboxBordered' style='overflow: auto;'>
  11. <table class='vboxHorizontal'>
  12. <thead>
  13. <tr>
  14. <th class='translate'>Name</th>
  15. <th class='translate'>Protocol</th>
  16. <th class='translate'>Host IP</th>
  17. <th class='translate'>Host Port</th>
  18. <th class='translate'>Guest IP</th>
  19. <th class='translate'>Guest Port</th>
  20. </tr>
  21. </thead>
  22. <tbody id='vboxSettingsPortForwardingList' class='vboxHover'></tbody>
  23. </table>
  24. </div>
  25. </td><td id='vboxSettingsPortForwardingToolbar'></td>
  26. </tr>
  27. </table>
  28. <script type='text/javascript'>
  29. /*
  30. * Translate
  31. */
  32. $('#vboxSettingsPortForwarding').find('.translate').html(function(i,h){return trans(h,'UIPortForwardingModel');}).removeClass('translate');
  33. /*
  34. * Init port forwarding buttons and toolbar
  35. */
  36. var sButtons = new Array(
  37. {
  38. 'name' : 'insportfwd',
  39. 'label' : 'Insert new rule',
  40. 'icon' : 'controller_add',
  41. 'click' : function () {
  42. var rname = null;
  43. var rules = $('#vboxSettingsPortForwardingList').children('tr');
  44. for(var n = 1; n < 100; n++) {
  45. rname = trans('Rule %1').replace('%1',n);
  46. for(var i = 0; i < rules.length; i++) {
  47. if($(rules[i]).data('vboxRule')[0] == rname) {
  48. rname = null;
  49. break;
  50. }
  51. }
  52. if(rname) break;
  53. }
  54. vboxSettingsPortForwardingAdd(rname+',1,,,,');
  55. }
  56. },
  57. {
  58. 'name' : 'delportfwd',
  59. 'label' : 'Delete selected rule',
  60. 'icon' : 'controller_remove',
  61. 'click' : function () {
  62. $('#vboxSettingsPortForwardingList').children('tr.vboxListItemSelected').first().remove();
  63. $('#vboxSettingsPortForwardingList').trigger('select');
  64. },
  65. 'enabled' : function(item) {return ((item && $(item).data('vboxRule')) ? true : false);}
  66. }
  67. );
  68. var pfToolbar = new vboxToolbarSmall({buttons: sButtons, language_context: 'UIMachineSettingsPortForwardingDlg'});
  69. pfToolbar.renderTo('vboxSettingsPortForwardingToolbar');
  70. $('#vboxSettingsPortForwardingList').on('select',function(e,el){pfToolbar.update(el);});
  71. $('#vboxSettingsPortForwardingList').trigger('select');
  72. /* Edit rule element */
  73. function vboxSettingsPortForwardingEdit(td,type) {
  74. if($(td).children('input').length) return;
  75. var ex = $(td).parent().data('vboxRule')[$(td).data('vboxPane')];
  76. var w = $(td).width();
  77. $(td).html('');
  78. $('<input />').data('vboxPane',$(td).data('vboxPane')).attr({'class':'vboxText'}).val(ex).blur(function(){
  79. switch($(this).data('vboxPane')) {
  80. /* name */
  81. case 0:
  82. $(this).val(jQuery.trim($(this).val().replace(',','')));
  83. if(!$(this).val())
  84. $(this).val($(this).parent().parent().data('vboxRule')[0]);
  85. break;
  86. /* IPs */
  87. case 2:
  88. case 4:
  89. $(this).val($(this).val().replace(/[^0-9\.]/,''));
  90. break;
  91. /* ports */
  92. case 3:
  93. case 5:
  94. $(this).val($(this).val().replace(/[^0-9]/,''));
  95. if(!$(this).val() || $(this).val() < 0) $(this).val('0');
  96. else if($(this).val() > 65535) $(this).val('65535');
  97. break;
  98. }
  99. $(this).parent().parent().data('vboxRule')[$(this).data('vboxPane')] = $(this).val();
  100. var ex = $(this).val();
  101. $(this).replaceWith($('<div />').html(ex).text());
  102. }).css({'width':(w-8)+'px','padding':'0px','margin':'0px'}).keydown(function(event){
  103. if(event.keyCode == 13) {
  104. $(this).trigger('blur');
  105. return;
  106. }
  107. switch($(this).data('vboxPane')) {
  108. /* name */
  109. case 0:
  110. if(event.keyCode == 188) return false; // no commas
  111. break;
  112. /* IPs */
  113. case 2:
  114. case 4:
  115. return true;
  116. break;
  117. /* ports */
  118. case 3:
  119. case 5:
  120. return (vboxValidateCtrl(event.keyCode) || vboxValidateNum(event.keyCode));
  121. break;
  122. }
  123. }).appendTo(td).focus();
  124. }
  125. /* Edit protocol */
  126. function vboxSettingsPortForwardingEditProto(td) {
  127. var ex = $(td).parent().data('vboxRule')[1];
  128. if(ex == 0) val = 1;
  129. else val = 0;
  130. $(td).parent().data('vboxRule')[1] = val;
  131. $(td).html(val == '1' ? trans('TCP','VBoxGlobal') : trans('UDP','VBoxGlobal'));
  132. }
  133. /* Add forwarding rule */
  134. function vboxSettingsPortForwardingAdd(r) {
  135. var rule = r.split(',');
  136. var tr = $('<tr />').attr({'class':'vboxListItem'});
  137. $('<td />').data('vboxPane',0).html($('<div />').html(rule[0]).text()).click(function(){
  138. if($(this).parent().hasClass('vboxListItemSelected')) {
  139. vboxSettingsPortForwardingEdit(this,'name');
  140. return;
  141. }
  142. $(this).parent().addClass('vboxListItemSelected').removeClass('vboxHover').siblings().removeClass('vboxListItemSelected');
  143. $('#vboxSettingsPortForwardingList').trigger('select',$(this).parent());
  144. }).addClass('vboxHoverFirst').appendTo(tr);
  145. $('<td />').click(function(){
  146. if($(this).parent().hasClass('vboxListItemSelected')) {
  147. vboxSettingsPortForwardingEditProto(this);
  148. return;
  149. }
  150. $(this).parent().addClass('vboxListItemSelected').removeClass('vboxHover').siblings().removeClass('vboxListItemSelected');
  151. $('#vboxSettingsPortForwardingList').trigger('select',$(this).parent());
  152. }).addClass('vboxProto vboxHoverMid').html(trans(rule[1] == 1 ? 'TCP' : 'UDP','VBoxGlobal')).appendTo(tr);
  153. for(var i = 2; i < rule.length; i++) {
  154. $('<td />').data('vboxPane',i).click(function(){
  155. if($(this).parent().hasClass('vboxListItemSelected')) {
  156. vboxSettingsPortForwardingEdit(this,'port');
  157. return;
  158. }
  159. $(this).parent().addClass('vboxListItemSelected').removeClass('vboxHover').siblings().removeClass('vboxListItemSelected');
  160. $('#vboxSettingsPortForwardingList').trigger('select',$(this).parent());
  161. }).addClass('vboxHover' + (i == (rule.length-1) ? 'Last' : 'Mid'))
  162. .html($('<div />').html(rule[i]).text()).addClass((i%2 ? 'vboxPort' : 'vboxIP')).appendTo(tr);
  163. }
  164. $(tr).data({'vboxRule':rule}).hover(function(){
  165. if(!$(this).hasClass('vboxListItemSelected'))
  166. $(this).addClass('vboxHover');
  167. },function(){
  168. $(this).removeClass('vboxHover');
  169. }).appendTo($('#vboxSettingsPortForwardingList'));
  170. }
  171. function vboxSettingsPortForwardingInit(rules) {
  172. for(var r = 0; r < rules.length; r++) {
  173. vboxSettingsPortForwardingAdd(rules[r]);
  174. }
  175. }
  176. </script>
  177. </div>