I've been having trouble with firewalls lately on a few different servers. And im wanting to create a script that will run once every hour or so, and check a file on an external server and execute the relevant firewall rule set. As at the moment if SOMETHING happens to the firewall, and i get my ssh/etc blocked I have to schedule an onsite visit which is ridiculously expensive. So this will effectively be a failsafe system. If something goes wrong, i can use another server to initiate a change on the "broken" server and get it back to being able to be remotely managed. Bit haxy i know, but at my current Linux admin level should work out well.
I've never really done bash/sh scripting before, but im used to bat. So what im needing help with from the community is to turn this psudo code into something that might work:
$PATH = "/usr/firewall-scripts/temp/";
cd $PATH;
wget https://example.com/firewall/config/failsafe;
$FAILSAFE = readfile("$PATH/failtsafe");#This <--- im sure doesn't exist.
if($FAILSAFE == "1") {
/usr/firewall-scripts/failsafe.fw
}
else if ($FAILSAFE == "2") {
/usr/firewall-scripts/failsafe2.fw
}
else if ($FAILSAFE == "0") {
/usr/firewall-scripts/normal.fw
}
else if ($FAILSAFE == "-1") {
/usr/firewall-scripts/extra-secure.fw
}
The remote file would just have the numbers listed 1,2,0 or -1 (or something similar to these lines.
Its purely just a conditional tree/switch to execute different files.
Thanks in advance!
Note: Using a mixture of Mandrivia 2010.R2 / Ubuntu 10.04 / ClearOS, all have full sh and bash, incase that matters. Which it shouldn't.
EDIT: This is a hacky approach and there is probably far better (secure) ways to do this, but this is very light and simple.