luci-app-firewall: support 'helper' and 'reflection_src' parameters for redirects
authorJo-Philipp Wich <jo@mein.io>
Thu, 16 Jan 2020 15:30:58 +0000 (16:30 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 16 Jan 2020 15:30:58 +0000 (16:30 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js

index af2f9b76e84fc23c3b80d4b64652801b5314a044..49c8cd75fe7fe8226909024e14615660a38e902e 100644 (file)
@@ -79,14 +79,22 @@ return L.view.extend({
                expect: { '': {} }
        }),
 
+       callConntrackHelpers: rpc.declare({
+               object: 'luci',
+               method: 'getConntrackHelpers',
+               expect: { result: [] }
+       }),
+
        load: function() {
                return Promise.all([
-                       this.callHostHints()
+                       this.callHostHints(),
+                       this.callConntrackHelpers()
                ]);
        },
 
        render: function(data) {
                var hosts = data[0],
+                   ctHelpers = data[1],
                    m, s, o;
 
                m = new form.Map('firewall', _('Firewall - Port Forwards'),
@@ -264,6 +272,33 @@ return L.view.extend({
                o.rmempty = true;
                o.default = o.enabled;
 
+               o = s.taboption('advanced', form.ListValue, 'reflection_src', _('Loopback source IP'), _('Specifies whether to use the external or the internal IP address for reflected traffic.'));
+               o.modalonly = true;
+               o.depends('reflection', '1');
+               o.value('internal', _('Use internal IP address'));
+               o.value('external', _('Use external IP address'));
+               o.write = function(section_id, value) {
+                       uci.set('firewall', section_id, 'reflection_src', (value != 'internal') ? value : null);
+               };
+
+               o = s.taboption('advanced', form.Value, 'helper', _('Match helper'), _('Match traffic using the specified connection tracking helper.'));
+               o.modalonly = true;
+               o.placeholder = _('any');
+               for (var i = 0; i < ctHelpers.length; i++)
+                       o.value(ctHelpers[i].name, '%s (%s)'.format(ctHelpers[i].description, ctHelpers[i].name.toUpperCase()));
+               o.validate = function(section_id, value) {
+                       if (value == '' || value == null)
+                               return true;
+
+                       value = value.replace(/^!\s*/, '');
+
+                       for (var i = 0; i < ctHelpers.length; i++)
+                               if (value == ctHelpers[i].name)
+                                       return true;
+
+                       return _('Unknown or not installed conntrack helper "%s"').format(value);
+               };
+
                o = s.taboption('advanced', form.Value, 'extra', _('Extra arguments'),
                        _('Passes additional arguments to iptables. Use with care!'));
                o.modalonly = true;