Auto Login Failure Notification Telegram
Auto Login Function of wifi vendo systems for Mikrotik based paperless voucher may fail. For some technical reasons, it is not 100% of the time, users phone auto login is successful but it will successfully create a voucher code to the mikrotik. JuanFi System will save the voucher code in text box but some users closed the browser and the voucher saved erased. This tutorial is for us to be notified in case there is a voucher code created by wifi vendo but didn't login or unsuccessfully do the auto login function.
Mikrotik Terminal
/system script
add comment=1 dont-require-permissions=no name=userlist owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="0"
/system schedule
add interval=10s name=userlist on-event="###replace telegram token\r\
\n:local telegramToken \"your token\";\
\r\
\n###replace telegram chat id / group id\r\
\n:local chatId \"your chat id\";\r\
\n###replace your voucher code prefix\r\
\n:local prefN \"R\";\r\
\n:local string;\r\
\n:local stringN \"0\";\r\
\n:global notifu \"\";\r\
\n:local usercountN [/ip hotspot user print count-only];\r\
\n:local usercountO [/sys scr get [find where name=userlist] comment];\r\
\n:if (\$usercountN < \$usercountO) do={ \r\
\n:foreach fu in=[/ip hotspot user find] do={\r\
\n:if ([/ip hots user get \$fu comment] != \"\" and [:pick [/ip hots user \
get \$fu name] 0 [:len \$prefN]] = \$prefN) do={ \r\
\n:set \$stringN (\"\$stringN;\".[/ip hots user get \$fu name]);\r\
\n}}\r\
\n/sys scr set [find where name=userlist] source=\$stringN;/sys scr set [f\
ind where name=userlist] comment=\$usercountN;} \r\
\n\r\
\n:if (\$usercountN > \$usercountO) do={\r\
\n:foreach fu in=[/ip hotspot user find] do={\r\
\n:if ([/ip hots user get \$fu comment] != \"\" and [:pick [/ip hots user \
get \$fu name] 0 [:len \$prefN]] = \$prefN) do={ \r\
\n:set \$stringN (\"\$stringN;\".[/ip hots user get \$fu name]);\r\
\n}}\r\
\n\r\
\n:delay 3s;\r\
\n:foreach fo in=[/ip hotspot user find] do={\r\
\n:if ([/ip hots user get \$fo comment] != \"\" and [:pick [/ip hots user \
get \$fo name] 0 [:len \$prefN]] = \$prefN) do={ \r\
\n:set \$string [/ip hots user get \$fo name];\r\
\n:delay 100ms;\r\
\n\$matcher \$string;\r\
\n}}\r\
\n\r\
\n:global matcher do={\r\
\n:local ulist [/sys scr get [find where name=userlist] source];\r\
\n:if (\$ulist~\"\$1(;|\\\$)\") do={\r\
\n:set notifu \"failed\";\r\
\n} else={\r\
\n:set \$notifu \$1;\r\
\n}\r\
\n}}\r\
\n:if (\$notifu != \"failed\") do={:if ([/sys sche find name=\$notifu]) do\
={} else={\r\
\n:local com [/ip hots user get [find where name=\$notifu] comment];\r\
\n:local infoArray [:toarray [:pick \$com ([:find \$com \",\"]+1) [:len \$\
com]]];\r\
\n:local amt [:pick \$infoArray 0];\r\
\n /tool fetch url=\"https://api.telegram.org/bot\$telegramToken/sendmessa\
ge\?chat_id=\$chatId&text=<<===Failed User Login===>> %0A User: \$notifu %\
0AAmount: \$amt %0A<<====================>>\" keep-result=no;}}\r\
\n/sys scr set [find where name=userlist] source=\$stringN;/sys scr set [f\
ind where name=userlist] comment=\$usercountN;\r\
\n}\r\
\n" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=sep/04/2022 start-time=01:42:36
Note: Edit system > scheduler > userlist find the telegram token and chat id then replace yours. On voucher code prefix change what you use, for my case is "R", find in userlist scheduler the :local prefN "your prefix here";
Comments
Post a Comment