olsrdiface.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. 'use strict';
  2. 'require view';
  3. 'require form';
  4. 'require uci';
  5. 'require ui';
  6. 'require tools.widgets as widgets';
  7. return view.extend({
  8. load: function () {
  9. return Promise.all([uci.load('olsrd')]);
  10. },
  11. render: function () {
  12. var m = new form.Map(
  13. 'olsrd',
  14. _('OLSR Daemon - Interface'),
  15. _(
  16. 'The OLSR daemon is an implementation of the Optimized Link State Routing protocol. ' +
  17. 'As such it allows mesh routing for any network equipment. ' +
  18. 'It runs on any wifi card that supports ad-hoc mode and of course on any ethernet device. ' +
  19. "Visit <a href='http://www.olsr.org'>olsrd.org</a> for help and documentation."
  20. )
  21. );
  22. var pathname = window.location.pathname;
  23. var segments = pathname.split('/');
  24. var sidIndex = segments.lastIndexOf('iface') + 1;
  25. var sid = null;
  26. if (sidIndex !== -1 && sidIndex < segments.length) {
  27. sid = segments[sidIndex];
  28. }
  29. var i = m.section(form.NamedSection, sid, 'Interface', _('Interface'));
  30. i.anonymous = true;
  31. i.addremove = false;
  32. i.tab('general', _('General Settings'));
  33. i.tab('addrs', _('IP Addresses'));
  34. i.tab('timing', _('Timing and Validity'));
  35. var ign = i.taboption('general', form.Flag, 'ignore', _('Enable'), _('Enable this interface.'));
  36. ign.enabled = '0';
  37. ign.disabled = '1';
  38. ign.rmempty = false;
  39. ign.cfgvalue = function (section_id) {
  40. return uci.get('olsrd', section_id, 'ignore') || '0';
  41. };
  42. var network = i.taboption('general', widgets.NetworkSelect, 'interface', _('Network'), _('The interface OLSRd should serve.'));
  43. network.optional = false;
  44. var mode = i.taboption('general', form.ListValue, 'Mode', _('Mode'), _('Interface mode is used to prevent unnecessary packet forwarding on switched ethernet interfaces. ' + 'Valid modes are "mesh" and "ether". Default is "mesh".'));
  45. mode.value('mesh');
  46. mode.value('ether');
  47. mode.optional = true;
  48. mode.rmempty = true;
  49. var weight = i.taboption(
  50. 'general',
  51. form.Value,
  52. 'Weight',
  53. _('Weight'),
  54. _(
  55. 'When multiple links exist between hosts the weight of interface is used to determine the link to use. ' +
  56. 'Normally the weight is automatically calculated by olsrd based on the characteristics of the interface, ' +
  57. 'but here you can specify a fixed value. Olsrd will choose links with the lowest value.<br />' +
  58. '<b>Note:</b> Interface weight is used only when LinkQualityLevel is set to 0. ' +
  59. 'For any other value of LinkQualityLevel, the interface ETX value is used instead.'
  60. )
  61. );
  62. weight.optional = true;
  63. weight.datatype = 'uinteger';
  64. weight.placeholder = '0';
  65. var lqmult = i.taboption(
  66. 'general',
  67. form.DynamicList,
  68. 'LinkQualityMult',
  69. _('LinkQuality Multiplicator'),
  70. _(
  71. 'Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. ' +
  72. 'It is only used when LQ-Level is greater than 0. Examples:<br />' +
  73. 'reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />' +
  74. 'reduce LQ to all nodes on this interface by 20%: default 0.8'
  75. )
  76. );
  77. lqmult.optional = true;
  78. lqmult.rmempty = true;
  79. lqmult.cast = 'table';
  80. lqmult.placeholder = 'default 1.0';
  81. lqmult.validate = function (section_id) {
  82. for (var i = 0; i < lqmult.formvalue(section_id).length; i++) {
  83. var v = lqmult.formvalue(section_id)[i];
  84. if (v !== '') {
  85. var val = v.split(' ');
  86. var host = val[0];
  87. var mult = val[1];
  88. if (!host || !mult) {
  89. return [null, "LQMult requires two values (IP address or 'default' and multiplicator) separated by space."];
  90. }
  91. if (!/^(\d{1,3}\.){3}\d{1,3}$|^([a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/.test(host) && host !== 'default') {
  92. return [null, "Can only be a valid IPv4 or IPv6 address or 'default'"];
  93. }
  94. if (isNaN(mult) || mult > 1 || mult < 0.01) {
  95. return [null, 'Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.'];
  96. }
  97. if (!/^[0-1]\.\d+$/.test(mult)) {
  98. return [null, 'Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.'];
  99. }
  100. }
  101. }
  102. return true;
  103. };
  104. var ip4b = i.taboption(
  105. 'addrs',
  106. form.Value,
  107. 'Ip4Broadcast',
  108. _('IPv4 broadcast'),
  109. _('IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. ' + 'Default is "0.0.0.0", which triggers the usage of the interface broadcast IP.')
  110. );
  111. ip4b.optional = true;
  112. ip4b.datatype = 'ip4addr';
  113. ip4b.placeholder = '0.0.0.0';
  114. var ip6m = i.taboption('addrs', form.Value, 'IPv6Multicast', _('IPv6 multicast'), _('IPv6 multicast address. Default is "FF02::6D", the manet-router linklocal multicast.'));
  115. ip6m.optional = true;
  116. ip6m.datatype = 'ip6addr';
  117. ip6m.placeholder = 'FF02::6D';
  118. var ip4s = i.taboption('addrs', form.Value, 'IPv4Src', _('IPv4 source'), _('IPv4 src address for outgoing OLSR packages. Default is "0.0.0.0", which triggers usage of the interface IP.'));
  119. ip4s.optional = true;
  120. ip4s.datatype = 'ip4addr';
  121. ip4s.placeholder = '0.0.0.0';
  122. var ip6s = i.taboption(
  123. 'addrs',
  124. form.Value,
  125. 'IPv6Src',
  126. _('IPv6 source'),
  127. _('IPv6 src prefix. OLSRd will choose one of the interface IPs which matches the prefix of this parameter. ' + 'Default is "0::/0", which triggers the usage of a not-linklocal interface IP.')
  128. );
  129. ip6s.optional = true;
  130. ip6s.datatype = 'ip6addr';
  131. ip6s.placeholder = '0::/0';
  132. var hi = i.taboption('timing', form.Value, 'HelloInterval', _('Hello interval'));
  133. hi.optional = true;
  134. hi.datatype = 'ufloat';
  135. hi.placeholder = '5.0';
  136. hi.write = function (section_id, value) {
  137. let n = parseFloat(value).toFixed(1);
  138. if (!isNaN(n)) {
  139. uci.set('olsrd', section_id, 'HelloInterval', n);
  140. }
  141. };
  142. var hv = i.taboption('timing', form.Value, 'HelloValidityTime', _('Hello validity time'));
  143. hv.optional = true;
  144. hv.datatype = 'ufloat';
  145. hv.placeholder = '40.0';
  146. hv.write = function (section_id, value) {
  147. let n = parseFloat(value).toFixed(1);
  148. if (!isNaN(n)) {
  149. uci.set('olsrd', section_id, 'HelloValidityTime', n);
  150. }
  151. };
  152. var ti = i.taboption('timing', form.Value, 'TcInterval', _('TC interval'));
  153. ti.optional = true;
  154. ti.datatype = 'ufloat';
  155. ti.placeholder = '2.0';
  156. ti.write = function (section_id, value) {
  157. let n = parseFloat(value).toFixed(1);
  158. if (!isNaN(n)) {
  159. uci.set('olsrd', section_id, 'TcInterval', n);
  160. }
  161. };
  162. var tv = i.taboption('timing', form.Value, 'TcValidityTime', _('TC validity time'));
  163. tv.optional = true;
  164. tv.datatype = 'ufloat';
  165. tv.placeholder = '256.0';
  166. tv.write = function (section_id, value) {
  167. let n = parseFloat(value).toFixed(1);
  168. if (!isNaN(n)) {
  169. uci.set('olsrd', section_id, 'TcValidityTime', n);
  170. }
  171. };
  172. var mi = i.taboption('timing', form.Value, 'MidInterval', _('MID interval'));
  173. mi.optional = true;
  174. mi.datatype = 'ufloat';
  175. mi.placeholder = '18.0';
  176. mi.write = function (section_id, value) {
  177. let n = parseFloat(value).toFixed(1);
  178. if (!isNaN(n)) {
  179. uci.set('olsrd', section_id, 'MidInterval', n);
  180. }
  181. };
  182. var mv = i.taboption('timing', form.Value, 'MidValidityTime', _('MID validity time'));
  183. mv.optional = true;
  184. mv.datatype = 'ufloat';
  185. mv.placeholder = '324.0';
  186. mv.write = function (section_id, value) {
  187. let n = parseFloat(value).toFixed(1);
  188. if (!isNaN(n)) {
  189. uci.set('olsrd', section_id, 'MidValidityTime', n);
  190. }
  191. };
  192. var ai = i.taboption('timing', form.Value, 'HnaInterval', _('HNA interval'));
  193. ai.optional = true;
  194. ai.datatype = 'ufloat';
  195. ai.placeholder = '18.0';
  196. ai.write = function (section_id, value) {
  197. let n = parseFloat(value).toFixed(1);
  198. if (!isNaN(n)) {
  199. uci.set('olsrd', section_id, 'HnaInterval', n);
  200. }
  201. };
  202. var av = i.taboption('timing', form.Value, 'HnaValidityTime', _('HNA validity time'));
  203. av.optional = true;
  204. av.datatype = 'ufloat';
  205. av.placeholder = '108.0';
  206. av.write = function (section_id, value) {
  207. let n = parseFloat(value).toFixed(1);
  208. if (!isNaN(n)) {
  209. uci.set('olsrd', section_id, 'HnaValidityTime', n);
  210. }
  211. };
  212. return m.render();
  213. },
  214. });