Migrate scripts from mikrotik-scripts repo and make further improvements for the first commit!

This commit is contained in:
Pothi Kalimuthu 2022-11-06 10:28:02 +05:30
parent bd0215876c
commit 3d3ddb191b
No known key found for this signature in database
GPG key ID: 08202A469C2D0E06
7 changed files with 615 additions and 2 deletions

View file

@ -0,0 +1,29 @@
# Alert upon new firmware for LTE Modem
# Ref: https://wiki.mikrotik.com/wiki/Manual:Interface/LTE#Modem_firmware_upgrade
# requirement/s:
# policy: read, write, policy, test
# active internet
# $adminEmail
:global adminEmail
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={ :log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
:log info "\nChecking for new firmware for LTE Modem..."
:local lteFirmwareInfo [/interface lte firmware-upgrade lte1 as-value];
:local lteInstalledVer ($lteFirmwareInfo->"installed");
:local lteLatestVer ($lteFirmwareInfo->"latest");
:if ( $lteInstalledVer != $lteLatestVer ) do={
/tool e-mail send to="$adminEmail" subject="A new FIRMWARE update is available for (SXT) LTE." \
body=" LTE Installed Firmware Version: $lteInstalledVer
LTE Latest Firmware Version: $lteLatestVer"
:log info "A new firmware is available for LTE modem and an email is sent to '$adminEmail'."
} else={
:log info "No new firmware update for LTE."
:log info "LTE Installed Firmware Ver: $lteInstalledVer"
:log info " LTE Latest Firmware Ver: $lteLatestVer"
}

40
scripts/sim-toggle.rsc Normal file
View file

@ -0,0 +1,40 @@
# Toggle SIM Slot in LTE Modem.
# Applicable for RouterOS above 6.45.1
# see https://wiki.mikrotik.com/wiki/Dual_SIM_Application#Initial_settings
# see https://forum.mikrotik.com/viewtopic.php?f=13&t=159520&p=816964#p816964
:log info "\nSIM toggled by the script..."
/system routerboard modem
:local oldSlot [get sim-slot]
:local newSlot
:local oldOperator
:local newOperator
:if ( $oldSlot = "a" ) do={
:set $newSlot "b"
:set $oldOperator "BSNL"
:set $newOperator "Airtel"
} else={
:set $newSlot "a"
:set $oldOperator "Airtel"
:set $newOperator "BSNL"
}
set sim-slot=$newSlot
# Speed restrictions enable / disable
:if ( $newOperator = "Airtel" ) do={
/queue simple enable Airtel
/ip firewall filter disable [find action=fasttrack-connection]
} else={
/queue simple disable Airtel
/ip firewall filter enable [find action=fasttrack-connection]
}
:log warning "LTE SIM SLOT will change from $oldSlot to $newSlot";
:log warning "LTE SIM SLOT will change from $oldOperator to $newOperator";
:log info "Please hold on while switching SIM. Internet will come back in a few seconds."
:delay 2s

33
scripts/sms-to-email.rsc Normal file
View file

@ -0,0 +1,33 @@
# SMS to Email
# Source: https://forum.mikrotik.com/viewtopic.php?f=9&t=61068#p312202
# Note: The SMS is removed from the inbox after sent by Email and forwarded
# even if email and forward fail! So, test it often!
:global adminEmail
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={ :log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
:local smsPhone
:local smsMessage
:local smsTimeStamp
/tool sms inbox
:foreach receivedSMS in=[find] do={
:set smsPhone [get $receivedSMS phone]
:set smsMessage [get $receivedSMS message]
:set smsTimeStamp [get $receivedSMS timestamp]
:log info "\nSMS Received From: $smsPhone on $smsTimeStamp Message: $smsMessage"
# Send Email to $adminEmail
:do {
/tool e-mail send to="$adminEmail" body="$smsMessage" \
subject="SMS from $smsPhone at $smsTimeStamp"
} on-error={ :log error "SMS to Email Failed." }
:delay 3s
# Let's remove the SMS!
remove $receivedSMS
}

34
scripts/sms-to-sms.rsc Normal file
View file

@ -0,0 +1,34 @@
# SMS to SMS
# Limitation: It doesn't forward the full SMS message. It forwards the actual message, but doesn't forward the senderPhoneNumber or timestamp of received SMS. So, it doesn't remove the SMS and the SMS is removed only by the other script (sms-to-email).
# Source: https://forum.mikrotik.com/viewtopic.php?f=9&t=61068#p312202
:global adminPh
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={ :log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
:local smsForwardPh $adminPh
:if ([:typeof $adminPh] = "nothing" || $adminPh = "") do={ :log error "adminPh is not defined or nil."; :error "Error: Check the log"; }
:local smsPhone
:local smsMessage
:local smsTimeStamp
/tool sms inbox
:foreach receivedSMS in=[find] do={
:set smsPhone [get $receivedSMS phone]
:set smsMessage [get $receivedSMS message]
:set smsTimeStamp [get $receivedSMS timestamp]
:log info "\nSMS Received From: $smsPhone on $smsTimeStamp Message: $smsMessage"
# Forward the SMS to $smsForwardPh, without $smsPhone and smsTimeStamp
:do {
/tool sms send lte1 phone-number=$smsForwardPh message=$smsMessage
} on-error={ :log error "SMS to SMS Failed." }
:delay 2s
# *** Let's NOT remove the SMS! ***
# Let the other script (SMS to Email) remove it, after sending the message with *full details*.
# remove $receivedSMS
}