#!/usr/bin/perl #this software is licensed under the terms of the GNU General Public Licence (GPL) #author: Chris Sincock #version: 1.1 # #This script controls the red interface of a smoothwall box, as if you had #clicked on the 'connect' or 'disonnect' buttons on it's web page yourself. #It takes a single argument - Connect, Disconnect,Status or view # Connect tells the smoothwall to connect the interface # Disconnect tells it to disconnect the red interface # Status should print out Down or the uptime of the interface # view opens a web browser to the smoothwall status page #You will need to edit the variables at the top of this script. #Also, as I have written it, it is designed for Smoothwall version 2.0 beta, but #it should be very easy to change it to work with previous versions. # my $firewall="192.168.1.1"; my $port = 445; my $dialuser="admin"; my $dialpage="/cgi-bin/dial.cgi"; my $statuspage="/cgi-bin/index.cgi"; my $referrer="https://$firewall:$port$statuspage"; my $browser="galeon"; use Net::SSLeay qw(make_headers make_form post_https); use MIME::Base64; my ($action)=@ARGV; if(!$action) { print "usage: $0 Connect|Disconnect|Status|view\n"; } elsif($action =~ /^view$/i) { system("$browser https://$firewall:$port$statuspage &"); } elsif($action =~ /^(disconnect|connect)$/i ) { my $pass=&getPassword; chomp $pass; #get rid of newline at the end, if there is one my $auth='Basic ' . encode_base64("$dialuser:$pass",''); my $headers=make_headers(Authorization => $auth, referer => $referrer); my ($page, $response, %reply_headers) = post_https( $firewall, $port, $dialpage, $headers,make_form('ACTION' => $action) ); # print "page:$page\n"; # print "response:$response\n"; # print "reply headers:@reply_headers\n"; } else #if any other argument was given, just check the status { my $str=`lynx -dump https://$firewall:$port$statuspage | grep 'Connected \('` ; chomp $str; if(!$str) { print "Down\n"; } elsif($str =~ /(\d\d*)d (\d\d*)h (\d\d*)m (\d\d*)s/) { #I am not really interested in the seconds... print "$1d $2:$3\n"; } } sub getPassword() { #either return your password here, or generate it somehow return "password"; }