Add test scripts and backup-buttons script

This commit is contained in:
Pothi Kalimuthu 2022-11-10 12:35:50 +05:30
parent bf07a55ca5
commit a1a0489377
No known key found for this signature in database
GPG key ID: 08202A469C2D0E06
6 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,39 @@
# Backup button configurations - reset button, mode button.
# filename: backup-button-config
# policy: ftp, read, write, policy, test
:global adminEmail
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={
:log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
:local backupName "buttons"
:local fileName "$backupName.rsc"
:local emailStatus
:log info "\nCreating a $backupName backup..."
# remove existing file, if exists for unknown reason
/file remove [find name=$fileName]; :delay 1s
# export relevant info
/system routerboard
export file=$fileName
:delay 3s
/tool e-mail
:do { send to="$adminEmail" subject="Backup of $backupName" \
body="See the subject and the attachment." file=$fileName
} on-error={ :log error "Error sending email." }
:do { :delay 5s; :set emailStatus [get last-status] } while=( $emailStatus = "in-progress" )
:if ( $emailStatus = "failed" ) do={
:log error "Backup failed!"
} else={
:log info "Backup is taken and is sent to $adminEmail."
}
/file remove $fileName

3
test-snippets/README.md Normal file
View file

@ -0,0 +1,3 @@
# Test Snippets
These are not full-fledged scripts. Just snippets to test a single unit of action such as detecting internet or detecting DNS. I hope someone finds it useful!

View file

@ -0,0 +1,13 @@
# requirement: /interface detect-internet set detect-interface-list=WAN
/interface detect-internet
# set detect-interface-list=WAN
state
:do {
:log info "Waiting for internet..."
:set $internetStatus ([:pick [print as-value] 0]->"state")
:delay 3s
} while ($internetStatus != "internet")
:log info "Connected to internet."

View file

@ -0,0 +1,7 @@
:global adminEmail
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={ :log error "Admin Email is not defined or nil."; :error "Admin Email is not defined or nil."; } else={ :put "We are good to proceed!" }
# :if ($adminEmail = "") do={ :log error "Admin Email is nil."; :error "Admin Email is nil."; }
:put "This should not be visible if admin email is not defined or nil!"

View file

@ -0,0 +1,5 @@
:global myPassword;
:set myPassword [:pick ([/cert scep-server otp generate as-value minutes-valid=1]->"password") 0 20]
:put "Your new password is..."
:put $myPassword

12
test-snippets/test-log Normal file
View file

@ -0,0 +1,12 @@
# Email the generic-log when it reaches the threshold!
:global adminEmail
:local emailStatus
:local logFile "genericLog.1.txt"
:local fileContent "temp"
:do {
if ( [/file get "flash/$logFile" ] != "no such item" ) do={ :log info "Log file found!" }
} on-error={ :log warning "Log file isn't big enough!" }
:put $fileContent