Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

settingsGlobalNetwork.html 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <!--
  2. General Network Preferences
  3. Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  4. $Id: settingsGlobalNetwork.html 597 2015-04-20 11:41:28Z imoore76 $
  5. -->
  6. <ul>
  7. <li><a href="#vboxGlobalNATNetworks"><span class='translate'>NAT Networks</span></a>
  8. <li><a href="#vboxGlobalHostNetworking"><span class='translate'>Host-only Networks</span></a>
  9. </ul>
  10. <div id='vboxGlobalNATNetworks'>
  11. <table style='width: 100%; margin-left:auto; margin-right:auto;' class='vboxInvisible'>
  12. <tr style='vertical-align:top'>
  13. <td>
  14. <div class='vboxBordered' style='height: 280px'>
  15. <table style='width:100%; border-spacing: 0px;' class='vboxList vboxHover'>
  16. <thead>
  17. <tr>
  18. <th style='width: 140px; padding-left: 4px;text-align:left' class='translate'>Active</th>
  19. <th style='text-align:left' class='translate'>Name</th>
  20. </tr>
  21. </thead>
  22. <tbody id='vboxSettingsGlobalNATNetList'>
  23. <tr><td>asdf</td><td>asdf</td></tr>
  24. </tbody>
  25. </table>
  26. </div>
  27. </td>
  28. <td style='width: 1%; padding: 4px;' id='vboxSettingsGlobalNATNetToolbar'></td>
  29. </tr>
  30. </table>
  31. </div>
  32. <div id='vboxGlobalHostNetworking'>
  33. <table style='width: 100%; margin-left:auto; margin-right:auto;' class='vboxInvisible'>
  34. <tr style='vertical-align:top'>
  35. <td >
  36. <ul id='vboxSettingsGlobalNetList' class='vboxBordered vboxList vboxHover' style='width: 100%; margin-top: 0px;'>
  37. <li>interface</li>
  38. </ul>
  39. </td>
  40. <td style='width: 1%; padding: 4px;' id='vboxSettingsGlobalNetToolbar'></td>
  41. </tr>
  42. </table>
  43. </div>
  44. <!-- Edit Host Networking Properties Dialog -->
  45. <div id='vboxSettingsGlobalNetEditDialog' style='display: none'>
  46. <div id='vboxSettingsGlobalNetEdit' class='vboxTabbed'>
  47. <ul>
  48. <li><a href="#vboxSettingsGlobalNetEditAdapter"><span class='translate'>Adapter</span></a></li>
  49. <li><a href="#vboxSettingsGlobalNetEditDHCP"><span class='translate'>DHCP Server</span></a></li>
  50. </ul>
  51. <div id="vboxSettingsGlobalNetEditAdapter" class="vboxDialogContent vboxTabContent">
  52. <table class="vboxSettingsTable">
  53. <tr>
  54. <th><span class='translate'>IPv4 Address:</span></th>
  55. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetIPv4' /></td>
  56. </tr>
  57. <tr>
  58. <th><span class='translate'>IPv4 Network Mask:</span></th>
  59. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetIPv4Mask' /></td>
  60. </tr>
  61. <tr>
  62. <th><span class='translate'>IPv6 Address:</span></th>
  63. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetIPv6' /></td>
  64. </tr>
  65. <tr>
  66. <th><span class='translate'>IPv6 Network Mask Length:</span></th>
  67. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetIPv6Mask' /></td>
  68. </tr>
  69. </table>
  70. </div>
  71. <div id="vboxSettingsGlobalNetEditDHCP" class='vboxDialogContent vboxTabContent'>
  72. <table class="vboxSettingsTable">
  73. <tr>
  74. <td colspan='2'><label><input type='checkbox' class='vboxCheckbox vboxEnablerCheckbox' id='vboxSettingsGlobalNetDHCPEnabled' /> <span class='translate'>Enable Server</span></label></td>
  75. </tr>
  76. <tr>
  77. <th><span class='translate'>Server Address:</span></th>
  78. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetServerAddress' /></td>
  79. </tr>
  80. <tr>
  81. <th><span class='translate'>Server Mask:</span></th>
  82. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetServerMask' /></td>
  83. </tr>
  84. <tr>
  85. <th><span class='translate'>Lower Address Bound:</span></th>
  86. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetLower' /></td>
  87. </tr>
  88. <tr>
  89. <th><span class='translate'>Upper Address Bound:</span></th>
  90. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNetUpper' /></td>
  91. </tr>
  92. </table>
  93. </div>
  94. </div>
  95. </div>
  96. <!-- Edit NAT NET Networking Properties Dialog -->
  97. <div id='vboxSettingsGlobalNATNetworkEditDialog' style='display: none'>
  98. <div class='vboxDialogContent'>
  99. <table class="vboxSettingsTable">
  100. <tr>
  101. <td colspan='2'><label><input type='checkbox' class='vboxCheckbox vboxEnablerCheckbox' id='vboxSettingsGlobalNATNetEnabled' /> <span class='translate'>Enable Network</span></label></td>
  102. </tr>
  103. <tr>
  104. <th><span class='translate'>Network Name:</span></th>
  105. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNATNetName' style='width:200px' /></td>
  106. </tr>
  107. <tr>
  108. <th><span class='translate'>Network CIDR:</span></th>
  109. <td><input type='text' class='vboxText' id='vboxSettingsGlobalNATNetNetwork' style='width:200px' /></td>
  110. </tr>
  111. <tr>
  112. <th><span class='translate'>Network Options:</span></th>
  113. <td><label><input type='checkbox' class='vboxCheckbox' id='vboxSettingsGlobalNATNetDHCP' /> <span class='translate vboxEnablerListen'>Supports DHCP</span></label></td>
  114. </tr>
  115. <tr>
  116. <th></th>
  117. <td><label><input type='checkbox' class='vboxCheckbox vboxEnablerTrigger' id='vboxSettingsGlobalNATNetIPv6' /> <span class='translate vboxEnablerListen'>Supports IPv6</span></label></td>
  118. </tr>
  119. <tr>
  120. <th></th>
  121. <td><label><input type='checkbox' class='vboxCheckbox' id='vboxSettingsGlobalNATNetIPv6Route' /> <span class='translate vboxEnablerListen'>Advertise Default IPv6 Route</span></label></td>
  122. </tr>
  123. <tr>
  124. <th></th>
  125. <td><input type='button' class='vboxButton' id='vboxSettingsGlobalNATNetRules' value='Port Forwarding' /></td>
  126. </tr>
  127. </table>
  128. </div>
  129. </div>
  130. <script type='text/javascript'>
  131. /* Build Host interface Toolbar */
  132. var sButtons = new Array(
  133. {
  134. 'name' : 'addNet',
  135. 'label' : 'Add host-only network',
  136. 'icon' : 'add_host_iface',
  137. 'enabled' : function () { return true; },
  138. 'click' : function () {
  139. var refreshInterfaces = function(){
  140. var l = new vboxLoader();
  141. l.add('hostOnlyInterfacesGet',function(d){$('#vboxSettingsDialog').data('vboxHostOnlyInterfaces',d.responseData);});
  142. l.onLoad = function(){
  143. vboxSettingsGlobalNetworkAddAdpaters();
  144. vboxVMDataMediator.refreshVMData('host');
  145. };
  146. l.run();
  147. };
  148. var l = new vboxLoader();
  149. l.add('hostOnlyInterfaceCreate',function(d){
  150. if(d && d.responseData && d.responseData.progress) {
  151. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){
  152. $('#vboxSettingsGlobalNetList').html('<li><img src="images/spinner.gif" /></li>');
  153. setTimeout(refreshInterfaces,2000);
  154. },null,trans('Add host-only network','UIGlobalSettingsNetwork'),'',true);
  155. }
  156. });
  157. l.run();
  158. }
  159. },
  160. {
  161. 'name' : 'delNet',
  162. 'label' : 'Remove host-only network',
  163. 'icon' : 'remove_host_iface',
  164. 'enabled' : function (item) { return ($(item).data('interface')); },
  165. 'click' : function () {
  166. var item = $('#vboxSettingsGlobalNetList').children('li.vboxListItemSelected').first();
  167. var buttons = {};
  168. buttons[trans('OK','QIMessageBox')] = function() {
  169. var dialog = this;
  170. var item = $('#vboxSettingsGlobalNetList').children('li.vboxListItemSelected').first();
  171. var l = new vboxLoader();
  172. l.add('hostOnlyInterfaceRemove',function(d){
  173. if(d && d.responseData && d.responseData.progress) {
  174. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){
  175. var l2 = new vboxLoader();
  176. l2.add('hostOnlyInterfacesGet',function(d){$('#vboxSettingsDialog').data('vboxHostOnlyInterfaces',d.responseData);});
  177. l2.onLoad = function(){
  178. vboxSettingsGlobalNetworkAddAdpaters();
  179. vboxVMDataMediator.refreshVMData('host');
  180. };
  181. l2.run();
  182. },null,trans('Remove host-only network','UIGlobalSettingsNetwork'),'',true);
  183. }
  184. },{'id':$(item).data('interface').id});
  185. l.onLoad = function(){$(dialog).empty().remove();};
  186. l.run();
  187. };
  188. vboxConfirm(trans("<p>Deleting this host-only network will remove " +
  189. "the host-only interface this network is based on. Do you want to " +
  190. "remove the (host-only network) interface <nobr><b>%1</b>?</nobr></p>" +
  191. "<p><b>Note:</b> this interface may be in use by one or more " +
  192. "virtual network adapters belonging to one of your VMs. " +
  193. "After it is removed, these adapters will no longer be usable until " +
  194. "you correct their settings by either choosing a different interface " +
  195. "name or a different adapter attachment type.</p>",'UIMessageCenter').replace('%1',$(item).data('interface').name),buttons);
  196. }
  197. },
  198. {
  199. 'name' : 'editNet',
  200. 'label' : 'Edit host-only network',
  201. 'icon' : 'guesttools',
  202. 'enabled' : function (item) { return ($(item).data('interface')); },
  203. 'click' : function () {
  204. vboxSettingsGlobalNetEditDialog();
  205. }
  206. },{
  207. name : 'refreshNet',
  208. 'label' : 'Refresh',
  209. 'language_context': 'UIVMLogViewer',
  210. 'icon' : 'refresh',
  211. click: function() {
  212. var l = new vboxLoader();
  213. l.add('hostOnlyInterfacesGet',function(d){$('#vboxSettingsDialog').data('vboxHostOnlyInterfaces',d.responseData);});
  214. l.onLoad = function(){
  215. vboxSettingsGlobalNetworkAddAdpaters();
  216. };
  217. l.run();
  218. }
  219. }
  220. );
  221. var netToolbar = new vboxToolbarSmall({buttons: sButtons, language_context: 'UIGlobalSettingsNetwork'});
  222. netToolbar.renderTo('vboxSettingsGlobalNetToolbar');
  223. $('#vboxSettingsGlobalNetList').on('select',function(e,i){
  224. netToolbar.update(i);
  225. });
  226. /* Build nat network Toolbar */
  227. var sButtons = new Array(
  228. {
  229. 'name' : 'addNet',
  230. 'label' : 'Add NAT network',
  231. 'icon' : 'add_host_iface',
  232. 'click' : function () {
  233. // Elect name...
  234. var netNameTpl = 'NatNetwork';
  235. var number = 1;
  236. var netName = netNameTpl + number++;
  237. while($('#vboxSettingsGlobalNATNetList').find('td:contains("'+netName+'")').length) {
  238. netName = netNameTpl + number++;
  239. }
  240. vboxSettingsGlobalNATNetworksAddNet({'enabled':false,'networkName':netName,'portForwardRules4':[],'portForwardRules6':[]});
  241. }
  242. },
  243. {
  244. 'name' : 'delNet',
  245. 'label' : 'Remove NAT network',
  246. 'icon' : 'remove_host_iface',
  247. 'enabled' : function (item) { return (item); },
  248. 'click' : function () {
  249. var item = $('#vboxSettingsGlobalNATNetList').children('tr.vboxListItemSelected').first();
  250. var buttons = {};
  251. buttons[trans('OK','QIMessageBox')] = function() {
  252. $(item).remove();
  253. $('#vboxSettingsGlobalNATNetList').trigger('select', null);
  254. $(this).empty().remove();
  255. };
  256. vboxConfirm(trans("<p>Deleting this host-only network will remove " +
  257. "the host-only interface this network is based on. Do you want to " +
  258. "remove the (host-only network) interface <nobr><b>%1</b>?</nobr></p>" +
  259. "<p><b>Note:</b> this interface may be in use by one or more " +
  260. "virtual network adapters belonging to one of your VMs. " +
  261. "After it is removed, these adapters will no longer be usable until " +
  262. "you correct their settings by either choosing a different interface " +
  263. "name or a different adapter attachment type.</p>",'UIMessageCenter').replace('%1',$(item).data('NATNetwork').networkName),buttons);
  264. }
  265. },
  266. {
  267. 'name' : 'editNet',
  268. 'label' : 'Edit NAT network',
  269. 'icon' : 'guesttools',
  270. 'enabled' : function (item) { return (item); },
  271. 'click' : function () {
  272. vboxSettingsGlobalNATNetworkEditDialog();
  273. }
  274. },{
  275. name : 'refreshNet',
  276. 'label' : 'Refresh',
  277. 'language_context': 'UIVMLogViewer',
  278. 'icon' : 'refresh',
  279. click: function() {
  280. var l = new vboxLoader();
  281. l.add('vboxNATNetworksGet',function(d){$('#vboxSettingsDialog').data('vboxNATNetworks',d.responseData);});
  282. l.onLoad = function(){
  283. vboxSettingsGlobalNATNetworksAdd();
  284. };
  285. l.run();
  286. }
  287. }
  288. );
  289. var natNetToolbar = new vboxToolbarSmall({buttons: sButtons, language_context: 'UIGlobalSettingsNetwork'});
  290. natNetToolbar.renderTo('vboxSettingsGlobalNATNetToolbar');
  291. $('#vboxSettingsGlobalNATNetList').on('select',function(e,i){
  292. natNetToolbar.update(i);
  293. });
  294. /*
  295. *
  296. * Function to fill network adapters
  297. *
  298. */
  299. function vboxSettingsGlobalNetworkAddAdpater(n) {
  300. // If the adapter exists, don't add it
  301. var exists = false;
  302. $('#vboxSettingsGlobalNetList').children('li').each(function(){
  303. if($(this).data('interface').id == n.id) {
  304. exists = true;
  305. return false;
  306. }
  307. });
  308. if(exists) return;
  309. $('<li />').attr({'class':'vboxListItem'}).html($('<div />').text(n.name).html()).hoverClass('vboxHover').data('interface',n).click(function(){
  310. $(this).parent().children('li.vboxListItemSelected').removeClass('vboxListItemSelected').addClass('vboxListItem');
  311. $(this).addClass('vboxListItemSelected').removeClass('vboxListItem');
  312. $('#vboxSettingsGlobalNetList').trigger('select',this);
  313. }).appendTo($('#vboxSettingsGlobalNetList'));
  314. }
  315. /*
  316. *
  317. * Fill network adapters
  318. *
  319. */
  320. function vboxSettingsGlobalNetworkAddAdpaters() {
  321. $('#vboxSettingsGlobalNetList').children().remove();
  322. var nics = $('#vboxSettingsDialog').data('vboxHostOnlyInterfaces').networkInterfaces;
  323. for(var i = 0; i < nics.length; i++) {
  324. vboxSettingsGlobalNetworkAddAdpater(nics[i]);
  325. }
  326. $('#vboxSettingsGlobalNetList').trigger('select',null);
  327. }
  328. vboxSettingsGlobalNetworkAddAdpaters();
  329. /*
  330. *
  331. * FIll nat networks
  332. */
  333. function vboxSettingsGlobalNATNetworksAdd() {
  334. var nets = $('#vboxSettingsDialog').data('vboxNATNetworks');
  335. $('#vboxSettingsGlobalNATNetList').empty();
  336. for(var i = 0; i < nets.length; i++) {
  337. nets[i].orig_networkName = nets[i].networkName;
  338. vboxSettingsGlobalNATNetworksAddNet(nets[i]);
  339. }
  340. $('#vboxSettingsGlobalNATNetList').trigger('select',null);
  341. }
  342. function vboxSettingsGlobalNATNetworksAddNet(net) {
  343. $('<tr />').data({'NATNetwork':net}).hoverClass('vboxHover').addClass('vboxListItem').append(
  344. $('<td />').append(
  345. $('<input />').attr({'type':'checkbox'}).click(function(){
  346. $(this).closest('tr').data('NATNetwork').enabled = this.checked;
  347. $(this).closest('tr').data('NATNetwork')._modified = true;
  348. }).prop('checked', net.enabled)
  349. ).click(function(){
  350. $(this).parent().parent().children('tr.vboxListItemSelected').removeClass('vboxListItemSelected').addClass('vboxListItem');
  351. $(this).parent().addClass('vboxListItemSelected').removeClass('vboxListItem');
  352. $('#vboxSettingsGlobalNATNetList').trigger('select',this);
  353. })
  354. ).append(
  355. $('<td />').html($('<div />').html(net.networkName).text()).click(function(){
  356. $(this).parent().parent().children('tr.vboxListItemSelected').removeClass('vboxListItemSelected').addClass('vboxListItem');
  357. $(this).parent().addClass('vboxListItemSelected').removeClass('vboxListItem');
  358. $('#vboxSettingsGlobalNATNetList').trigger('select',this);
  359. })
  360. ).appendTo($('#vboxSettingsGlobalNATNetList'));
  361. }
  362. vboxSettingsGlobalNATNetworksAdd();
  363. /*
  364. *
  365. * Edit Network Interface Dialog
  366. *
  367. */
  368. vboxInitDisplay('vboxSettingsGlobalNetEditDialog','UIGlobalSettingsNetworkDetails');
  369. var buttons = {};
  370. buttons[trans('OK','QIMessageBox')] = function(){
  371. var nic = $('#vboxSettingsGlobalNetList').children('li.vboxListItemSelected').first().data('interface');
  372. nic.IPAddress = $('#vboxSettingsGlobalNetIPv4').val();
  373. nic.networkMask = $('#vboxSettingsGlobalNetIPv4Mask').val();
  374. nic.IPV6Address = $('#vboxSettingsGlobalNetIPv6').val();
  375. nic.IPV6NetworkMaskPrefixLength = $('#vboxSettingsGlobalNetIPv6Mask').val();
  376. nic.dhcpServer = {};
  377. nic.dhcpServer.networkName = nic.networkName;
  378. nic.dhcpServer.enabled = $('#vboxSettingsGlobalNetDHCPEnabled').prop('checked');
  379. nic.dhcpServer.IPAddress = $('#vboxSettingsGlobalNetServerAddress').val();
  380. nic.dhcpServer.networkMask = $('#vboxSettingsGlobalNetServerMask').val();
  381. nic.dhcpServer.lowerIP = $('#vboxSettingsGlobalNetLower').val();
  382. nic.dhcpServer.upperIP = $('#vboxSettingsGlobalNetUpper').val();
  383. $('#vboxSettingsGlobalNetList').children('li.vboxListItemSelected').first().data('interface',nic);
  384. $(this).dialog("close");
  385. };
  386. buttons[trans('Cancel','QIMessageBox')] = function(){$(this).dialog("close");};
  387. $('#vboxSettingsGlobalNetEditDialog').dialog({'buttons':buttons,'width':500,'modal':true,'autoOpen':false,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/nw_16px.png" class="vboxDialogTitleIcon" /> ' +trans('Host-only Network Details','UIGlobalSettingsNetworkDetails')});
  388. function vboxSettingsGlobalNetEditDialog() {
  389. var nic = $('#vboxSettingsGlobalNetList').children('li.vboxListItemSelected').first().data('interface');
  390. // Set Form Values
  391. $('#vboxSettingsGlobalNetIPv4').val(nic.IPAddress);
  392. $('#vboxSettingsGlobalNetIPv4Mask').val(nic.networkMask);
  393. if(nic.IPV6Supported) {
  394. $('#vboxSettingsGlobalNetIPv6').prop('disabled',false).val(nic.IPV6Address).closest('tr').find('span').removeClass('vboxDisabled');
  395. $('#vboxSettingsGlobalNetIPv6Mask').prop('disabled',false).val(nic.IPV6NetworkMaskPrefixLength).closest('tr').find('span').removeClass('vboxDisabled');
  396. } else {
  397. $('#vboxSettingsGlobalNetIPv6').prop('disabled',true).val('').closest('tr').find('span').addClass('vboxDisabled');
  398. $('#vboxSettingsGlobalNetIPv6Mask').prop('disabled',true).val('').closest('tr').find('span').addClass('vboxDisabled');
  399. }
  400. if(nic.dhcpServer && nic.dhcpServer.networkName) {
  401. $('#vboxSettingsGlobalNetServerAddress').val(nic.dhcpServer.IPAddress);
  402. $('#vboxSettingsGlobalNetServerMask').val(nic.dhcpServer.networkMask);
  403. $('#vboxSettingsGlobalNetLower').val(nic.dhcpServer.lowerIP);
  404. $('#vboxSettingsGlobalNetUpper').val(nic.dhcpServer.upperIP);
  405. } else {
  406. $('#vboxSettingsGlobalNetServerAddress').val('');
  407. $('#vboxSettingsGlobalNetServerMask').val('');
  408. $('#vboxSettingsGlobalNetLower').val('');
  409. $('#vboxSettingsGlobalNetUpper').val('');
  410. }
  411. $('#vboxSettingsGlobalNetEdit').tabs('option','active',0);
  412. $('#vboxSettingsGlobalNetDHCPEnabled').trigger('click');
  413. if(nic.dhcpServer && nic.dhcpServer.enabled && !$('#vboxSettingsGlobalNetDHCPEnabled').prop('checked')) {
  414. $('#vboxSettingsGlobalNetDHCPEnabled').trigger('click');
  415. } else if(nic.dhcpServer && !nic.dhcpServer.enabled && $('#vboxSettingsGlobalNetDHCPEnabled').prop('checked')) {
  416. $('#vboxSettingsGlobalNetDHCPEnabled').trigger('click');
  417. }
  418. $('#vboxSettingsGlobalNetEditDialog').dialog('open');
  419. }
  420. /*
  421. *
  422. * Edit NAT Network Interface Dialog
  423. *
  424. */
  425. vboxInitDisplay('vboxSettingsGlobalNATNetworkEditDialog', 'UIGlobalSettingsNetworkDetailsNAT');
  426. var buttons = {};
  427. buttons[trans('OK','QIMessageBox')] = function(){
  428. var net = $('#vboxSettingsGlobalNATNetList').children('tr.vboxListItemSelected').first().data('NATNetwork');
  429. // Get Form Values
  430. net.enabled = $('#vboxSettingsGlobalNATNetEnabled').prop('checked');
  431. net.networkName = $('#vboxSettingsGlobalNATNetName').val();
  432. net.network = $('#vboxSettingsGlobalNATNetNetwork').val();
  433. net.needDhcpServer = $('#vboxSettingsGlobalNATNetDHCP').prop('checked');
  434. net.IPv6Enabled = $('#vboxSettingsGlobalNATNetIPv6').prop('checked');
  435. net.advertiseDefaultIPv6RouteEnabled = $('#vboxSettingsGlobalNATNetIPv6Route').prop('checked');
  436. net._modified = true;
  437. $('#vboxSettingsGlobalNATNetList').children('tr.vboxListItemSelected').first().data('NATNetwork',net).find('input').prop('checked', net.enabled);
  438. $(this).dialog("close");
  439. };
  440. buttons[trans('Cancel','QIMessageBox')] = function(){$(this).dialog("close");};
  441. $('#vboxSettingsGlobalNATNetworkEditDialog').dialog({'buttons':buttons,'width':500,'modal':true,'autoOpen':false,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/nw_16px.png" class="vboxDialogTitleIcon" /> ' +trans('Host-only Network Details','UIGlobalSettingsNetworkDetails')});
  442. $('#vboxSettingsGlobalNATNetIPv6').on('enable',function() {
  443. if(this.checked) {
  444. $('#vboxSettingsGlobalNATNetIPv6Route').prop('disabled', false).siblings().removeClass('vboxDisabled');
  445. } else {
  446. $('#vboxSettingsGlobalNATNetIPv6Route').prop('disabled', true).siblings().addClass('vboxDisabled');
  447. }
  448. }).on('click',function(){
  449. $(this).trigger('enable');
  450. });
  451. function vboxSettingsGlobalNATNetworkEditDialog() {
  452. var net = $('#vboxSettingsGlobalNATNetList').children('tr.vboxListItemSelected').first().data('NATNetwork');
  453. // Set Form Values
  454. $('#vboxSettingsGlobalNATNetEnabled').prop('checked', net.enabled);
  455. $('#vboxSettingsGlobalNATNetName').val(net.networkName);
  456. $('#vboxSettingsGlobalNATNetNetwork').val(net.network);
  457. $('#vboxSettingsGlobalNATNetDHCP').prop('checked', net.needDhcpServer)
  458. $('#vboxSettingsGlobalNATNetIPv6').prop('checked', net.IPv6Enabled)
  459. $('#vboxSettingsGlobalNATNetIPv6Route').prop('checked', net.advertiseDefaultIPv6RouteEnabled)
  460. $('#vboxSettingsGlobalNATNetEnabled').triggerHandler('click');
  461. $('#vboxSettingsGlobalNATNetIPv6').triggerHandler('click');
  462. $('#vboxSettingsGlobalNATNetRules').val(trans('Port Forwarding', 'UIGlobalSettingsNetworkDetailsNAT')).off('click').on('click',function(){
  463. vboxSettingsGlobalNetworkNatPortForwardingDialog(net, $('#vboxSettingsGlobalNATNetList').children('tr.vboxListItemSelected').first());
  464. });
  465. $('#vboxSettingsGlobalNATNetworkEditDialog').dialog('open');
  466. }
  467. function vboxSettingsGlobalNetworkNatPortForwardingDialog(net, row) {
  468. if($('#vboxSettingsGlobalNetworkNatPortForwardingDialog')[0])
  469. $('#vboxSettingsGlobalNetworkNatPortForwardingDialog').empty().remove();
  470. var l = new vboxLoader();
  471. l.addFileToDOM("panes/settingsGlobalNetworkNATPortForwarding.html");
  472. l.onLoad = function(){
  473. vboxSettingsGlobalNetworkNatPortForwardingInit(net.portForwardRules4, false);
  474. vboxSettingsGlobalNetworkNatPortForwardingInit(net.portForwardRules6, true);
  475. var buttons = {};
  476. buttons[trans('OK','QIMessageBox')] = function(){
  477. // wrap ips in []
  478. var wrapIp = function(ip) {
  479. ip = ip.trim();
  480. if(!ip) return '[]';
  481. if(ip[0] != '[') $ip = '[' + ip;
  482. if(ip[ip.length-1] != ']') ip += ']';
  483. return ip;
  484. }
  485. // Get rules
  486. var none=0;
  487. do {
  488. var ruleNum = 4 + (none*2);
  489. var rules = $('#vboxSettingsGlobalNetworkNatPortForwardingListIPv'+ruleNum).children('tr');
  490. var rulesToPass = new Array();
  491. for(var i = 0; i < rules.length; i++) {
  492. if($(rules[i]).data('vboxRule')[3] == 0 || $(rules[i]).data('vboxRule')[5] == 0) {
  493. vboxAlert(trans("The current port forwarding rules are not valid. " +
  494. "None of the host or guest port values may be set to zero.",'UIMessageCenter'));
  495. return;
  496. }
  497. rulesToPass[i] = $(rules[i]).data('vboxRule');
  498. rulesToPass[i][0] = rulesToPass[i][0].replace(':','');
  499. rulesToPass[i][2] = wrapIp(rulesToPass[i][2]);
  500. rulesToPass[i][4] = wrapIp(rulesToPass[i][4]);
  501. rulesToPass[i] = rulesToPass[i].join(':');
  502. }
  503. $('#vboxSettingsGlobalNATNetList').children('tr.vboxListItemSelected').first().data('NATNetwork')['portForwardRules'+ruleNum] = rulesToPass;
  504. } while(none++ < 1)
  505. $(this).trigger('close').empty().remove();
  506. };
  507. buttons[trans('Cancel','QIMessageBox')] = function(){
  508. $(this).trigger('close').empty().remove();
  509. };
  510. vboxInitDisplay($('#vboxSettingsGlobalNetworkNatPortForwardingDialog'), 'UIPortForwardingModel');
  511. $('#vboxSettingsGlobalNetworkNatPortForwardingDialog').tabs();
  512. $('#vboxSettingsGlobalNetworkNatPortForwardingDialog').dialog({'closeOnEscape':true,'width':840,'height':400,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/nw_16px.png" class="vboxDialogTitleIcon" /> ' + trans('Port Forwarding Rules','UIMachineSettingsPortForwardingDlg')}).on("dialogbeforeclose",function(){
  513. $(this).parent().find('span:contains("'+trans('Cancel','QIMessageBox')+'")').trigger('click');
  514. });
  515. };
  516. l.run();
  517. }
  518. /*
  519. *
  520. * Update Data onSave()
  521. *
  522. */
  523. $('#vboxSettingsDialog').on('save',function(){
  524. $('#vboxSettingsDialog').data('vboxHostOnlyInterfaces').networkInterfaces = new Array();
  525. $('#vboxSettingsGlobalNetList').children('li').each(function(){
  526. $('#vboxSettingsDialog').data('vboxHostOnlyInterfaces').networkInterfaces.push($(this).data('interface'));
  527. });
  528. var nets = [];
  529. $('#vboxSettingsGlobalNATNetList').children('tr').each(function(){
  530. nets.push($(this).data('NATNetwork'));
  531. });
  532. $('#vboxSettingsDialog').data('vboxNATNetworks',nets);
  533. });
  534. /*
  535. * Remove dialogs on close
  536. */
  537. $('#vboxSettingsDialog').on('close',function(){
  538. $('#vboxSettingsGlobalNetEditDialog').remove();
  539. $('#vboxSettingsGlobalNATNetworkEditDialog').remove();
  540. });
  541. </script>