i got sick of having to access my soho via my browser just to add a bunch of sites that i want to block (for fighting spam and the spread of desease) so threw together this script. let me know if there is anyway that i can optimize and/or make it prettier :)
use strict;
use LWP::Simple;
use LWP::UserAgent;
my %config = (
fw=>"IP_ADDRESS_OF_YOUR_WATCHGUARD",
usr=>"administrator",
pwd=>"ADMIN_PASSWORD"
);
my $toadd;
if (shift =~ /((\d{1,3}\.){3}\d{1,3}((-(\d{1,3}\.){3}\d{1,3})|\/\d{1,2
+})?)/){
$toadd = $1;
}else {
&showUsage;
}
sub showUsage{
die <<EOF
Correct usage is as follows:
newDeny.pl xxx.xxx.xxx.xxx
newDeny.pl xxx.xxx.xxx.xxx-xxx.xxx.xxx.xxx
newDeny.pl xxx.xxx.xxx.xxx/xx
EOF
}
my @virginPage = split /\n/, get "http://$config{usr}:$config{pwd}\@$c
+onfig{fw}/blksites.htm";
my @siteList;
map { push @siteList, ($1) if /<option>((\d{1,3}\.){3}\d{1,3}((-(\d{1,
+3}\.){3}\d{1,3})|\/\d{1,2})?)/i } @virginPage;
push @siteList, ($toadd);
my $postString = "result_ok=blksites.htm%3Fresult%3DOK&changed=1&refre
+sh=0&count=". ($#siteList+1) . "&";
$postString .= join "", map {"siteList=$_&"} @siteList;
$postString .= "addrType=blksites.htm%3FaddrType%3Dhost&addr=0.0.0.0&s
+ubmitBtn=Submit";
my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CL
+R 1.1.4322)');
my $req = HTTP::Request->new(POST => "http://$config{usr}:$config{pwd
+}\@$config{fw}/blksites.htm");
$req->content_type('application/x-www-form-urlencoded');
$req->content($postString);
my $res = $ua->request($req);
print $res->as_string;
c0s