'require tools.firewall as fwtool';
'require tools.widgets as widgets';
-function skeys(obj, key, mode) {
- if (obj == null || typeof(obj) != 'object')
- return [];
-
- return Object.keys(obj).map(function(e) {
- var v = (key != null) ? obj[e][key] : e;
-
- switch (mode) {
- case 'addr':
- v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g,
- function(m0, m1) { return ('000' + m1.toLowerCase()).substr(-4) }) : null;
- break;
-
- case 'num':
- v = (v != null) ? +v : null;
- break;
- }
-
- return [ e, v ];
- }).filter(function(e) {
- return (e[1] != null);
- }).sort(function(a, b) {
- return (a[1] > b[1]);
- }).map(function(e) {
- return e[0];
- });
-}
-
function fmt(fmt /*, ...*/) {
var repl = [], wrap = false;
}
function forward_proto_txt(s) {
- return fmt('%s-%s', _('IPv4'),
+ return fmt('%s-%s',
+ fwtool.fmt_family(uci.get('firewall', s, 'family')),
fwtool.fmt_proto(uci.get('firewall', s, 'proto'),
uci.get('firewall', s, 'icmp_type')) || 'TCP+UDP');
}
return L.view.extend({
callHostHints: rpc.declare({
object: 'luci',
- method: 'host_hints'
+ method: 'getHostHints',
+ expect: { '': {} }
}),
load: function() {
return uci.get('firewall', section_id, 'name') || _('Unnamed forward');
};
+ s.handleAdd = function(ev) {
+ var config_name = this.uciconfig || this.map.config,
+ section_id = uci.add(config_name, this.sectiontype);
+
+ uci.set(config_name, section_id, 'target', 'DNAT');
+
+ this.addedSection = section_id;
+ this.renderMoreOptionsModal(section_id);
+ };
+
o = s.taboption('general', form.Value, 'name', _('Name'));
o.placeholder = _('Unnamed forward');
o.modalonly = true;
o.rmempty = true;
o.datatype = 'neg(macaddr)';
o.placeholder = E('em', _('any'));
- skeys(hosts).forEach(function(mac) {
+ L.sortedKeys(hosts).forEach(function(mac) {
o.value(mac, '%s (%s)'.format(
mac,
hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?'
o.rmempty = true;
o.datatype = 'neg(ipmask4)';
o.placeholder = E('em', _('any'));
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
o.rmempty = true;
o.datatype = 'neg(ipmask4)';
o.placeholder = E('em', _('any'));
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac
o.modalonly = true;
o.rmempty = true;
o.datatype = 'ipmask4';
- skeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
+ L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
o.value(hosts[mac].ipv4, '%s (%s)'.format(
hosts[mac].ipv4,
hosts[mac].name || mac