-
Notifications
You must be signed in to change notification settings - Fork 2
/
rawconf_capxl_latest.rsc
executable file
·1760 lines (1760 loc) · 76.7 KB
/
rawconf_capxl_latest.rsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# jun/22/2023 23:20:53 by RouterOS 7.7
# software id = 59DY-JI10
#
# model = RBcAPGi-5acD2nD
# serial number = HD208EFDKQY
/interface bridge add admin-mac=18:FD:74:13:6E:33 auto-mac=no igmp-snooping=yes name="main infrastructure"
/interface ethernet set [ find default-name=ether1 ] arp=disabled name="lan A"
/interface ethernet set [ find default-name=ether2 ] name="lan B"
/interface wireless
# managed by CAPsMAN
# channel: 2412/20/gn(17dBm), SSID: WiFi 2Ghz PRIVATE, CAPsMAN forwarding
set [ find default-name=wlan1 ] antenna-gain=0 country=no_country_set frequency-mode=manual-txpower name="wlan 2Ghz" ssid=MikroTik station-roaming=enabled
/interface wireless
# managed by CAPsMAN
# channel: 5220/20-Ce/ac/P(15dBm), SSID: WiFi 5Ghz PRIVATE, CAPsMAN forwarding
set [ find default-name=wlan2 ] antenna-gain=0 country=no_country_set frequency-mode=manual-txpower name="wlan 5Ghz" ssid=MikroTik station-roaming=enabled
/interface lte apn set [ find default=yes ] ip-type=ipv4 use-network-apn=no
/interface wireless security-profiles set [ find default=yes ] supplicant-identity=MikroTik
/ip dhcp-client option add code=60 name=classid value="'mikrotik-cap'"
/snmp community set [ find default=yes ] authentication-protocol=SHA1 encryption-protocol=AES name=globus
/snmp community add addresses=::/0 disabled=yes name=public
/system logging action set 0 memory-lines=300
/system logging action add memory-lines=300 name=IpsecOnScreenLog target=memory
/system logging action add disk-file-count=1 disk-file-name=flash/ScriptsDiskLog disk-lines-per-file=10000 name=ScriptsDiskLog target=disk
/system logging action add disk-file-count=1 disk-file-name=flash/ErrorDiskLog disk-lines-per-file=300 name=ErrorDiskLog target=disk
/system logging action add name=TerminalConsoleLog remember=no target=echo
/system logging action add memory-lines=300 name=OnScreenLog target=memory
/system logging action add memory-lines=300 name=DHCPOnScreenLog target=memory
/system logging action add memory-lines=300 name=DNSOnScreenLog target=memory
/system logging action add memory-lines=300 name=RouterControlLog target=memory
/system logging action add memory-lines=300 name=OSPFOnscreenLog target=memory
/system logging action add memory-lines=300 name=L2TPOnScreenLog target=memory
/system logging action add disk-file-name=flash/AuthDiskLog name=AuthDiskLog target=disk
/system logging action add memory-lines=300 name=CertificatesOnScreenLog target=memory
/system logging action add memory-lines=300 name=ParseMemoryLog target=memory
/system logging action add memory-lines=300 name=CAPSOnScreenLog target=memory
/system logging action add memory-lines=300 name=FirewallOnScreenLog target=memory
/system logging action add memory-lines=300 name=FTPMemoryLog target=memory
/user group set read policy=local,telnet,ssh,read,test,winbox,password,web,sniff,api,romon,rest-api,!ftp,!reboot,!write,!policy,!sensitive
/user group set write policy=local,telnet,ssh,read,write,test,winbox,password,web,sniff,api,romon,rest-api,!ftp,!reboot,!policy,!sensitive
/interface bridge port add bridge="main infrastructure" ingress-filtering=no interface="lan A" trusted=yes
/interface bridge port add bridge="main infrastructure" ingress-filtering=no interface="lan B" trusted=yes
/interface bridge settings set use-ip-firewall=yes
/ip firewall connection tracking set enabled=yes
/ip neighbor discovery-settings set discover-interface-list=!dynamic
/ip settings set accept-source-route=yes max-neighbor-entries=8192
/ipv6 settings set disable-ipv6=yes max-neighbor-entries=8192
/interface detect-internet set detect-interface-list=all
/interface ovpn-server server set auth=sha1,md5
/interface wireless cap
#
set caps-man-addresses=192.168.90.1 discovery-interfaces="main infrastructure" enabled=yes interfaces="wlan 2Ghz,wlan 5Ghz"
/ip cloud set update-time=no
/ip dhcp-client add dhcp-options=hostname,clientid,classid interface="main infrastructure"
/ip dns set cache-max-ttl=1d cache-size=1024KiB query-server-timeout=3s
/ip firewall address-list add address=109.252.162.10 list=external-ip
/ip firewall address-list add list=alist-nat-external-ip
/ip firewall service-port set tftp disabled=yes
/ip firewall service-port set h323 disabled=yes
/ip firewall service-port set sip disabled=yes
/ip firewall service-port set pptp disabled=yes
/ip firewall service-port set udplite disabled=yes
/ip firewall service-port set dccp disabled=yes
/ip firewall service-port set sctp disabled=yes
/ip service set telnet disabled=yes
/ip service set api disabled=yes
/ip service set api-ssl disabled=yes
/ip smb set allow-guests=no domain=HNW interfaces="main infrastructure"
/ip smb shares set [ find default=yes ] directory=/pub disabled=yes
/ip ssh set allow-none-crypto=yes forwarding-enabled=remote
/ip tftp add real-filename=NAS/ req-filename=.*
/ip upnp set enabled=yes
/ip upnp interfaces add interface="main infrastructure" type=internal
/snmp set [email protected] enabled=yes location=RU trap-generators=interfaces trap-interfaces="main infrastructure" trap-version=2
/system clock set time-zone-autodetect=no time-zone-name=Europe/Moscow
/system identity set name=capxl
/system logging set 0 action=OnScreenLog topics=info,!ipsec,!script,!dns
/system logging set 1 action=OnScreenLog
/system logging set 2 action=OnScreenLog
/system logging set 3 action=TerminalConsoleLog
/system logging add action=IpsecOnScreenLog topics=ipsec,!debug
/system logging add action=ErrorDiskLog topics=critical
/system logging add action=ErrorDiskLog topics=error
/system logging add action=ScriptsDiskLog topics=script
/system logging add action=OnScreenLog topics=firewall
/system logging add action=OnScreenLog topics=smb
/system logging add action=OnScreenLog topics=critical
/system logging add action=DHCPOnScreenLog topics=dhcp
/system logging add action=DNSOnScreenLog topics=dns
/system logging add action=OSPFOnscreenLog topics=ospf,!raw
/system logging add action=OnScreenLog topics=event
/system logging add action=L2TPOnScreenLog topics=l2tp
/system logging add action=AuthDiskLog topics=account
/system logging add action=CertificatesOnScreenLog topics=certificate
/system logging add action=AuthDiskLog topics=manager
/system logging add action=ParseMemoryLog topics=account
/system logging add action=ParseMemoryLog topics=wireless
/system logging add action=CAPSOnScreenLog topics=caps
/system logging add action=FirewallOnScreenLog topics=firewall
/system logging add action=CAPSOnScreenLog topics=wireless
/system logging add action=ParseMemoryLog topics=info,system,!script
/system logging add action=FTPMemoryLog topics=tftp
/system note set note="IPSEC: \t\tokay \
\nDefault route: \t192.168.90.1 \
\ncapxl: \t\t7.7 \
\nUptime:\t\t1w6d10:30:57 \
\nTime:\t\tjun/22/2023 23:13:06 \
\nya.ru latency:\t4 ms \
\nCHR:\t\t185.13.148.14 \
\nMIK:\t\t85.174.193.108 \
\nANNA:\t\t46.39.51.161 \
\nClock:\t\tsynchronized \
\n"
/system ntp client set enabled=yes
/system scheduler add interval=1w3d name=doRandomGen on-event="/system script run doRandomGen" policy=ftp,reboot,read,write,policy,test,password,sensitive start-date=mar/01/2018 start-time=15:55:00
/system scheduler add interval=5d name=doBackup on-event="/system script run doBackup" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=jun/26/2018 start-time=21:00:00
/system scheduler add interval=30m name=doHeatFlag on-event="/system script run doHeatFlag" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=jul/10/2018 start-time=15:10:00
/system scheduler add interval=1d name=doLEDoff on-event="/system script run doLEDoff" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=sep/09/2018 start-time=23:30:00
/system scheduler add interval=1d name=doLEDon on-event="/system script run doLEDon" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=sep/09/2018 start-time=07:00:00
/system scheduler add interval=1m name=doPeriodicLogDump on-event="/system script run doPeriodicLogDump" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=feb/07/2019 start-time=11:31:24
/system scheduler add name=doStartupScript on-event="/system script run doStartupScript" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup
/system scheduler add interval=15m name=doCPUHighLoadReboot on-event="/system script run doCPUHighLoadReboot" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=feb/07/2019 start-time=06:05:00
/system scheduler add interval=1h name=doUpdateExternalDNS on-event="/system script run doUpdateExternalDNS" policy=read,write,policy,password start-date=jan/30/2017 start-time=18:57:09
/system scheduler add interval=1d name=doFreshTheScripts on-event="/system script run doFreshTheScripts" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=mar/01/2018 start-time=08:00:00
/system scheduler add interval=10m name=doCoolConsole on-event="/system script run doCoolConsole" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=apr/15/2023 start-time=17:52:52
/system scheduler add interval=6h name=doFlushLogs on-event="/system script run doFlushLogs" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=may/02/2023 start-time=22:00:00
/system script add comment="StarWars march to alarm on startup" dont-require-permissions=yes name=doImperialMarch owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:global globalScriptBeforeRun;\r\
\n\$globalScriptBeforeRun \"doImperialMarch\";\r\
\n\r\
\n:delay 6\r\
\n\r\
\n:beep frequency=500 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=500 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=500 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=400 length=500ms;\r\
\n:delay 400ms;\r\
\n\r\
\n:beep frequency=600 length=200ms;\r\
\n:delay 100ms;\r\
\n\r\
\n:beep frequency=500 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=400 length=500ms;\r\
\n:delay 400ms;\r\
\n\r\
\n:beep frequency=600 length=200ms;\r\
\n:delay 100ms;\r\
\n\r\
\n:beep frequency=500 length=500ms;\r\
\n:delay 1000ms;\r\
\n\r\
\n\r\
\n\r\
\n:beep frequency=750 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=750 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=750 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=810 length=500ms;\r\
\n:delay 400ms;\r\
\n\r\
\n:beep frequency=600 length=200ms;\r\
\n:delay 100ms;\r\
\n\r\
\n:beep frequency=470 length=500ms;\r\
\n:delay 500ms;\r\
\n\r\
\n:beep frequency=400 length=500ms;\r\
\n:delay 400ms;\r\
\n\r\
\n:beep frequency=600 length=200ms;\r\
\n:delay 100ms;\r\
\n\r\
\n:beep frequency=500 length=500ms;\r\
\n:delay 1000ms;"
/system script add comment="Updates address-list that contains my external IP" dont-require-permissions=yes name=doUpdateExternalDNS owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:local sysname [/system identity get name];\r\
\n:local scriptname \"doUpdateExternalDNS\";\r\
\n:global globalScriptBeforeRun;\r\
\n\$globalScriptBeforeRun \$scriptname;\r\
\n\r\
\n:global globalNoteMe;\r\
\n:local itsOk true;\r\
\n:local payLoad false;\r\
\n:local state \"\";\r\
\n\r\
\n:local content\r\
\n:local IPv4\r\
\n:global LastIPv4\r\
\n\r\
\n# parsing the current IPv4 result\r\
\n/ip cloud force-update;\r\
\n:delay 7s;\r\
\n:set IPv4 [/ip cloud get public-address];\r\
\n\r\
\n\r\
\n:if ((\$LastIPv4 != \$IPv4) || (\$force = true)) do={\r\
\n\r\
\n :set state \"External IP changed: current - (\$IPv4), last - (\$LastIPv4)\";\r\
\n \$globalNoteMe value=\$state;\r\
\n\r\
\n /ip firewall address-list remove [find list~\"alist-nat-external-ip\"];\r\
\n /ip firewall address-list add list=\"alist-nat-external-ip\" address=\$IPv4;\r\
\n \r\
\n /ip dns static remove [/ip dns static find name=ftpserver.org];\r\
\n /ip dns static add name=ftpserver.org address=\$IPv4;\r\
\n \r\
\n :set LastIPv4 \$IPv4;\r\
\n \r\
\n :set payLoad true; \r\
\n\r\
\n :local count [:len [/system script find name=\"doSuperviseCHRviaSSH\"]];\r\
\n :if (\$count > 0) do={\r\
\n \r\
\n :set state \"Refreshing VPN server (CHR) IPSEC policies\";\r\
\n \$globalNoteMe value=\$state;\r\
\n /system script run doSuperviseCHRviaSSH;\r\
\n \r\
\n }\r\
\n \r\
\n}\r\
\n\r\
\n:local inf \"\"\r\
\n:if (\$itsOk and \$payLoad ) do={\r\
\n :set inf \"\$scriptname on \$sysname: external IP address change detected, refreshed\"\r\
\n}\r\
\n\r\
\n\r\
\n:if (\$itsOk and !\$payLoad ) do={\r\
\n :set inf \"\$scriptname on \$sysname: no external IP address update needed\"\r\
\n}\r\
\n\r\
\n\r\
\n:if (!\$itsOk) do={\r\
\n :set inf \"Error When \$scriptname on \$sysname: \$state\" \r\
\n}\r\
\n\r\
\n\$globalNoteMe value=\$inf\r\
\n\r\
\n:if (!\$itsOk) do={\r\
\n\r\
\n :global globalTgMessage;\r\
\n \$globalTgMessage value=\$inf;\r\
\n \r\
\n}\r\
\n\r\
\n\r\
\n\r\
\n"
/system script add comment="Runs once on startup and makes console welcome message pretty" dont-require-permissions=yes name=doCoolConsole owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":global globalScriptBeforeRun;\r\
\n\$globalScriptBeforeRun \"doCoolConsole\";\r\
\n\r\
\n:global globalNoteMe;\r\
\n\r\
\n:local logcontenttemp \"\";\r\
\n:local logcontent \"\";\r\
\n\r\
\n:local rosVer [:tonum [:pick [/system resource get version] 0 1]];\r\
\n\r\
\n# reset current\r\
\n/system note set note=\"Pending\";\r\
\n\r\
\n:local sysver \"NA\";\r\
\n:if ( [ :len [ /system package find where name=\"system\" and disabled=no ] ] > 0 and \$rosVer = 6 ) do={\r\
\n :set sysver [/system package get system version];\r\
\n}\r\
\n:if ( [ :len [ /system package find where name=\"routeros\" and disabled=no ] ] > 0 and \$rosVer = 7 ) do={\r\
\n :set sysver [/system package get routeros version];\r\
\n}\r\
\n\r\
\n:log info \"Picking default route\";\r\
\n:local defaultRoute \"unreachable\";\r\
\n/ip route {\r\
\n :foreach i in=[find where dst-address=\"0.0.0.0/0\" and active and routing-table=main] do={\r\
\n :set defaultRoute [:tostr [/ip route get \$i gateway] ];\r\
\n }\r\
\n}\r\
\n\r\
\n:log info \"Picking ipsec\";\r\
\n:local ipsecState \"okay\";\r\
\n/ip ipsec policy {\r\
\n :foreach vpnEndpoint in=[find (!disabled and !template)] do={\r\
\n :local ph2state [get value-name=ph2-state \$vpnEndpoint]\r\
\n\r\
\n :if (\$ph2state != \"established\") do={\r\
\n :local ipsecState \"issues found\";\r\
\n }\r\
\n }\r\
\n}\r\
\n\r\
\n:set logcontenttemp \"IPSEC: \t\t\$ipsecState\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\") \r\
\n:set logcontenttemp \"Default route: \t\$defaultRoute\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\") \r\
\n:set logcontenttemp \"\$[/system identity get name]: \t\t\$sysver\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n:set logcontenttemp \"Uptime:\t\t\$[/system resource get uptime]\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n\r\
\n:local SafeResolve do={\r\
\n\r\
\n :if ([:len \$0]!=0) do={\r\
\n :if ([:len \$1]!=0) do={\r\
\n :do {\r\
\n :local host [:resolve \"\$1\"];\r\
\n :log warning \"Resolving: \$1\";\r\
\n :put \"Resolving: \$1 - Ok\"\r\
\n :return \$host;\r\
\n } on-error= {\r\
\n :log error \"FAIL resolving: \$1\";\r\
\n :put \"FAIL resolving: \$1\";\r\
\n :return \"ERROR\";\r\
\n };\r\
\n }\r\
\n } \r\
\n :log error \"FAIL resolving: \$1\";\r\
\n :put \"FAIL resolving: \$1\";\r\
\n :return \"ERROR\";\r\
\n}\r\
\n\r\
\n:local avgRttA 0;\r\
\n:local numPing 6;\r\
\n:local latency \"NA\";\r\
\n\r\
\n:local latencySite \"ya.ru\";\r\
\n:local yaResolve [\$SafeResolve \$latencySite];\r\
\n\r\
\n:log info \"Picking latency\";\r\
\n:if (\$yaResolve != \"ERROR\" ) do {\r\
\n \r\
\n :for tmpA from=1 to=\$numPing step=1 do={\r\
\n /tool flood-ping count=1 size=38 address=\$yaResolve do={ :set avgRttA (\$\"avg-rtt\" + \$avgRttA); }\r\
\n :delay 1s;\r\
\n }\r\
\n :set latency [:tostr (\$avgRttA / \$numPing )];\r\
\n\r\
\n} else={\r\
\n :set latency \"unreachable\";\r\
\n}\r\
\n\r\
\n:log info \"Resolving chr\";\r\
\n:local hostname \"accb195e0dffc6bb.sn.mynetname.net\";\r\
\n:local chrResolve [\$SafeResolve \$hostname];\r\
\n:if (\$chrResolve = \"ERROR\" ) do { \r\
\n :set chrResolve \"unreachable\";\r\
\n}\r\
\n\r\
\n:log info \"Resolving mik\";\r\
\n:local hostname \"673706ed7949.sn.mynetname.net\";\r\
\n:local mikResolve [\$SafeResolve \$hostname];\r\
\n:if (\$mikResolve = \"ERROR\" ) do { \r\
\n :set mikResolve \"unreachable\";\r\
\n}\r\
\n\r\
\n:log info \"Resolving anna\";\r\
\n:local hostname \"hcy086pz6xz.sn.mynetname.net\";\r\
\n:local annaResolve [\$SafeResolve \$hostname];\r\
\n:if (\$annaResolve = \"ERROR\" ) do { \r\
\n :set annaResolve \"unreachable\";\r\
\n}\r\
\n\r\
\n:set logcontenttemp \"Time:\t\t\$[/system clock get date] \$[/system clock get time]\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n:set logcontenttemp \"\$latencySite latency:\t\$latency ms\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n\r\
\n:set logcontenttemp \"CHR:\t\t\$chrResolve\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n:set logcontenttemp \"MIK:\t\t\$mikResolve\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n:set logcontenttemp \"ANNA:\t\t\$annaResolve\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n\r\
\n:set logcontenttemp \"Clock:\t\t\$[/system ntp client get status]\"\r\
\n:set logcontent (\"\$logcontent\" .\"\$logcontenttemp\" .\" \\n\")\r\
\n\r\
\n/system note set note=\"\$logcontent\" \r\
\n\r\
\n"
/system script add comment="Checks device temperature and warns on overheat" dont-require-permissions=yes name=doHeatFlag owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:local sysname [/system identity get name];\r\
\n:local scriptname \"doHeatFlag\";\r\
\n:global globalScriptBeforeRun;\r\
\n\$globalScriptBeforeRun \$scriptname;\r\
\n\r\
\n:global globalNoteMe;\r\
\n\r\
\n:local maxTemp;\r\
\n:local currentTemp [/system health get temperature];\r\
\n\r\
\n:set maxTemp 68;\r\
\n\r\
\n#\r\
\n\r\
\n:if (\$currentTemp > \$maxTemp) do= {\r\
\n\r\
\n:local inf \"\$scriptname on \$sysname: system overheat at \$currentTemp C\" \r\
\n\r\
\n\$globalNoteMe value=\$inf\r\
\n\r\
\n:global globalTgMessage;\r\
\n\$globalTgMessage value=\$inf;\r\
\n\r\
\n\r\
\n/beep length=.1\r\
\n :delay 250ms\r\
\n /beep length=.1\r\
\n :delay 800ms\r\
\n /beep length=.1\r\
\n :delay 250ms\r\
\n /beep length=.1\r\
\n :delay 800ms\r\
\n\r\
\n\r\
\n};\r\
\n\r\
\n"
/system script add comment="Runs at midnight to have less flashes at living room (swith off all LEDs)" dont-require-permissions=yes name=doLEDoff owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:global globalScriptBeforeRun;\r\
\n\$globalScriptBeforeRun \"doLEDoff\";\r\
\n\r\
\n/system leds settings set all-leds-off=immediate\r\
\n\r\
\n\r\
\n\r\
\n"
/system script add comment="Runs at morning to get flashes back (swith on all LEDs)" dont-require-permissions=yes name=doLEDon owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:global globalScriptBeforeRun;\r\
\n\$globalScriptBeforeRun \"doLEDon\";\r\
\n\r\
\n/system leds settings set all-leds-off=never;\r\
\n\r\
\n\r\
\n"
/system script add comment="Simple telegram notify script" dont-require-permissions=yes name=doTelegramNotify owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:global globalScriptBeforeRun;\r\
\n\$globalScriptBeforeRun \"doTelegramNotify\";\r\
\n\r\
\n:global TelegramToken \"798290125:AAE3gfeLKdtai3RPtnHRLbE8quNgAh7iC8M\";\r\
\n:global TelegramGroupID \"-343674739\";\r\
\n:global TelegramURL \"https://api.telegram.org/bot\$TelegramToken/sendMessage\\\?chat_id=\$TelegramGroupID\";\r\
\n\r\
\n:global TelegramMessage;\r\
\n\r\
\n:log info (\"Sending telegram message... \$TelegramMessage\");\r\
\n:put \"Sending telegram message... \$TelegramMessage\";\r\
\n\r\
\n:do {\r\
\n/tool fetch http-method=post mode=https url=\"\$TelegramURL\" http-data=\"text=\$TelegramMessage\" keep-result=no;\r\
\n} on-error= {\r\
\n:log error (\"Telegram notify error\");\r\
\n:put \"Telegram notify error\";\r\
\n};\r\
\n\r\
\n"
/system script add comment="Flushes all global variables on Startup" dont-require-permissions=yes name=doEnvironmentClearance owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n#clear all global variables\r\
\n/system script environment remove [find];\r\
\n\r\
\n"
/system script add comment="Startup script" dont-require-permissions=yes name=doStartupScript owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="# reset current\r\
\n/system note set note=\"Pending\";\r\
\n\r\
\n:do {\r\
\n\r\
\n # Track sync time (avoid CHR initial clock bug), with this we are also checking if internet comes up\r\
\n\r\
\n :local successSyncState \"synchronized\";\r\
\n :local syncOk false;\r\
\n :local syncState \"\";\r\
\n :local timeSpent 0;\r\
\n :local ticks 0;\r\
\n :local maxTicks 40;\r\
\n :local break false;\r\
\n :do {\r\
\n :set syncState [/system ntp client get status];\r\
\n :set syncOk (\$syncState = \$successSyncState);\r\
\n\r\
\n :log info \"Waiting 15s for clock sync using NTP.. (\$ticks/\$maxTicks, \$syncState)\";\r\
\n :put \"Waiting 15s for clock sync using NTP.. (\$ticks/\$maxTicks, \$syncState)\";\r\
\n \r\
\n :if (!\$syncOk) do={\r\
\n\r\
\n :delay 15s; \r\
\n :set timeSpent (\$timeSpent + 15);\r\
\n :set break (\$ticks >= \$maxTicks);\r\
\n\r\
\n } else={\r\
\n :set break true;\r\
\n };\r\
\n\r\
\n :set ticks (\$ticks + 1);\r\
\n\r\
\n } while=(! \$break )\r\
\n\r\
\n :if (\$syncOk) do={\r\
\n :log warning \"Successful clock sync using NTP in \$timeSpent seconds\";\r\
\n :put \"Successful clock sync using NTP in \$timeSpent seconds\";\r\
\n \r\
\n } else={\r\
\n :log error \"Error when clock sync using NTP in \$timeSpent seconds\";\r\
\n :put \"Error when clock sync using NTP in \$timeSpent seconds\";\r\
\n\r\
\n };\r\
\n \r\
\n} on-error={\r\
\n\r\
\n :log error \"Error when tracking clock sync using NTP\";\r\
\n :put \"Error when tracking clock sync using NTP\";\r\
\n\r\
\n};\r\
\n\r\
\n:local SafeScriptCall do={\r\
\n\r\
\n :if ([:len \$0]!=0) do={\r\
\n :if ([:len \$1]!=0) do={\r\
\n :if ([:len [/system script find name=\$1]]!=0) do={\r\
\n\r\
\n :do {\r\
\n :log warning \"Starting script: \$1\";\r\
\n :put \"Starting script: \$1\"\r\
\n /system script run \$1;\r\
\n } on-error= {\r\
\n :log error \"FAIL Starting script: \$1\";\r\
\n :put \"FAIL Starting script: \$1\"\r\
\n };\r\
\n\r\
\n }\r\
\n }\r\
\n } \r\
\n\r\
\n}\r\
\n\r\
\n\$SafeScriptCall \"doEnvironmentClearance\";\r\
\n\$SafeScriptCall \"doEnvironmentSetup\";\r\
\n\$SafeScriptCall \"doImperialMarch\";\r\
\n\$SafeScriptCall \"doCoolConsole\";\r\
\n\$SafeScriptCall \"SAT!start\";\r\
\n\r\
\n# wait some for all tunnels to come up after reboot and VPN to work\r\
\n\r\
\n:local inf \"Wait some for all tunnels to come up after reboot and VPN to work..\" ;\r\
\n:global globalNoteMe;\r\
\n:global globalTgMessage;\r\
\n:if (any \$globalNoteMe ) do={ \$globalNoteMe value=\$inf; }\r\
\n\r\
\n:delay 15s;\r\
\n\r\
\n:local sysname [/system identity get name];\r\
\n:local scriptname \"doStartupScript\";\r\
\n\r\
\n:local inf \"\$scriptname on \$sysname: system restart detected\" ;\r\
\n:if (any \$globalNoteMe ) do={ \$globalNoteMe value=\$inf; }\r\
\n:if (any \$globalTgMessage ) do={ \$globalTgMessage value=\$inf; }\r\
\n \r\
\n\r\
\n\r\
\n"
/system script add comment="Mikrotik system log dump, collects new entries once per minute. You should have 'ParseMemoryLog' buffer at your 'system-logging'. Calls 'doPeriodicLogParse' when new logs available" dont-require-permissions=yes name=doPeriodicLogDump owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:global globalScriptBeforeRun;\r\
\n#\$globalScriptBeforeRun \"doPeriodicLogDump\";\r\
\n\r\
\n# Script Name: Log-Parser\r\
\n# This script reads a specified log buffer. At each log entry read,\r\
\n# the global variable 'globalParseVar' is set to \"<log entry time>,<log entry topics>,<log entry message>\"\r\
\n# then a parser action script is run. The parser action script reads the global variable, and performs specified actions.\r\
\n# The log buffer is then cleared, so only new entries are read each time this script gets executed.\r\
\n\r\
\n# Set this to a \"memory\" action log buffer\r\
\n:local logBuffer \"ParseMemoryLog\"\r\
\n\r\
\n# Set to name of parser script to run against each log entry in buffer\r\
\n:local logParserScript \"doPeriodicLogParse\"\r\
\n# This changes are almost made by the other scripts, so skip them to avoid spam\r\
\n:local excludedMsgs [:toarray \"static dns entry, simple queue, script settings, led settings\"];\r\
\n\r\
\n# Internal processing below....\r\
\n# -----------------------------------\r\
\n:global globalParseVar \"\"\r\
\n:global globalLastParseTime\r\
\n:global globalLastParseMsg\r\
\n:global globalNoteMe;\r\
\n\r\
\n:local findindex\r\
\n:local property\r\
\n:local value\r\
\n:local logEntryTopics\r\
\n:local logEntryTime\r\
\n:local logEntryMessage\r\
\n:local curDate\r\
\n:local curMonth\r\
\n:local curDay\r\
\n:local curYear\r\
\n:local clearedbuf\r\
\n:local lines\r\
\n\r\
\n# Get current date settings\r\
\n:set \$curDate [/system clock get date]\r\
\n:set \$curMonth [:pick [:tostr \$curDate] 0 3]\r\
\n:set \$curDay [:pick [:tostr \$curDate] 4 6]\r\
\n:set \$curYear [:pick [:tostr \$curDate] 7 11]\r\
\n\r\
\n:set \$clearedbuf 0\r\
\n:foreach rule in=[/log print as-value where buffer=(\$logBuffer)] do={\r\
\n# Now all data is collected in memory..\r\
\n\r\
\n# Clear log buffer right away so new entries come in\r\
\n :if (\$clearedbuf = 0) do={\r\
\n /system logging action {\r\
\n :set \$lines [get (\$logBuffer) memory-lines]\r\
\n set (\$logBuffer) memory-lines 1\r\
\n set (\$logBuffer) memory-lines \$lines\r\
\n }\r\
\n :set \$clearedbuf 1\r\
\n }\r\
\n# End clear log buffer\r\
\n\r\
\n :set \$logEntryTime \"\"\r\
\n :set \$logEntryTopics \"\"\r\
\n :set \$logEntryMessage \"\"\r\
\n\r\
\n# Get each log entry's properties\r\
\n :local items {\$rule}\r\
\n :foreach item in=[\$items] do={\r\
\n :set \$logEntryTime (\$item->\"time\")\r\
\n :set \$logEntryTopics (\$item->\"topics\")\r\
\n :set \$logEntryMessage (\$item->\"message\")\r\
\n }\r\
\n# end foreach item\r\
\n }\r\
\n\r\
\n# Set \$logEntryTime to full time format (mmm/dd/yyyy HH:MM:SS)\r\
\n :set \$findindex [:find [:tostr \$logEntryTime] \" \"]\r\
\n# If no spaces are found, only time is given (HH:MM:SS), insert mmm/dd/yyyy\r\
\n :if ([:len \$findindex] = 0) do={\r\
\n :set \$logEntryTime (\$curMonth . \"/\" . \$curDay . \"/\" . \$curYear . \" \" . \\\r\
\n [:tostr \$logEntryTime])\r\
\n }\r\
\n# Only (mmm/dd HH:MM:SS) is given, insert year\r\
\n :if (\$findindex = 6) do={\r\
\n :set \$logEntryTime ([:pick [:tostr \$logEntryTime] 0 \$findindex] . \"/\" . \$curYear . \\\r\
\n [:pick [:tostr \$logEntryTime] \$findindex [:len [:tostr \$logEntryTime]]])\r\
\n }\r\
\n# Only (mmm HH:MM:SS) is given, insert day and year\r\
\n :if (\$findindex = 3) do={\r\
\n :set \$logEntryTime ([:pick [:tostr \$logEntryTime] 0 \$findindex] . \"/\" . \$curDay . \"/\" . \$curYear . \\\r\
\n [:pick [:tostr \$logEntryTime] \$findindex [:len [:tostr \$logEntryTime]]])\r\
\n }\r\
\n# End set \$logEntryTime to full time format\r\
\n\r\
\n# Skip if logEntryTime and logEntryMessage are the same as previous parsed log entry\r\
\n :if (\$logEntryTime = \$globalLastParseTime && \$logEntryMessage = \$globalLastParseMsg) do={\r\
\n \r\
\n } else={\r\
\n\r\
\n :local skip false;\r\
\n :foreach i in=\$excludedMsgs do={\r\
\n :if ( !\$skip and \$logEntryMessage~\$i ) do={\r\
\n :set skip true;\r\
\n :put \"log entry skipped due to setup: \$logEntryMessage\"; \r\
\n }\r\
\n }\r\
\n\r\
\n # Do not track LOG config changes because we're doing it right there (in that script)\r\
\n # and that will be a huge one-per-minute spam\r\
\n :if ( \$skip or \$logEntryMessage~\"log action\") do={\r\
\n\r\
\n \r\
\n } else={\r\
\n\r\
\n # Set \$globalParseVar, then run parser script\r\
\n :set \$globalParseVar {\$logEntryTime ; \$logEntryTopics; \$logEntryMessage}\r\
\n /system script run (\$logParserScript)\r\
\n\r\
\n # Update last parsed time, and last parsed message\r\
\n :set \$globalLastParseTime \$logEntryTime\r\
\n :set \$globalLastParseMsg \$logEntryMessage\r\
\n }\r\
\n }\r\
\n\r\
\n# end foreach rule\r\
\n}\r\
\n\r\
\n\r\
\n"
/system script add comment="Mikrotik system log analyzer, called manually by 'doPeriodicLogDump' script, checks 'interesting' conditions and does the routine" dont-require-permissions=yes name=doPeriodicLogParse owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n:global globalScriptBeforeRun;\r\
\n#\$globalScriptBeforeRun \"doPeriodicLogParse\";\r\
\n\r\
\n:local sysname [/system identity get name]\r\
\n:local scriptname \"doPeriodicLogParse\"\r\
\n\r\
\n# Script Name: Log-Parser-Script\r\
\n#\r\
\n# This is an EXAMPLE script. Modify it to your requirements.\r\
\n#\r\
\n# This script will work with all v3.x and v4.x\r\
\n# If your version >= v3.23, you can use the ~ operator to match against\r\
\n# regular expressions.\r\
\n\r\
\n# Get log entry data from global variable and store it locally\r\
\n:global globalParseVar;\r\
\n\r\
\n:global globalTgMessage;\r\
\n:global globalNoteMe;\r\
\n\r\
\n:local logTime (\$globalParseVar->0)\r\
\n:local logTopics [:tostr (\$globalParseVar->1)]\r\
\n:local logMessage [:tostr (\$globalParseVar->2)]\r\
\n\r\
\n:set \$globalParseVar \"\"\r\
\n\r\
\n:local ruleop\r\
\n:local loguser\r\
\n:local logsettings\r\
\n:local findindex\r\
\n:local tmpstring\r\
\n\r\
\n# Uncomment to view the log entry's details\r\
\n:put (\"Log Time: \" . \$logTime)\r\
\n:put (\"Log Topics: \" . \$logTopics)\r\
\n:put (\"Log Message: \" . \$logMessage)\r\
\n\r\
\n# Check for login failure\r\
\n:if (\$logMessage~\"login failure\") do={\r\
\n\r\
\n :local inf \"\$scriptname on \$sysname: A login failure has occured: \$logMessage. Take some action\";\r\
\n\r\
\n \$globalNoteMe value=\$inf;\r\
\n \$globalTgMessage value=\$inf;\r\
\n\r\
\n}\r\
\n# End check for login failure\r\
\n\r\
\n# Check for logged in users\r\
\n:if (\$logMessage~\"logged in\") do={\r\
\n \r\
\n :local inf \"\$scriptname on \$sysname: A user has logged in: \$logMessage\";\r\
\n\r\
\n \$globalNoteMe value=\$inf;\r\
\n \$globalTgMessage value=\$inf;\r\
\n\r\
\n}\r\
\n# End check for logged in users\r\
\n\r\
\n# Check for configuration changes: added, changed, or removed\r\
\n:if ([:tostr \$logTopics] = \"system;info\") do={\r\
\n :set ruleop \"\"\r\
\n :if ([:len [:find [:tostr \$logMessage] \"changed \"]] > 0) do={ :set ruleop \"changed\" }\r\
\n :if ([:len [:find [:tostr \$logMessage] \"added \"]] > 0) do={ :set ruleop \"added\" }\r\
\n :if ([:len [:find [:tostr \$logMessage] \"removed \"]] > 0) do={ :set ruleop \"removed\" }\r\
\n\r\
\n :if ([:len \$ruleop] > 0) do={\r\
\n :set tmpstring \$logMessage\r\
\n :set findindex [:find [:tostr \$tmpstring] [:tostr \$ruleop]]\r\
\n :set tmpstring ([:pick [:tostr \$tmpstring] 0 \$findindex] . \\\r\
\n [:pick [:tostr \$tmpstring] (\$findindex + [:len [:tostr \$ruleop]]) [:len [:tostr \$tmpstring]]])\r\
\n :set findindex [:find [:tostr \$tmpstring] \" by \"]\r\
\n :set loguser ([:pick [:tostr \$tmpstring] (\$findindex + 4) [:len [:tostr \$tmpstring]]])\r\
\n :set logsettings [:pick [:tostr \$tmpstring] 0 \$findindex]\r\
\n\r\
\n :put (\$loguser . \" \" . \$ruleop . \" \" . \$logsettings . \" configuration. We should take a backup now.\")\r\
\n\r\
\n :local inf \"\$scriptname on \$sysname: \$loguser \$ruleop \$logsettings configuration. We should take a backup now.\";\r\
\n\r\
\n \$globalNoteMe value=\$inf;\r\
\n \$globalTgMessage value=\$inf;\r\
\n\r\
\n }\r\
\n}\r\
\n\r\
\n# End check for configuration changes\r\
\n\r\
\n}\r\
\n\r\
\n"
/system script add comment="Setups global functions, called by the other scripts (runs once on startup)" dont-require-permissions=yes name=doEnvironmentSetup owner=owner policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\r\
\n\r\
\n:global globalNoteMe;\r\
\n:if (!any \$globalNoteMe) do={\r\
\n\r\
\n :global globalNoteMe do={\r\
\n\r\
\n ## outputs \$value using both :put and :log info\r\
\n ## example \$outputInfo value=\"12345\"\r\
\n\r\
\n :put \"info: \$value\"\r\
\n :log info \"\$value\"\r\
\n\r\
\n }\r\
\n}\r\
\n\r\
\n\r\
\n:global globalScriptBeforeRun;\r\
\n:if (!any \$globalScriptBeforeRun) do={\r\
\n :global globalScriptBeforeRun do={\r\
\n\r\
\n :global globalNoteMe;\r\
\n :if ([:len \$1] > 0) do={\r\
\n\r\
\n :local currentTime ([/system clock get date] . \" \" . [/system clock get time]);\r\
\n :local scriptname \"\$1\";\r\
\n :local count [:len [/system script job find script=\$scriptname]];\r\
\n\r\
\n :if (\$count > 0) do={\r\
\n\r\
\n :foreach counter in=[/system script job find script=\$scriptname] do={\r\
\n #But ignoring scripts started right NOW\r\
\n\r\
\n :local thisScriptCallTime [/system script job get \$counter started];\r\
\n :if (\$currentTime != \$thisScriptCallTime) do={\r\
\n\r\
\n :local state \"\$scriptname already Running at \$thisScriptCallTime - killing old script before continuing\";\r\
\n :log error \$state\r\
\n \$globalNoteMe value=\$state;\r\
\n /system script job remove \$counter;\r\
\n\r\
\n }\r\
\n }\r\
\n }\r\
\n\r\
\n :local state \"Starting script: \$scriptname\";\r\
\n :put \"info: \$state\"\r\
\n :log info \"\$state\"\r\
\n }\r\
\n }\r\
\n}\r\
\n\r\
\n:global globalTgMessage;\r\
\n:if (!any \$globalTgMessage) do={\r\
\n :global globalTgMessage do={\r\
\n\r\
\n :global globalNoteMe;\r\
\n :local tToken \"798290125:AAE3gfeLKdtai3RPtnHRLbE8quNgAh7iC8M\";\r\
\n :local tGroupID \"-1001798127067\";\r\
\n :local tURL \"https://api.telegram.org/bot\$tToken/sendMessage\\\?chat_id=\$tGroupID\";\r\
\n\r\
\n :local state (\"Sending telegram message... \$value\");\r\
\n \$globalNoteMe value=\$state;\r\
\n\r\
\n :do {\r\
\n /tool fetch http-method=post mode=https url=\"\$tURL\" http-data=\"text=\$value\" keep-result=no;\r\
\n } on-error= {\r\
\n :local state (\"Telegram notify error\");\r\
\n \$globalNoteMe value=\$state;\r\
\n };\r\
\n }\r\
\n}\r\
\n\r\
\n:global globalIPSECPolicyUpdateViaSSH;\r\
\n:if (!any \$globalIPSECPolicyUpdateViaSSH) do={\r\
\n :global globalIPSECPolicyUpdateViaSSH do={\r\
\n\r\
\n :global globalRemoteIp;\r\
\n :global globalNoteMe;\r\
\n\r\
\n :if ([:len \$1] > 0) do={\r\
\n :global globalRemoteIp (\"\$1\" . \"/32\");\r\
\n }\r\
\n\r\
\n :if (!any \$globalRemoteIp) do={\r\
\n :global globalRemoteIp \"0.0.0.0/32\"\r\
\n } else={\r\
\n }\r\
\n\r\
\n :local state (\"RPC... \$value\");\r\
\n \$globalNoteMe value=\$state;\r\
\n :local count [:len [/system script find name=\"doUpdatePoliciesRemotely\"]];\r\
\n :if (\$count > 0) do={\r\
\n :local state (\"Starting policies process... \$globalRemoteIp \");\r\
\n \$globalNoteMe value=\$state;\r\
\n /system script run doUpdatePoliciesRemotely;\r\
\n }\r\
\n }\r\
\n}\r\
\n\r\
\n#Example call\r\
\n#\$globalNewNetworkMember ip=192.168.99.130 mac=50:DE:06:25:C2:FC gip=192.168.98.229 comm=iPadAlxPro ssid=\"WiFi 5\"\r\
\n:global globalNewNetworkMember;\r\
\n:if (!any \$globalNewNetworkMember) do={\r\
\n :global globalNewNetworkMember do={\r\
\n\r\
\n :global globalNoteMe;\r\
\n\r\
\n #to prevent connection\r\
\n :local guestDHCP \"guest-dhcp-server\";\r\
\n\r\
\n #to allow connection\r\
\n :local mainDHCP \"main-dhcp-server\";\r\
\n\r\
\n #when DHCP not using (add arp for leases)\r\
\n :local arpInterface \"main-infrastructure-br\";\r\
\n :local state (\"Adding new network member... \");\r\
\n\r\
\n \$globalNoteMe value=\$state;\r\
\n\r\
\n # incoming named params\r\
\n :local newIp [ :tostr \$ip ];\r\
\n :local newBlockedIp [ :tostr \$gip ];\r\
\n :local newMac [ :tostr \$mac ];\r\
\n :local comment [ :tostr \$comm ];\r\
\n :local newSsid [ :tostr \$ssid ];\r\
\n :if ([:len \$newIp] > 0) do={\r\
\n :if ([ :typeof [ :toip \$newIp ] ] != \"ip\" ) do={\r\
\n\r\
\n :local state (\"Error: bad IP parameter passed - (\$newIp)\");\r\
\n \$globalNoteMe value=\$state;\r\
\n :return false;\r\
\n\r\
\n }\r\
\n } else={\r\
\n\r\
\n :local state (\"Error: bad IP parameter passed - (\$newIp)\");\r\
\n \$globalNoteMe value=\$state;\r\
\n :return false;\r\
\n\r\
\n }\r\
\n\r\
\n :do {\r\
\n\r\
\n :local state (\"Removing existing DHCP configuration for (\$newIp/\$newMac) on \$mainDHCP\");\r\
\n \$globalNoteMe value=\$state; \r\
\n /ip dhcp-server lease remove [find address=\$newIp];\r\
\n /ip dhcp-server lease remove [find mac-address=\$newMac];\r\
\n\r\
\n :local state (\"Adding DHCP configuration for (\$newIp/\$newMac) on \$mainDHCP\");\r\
\n \$globalNoteMe value=\$state;\r\
\n \r\
\n :if ([ :len [ /ip dhcp-server find where name=\"\$mainDHCP\" ] ] > 0) do={\r\
\n /ip dhcp-server lease add address=\$newIp mac-address=\$newMac server=\$mainDHCP comment=\$comment;\r\
\n :local state (\"Done.\");\r\
\n \$globalNoteMe value=\$state;\r\
\n } else={\r\
\n :local state (\"Cant find DHCP server \$mainDHCP. SKIPPED.\");\r\
\n \$globalNoteMe value=\$state;\r\
\n }\r\
\n\r\
\n } on-error={\r\
\n\r\
\n :local state (\"Error: something fail on DHCP configuration 'allow' step for (\$newIp/\$newMac) on \$mainDHCP\");\r\
\n \$globalNoteMe value=\$state;\r\
\n :return false;\r\
\n\r\
\n }\r\
\n\r\
\n :do {\r\
\n\r\
\n /ip dhcp-server lease remove [find address=\$newBlockedIp];\r\
\n :local state (\"Adding DHCP configuration for (\$newBlockedIp/\$newMac) on \$guestDHCP (preventing connections to guest network)\");\r\
\n \$globalNoteMe value=\$state;\r\
\n\r\
\n :if ([ :len [ /ip dhcp-server find where name=\"\$guestDHCP\" ] ] > 0) do={\r\
\n /ip dhcp-server lease add address=\$newBlockedIp block-access=yes mac-address=\$newMac server=\$guestDHCP comment=(\$comment . \"(blocked)\");\r\
\n :local state (\"Done.\");\r\
\n \$globalNoteMe value=\$state;\r\
\n } else={\r\
\n :local state (\"Cant find DHCP server \$guestDHCP. SKIPPED.\");\r\
\n \$globalNoteMe value=\$state;\r\
\n }\r\
\n\r\
\n } on-error={\r\
\n\r\
\n :local state (\"Error: something fail on DHCP configuration 'block' step for (\$newBlockedIp/\$newMac) on \$guestDHCP\");\r\
\n \$globalNoteMe value=\$state;\r\
\n :return false;\r\
\n\r\
\n }\r\
\n\r\
\n :do {\r\
\n\r\
\n :local state (\"Adding ARP static entries for (\$newBlockedIp/\$newMac) on \$mainDHCP\");\r\
\n \$globalNoteMe value=\$state;\r\
\n /ip arp remove [find address=\$newIp];\r\
\n /ip arp remove [find address=\$newBlockedIp];\r\
\n /ip arp remove [find mac-address=\$newMac];\r\
\n\r\
\n :if ([ :len [ /interface find where name=\"\$arpInterface\" ] ] > 0) do={\r\
\n /ip arp add address=\$newIp interface=\$arpInterface mac-address=\$newMac comment=\$comment\r\
\n :local state (\"Done.\");\r\
\n \$globalNoteMe value=\$state;\r\
\n } else={\r\
\n :local state (\"Cant find interface \$arpInterface. SKIPPED.\");\r\
\n \$globalNoteMe value=\$state;\r\
\n }\r\
\n\r\
\n } on-error={\r\
\n\r\
\n :local state (\"Error: something fail on ARP configuration step\");\r\