diff --git a/src/js/yunohost/controllers/firewall.js b/src/js/yunohost/controllers/firewall.js index 5ccd5964..f1055638 100644 --- a/src/js/yunohost/controllers/firewall.js +++ b/src/js/yunohost/controllers/firewall.js @@ -30,23 +30,53 @@ // Get UPnP status firewall.upnp = data.uPnP.enabled; - c.view('tools/tools_firewall', firewall); + c.view('tools/tools_firewall', firewall, function() { + + // Buttons in the 'ports' panel to open/close specific ports + $("button[data-port]").on("click", function() { + + var port = $(this).data("port"); + var action = $(this).data("action"); + var protocol = $(this).data("protocol"); + var connection = $(this).data("connection"); + c.confirm( + y18n.t('firewall'), + // confirm_firewall_open and confirm_firewall_close + y18n.t('confirm_firewall_' + action, [ port, y18n.t(protocol), y18n.t(connection)]), + function(){ c.togglePort(port, protocol, connection, action); } + ); + }); + + // Buttons to enable / disable UPnP + $("button[data-upnp]").on("click", function() { + var action = $(this).data("upnp"); + c.confirm( + y18n.t('firewall'), + // confirm_upnp_enable and confirm_upnp_disable + y18n.t('confirm_upnp_' + action), + function(){ + c.api('GET', '/firewall/upnp', {action: action}, function(data) { + c.redirect_to('#/tools/firewall'); + }); + } + ); + }); + }); }); }); - // Enable/Disable UPnP - app.get('#/tools/firewall/upnp/:action', function (c) { + // Update port status from form + app.post('#/tools/firewall/port', function (c) { c.confirm( y18n.t('firewall'), - // confirm_upnp_enable and confirm_upnp_disable - y18n.t('confirm_upnp_' + c.params['action'].toLowerCase()), + y18n.t('confirm_firewall_' + c.params['action'].toLowerCase(), [ c.params['port'], y18n.t(c.params['protocol']), y18n.t(c.params['connection']) ]), function(){ - var params = { - action : c.params['action'] - }; - c.api('GET', '/firewall/upnp', params, function(data) { - c.redirect_to('#/tools/firewall'); - }); + c.togglePort( + c.params['port'], + c.params['protocol'], + c.params['connection'], + c.params['action'] + ); } ); }); @@ -118,38 +148,5 @@ return; }); - // Update port status from direct link - // #/firewall/port/{{@key}}/tcp/ipv4/close - app.get('#/tools/firewall/port/:port/:protocol/:connection/:action', function (c) { - c.confirm( - y18n.t('firewall'), - // confirm_firewall_open and confirm_firewall_close - y18n.t( 'confirm_firewall_' + c.params['action'].toLowerCase(), [ c.params['port'], y18n.t(c.params['protocol']), y18n.t(c.params['connection'])]), - function(){ - c.togglePort( - c.params['port'], - c.params['protocol'], - c.params['connection'], - c.params['action'] - ); - } - ); - }); - - // Update port status from form - app.post('#/tools/firewall/port', function (c) { - c.confirm( - y18n.t('firewall'), - y18n.t('confirm_firewall_' + c.params['action'].toLowerCase(), [ c.params['port'], y18n.t(c.params['protocol']), y18n.t(c.params['connection']) ]), - function(){ - c.togglePort( - c.params['port'], - c.params['protocol'], - c.params['connection'], - c.params['action'] - ); - } - ); - }); })(); diff --git a/src/views/tools/tools_firewall.ms b/src/views/tools/tools_firewall.ms index a22ef665..c03c03d3 100644 --- a/src/views/tools/tools_firewall.ms +++ b/src/views/tools/tools_firewall.ms @@ -29,20 +29,20 @@
{{t 'upnp_enabled'}}
- {{t 'disable'}} + {{else}}{{t 'upnp_disabled'}}
- {{t 'enable'}} + {{/if}}