Hello Folks
Can decent coders please advise on fix for the following script..
RB3011UIAS-RM
I used Chatgtp for the following code however I cannot see anything wrong myself.
VS Code with RouterOS (routeros) plugin cannot seem to find any faults during debugging too.
Error : executing script from scheduler failed, please check it manually (Winbox Log)
Idea of this was to use in scheduler to backup router information..
Script was to send DHCP Information via telegram and Email.
In addition it to send backup files - .backup / export.rsc and log.txt file.. and Supout.rif file..
=========
Device Report :
IP Address :
MAC Address :
IP Comment :
Device Identify - Router’s tag
Device Serial :
Current Firmware :
Latest Stable Firmware :
Netwatch State :
Noted : I want to implement telegram chat bot too… for cross interaction.
However i dont seem to manage it…
Please need help with other ideas for future plans.
1 →
However i too wanted to do 2MFA via email/telegram.. Got Google Authenticator on phone.
The idea is to have bot show the following information.
I made a telegram group with topics however could not get bot to send messages to set topics.
DHCP Lease - Active listing remotely of devices online.
Connection Tracking/Rogue IP - Notice of login attempts to router or other section of network ( valid and invalid) - > Username + Password IP address + Time
Logs - Active copy of current log
Internet-Allow list ( Would wanted to use telegram to interact with this list to enable/disable address list )
TrustedIPs - List of active trusted connections
Wake-Device - Want to use wake on lan / send alert notice to Security Camera/gate
2 →
Wireguard to network from external network - NATTED WAN uplink from ISP
Plan to vpn into home network which would allow internet access from there on..
-
Not sure if one can sub-dial another vpn as work allowed VPN from fixed public ip
Once can locate other hardware - was looking to perhaps use L2TP with other mikrotik devices.
3 - > Need more advanced firewalls / scripts
Using 3CX SMB want to access control via VOIP phones / Wiegand Access Panels
# Variables
:local ipAddress "";
:local macAddress "";
:local ipComment "";
:local deviceIdentity [/system identity get name];
:local deviceSerial [/system routerboard get serial-number];
:local currentFirmware [/system routerboard get current-firmware];
:local latestFirmware [/system routerboard get upgrade-firmware];
:local netwatchState "";
# Telegram configuration
:local telegramToken "xxxxxxxxx:xxxxxxxxxxxx"; # Change to API Token
:local chatID "-xxxxxxx"; # Change to Chat ID
# Email configuration
:local emailTo "admin@address.com"; # Replace with your email recipient
# Generate Backup File
:local backupFileName ("router-backup-" . [/system clock get date] . ".backup");
:execute {
/system backup save name=$backupFileName;
}
# Generate Export File
:local exportFileName ("router-export-" . [/system clock get date] . ".rsc");
:execute {
/export file=$exportFileName;
}
# Generate Supout File
:local supoutFileName ("router-supout-" . [/system clock get date] . ".rif");
:execute {
/system sup-output name=$supoutFileName;
}
# Generate Log File
:local logFileName ("router-log-" . [/system clock get date] . ".txt");
:execute {
/log print file=$logFileName;
}
# Get DHCP Lease information
:foreach lease in=[/ip dhcp-server lease find] do={
:set ipAddress [/ip dhcp-server lease get $lease address];
:set macAddress [/ip dhcp-server lease get $lease mac-address];
:set ipComment [/ip dhcp-server lease get $lease comment];
}
# Get Netwatch State
:foreach state in=[/tool netwatch find] do={
:set netwatchState [/tool netwatch get $state status];
}
# Compose message body
:local messageBody ("Device Report:\n" .
"IP Address: $ipAddress\n" .
"MAC Address: $macAddress\n" .
"IP Comment: $ipComment\n" .
"Device Identity: $deviceIdentity\n" .
"Device Serial: $deviceSerial\n" .
"Current Firmware: $currentFirmware\n" .
"Latest Stable Firmware: $latestFirmware\n" .
"Netwatch State: $netwatchState");
# Compose email subject
:local emailSubject ("MikroTik Device Report - IP: $ipAddress");
# Send Email with attachments
:do {
/tool e-mail send to=$emailTo subject=$emailSubject body=$messageBody file=$backupFileName;
/tool e-mail send to=$emailTo subject=$emailSubject body=$messageBody file=$exportFileName;
/tool e-mail send to=$emailTo subject=$emailSubject body=$messageBody file=$supoutFileName;
/tool e-mail send to=$emailTo subject=$emailSubject body=$messageBody file=$logFileName;
:log info "Email sent successfully with attachments to $emailTo.";
} on-error={
:log error "Failed to send email with attachments. Check email settings.";
}
# Send Files via Telegram
:local sendFileTelegram do={
:local filePath [/file get $1 name];
:local encodedFilePath [:uriEncode $filePath];
/tool fetch url=("https://api.telegram.org/bot" . $telegramToken . "/sendDocument?chat_id=" . $chatID) keep-result=no http-method=post file=$1;
}
# Send Backup File via Telegram
:do {
$sendFileTelegram $backupFileName;
} on-error={
:log error "Failed to send backup file via Telegram.";
}
# Send Export File via Telegram
:do {
$sendFileTelegram $exportFileName;
} on-error={
:log error "Failed to send export file via Telegram.";
}
# Send Supout File via Telegram
:do {
$sendFileTelegram $supoutFileName;
} on-error={
:log error "Failed to send supout file via Telegram.";
}
# Send Log File via Telegram
:do {
$sendFileTelegram $logFileName;
} on-error={
:log error "Failed to send log file via Telegram.";
}
# Cleanup files after sending
:foreach file in=[$backupFileName $exportFileName $supoutFileName $logFileName] do={
/file remove $file;
}
:log info "Temporary files cleaned up.";