l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

routeros.js (6095B)


      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 
      8 // Colors from RouterOS terminal:
      9 //   green        - #0E9A00
     10 //   teal         - #0C9A9A
     11 //   purple       - #99069A
     12 //   light-brown  - #9A9900
     13 
     14 function routeros(hljs) {
     15 
     16   var STATEMENTS = 'foreach do while for if from to step else on-error and or not in';
     17 
     18   // Global commands: Every global command should start with ":" token, otherwise it will be treated as variable.
     19   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';
     20 
     21   // Common commands: Following commands available from most sub-menus:
     22   var COMMON_COMMANDS = 'add remove enable disable set get print export edit find run debug error info warning';
     23 
     24   var LITERALS = 'true false yes no nothing nil null';
     25 
     26   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';
     27 
     28   var VAR = {
     29     className: 'variable',
     30     variants: [
     31       {begin: /\$[\w\d#@][\w\d_]*/},
     32       {begin: /\$\{(.*?)}/}
     33     ]
     34   };
     35 
     36   var QUOTE_STRING = {
     37     className: 'string',
     38     begin: /"/, end: /"/,
     39     contains: [
     40       hljs.BACKSLASH_ESCAPE,
     41       VAR,
     42       {
     43         className: 'variable',
     44         begin: /\$\(/, end: /\)/,
     45         contains: [hljs.BACKSLASH_ESCAPE]
     46       }
     47     ]
     48   };
     49 
     50   var APOS_STRING = {
     51     className: 'string',
     52     begin: /'/, end: /'/
     53   };
     54   //////////////////////////////////////////////////////////////////////
     55   return {
     56     name: 'Microtik RouterOS script',
     57     aliases: ['routeros', 'mikrotik'],
     58     case_insensitive: true,
     59     keywords: {
     60       $pattern: /:?[\w-]+/,
     61       literal: LITERALS,
     62       keyword: STATEMENTS + ' :' + STATEMENTS.split(' ').join(' :') + ' :' + GLOBAL_COMMANDS.split(' ').join(' :'),
     63     },
     64     contains: [
     65       { // недопустимые конструкции
     66         variants: [
     67           { begin: /^@/, end: /$/, },               // dns
     68           { begin: /\/\*/, end: /\*\//, },          // -- comment
     69           { begin: /%%/, end: /$/, },               // -- comment
     70           { begin: /^'/, end: /$/, },               // Monkey one line comment
     71           { begin: /^\s*\/[\w-]+=/, end: /$/, },    // jboss-cli
     72           { begin: /\/\//, end: /$/, },             // Stan comment
     73           { begin: /^\[\</, end: /\>\]$/, },        // F# class declaration?
     74           { begin: /<\//, end: />/, },              // HTML tags
     75           { begin: /^facet /, end: /\}/, },         // roboconf - лютый костыль )))
     76           { begin: '^1\\.\\.(\\d+)$', end: /$/, },  // tap
     77         ],
     78         illegal: /./,
     79       },
     80       hljs.COMMENT('^#', '$'),
     81       QUOTE_STRING,
     82       APOS_STRING,
     83       VAR,
     84       { // attribute=value
     85         begin: /[\w-]+\=([^\s\{\}\[\]\(\)]+)/,
     86         relevance: 0,
     87         returnBegin: true,
     88         contains: [
     89           {
     90             className: 'attribute',
     91             begin: /[^=]+/
     92           },
     93           {
     94             begin: /=/,
     95             endsWithParent:  true,
     96             relevance: 0,
     97             contains: [
     98               QUOTE_STRING,
     99               APOS_STRING,
    100               VAR,
    101               {
    102                 className: 'literal',
    103                 begin: '\\b(' + LITERALS.split(' ').join('|') + ')\\b',
    104               },
    105               /*{
    106                 // IPv4 addresses and subnets
    107                 className: 'number',
    108                 variants: [
    109                   {begin: IPADDR_wBITMASK+'(,'+IPADDR_wBITMASK+')*'}, //192.168.0.0/24,1.2.3.0/24
    110                   {begin: IPADDR+'-'+IPADDR},       // 192.168.0.1-192.168.0.3
    111                   {begin: IPADDR+'(,'+IPADDR+')*'}, // 192.168.0.1,192.168.0.34,192.168.24.1,192.168.0.1
    112                 ]
    113               }, // */
    114               /*{
    115                 // MAC addresses and DHCP Client IDs
    116                 className: 'number',
    117                 begin: /\b(1:)?([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]){1,2}\b/,
    118               }, //*/
    119               {
    120                 // Не форматировать не классифицированные значения. Необходимо для исключения подсветки значений как built_in.
    121                 // className: 'number',
    122                 begin: /("[^"]*"|[^\s\{\}\[\]]+)/,
    123               }, //*/
    124             ]
    125           } //*/
    126         ]
    127       },//*/
    128       {
    129         // HEX values
    130         className: 'number',
    131         begin: /\*[0-9a-fA-F]+/,
    132       }, //*/
    133 
    134       {
    135         begin: '\\b(' + COMMON_COMMANDS.split(' ').join('|') + ')([\\s\[\(]|\])',
    136         returnBegin: true,
    137         contains: [
    138           {
    139             className: 'builtin-name', //'function',
    140             begin: /\w+/,
    141           },
    142         ],
    143       },
    144 
    145       {
    146         className: 'built_in',
    147         variants: [
    148           {begin: '(\\.\\./|/|\\s)((' + OBJECTS.split(' ').join('|') + ');?\\s)+',relevance: 10,},
    149           {begin: /\.\./,},
    150         ],
    151       },//*/
    152     ]
    153   };
    154 }
    155 
    156 module.exports = routeros;