treewide: transition div tables to actual table markup
[project/luci.git] / applications / luci-app-upnp / htdocs / luci-static / resources / view / upnp / upnp.js
1 'use strict';
2 'require view';
3 'require dom';
4 'require poll';
5 'require uci';
6 'require rpc';
7 'require form';
8
9 var callInitAction, callUpnpGetStatus, callUpnpDeleteRule, handleDelRule;
10
11 callInitAction = rpc.declare({
12 object: 'luci',
13 method: 'setInitAction',
14 params: [ 'name', 'action' ],
15 expect: { result: false }
16 });
17
18 callUpnpGetStatus = rpc.declare({
19 object: 'luci.upnp',
20 method: 'get_status',
21 expect: { }
22 });
23
24 callUpnpDeleteRule = rpc.declare({
25 object: 'luci.upnp',
26 method: 'delete_rule',
27 params: [ 'token' ],
28 expect: { result : "OK" },
29 });
30
31 handleDelRule = function(num, ev) {
32 dom.parent(ev.currentTarget, '.tr').style.opacity = 0.5;
33 ev.currentTarget.classList.add('spinning');
34 ev.currentTarget.disabled = true;
35 ev.currentTarget.blur();
36 callUpnpDeleteRule(num);
37 };
38
39 return view.extend({
40 load: function() {
41 return Promise.all([
42 callUpnpGetStatus(),
43 uci.load('upnpd')
44 ]);
45 },
46
47 poll_status: function(nodes, data) {
48
49 var rules = Array.isArray(data[0].rules) ? data[0].rules : [];
50
51 var rows = rules.map(function(rule) {
52 return [
53 rule.proto,
54 rule.extport,
55 rule.intaddr,
56 rule.host_hint || _('Unknown'),
57 rule.intport,
58 rule.descr,
59 E('button', {
60 'class': 'btn cbi-button-remove',
61 'click': L.bind(handleDelRule, this, rule.num)
62 }, [ _('Delete') ])
63 ];
64 });
65
66 cbi_update_table(nodes.querySelector('#upnp_status_table'), rows, E('em', _('There are no active redirects.')));
67
68 return;
69 },
70
71 render: function(data) {
72
73 var m, s, o;
74
75 m = new form.Map('upnpd', [_('Universal Plug & Play')],
76 _('UPnP allows clients in the local network to automatically configure the router.'));
77
78 s = m.section(form.GridSection, '_active_rules');
79
80 s.render = L.bind(function(view, section_id) {
81 var table = E('table', { 'class': 'table cbi-section-table', 'id': 'upnp_status_table' }, [
82 E('tr', { 'class': 'tr table-titles' }, [
83 E('th', { 'class': 'th' }, _('Protocol')),
84 E('th', { 'class': 'th' }, _('External Port')),
85 E('th', { 'class': 'th' }, _('Client Address')),
86 E('th', { 'class': 'th' }, _('Host')),
87 E('th', { 'class': 'th' }, _('Client Port')),
88 E('th', { 'class': 'th' }, _('Description')),
89 E('th', { 'class': 'th cbi-section-actions' }, '')
90 ])
91 ]);
92
93 var rules = Array.isArray(data[0].rules) ? data[0].rules : [];
94
95 var rows = rules.map(function(rule) {
96 return [
97 rule.proto,
98 rule.extport,
99 rule.intaddr,
100 rule.host_hint || _('Unknown'),
101 rule.intport,
102 rule.descr,
103 E('button', {
104 'class': 'btn cbi-button-remove',
105 'click': L.bind(handleDelRule, this, rule.num)
106 }, [ _('Delete') ])
107 ];
108 });
109
110 cbi_update_table(table, rows, E('em', _('There are no active redirects.')));
111
112 return E('div', { 'class': 'cbi-section cbi-tblsection' }, [
113 E('h3', _('Active UPnP Redirects')), table ]);
114 }, o, this);
115
116 s = m.section(form.NamedSection, 'config', 'upnpd', _('MiniUPnP settings'));
117 s.addremove = false;
118 s.tab('general', _('General Settings'));
119 s.tab('advanced', _('Advanced Settings'));
120
121 o = s.taboption('general', form.Flag, 'enabled', _('Start UPnP and NAT-PMP service'));
122 o.rmempty = false;
123
124 s.taboption('general', form.Flag, 'enable_upnp', _('Enable UPnP functionality')).default = '1'
125 s.taboption('general', form.Flag, 'enable_natpmp', _('Enable NAT-PMP functionality')).default = '1'
126
127 s.taboption('general', form.Flag, 'secure_mode', _('Enable secure mode'),
128 _('Allow adding forwards only to requesting ip addresses')).default = '1'
129
130 s.taboption('general', form.Flag, 'igdv1', _('Enable IGDv1 mode'),
131 _('Advertise as IGDv1 device instead of IGDv2')).default = '0'
132
133 s.taboption('general', form.Flag, 'log_output', _('Enable additional logging'),
134 _('Puts extra debugging information into the system log'))
135
136 s.taboption('general', form.Value, 'download', _('Downlink'),
137 _('Value in KByte/s, informational only')).rmempty = true
138
139 s.taboption('general', form.Value, 'upload', _('Uplink'),
140 _('Value in KByte/s, informational only')).rmempty = true
141
142 o = s.taboption('general', form.Value, 'port', _('Port'))
143 o.datatype = 'port'
144 o.default = 5000
145
146 s.taboption('advanced', form.Flag, 'system_uptime', _('Report system instead of daemon uptime')).default = '1'
147
148 s.taboption('advanced', form.Value, 'uuid', _('Device UUID'))
149 s.taboption('advanced', form.Value, 'serial_number', _('Announced serial number'))
150 s.taboption('advanced', form.Value, 'model_number', _('Announced model number'))
151
152 o = s.taboption('advanced', form.Value, 'notify_interval', _('Notify interval'))
153 o.datatype = 'uinteger'
154 o.placeholder = 30
155
156 o = s.taboption('advanced', form.Value, 'clean_ruleset_threshold', _('Clean rules threshold'))
157 o.datatype = 'uinteger'
158 o.placeholder = 20
159
160 o = s.taboption('advanced', form.Value, 'clean_ruleset_interval', _('Clean rules interval'))
161 o.datatype = 'uinteger'
162 o.placeholder = 600
163
164 o = s.taboption('advanced', form.Value, 'presentation_url', _('Presentation URL'))
165 o.placeholder = 'http://192.168.1.1/'
166
167 o = s.taboption('advanced', form.Value, 'upnp_lease_file', _('UPnP lease file'))
168 o.placeholder = '/var/run/miniupnpd.leases'
169
170 s.taboption('advanced', form.Flag, 'use_stun', _('Use STUN'))
171
172 o = s.taboption('advanced', form.Value, 'stun_host', _('STUN Host'))
173 o.depends('use_stun', '1');
174 o.datatype = 'host'
175
176 o = s.taboption('advanced', form.Value, 'stun_port', _('STUN Port'))
177 o.depends('use_stun', '1');
178 o.datatype = 'port'
179 o.placeholder = '0-65535'
180
181 s = m.section(form.GridSection, 'perm_rule', _('MiniUPnP ACLs'),
182 _('ACLs specify which external ports may be redirected to which internal addresses and ports'))
183
184 s.sortable = true
185 s.anonymous = true
186 s.addremove = true
187
188 s.option(form.Value, 'comment', _('Comment'))
189
190 o = s.option(form.Value, 'ext_ports', _('External ports'))
191 o.datatype = 'portrange'
192 o.placeholder = '0-65535'
193
194 o = s.option(form.Value, 'int_addr', _('Internal addresses'))
195 o.datatype = 'ip4addr'
196 o.placeholder = '0.0.0.0/0'
197
198 o = s.option(form.Value, 'int_ports', _('Internal ports'))
199 o.datatype = 'portrange'
200 o.placeholder = '0-65535'
201
202 o = s.option(form.ListValue, 'action', _('Action'))
203 o.value('allow')
204 o.value('deny')
205
206 return m.render().then(L.bind(function(m, nodes) {
207 poll.add(L.bind(function() {
208 return Promise.all([
209 callUpnpGetStatus()
210 ]).then(L.bind(this.poll_status, this, nodes));
211 }, this), 5);
212 return nodes;
213 }, this, m));
214 }
215 });