diff --git a/RouterOS_Config_Fetch.rsc b/RouterOS_Config_Fetch.rsc new file mode 100644 index 0000000..023945f --- /dev/null +++ b/RouterOS_Config_Fetch.rsc @@ -0,0 +1,65 @@ +# RouterOS Function +# Copyright (c) Grzegorz Budny +# Version 1.0 +# Last update: 22/22/2020 +# Fetches RouterOS script (dedicated for initial config) adds scheduler entry to start it on startup + +:global FetchConfig do={ + + :log info "...:::Configuration fetch process started:::..."; + + :do { + + /tool fetch address=$repositoryIP user=$userName password=$password \ + port=21 mode=ftp src-path=($sourcePath.$sourceFileName) dst-path=($destinationPath.$destinationFileName); + + } on-error={ + + :put "An error occured when dowloading configuration file!"; + :log critical "...:::An error occured when dowloading configuration file!:::..."; + + }; + + :if($isRun)do={ + + :do { + + :log info "...:::Configuration import started:::..."; + /import ($destinationPath.$destinationFileName); + + } on-error={ + + :put "An error occured during configuration import!"; + :log critical "...:::An error occured during configuration import!:::..."; + + }; + + :delay 5; + :log warning "...:::Import secessful. Rebooting device:::..."; + /system reboot; + + }\ + else={ + + :log info "...:::Configuring import on startup:::..."; + + :do { + + /system scheduler \ + add interval=($interval.h) name=$taskName on-event=("system script run ".($destinationPath.$destinationFileName)) \ + policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \ + start-date=jan/01/1970 start-time=$startTime; + + } on-error={ + + :put "An error occured during import job schedule!"; + :log critical "...:::An error occured during import job schedule!:::..."; + + } + + :log info "...:::Configuration job scheduled for next startup!:::..."; + + } +} + +FetchConfig isRun=true; \ No newline at end of file diff --git a/RouterOS_Measure_Execution_Time.rsc b/RouterOS_Measure_Execution_Time.rsc new file mode 100644 index 0000000..493bba6 --- /dev/null +++ b/RouterOS_Measure_Execution_Time.rsc @@ -0,0 +1,32 @@ +# RouterOS Function +# Copyright (c) Grzegorz Budny +# Version 1.0 +# Last update: 3/22/2020 +# Measures script execution time + +:global MeasureExecutionTime do={ + + :local timeDifferance; + :local startTime [/system clock get time]; + + /system script run $scriptName; + + :local endTime [/system clock get time] + :set $timeDifferance ($endTime-$startTime); + + :if($return) do={ + + :return $timeDifferance; + + }\ + else={ + + :put ("Script executed in : ".$timeDifferance); + + } + + :set $timeDifferance; + +} + +$MeasureExecutionTime scriptName=scriptName return=true; \ No newline at end of file diff --git a/RouterOS_RB750GR3_DUDE_Setup.rsc b/RouterOS_RB750GR3_DUDE_Setup.rsc new file mode 100644 index 0000000..9e48f94 --- /dev/null +++ b/RouterOS_RB750GR3_DUDE_Setup.rsc @@ -0,0 +1,42 @@ +# RouterOS Function +# Copyright (c) Grzegorz Budny +# Version 1.0 +# Last update: 3/23/2020 +# DUDE Server initial setup on RB750GR3 with microSD or USB drive + +:global SetupDudeRB750GR3 do={ + + :local isDude [/system packages find name=dude]; + + :if ($isDude) do={ + + :log info "...:::Started DUDE Server Setup:::..."; + :log warning "...:::Formatting drive:::..."; + + /disk eject-drive $driveNumber; + + :do { + + /disk format-drive $driveNumber file-system=ext3 label=$driveLabel; + + } on-error={ + + :log critical "...:::Formatting failed. Check your drive:::..."; + + } + + :log info "...:::Formatting finished:::..."; + + /dude set data-directory=$dudeDirectory; + /dude set enabled=yes; + + }\ + else={ + + :log critical "...:::Setup failed. Install DUDE package first:::..."; + + } +} + + +$SetupDudeRB750GR3 driveNumber=driveNumber driveLabel=driveLabel dudeDirectory=directoryName; \ No newline at end of file