Reinstate advanced features to QOS/BWLimiter
[tomato/davidwu.git] / release / src / router / www / qos-qoslimit.asp
blobd20f7691d67bafadcd137d857651852457f00f92
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
4 Copyright (C) 2006-2008 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 Copyright (C) 2011 Deon 'PrinceAMD' Thomas
8 rate limit & connection limit from Conanxu,
9 adapted by Victek, Shibby, PrinceAMD, Phykris
11 For use with Tomato Firmware only.
12 No part of this file may be used without permission.
13 -->
14 <html>
15 <head>
16 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
17 <meta name='robots' content='noindex,nofollow'>
18 <title>[<% ident(); %>] QoS - Bandwidth Limiter</title>
19 <link rel='stylesheet' type='text/css' href='tomato.css'>
20 <link rel='stylesheet' type='text/css' href='color.css'>
21 <script type='text/javascript' src='tomato.js'></script>
23 <!-- / / / -->
24 <style type='text/css'>
25 #qosg-grid {
26 width: 100%;
28 #qosg-grid .co1 {
29 width: 30%;
31 #qosg-grid .co2,
32 #qosg-grid .co3,
33 #qosg-grid .co4,
34 #qosg-grid .co5,
35 #qosg-grid .co6,
36 #qosg-grid .co7,
37 #qosg-grid .co8 {
38 width: 10%;
40 </style>
42 <script type='text/javascript' src='debug.js'></script>
44 <script type='text/javascript'>
45 // <% nvram("qosl_enable,qos_ibw,qos_obw,qosl_rules,lan_ipaddr,lan_netmask,qosl_denable,qosl_dlr,qosl_dlc,qosl_ulr,qosl_ulc,qosl_udp,qosl_tcp"); %>
47 var class_prio = [['0','Highest'],['1','High'],['2','Normal'],['3','Low'],['4','Lowest']];
48 var class_tcp = [['0','nolimit']];
49 var class_udp = [['0','nolimit']];
50 for (var i = 1; i <= 100; ++i) {
51 class_tcp.push([i*10, i*10+'']);
52 class_udp.push([i, i + '/s']);
54 var qosg = new TomatoGrid();
56 qosg.setup = function() {
57 this.init('qosg-grid', '', 80, [
58 { type: 'text', maxlen: 31 },
59 { type: 'text', maxlen: 6 },
60 { type: 'text', maxlen: 6 },
61 { type: 'text', maxlen: 6 },
62 { type: 'text', maxlen: 6 },
63 { type: 'select', options: class_prio },
64 { type: 'select', options: class_tcp },
65 { type: 'select', options: class_udp }]);
66 this.headerSet(['IP | IP Range | MAC Address', 'DLRate', 'DLCeil', 'ULRate', 'ULCeil', 'Priority', 'TCP Limit', 'UDP Limit']);
67 var qoslimitrules = nvram.qosl_rules.split('>');
68 for (var i = 0; i < qoslimitrules.length; ++i) {
69 var t = qoslimitrules[i].split('<');
70 if (t.length == 8) this.insertData(-1, t);
72 this.showNewEditor();
73 this.resetNewEditor();
76 qosg.dataToView = function(data) {
77 return [data[0],data[1]+'kbps',data[2]+'kbps',data[3]+'kbps',data[4]+'kbps',class_prio[data[5]*1][1],class_tcp[data[6]*1/10][1],class_udp[data[7]*1][1]];
80 qosg.resetNewEditor = function() {
81 var f, c, n;
83 var f = fields.getAll(this.newEditor);
84 ferror.clearAll(f);
85 if ((c = cookie.get('addqoslimit')) != null) {
86 cookie.set('addqoslimit', '', 0);
87 c = c.split(',');
88 if (c.length == 2) {
89 f[0].value = c[0];
90 f[1].value = '';
91 f[2].value = '';
92 f[3].value = '';
93 f[4].value = '';
94 f[5].selectedIndex = '2';
95 f[6].selectedIndex = '0';
96 f[7].selectedIndex = '0';
97 return;
101 f[0].value = '';
102 f[1].value = '';
103 f[2].value = '';
104 f[3].value = '';
105 f[4].value = '';
106 f[5].selectedIndex = '2';
107 f[6].selectedIndex = '0';
108 f[7].selectedIndex = '0';
112 qosg.exist = function(f, v)
114 var data = this.getAllData();
115 for (var i = 0; i < data.length; ++i) {
116 if (data[i][f] == v) return true;
118 return false;
121 qosg.existID = function(id)
123 return this.exist(0, id);
126 qosg.existIP = function(ip)
128 if (ip == "0.0.0.0") return true;
129 return this.exist(1, ip);
132 qosg.checkRate = function(rate)
134 var s = parseInt(rate, 10);
135 if( isNaN(s) || s <= 0 || a >= 100000 ) return true;
136 return false;
139 qosg.checkRateCeil = function(rate, ceil)
141 var r = parseInt(rate, 10);
142 var c = parseInt(ceil, 10);
143 if( r > c ) return true;
144 return false;
147 qosg.verifyFields = function(row, quiet)
149 var ok = 1;
150 var f = fields.getAll(row);
151 var s;
154 if (v_ip(f[0], quiet)) {
155 if(this.existIP(f[0].value)) {
156 ferror.set(f[0], 'duplicate IP address', quiet);
157 ok = 0;
161 if(v_macip(f[0], quiet, 0, nvram.lan_ipaddr, nvram.lan_netmask)) {
162 if(this.existIP(f[0].value)) {
163 ferror.set(f[0], 'duplicate IP or MAC address', quiet);
164 ok = 0;
168 if( this.checkRate(f[1].value)) {
169 ferror.set(f[1], 'DLRate must between 1 and 99999', quiet);
170 ok = 0;
173 if( this.checkRate(f[2].value)) {
174 ferror.set(f[2], 'DLCeil must between 1 and 99999', quiet);
175 ok = 0;
178 if( this.checkRateCeil(f[1].value, f[2].value)) {
179 ferror.set(f[2], 'DLCeil must be greater than DLRate', quiet);
180 ok = 0;
183 if( this.checkRate(f[3].value)) {
184 ferror.set(f[3], 'ULRate must between 1 and 99999', quiet);
185 ok = 0;
188 if( this.checkRate(f[4].value)) {
189 ferror.set(f[4], 'ULCeil must between 1 and 99999', quiet);
190 ok = 0;
193 if( this.checkRateCeil(f[3].value, f[4].value)) {
194 ferror.set(f[4], 'ULCeil must be greater than ULRate', quiet);
195 ok = 0;
198 return ok;
201 function verifyFields(focused, quiet)
203 var a = !E('_f_qosl_enable').checked;
204 var b = !E('_f_qosl_denable').checked;
206 E('_qos_ibw').disabled = a;
207 E('_qos_obw').disabled = a;
208 E('_f_qosl_denable').disabled = a;
210 E('_qosl_dlr').disabled = b || a;
211 E('_qosl_dlc').disabled = b || a;
212 E('_qosl_ulr').disabled = b || a;
213 E('_qosl_ulc').disabled = b || a;
214 E('_qosl_tcp').disabled = b || a;
215 E('_qosl_udp').disabled = b || a;
217 elem.display(PR('_qos_ibw'), PR('_qos_obw'), !a);
218 elem.display(PR('_qosl_dlr'), PR('_qosl_dlc'), PR('_qosl_ulr'), PR('_qosl_ulc'), PR('_qosl_tcp'), PR('_qosl_udp'), !a && !b);
220 return 1;
223 function save()
225 if (qosg.isEditing()) return;
227 var data = qosg.getAllData();
228 var qoslimitrules = '';
229 var i;
231 if (data.length != 0) qoslimitrules += data[0].join('<');
232 for (i = 1; i < data.length; ++i) {
233 qoslimitrules += '>' + data[i].join('<');
236 var fom = E('_fom');
237 fom.qosl_enable.value = E('_f_qosl_enable').checked ? 1 : 0;
238 fom.qosl_denable.value = E('_f_qosl_denable').checked ? 1 : 0;
239 fom.qosl_rules.value = qoslimitrules;
240 form.submit(fom, 1);
243 function init()
245 qosg.recolor();
247 </script>
248 </head>
249 <body onload='init()'>
250 <form id='_fom' method='post' action='tomato.cgi'>
251 <table id='container' cellspacing=0>
252 <tr><td colspan=2 id='header'>
253 <div class='title'>Tomato</div>
254 <div class='version'>Version <% version(); %></div>
255 </td></tr>
256 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
257 <td id='content'>
258 <div id='ident'><% ident(); %></div>
260 <!-- / / / -->
262 <input type='hidden' name='_nextpage' value='qos-qoslimit.asp'>
263 <input type='hidden' name='_nextwait' value='10'>
264 <input type='hidden' name='_service' value='qoslimit-restart'>
266 <input type='hidden' name='qosl_enable'>
267 <input type='hidden' name='qosl_rules'>
268 <input type='hidden' name='qosl_denable'>
271 <div id='qoslimit'>
273 <div class='section-title'>Bandwidth Limiter - QOS</div>
274 <div class='section'>
275 <script type='text/javascript'>
276 createFieldTable('', [
277 { title: 'Enable Limiter', name: 'f_qosl_enable', type: 'checkbox', value: nvram.qosl_enable != '0' },
278 { title: 'Max Download Bandwidth <small>(also used by QOS)', name: 'qos_ibw', type: 'text', maxlen: 6, size: 8, suffix: ' <small>kbit/s</small>', value: nvram.qos_ibw },
279 { title: 'Max Upload Bandwidth <small>(also used by QOS)', name: 'qos_obw', type: 'text', maxlen: 6, size: 8, suffix: ' <small>kbit/s</small>', value: nvram.qos_obw }
281 </script>
282 <br>
283 <table class='tomato-grid' id='qosg-grid'></table>
284 <div>
285 <br>
286 <br>
287 <br>
288 <ul>
289 <li><b>IP Address / IP Range</b> - e.g. 192.168.1.5 or 192.168.1.45-57 or 45-57 - A range of IP's will <b>share</b> the bandwidth.<br>
290 </ul>
291 </div>
292 </div>
295 <div class='section-title'>Default Class rate/ceiling for unlisted IP's</div>
296 <div class='section'>
297 <script type='text/javascript'>
298 createFieldTable('', [
299 { title: 'Enable', name: 'f_qosl_denable', type: 'checkbox', value: nvram.qosl_denable == '1'},
300 { title: 'Download rate', name: 'qosl_dlr', type: 'text', maxlen: 6, size: 8, suffix: ' <small>kbit/s</small>', value: nvram.qosl_dlr },
301 { title: 'Download ceil', name: 'qosl_dlc', type: 'text', maxlen: 6, size: 8, suffix: ' <small>kbit/s</small>', value: nvram.qosl_dlc },
302 { title: 'Upload rate', name: 'qosl_ulr', type: 'text', maxlen: 6, size: 8, suffix: ' <small>kbit/s</small>', value: nvram.qosl_ulr },
303 { title: 'Upload ceil', name: 'qosl_ulc', type: 'text', maxlen: 6, size: 8, suffix: ' <small>kbit/s</small>', value: nvram.qosl_ulc },
304 { title: 'TCP Limit', name: 'qosl_tcp', type: 'select', options:
305 [['0', 'no limit'],
306 ['1', '1'],
307 ['2', '2'],
308 ['5', '5'],
309 ['10', '10'],
310 ['20', '20'],
311 ['50', '50'],
312 ['100', '100'],
313 ['200', '200'],
314 ['500', '500'],
315 ['1000', '1000']], value: nvram.qosl_tcp },
316 { title: 'UDP limit', name: 'qosl_udp', type: 'select', options:
317 [['0', 'no limit'],
318 ['1', '1/s'],
319 ['2', '2/s'],
320 ['5', '5/s'],
321 ['10', '10/s'],
322 ['20', '20/s'],
323 ['50', '50/s'],
324 ['100', '100/s']], value: nvram.qosl_udp }
326 </script>
327 <div>
328 <br>
329 <br>
330 <br>
331 <ul>
332 <li><b>Default Class</b> - All clients not included in the list will <b>share</b> the Default Rate/Ceiling setting.
333 </ul>
334 </div>
335 </div>
336 </div>
338 <!-- / / / -->
340 </td></tr>
341 <tr><td id='footer' colspan=2>
342 <span id='footer-msg'></span>
343 <input type='button' value='Save' id='save-button' onclick='save()'>
344 <input type='button' value='Cancel' id='cancel-button' onclick='reloadPage();'>
345 </td></tr>
346 </table>
347 </form>
348 <script type='text/javascript'>qosg.setup(); verifyFields(null, 1);</script>
349 </body>
350 </html>