11 'require tools.widgets as widgets';
13 function count_changes(section_id) {
14 var changes = ui.changes.changes, n = 0;
16 if (!L.isObject(changes))
19 if (Array.isArray(changes.network))
20 for (var i = 0; i < changes.network.length; i++)
21 n += (changes.network[i][1] == section_id);
23 if (Array.isArray(changes.dhcp))
24 for (var i = 0; i < changes.dhcp.length; i++)
25 n += (changes.dhcp[i][1] == section_id);
30 function render_iface(dev, alias) {
31 var type = dev ? dev.getType() : 'ethernet',
32 up = dev ? dev.isUp() : false;
34 return E('span', { class: 'cbi-tooltip-container' }, [
35 E('img', { 'class' : 'middle', 'src': L.resource('icons/%s%s.png').format(
36 alias ? 'alias' : type,
37 up ? '' : '_disabled') }),
38 E('span', { 'class': 'cbi-tooltip ifacebadge large' }, [
39 E('img', { 'src': L.resource('icons/%s%s.png').format(
40 type, up ? '' : '_disabled') }),
41 L.itemlist(E('span', { 'class': 'left' }), [
42 _('Type'), dev ? dev.getTypeI18n() : null,
43 _('Device'), dev ? dev.getName() : _('Not present'),
44 _('Connected'), up ? _('yes') : _('no'),
45 _('MAC'), dev ? dev.getMAC() : null,
46 _('RX'), dev ? '%.2mB (%d %s)'.format(dev.getRXBytes(), dev.getRXPackets(), _('Pkts.')) : null,
47 _('TX'), dev ? '%.2mB (%d %s)'.format(dev.getTXBytes(), dev.getTXPackets(), _('Pkts.')) : null
53 function render_status(node, ifc, with_device) {
54 var desc = null, c = [];
57 desc = _('Virtual dynamic interface');
58 else if (ifc.isAlias())
59 desc = _('Alias Interface');
60 else if (!uci.get('network', ifc.getName()))
61 return L.itemlist(node, [
62 null, E('em', _('Interface is marked for deletion'))
65 var i18n = ifc.getI18n();
67 desc = desc ? '%s (%s)'.format(desc, i18n) : i18n;
69 var changecount = with_device ? 0 : count_changes(ifc.getName()),
70 ipaddrs = changecount ? [] : ifc.getIPAddrs(),
71 ip6addrs = changecount ? [] : ifc.getIP6Addrs(),
72 errors = ifc.getErrors(),
73 maindev = ifc.getL3Device() || ifc.getDevice(),
74 macaddr = maindev ? maindev.getMAC() : null;
76 return L.itemlist(node, [
77 _('Protocol'), with_device ? null : (desc || '?'),
78 _('Device'), with_device ? (maindev ? maindev.getShortName() : E('em', _('Not present'))) : null,
79 _('Uptime'), (!changecount && ifc.isUp()) ? '%t'.format(ifc.getUptime()) : null,
80 _('MAC'), (!changecount && !ifc.isDynamic() && !ifc.isAlias() && macaddr) ? macaddr : null,
81 _('RX'), (!changecount && !ifc.isDynamic() && !ifc.isAlias() && maindev) ? '%.2mB (%d %s)'.format(maindev.getRXBytes(), maindev.getRXPackets(), _('Pkts.')) : null,
82 _('TX'), (!changecount && !ifc.isDynamic() && !ifc.isAlias() && maindev) ? '%.2mB (%d %s)'.format(maindev.getTXBytes(), maindev.getTXPackets(), _('Pkts.')) : null,
83 _('IPv4'), ipaddrs[0],
84 _('IPv4'), ipaddrs[1],
85 _('IPv4'), ipaddrs[2],
86 _('IPv4'), ipaddrs[3],
87 _('IPv4'), ipaddrs[4],
88 _('IPv6'), ip6addrs[0],
89 _('IPv6'), ip6addrs[1],
90 _('IPv6'), ip6addrs[2],
91 _('IPv6'), ip6addrs[3],
92 _('IPv6'), ip6addrs[4],
93 _('IPv6'), ip6addrs[5],
94 _('IPv6'), ip6addrs[6],
95 _('IPv6'), ip6addrs[7],
96 _('IPv6'), ip6addrs[8],
97 _('IPv6'), ip6addrs[9],
98 _('IPv6-PD'), changecount ? null : ifc.getIP6Prefix(),
99 _('Information'), with_device ? null : (ifc.get('auto') != '0' ? null : _('Not started on boot')),
100 _('Error'), errors ? errors[0] : null,
101 _('Error'), errors ? errors[1] : null,
102 _('Error'), errors ? errors[2] : null,
103 _('Error'), errors ? errors[3] : null,
104 _('Error'), errors ? errors[4] : null,
105 null, changecount ? E('a', {
107 click: L.bind(ui.changes.displayChanges, ui.changes)
108 }, _('Interface has %d pending changes').format(changecount)) : null
112 function render_modal_status(node, ifc) {
113 var dev = ifc ? (ifc.getDevice() || ifc.getL3Device() || ifc.getL3Device()) : null;
117 'src': L.resource('icons/%s%s.png').format(dev ? dev.getType() : 'ethernet', (dev && dev.isUp()) ? '' : '_disabled'),
118 'title': dev ? dev.getTypeI18n() : _('Not present')
120 ifc ? render_status(E('span'), ifc, true) : E('em', _('Interface not present or not connected yet.'))
126 function render_ifacebox_status(node, ifc) {
127 var dev = ifc.getL3Device() || ifc.getDevice(),
128 subdevs = ifc.getDevices(),
129 c = [ render_iface(dev, ifc.isAlias()) ];
131 if (subdevs && subdevs.length) {
134 for (var j = 0; j < subdevs.length; j++)
135 sifs.push(render_iface(subdevs[j]));
139 c.push(E('span', {}, sifs));
143 c.push(E('small', {}, ifc.isAlias() ? _('Alias of "%s"').format(ifc.isAlias())
144 : (dev ? dev.getName() : E('em', _('Not present')))));
146 dom.content(node, c);
148 return firewall.getZoneByNetwork(ifc.getName()).then(L.bind(function(zone) {
149 this.style.backgroundColor = zone ? zone.getColor() : '#EEEEEE';
150 this.title = zone ? _('Part of zone %q').format(zone.getName()) : _('No zone assigned');
151 }, node.previousElementSibling));
154 function iface_updown(up, id, ev, force) {
155 var row = document.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(id)),
156 dsc = row.querySelector('[data-name="_ifacestat"] > div'),
157 btns = row.querySelectorAll('.cbi-section-actions .reconnect, .cbi-section-actions .down');
160 btns[+!up].classList.add('spinning');
162 btns[0].disabled = true;
163 btns[1].disabled = true;
166 L.resolveDefault(fs.exec_direct('/usr/libexec/luci-peeraddr')).then(function(res) {
167 var info = null; try { info = JSON.parse(res); } catch(e) {}
169 if (L.isObject(info) &&
170 Array.isArray(info.inbound_interfaces) &&
171 info.inbound_interfaces.filter(function(i) { return i == id })[0]) {
173 ui.showModal(_('Confirm disconnect'), [
174 E('p', _('You appear to be currently connected to the device via the "%h" interface. Do you really want to shut down the interface?').format(id)),
175 E('div', { 'class': 'right' }, [
177 'class': 'cbi-button cbi-button-neutral',
178 'click': function(ev) {
179 btns[1].classList.remove('spinning');
180 btns[1].disabled = false;
181 btns[0].disabled = false;
188 'class': 'cbi-button cbi-button-negative important',
189 'click': function(ev) {
190 dsc.setAttribute('disconnect', '');
191 dom.content(dsc, E('em', _('Interface is shutting down...')));
200 dsc.setAttribute('disconnect', '');
201 dom.content(dsc, E('em', _('Interface is shutting down...')));
206 dsc.setAttribute(up ? 'reconnect' : 'disconnect', force ? 'force' : '');
207 dom.content(dsc, E('em', up ? _('Interface is reconnecting...') : _('Interface is shutting down...')));
211 function get_netmask(s, use_cfgvalue) {
212 var readfn = use_cfgvalue ? 'cfgvalue' : 'formvalue',
213 addropt = s.children.filter(function(o) { return o.option == 'ipaddr'})[0],
214 addrvals = addropt ? L.toArray(addropt[readfn](s.section)) : [],
215 maskopt = s.children.filter(function(o) { return o.option == 'netmask'})[0],
216 maskval = maskopt ? maskopt[readfn](s.section) : null,
217 firstsubnet = maskval ? addrvals[0] + '/' + maskval : addrvals.filter(function(a) { return a.indexOf('/') > 0 })[0];
219 if (firstsubnet == null)
222 var mask = firstsubnet.split('/')[1];
225 mask = network.prefixToMask(+mask);
231 poll_status: function(map, networks) {
232 var resolveZone = null;
234 for (var i = 0; i < networks.length; i++) {
235 var ifc = networks[i],
236 row = map.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(ifc.getName()));
241 var dsc = row.querySelector('[data-name="_ifacestat"] > div'),
242 box = row.querySelector('[data-name="_ifacebox"] .ifacebox-body'),
243 btn1 = row.querySelector('.cbi-section-actions .reconnect'),
244 btn2 = row.querySelector('.cbi-section-actions .down'),
245 stat = document.querySelector('[id="%s-ifc-status"]'.format(ifc.getName())),
246 resolveZone = render_ifacebox_status(box, ifc),
247 disabled = ifc ? !ifc.isUp() : true,
248 dynamic = ifc ? ifc.isDynamic() : false;
250 if (dsc.hasAttribute('reconnect')) {
251 dom.content(dsc, E('em', _('Interface is starting...')));
253 else if (dsc.hasAttribute('disconnect')) {
254 dom.content(dsc, E('em', _('Interface is stopping...')));
256 else if (ifc.getProtocol() || uci.get('network', ifc.getName()) == null) {
257 render_status(dsc, ifc, false);
259 else if (!ifc.getProtocol()) {
260 var e = map.querySelector('[id="cbi-network-%s"] .cbi-button-edit'.format(ifc.getName()));
261 if (e) e.disabled = true;
263 var link = L.url('admin/system/opkg') + '?query=luci-proto';
265 E('em', _('Unsupported protocol type.')), E('br'),
266 E('a', { href: link }, _('Install protocol extensions...'))
270 dom.content(dsc, E('em', _('Interface not present or not connected yet.')));
274 var dev = ifc.getDevice();
277 'src': L.resource('icons/%s%s.png').format(dev ? dev.getType() : 'ethernet', (dev && dev.isUp()) ? '' : '_disabled'),
278 'title': dev ? dev.getTypeI18n() : _('Not present')
280 render_status(E('span'), ifc, true)
284 btn1.disabled = btn1.classList.contains('spinning') || btn2.classList.contains('spinning') || dynamic;
285 btn2.disabled = btn1.classList.contains('spinning') || btn2.classList.contains('spinning') || dynamic || disabled;
288 return Promise.all([ resolveZone, network.flushCache() ]);
293 network.getDSLModemType(),
298 render: function(data) {
299 var dslModemType = data[0],
302 m = new form.Map('network');
306 s = m.section(form.GridSection, 'interface', _('Interfaces'));
309 s.addbtntitle = _('Add new interface...');
311 s.load = function() {
313 network.getNetworks(),
315 ]).then(L.bind(function(data) {
316 this.networks = data[0];
317 this.zones = data[1];
321 s.tab('general', _('General Settings'));
322 s.tab('advanced', _('Advanced Settings'));
323 s.tab('physical', _('Physical Settings'));
324 s.tab('firewall', _('Firewall Settings'));
325 s.tab('dhcp', _('DHCP Server'));
327 s.cfgsections = function() {
328 return this.networks.map(function(n) { return n.getName() })
329 .filter(function(n) { return n != 'loopback' });
332 s.modaltitle = function(section_id) {
333 return _('Interfaces') + ' » ' + section_id.toUpperCase();
336 s.renderRowActions = function(section_id) {
337 var tdEl = this.super('renderRowActions', [ section_id, _('Edit') ]),
338 net = this.networks.filter(function(n) { return n.getName() == section_id })[0],
339 disabled = net ? !net.isUp() : true,
340 dynamic = net ? net.isDynamic() : false;
342 dom.content(tdEl.lastChild, [
344 'class': 'cbi-button cbi-button-neutral reconnect',
345 'click': iface_updown.bind(this, true, section_id),
346 'title': _('Reconnect this interface'),
347 'disabled': dynamic ? 'disabled' : null
350 'class': 'cbi-button cbi-button-neutral down',
351 'click': iface_updown.bind(this, false, section_id),
352 'title': _('Shutdown this interface'),
353 'disabled': (dynamic || disabled) ? 'disabled' : null
355 tdEl.lastChild.firstChild,
356 tdEl.lastChild.lastChild
359 if (!dynamic && net && !uci.get('network', net.getName())) {
360 tdEl.lastChild.childNodes[0].disabled = true;
361 tdEl.lastChild.childNodes[2].disabled = true;
362 tdEl.lastChild.childNodes[3].disabled = true;
368 s.addModalOptions = function(s) {
369 var protoval = uci.get('network', s.section, 'proto'),
370 protoclass = protoval ? network.getProtocol(protoval) : null,
371 o, ifname_single, ifname_multi, proto_select, proto_switch, type, stp, igmp, ss, so;
376 return network.getNetwork(s.section).then(L.bind(function(ifc) {
377 var protocols = network.getProtocols();
379 protocols.sort(function(a, b) {
380 return a.getProtocol() > b.getProtocol();
383 o = s.taboption('general', form.DummyValue, '_ifacestat_modal', _('Status'));
385 o.cfgvalue = L.bind(function(section_id) {
386 var net = this.networks.filter(function(n) { return n.getName() == section_id })[0];
388 return render_modal_status(E('div', {
389 'id': '%s-ifc-status'.format(section_id),
390 'class': 'ifacebadge large'
393 o.write = function() {};
395 proto_select = s.taboption('general', form.ListValue, 'proto', _('Protocol'));
396 proto_select.modalonly = true;
398 proto_switch = s.taboption('general', form.Button, '_switch_proto');
399 proto_switch.modalonly = true;
400 proto_switch.title = _('Really switch protocol?');
401 proto_switch.inputtitle = _('Switch protocol');
402 proto_switch.inputstyle = 'apply';
403 proto_switch.onclick = L.bind(function(ev) {
405 .then(L.bind(m.load, m))
406 .then(L.bind(m.render, m))
407 .then(L.bind(this.renderMoreOptionsModal, this, s.section));
410 o = s.taboption('general', form.Flag, 'auto', _('Bring up on boot'));
412 o.default = o.enabled;
414 type = s.taboption('physical', form.Flag, 'type', _('Bridge interfaces'), _('Creates a bridge over specified interface(s)'));
415 type.modalonly = true;
417 type.enabled = 'bridge';
418 type.write = type.remove = function(section_id, value) {
419 var protocol = network.getProtocol(proto_select.formvalue(section_id)),
420 ifnameopt = this.section.children.filter(function(o) { return o.option == (value ? 'ifname_multi' : 'ifname_single') })[0];
422 if (!protocol.isVirtual() && !this.isActive(section_id))
425 var old_ifnames = [],
426 devs = ifc.getDevices() || L.toArray(ifc.getDevice());
428 for (var i = 0; i < devs.length; i++)
429 old_ifnames.push(devs[i].getName());
431 var new_ifnames = L.toArray(ifnameopt.formvalue(section_id));
434 new_ifnames.length = Math.max(new_ifnames.length, 1);
439 for (var i = 0; i < Math.max(old_ifnames.length, new_ifnames.length); i++) {
440 if (old_ifnames[i] != new_ifnames[i]) {
442 for (var j = 0; j < old_ifnames.length; j++)
443 ifc.deleteDevice(old_ifnames[j]);
445 for (var j = 0; j < new_ifnames.length; j++)
446 ifc.addDevice(new_ifnames[j]);
453 uci.set('network', section_id, 'type', 'bridge');
455 uci.unset('network', section_id, 'type');
458 stp = s.taboption('physical', form.Flag, 'stp', _('Enable <abbr title="Spanning Tree Protocol">STP</abbr>'), _('Enables the Spanning Tree Protocol on this bridge'));
460 igmp = s.taboption('physical', form.Flag, 'igmp_snooping', _('Enable <abbr title="Internet Group Management Protocol">IGMP</abbr> snooping'), _('Enables IGMP snooping on this bridge'));
462 ifname_single = s.taboption('physical', widgets.DeviceSelect, 'ifname_single', _('Interface'));
463 ifname_single.nobridges = ifc.isBridge();
464 ifname_single.noaliases = false;
465 ifname_single.optional = false;
466 ifname_single.network = ifc.getName();
467 ifname_single.write = ifname_single.remove = function() {};
469 ifname_multi = s.taboption('physical', widgets.DeviceSelect, 'ifname_multi', _('Interface'));
470 ifname_multi.nobridges = ifc.isBridge();
471 ifname_multi.noaliases = true;
472 ifname_multi.multiple = true;
473 ifname_multi.optional = true;
474 ifname_multi.network = ifc.getName();
475 ifname_multi.display_size = 6;
476 ifname_multi.write = ifname_multi.remove = function() {};
478 ifname_single.cfgvalue = ifname_multi.cfgvalue = function(section_id) {
479 var devs = ifc.getDevices() || L.toArray(ifc.getDevice()),
482 for (var i = 0; i < devs.length; i++)
483 ifnames.push(devs[i].getName());
488 if (L.hasSystemFeature('firewall')) {
489 o = s.taboption('firewall', widgets.ZoneSelect, '_zone', _('Create / Assign firewall-zone'), _('Choose the firewall zone you want to assign to this interface. Select <em>unspecified</em> to remove the interface from the associated zone or fill out the <em>custom</em> field to define a new zone and attach the interface to it.'));
490 o.network = ifc.getName();
493 o.cfgvalue = function(section_id) {
494 return firewall.getZoneByNetwork(ifc.getName()).then(function(zone) {
495 return (zone != null ? zone.getName() : null);
499 o.write = o.remove = function(section_id, value) {
501 firewall.getZoneByNetwork(ifc.getName()),
502 (value != null) ? firewall.getZone(value) : null
503 ]).then(function(data) {
504 var old_zone = data[0],
507 if (old_zone == null && new_zone == null && (value == null || value == ''))
510 if (old_zone != null && new_zone != null && old_zone.getName() == new_zone.getName())
513 if (old_zone != null)
514 old_zone.deleteNetwork(ifc.getName());
516 if (new_zone != null)
517 new_zone.addNetwork(ifc.getName());
518 else if (value != null)
519 return firewall.addZone(value).then(function(new_zone) {
520 new_zone.addNetwork(ifc.getName());
526 for (var i = 0; i < protocols.length; i++) {
527 proto_select.value(protocols[i].getProtocol(), protocols[i].getI18n());
529 if (protocols[i].getProtocol() != uci.get('network', s.section, 'proto'))
530 proto_switch.depends('proto', protocols[i].getProtocol());
532 if (!protocols[i].isVirtual()) {
533 type.depends('proto', protocols[i].getProtocol());
534 stp.depends({ type: 'bridge', proto: protocols[i].getProtocol() });
535 igmp.depends({ type: 'bridge', proto: protocols[i].getProtocol() });
536 ifname_single.depends({ type: '', proto: protocols[i].getProtocol() });
537 ifname_multi.depends({ type: 'bridge', proto: protocols[i].getProtocol() });
541 if (L.hasSystemFeature('dnsmasq') || L.hasSystemFeature('odhcpd')) {
542 o = s.taboption('dhcp', form.SectionValue, '_dhcp', form.TypedSection, 'dhcp');
543 o.depends('proto', 'static');
546 ss.uciconfig = 'dhcp';
547 ss.addremove = false;
550 ss.tab('general', _('General Setup'));
551 ss.tab('advanced', _('Advanced Settings'));
552 ss.tab('ipv6', _('IPv6 Settings'));
554 ss.filter = function(section_id) {
555 return (uci.get('dhcp', section_id, 'interface') == ifc.getName());
558 ss.renderSectionPlaceholder = function() {
559 return E('div', { 'class': 'cbi-section-create' }, [
560 E('p', _('No DHCP Server configured for this interface') + '   '),
562 'class': 'cbi-button cbi-button-add',
563 'title': _('Setup DHCP Server'),
564 'click': ui.createHandlerFn(this, function(section_id, ev) {
565 this.map.save(function() {
566 uci.add('dhcp', 'dhcp', section_id);
567 uci.set('dhcp', section_id, 'interface', section_id);
568 uci.set('dhcp', section_id, 'start', 100);
569 uci.set('dhcp', section_id, 'limit', 150);
570 uci.set('dhcp', section_id, 'leasetime', '12h');
573 }, _('Setup DHCP Server'))
577 ss.taboption('general', form.Flag, 'ignore', _('Ignore interface'), _('Disable <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr> for this interface.'));
579 so = ss.taboption('general', form.Value, 'start', _('Start'), _('Lowest leased address as offset from the network address.'));
581 so.datatype = 'or(uinteger,ip4addr("nomask"))';
584 so = ss.taboption('general', form.Value, 'limit', _('Limit'), _('Maximum number of leased addresses.'));
586 so.datatype = 'uinteger';
589 so = ss.taboption('general', form.Value, 'leasetime', _('Lease time'), _('Expiry time of leased addresses, minimum is 2 minutes (<code>2m</code>).'));
593 so = ss.taboption('advanced', form.Flag, 'dynamicdhcp', _('Dynamic <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>'), _('Dynamically allocate DHCP addresses for clients. If disabled, only clients having static leases will be served.'));
594 so.default = so.enabled;
596 ss.taboption('advanced', form.Flag, 'force', _('Force'), _('Force DHCP on this network even if another server is detected.'));
598 // XXX: is this actually useful?
599 //ss.taboption('advanced', form.Value, 'name', _('Name'), _('Define a name for this network.'));
601 so = ss.taboption('advanced', form.Value, 'netmask', _('<abbr title="Internet Protocol Version 4">IPv4</abbr>-Netmask'), _('Override the netmask sent to clients. Normally it is calculated from the subnet that is served.'));
603 so.datatype = 'ip4addr';
605 so.render = function(option_index, section_id, in_table) {
606 this.placeholder = get_netmask(s, true);
607 return form.Value.prototype.render.apply(this, [ option_index, section_id, in_table ]);
610 so.validate = function(section_id, value) {
611 var node = this.map.findElement('id', this.cbid(section_id));
613 node.querySelector('input').setAttribute('placeholder', get_netmask(s, false));
614 return form.Value.prototype.validate.apply(this, [ section_id, value ]);
617 ss.taboption('advanced', form.DynamicList, 'dhcp_option', _('DHCP-Options'), _('Define additional DHCP options, for example "<code>6,192.168.2.1,192.168.2.2</code>" which advertises different DNS servers to clients.'));
619 for (var i = 0; i < ss.children.length; i++)
620 if (ss.children[i].option != 'ignore')
621 ss.children[i].depends('ignore', '0');
623 so = ss.taboption('ipv6', form.ListValue, 'ra', _('Router Advertisement-Service'));
624 so.value('', _('disabled'));
625 so.value('server', _('server mode'));
626 so.value('relay', _('relay mode'));
627 so.value('hybrid', _('hybrid mode'));
629 so = ss.taboption('ipv6', form.ListValue, 'dhcpv6', _('DHCPv6-Service'));
630 so.value('', _('disabled'));
631 so.value('server', _('server mode'));
632 so.value('relay', _('relay mode'));
633 so.value('hybrid', _('hybrid mode'));
635 so = ss.taboption('ipv6', form.ListValue, 'ndp', _('NDP-Proxy'));
636 so.value('', _('disabled'));
637 so.value('relay', _('relay mode'));
638 so.value('hybrid', _('hybrid mode'));
640 so = ss.taboption('ipv6', form.Flag , 'master', _('Master'), _('Set this interface as master for the dhcpv6 relay.'));
641 so.depends('dhcpv6', 'relay');
642 so.depends('dhcpv6', 'hybrid');
644 so = ss.taboption('ipv6', form.ListValue, 'ra_management', _('DHCPv6-Mode'), _('Default is stateless + stateful'));
645 so.value('0', _('stateless'));
646 so.value('1', _('stateless + stateful'));
647 so.value('2', _('stateful-only'));
648 so.depends('dhcpv6', 'server');
649 so.depends('dhcpv6', 'hybrid');
652 so = ss.taboption('ipv6', form.Flag, 'ra_default', _('Always announce default router'), _('Announce as default router even if no public prefix is available.'));
653 so.depends('ra', 'server');
654 so.depends('ra', 'hybrid');
656 ss.taboption('ipv6', form.DynamicList, 'dns', _('Announced DNS servers'));
657 ss.taboption('ipv6', form.DynamicList, 'domain', _('Announced DNS domains'));
660 ifc.renderFormOptions(s);
662 for (var i = 0; i < s.children.length; i++) {
671 case 'igmp_snooping':
672 case 'ifname_single':
676 case '_switch_proto':
677 case '_ifacestat_modal':
682 for (var j = 0; j < o.deps.length; j++)
683 o.deps[j].proto = protoval;
685 o.depends('proto', protoval);
691 s.handleAdd = function(ev) {
692 var m2 = new form.Map('network'),
693 s2 = m2.section(form.NamedSection, '_new_'),
694 protocols = network.getProtocols(),
695 proto, name, bridge, ifname_single, ifname_multi;
697 protocols.sort(function(a, b) {
698 return a.getProtocol() > b.getProtocol();
701 s2.render = function() {
704 this.renderUCISection('_new_')
705 ]).then(this.renderContents.bind(this));
708 name = s2.option(form.Value, 'name', _('Name'));
709 name.rmempty = false;
710 name.datatype = 'uciname';
711 name.placeholder = _('New interface name…');
712 name.validate = function(section_id, value) {
713 if (uci.get('network', value) != null)
714 return _('The interface name is already used');
716 var pr = network.getProtocol(proto.formvalue(section_id), value),
717 ifname = pr.isVirtual() ? '%s-%s'.format(pr.getProtocol(), value) : 'br-%s'.format(value);
719 if (value.length > 15)
720 return _('The interface name is too long');
725 proto = s2.option(form.ListValue, 'proto', _('Protocol'));
726 proto.validate = name.validate;
728 bridge = s2.option(form.Flag, 'type', _('Bridge interfaces'), _('Creates a bridge over specified interface(s)'));
729 bridge.modalonly = true;
730 bridge.disabled = '';
731 bridge.enabled = 'bridge';
733 ifname_single = s2.option(widgets.DeviceSelect, 'ifname_single', _('Interface'));
734 ifname_single.noaliases = false;
735 ifname_single.optional = false;
737 ifname_multi = s2.option(widgets.DeviceSelect, 'ifname_multi', _('Interface'));
738 ifname_multi.nobridges = true;
739 ifname_multi.noaliases = true;
740 ifname_multi.multiple = true;
741 ifname_multi.optional = true;
742 ifname_multi.display_size = 6;
744 for (var i = 0; i < protocols.length; i++) {
745 proto.value(protocols[i].getProtocol(), protocols[i].getI18n());
747 if (!protocols[i].isVirtual()) {
748 bridge.depends({ proto: protocols[i].getProtocol() });
749 ifname_single.depends({ type: '', proto: protocols[i].getProtocol() });
750 ifname_multi.depends({ type: 'bridge', proto: protocols[i].getProtocol() });
754 m2.render().then(L.bind(function(nodes) {
755 ui.showModal(_('Add new interface...'), [
757 E('div', { 'class': 'right' }, [
760 'click': ui.hideModal
761 }, _('Cancel')), ' ',
763 'class': 'cbi-button cbi-button-positive important',
764 'click': ui.createHandlerFn(this, function(ev) {
765 var nameval = name.isValid('_new_') ? name.formvalue('_new_') : null,
766 protoval = proto.isValid('_new_') ? proto.formvalue('_new_') : null,
767 protoclass = protoval ? network.getProtocol(protoval) : null;
769 if (nameval == null || protoval == null || nameval == '' || protoval == '')
772 return protoclass.isCreateable(nameval).then(function(checkval) {
773 if (checkval != null) {
774 ui.addNotification(null,
775 E('p', _('New interface for "%s" can not be created: %s').format(protoclass.getI18n(), checkval)));
780 return m.save(function() {
781 var section_id = uci.add('network', 'interface', nameval);
783 uci.set('network', section_id, 'proto', protoval);
785 if (ifname_single.isActive('_new_')) {
786 uci.set('network', section_id, 'ifname', ifname_single.formvalue('_new_'));
788 else if (ifname_multi.isActive('_new_')) {
789 uci.set('network', section_id, 'type', 'bridge');
790 uci.set('network', section_id, 'ifname', L.toArray(ifname_multi.formvalue('_new_')).join(' '));
792 }).then(L.bind(m.children[0].renderMoreOptionsModal, m.children[0], nameval));
796 }, _('Create interface'))
800 nodes.querySelector('[id="%s"] input[type="text"]'.format(name.cbid('_new_'))).focus();
804 s.handleRemove = function(section_id, ev) {
805 return network.deleteNetwork(section_id).then(L.bind(function(section_id, ev) {
806 return form.GridSection.prototype.handleRemove.apply(this, [section_id, ev]);
807 }, this, section_id, ev));
810 o = s.option(form.DummyValue, '_ifacebox');
812 o.textvalue = function(section_id) {
813 var net = this.section.networks.filter(function(n) { return n.getName() == section_id })[0],
814 zone = net ? this.section.zones.filter(function(z) { return !!z.getNetworks().filter(function(n) { return n == section_id })[0] })[0] : null;
819 var node = E('div', { 'class': 'ifacebox' }, [
821 'class': 'ifacebox-head',
822 'style': 'background-color:%s'.format(zone ? zone.getColor() : '#EEEEEE'),
823 'title': zone ? _('Part of zone %q').format(zone.getName()) : _('No zone assigned')
824 }, E('strong', net.getName().toUpperCase())),
826 'class': 'ifacebox-body',
827 'id': '%s-ifc-devices'.format(section_id),
828 'data-network': section_id
831 'src': L.resource('icons/ethernet_disabled.png'),
832 'style': 'width:16px; height:16px'
834 E('br'), E('small', '?')
838 render_ifacebox_status(node.childNodes[1], net);
843 o = s.option(form.DummyValue, '_ifacestat');
845 o.textvalue = function(section_id) {
846 var net = this.section.networks.filter(function(n) { return n.getName() == section_id })[0];
851 var node = E('div', { 'id': '%s-ifc-description'.format(section_id) });
853 render_status(node, net, false);
858 o = s.taboption('advanced', form.Flag, 'delegate', _('Use builtin IPv6-management'));
860 o.default = o.enabled;
862 o = s.taboption('advanced', form.Flag, 'force_link', _('Force link'), _('Set interface properties regardless of the link carrier (If set, carrier sense events do not invoke hotplug handlers).'));
864 o.render = function(option_index, section_id, in_table) {
865 var protoopt = this.section.children.filter(function(o) { return o.option == 'proto' })[0],
866 protoval = protoopt ? protoopt.cfgvalue(section_id) : null;
868 this.default = (protoval == 'static') ? this.enabled : this.disabled;
869 return this.super('render', [ option_index, section_id, in_table ]);
873 s = m.section(form.TypedSection, 'globals', _('Global network options'));
877 o = s.option(form.Value, 'ula_prefix', _('IPv6 ULA-Prefix'));
878 o.datatype = 'cidr6';
880 o = s.option(form.Flag, 'packet_steering', _('Packet Steering'), _('Enable packet steering across all CPUs. May help or hinder network speed.'));
884 if (dslModemType != null) {
885 s = m.section(form.TypedSection, 'dsl', _('DSL'));
888 o = s.option(form.ListValue, 'annex', _('Annex'));
889 o.value('a', _('Annex A + L + M (all)'));
890 o.value('b', _('Annex B (all)'));
891 o.value('j', _('Annex J (all)'));
892 o.value('m', _('Annex M (all)'));
893 o.value('bdmt', _('Annex B G.992.1'));
894 o.value('b2', _('Annex B G.992.3'));
895 o.value('b2p', _('Annex B G.992.5'));
896 o.value('at1', _('ANSI T1.413'));
897 o.value('admt', _('Annex A G.992.1'));
898 o.value('alite', _('Annex A G.992.2'));
899 o.value('a2', _('Annex A G.992.3'));
900 o.value('a2p', _('Annex A G.992.5'));
901 o.value('l', _('Annex L G.992.3 POTS 1'));
902 o.value('m2', _('Annex M G.992.3'));
903 o.value('m2p', _('Annex M G.992.5'));
905 o = s.option(form.ListValue, 'tone', _('Tone'));
906 o.value('', _('auto'));
907 o.value('a', _('A43C + J43 + A43'));
908 o.value('av', _('A43C + J43 + A43 + V43'));
909 o.value('b', _('B43 + B43C'));
910 o.value('bv', _('B43 + B43C + V43'));
912 if (dslModemType == 'vdsl') {
913 o = s.option(form.ListValue, 'xfer_mode', _('Encapsulation mode'));
914 o.value('', _('auto'));
915 o.value('atm', _('ATM (Asynchronous Transfer Mode)'));
916 o.value('ptm', _('PTM/EFM (Packet Transfer Mode)'));
918 o = s.option(form.ListValue, 'line_mode', _('DSL line mode'));
919 o.value('', _('auto'));
920 o.value('adsl', _('ADSL'));
921 o.value('vdsl', _('VDSL'));
923 o = s.option(form.ListValue, 'ds_snr_offset', _('Downstream SNR offset'));
926 for (var i = -100; i <= 100; i += 5)
927 o.value(i, _('%.1f dB').format(i / 10));
930 s.option(form.Value, 'firmware', _('Firmware File'));
934 // Show ATM bridge section if we have the capabilities
935 if (L.hasSystemFeature('br2684ctl')) {
936 s = m.section(form.TypedSection, 'atm-bridge', _('ATM Bridges'), _('ATM bridges expose encapsulated ethernet in AAL5 connections as virtual Linux network interfaces which can be used in conjunction with DHCP or PPP to dial into the provider network.'));
940 s.addbtntitle = _('Add ATM Bridge');
942 s.handleAdd = function(ev) {
943 var sections = uci.sections('network', 'atm-bridge'),
946 for (var i = 0; i < sections.length; i++) {
947 var unit = +sections[i].unit;
949 if (!isNaN(unit) && unit > max_unit)
953 return this.map.save(function() {
954 var sid = uci.add('network', 'atm-bridge');
956 uci.set('network', sid, 'unit', max_unit + 1);
957 uci.set('network', sid, 'atmdev', 0);
958 uci.set('network', sid, 'encaps', 'llc');
959 uci.set('network', sid, 'payload', 'bridged');
960 uci.set('network', sid, 'vci', 35);
961 uci.set('network', sid, 'vpi', 8);
965 s.tab('general', _('General Setup'));
966 s.tab('advanced', _('Advanced Settings'));
968 o = s.taboption('general', form.Value, 'vci', _('ATM Virtual Channel Identifier (VCI)'));
969 s.taboption('general', form.Value, 'vpi', _('ATM Virtual Path Identifier (VPI)'));
971 o = s.taboption('general', form.ListValue, 'encaps', _('Encapsulation mode'));
972 o.value('llc', _('LLC'));
973 o.value('vc', _('VC-Mux'));
975 s.taboption('advanced', form.Value, 'atmdev', _('ATM device number'));
976 s.taboption('advanced', form.Value, 'unit', _('Bridge unit number'));
978 o = s.taboption('advanced', form.ListValue, 'payload', _('Forwarding mode'));
979 o.value('bridged', _('bridged'));
980 o.value('routed', _('routed'));
984 return m.render().then(L.bind(function(m, nodes) {
985 poll.add(L.bind(function() {
986 var section_ids = m.children[0].cfgsections(),
989 for (var i = 0; i < section_ids.length; i++) {
990 var row = nodes.querySelector('.cbi-section-table-row[data-sid="%s"]'.format(section_ids[i])),
991 dsc = row.querySelector('[data-name="_ifacestat"] > div'),
992 btn1 = row.querySelector('.cbi-section-actions .reconnect'),
993 btn2 = row.querySelector('.cbi-section-actions .down');
995 if (dsc.getAttribute('reconnect') == '') {
996 dsc.setAttribute('reconnect', '1');
997 tasks.push(fs.exec('/sbin/ifup', [section_ids[i]]).catch(function(e) {
998 ui.addNotification(null, E('p', e.message));
1001 else if (dsc.getAttribute('disconnect') == '') {
1002 dsc.setAttribute('disconnect', '1');
1003 tasks.push(fs.exec('/sbin/ifdown', [section_ids[i]]).catch(function(e) {
1004 ui.addNotification(null, E('p', e.message));
1007 else if (dsc.getAttribute('reconnect') == '1') {
1008 dsc.removeAttribute('reconnect');
1009 btn1.classList.remove('spinning');
1010 btn1.disabled = false;
1012 else if (dsc.getAttribute('disconnect') == '1') {
1013 dsc.removeAttribute('disconnect');
1014 btn2.classList.remove('spinning');
1015 btn2.disabled = false;
1019 return Promise.all(tasks)
1020 .then(L.bind(network.getNetworks, network))
1021 .then(L.bind(this.poll_status, this, nodes));