summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-qos/htdocs/luci-static/resources/view/qos/qos.js
blob: 7fe08484d4f770cb6f8bac113e9c043dfafa8637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
'require form';
'require network';
'require rpc';
'require tools.widgets as widgets';
'require view';

var callHostHints = rpc.declare({
	object: 'luci-rpc',
	method: 'getHostHints',
	expect: { '': {} }
});

return view.extend({
	load: function() {
		return Promise.all([
			network.getNetworks(),
			callHostHints(),
		]);
	},

	render: function (loaded_promises) {
		var m, s, o;
		const networks = loaded_promises[0];
		const hosts = loaded_promises[1];

		m = new form.Map('qos', _('Quality of Service'),
			_('With %s you can prioritize network traffic selected by addresses, ports or services.'.format('<abbr title=\"Quality of Service\">QoS</abbr>')));

		s = m.section(form.TypedSection, 'interface', _('Interfaces'));
		s.anonymous = false;
		s.addremove = true;

		o = s.option(form.Flag, 'enabled', _('Enable'));

		o = s.option(form.ListValue, 'classgroup', _('Classification group'));
		o.placeholder = 'Default';
		o.value('Default', _('default'));
		o.rmempty = true;
		o.depends({ enabled: '1' });

		o = s.option(form.Flag, 'overhead', _('Calculate overhead'));
		o.depends({ enabled: '1' });

		o = s.option(form.Flag, 'halfduplex', _('Half-duplex'));
		o.depends({ enabled: '1' });

		o = s.option(form.Value, 'download', _('Download speed (kbit/s)'));
		o.rmempty = true;
		o.placeholder = 1024;
		o.datatype = 'and(uinteger,min(1))';
		o.depends({ enabled: '1' });

		o = s.option(form.Value, 'upload', _('Upload speed (kbit/s)'));
		o.rmempty = true;
		o.placeholder = 128;
		o.datatype = 'and(uinteger,min(1))';
		o.depends({ enabled: '1' });

		s = m.section(form.TableSection, 'classify', _('Classification Rules'));
		s.anonymous = true;
		s.addremove = true;
		s.sortable  = true;
		s.rowcolors = true;
		s.nodescriptions = true;

		o = s.option(form.ListValue, 'target', _('Target'));
		o.value('Priority', _('priority'));
		o.value('Express', _('express'));
		o.value('Normal', _('normal'));
		o.value('Low', _('low'));

		Object.values(L.uci.sections('qos', 'class')).forEach(function(val, index) {
			const n = val['.name'];
			if (!n.endsWith('_down'))
				o.value(n);
		});

		var ipaddrs = {};
		Object.keys(hosts).forEach(function(mac) {
			L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4).forEach(function(ip) {
				ipaddrs[ip] = mac;
			});

			L.toArray(hosts[mac].ip6addrs || hosts[mac].ipv6).forEach(function(ip) {
				ipaddrs[ip] = mac;
			});
		});

		o = s.option(form.Value, 'srchost', _('Source host'));
		o.rmempty = true;
		o.width = '15%';
		o.datatype = 'ipaddr';
		o.value('', _('all'));
		L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ipv4) {
			o.value(ipv4, '%s (%s)'.format(ipv4, ipaddrs[ipv4]));
		});

		o = s.option(form.Value, 'dsthost', _('Destination host'));
		o.rmempty = true;
		o.width = '15%';
		o.datatype = 'ipaddr';
		o.value('', _('all'));
		L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ipv4) {
			o.value(ipv4, '%s (%s)'.format(ipv4, ipaddrs[ipv4]));
		});

		o = s.option(form.Value, 'proto', _('Protocol'));
		o.rmempty = true;
		o.width = '15%';
		o.value('', _('all'));
		o.value('tcp');
		o.value('udp');
		o.value('icmp');

		o = s.option(form.Value, 'ports', _('Ports'));
		o.rmempty = true;
		o.width = '15%';
		o.value('', _('all'));
		o.validate = function(section, value) {
			if (!value) return true

			const valuesArray = value.split(',').map(v => v.trim());

			return valuesArray.every(v => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) < 65536);
		};

		o = s.option(form.Value, 'connbytes', _('Number of bytes'));
		o.datatype = 'uinteger';
		o.width = '5%';

		o = s.option(form.Value, 'comment', _('Comment'));
		o.rmempty = true;

		return m.render();
	}
});