#!/usr/bin/perl -w #this software is licensed under the terms of the GNU General Public Licence (GPL) #author: Chris Sincock #version: 1.1 # #This script creates an applet for the gnome panel which shows the status of #your smoothwall box with a smiley or sad face. If you click on the applet #you get a popup window with a choice of options for managing your smoothwall #such as disconnecting or connecting the red interface, or opening your web #browser to view the smoothwalls internal web pages. #The actual control of the smoothwall is done using my accomanying chilli_control #script, and the popup is done using my pgprompt script. # #You will need to edit the chilli_control script to suit your smoothwall setup. # use Gnome; use Gnome::Applet; use strict; my $updatePeriod=30; #in seconds #build the applet init Gnome::AppletWidget "chilli_applet"; my $applet = new Gnome::AppletWidget "chilli_applet"; my $button = new Gtk::Button("?"); $applet->add($button); show $button; show $applet; #add signals, etc $button->signal_connect ("clicked", \&popupControl); $applet->register_callback("Connect", "Connect", sub { system("chilli_control Connect");} ); $applet->register_callback("Disconnect", "Disconnect", sub { system("chilli_control Disconnect");} ); $applet->register_callback("Manage", "Manage", sub { system("chilli_control view"); } ); Gtk->timeout_add($updatePeriod * 1000, sub { &checkChilli; return 1;} ); #do an immediate check, then start the event loop &checkChilli; gtk_main Gnome::AppletWidget; #checks the smoothwall, updates the text shown in the applet,then #return 1 if the smoothwall's red interface is up, 0 if it is down sub checkChilli { my $str=`chilli_control Refresh`; chomp $str; my $ok = $str ne "Down"; my $displayString=$ok ? ":)" : ":("; $button->child->set($displayString); return $ok; } #pops up a window with Connect,Disconnect,Refresh buttons etc sub popupControl { my $cont=1; while ($cont) { my $status=`chilli_control Refresh`; chomp $status; my $buttons="Connect/Disconnect/Refresh/Manage/Exit"; my $choice=`pgprompt "TITLE=Chilli Control" "MESSAGE=$status" BUTTONS="$buttons" CANCEL=Exit BUTTONSEP=/ tell`; chomp $choice; if($choice eq "Exit") { $cont=0; } elsif($choice eq "Refresh") { $cont=1; } elsif($choice eq "Manage") { $cont=0; system("chilli_control view"); } elsif($choice eq "Connect") { system("chilli_control Connect"); sleep 3; $cont = checkChilli; } elsif($choice eq "Disconnect") { system("chilli_control Disconnect"); $cont = ! checkChilli; } } }