routeros.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. Language: Microtik RouterOS script
  3. Author: Ivan Dementev <ivan_div@mail.ru>
  4. Description: Scripting host provides a way to automate some router maintenance tasks by means of executing user-defined scripts bounded to some event occurrence
  5. Website: https://wiki.mikrotik.com/wiki/Manual:Scripting
  6. */
  7. // Colors from RouterOS terminal:
  8. // green - #0E9A00
  9. // teal - #0C9A9A
  10. // purple - #99069A
  11. // light-brown - #9A9900
  12. function routeros(hljs) {
  13. var STATEMENTS = 'foreach do while for if from to step else on-error and or not in';
  14. // Global commands: Every global command should start with ":" token, otherwise it will be treated as variable.
  15. var GLOBAL_COMMANDS = 'global local beep delay put len typeof pick log time set find environment terminal error execute parse resolve toarray tobool toid toip toip6 tonum tostr totime';
  16. // Common commands: Following commands available from most sub-menus:
  17. var COMMON_COMMANDS = 'add remove enable disable set get print export edit find run debug error info warning';
  18. var LITERALS = 'true false yes no nothing nil null';
  19. var OBJECTS = 'traffic-flow traffic-generator firewall scheduler aaa accounting address-list address align area bandwidth-server bfd bgp bridge client clock community config connection console customer default dhcp-client dhcp-server discovery dns e-mail ethernet filter firewall firmware gps graphing group hardware health hotspot identity igmp-proxy incoming instance interface ip ipsec ipv6 irq l2tp-server lcd ldp logging mac-server mac-winbox mangle manual mirror mme mpls nat nd neighbor network note ntp ospf ospf-v3 ovpn-server page peer pim ping policy pool port ppp pppoe-client pptp-server prefix profile proposal proxy queue radius resource rip ripng route routing screen script security-profiles server service service-port settings shares smb sms sniffer snmp snooper socks sstp-server system tool tracking type upgrade upnp user-manager users user vlan secret vrrp watchdog web-access wireless pptp pppoe lan wan layer7-protocol lease simple raw';
  20. var VAR = {
  21. className: 'variable',
  22. variants: [
  23. {begin: /\$[\w\d#@][\w\d_]*/},
  24. {begin: /\$\{(.*?)}/}
  25. ]
  26. };
  27. var QUOTE_STRING = {
  28. className: 'string',
  29. begin: /"/, end: /"/,
  30. contains: [
  31. hljs.BACKSLASH_ESCAPE,
  32. VAR,
  33. {
  34. className: 'variable',
  35. begin: /\$\(/, end: /\)/,
  36. contains: [hljs.BACKSLASH_ESCAPE]
  37. }
  38. ]
  39. };
  40. var APOS_STRING = {
  41. className: 'string',
  42. begin: /'/, end: /'/
  43. };
  44. //////////////////////////////////////////////////////////////////////
  45. return {
  46. name: 'Microtik RouterOS script',
  47. aliases: ['routeros', 'mikrotik'],
  48. case_insensitive: true,
  49. keywords: {
  50. $pattern: /:?[\w-]+/,
  51. literal: LITERALS,
  52. keyword: STATEMENTS + ' :' + STATEMENTS.split(' ').join(' :') + ' :' + GLOBAL_COMMANDS.split(' ').join(' :'),
  53. },
  54. contains: [
  55. { // недопустимые конструкции
  56. variants: [
  57. { begin: /^@/, end: /$/, }, // dns
  58. { begin: /\/\*/, end: /\*\//, }, // -- comment
  59. { begin: /%%/, end: /$/, }, // -- comment
  60. { begin: /^'/, end: /$/, }, // Monkey one line comment
  61. { begin: /^\s*\/[\w-]+=/, end: /$/, }, // jboss-cli
  62. { begin: /\/\//, end: /$/, }, // Stan comment
  63. { begin: /^\[\</, end: /\>\]$/, }, // F# class declaration?
  64. { begin: /<\//, end: />/, }, // HTML tags
  65. { begin: /^facet /, end: /\}/, }, // roboconf - лютый костыль )))
  66. { begin: '^1\\.\\.(\\d+)$', end: /$/, }, // tap
  67. ],
  68. illegal: /./,
  69. },
  70. hljs.COMMENT('^#', '$'),
  71. QUOTE_STRING,
  72. APOS_STRING,
  73. VAR,
  74. { // attribute=value
  75. begin: /[\w-]+\=([^\s\{\}\[\]\(\)]+)/,
  76. relevance: 0,
  77. returnBegin: true,
  78. contains: [
  79. {
  80. className: 'attribute',
  81. begin: /[^=]+/
  82. },
  83. {
  84. begin: /=/,
  85. endsWithParent: true,
  86. relevance: 0,
  87. contains: [
  88. QUOTE_STRING,
  89. APOS_STRING,
  90. VAR,
  91. {
  92. className: 'literal',
  93. begin: '\\b(' + LITERALS.split(' ').join('|') + ')\\b',
  94. },
  95. /*{
  96. // IPv4 addresses and subnets
  97. className: 'number',
  98. variants: [
  99. {begin: IPADDR_wBITMASK+'(,'+IPADDR_wBITMASK+')*'}, //192.168.0.0/24,1.2.3.0/24
  100. {begin: IPADDR+'-'+IPADDR}, // 192.168.0.1-192.168.0.3
  101. {begin: IPADDR+'(,'+IPADDR+')*'}, // 192.168.0.1,192.168.0.34,192.168.24.1,192.168.0.1
  102. ]
  103. }, // */
  104. /*{
  105. // MAC addresses and DHCP Client IDs
  106. className: 'number',
  107. begin: /\b(1:)?([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]){1,2}\b/,
  108. }, //*/
  109. {
  110. // Не форматировать не классифицированные значения. Необходимо для исключения подсветки значений как built_in.
  111. // className: 'number',
  112. begin: /("[^"]*"|[^\s\{\}\[\]]+)/,
  113. }, //*/
  114. ]
  115. } //*/
  116. ]
  117. },//*/
  118. {
  119. // HEX values
  120. className: 'number',
  121. begin: /\*[0-9a-fA-F]+/,
  122. }, //*/
  123. {
  124. begin: '\\b(' + COMMON_COMMANDS.split(' ').join('|') + ')([\\s\[\(]|\])',
  125. returnBegin: true,
  126. contains: [
  127. {
  128. className: 'builtin-name', //'function',
  129. begin: /\w+/,
  130. },
  131. ],
  132. },
  133. {
  134. className: 'built_in',
  135. variants: [
  136. {begin: '(\\.\\./|/|\\s)((' + OBJECTS.split(' ').join('|') + ');?\\s)+',relevance: 10,},
  137. {begin: /\.\./,},
  138. ],
  139. },//*/
  140. ]
  141. };
  142. }
  143. module.exports = routeros;