Guest User

Old Tomato qos-classify.asp

a guest
Sep 8th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
  2. <!--
  3. Tomato GUI
  4. Copyright (C) 2006-2010 Jonathan Zarate
  5. http://www.polarcloud.com/tomato/
  6. For use with Tomato Firmware only.
  7. No part of this file may be used without permission.
  8. -->
  9. <html>
  10. <head>
  11. <meta http-equiv='content-type' content='text/html;charset=utf-8'>
  12. <meta name='robots' content='noindex,nofollow'>
  13. <title>[<% ident(); %>] QoS: Classification</title>
  14. <link rel='stylesheet' type='text/css' href='tomato.css'>
  15. <% css(); %>
  16. <script type='text/javascript' src='tomato.js'></script>
  17. <script type='text/javascript' src='protocols.js'></script>
  18. <style type='text/css'>
  19. #qg div {
  20. padding: 0 0 1px 0;
  21. margin: 0;
  22. }
  23. #qg .co1 {
  24. width: 370px;
  25. }
  26. #qg .co2 {
  27. width: 80px;
  28. }
  29. #qg .co3 {
  30. width: 300px;
  31. }
  32. #qg .co4 {
  33. width: 40px;
  34. }
  35. #qg .x1a {
  36. width: 34%;
  37. float: left;
  38. }
  39. #qg .x1b {
  40. width: 66%;
  41. float: left;
  42. }
  43. #qg .x2a {
  44. width: 35%;
  45. float: left;
  46. clear: left;
  47. }
  48. #qg .x2b {
  49. width: 23%;
  50. float: left;
  51. }
  52. #qg .x2c {
  53. width: 41%;
  54. float: left;
  55. }
  56. #qg .x3a {
  57. width: 40%;
  58. float: left;
  59. clear: left;
  60. }
  61. #qg .x3b {
  62. width: 60%;
  63. float: left;
  64. }
  65. #qg .x4a {
  66. width: 58%;
  67. float: left;
  68. clear: left;
  69. }
  70. #qg .x4b {
  71. width: 41%;
  72. float: left;
  73. }
  74. #qg .x5a {
  75. float: left;
  76. clear: left;
  77. width: 70px;
  78. }
  79. #qg .x5b {
  80. float: left;
  81. padding: 2px 8px 0 8px;
  82. width: 10px;
  83. text-align: center;
  84. }
  85. #qg .x5c {
  86. float: left;
  87. width: 70px;
  88. }
  89. #qg .x5d {
  90. float: left;
  91. padding: 2px 0 0 8px;
  92. width: 100px;
  93. }
  94. </style>
  95. <script type='text/javascript'>
  96. //  <% nvram("qos_classnames,qos_enable,qos_orules"); %>
  97. var abc = nvram.qos_classnames.split(' ');      // Toastman - configurable class names
  98. var ipp2p = [
  99. [0,'IPP2P (disabled)'],[0xFFF,'All IPP2P filters'],[1,'AppleJuice'],[2,'Ares'],[4,'BitTorrent'],[8,'Direct Connect'],
  100. [16,'eDonkey'],[32,'Gnutella'],[64,'Kazaa'],[128,'Mute'],[256,'SoulSeek'],[512,'Waste'],[1024,'WinMX'],[2048,'XDCC']];
  101. var dscp = [
  102. ['','DSCP (any)'],['0x00','BE'],
  103. ['0x08','CS1'],['0x10','CS2'],['0x18','CS3'],['0x20','CS4'],['0x28','CS5'],['0x30','CS6'],['0x38','CS7'],
  104. ['0x0a','AF11'],['0x0c','AF12'],['0x0e','AF13'],['0x12','AF21'],['0x14','AF22'],['0x16','AF23'],
  105. ['0x1a','AF31'],['0x1c','AF32'],['0x1e','AF33'],['0x22','AF41'],['0x24','AF42'],['0x26','AF43'],
  106. ['0x2e','EF'],['*','DSCP value']];
  107. for (i = 1; i < dscp.length - 1; ++i)
  108. dscp[i][1] = 'DSCP Class ' + dscp[i][1];
  109. // <% layer7(); %>
  110. layer7.sort();
  111. for (i = 0; i < layer7.length; ++i)
  112. layer7[i] = [layer7[i],layer7[i]];
  113. layer7.unshift(['', 'Layer 7 (disabled)']);
  114. var class1 = [[-1,'Disabled']];
  115. for (i = 0; i < 10; ++i) class1.push([i, abc[i]]);
  116. var class2 = class1.slice(1);
  117. var ruleCounter = 0;
  118. var qosg = new TomatoGrid();
  119. function dscpClass(v)
  120. {
  121. var s, i;
  122. s = '';
  123. if (v != '') {
  124. for (i = 1; i < dscp.length - 1; ++i)   // skip 1st and last elements
  125. if (dscp[i][0] * 1 == v * 1) {
  126. s = dscp[i][1];
  127. break;
  128. }
  129. }
  130. return s;
  131. }
  132. qosg.dataToView = function(data) {
  133. var b = [];
  134. var s, i;
  135. if (data[0] != 0) {
  136. b.push(((data[0] == 1) ? 'To ' : 'From ') + data[1]);
  137. }
  138. if (data[2] >= -1) {
  139. if (data[2] == -1) b.push('TCP/UDP');
  140. else if (data[2] >= 0) b.push(protocols[data[2]] || data[2]);
  141. if (data[3] != 'a') {
  142. if (data[3] == 'd') s = 'Dst ';
  143. else if (data[3] == 's') s = 'Src ';
  144. else s = '';
  145. b.push(s + 'Port: ' + data[4].replace(/:/g, '-'));
  146. }
  147. }
  148. if (data[5] != 0) {
  149. for (i = 0; i < ipp2p.length; ++i)
  150. if (ipp2p[i][0] == data[5]) {
  151. b.push('IPP2P: ' + ipp2p[i][1]);
  152. break;
  153. }
  154. }
  155. else if (data[6] != '') {
  156. b.push('L7: ' + data[6])
  157. }
  158. if (data[9] != '') {
  159. s = dscpClass(data[9]);
  160. if (s != '') b.push(s);
  161. else b.push('DSCP Value: ' + data[9]);
  162. }
  163. if (data[7] != '') {
  164. b.push('Transferred: ' + data[7] + ((data[8] == '') ? '<small>KB+</small>' : (' - ' + data[8] + '<small>KB</small>')));
  165. }
  166. return [b.join('<br>'), class1[(data[10] * 1) + 1][1], escapeHTML(data[11]), (ruleCounter >= 0) ? ''+ ++ruleCounter : ''];
  167. }
  168. qosg.fieldValuesToData = function(row) {
  169. var f = fields.getAll(row);
  170. var proto = f[2].value;
  171. var dir = f[3].value;
  172. var vdscp = (f[7].value == '*') ? f[8].value : f[7].value;
  173. if ((proto != -1) && (proto != 6) && (proto != 17)) dir = 'a';
  174. return [f[0].value, f[0].selectedIndex ? f[1].value : '',
  175. proto, dir, (dir != 'a') ? f[4].value : '',
  176. f[5].value, f[6].value, f[9].value, f[10].value,
  177. vdscp, f[11].value, f[12].value];
  178. }
  179. qosg.dataToFieldValues = function(data) {
  180. var s = '';
  181. if (data[9] != '') {
  182. if (dscpClass(data[9]) == '') s = '*';
  183. else s = data[9].toLowerCase();
  184. }
  185. return [data[0], data[1], data[2], data[3], data[4], data[5], data[6], s, data[9], data[7], data[8], data[10], data[11]];
  186. }
  187. qosg.resetNewEditor = function() {
  188. var f = fields.getAll(this.newEditor);
  189. f[0].selectedIndex = 0;
  190. f[1].value = '';
  191. f[2].selectedIndex = 1;
  192. f[3].selectedIndex = 0;
  193. f[4].value = '';
  194. f[5].selectedIndex = 0;
  195. f[6].selectedIndex = 0;
  196. f[7].selectedIndex = 0;
  197. f[8].value = '';
  198. f[9].value = '';
  199. f[10].value = '';
  200. f[11].selectedIndex = 5;
  201. f[12].value = '';
  202. this.enDiFields(this.newEditor);
  203. ferror.clearAll(fields.getAll(this.newEditor));
  204. }
  205. qosg._disableNewEditor = qosg.disableNewEditor;
  206. qosg.disableNewEditor = function(disable) {
  207. qosg._disableNewEditor(disable);
  208. if (!disable) {
  209. this.enDiFields(this.newEditor);
  210. }
  211. }
  212. qosg.enDiFields = function(row) {
  213. var f = fields.getAll(row);
  214. var x;
  215. f[1].disabled = (f[0].selectedIndex == 0);
  216. x = f[2].value;
  217. x = ((x != -1) && (x != 6) && (x != 17));
  218. f[3].disabled = x;
  219. if (f[3].selectedIndex == 0) x = 1;
  220. f[4].disabled = x;
  221. f[6].disabled = (f[5].selectedIndex != 0);
  222. f[5].disabled = (f[6].selectedIndex != 0);
  223. f[8].disabled = (f[7].value != '*');
  224. }
  225. function v_dscp(e, quiet)
  226. {
  227. if ((e = E(e)) == null) return 0;
  228. var v = e.value;
  229. if ((!v.match(/^ *(0x)?[0-9A-Fa-f]+ *$/)) || (v < 0) || (v > 63)) {
  230. ferror.set(e, 'Invalid DSCP value. Valid range: 0x00-0x3F', quiet);
  231. return 0;
  232. }
  233. e.value = '0x' + (v * 1).hex(2);
  234. ferror.clear(e);
  235. return 1;
  236. }
  237. qosg.verifyFields = function(row, quiet) {
  238. var f = fields.getAll(row);
  239. var a, b, e;
  240. this.enDiFields(row);
  241. ferror.clearAll(f);
  242. a = f[0].value * 1;
  243. if ((a == 1) || (a == 2)) {
  244. if (!v_length(f[1], quiet, 1)) return 0;
  245. if (!_v_iptaddr(f[1], quiet, 0, 1, 1)) return 0;
  246. }
  247. else if ((a == 3) && (!v_mac(f[1], quiet))) return 0;
  248. b = f[2].selectedIndex;
  249. if ((b > 0) && (b <= 3) && (f[3].selectedIndex != 0) && (!v_iptport(f[4], quiet))) return 0;
  250. var BMAX = 1024 * 1024;
  251. e = f[9];
  252. a = e.value = e.value.trim();
  253. if (a != '') {
  254. if (!v_range(e, quiet, 0, BMAX)) return 0;
  255. a *= 1;
  256. }
  257. e = f[10];
  258. b = e.value = e.value.trim();
  259. if (b != '') {
  260. b *= 1;
  261. if (b >= BMAX) e.value = '';
  262. else if (!v_range(e, quiet, 0, BMAX)) return 0;
  263. if (a == '') f[9].value = a = 0;
  264. }
  265. else if (a != '') {
  266. b = BMAX;
  267. }
  268. if ((b != '') && (a >= b)) {
  269. ferror.set(f[9], 'Invalid range', quiet);
  270. return 0;
  271. }
  272. if (f[7].value == '*') {
  273. if (!v_dscp(f[8], quiet)) return 0;
  274. }
  275. else f[8].value = f[7].value;
  276. if (!v_nodelim(f[12], quiet, 'Description', 1)) return 0;
  277. return v_length(f[12], quiet);
  278. }
  279. qosg.setup = function() {
  280. var i, a, b;
  281. a = [[-2, 'Any Protocol'],[-1,'TCP/UDP'],[6,'TCP'],[17,'UDP']];
  282. for (i = 0; i < 256; ++i) {
  283. if ((i != 6) && (i != 17)) a.push([i, protocols[i] || i]);
  284. }
  285. // what a mess...
  286. this.init('qg', 'move', 100, [
  287. { multi: [
  288. { type: 'select', options: [[0,'Any Address'],[1,'Dst IP'],[2,'Src IP'],[3,'Src MAC']],
  289. prefix: '<div class="x1a">', suffix: '</div>' },
  290. { type: 'text', prefix: '<div class="x1b">', suffix: '</div>' },
  291. { type: 'select', prefix: '<div class="x2a">', suffix: '</div>', options: a },
  292. { type: 'select', prefix: '<div class="x2b">', suffix: '</div>',
  293. options: [['a','Any Port'],['d','Dst Port'],['s','Src Port'],['x','Src or Dst']] },
  294. { type: 'text', prefix: '<div class="x2c">', suffix: '</div>' },
  295. { type: 'select', prefix: '<div class="x3a">', suffix: '</div>', options: ipp2p },
  296. { type: 'select', prefix: '<div class="x3b">', suffix: '</div>', options: layer7 },
  297. { type: 'select', prefix: '<div class="x4a">', suffix: '</div>', options: dscp },
  298. { type: 'text', prefix: '<div class="x4b">', suffix: '</div>' },
  299. { type: 'text', prefix: '<div class="x5a">', suffix: '</div>' },
  300. { type: 'text', prefix: '<div class="x5b"> - </div><div class="x5c">', suffix: '</div><div class="x5d">KB Transferred</div>' }
  301. ] },
  302. { type: 'select', options: class1, vtop: 1 },
  303. { type: 'text', maxlen: 32, vtop: 1 }
  304. ]);
  305. this.headerSet(['Match Rule', 'Class', 'Description', '#']);
  306. // addr_type < addr < proto < port_type < port < ipp2p < L7 < bcount < dscp < class < desc
  307. a = nvram.qos_orules.split('>');
  308. for (i = 0; i < a.length; ++i) {
  309. b = a[i].split('<');
  310. if (b.length == 9) {
  311. // fixup < 0.08     !!! temp
  312. b.splice(7, 0, '', '', '');
  313. }
  314. else if (b.length == 10) {
  315. // fixup < 1.28.xx55
  316. b.splice(8, 0, '');
  317. }
  318. if (b.length == 11) {
  319. c = b[7].split(':');
  320. b.splice(7, 1, c[0], (c.length == 1) ? '' : c[1]);
  321. b[11] = unescape(b[11]);
  322. }
  323. else continue;
  324. b[4] = b[4].replace(/:/g, '-');
  325. qosg.insertData(-1, b);
  326. }
  327. ruleCounter = -1;
  328. this.showNewEditor();
  329. this.resetNewEditor();
  330. }
  331. function verifyFields(focused, quiet)
  332. {
  333. return 1;
  334. }
  335. function save()
  336. {
  337. if (qosg.isEditing()) return;
  338. var fom = E('_fom');
  339. var i, a, b, c;
  340. c = qosg.getAllData();
  341. a = [];
  342. for (i = 0; i < c.length; ++i) {
  343. b = c[i].slice(0);
  344. b[4] = b[4].replace(/-/g, ':');
  345. b.splice(7, 2, (b[7] == '') ? '' : [b[7],b[8]].join(':'));
  346. b[10] = escapeD(b[10]);
  347. a.push(b.join('<'));
  348. }
  349. fom.qos_orules.value = a.join('>');
  350. form.submit(fom, 0);
  351. }
  352. function init()
  353. {
  354. qosg.recolor();
  355. }
  356. </script>
  357. </head>
  358. <body onload='init()'>
  359. <form id='_fom' method='post' action='tomato.cgi'>
  360. <table id='container' cellspacing=0>
  361. <tr><td colspan=2 id='header'>
  362. <div class='title'>Tomato</div>
  363. <div class='version'>Version <% version(); %></div>
  364. </td></tr>
  365. <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
  366. <td id='content'>
  367. <div id='ident'><% ident(); %></div>
  368. <input type='hidden' name='_nextpage' value='qos-classify.asp'>
  369. <input type='hidden' name='_service' value='qos-restart'>
  370. <input type='hidden' name='qos_orules'>
  371. <div class='section-title'>Classification Rules</div>
  372. <div class='section'>
  373. <table class='tomato-grid' cellspacing=1 id='qg'></table>
  374. </div>
  375. <br>
  376. <script type='text/javascript'>
  377. if (nvram.qos_enable != '1') {
  378. W('<div class="note-disabled"><b>QoS disabled.</b> &nbsp; <a href="qos-settings.asp">Enable &raquo;</a></div>');
  379. }
  380. else {
  381. show_notice1('<% notice("iptables"); %>');
  382. }
  383. </script>
  384. </td></tr>
  385. <tr><td id='footer' colspan=2>
  386. <span id='footer-msg'></span>
  387. <input type='button' value='Save' id='save-button' onclick='save()'>
  388. <input type='button' value='Cancel' id='cancel-button' onclick='reloadPage();'>
  389. </td></tr>
  390. </table>
  391. </form>
  392. <script type='text/javascript'>qosg.setup();</script>
  393. </body>
  394. </html>
  395.  
Add Comment
Please, Sign In to add comment