- this.uci = {
-
- writable: function()
- {
- return _luci2.session.access('ubus', 'uci', 'commit');
- },
-
- add: _luci2.rpc.declare({
- object: 'uci',
- method: 'add',
- params: [ 'config', 'type', 'name', 'values' ],
- expect: { section: '' }
- }),
-
- apply: function()
- {
-
- },
-
- configs: _luci2.rpc.declare({
- object: 'uci',
- method: 'configs',
- expect: { configs: [ ] }
- }),
-
- _changes: _luci2.rpc.declare({
- object: 'uci',
- method: 'changes',
- params: [ 'config' ],
- expect: { changes: [ ] }
- }),
-
- changes: function(config)
- {
- if (typeof(config) == 'string')
- return this._changes(config);
-
- var configlist;
- return this.configs().then(function(configs) {
- _luci2.rpc.batch();
- configlist = configs;
-
- for (var i = 0; i < configs.length; i++)
- _luci2.uci._changes(configs[i]);
-
- return _luci2.rpc.flush();
- }).then(function(changes) {
- var rv = { };
-
- for (var i = 0; i < configlist.length; i++)
- if (changes[i].length)
- rv[configlist[i]] = changes[i];
-
- return rv;
- });
- },
-
- commit: _luci2.rpc.declare({
- object: 'uci',
- method: 'commit',
- params: [ 'config' ]
- }),
-
- _delete_one: _luci2.rpc.declare({
- object: 'uci',
- method: 'delete',
- params: [ 'config', 'section', 'option' ]
- }),
-
- _delete_multiple: _luci2.rpc.declare({
- object: 'uci',
- method: 'delete',
- params: [ 'config', 'section', 'options' ]
- }),
-
- 'delete': function(config, section, option)
- {
- if ($.isArray(option))
- return this._delete_multiple(config, section, option);
- else
- return this._delete_one(config, section, option);
- },
-
- delete_all: _luci2.rpc.declare({
- object: 'uci',
- method: 'delete',
- params: [ 'config', 'type', 'match' ]
- }),
-
- _foreach: _luci2.rpc.declare({
- object: 'uci',
- method: 'get',
- params: [ 'config', 'type' ],
- expect: { values: { } }
- }),
-
- foreach: function(config, type, cb)
- {
- return this._foreach(config, type).then(function(sections) {
- for (var s in sections)
- cb(sections[s]);
- });
- },
-
- get: _luci2.rpc.declare({
- object: 'uci',
- method: 'get',
- params: [ 'config', 'section', 'option' ],
- expect: { '': { } },
- filter: function(data, params) {
- if (typeof(params.option) == 'undefined')
- return data.values ? data.values['.type'] : undefined;
- else
- return data.value;
- }
- }),
-
- get_all: _luci2.rpc.declare({
- object: 'uci',
- method: 'get',
- params: [ 'config', 'section' ],
- expect: { values: { } },
- filter: function(data, params) {
- if (typeof(params.section) == 'string')
- data['.section'] = params.section;
- else if (typeof(params.config) == 'string')
- data['.package'] = params.config;
- return data;
- }
- }),
-
- get_first: function(config, type, option)
- {
- return this._foreach(config, type).then(function(sections) {
- for (var s in sections)
- {
- var val = (typeof(option) == 'string') ? sections[s][option] : sections[s]['.name'];
-
- if (typeof(val) != 'undefined')
- return val;
- }
-
- return undefined;
- });
- },
-
- section: _luci2.rpc.declare({
- object: 'uci',
- method: 'add',
- params: [ 'config', 'type', 'name', 'values' ],
- expect: { section: '' }
- }),
-
- _set: _luci2.rpc.declare({
- object: 'uci',
- method: 'set',
- params: [ 'config', 'section', 'values' ]
- }),
-
- set: function(config, section, option, value)
- {
- if (typeof(value) == 'undefined' && typeof(option) == 'string')
- return this.section(config, section, option); /* option -> type */
- else if ($.isPlainObject(option))
- return this._set(config, section, option); /* option -> values */
-
- var values = { };
- values[option] = value;
-
- return this._set(config, section, values);
- },
-
- order: _luci2.rpc.declare({
- object: 'uci',
- method: 'order',
- params: [ 'config', 'sections' ]
- })
- };
-
- this.network = {
- listNetworkNames: function() {
- return _luci2.rpc.list('network.interface.*').then(function(list) {
- var names = [ ];
- for (var name in list)
- if (name != 'network.interface.loopback')
- names.push(name.substring(18));
- names.sort();
- return names;
- });
- },
-
- listDeviceNames: _luci2.rpc.declare({
- object: 'network.device',
- method: 'status',
- expect: { '': { } },
- filter: function(data) {
- var names = [ ];
- for (var name in data)
- if (name != 'lo')
- names.push(name);
- names.sort();
- return names;
- }
- }),
-
- getNetworkStatus: function()
- {
- var nets = [ ];
- var devs = { };
-
- return this.listNetworkNames().then(function(names) {
- _luci2.rpc.batch();
-
- for (var i = 0; i < names.length; i++)
- _luci2.network.getInterfaceStatus(names[i]);
-
- return _luci2.rpc.flush();
- }).then(function(networks) {
- for (var i = 0; i < networks.length; i++)
- {
- var net = nets[i] = networks[i];
- var dev = net.l3_device || net.l2_device;
- if (dev)
- net.device = devs[dev] || (devs[dev] = { });
- }
-
- _luci2.rpc.batch();
-
- for (var dev in devs)
- _luci2.network.getDeviceStatus(dev);
-
- return _luci2.rpc.flush();
- }).then(function(devices) {
- _luci2.rpc.batch();
-
- for (var i = 0; i < devices.length; i++)
- {
- var brm = devices[i]['bridge-members'];
- delete devices[i]['bridge-members'];
-
- $.extend(devs[devices[i]['device']], devices[i]);
-
- if (!brm)
- continue;
-
- devs[devices[i]['device']].subdevices = [ ];
-
- for (var j = 0; j < brm.length; j++)
- {
- if (!devs[brm[j]])
- {
- devs[brm[j]] = { };
- _luci2.network.getDeviceStatus(brm[j]);
- }
-
- devs[devices[i]['device']].subdevices[j] = devs[brm[j]];
- }
- }
-
- return _luci2.rpc.flush();
- }).then(function(subdevices) {
- for (var i = 0; i < subdevices.length; i++)
- $.extend(devs[subdevices[i]['device']], subdevices[i]);
-
- _luci2.rpc.batch();
-
- for (var dev in devs)
- _luci2.wireless.getDeviceStatus(dev);
-
- return _luci2.rpc.flush();
- }).then(function(wifidevices) {
- for (var i = 0; i < wifidevices.length; i++)
- if (wifidevices[i])
- devs[wifidevices[i]['device']].wireless = wifidevices[i];
-
- nets.sort(function(a, b) {
- if (a['interface'] < b['interface'])
- return -1;
- else if (a['interface'] > b['interface'])
- return 1;
- else
- return 0;
- });
-
- return nets;
- });
- },
-
- findWanInterfaces: function(cb)
- {
- return this.listNetworkNames().then(function(names) {
- _luci2.rpc.batch();
-
- for (var i = 0; i < names.length; i++)
- _luci2.network.getInterfaceStatus(names[i]);
-
- return _luci2.rpc.flush();
- }).then(function(interfaces) {
- var rv = [ undefined, undefined ];
-
- for (var i = 0; i < interfaces.length; i++)
- {
- if (!interfaces[i].route)
- continue;
-
- for (var j = 0; j < interfaces[i].route.length; j++)
- {
- var rt = interfaces[i].route[j];
-
- if (typeof(rt.table) != 'undefined')
- continue;
-
- if (rt.target == '0.0.0.0' && rt.mask == 0)
- rv[0] = interfaces[i];
- else if (rt.target == '::' && rt.mask == 0)
- rv[1] = interfaces[i];
- }
- }
-
- return rv;
- });
- },
-
- getDHCPLeases: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'dhcp_leases',
- expect: { leases: [ ] }
- }),
-
- getDHCPv6Leases: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'dhcp6_leases',
- expect: { leases: [ ] }
- }),
-
- getRoutes: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'routes',
- expect: { routes: [ ] }
- }),
-
- getIPv6Routes: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'routes',
- expect: { routes: [ ] }
- }),
-
- getARPTable: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'arp_table',
- expect: { entries: [ ] }
- }),
-
- getInterfaceStatus: _luci2.rpc.declare({
- object: 'network.interface',
- method: 'status',
- params: [ 'interface' ],
- expect: { '': { } },
- filter: function(data, params) {
- data['interface'] = params['interface'];
- data['l2_device'] = data['device'];
- delete data['device'];
- return data;
- }
- }),
-
- getDeviceStatus: _luci2.rpc.declare({
- object: 'network.device',
- method: 'status',
- params: [ 'name' ],
- expect: { '': { } },
- filter: function(data, params) {
- data['device'] = params['name'];
- return data;
- }
- }),
-
- getConntrackCount: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'conntrack_count',
- expect: { '': { count: 0, limit: 0 } }
- }),
-
- listSwitchNames: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'switch_list',
- expect: { switches: [ ] }
- }),
-
- getSwitchInfo: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'switch_info',
- params: [ 'switch' ],
- expect: { info: { } },
- filter: function(data, params) {
- data['attrs'] = data['switch'];
- data['vlan_attrs'] = data['vlan'];
- data['port_attrs'] = data['port'];
- data['switch'] = params['switch'];
-
- delete data.vlan;
- delete data.port;
-
- return data;
- }
- }),
-
- getSwitchStatus: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'switch_status',
- params: [ 'switch' ],
- expect: { ports: [ ] }
- }),
-
-
- runPing: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'ping',
- params: [ 'data' ],
- expect: { '': { code: -1 } }
- }),
-
- runPing6: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'ping6',
- params: [ 'data' ],
- expect: { '': { code: -1 } }
- }),
-
- runTraceroute: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'traceroute',
- params: [ 'data' ],
- expect: { '': { code: -1 } }
- }),
-
- runTraceroute6: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'traceroute6',
- params: [ 'data' ],
- expect: { '': { code: -1 } }
- }),
-
- runNslookup: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'nslookup',
- params: [ 'data' ],
- expect: { '': { code: -1 } }
- }),
-
-
- setUp: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'ifup',
- params: [ 'data' ],
- expect: { '': { code: -1 } }
- }),
-
- setDown: _luci2.rpc.declare({
- object: 'luci2.network',
- method: 'ifdown',
- params: [ 'data' ],
- expect: { '': { code: -1 } }
- })
- };