forked from highlightjs/highlight.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request highlightjs#1501 from DiVAN1x/routeros
New languages: MikroTik RouterOS Scripting language
- Loading branch information
Showing
6 changed files
with
302 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,3 +248,4 @@ Contributors: | |
- Joël Porquet <[email protected]> | ||
- Alex Arslan <[email protected]> | ||
- Stanislav Belov <[email protected]> | ||
- Ivan Dementev <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,3 +248,4 @@ URL: https://highlightjs.org/ | |
- Джоель Порке <[email protected]> | ||
- Алекс Арслан <[email protected]> | ||
- Станислав Белов <[email protected]> | ||
- Иван Дементьев <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
Language: Microtik RouterOS script | ||
Author: Ivan Dementev <[email protected]> | ||
Description: Scripting host provides a way to automate some router maintenance tasks by means of executing user-defined scripts bounded to some event occurrence | ||
URL: https://wiki.mikrotik.com/wiki/Manual:Scripting | ||
*/ | ||
|
||
// Colors from RouterOS terminal: | ||
// green - #0E9A00 | ||
// teal - #0C9A9A | ||
// purple - #99069A | ||
// light-brown - #9A9900 | ||
|
||
function(hljs) { | ||
|
||
var STATEMENTS = 'foreach do while for if from to step else on-error and or not in'; | ||
|
||
// Global commands: Every global command should start with ":" token, otherwise it will be treated as variable. | ||
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'; | ||
|
||
// Common commands: Following commands available from most sub-menus: | ||
var COMMON_COMMANDS = 'add remove enable disable set get print export edit find run debug error info warning'; | ||
|
||
var LITERALS = 'true false yes no nothing nil null'; | ||
|
||
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'; | ||
|
||
// print parameters | ||
// Several parameters are available for print command: | ||
// ToDo: var PARAMETERS_PRINT = 'append as-value brief detail count-only file follow follow-only from interval terse value-list without-paging where info'; | ||
// ToDo: var OPERATORS = '&& and ! not || or in ~ ^ & << >> + - * /'; | ||
// ToDo: var TYPES = 'num number bool boolean str string ip ip6-prefix id time array'; | ||
// ToDo: The following tokens serve as delimiters in the grammar: () [] {} : ; $ / | ||
|
||
var VAR_PREFIX = 'global local set for foreach'; | ||
|
||
var VAR = { | ||
className: 'variable', | ||
variants: [ | ||
{begin: /\$[\w\d#@][\w\d_]*/}, | ||
{begin: /\$\{(.*?)}/} | ||
] | ||
}; | ||
|
||
var QUOTE_STRING = { | ||
className: 'string', | ||
begin: /"/, end: /"/, | ||
contains: [ | ||
hljs.BACKSLASH_ESCAPE, | ||
VAR, | ||
{ | ||
className: 'variable', | ||
begin: /\$\(/, end: /\)/, | ||
contains: [hljs.BACKSLASH_ESCAPE] | ||
} | ||
] | ||
}; | ||
|
||
var APOS_STRING = { | ||
className: 'string', | ||
begin: /'/, end: /'/ | ||
}; | ||
|
||
var IPADDR = '((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\b'; | ||
var IPADDR_wBITMASK = IPADDR+'/(3[0-2]|[1-2][0-9]|\\d)'; | ||
////////////////////////////////////////////////////////////////////// | ||
return { | ||
aliases: ['routeros', 'mikrotik'], | ||
case_insensitive: true, | ||
lexemes: /:?[\w-]+/, | ||
keywords: { | ||
literal: LITERALS, | ||
keyword: STATEMENTS + ' :' + STATEMENTS.split(' ').join(' :') + ' :' + GLOBAL_COMMANDS.split(' ').join(' :'), | ||
}, | ||
contains: [ | ||
{ // недопустимые конструкции | ||
variants: [ | ||
{ begin: /^@/, end: /$/, }, // dns | ||
{ begin: /\/\*/, end: /\*\//, }, // -- comment | ||
{ begin: /%%/, end: /$/, }, // -- comment | ||
{ begin: /^'/, end: /$/, }, // Monkey one line comment | ||
{ begin: /^\s*\/[\w-]+=/, end: /$/, }, // jboss-cli | ||
{ begin: /\/\//, end: /$/, }, // Stan comment | ||
{ begin: /^\[\</, end: /\>\]$/, }, // F# class declaration? | ||
{ begin: /<\//, end: />/, }, // HTML tags | ||
{ begin: /^facet /, end: /\}/, }, // roboconf - лютый костыль ))) | ||
{ begin: '^1\\.\\.(\\d+)$', end: /$/, }, // tap | ||
], | ||
illegal: /./, | ||
}, | ||
hljs.COMMENT('^#', '$'), | ||
QUOTE_STRING, | ||
APOS_STRING, | ||
VAR, | ||
{ // attribute=value | ||
begin: /[\w-]+\=([^\s\{\}\[\]\(\)]+)/, | ||
relevance: 0, | ||
returnBegin: true, | ||
contains: [ | ||
{ | ||
className: 'attribute', | ||
begin: /[^=]+/ | ||
}, | ||
{ | ||
begin: /=/, | ||
endsWithParent: true, | ||
relevance: 0, | ||
contains: [ | ||
QUOTE_STRING, | ||
APOS_STRING, | ||
VAR, | ||
{ | ||
className: 'literal', | ||
begin: '\\b(' + LITERALS.split(' ').join('|') + ')\\b', | ||
}, | ||
/*{ | ||
// IPv4 addresses and subnets | ||
className: 'number', | ||
variants: [ | ||
{begin: IPADDR_wBITMASK+'(,'+IPADDR_wBITMASK+')*'}, //192.168.0.0/24,1.2.3.0/24 | ||
{begin: IPADDR+'-'+IPADDR}, // 192.168.0.1-192.168.0.3 | ||
{begin: IPADDR+'(,'+IPADDR+')*'}, // 192.168.0.1,192.168.0.34,192.168.24.1,192.168.0.1 | ||
] | ||
}, // */ | ||
/*{ | ||
// MAC addresses and DHCP Client IDs | ||
className: 'number', | ||
begin: /\b(1:)?([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]){1,2}\b/, | ||
}, //*/ | ||
{ | ||
// Не форматировать не классифицированные значения. Необходимо для исключения подсветки значений как built_in. | ||
// className: 'number', | ||
begin: /("[^"]*"|[^\s\{\}\[\]]+)/, | ||
}, //*/ | ||
] | ||
} //*/ | ||
] | ||
},//*/ | ||
{ | ||
// HEX values | ||
className: 'number', | ||
begin: /\*[0-9a-fA-F]+/, | ||
}, //*/ | ||
|
||
{ | ||
begin: '\\b(' + COMMON_COMMANDS.split(' ').join('|') + ')([\\s\[\(]|\])', | ||
returnBegin: true, | ||
contains: [ | ||
{ | ||
className: 'builtin-name', //'function', | ||
begin: /\w+/, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
className: 'built_in', | ||
variants: [ | ||
{begin: '(\\.\\./|/|\\s)((' + OBJECTS.split(' ').join('|') + ');?\\s)+',relevance: 10,}, | ||
{begin: /\.\./,}, | ||
], | ||
},//*/ | ||
] | ||
}; | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
highlight.js style for Microtik RouterOS script | ||
*/ | ||
|
||
.hljs { | ||
display: block; | ||
overflow-x: auto; | ||
padding: 0.5em; | ||
background: #F0F0F0; | ||
} | ||
|
||
/* Base color: saturation 0; */ | ||
|
||
.hljs, | ||
.hljs-subst { | ||
color: #444; | ||
} | ||
|
||
.hljs-comment { | ||
color: #888888; | ||
} | ||
|
||
.hljs-keyword, | ||
.hljs-selector-tag, | ||
.hljs-meta-keyword, | ||
.hljs-doctag, | ||
.hljs-name { | ||
font-weight: bold; | ||
} | ||
|
||
.hljs-attribute { | ||
color: #0E9A00; | ||
} | ||
|
||
.hljs-function { | ||
color: #99069A; | ||
} | ||
|
||
.hljs-builtin-name { | ||
color: #99069A; | ||
} | ||
|
||
/* User color: hue: 0 */ | ||
|
||
.hljs-type, | ||
.hljs-string, | ||
.hljs-number, | ||
.hljs-selector-id, | ||
.hljs-selector-class, | ||
.hljs-quote, | ||
.hljs-template-tag, | ||
.hljs-deletion { | ||
color: #880000; | ||
} | ||
|
||
.hljs-title, | ||
.hljs-section { | ||
color: #880000; | ||
font-weight: bold; | ||
} | ||
|
||
.hljs-regexp, | ||
.hljs-symbol, | ||
.hljs-variable, | ||
.hljs-template-variable, | ||
.hljs-link, | ||
.hljs-selector-attr, | ||
.hljs-selector-pseudo { | ||
color: #BC6060; | ||
} | ||
|
||
|
||
/* Language color: hue: 90; */ | ||
|
||
.hljs-literal { | ||
color: #78A960; | ||
} | ||
|
||
.hljs-built_in, | ||
.hljs-bullet, | ||
.hljs-code, | ||
.hljs-addition { | ||
color: #0C9A9A; | ||
} | ||
|
||
|
||
/* Meta color: hue: 200 */ | ||
|
||
.hljs-meta { | ||
color: #1f7199; | ||
} | ||
|
||
.hljs-meta-string { | ||
color: #4d99bf; | ||
} | ||
|
||
|
||
/* Misc effects */ | ||
|
||
.hljs-emphasis { | ||
font-style: italic; | ||
} | ||
|
||
.hljs-strong { | ||
font-weight: bold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Берем список DNS серверов из /ip dns | ||
# Проверяем их доступность, | ||
# и только рабочие прописываем в настройки DHCP сервера | ||
:global ActiveDNSServers [] | ||
:local PingResult 0 | ||
:foreach serv in=[/ip dns get servers] do={ | ||
:do {:set PingResult [ping $serv count=3]} on-error={:set PingResult 0} | ||
:if ($PingResult=3) do={ :set ActiveDNSServers ($ActiveDNSServers,$serv) } | ||
# отладочный вывод в журнал | ||
:log info "Server: $serv, Ping-result: $PingResult"; | ||
} | ||
|
||
/ip dhcp-server network set [find address=192.168.254.0/24] dns-server=$ActiveDNSServers | ||
|
||
#--- FIX TTL ---- | ||
/ip firewall mangle chain=postrouting action=change-ttl new-ttl=set:128 comment="NAT hide" | ||
|