# jan/16/2023 13:47:38 by RouterOS 6.49.7
# software id = T9PD-VUT8
# model = RB941-2nD
# serial number = HCR087MNR5P
/interface bridge
add name=Bridge_LAN vlan-filtering=yes
/interface vlan
add interface=Bridge_LAN name=vlanAdmin88 vlan-id=88
add interface=Bridge_LAN name=vlanGUEST29 vlan-id=29
add interface=Bridge_LAN name=vlanHOME27 vlan-id=27
add interface=Bridge_LAN name=vlanIOT28 vlan-id=28
/interface list
add name=WAN
add name=LAN
add name=Admin
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
add authentication-types=wpa-psk,wpa2-psk group-ciphers=tkip,aes-ccm mode=\
dynamic-keys name=E3User supplicant-identity="" unicast-ciphers=\
tkip,aes-ccm
add authentication-types=wpa-psk,wpa2-psk group-ciphers=tkip,aes-ccm mode=\
dynamic-keys name=E3IOT supplicant-identity="" unicast-ciphers=\
tkip,aes-ccm
/interface wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n country=indonesia disabled=no \
frequency=2472 mode=ap-bridge security-profile=E3IOT ssid=E3IOT
add disabled=no keepalive-frames=disabled mac-address=1A:FD:74:39:10:18 \
master-interface=wlan1 multicast-buffering=disabled name=wlan2 \
security-profile=E3User ssid=E3Guest wds-cost-range=0 wds-default-cost=0 \
wps-mode=push-button-5s
/ip hotspot profile
set [ find default=yes ] hotspot-address=192.168.29.1
/ip pool
add name=LAN ranges=192.168.27.10-192.168.27.250
add name=Admin ranges=192.168.88.2-192.168.88.10
add name=wlan_IOT ranges=192.168.28.10-192.168.28.250
add name=wlan_guest ranges=192.168.29.10-192.168.29.250
/ip dhcp-server
add address-pool=LAN disabled=no interface=vlanHOME27 lease-time=12h name=\
DHCP_LAN
add address-pool=Admin disabled=no interface=vlanAdmin88 name=DHCP_Admin
add address-pool=wlan_IOT disabled=no interface=vlanIOT28 lease-time=12h \
name=DHCP_WLANIIOT
add address-pool=wlan_guest disabled=no interface=vlanGUEST29 lease-time=12h \
name=DHCP_WLANGuest
/ip hotspot
add address-pool=wlan_guest disabled=no interface=vlanGUEST29 name=\
HotSpot_Server
/queue tree
add bucket-size=0.01 max-limit=12M name=UP parent=ether1 queue=default
add name="1. VOIP_" packet-mark=VOIP parent=UP priority=1 queue=default
add name="2. DNS_" packet-mark=DNS parent=UP priority=2 queue=default
add name="3. ACK_" packet-mark=ACK parent=UP priority=3 queue=default
add name="4. UDP_" packet-mark=UDP parent=UP priority=3 queue=default
add name="5. ICMP_" packet-mark=ICMP parent=UP priority=4 queue=default
add name="6. HTTP_" packet-mark=HTTP parent=UP priority=5 queue=default
add name="7. HTTP_BIG_" packet-mark=HTTP_BIG parent=UP priority=6 queue=\
default
add name="8. QUIC_" packet-mark=QUIC parent=UP priority=7 queue=default
add bucket-size=0.01 max-limit=12M name=DOWN parent=Bridge_LAN queue=default
add name="1. VOIP" packet-mark=VOIP parent=DOWN priority=1 queue=default
add name="2. DNS" packet-mark=DNS parent=DOWN priority=2 queue=default
add name="3. ACK" packet-mark=ACK parent=DOWN priority=3 queue=default
add name="4. UDP" packet-mark=UDP parent=DOWN priority=3 queue=default
add name="5. ICMP" packet-mark=ICMP parent=DOWN priority=4 queue=default
add name="6. HTTP" packet-mark=HTTP parent=DOWN priority=5 queue=default
add name="7. HTTP_BIG" packet-mark=HTTP_BIG parent=DOWN priority=6 queue=\
default
add name="8. QUIC" packet-mark=QUIC parent=DOWN priority=7 queue=default
add name="9. OTHER" packet-mark=OTHER parent=DOWN queue=default
/interface bridge port
add bridge=Bridge_LAN frame-types=admit-only-untagged-and-priority-tagged \
ingress-filtering=yes interface=ether2 pvid=27
add bridge=Bridge_LAN frame-types=admit-only-untagged-and-priority-tagged \
ingress-filtering=yes interface=ether3 pvid=27
add bridge=Bridge_LAN frame-types=admit-only-untagged-and-priority-tagged \
ingress-filtering=yes interface=ether4 pvid=88
add bridge=Bridge_LAN frame-types=admit-only-untagged-and-priority-tagged \
ingress-filtering=yes interface=wlan1 pvid=28
add bridge=Bridge_LAN frame-types=admit-only-untagged-and-priority-tagged \
ingress-filtering=yes interface=wlan2 pvid=29
/ip neighbor discovery-settings
set discover-interface-list=Admin
/interface bridge vlan
add bridge=Bridge_LAN tagged=Bridge_LAN untagged=ether2,ether3 vlan-ids=27
add bridge=Bridge_LAN tagged=Bridge_LAN untagged=ether4 vlan-ids=88
add bridge=Bridge_LAN tagged=Bridge_LAN untagged=wlan1 vlan-ids=28
add bridge=Bridge_LAN tagged=Bridge_LAN untagged=wlan2 vlan-ids=29
/interface list member
add interface=ether1 list=WAN
add interface=vlanHOME27 list=LAN
add interface=vlanAdmin88 list=LAN
add interface=vlanIOT28 list=LAN
add interface=vlanGUEST29 list=LAN
add interface=vlanHOME27 list=Admin
add interface=vlanAdmin88 list=Admin
/ip address
add address=192.168.88.1/24 interface=vlanAdmin88 network=192.168.88.0
add address=192.168.27.1/24 interface=vlanHOME27 network=192.168.27.0
add address=192.168.28.1/24 interface=vlanIOT28 network=192.168.28.0
add address=192.168.29.1/24 interface=vlanGUEST29 network=192.168.29.0
/ip dhcp-client
add disabled=no interface=ether1
/ip dhcp-server network
add address=192.168.27.0/24 dns-server=1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4 \
gateway=192.168.27.1
add address=192.168.28.0/24 dns-server=1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4 \
gateway=192.168.28.1
add address=192.168.29.0/24 dns-server=1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4 \
gateway=192.168.29.1
add address=192.168.88.0/24 dns-server=1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4 \
gateway=192.168.88.1
/ip dns
set allow-remote-requests=yes servers=8.8.8.8,8.8.4.4,1.1.1.1,1.0.0.1
/ip firewall filter
add action=passthrough chain=unused-hs-chain comment=\
"place hotspot rules here" disabled=yes
add action=accept chain=input comment=\
"defconf: accept established,related,untracked" connection-state=\
established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment="allow admin access" in-interface-list=\
Admin
add action=accept chain=input dst-port=53 in-interface-list=LAN protocol=udp
add action=accept chain=input dst-port=53 in-interface-list=LAN protocol=tcp
add action=drop chain=input comment="drop all else"
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
connection-state=established,related
add action=accept chain=forward comment=\
"defconf: accept established,related, untracked" connection-state=\
established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
connection-state=invalid
add action=accept chain=forward comment="allow internet traffic" \
in-interface-list=LAN out-interface-list=WAN
add action=accept chain=forward comment="allow port forwarding" \
connection-nat-state=dstnat disabled=yes
add action=drop chain=forward
/ip firewall nat
add action=passthrough chain=unused-hs-chain comment=\
"place hotspot rules here" disabled=yes
add action=masquerade chain=srcnat ipsec-policy=out,none out-interface-list=\
WAN
/ip firewall service-port
set ftp disabled=yes
set tftp disabled=yes
set irc disabled=yes
set h323 disabled=yes
set sip disabled=yes
set pptp disabled=yes
set udplite disabled=yes
set dccp disabled=yes
set sctp disabled=yes
/ip hotspot user
add name=E3Guest server=HotSpot_Server
/ip service
set telnet disabled=yes
set ftp disabled=yes
set www-ssl disabled=no
set api disabled=yes
set winbox address=192.168.27.0/24,192.168.88.0/24
set api-ssl disabled=yes
/ip ssh
set strong-crypto=yes
/system clock
set time-zone-name=Asia/Jakarta
/system identity
set name=Marge
/system scheduler
add interval=10m name=SystemStateScheduler on-event=TelegramSystemState \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-time=startup
add comment="jan/02/1970 00:00:32" interval=1m name=LogToTG-FailedLogin \
on-event=LogToTG-FailedLogin policy=read,write,policy,test start-time=\
startup
add comment="jan/16/2023 13:44:06" interval=1m name=LogToTG-SuccessLogin \
on-event=LogToTG-SuccessLogin policy=read,write,policy,test start-time=\
startup
add name=SendReportAfterReboot on-event=\
":delay 60\r\
\n/system script run ReportGenerationRouterBoot" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-time=startup
add interval=12h name=UpdatePackageChecker on-event=NotifTGRouterOSUpdate \
policy=read,write,policy,test start-time=startup
add comment="jan/16/2023 00:14:36" disabled=yes interval=3h name=LogToEmail \
on-event=SendingLogToEmail policy=read,write,policy,test start-time=\
startup
/system script
add dont-require-permissions=yes name=TGBotSenderScript owner=Seno@E3 policy=\
read,write,policy,test source=":local BotToken \"XXX\";\r\
\n:local ChatID \"-1001781133257\";\r\
\n:local ParseMode \"html\";\r\
\n:local DisableWebPagePreview True;\r\
\n:local SendText \$MessageText;\r\
\n\r\
\n:local tgUrl \"https://api.telegram.org/bot\$BotToken/sendMessage\\\?cha\
t_id=\$ChatID&text=\$SendText&parse_mode=\$ParseMode&disable_web_page_prev\
iew=\$DisableWebPagePreview\";\r\
\n\r\
\n/tool fetch http-method=get url=\$tgUrl output=none;"
add dont-require-permissions=no name=SendingLogToTelegram owner=E3 policy=\
read,write,policy,test source="# BEGIN SETUP\r\
\n#Change this to the name of your schedule (the date/time stamp is saved \
in the schedule's comment).\r\
\n:local scheduleName \"GeneralLogToTelegram\"\r\
\n\r\
\n#Get System Name\r\
\n:local DeviceName [/system identity get name];\r\
\n\r\
\n#This currently detects two strings. It can be changed to more or less s\
trings if desired. Remove: || message~\"login failure\" if you only want t\
o use one string, or if you want more strings, add this same code at the e\
nd (but before the last two end brackets).\r\
\n:local startBuf [:toarray [/log find topics~\"error\" || topics~\"critic\
al\" || topics~\"system\" || topics~\"script\" || topics~\"gsm\" || topics\
~\"interface\" || topic~\"pppoe\" || topic~\"system\"]]\r\
\n\r\
\n#Edit the quoted items for strings you want to be filtered out of the re\
sults. For example, if you want all \"logged in\" logs found, but you do n\
ot want any of the \"logged in via telnet\" logs included, simply include \
the word \"telnet\" in the array and these logs will be excluded. Double q\
uote additional strings and separate them with semi-colons. If you don't w\
ant any logs filtered, simply declare the variable :local removeThese with\
out any curly braces. curly braces sample as follow {\"testing\";\"whateve\
r string you want\"}\r\
\n:local removeThese {\"login\";\"logged\";\"2admin\";\"LOGMON\"}\r\
\n\r\
\n# END SETUP\r\
\n# warn if schedule does not exist\r\
\n:if ([:len [/system scheduler find name=\"\$scheduleName\"]] = 0) do={\r\
\n /log warning \"[LOGMON] ERROR: Schedule does not exist. Create schedul\
e and edit script to match name\"\r\
\n}\r\
\n# get last time\r\
\n:local lastTime [/system scheduler get [find name=\"\$scheduleName\"] co\
mment]\r\
\n# for checking time of each log entry\r\
\n:local currentTime\r\
\n# log message\r\
\n:local message\r\
\n# final output\r\
\n:local output\r\
\n:local keepOutput false\r\
\n# if lastTime is empty, set keepOutput to true\r\
\n:if ([:len \$lastTime] = 0) do={\r\
\n :set keepOutput true\r\
\n}\r\
\n:local counter 0\r\
\n# loop through all log entries that have been found\r\
\n:foreach i in=\$startBuf do={\r\
\n# loop through all removeThese array items\r\
\n :local keepLog true\r\
\n :foreach j in=\$removeThese do={\r\
\n# if this log entry contains any of them, it will be ignored\r\
\n :if ([/log get \$i message] ~ \"\$j\") do={\r\
\n :set keepLog false\r\
\n }\r\
\n }\r\
\n :if (\$keepLog = true) do={\r\
\n :set message [/log get \$i message]\r\
\n# LOG DATE\r\
\n# depending on log date/time, the format may be different. 3 known for\
mats\r\
\n# format of jan/01/2002 00:00:00 which shows up at unknown date/time. \
Using as default\r\
\n :set currentTime [ /log get \$i time ]\r\
\n# format of 00:00:00 which shows up on current day's logs\r\
\n :if ([:len \$currentTime] = 8 ) do={\r\
\n :set currentTime ([:pick [/system clock get date] 0 11].\" \".\$cur\
rentTime)\r\
\n } else={\r\
\n# format of jan/01 00:00:00 which shows up on previous day's logs\r\
\n :if ([:len \$currentTime] = 15 ) do={\r\
\n :set currentTime ([:pick \$currentTime 0 6].\"/\".[:pick [/syste\
m clock get date] 7 11].\" \".[:pick \$currentTime 7 15])\r\
\n }\r\
\n }\r\
\n# if keepOutput is true, add this log entry to output\r\
\n :if (\$keepOutput = true) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"%0A%0A %E2%84\
%B9 \")\r\
\n }\r\
\n# if currentTime = lastTime, set keepOutput so any further logs found \
will be added to output\r\
\n# reset output in the case we have multiple identical date/time entrie\
s in a row as the last matching logs\r\
\n# otherwise, it would stop at the first found matching log, thus all f\
ollowing logs would be output\r\
\n :if (\$currentTime = \$lastTime) do={\r\
\n :set keepOutput true\r\
\n :set output \"\"\r\
\n }\r\
\n }\r\
\n# if this is last log entry\r\
\n :if (\$counter = ([:len \$startBuf]-1)) do={\r\
\n# If keepOutput is still false after loop, this means lastTime has a v\
alue, but a matching currentTime was never found.\r\
\n# This can happen if 1) The router was rebooted and matching logs stor\
ed in memory were wiped, or 2) An item is added\r\
\n# to the removeThese array that then ignores the last log that determi\
ned the lastTime variable.\r\
\n# This resets the comment to nothing. The next run will be like the fi\
rst time, and you will get all matching logs\r\
\n :if (\$keepOutput = false) do={\r\
\n# if previous log was found, this will be our new lastTime entry \
\_ \r\
\n :if ([:len \$message] > 0) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"%0A%0A %E2\
%84%B9 \")\r\
\n }\r\
\n }\r\
\n }\r\
\n :set counter (\$counter + 1)\r\
\n}\r\
\n# If we have output, save new date/time, and send email\r\
\nif ([:len \$output] > 0) do={\r\
\n /system scheduler set [find name=\"\$scheduleName\"] comment=\$current\
Time\r\
\n \r\
\n#to get ouput value to be printed\r\
\n#:log info \"value is: \$output\"\r\
\n \r\
\n :local MessageText \"%F0%9F%A4%96 <b>\$DeviceName: </b>General Logs Re\
port %0A%0A %E2%84%B9 \$output\";\r\
\n \r\
\n#get TGBotSenderScript to send\r\
\n :local SendTelegramMessage [:parse [/system script get TGBotSenderScri\
pt source]];\r\
\n \$SendTelegramMessage MessageText=\$MessageText;\r\
\n /log info \"[LOGMON] New <b>General</b> logs found, sending Telegram M\
essage\"\r\
\n}"
add dont-require-permissions=no name=TelegramSystemState owner=Seno@E3 \
policy=read,write,policy,test source=":local DeviceName [/system identity \
get name];\r\
\n:local freemem ([/system resource get free-memory] / 1024 / 1024);\r\
\n:local totmem ([/system resource get total-memory] / 1024 / 1024);\r\
\n:local freehddspace ([/system resource get free-hdd-space] / 1024 / 1024\
);\r\
\n:local totalhddspace ([/system resource get total-hdd-space] / 1024 / 10\
24);\r\
\n:local cpuload ([/system resource get cpu-load]);\r\
\n:local up ([/system resource get uptime]);\r\
\n\r\
\n:local MessageText \"%F0%9F%A4%96 <b>\$DeviceName:<u> System Status</u>\
</b> %0A%E2%8C%9B <b> CPU = </b><i>\$cpuload % </i> %0A%F0%9F%90%8F <b> F\
ree Ram = </b><i>\$freemem / \$totmem MB</i> %0A%F0%9F%93%80 <b>Free Spa\
ce = </b><i>\$freehddspace / \$totalhddspace</i> %0A%E2%8F%B0 <b> Uptime =\
\_</b><i>\$up</i>\"\r\
\n\r\
\n#get TGBotSenderScript to send\r\
\n:local SendTelegramMessage [:parse [/system script get TGBotSenderScrip\
t source]];\r\
\n\$SendTelegramMessage MessageText=\$MessageText;"
add dont-require-permissions=yes name=LogToTG-FailedLogin owner=E3 policy=\
read,write,policy,test source="# BEGIN SETUP\r\
\n#Change this to the name of your schedule (the date/time stamp is saved \
in the schedule's comment).\r\
\n:local scheduleName \"LogToTG-FailedLogin\"\r\
\n\r\
\n#Get System Name\r\
\n:local DeviceName [/system identity get name];\r\
\n\r\
\n#This currently detects two strings. It can be changed to more or less s\
trings if desired. Remove: || message~\"login failure\" if you only want t\
o use one string, or if you want more strings, add this same code at the e\
nd (but before the last two end brackets).\r\
\n:local startBuf [:toarray [/log find where topics~\"critical\" || messag\
e~\"login\"]]\r\
\n\r\
\n#Edit the quoted items for strings you want to be filtered out of the re\
sults. For example, if you want all \"logged in\" logs found, but you do n\
ot want any of the \"logged in via telnet\" logs included, simply include \
the word \"telnet\" in the array and these logs will be excluded. Double q\
uote additional strings and separate them with semi-colons. If you don't w\
ant any logs filtered, simply declare the variable :local removeThese with\
out any curly braces. curly braces sample as follow {\"testing\";\"whateve\
r string you want\"}\r\
\n:local removeThese\r\
\n\r\
\n# END SETUP\r\
\n# warn if schedule does not exist\r\
\n:if ([:len [/system scheduler find name=\"\$scheduleName\"]] = 0) do={\r\
\n /log warning \"[LOGMON] ERROR: Schedule does not exist. Create schedul\
e and edit script to match name\"\r\
\n}\r\
\n# get last time\r\
\n:local lastTime [/system scheduler get [find name=\"\$scheduleName\"] co\
mment]\r\
\n# for checking time of each log entry\r\
\n:local currentTime\r\
\n# log message\r\
\n:local message\r\
\n# final output\r\
\n:local output\r\
\n:local keepOutput false\r\
\n# if lastTime is empty, set keepOutput to true\r\
\n:if ([:len \$lastTime] = 0) do={\r\
\n :set keepOutput true\r\
\n}\r\
\n:local counter 0\r\
\n# loop through all log entries that have been found\r\
\n:foreach i in=\$startBuf do={\r\
\n# loop through all removeThese array items\r\
\n :local keepLog true\r\
\n :foreach j in=\$removeThese do={\r\
\n# if this log entry contains any of them, it will be ignored\r\
\n :if ([/log get \$i message] ~ \"\$j\") do={\r\
\n :set keepLog false\r\
\n }\r\
\n }\r\
\n :if (\$keepLog = true) do={\r\
\n :set message [/log get \$i message]\r\
\n# LOG DATE\r\
\n# depending on log date/time, the format may be different. 3 known for\
mats\r\
\n# format of jan/01/2002 00:00:00 which shows up at unknown date/time. \
Using as default\r\
\n :set currentTime [ /log get \$i time ]\r\
\n# format of 00:00:00 which shows up on current day's logs\r\
\n :if ([:len \$currentTime] = 8 ) do={\r\
\n :set currentTime ([:pick [/system clock get date] 0 11].\" \".\$cur\
rentTime)\r\
\n } else={\r\
\n# format of jan/01 00:00:00 which shows up on previous day's logs\r\
\n :if ([:len \$currentTime] = 15 ) do={\r\
\n :set currentTime ([:pick \$currentTime 0 6].\"/\".[:pick [/syste\
m clock get date] 7 11].\" \".[:pick \$currentTime 7 15])\r\
\n }\r\
\n }\r\
\n# if keepOutput is true, add this log entry to output\r\
\n :if (\$keepOutput = true) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"%0A%0A %F0%9F\
%9A%AB \")\r\
\n }\r\
\n# if currentTime = lastTime, set keepOutput so any further logs found \
will be added to output\r\
\n# reset output in the case we have multiple identical date/time entrie\
s in a row as the last matching logs\r\
\n# otherwise, it would stop at the first found matching log, thus all f\
ollowing logs would be output\r\
\n :if (\$currentTime = \$lastTime) do={\r\
\n :set keepOutput true\r\
\n :set output \"\"\r\
\n }\r\
\n }\r\
\n# if this is last log entry\r\
\n :if (\$counter = ([:len \$startBuf]-1)) do={\r\
\n# If keepOutput is still false after loop, this means lastTime has a v\
alue, but a matching currentTime was never found.\r\
\n# This can happen if 1) The router was rebooted and matching logs stor\
ed in memory were wiped, or 2) An item is added\r\
\n# to the removeThese array that then ignores the last log that determi\
ned the lastTime variable.\r\
\n# This resets the comment to nothing. The next run will be like the fi\
rst time, and you will get all matching logs\r\
\n :if (\$keepOutput = false) do={\r\
\n# if previous log was found, this will be our new lastTime entry \
\_ \r\
\n :if ([:len \$message] > 0) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"%0A%0A %F0\
%9F%9A%AB \")\r\
\n }\r\
\n }\r\
\n }\r\
\n :set counter (\$counter + 1)\r\
\n}\r\
\n# If we have output, save new date/time, and send email\r\
\nif ([:len \$output] > 0) do={\r\
\n /system scheduler set [find name=\"\$scheduleName\"] comment=\$current\
Time\r\
\n\r\
\n #Send Telegram Notif\r\
\n :local MessageText \"%F0%9F%A4%96<b>\$DeviceName:</b> Critical Notifca\
tion %0A%0A%F0%9F%9A%AB \$output\";\r\
\n \r\
\n#get TGBotSenderScript to send\r\
\n :local SendTelegramMessage [:parse [/system script get TGBotSenderScri\
pt source]];\r\
\n \$SendTelegramMessage MessageText=\$MessageText;\r\
\n /log info \"[LOGMON] Login <b>Failure</b> logs found, sending Telegram\
\_Message\"\r\
\n}"
add dont-require-permissions=yes name=LogToTG-SuccessLogin owner=E3 policy=\
read,write,policy,test source="# BEGIN SETUP\r\
\n#Change this to the name of your schedule (the date/time stamp is saved \
in the schedule's comment).\r\
\n:local scheduleName \"LogToTG-SuccessLogin\"\r\
\n\r\
\n#Get System Name\r\
\n:local DeviceName [/system identity get name];\r\
\n\r\
\n#This currently detects two strings. It can be changed to more or less s\
trings if desired. Remove: || message~\"login failure\" if you only want t\
o use one string, or if you want more strings, add this same code at the e\
nd (but before the last two end brackets).\r\
\n:local startBuf [:toarray [/log find where topics~\"account\" ]]\r\
\n\r\
\n#Edit the quoted items for strings you want to be filtered out of the re\
sults. For example, if you want all \"logged in\" logs found, but you do n\
ot want any of the \"logged in via telnet\" logs included, simply include \
the word \"telnet\" in the array and these logs will be excluded. Double q\
uote additional strings and separate them with semi-colons. If you don't w\
ant any logs filtered, simply declare the variable :local removeThese with\
out any curly braces. curly braces sample as follow {\"testing\";\"whateve\
r string you want\"}\r\
\n:local removeThese \r\
\n\r\
\n# END SETUP\r\
\n# warn if schedule does not exist\r\
\n:if ([:len [/system scheduler find name=\"\$scheduleName\"]] = 0) do={\r\
\n /log warning \"[LOGMON] ERROR: Schedule does not exist. Create schedul\
e and edit script to match name\"\r\
\n}\r\
\n# get last time\r\
\n:local lastTime [/system scheduler get [find name=\"\$scheduleName\"] co\
mment]\r\
\n# for checking time of each log entry\r\
\n:local currentTime\r\
\n# log message\r\
\n:local message\r\
\n# final output\r\
\n:local output\r\
\n:local keepOutput false\r\
\n# if lastTime is empty, set keepOutput to true\r\
\n:if ([:len \$lastTime] = 0) do={\r\
\n :set keepOutput true\r\
\n}\r\
\n:local counter 0\r\
\n# loop through all log entries that have been found\r\
\n:foreach i in=\$startBuf do={\r\
\n# loop through all removeThese array items\r\
\n :local keepLog true\r\
\n :foreach j in=\$removeThese do={\r\
\n# if this log entry contains any of them, it will be ignored\r\
\n :if ([/log get \$i message] ~ \"\$j\") do={\r\
\n :set keepLog false\r\
\n }\r\
\n }\r\
\n :if (\$keepLog = true) do={\r\
\n :set message [/log get \$i message]\r\
\n# LOG DATE\r\
\n# depending on log date/time, the format may be different. 3 known for\
mats\r\
\n# format of jan/01/2002 00:00:00 which shows up at unknown date/time. \
Using as default\r\
\n :set currentTime [ /log get \$i time ]\r\
\n# format of 00:00:00 which shows up on current day's logs\r\
\n :if ([:len \$currentTime] = 8 ) do={\r\
\n :set currentTime ([:pick [/system clock get date] 0 11].\" \".\$cur\
rentTime)\r\
\n } else={\r\
\n# format of jan/01 00:00:00 which shows up on previous day's logs\r\
\n :if ([:len \$currentTime] = 15 ) do={\r\
\n :set currentTime ([:pick \$currentTime 0 6].\"/\".[:pick [/syste\
m clock get date] 7 11].\" \".[:pick \$currentTime 7 15])\r\
\n }\r\
\n }\r\
\n# if keepOutput is true, add this log entry to output\r\
\n :if (\$keepOutput = true) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"%0A%0A %E2%9C\
%85 \")\r\
\n }\r\
\n# if currentTime = lastTime, set keepOutput so any further logs found \
will be added to output\r\
\n# reset output in the case we have multiple identical date/time entrie\
s in a row as the last matching logs\r\
\n# otherwise, it would stop at the first found matching log, thus all f\
ollowing logs would be output\r\
\n :if (\$currentTime = \$lastTime) do={\r\
\n :set keepOutput true\r\
\n :set output \"\"\r\
\n }\r\
\n }\r\
\n# if this is last log entry\r\
\n :if (\$counter = ([:len \$startBuf]-1)) do={\r\
\n# If keepOutput is still false after loop, this means lastTime has a v\
alue, but a matching currentTime was never found.\r\
\n# This can happen if 1) The router was rebooted and matching logs stor\
ed in memory were wiped, or 2) An item is added\r\
\n# to the removeThese array that then ignores the last log that determi\
ned the lastTime variable.\r\
\n# This resets the comment to nothing. The next run will be like the fi\
rst time, and you will get all matching logs\r\
\n :if (\$keepOutput = false) do={\r\
\n# if previous log was found, this will be our new lastTime entry \
\_ \r\
\n :if ([:len \$message] > 0) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"%0A%0A %E2\
%9C%85 \")\r\
\n }\r\
\n }\r\
\n }\r\
\n :set counter (\$counter + 1)\r\
\n}\r\
\n# If we have output, save new date/time, \r\
\nif ([:len \$output] > 0) do={\r\
\n /system scheduler set [find name=\"\$scheduleName\"] comment=\$current\
Time\r\
\n\r\
\n#Send Telegram Notif\r\
\n :local MessageText \"%F0%9F%A4%96<b>\$DeviceName:</b> Account Activiti\
es Log %0A%0A%E2%9C%85 \$output\";\r\
\n \r\
\n#get TGBotSenderScript to send\r\
\n :local SendTelegramMessage [:parse [/system script get TGBotSenderScri\
pt source]];\r\
\n \$SendTelegramMessage MessageText=\$MessageText;\r\
\n /log info \"[LOGMON] Account <b>Actitvity</b> logs found, sending Tele\
gram Message\"\r\
\n}"
add dont-require-permissions=no name=ReportGenerationRouterBoot owner=Seno@E3 \
policy=ftp,read,write,policy,test source=":delay 5\r\
\n\r\
\n:local reportBody \"\"\r\
\n\r\
\n:local deviceName [/system identity get name]\r\
\n:local deviceDate [/system clock get date]\r\
\n:local deviceTime [/system clock get time]\r\
\n:local hwModel [/system routerboard get model]\r\
\n:local rosVersion [/system package get system version]\r\
\n:local currentFirmware [/system routerboard get current-firmware]\r\
\n:local upgradeFirmware [/system routerboard get upgrade-firmware]\r\
\n\r\
\n\r\
\n:set reportBody (\$reportBody . \"Router Reboot Report for \$deviceName\
\\n\")\r\
\n:set reportBody (\$reportBody . \"Report generated on \$deviceDate at \$\
deviceTime\\n\\n\")\r\
\n\r\
\n:set reportBody (\$reportBody . \"Hardware Model: \$hwModel\\n\")\r\
\n:set reportBody (\$reportBody . \"RouterOS Version: \$rosVersion\\n\")\r\
\n:set reportBody (\$reportBody . \"Current Firmware: \$currentFirmware\\n\
\")\r\
\n:set reportBody (\$reportBody . \"Upgrade Firmware: \$upgradeFirmware\")\
\r\
\nif ( \$currentFirmware < \$upgradeFirmware) do={\r\
\n:set reportBody (\$reportBody . \"NOTE: You should upgrade the RouterBOA\
RD firmware!\\n\")\r\
\n}\r\
\n\r\
\n:set reportBody (\$reportBody . \"\\n\\n=== Critical Log Events ===\\n\"\
\_)\r\
\n\r\
\n:local x\r\
\n:local ts\r\
\n:local msg\r\
\nforeach i in=([/log find where topics~\"critical\"]) do={\r\
\n:set \$ts [/log get \$i time]\r\
\n:set \$msg [/log get \$i message]\r\
\n:set \$reportBody (\$reportBody . \$ts . \" \" . \$msg . \"\\n\" )\r\
\n}\r\
\n\r\
\n:set reportBody (\$reportBody . \"\\n=== end of report ===\\n\")\r\
\n\r\
\n/tool e-mail send subject=\"[\$deviceName] Router Reboot Report\" to=\"d\
ermawas@gmail.com\" body=\$reportBody"
add dont-require-permissions=no name=SendingLogToEmail owner=Seno@E3 policy=\
read,write,policy,test source="# BEGIN SETUP\r\
\n#Change this to the name of your schedule (the date/time stamp is saved \
in the schedule's comment).\r\
\n:local scheduleName \"LogToEmail\"\r\
\n\r\
\n#Put your email address here.\r\
\n:local emailAddress \"dermawas@gmail.com\"\r\
\n\r\
\n#This currently detects two strings. It can be changed to more or less s\
trings if desired. Remove: || message~\"login failure\" if you only want t\
o use one string, or if you want more strings, add this same code at the e\
nd (but before the last two end brackets).\r\
\n:local startBuf [:toarray [/log find topics~\"error\" || topics~\"critic\
al\" || topics~\"system\" || topics~\"script\" || topics~\"gsm\" || topics\
~\"dhcp\" || topics~\"interface\" || topic~\"account\" || topic~\"pppoe\" \
]]\r\
\n\r\
\n#Edit the quoted items for strings you want to be filtered out of the re\
sults. For example, if you want all \"logged in\" logs found, but you do n\
ot want any of the \"logged in via telnet\" logs included, simply include \
the word \"telnet\" in the array and these logs will be excluded. Double q\
uote additional strings and separate them with semi-colons. If you don't w\
ant any logs filtered, simply declare the variable :local removeThese with\
out any curly braces. curly braces sample as follow {\"testing\";\"whateve\
r string you want\"}\r\
\n:local removeThese \r\
\n\r\
\n# END SETUP\r\
\n# warn if schedule does not exist\r\
\n:if ([:len [/system scheduler find name=\"\$scheduleName\"]] = 0) do={\r\
\n /log warning \"[LOGMON] ERROR: Schedule does not exist. Create schedul\
e and edit script to match name\"\r\
\n}\r\
\n# get last time\r\
\n:local lastTime [/system scheduler get [find name=\"\$scheduleName\"] co\
mment]\r\
\n# for checking time of each log entry\r\
\n:local currentTime\r\
\n# log message\r\
\n:local message\r\
\n# final output\r\
\n:local output\r\
\n:local keepOutput false\r\
\n# if lastTime is empty, set keepOutput to true\r\
\n:if ([:len \$lastTime] = 0) do={\r\
\n :set keepOutput true\r\
\n}\r\
\n:local counter 0\r\
\n# loop through all log entries that have been found\r\
\n:foreach i in=\$startBuf do={\r\
\n# loop through all removeThese array items\r\
\n :local keepLog true\r\
\n :foreach j in=\$removeThese do={\r\
\n# if this log entry contains any of them, it will be ignored\r\
\n :if ([/log get \$i message] ~ \"\$j\") do={\r\
\n :set keepLog false\r\
\n }\r\
\n }\r\
\n :if (\$keepLog = true) do={\r\
\n :set message [/log get \$i message]\r\
\n# LOG DATE\r\
\n# depending on log date/time, the format may be different. 3 known for\
mats\r\
\n# format of jan/01/2002 00:00:00 which shows up at unknown date/time. \
Using as default\r\
\n :set currentTime [ /log get \$i time ]\r\
\n# format of 00:00:00 which shows up on current day's logs\r\
\n :if ([:len \$currentTime] = 8 ) do={\r\
\n :set currentTime ([:pick [/system clock get date] 0 11].\" \".\$cur\
rentTime)\r\
\n } else={\r\
\n# format of jan/01 00:00:00 which shows up on previous day's logs\r\
\n :if ([:len \$currentTime] = 15 ) do={\r\
\n :set currentTime ([:pick \$currentTime 0 6].\"/\".[:pick [/syste\
m clock get date] 7 11].\" \".[:pick \$currentTime 7 15])\r\
\n }\r\
\n }\r\
\n# if keepOutput is true, add this log entry to output\r\
\n :if (\$keepOutput = true) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"\\r\\r\")\r\
\n }\r\
\n# if currentTime = lastTime, set keepOutput so any further logs found \
will be added to output\r\
\n# reset output in the case we have multiple identical date/time entrie\
s in a row as the last matching logs\r\
\n# otherwise, it would stop at the first found matching log, thus all f\
ollowing logs would be output\r\
\n :if (\$currentTime = \$lastTime) do={\r\
\n :set keepOutput true\r\
\n :set output \"\"\r\
\n }\r\
\n }\r\
\n# if this is last log entry\r\
\n :if (\$counter = ([:len \$startBuf]-1)) do={\r\
\n# If keepOutput is still false after loop, this means lastTime has a v\
alue, but a matching currentTime was never found.\r\
\n# This can happen if 1) The router was rebooted and matching logs stor\
ed in memory were wiped, or 2) An item is added\r\
\n# to the removeThese array that then ignores the last log that determi\
ned the lastTime variable.\r\
\n# This resets the comment to nothing. The next run will be like the fi\
rst time, and you will get all matching logs\r\
\n :if (\$keepOutput = false) do={\r\
\n# if previous log was found, this will be our new lastTime entry \
\_ \r\
\n :if ([:len \$message] > 0) do={\r\
\n :set output (\$output.\$currentTime.\" \".\$message.\"\\r\\r\")\
\r\
\n }\r\
\n }\r\
\n }\r\
\n :set counter (\$counter + 1)\r\
\n}\r\
\n# If we have output, save new date/time, and send email\r\
\nif ([:len \$output] > 0) do={\r\
\n /system scheduler set [find name=\"\$scheduleName\"] comment=\$current\
Time\r\
\n /tool e-mail send to=\"\$emailAddress\" subject=\"\\F0\\9F\\A4\\96 \\E\
2\\84\\B9 Marge alert \$currentTime\" body=\"\$output\"\r\
\n /log info \"[LOGMON] New logs found, sending email\"\r\
\n}\r\
\n#Other Notes, If you would rather run a script or whatever (instead of s\
ending email), simply remove the email config line at the top, and change \
the \"/tool email\" line near the bottom to do whatever you want.\r\
\n"
add dont-require-permissions=no name=NotifTGRouterOSUpdate owner=Seno@E3 \
policy=read,write,policy,test source="# Constants\r\
\n:local DeviceName [/system identity get name];\r\
\n:local MessageText \"%F0%9F%A4%96 <b>\$DeviceName: </b>%0A %E3%8A%99 \";\
\r\
\n\r\
\n\r\
\n# Check Update\r\
\n:local MyVar [/system package update check-for-updates as-value];\r\
\n:local Chan (\$MyVar -> \"channel\");\r\
\n:local InstVer (\$MyVar -> \"installed-version\");\r\
\n:local LatVer (\$MyVar -> \"latest-version\");\r\
\n\r\
\n\r\
\n:if (\$InstVer = \$LatVer) do={\r\
\n :set MessageText (\$MessageText . \"System OS is up to date\");\r\
\n} else={\r\
\n \r\
\n :set MessageText (\"\$MessageText New version \$LatVer is available\
! <a href=\\\"https://mikrotik.com/download/changelogs\\\">Changelogs</a>.\
\_[Installed version \$InstVer, Channel \$Chan].\");\r\
\n}\r\
\n #get TGBotSenderScript to send\r\
\n :local SendTelegramMessage [:parse [/system script get TGBotSenderS\
cript source]];\r\
\n \$SendTelegramMessage MessageText=\$MessageText;"
/tool e-mail
set address=smtp.gmail.com from=dermawas@gmail.com port=587 start-tls=yes \
user=dermawas@gmail.com
/tool mac-server
set allowed-interface-list=none
/tool mac-server mac-winbox
set allowed-interface-list=Admin
/tool netwatch
add down-script=":local DeviceName [/system identity get name];\r\
\n\r\
\n:local MessageText \"%F0%9F%A4%96 <b>\$DeviceName:</b><b>Internet conne\
ction is Down </b>\";\r\
\n\r\
\n#Create MSG Tosend\r\
\n:local SendTelegramMessage [:parse [/system script get TGBotSenderScrip\
t source]];\r\
\n\r\
\n#Create Script to get the sender to send Telegram msg\r\
\n\$SendTelegramMessage MessageText=\$MessageText;" host=8.8.8.8 \
up-script=":local DeviceName [/system identity get name];\r\
\n\r\
\n:local MessageText \"%F0%9F%A4%96 <b>\$DeviceName:</b>%F0%9F%8E%8A <b>I\
nternet connection is UP </b>\";\r\
\n\r\
\n#Create MSG Tosend\r\
\n:local SendTelegramMessage [:parse [/system script get TGBotSenderScrip\
t source]];\r\
\n\r\
\n#Create Script to get the sender to send Telegram msg\r\
\n\$SendTelegramMessage MessageText=\$MessageText;"