olsrdiface6.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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('olsrd6')]);
  10. },
  11. render: function () {
  12. var m = new form.Map(
  13. 'olsrd6',
  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 fd91:662e:3c58::1 by half: fd91:662e:3c58::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 ip6m = i.taboption('addrs', form.Value, 'IPv6Multicast', _('IPv6 multicast'), _('IPv6 multicast address. Default is "FF02::6D", the manet-router linklocal multicast.'));
  105. ip6m.optional = true;
  106. ip6m.datatype = 'ip6addr';
  107. ip6m.placeholder = 'FF02::6D';
  108. var ip6s = i.taboption(
  109. 'addrs',
  110. form.Value,
  111. 'IPv6Src',
  112. _('IPv6 source'),
  113. _('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.')
  114. );
  115. ip6s.optional = true;
  116. ip6s.datatype = 'ip6addr';
  117. ip6s.placeholder = '0::/0';
  118. var hi = i.taboption('timing', form.Value, 'HelloInterval', _('Hello interval'));
  119. hi.optional = true;
  120. hi.datatype = 'ufloat';
  121. hi.placeholder = '5.0';
  122. hi.write = function (section_id, value) {
  123. let n = parseFloat(value).toFixed(1);
  124. if (!isNaN(n)) {
  125. uci.set('olsrd6', section_id, 'HelloInterval', n);
  126. }
  127. };
  128. var hv = i.taboption('timing', form.Value, 'HelloValidityTime', _('Hello validity time'));
  129. hv.optional = true;
  130. hv.datatype = 'ufloat';
  131. hv.placeholder = '40.0';
  132. hv.write = function (section_id, value) {
  133. let n = parseFloat(value).toFixed(1);
  134. if (!isNaN(n)) {
  135. uci.set('olsrd6', section_id, 'HelloValidityTime', n);
  136. }
  137. };
  138. var ti = i.taboption('timing', form.Value, 'TcInterval', _('TC interval'));
  139. ti.optional = true;
  140. ti.datatype = 'ufloat';
  141. ti.placeholder = '2.0';
  142. ti.write = function (section_id, value) {
  143. let n = parseFloat(value).toFixed(1);
  144. if (!isNaN(n)) {
  145. uci.set('olsrd6', section_id, 'TcInterval', n);
  146. }
  147. };
  148. var tv = i.taboption('timing', form.Value, 'TcValidityTime', _('TC validity time'));
  149. tv.optional = true;
  150. tv.datatype = 'ufloat';
  151. tv.placeholder = '256.0';
  152. tv.write = function (section_id, value) {
  153. let n = parseFloat(value).toFixed(1);
  154. if (!isNaN(n)) {
  155. uci.set('olsrd6', section_id, 'TcValidityTime', n);
  156. }
  157. };
  158. var mi = i.taboption('timing', form.Value, 'MidInterval', _('MID interval'));
  159. mi.optional = true;
  160. mi.datatype = 'ufloat';
  161. mi.placeholder = '18.0';
  162. mi.write = function (section_id, value) {
  163. let n = parseFloat(value).toFixed(1);
  164. if (!isNaN(n)) {
  165. uci.set('olsrd6', section_id, 'MidInterval', n);
  166. }
  167. };
  168. var mv = i.taboption('timing', form.Value, 'MidValidityTime', _('MID validity time'));
  169. mv.optional = true;
  170. mv.datatype = 'ufloat';
  171. mv.placeholder = '324.0';
  172. mv.write = function (section_id, value) {
  173. let n = parseFloat(value).toFixed(1);
  174. if (!isNaN(n)) {
  175. uci.set('olsrd6', section_id, 'MidValidityTime', n);
  176. }
  177. };
  178. var ai = i.taboption('timing', form.Value, 'HnaInterval', _('HNA interval'));
  179. ai.optional = true;
  180. ai.datatype = 'ufloat';
  181. ai.placeholder = '18.0';
  182. ai.write = function (section_id, value) {
  183. let n = parseFloat(value).toFixed(1);
  184. if (!isNaN(n)) {
  185. uci.set('olsrd6', section_id, 'HnaInterval', n);
  186. }
  187. };
  188. var av = i.taboption('timing', form.Value, 'HnaValidityTime', _('HNA validity time'));
  189. av.optional = true;
  190. av.datatype = 'ufloat';
  191. av.placeholder = '108.0';
  192. av.write = function (section_id, value) {
  193. let n = parseFloat(value).toFixed(1);
  194. if (!isNaN(n)) {
  195. uci.set('olsrd6', section_id, 'HnaValidityTime', n);
  196. }
  197. };
  198. return m.render();
  199. },
  200. });