You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settingsGlobalNetworkNATPortForwarding.html 8.9KB

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