#!/usr/bin/php timeout=1; $localhost->packetsize=32; $localhost->samplesize=1; $localhost->ping(); if($localhost->rtlatency<0) { echo "I cant ping myself ?!?!\n"; echo "Quitting....\n"; exit(); } if($localhost->rtlatency>1) { echo "Its taking more than 1ms to ping myself ?\n"; echo "Quitting....\n"; exit(); } // Load libraries if(!class_exists('gtk')) { if($windows) $lib='php_gtk.dll'; else $lib='php_gtk.so'; if(!dl($lib)) { echo "I cant find the library $lib !\n"; echo "Quitting....\n"; exit(); } } //-------------------MAIN WINDOW------------------- // Create images $xpm_active=array("16 16 4 1", " c None s None", ". c black", "X c red", "o c white", " ", " ", " ..... ", " .XXXXX. ", " .XXXXXoX. ", " .XXXXXXXoX. ", " .XXXXXXXXXoX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXX. ", " .XXXXXXX. ", " .XXXXX. ", " ..... ", " "); $xpm_inactive=array("16 16 4 1", " c None s None", ". c black", "X c grey", "o c white", " ", " ", " ..... ", " .XXXXX. ", " .XXXXXoX. ", " .XXXXXXXoX. ", " .XXXXXXXXXoX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXXXX. ", " .XXXXXXXXX. ", " .XXXXXXX. ", " .XXXXX. ", " ..... ", " "); $c_transparent = &new GdkColor(0, 0, 0); list($pixmap_active, $mask_active)=Gdk::pixmap_create_from_xpm_d(NULL, $c_transparent, $xpm_active); list($pixmap_inactive, $mask_inactive)=Gdk::pixmap_create_from_xpm_d(NULL, $c_transparent, $xpm_inactive); // Create Fonts if($windows) { $font=gdk::font_load('-unknown-Arial-bold-r-normal--*-100-*-*-p-0-iso8859-1'); $reportfont=gdk::font_load('-unknown-courier-meduim-r-normal--*-120-*-*-m-0-iso8859-1'); } else { $font=gdk::font_load('-unknown-Arial-bold-r-normal--*-100-*-*-p-0-iso8859-1'); $reportfont=gdk::font_load('-unknown-courier-medium-r-normal--*-120-*-*-m-0-iso8859-1'); } // Create Styles $defaultstyle=&new GtkStyle(); $defaultstyle->bg[GTK_STATE_NORMAL]=new GdkColor('#EEEEEE'); $defaultstyle->font=$font; $buttonstyle=&new GtkStyle(); $buttonstyle->bg[GTK_STATE_NORMAL]=new GdkColor('#E1E1E1'); $buttonstyle->font=$font; $warningstyle=&new GtkStyle(); $warningstyle->fg[GTK_STATE_NORMAL]=new GdkColor('#FF0000'); $warningstyle->font=$font; $sitestyle=&new GtkStyle(); $sitestyle->fg[GTK_STATE_NORMAL]=new GdkColor('#0000FF'); $sitestyle->font=$font; gtk::widget_set_default_style($defaultstyle); // Create List Colours $c_normal=new GdkColor('#008000'); $s_normal=&new GtkStyle(); $s_normal->fg[GTK_STATE_NORMAL]=$c_normal; $s_normal->font=$font; $c_acceptable=new GdkColor('#000000'); $s_acceptable=&new GtkStyle(); $s_acceptable->fg[GTK_STATE_NORMAL]=$c_acceptable; $s_acceptable->font=$font; $c_warning=new GdkColor('#B07000'); $s_warning=&new GtkStyle(); $s_warning->fg[GTK_STATE_NORMAL]=$c_warning; $s_warning->font=$font; $c_failed=new GdkColor('#C00000'); $s_failed=&new GtkStyle(); $s_failed->fg[GTK_STATE_NORMAL]=$c_failed; $s_failed->font=$font; $c_normal_bg=new GdkColor('#FFFFFF'); $c_warning_bg=new GdkColor('#FFA0A0'); $c_failed_bg=new GdkColor('#FF5050'); // Create tool tips $tooltips=&new GtkTooltips(); $tooltips->set_delay(200); $tooltips->enable(); // Create not yet implimented window $notimplimented=&new dialogue_box(1, "conTest", "Sorry this function is not available yet."); // Create main window $window=&new GtkWindow(); $window->connect_object('delete_event', 'save_changes'); $window->connect_object('destroy', array('gtk', 'main_quit')); $window->set_title('conTest'); $window->set_border_width(10); $mainbox=&new GtkVBox(false,5); $window->add($mainbox); // Create Status indicators $statusbox=&new GtkHBox(false,5); $pingstatus=&new GtkPixmap($pixmap_inactive, $mask_inactive); $statusbox->pack_end($pingstatus, false, false); $pinglabel=&new GtkLabel('Ping'); $statusbox->pack_end($pinglabel, false, false); $spacer=&new GtkLabel(' '); $statusbox->pack_end($spacer, false, false); $emailstatus=&new GtkPixmap($pixmap_inactive, $mask_inactive); $statusbox->pack_end($emailstatus, false, false); $emaillabel=&new GtkLabel('Email Level Reached'); $statusbox->pack_end($emaillabel, false, false); $spacer=&new GtkLabel(' '); $statusbox->pack_end($spacer, false, false); $emailsentstatus=&new GtkPixmap($pixmap_inactive, $mask_inactive); $statusbox->pack_end($emailsentstatus, false, false); $emailsentlabel=&new GtkLabel('Email Sent'); $statusbox->pack_end($emailsentlabel, false, false); // Load data $allsites=&new sitearray; $allsites->load("conTest-sites.xml"); // Add data and status to main window $mainbox->add($allsites->widget); $mainbox->pack_end($statusbox, false, false); // Display the window $window->show_all(); //Debug //gtk::timeout_add(2000, array(&$allsites, 'show')); // Start GTK gtk::main(); //-------------------SERVER CLASS------------------- class server { var $dnsname; var $ip; var $latency; var $rtlatency; var $loss; var $stats; // Latency array var $timeout; var $packetsize; var $samplesize; var $maxloss; // Array for notification levels var $maxlatency; // Array for notification levels // Server Constructor function server($dnsname, $ip) { $this->dnsname=$dnsname; $this->ip=$ip; $this->latency=-1; $this->rtlatency=-1; $this->loss=-1; $this->stats=array(); $this->timeout=-1; $this->packetsize=-1; $this->samplesize=-1; $this->maxloss=array(-1, -1, -1, -1); $this->maxlatency=array(-1, -1, -1, -1); } // Edit Server function edit(&$clist, $row) { global $sitestyle, $buttonstyle; global $s_normal, $s_acceptable, $s_warning, $s_failed; $window=&new GtkWindow(); $window->set_title('Edit Server'); $window->set_border_width(10); $vbox=&new GtkVBox(false,5); $window->add($vbox); // Server Box $serverbox=&new GtkFrame('Server'); $serverbox->set_style($sitestyle); $vbox->add($serverbox); $servertable=&new GtkTable(2, 2, false); $servertable->set_row_spacings(5); $servertable->set_col_spacings(5); $servertable->set_border_width(10); $serverbox->add($servertable); $l_dnsname=&new GtkLabel('Hostname'); $servertable->attach($l_dnsname, 0, 1, 0, 1); $e_dnsname=&new GtkEntry(); $e_dnsname->set_max_length(50); $e_dnsname->set_text($this->dnsname); $servertable->attach($e_dnsname, 1, 2, 0, 1); $l_ip=&new GtkLabel('IP Address'); $servertable->attach($l_ip, 0, 1, 1, 2); $e_ip=&new GtkEntry(); $e_ip->set_max_length(15); $e_ip->set_text($this->ip); $servertable->attach($e_ip, 1, 2, 1, 2); // Ping Box $pingbox=&new GtkFrame('Ping'); $pingbox->set_style($sitestyle); $vbox->add($pingbox); $pingtable=&new GtkTable(2, 3, false); $pingtable->set_row_spacings(5); $pingtable->set_col_spacings(5); $pingtable->set_border_width(10); $pingbox->add($pingtable); $l_packetsize=&new GtkLabel('Packet Size'); $pingtable->attach($l_packetsize, 0, 1, 0, 1); $a_packetsize=&new GtkAdjustment(32, 1, 1024, 1, 32, 32); $e_packetsize=&new GtkSpinButton($a_packetsize, 0, 0); $e_packetsize->set_value($this->packetsize); $pingtable->attach($e_packetsize, 1, 2, 0, 1); $u_packetsize=&new GtkLabel('bytes'); $pingtable->attach($u_packetsize, 2, 3, 0, 1); $l_timeout=&new GtkLabel('Timeout'); $pingtable->attach($l_timeout, 0, 1, 1, 2); $a_timeout=&new GtkAdjustment(1, 1, 10, 1, 1, 1); $e_timeout=&new GtkSpinButton($a_timeout, 0, 0); $e_timeout->set_value($this->timeout); $pingtable->attach($e_timeout, 1, 2, 1, 2); $u_timeout=&new GtkLabel('seconds'); $pingtable->attach($u_timeout, 2, 3, 1, 2); // Stats Box $statsbox=&new GtkFrame('Stats'); $statsbox->set_style($sitestyle); $vbox->add($statsbox); $statstable=&new GtkTable(2, 3, false); $statstable->set_row_spacings(5); $statstable->set_col_spacings(5); $statstable->set_border_width(10); $statsbox->add($statstable); $l_samplesize=&new GtkLabel('Sample Size'); $statstable->attach($l_samplesize, 0, 1, 0, 1); $a_samplesize=&new GtkAdjustment(30, 1, 100000, 1, 10, 10); $e_samplesize=&new GtkSpinButton($a_samplesize, 0, 0); $e_samplesize->set_value($this->samplesize); $statstable->attach($e_samplesize, 1, 2, 0, 1); $u_samplesize=&new GtkLabel('echo requests'); $statstable->attach($u_samplesize, 2, 3, 0, 1); $l_samples=&new GtkLabel('Sample Count'); $statstable->attach($l_samples, 0, 1, 1, 2); $e_samples=&new GtkLabel(count($this->stats)); $statstable->attach($e_samples, 1, 2, 1, 2); $u_samples=&new GtkLabel('echo requests'); $statstable->attach($u_samples, 2, 3, 1, 2); // Notify Levels Box $notifybox=&new GtkFrame('Notification Levels'); $notifybox->set_style($sitestyle); $vbox->add($notifybox); $notifytable=&new GtkTable(4, 5, false); $notifytable->set_row_spacings(5); $notifytable->set_col_spacings(5); $notifytable->set_border_width(10); $notifybox->add($notifytable); $l_normal=&new GtkLabel('Normal Maximum'); $l_normal->set_style($s_normal); $notifytable->attach($l_normal, 0, 1, 0, 1); $a_normalloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_normalloss=&new GtkSpinButton($a_normalloss, 0, 0); $e_normalloss->set_value($this->maxloss[1]); $notifytable->attach($e_normalloss, 1, 2, 0, 1); $u_normalloss=&new GtkLabel('% loss, '); $u_normalloss->set_style($s_normal); $notifytable->attach($u_normalloss, 2, 3, 0, 1); $a_normallatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_normallatency=&new GtkSpinButton($a_normallatency, 0, 0); $e_normallatency->set_value($this->maxlatency[1]); $notifytable->attach($e_normallatency, 3, 4, 0, 1); $u_normallatency=&new GtkLabel('ms latency'); $u_normallatency->set_style($s_normal); $notifytable->attach($u_normallatency, 4, 5, 0, 1); $l_acceptable=&new GtkLabel('Acceptable Maximum'); $l_acceptable->set_style($s_acceptable); $notifytable->attach($l_acceptable, 0, 1, 1, 2); $a_acceptableloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_acceptableloss=&new GtkSpinButton($a_acceptableloss, 0, 0); $e_acceptableloss->set_value($this->maxloss[2]); $notifytable->attach($e_acceptableloss, 1, 2, 1, 2); $u_acceptableloss=&new GtkLabel('% loss, '); $u_acceptableloss->set_style($s_acceptable); $notifytable->attach($u_acceptableloss, 2, 3, 1, 2); $a_acceptablelatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_acceptablelatency=&new GtkSpinButton($a_acceptablelatency, 0, 0); $e_acceptablelatency->set_value($this->maxlatency[2]); $notifytable->attach($e_acceptablelatency, 3, 4, 1, 2); $u_acceptablelatency=&new GtkLabel('ms latency'); $u_acceptablelatency->set_style($s_acceptable); $notifytable->attach($u_acceptablelatency, 4, 5, 1, 2); $l_warning=&new GtkLabel('Warning Maximum'); $l_warning->set_style($s_warning); $notifytable->attach($l_warning, 0, 1, 2, 3); $a_warningloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_warningloss=&new GtkSpinButton($a_warningloss, 0, 0); $e_warningloss->set_value($this->maxloss[3]); $notifytable->attach($e_warningloss, 1, 2, 2, 3); $u_warningloss=&new GtkLabel('% loss, '); $u_warningloss->set_style($s_warning); $notifytable->attach($u_warningloss, 2, 3, 2, 3); $a_warninglatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_warninglatency=&new GtkSpinButton($a_warninglatency, 0, 0); $e_warninglatency->set_value($this->maxlatency[3]); $notifytable->attach($e_warninglatency, 3, 4, 2, 3); $u_warninglatency=&new GtkLabel('ms latency'); $u_warninglatency->set_style($s_warning); $notifytable->attach($u_warninglatency, 4, 5, 2, 3); $l_failed=&new GtkLabel('Failed Maximum'); $l_failed->set_style($s_failed); $notifytable->attach($l_failed, 0, 1, 3, 4); $e_failedloss=&new GtkLabel('100'); $notifytable->attach($e_failedloss, 1, 2, 3, 4); $u_failedloss=&new GtkLabel('% loss, '); $u_failedloss->set_style($s_failed); $notifytable->attach($u_failedloss, 2, 3, 3, 4); $e_failedlatency=&new GtkLabel($this->timeout*1000); $notifytable->attach($e_failedlatency, 3, 4, 3, 4); $u_failedlatency=&new GtkLabel('ms latency'); $u_failedlatency->set_style($s_failed); $notifytable->attach($u_failedlatency, 4, 5, 3, 4); // Email Box $emailbox=&new GtkFrame('Email Levels'); $emailbox->set_style($sitestyle); $vbox->add($emailbox); $emailtable=&new GtkTable(1, 5, false); $emailtable->set_row_spacings(5); $emailtable->set_col_spacings(5); $emailtable->set_border_width(10); $emailbox->add($emailtable); $l_email=&new GtkLabel('Email Report Trigger'); $emailtable->attach($l_email, 0, 1, 0, 1); $a_emailloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_emailloss=&new GtkSpinButton($a_emailloss, 0, 0); $e_emailloss->set_value($this->maxloss[0]); $emailtable->attach($e_emailloss, 1, 2, 0, 1); $u_emailloss=&new GtkLabel('% loss, '); $emailtable->attach($u_emailloss, 2, 3, 0, 1); $a_emaillatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_emaillatency=&new GtkSpinButton($a_emaillatency, 0, 0); $e_emaillatency->set_value($this->maxlatency[0]); $emailtable->attach($e_emaillatency, 3, 4, 0, 1); $u_emaillatency=&new GtkLabel('ms latency'); $emailtable->attach($u_emaillatency, 4, 5, 0, 1); // Buttons $buttonbox=&new GtkHBox('true', 5); $vbox->add($buttonbox); $b_ok=&new GtkButton('OK'); $b_ok->connect_object('clicked', array(&$this, 'apply'), $e_dnsname, $e_ip, $e_packetsize, $e_timeout, $e_samplesize, $e_samples, $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, $e_emailloss, $e_emaillatency, &$clist, $row); $b_ok->connect_object('clicked', array($window, 'destroy')); $b_ok->set_style($buttonstyle); $buttonbox->add($b_ok); $b_cancel=&new GtkButton('Cancel'); $b_cancel->set_style($buttonstyle); $b_cancel->connect_object('clicked', array($window, 'destroy')); $buttonbox->add($b_cancel); $b_apply=&new GtkButton('Apply'); $b_apply->connect_object('clicked', array(&$this, 'apply'), $e_dnsname, $e_ip, $e_packetsize, $e_timeout, $e_samplesize, $e_samples, $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, $e_emailloss, $e_emaillatency, &$clist, $row); $b_apply->set_style($buttonstyle); $buttonbox->add($b_apply); $window->show_all(); } // Apply changes function apply( $dnsname, $ip, $packetsize, $timeout, $samplesize, $samples, $normalloss, $normallatency, $acceptableloss, $acceptablelatency, $warningloss, $warninglatency, $emailloss, $emaillatency, &$clist, $row) { if($this->ip!=$ip->get_text()) { $this->stats=array(); $samples->set_text('0'); $clist->set_text($row, 2, ''); $clist->set_text($row, 3, ''); $clist->set_text($row, 4, ''); } $this->dnsname=$dnsname->get_text(); $this->ip=$ip->get_text(); $this->packetsize=$packetsize->get_text(); $this->timeout=$timeout->get_text(); $this->samplesize=$samplesize->get_text(); $this->maxloss[0]=$emailloss->get_text(); $this->maxloss[1]=$normalloss->get_text(); $this->maxloss[2]=$acceptableloss->get_text(); $this->maxloss[3]=$warningloss->get_text(); $this->maxlatency[0]=$emaillatency->get_text(); $this->maxlatency[1]=$normallatency->get_text(); $this->maxlatency[2]=$acceptablelatency->get_text(); $this->maxlatency[3]=$warninglatency->get_text(); // Update screen $clist->set_text($row, 0, $this->dnsname); $clist->set_text($row, 1, $this->ip); } // Update Server function update(&$clist, $row) { global $c_normal, $c_acceptable, $c_warning, $c_failed; global $c_normal_bg, $c_warning_bg, $c_failed_bg; global $pingstatus, $pixmap_active, $mask_active, $pixmap_inactive, $mask_inactive; // Set ping status display $pingstatus->set($pixmap_active, $mask_active); update_screen(); // Run Ping $this->ping(); // Set ping status display $pingstatus->set($pixmap_inactive, $mask_inactive); update_screen(); $this->loss=0; $this->latency=0; // Add up loss and latency foreach($this->stats as $stat) { if($stat<0) $this->loss++; else $this->latency+=$stat; } // If its not 100% loss workout the average latency if($this->loss!=count($this->stats)) $this->latency=$this->latency/(count($this->stats)-$this->loss); else $this->latency=-1; // Work out average percentage loss if(count($this->stats)) $this->loss=($this->loss*100)/count($this->stats); else $this->loss=-1; $clist->set_text($row, 2, display_stats($this->rtlatency, 0, "ms")); $clist->set_text($row, 3, display_stats($this->latency, 0, "ms")); $clist->set_text($row, 4, display_stats($this->loss, 1, "%")); // Set Foreground if(($this->loss<=$this->maxloss[1]) && ($this->latency<=$this->maxlatency[1])) $clist->set_foreground($row, $c_normal); else if(($this->loss<=$this->maxloss[2]) && ($this->latency<=$this->maxlatency[2])) $clist->set_foreground($row, $c_acceptable); else if(($this->loss<=$this->maxloss[3]) && ($this->latency<=$this->maxlatency[3])) $clist->set_foreground($row, $c_warning); else $clist->set_foreground($row, $c_failed); // Set Background if($this->rtlatency<0) $clist->set_background($row, $c_failed_bg); // Failed: Instantaneous Loss else if($this->rtlatency<=$this->maxlatency[2]) $clist->set_background($row, $c_normal_bg); // Acceptable: Low Instantaneous Latency else $clist->set_background($row, $c_warning_bg); // Warning: High Instantaneous Latency // Set status if(($this->latency>=$this->maxlatency[0]) || ($this->loss>=$this->maxloss[0])) return 1; else return 0; } // Ping This Server function ping() { global $windows; if($windows) $command='ping -n 1 -w '.($this->timeout*1000).' -l '.$this->packetsize." ".$this->ip; else $command="ping -c 1 -w ".$this->timeout." -s ".$this->packetsize." ".$this->ip; // Run ping command $trace=`$command`; // Get Loss preg_match("/([0-9]+)%/i",$trace, $loss); // Get Latency if($loss[1]!=0) $latency[1]=-1; else { if($windows) preg_match("/Average = ([0-9]+\.?[0-9]*)ms/i",$trace, $latency); else preg_match("/[0-9]+\.?[0-9]*\/([0-9]+\.?[0-9]*)\/[0-9]+\.?[0-9]*\/[0-9]+\.?[0-9]* ms/i",$trace, $latency); } // Add new latency to stats $this->stats[]=$latency[1]; // Remove old latency stats off the bottom while(count($this->stats)>$this->samplesize) array_shift($this->stats); $this->rtlatency=$latency[1]; return true; } // Server Debug Display function show() { echo "Hostname: $this->dnsname\n"; echo "IP: $this->ip\n"; echo "Latency: $this->latency\n"; echo "Loss: $this->loss\n"; echo "Sample Size: $this->samplesize\n"; echo "Samples Stored: ".count($this->stats)."\n"; echo "Timeout: $this->timeout\n"; echo "Packetsize: $this->packetsize\n"; echo "Email: ".$this->maxloss[0]."% ".$this->maxlatency[0]."ms\n"; echo "Normal: ".$this->maxloss[1]."% ".$this->maxlatency[1]."ms\n"; echo "Acceptable: ".$this->maxloss[2]."% ".$this->maxlatency[2]."ms\n"; echo "Warning: ".$this->maxloss[3]."% ".$this->maxlatency[3]."ms\n"; echo "\n"; return true; } // Server Report function report($type) { $report=str_pad($this->dnsname.":", 20); if($type==1) { if(($this->loss<=$this->maxloss[1]) && ($this->latency<=$this->maxlatency[1])) $report.=" Normal "; else if(($this->loss<=$this->maxloss[2]) && ($this->latency<=$this->maxlatency[2])) $report.="Acceptable "; else if(($this->loss<=$this->maxloss[3]) && ($this->latency<=$this->maxlatency[3])) $report.="-WARNING- "; else $report.="-FAILURE- "; $report.=display_stats($this->loss, 1,"%")." loss, ".display_stats($this->latency, 0, "ms")." latency."; } if($type==2) foreach($this->stats as $stat) { if($stat<0) $report.="X"; else if($stat<=$this->maxlatency[1]) $report.="."; else if($stat<=$this->maxlatency[2]) $report.=","; else if($stat<=$this->maxlatency[3]) $report.="s"; } $report.="\n"; return $report; } // Load from file function load($data) { // Look for parameters if(preg_match("/(.*)<\/name>/isU",$data, $xmlstring)) $this->dnsname=$xmlstring[1]; if(preg_match("/(.*)<\/ip>/isU",$data, $xmlstring)) $this->ip=$xmlstring[1]; if(preg_match("/(.*)<\/packetsize>/isU",$data, $xmlstring)) $this->packetsize=$xmlstring[1]; if(preg_match("/(.*)<\/timeout>/isU",$data, $xmlstring)) $this->timeout=$xmlstring[1]; if(preg_match("/(.*)<\/samplesize>/isU",$data, $xmlstring)) $this->samplesize=$xmlstring[1]; // Get notification levels $garbage=""; while(preg_match("/(.*)(.*)<\/notify>(.*)$/isU", $data, $result)) { $garbage.=$result[1]; // Get notification level switch(strtolower($result[2])) { case "email": $level=0; break; case "normal": $level=1; break; case "acceptable": $level=2; break; case "warning": default: $level=3; break; } if(preg_match("/(.*)<\/maxloss>/isU",$result[3], $xmlstring)) $this->maxloss[$level]=$xmlstring[1]; if(preg_match("/(.*)<\/maxlatency>/isU",$result[3], $xmlstring)) $this->maxlatency[$level]=$xmlstring[1]; $data=$result[4]; } } // Save to file function save($file) { fputs($file,"\r\n \r\n"); fputs($file," ".$this->dnsname."\r\n"); fputs($file," ".$this->ip."\r\n"); fputs($file," ".$this->packetsize."\r\n"); fputs($file," ".$this->timeout."\r\n"); fputs($file," ".$this->samplesize."\r\n"); fputs($file," "); fputs($file,"".$this->maxloss[0].""); fputs($file,"".$this->maxlatency[0].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->maxloss[1].""); fputs($file,"".$this->maxlatency[1].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->maxloss[2].""); fputs($file,"".$this->maxlatency[2].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->maxloss[3].""); fputs($file,"".$this->maxlatency[3].""); fputs($file,"\r\n"); fputs($file," \r\n"); } } //-------------------SITE CLASS------------------- class site { var $name; var $servers; //Server array var $clist; //Sites cList var $widget; //GTK Site Widget // Child Widgets var $deletesite; //Delete site button // Child Defaults var $def_samplesize; var $def_packetsize; var $def_timeout; var $def_maxloss; // Array for notification levels var $def_maxlatency; // Array for notification levels // Site Constructor function site($name) { global $tooltips, $sitestyle, $buttonstyle; $this->name=$name; $this->servers=array(); $this->def_timeout=-1; $this->def_packetsize=-1; $this->def_samplesize=-1; $this->def_maxloss=array(-1, -1, -1, -1); $this->def_maxlatency=array(-1, -1, -1, -1); // Draw nice frame $this->widget=&new GtkFrame($this->name); $this->widget->set_style($sitestyle); // Make a vertical container for the whole site $vbox=&new GtkVBox(false,5); $vbox->set_border_width(5); $this->widget->add($vbox); // Make the horzontal container for the buttons $hbox=&new GtkHBox(false, 10); $vbox->pack_start($hbox, false); // Make the horzontal container for the server buttons $hserverbox=&new GtkHBox(true,0); $hbox->add($hserverbox); // Add Server Button $addserver=&new GtkButton('Add Server'); $addserver->set_style($buttonstyle); $tooltips->set_tip($addserver, "Adds a new server to the site"); $addserver->connect_object('clicked', 'entry_box', 'Add Server', 'Enter hostname or IP:', 'Example: localhost.default.com or 127.0.0.1', array(&$this, 'add_server')); $hserverbox->add($addserver); // Remove Server Button $deleteserver=&new GtkButton('Delete Server'); $deleteserver->set_style($buttonstyle); $tooltips->set_tip($deleteserver, "Deletes the selected server from the site"); $deleteserver->connect('clicked', array(&$this, 'remove_server')); $hserverbox->add($deleteserver); // Edit Server Button $editserver=&new GtkButton('Edit Server'); $editserver->set_style($buttonstyle); $tooltips->set_tip($editserver, "Edits the selected server"); $editserver->connect_object('clicked', array(&$this, 'edit_server')); $hserverbox->add($editserver); // Make the horzontal container for the site buttons $hsitebox=&new GtkHBox(true,0); $hbox->add($hsitebox); // Delete Site Button $this->deletesite=&new GtkButton('Delete Site'); $this->deletesite->set_style($buttonstyle); $tooltips->set_tip($this->deletesite, "Deletes the site"); $hsitebox->add($this->deletesite); // Edit Site Button $editsite=&new GtkButton('Edit Site'); $editsite->set_style($buttonstyle); $tooltips->set_tip($editsite, "Edits the site"); $editsite->connect_object('clicked', array(&$this, 'edit')); $hsitebox->add($editsite); // Create the clist $this->clist=&new GtkCList(5, array( "Hostname", "IP Address", "R/T Latency", "Ave Latency", "Ave Loss" )); $this->clist->set_column_justification(0, "GTK_JUSTIFY_RIGHT"); $this->clist->set_column_justification(1, "GTK_JUSTIFY_CENTER"); $this->clist->set_column_justification(2, "GTK_JUSTIFY_CENTER"); $this->clist->set_column_justification(3, "GTK_JUSTIFY_CENTER"); $this->clist->set_column_justification(4, "GTK_JUSTIFY_CENTER"); $this->clist->set_column_width(0, 160); $this->clist->set_column_width(1, 80); $this->clist->set_column_width(2, 60); $this->clist->set_column_width(3, 60); $this->clist->set_column_width(4, 60); $vbox->add($this->clist); } // Edit Site function edit() { global $sitestyle, $buttonstyle; global $s_normal, $s_acceptable, $s_warning, $s_failed; $serversset=&new dialogue_box(1, "Set all servers", "All servers in the site have now been set."); $window=&new GtkWindow(); $window->set_title('Edit Site'); $window->set_border_width(10); $vbox=&new GtkVBox(false,5); $window->add($vbox); // Site Box $sitebox=&new GtkFrame('Site'); $sitebox->set_style($sitestyle); $vbox->add($sitebox); $sitetable=&new GtkTable(1, 2, false); $sitetable->set_row_spacings(5); $sitetable->set_col_spacings(5); $sitetable->set_border_width(10); $sitebox->add($sitetable); $l_name=&new GtkLabel('Site Name'); $sitetable->attach($l_name, 0, 1, 0, 1); $e_name=&new GtkEntry(); $e_name->set_max_length(30); $e_name->set_text($this->name); $sitetable->attach($e_name, 1, 2, 0, 1); // Ping Box $pingbox=&new GtkFrame('Ping'); $pingbox->set_style($sitestyle); $vbox->add($pingbox); $pingtable=&new GtkTable(3, 3, false); $pingtable->set_row_spacings(5); $pingtable->set_col_spacings(5); $pingtable->set_border_width(10); $pingbox->add($pingtable); $l_packetsize=&new GtkLabel('Default Packet Size'); $pingtable->attach($l_packetsize, 0, 1, 0, 1); $a_packetsize=&new GtkAdjustment(32, 1, 1024, 1, 32, 32); $e_packetsize=&new GtkSpinButton($a_packetsize, 0, 0); $e_packetsize->set_value($this->def_packetsize); $pingtable->attach($e_packetsize, 1, 2, 0, 1); $u_packetsize=&new GtkLabel('bytes'); $pingtable->attach($u_packetsize, 2, 3, 0, 1); $l_timeout=&new GtkLabel('Default Timeout'); $pingtable->attach($l_timeout, 0, 1, 1, 2); $a_timeout=&new GtkAdjustment(1, 1, 10, 1, 1, 1); $e_timeout=&new GtkSpinButton($a_timeout, 0, 0); $e_timeout->set_value($this->def_timeout); $pingtable->attach($e_timeout, 1, 2, 1, 2); $u_timeout=&new GtkLabel('seconds'); $pingtable->attach($u_timeout, 2, 3, 1, 2); $b_pingreset=&new GtkButton('Set all Servers in the Site'); $b_pingreset->connect_object('clicked', array(&$this, 'apply'), '', $e_packetsize, $e_timeout, '', '', '', '', '', '', '', '', ''); $b_pingreset->connect_object('clicked', array(&$this, 'set_packet_size'), &$this->def_packetsize); $b_pingreset->connect_object('clicked', array(&$this, 'set_timeout'), &$this->def_timeout); $b_pingreset->connect_object('clicked', array(&$serversset->widget, 'show_all')); $b_pingreset->set_style($buttonstyle); $pingtable->attach($b_pingreset, 0, 3, 2, 3); // Stats Box $statsbox=&new GtkFrame('Stats'); $statsbox->set_style($sitestyle); $vbox->add($statsbox); $statstable=&new GtkTable(2, 3, false); $statstable->set_row_spacings(5); $statstable->set_col_spacings(5); $statstable->set_border_width(10); $statsbox->add($statstable); $l_samplesize=&new GtkLabel('Default Sample Size'); $statstable->attach($l_samplesize, 0, 1, 0, 1); $a_samplesize=&new GtkAdjustment(30, 1, 100000, 1, 10, 10); $e_samplesize=&new GtkSpinButton($a_samplesize, 0, 0); $e_samplesize->set_value($this->def_samplesize); $statstable->attach($e_samplesize, 1, 2, 0, 1); $u_samplesize=&new GtkLabel('echo requests'); $statstable->attach($u_samplesize, 2, 3, 0, 1); $b_statstable=&new GtkButton('Set all Servers in the Site'); $b_statstable->connect_object('clicked', array(&$this, 'apply'), '', '', '', $e_samplesize, '', '', '', '', '', '', '', ''); $b_statstable->connect_object('clicked', array(&$this, 'set_sample_size'), &$this->def_samplesize); $b_statstable->connect_object('clicked', array(&$serversset->widget, 'show_all')); $b_statstable->set_style($buttonstyle); $statstable->attach($b_statstable, 0, 3, 2, 3); // Notify Levels Box $notifybox=&new GtkFrame('Notification Levels'); $notifybox->set_style($sitestyle); $vbox->add($notifybox); $notifytable=&new GtkTable(5, 5, false); $notifytable->set_row_spacings(5); $notifytable->set_col_spacings(5); $notifytable->set_border_width(10); $notifybox->add($notifytable); $l_normal=&new GtkLabel('Normal Maximum'); $l_normal->set_style($s_normal); $notifytable->attach($l_normal, 0, 1, 0, 1); $a_normalloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_normalloss=&new GtkSpinButton($a_normalloss, 0, 0); $e_normalloss->set_value($this->def_maxloss[1]); $notifytable->attach($e_normalloss, 1, 2, 0, 1); $u_normalloss=&new GtkLabel('% loss, '); $u_normalloss->set_style($s_normal); $notifytable->attach($u_normalloss, 2, 3, 0, 1); $a_normallatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_normallatency=&new GtkSpinButton($a_normallatency, 0, 0); $e_normallatency->set_value($this->def_maxlatency[1]); $notifytable->attach($e_normallatency, 3, 4, 0, 1); $u_normallatency=&new GtkLabel('ms latency'); $u_normallatency->set_style($s_normal); $notifytable->attach($u_normallatency, 4, 5, 0, 1); $l_acceptable=&new GtkLabel('Acceptable Maxmimum'); $l_acceptable->set_style($s_acceptable); $notifytable->attach($l_acceptable, 0, 1, 1, 2); $a_acceptableloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_acceptableloss=&new GtkSpinButton($a_acceptableloss, 0, 0); $e_acceptableloss->set_value($this->def_maxloss[2]); $notifytable->attach($e_acceptableloss, 1, 2, 1, 2); $u_acceptableloss=&new GtkLabel('% loss, '); $u_acceptableloss->set_style($s_acceptable); $notifytable->attach($u_acceptableloss, 2, 3, 1, 2); $a_acceptablelatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_acceptablelatency=&new GtkSpinButton($a_acceptablelatency, 0, 0); $e_acceptablelatency->set_value($this->def_maxlatency[2]); $notifytable->attach($e_acceptablelatency, 3, 4, 1, 2); $u_acceptablelatency=&new GtkLabel('ms latency'); $u_acceptablelatency->set_style($s_acceptable); $notifytable->attach($u_acceptablelatency, 4, 5, 1, 2); $l_warning=&new GtkLabel('Warning Maximum'); $l_warning->set_style($s_warning); $notifytable->attach($l_warning, 0, 1, 2, 3); $a_warningloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_warningloss=&new GtkSpinButton($a_warningloss, 0, 0); $e_warningloss->set_value($this->def_maxloss[3]); $notifytable->attach($e_warningloss, 1, 2, 2, 3); $u_warningloss=&new GtkLabel('% loss, '); $u_warningloss->set_style($s_warning); $notifytable->attach($u_warningloss, 2, 3, 2, 3); $a_warninglatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_warninglatency=&new GtkSpinButton($a_warninglatency, 0, 0); $e_warninglatency->set_value($this->def_maxlatency[3]); $notifytable->attach($e_warninglatency, 3, 4, 2, 3); $u_warninglatency=&new GtkLabel('ms latency'); $u_warninglatency->set_style($s_warning); $notifytable->attach($u_warninglatency, 4, 5, 2, 3); $l_failed=&new GtkLabel('Failed Maximum'); $l_failed->set_style($s_failed); $notifytable->attach($l_failed, 0, 1, 3, 4); $e_failedloss=&new GtkLabel('100'); $notifytable->attach($e_failedloss, 1, 2, 3, 4); $u_failedloss=&new GtkLabel('% loss, '); $u_failedloss->set_style($s_failed); $notifytable->attach($u_failedloss, 2, 3, 3, 4); $e_failedlatency=&new GtkLabel($this->def_timeout*1000); $notifytable->attach($e_failedlatency, 3, 4, 3, 4); $u_failedlatency=&new GtkLabel('ms latency'); $u_failedlatency->set_style($s_failed); $notifytable->attach($u_failedlatency, 4, 5, 3, 4); $b_notifytable=&new GtkButton('Set all Servers in the Site'); $b_notifytable->connect_object('clicked', array(&$this, 'apply'), '', '', '', '', $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, '', ''); $b_notifytable->connect_object('clicked', array(&$this, 'set_notify'), 1, &$this->def_maxloss, &$this->def_maxlatency); $b_notifytable->connect_object('clicked', array(&$this, 'set_notify'), 2, &$this->def_maxloss, &$this->def_maxlatency); $b_notifytable->connect_object('clicked', array(&$this, 'set_notify'), 3, &$this->def_maxloss, &$this->def_maxlatency); $b_notifytable->connect_object('clicked', array(&$serversset->widget, 'show_all')); $b_notifytable->set_style($buttonstyle); $notifytable->attach($b_notifytable, 0, 5, 4, 5); // Email Box $emailbox=&new GtkFrame('Email Levels'); $emailbox->set_style($sitestyle); $vbox->add($emailbox); $emailtable=&new GtkTable(2, 5, false); $emailtable->set_row_spacings(5); $emailtable->set_col_spacings(5); $emailtable->set_border_width(10); $emailbox->add($emailtable); $l_email=&new GtkLabel('Email Report Trigger'); $emailtable->attach($l_email, 0, 1, 0, 1); $a_emailloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_emailloss=&new GtkSpinButton($a_emailloss, 0, 0); $e_emailloss->set_value($this->def_maxloss[0]); $emailtable->attach($e_emailloss, 1, 2, 0, 1); $u_emailloss=&new GtkLabel('% loss, '); $emailtable->attach($u_emailloss, 2, 3, 0, 1); $a_emaillatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_emaillatency=&new GtkSpinButton($a_emaillatency, 0, 0); $e_emaillatency->set_value($this->def_maxlatency[0]); $emailtable->attach($e_emaillatency, 3, 4, 0, 1); $u_emaillatency=&new GtkLabel('ms latency'); $emailtable->attach($u_emaillatency, 4, 5, 0, 1); $b_emailtable=&new GtkButton('Set all Servers in the Site'); $b_emailtable->connect_object('clicked', array(&$this, 'apply'), '', '', '', '', '', '', '', '', '', '', $e_emailloss, $e_emaillatency); $b_emailtable->connect_object('clicked', array(&$this, 'set_notify'), 0, &$this->def_maxloss, &$this->def_maxlatency); $b_emailtable->connect_object('clicked', array(&$serversset->widget, 'show_all')); $b_emailtable->set_style($buttonstyle); $emailtable->attach($b_emailtable, 0, 5, 2, 3); // Buttons $buttonbox=&new GtkHBox('true', 5); $vbox->add($buttonbox); $b_ok=&new GtkButton('OK'); $b_ok->connect_object('clicked', array(&$this, 'apply'), $e_name, $e_packetsize, $e_timeout, $e_samplesize, $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, $e_emailloss, $e_emaillatency); $b_ok->connect_object('clicked', array($window, 'destroy')); $b_ok->set_style($buttonstyle); $buttonbox->add($b_ok); $b_cancel=&new GtkButton('Cancel'); $b_cancel->set_style($buttonstyle); $b_cancel->connect_object('clicked', array($window, 'destroy')); $buttonbox->add($b_cancel); $b_apply=&new GtkButton('Apply'); $b_apply->connect_object('clicked', array(&$this, 'apply'), $e_name, $e_packetsize, $e_timeout, $e_samplesize, $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, $e_emailloss, $e_emaillatency); $b_apply->set_style($buttonstyle); $buttonbox->add($b_apply); $window->show_all(); } // Apply changes function apply($name, $packetsize, $timeout, $samplesize, $normalloss, $normallatency, $acceptableloss, $acceptablelatency, $warningloss, $warninglatency, $emailloss, $emaillatency) { if($name) if($name!=$name->get_text()) { $this->name=$name->get_text(); $this->widget->set_label($this->name); } if($packetsize) $this->def_packetsize=$packetsize->get_text(); if($timeout) $this->def_timeout=$timeout->get_text(); if($samplesize) $this->def_samplesize=$samplesize->get_text(); if($emailloss) $this->def_maxloss[0]=$emailloss->get_text(); if($normalloss) $this->def_maxloss[1]=$normalloss->get_text(); if($acceptableloss) $this->def_maxloss[2]=$acceptableloss->get_text(); if($warningloss) $this->def_maxloss[3]=$warningloss->get_text(); if($emaillatency) $this->def_maxlatency[0]=$emaillatency->get_text(); if($normallatency) $this->def_maxlatency[1]=$normallatency->get_text(); if($acceptablelatency) $this->def_maxlatency[2]=$acceptablelatency->get_text(); if($warninglatency) $this->def_maxlatency[3]=$warninglatency->get_text(); } // Add a Server to Site function add(&$newserver) { // If no values are loaded conform new server to site defaults if($newserver->samplesize==-1) $newserver->samplesize=$this->def_samplesize; if($newserver->packetsize==-1) $newserver->packetsize=$this->def_packetsize; if($newserver->timeout==-1) $newserver->timeout=$this->def_timeout; for($i=0; $i<=3; $i++) { if($newserver->maxloss[$i]==-1) $newserver->maxloss[$i]=$this->def_maxloss[$i]; if($newserver->maxlatency[$i]==-1) $newserver->maxlatency[$i]=$this->def_maxlatency[$i]; } // If the site defaults are also broken be brutal about it if($newserver->samplesize==-1) $newserver->samplesize=60; if($newserver->packetsize==-1) $newserver->packetsize=32; if($newserver->timeout==-1) $newserver->timeout=1; for($i=0; $i<=3; $i++) { if($newserver->maxloss[$i]==-1) $newserver->maxloss[$i]=0; if($newserver->maxlatency[$i]==-1) $newserver->maxlatency[$i]=0; } // Add Server $this->servers[]=&$newserver; $this->clist->append( array( $newserver->dnsname, $newserver->ip, display_stats($newserver->rtlatency, 0, "ms"), display_stats($newserver->latency, 0, "ms"), display_stats($newserver->loss, 1, "%") )); } // Remove server function remove_server() { if(($row = $this->clist->selection[0]) !== NULL) $this->remove($row); else { $notify=&new dialogue_box(1, 'Remove Server', 'Please select a server.'); $notify->widget->show_all(); } } // Remove a Server from a Site function remove($row) { //Remove from CList $this->clist->remove($row); $deadserver=$this->servers[$row]; array_splice($this->servers, $row, 1); unset($deadserver); } // Remove all Servers from a Site function remove_all() { while(count($this->servers)) $this->remove(0); } // Edit server function edit_server() { if(($row = $this->clist->selection[0]) !== NULL) $this->servers[$row]->edit($this->clist, $row); else { $notify=&new dialogue_box(1, 'Edit Server', 'Please select a server.'); $notify->widget->show_all(); } } // Add Server function add_server($window, $entry, $warninglabel) { $text=$entry->get_text(); // Check its not blank if($text=="") { $warninglabel->set_text("Please enter an IP address or hostname..."); return false; } // Check to see if its an IP if(preg_match("/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/i", $text, $ipelement)) { // Data is an IP for($i=1; $i<=4; $i++) if($ipelement[$i]>=255) { $warninglabel->set_text("IP Address out of range... try again"); return false; } $warninglabel->set_text("Please Wait: Checking IP address..."); update_screen(); $ip=$text; $hostname=gethostbyaddr($text); // If cant resolve a hostname leave it blank if($ip==$hostname) { $hostname=""; } } else { // Data is a hostname $warninglabel->set_text("Please Wait: Checking hostname..."); update_screen(); // Resolve IP $ip=gethostbyname($text); // If it cant resolve the IP, print error if($ip==$text) { $warninglabel->set_text("Sorry I cant find an IP for that... try again"); return false; } // Set proper hostname $hostname=gethostbyaddr($ip); // If it cant resolve the proper hostname set it back to the text if($ip==$hostname) $hostname=$text; // If the hostname is totaly different to the original text add a reminder if(!stristr($hostname, $text)) $hostname.=" (".$text.")"; } $this->add(new server($hostname, $ip)); $window->destroy(); } // Update Site function update() { $report=0; for($i=0; $iservers); $i++) $report+=$this->servers[$i]->update($this->clist, $i); return $report; } // Set Stats Array Size function set_sample_size($samplesize) { $this->def_samplesize=$samplesize; for($i=0; $iservers); $i++) $this->servers[$i]->samplesize=$samplesize; } // Set Ping Packet Size function set_packet_size($packetsize) { $this->def_packetsize=$packetsize; for($i=0; $iservers); $i++) $this->servers[$i]->packetsize=$packetsize; } // Set Ping Timeout function set_timeout($timeout) { $this->def_timeout=$timeout; for($i=0; $iservers); $i++) $this->servers[$i]->timeout=$timeout; } // Set Notify Levels function set_notify($level, $maxloss, $maxlatency) { $this->def_maxloss[$level]=$maxloss[$level]; $this->def_maxlatency[$level]=$maxlatency[$level]; for($i=0; $iservers); $i++) { $this->servers[$i]->maxloss[$level]=$maxloss[$level]; $this->servers[$i]->maxlatency[$level]=$maxlatency[$level]; } } // Site Debug Display function show() { echo "Site Name: $this->name\n"; echo "Site Server Count: ".count($this->servers)."\n"; echo "Site Default Sample Size: $this->def_samplesize\n"; echo "Site Default Timeout: $this->def_timeout\n"; echo "Site Default Packet Size: $this->def_packetsize\n"; echo "Email: ".$this->def_maxloss[0]."% ".$this->def_maxlatency[0]."ms\n"; echo "Normal: ".$this->def_maxloss[1]."% ".$this->def_maxlatency[1]."ms\n"; echo "Acceptable: ".$this->def_maxloss[2]."% ".$this->def_maxlatency[2]."ms\n"; echo "Warning: ".$this->def_maxloss[3]."% ".$this->def_maxlatency[3]."ms\n"; echo "\n"; for($i=0; $iservers); $i++) $this->servers[$i]->show(); return true; } // Site Report function report($type) { $report.="\n----$this->name----\n"; for($i=0; $iservers); $i++) $report.=$this->servers[$i]->report($type); return $report; } // Load from file function load($data) { // Remove the servers $garbage=""; while(preg_match("/(.*)(.*)<\/server>(.*)$/isU", $data, $result)) { $garbage.=$result[1]; $server=&new server("?", "?"); $server->load($result[2]); $this->add($server); $data=$result[3]; } // Add what wasnt used together $data.=$garbage; // Look for parameters if(preg_match("/(.*)<\/name>/isU",$data, $xmlstring)) { $this->name=$xmlstring[1]; $this->widget->set_label($this->name); } if(preg_match("/(.*)<\/ip>/isU",$data, $xmlstring)) $this->ip=$xmlstring[1]; if(preg_match("/(.*)<\/samplesize>/isU",$data, $xmlstring)) $this->def_samplesize=$xmlstring[1]; if(preg_match("/(.*)<\/packetsize>/isU",$data, $xmlstring)) $this->def_packetsize=$xmlstring[1]; if(preg_match("/(.*)<\/timeout>/isU",$data, $xmlstring)) $this->def_timeout=$xmlstring[1]; // Get notification levels $garbage=""; while(preg_match("/(.*)(.*)<\/notify>(.*)$/isU", $data, $result)) { $garbage.=$result[1]; // Get notification level switch(strtolower($result[2])) { case "email": $level=0; break; case "normal": $level=1; break; case "acceptable": $level=2; break; case "warning": default: $level=3; break; } if(preg_match("/(.*)<\/maxloss>/isU",$result[3], $xmlstring)) $this->def_maxloss[$level]=$xmlstring[1]; if(preg_match("/(.*)<\/maxlatency>/isU",$result[3], $xmlstring)) $this->def_maxlatency[$level]=$xmlstring[1]; $data=$result[4]; } } // Save to file function save($file) { fputs($file,"\r\n \r\n"); fputs($file," ".$this->name."\r\n"); fputs($file," ".$this->def_packetsize."\r\n"); fputs($file," ".$this->def_timeout."\r\n"); fputs($file," ".$this->def_samplesize."\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[0].""); fputs($file,"".$this->def_maxlatency[0].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[1].""); fputs($file,"".$this->def_maxlatency[1].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[2].""); fputs($file,"".$this->def_maxlatency[2].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[3].""); fputs($file,"".$this->def_maxlatency[3].""); fputs($file,"\r\n"); for($i=0; $iservers); $i++) $this->servers[$i]->save($file); fputs($file," \r\n"); } } //-------------------SITE ARRAY CLASS------------------- class sitearray { var $sites; // Site array var $widget; // GTK Scan Array Widget var $samplerate; var $sampleid; var $emailrate; // Email report rate var $sampleid; var $report; // Report Trigger var $emails; // Email address list var $replyto; // Child Defaults var $def_samplesize; var $def_packetsize; var $def_timeout; var $def_maxloss; // Array for notification levels var $def_maxlatency; // Array for notification levels // sitearray Constructor function sitearray() { global $tooltips, $buttonstyle; $this->sites=array(); $this->samplerate=5; $this->emailrate=900; $this->report=0; $this->def_samplesize=60; $this->def_packetsize=32; $this->def_timeout=1; $this->def_maxloss=array(50, 0, 10, 50); $this->def_maxlatency=array(600, 100, 300, 600); $this->emails=''; $this->replyto=''; // Make a vertical container for the whole array $this->widget=&new GtkVBox(false, 10); // Make the horzontal container for the buttons $hbox=&new GtkHBox(true,0); // Add Site Button $addsite=&new GtkButton('Add Site'); $addsite->set_style($buttonstyle); $tooltips->set_tip($addsite, "Adds a new site to the list"); $addsite->connect_object('clicked', 'entry_box', 'Add Site', 'Enter Sitename:', 'Example: MySite', array(&$this, 'add_site')); $hbox->add($addsite); // Report Button $report=&new GtkButton('Report'); $report->set_style($buttonstyle); $tooltips->set_tip($report, "Creates and displays a report"); $report->connect_object('clicked', array(&$this, 'display_report')); $hbox->add($report); // Settings Button $settings=&new GtkButton('Settings'); $settings->set_style($buttonstyle); $tooltips->set_tip($settings, "Edit settings"); $settings->connect_object('clicked', array(&$this, 'edit')); $hbox->add($settings); // Save Button $save=&new GtkButton('Save'); $save->set_style($buttonstyle); $tooltips->set_tip($save, "Save settings"); $save->connect_object('clicked', array(&$this, 'save'), "conTest-sites.xml"); $saved=&new dialogue_box(1, "Save Settings", "All settings have now been saved."); $save->connect_object('clicked', array(&$saved->widget, 'show_all')); $hbox->add($save); // About Button $about=&new GtkButton('About'); $about->set_style($buttonstyle); $tooltips->set_tip($about, "About conTest"); $about->connect_object('clicked', 'about_box'); $hbox->add($about); $this->widget->pack_start($hbox, false); } // Edit Sitearray function edit() { global $sitestyle, $buttonstyle; global $s_normal, $s_acceptable, $s_warning, $s_failed; // Popup boxes $sitesset=&new dialogue_box(1, "Set all servers and sites", "All servers and all sites have now been set."); $emailsent=&new dialogue_box(1, "Send test email", "A test email has now been sent."); $window=&new GtkWindow(); $window->set_title('Edit Settings'); $window->set_border_width(10); $vbox=&new GtkVBox(false,5); $window->add($vbox); // Update Box $updatebox=&new GtkFrame('Update Settings'); $updatebox->set_style($sitestyle); $vbox->add($updatebox); $updatetable=&new GtkTable(1, 3, false); $updatetable->set_row_spacings(5); $updatetable->set_col_spacings(5); $updatetable->set_border_width(10); $updatebox->add($updatetable); $l_samplerate=&new GtkLabel('Update Every'); $updatetable->attach($l_samplerate, 0, 1, 0, 1); $a_samplerate=&new GtkAdjustment(2, 1, 100000, 1, 60, 60); $e_samplerate=&new GtkSpinButton($a_samplerate, 0, 0); $e_samplerate->set_value($this->samplerate); $updatetable->attach($e_samplerate, 1, 2, 0, 1); $l_samplerate=&new GtkLabel('seconds'); $updatetable->attach($l_samplerate, 2, 3, 0, 1); // Ping Box $pingbox=&new GtkFrame('Ping'); $pingbox->set_style($sitestyle); $vbox->add($pingbox); $pingtable=&new GtkTable(3, 3, false); $pingtable->set_row_spacings(5); $pingtable->set_col_spacings(5); $pingtable->set_border_width(10); $pingbox->add($pingtable); $l_packetsize=&new GtkLabel('Default Packet Size'); $pingtable->attach($l_packetsize, 0, 1, 0, 1); $a_packetsize=&new GtkAdjustment(32, 1, 1024, 1, 32, 32); $e_packetsize=&new GtkSpinButton($a_packetsize, 0, 0); $e_packetsize->set_value($this->def_packetsize); $pingtable->attach($e_packetsize, 1, 2, 0, 1); $u_packetsize=&new GtkLabel('bytes'); $pingtable->attach($u_packetsize, 2, 3, 0, 1); $l_timeout=&new GtkLabel('Default Timeout'); $pingtable->attach($l_timeout, 0, 1, 1, 2); $a_timeout=&new GtkAdjustment(1, 1, 10, 1, 1, 1); $e_timeout=&new GtkSpinButton($a_timeout, 0, 0); $e_timeout->set_value($this->def_timeout); $pingtable->attach($e_timeout, 1, 2, 1, 2); $u_timeout=&new GtkLabel('seconds'); $pingtable->attach($u_timeout, 2, 3, 1, 2); $b_pingreset=&new GtkButton('Set all Servers and all Sites'); $b_pingreset->connect_object('clicked', array(&$this, 'apply'), '', '', $e_packetsize, $e_timeout, '', '', '', '', '', '', '', '', '', '', '', '', ''); $b_pingreset->connect_object('clicked', array(&$this, 'set_packet_size'), &$this->def_packetsize); $b_pingreset->connect_object('clicked', array(&$this, 'set_timeout'), &$this->def_timeout); $b_pingreset->connect_object('clicked', array(&$sitesset->widget, 'show_all')); $b_pingreset->set_style($buttonstyle); $pingtable->attach($b_pingreset, 0, 3, 2, 3); // Stats Box $statsbox=&new GtkFrame('Stats'); $statsbox->set_style($sitestyle); $vbox->add($statsbox); $statstable=&new GtkTable(2, 3, false); $statstable->set_row_spacings(5); $statstable->set_col_spacings(5); $statstable->set_border_width(10); $statsbox->add($statstable); $l_samplesize=&new GtkLabel('Default Sample Size'); $statstable->attach($l_samplesize, 0, 1, 0, 1); $a_samplesize=&new GtkAdjustment(30, 1, 100000, 1, 10, 10); $e_samplesize=&new GtkSpinButton($a_samplesize, 0, 0); $e_samplesize->set_value($this->def_samplesize); $statstable->attach($e_samplesize, 1, 2, 0, 1); $u_samplesize=&new GtkLabel('echo requests'); $statstable->attach($u_samplesize, 2, 3, 0, 1); $b_statstable=&new GtkButton('Set all Servers and all Sites'); $b_statstable->connect_object('clicked', array(&$this, 'apply'), '', '', '', '', $e_samplesize, '', '', '', '', '', '', '', '', '', '', '', ''); $b_statstable->connect_object('clicked', array(&$this, 'set_sample_size'), &$this->def_samplesize); $b_statstable->connect_object('clicked', array(&$sitesset->widget, 'show_all')); $b_statstable->set_style($buttonstyle); $statstable->attach($b_statstable, 0, 3, 2, 3); // Notify Levels Box $notifybox=&new GtkFrame('Notification Levels'); $notifybox->set_style($sitestyle); $vbox->add($notifybox); $notifytable=&new GtkTable(5, 5, false); $notifytable->set_row_spacings(5); $notifytable->set_col_spacings(5); $notifytable->set_border_width(10); $notifybox->add($notifytable); $l_normal=&new GtkLabel('Normal Maximum'); $l_normal->set_style($s_normal); $notifytable->attach($l_normal, 0, 1, 0, 1); $a_normalloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_normalloss=&new GtkSpinButton($a_normalloss, 0, 0); $e_normalloss->set_value($this->def_maxloss[1]); $notifytable->attach($e_normalloss, 1, 2, 0, 1); $u_normalloss=&new GtkLabel('% loss, '); $u_normalloss->set_style($s_normal); $notifytable->attach($u_normalloss, 2, 3, 0, 1); $a_normallatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_normallatency=&new GtkSpinButton($a_normallatency, 0, 0); $e_normallatency->set_value($this->def_maxlatency[1]); $notifytable->attach($e_normallatency, 3, 4, 0, 1); $u_normallatency=&new GtkLabel('ms latency'); $u_normallatency->set_style($s_normal); $notifytable->attach($u_normallatency, 4, 5, 0, 1); $l_acceptable=&new GtkLabel('Acceptable Maximum'); $l_acceptable->set_style($s_acceptable); $notifytable->attach($l_acceptable, 0, 1, 1, 2); $a_acceptableloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_acceptableloss=&new GtkSpinButton($a_acceptableloss, 0, 0); $e_acceptableloss->set_value($this->def_maxloss[2]); $notifytable->attach($e_acceptableloss, 1, 2, 1, 2); $u_acceptableloss=&new GtkLabel('% loss, '); $u_acceptableloss->set_style($s_acceptable); $notifytable->attach($u_acceptableloss, 2, 3, 1, 2); $a_acceptablelatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_acceptablelatency=&new GtkSpinButton($a_acceptablelatency, 0, 0); $e_acceptablelatency->set_value($this->def_maxlatency[2]); $notifytable->attach($e_acceptablelatency, 3, 4, 1, 2); $u_acceptablelatency=&new GtkLabel('ms latency'); $u_acceptablelatency->set_style($s_acceptable); $notifytable->attach($u_acceptablelatency, 4, 5, 1, 2); $l_warning=&new GtkLabel('Warning Maximum'); $l_warning->set_style($s_warning); $notifytable->attach($l_warning, 0, 1, 2, 3); $a_warningloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_warningloss=&new GtkSpinButton($a_warningloss, 0, 0); $e_warningloss->set_value($this->def_maxloss[3]); $notifytable->attach($e_warningloss, 1, 2, 2, 3); $u_warningloss=&new GtkLabel('% loss, '); $u_warningloss->set_style($s_warning); $notifytable->attach($u_warningloss, 2, 3, 2, 3); $a_warninglatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_warninglatency=&new GtkSpinButton($a_warninglatency, 0, 0); $e_warninglatency->set_value($this->def_maxlatency[3]); $notifytable->attach($e_warninglatency, 3, 4, 2, 3); $u_warninglatency=&new GtkLabel('ms latency'); $u_warninglatency->set_style($s_warning); $notifytable->attach($u_warninglatency, 4, 5, 2, 3); $l_failed=&new GtkLabel('Failed Maximum'); $l_failed->set_style($s_failed); $notifytable->attach($l_failed, 0, 1, 3, 4); $e_failedloss=&new GtkLabel('100'); $notifytable->attach($e_failedloss, 1, 2, 3, 4); $u_failedloss=&new GtkLabel('% loss, '); $u_failedloss->set_style($s_failed); $notifytable->attach($u_failedloss, 2, 3, 3, 4); $e_failedlatency=&new GtkLabel($this->def_timeout*1000); $notifytable->attach($e_failedlatency, 3, 4, 3, 4); $u_failedlatency=&new GtkLabel('ms latency'); $u_failedlatency->set_style($s_failed); $notifytable->attach($u_failedlatency, 4, 5, 3, 4); $b_notifytable=&new GtkButton('Set all Servers and all Sites'); $b_notifytable->connect_object('clicked', array(&$this, 'apply'), '', '', '', '', '', $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, '', '', '', '', '', ''); $b_notifytable->connect_object('clicked', array(&$this, 'set_notify'), 1, &$this->def_maxloss, &$this->def_maxlatency); $b_notifytable->connect_object('clicked', array(&$this, 'set_notify'), 2, &$this->def_maxloss, &$this->def_maxlatency); $b_notifytable->connect_object('clicked', array(&$this, 'set_notify'), 3, &$this->def_maxloss, &$this->def_maxlatency); $b_notifytable->connect_object('clicked', array(&$sitesset->widget, 'show_all')); $b_notifytable->set_style($buttonstyle); $notifytable->attach($b_notifytable, 0, 5, 4, 5); // Email Box $emailbox=&new GtkFrame('Email Levels'); $emailbox->set_style($sitestyle); $vbox->add($emailbox); $emailtable=&new GtkTable(2, 5, false); $emailtable->set_row_spacings(5); $emailtable->set_col_spacings(5); $emailtable->set_border_width(10); $emailbox->add($emailtable); $l_email=&new GtkLabel('Email Report Trigger'); $emailtable->attach($l_email, 0, 1, 0, 1); $a_emailloss=&new GtkAdjustment(10, 0, 100, 1, 10, 10); $e_emailloss=&new GtkSpinButton($a_emailloss, 0, 0); $e_emailloss->set_value($this->def_maxloss[0]); $emailtable->attach($e_emailloss, 1, 2, 0, 1); $u_emailloss=&new GtkLabel('% loss, '); $emailtable->attach($u_emailloss, 2, 3, 0, 1); $a_emaillatency=&new GtkAdjustment(100, 0, 10000, 10, 100, 100); $e_emaillatency=&new GtkSpinButton($a_emaillatency, 0, 0); $e_emaillatency->set_value($this->def_maxlatency[0]); $emailtable->attach($e_emaillatency, 3, 4, 0, 1); $u_emaillatency=&new GtkLabel('ms latency'); $emailtable->attach($u_emaillatency, 4, 5, 0, 1); $b_emailtable=&new GtkButton('Set all Servers and all Sites'); $b_emailtable->connect_object('clicked', array(&$this, 'apply'), '', '', '', '', '', '', '', '', '', '', '', $e_emailloss, $e_emaillatency, '', '', '', ''); $b_emailtable->connect_object('clicked', array(&$this, 'set_notify'), 0, &$this->def_maxloss, &$this->def_maxlatency); $b_emailtable->connect_object('clicked', array(&$sitesset->widget, 'show_all')); $b_emailtable->set_style($buttonstyle); $emailtable->attach($b_emailtable, 0, 5, 1, 2); // Email Report Box $emailreportbox=&new GtkFrame('Email Settings'); $emailreportbox->set_style($sitestyle); $vbox->add($emailreportbox); $emailreporttable=&new GtkTable(5, 3, false); $emailreporttable->set_row_spacings(5); $emailreporttable->set_col_spacings(5); $emailreporttable->set_border_width(10); $emailreportbox->add($emailreporttable); $l_emailrate=&new GtkLabel('Send Report Every'); $emailreporttable->attach($l_emailrate, 0, 1, 0, 1); $a_emailrate=&new GtkAdjustment(2, 1, 100000, 1, 60, 60); $e_emailrate=&new GtkSpinButton($a_emailrate, 0, 0); $e_emailrate->set_value($this->emailrate); $emailreporttable->attach($e_emailrate, 1, 2, 0, 1); $l_emailrate=&new GtkLabel('seconds'); $emailreporttable->attach($l_emailrate, 2, 3, 0, 1); $l_emails=&new GtkLabel('Email Addresses'); $emailreporttable->attach($l_emails, 0, 1, 1, 2); $e_emails=&new GtkEntry(); $e_emails->set_max_length(200); $e_emails->set_text($this->emails); $emailreporttable->attach($e_emails, 1, 3, 1, 2); $l_replyto=&new GtkLabel('Email Reply To'); $emailreporttable->attach($l_replyto, 0, 1, 2, 3); $e_replyto=&new GtkEntry(); $e_replyto->set_max_length(200); $e_replyto->set_text($this->replyto); $emailreporttable->attach($e_replyto, 1, 3, 2, 3); $l_mailserver=&new GtkLabel('Mail Server'); $emailreporttable->attach($l_mailserver, 0, 1, 3, 4); $e_mailserver=&new GtkEntry(); $e_mailserver->set_max_length(50); $e_mailserver->set_text(ini_get(SMTP)); $emailreporttable->attach($e_mailserver, 1, 3, 3, 4); $b_emailsend=&new GtkButton('Send Test Email'); $b_emailsend->connect_object('clicked', array(&$this, 'apply'), '', '', '', '', '', '', '', '', '', '', '', '', '', $e_emails, $e_replyto, $e_mailserver, '1'); $b_emailsend->connect_object('clicked', array(&$this, 'email')); $b_emailsend->connect_object('clicked', array(&$emailsent->widget, 'show_all')); $b_emailsend->set_style($buttonstyle); $emailreporttable->attach($b_emailsend, 0, 3, 4, 5); // Buttons $buttonbox=&new GtkHBox('true', 5); $vbox->add($buttonbox); $b_ok=&new GtkButton('OK'); $b_ok->connect_object('clicked', array(&$this, 'apply'), $e_samplerate, $e_emailrate, $e_packetsize, $e_timeout, $e_samplesize, $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, $e_emailloss, $e_emaillatency, $e_emails, $e_replyto, $e_mailserver, ''); $b_ok->connect_object('clicked', array($window, 'destroy')); $b_ok->set_style($buttonstyle); $buttonbox->add($b_ok); $b_cancel=&new GtkButton('Cancel'); $b_cancel->set_style($buttonstyle); $b_cancel->connect_object('clicked', array($window, 'destroy')); $buttonbox->add($b_cancel); $b_apply=&new GtkButton('Apply'); $b_apply->connect_object('clicked', array(&$this, 'apply'), $e_samplerate, $e_emailrate, $e_packetsize, $e_timeout, $e_samplesize, $e_normalloss, $e_normallatency, $e_acceptableloss, $e_acceptablelatency, $e_warningloss, $e_warninglatency, $e_emailloss, $e_emaillatency, $e_emails, $e_replyto, $e_mailserver, ''); $b_apply->set_style($buttonstyle); $buttonbox->add($b_apply); $window->show_all(); } // Apply changes function apply( $samplerate, $emailrate, $packetsize, $timeout, $samplesize, $normalloss, $normallatency, $acceptableloss, $acceptablelatency, $warningloss, $warninglatency, $emailloss, $emaillatency, $emails, $replyto, $mailserver, $report) { if($samplerate) $this->set_samplerate($samplerate->get_text()); if($emailrate) $this->set_emailrate($emailrate->get_text()); if($packetsize) $this->def_packetsize=$packetsize->get_text(); if($timeout) $this->def_timeout=$timeout->get_text(); if($samplesize) $this->def_samplesize=$samplesize->get_text(); if($emailloss) $this->def_maxloss[0]=$emailloss->get_text(); if($normalloss) $this->def_maxloss[1]=$normalloss->get_text(); if($acceptableloss) $this->def_maxloss[2]=$acceptableloss->get_text(); if($warningloss) $this->def_maxloss[3]=$warningloss->get_text(); if($emaillatency) $this->def_maxlatency[0]=$emaillatency->get_text(); if($normallatency) $this->def_maxlatency[1]=$normallatency->get_text(); if($acceptablelatency) $this->def_maxlatency[2]=$acceptablelatency->get_text(); if($warninglatency) $this->def_maxlatency[3]=$warninglatency->get_text(); if($emails) $this->emails=str_replace(" ", "",$emails->get_text()); if($replyto) $this->replyto=str_replace(" ", "",$replyto->get_text()); if($mailserver) ini_set(SMTP, $mailserver->get_text()); if($report) $this->report=$report; } // Add a Site to the sitearray function add(&$newsite) { // Conform new site to array defaults if($newsite->def_samplesize==-1) $newsite->set_sample_size($this->def_samplesize); if($newsite->def_packetsize==-1) $newsite->set_packet_size($this->def_packetsize); if($newsite->def_timeout==-1) $newsite->set_timeout($this->def_timeout); for($i=0; $i<=3; $i++) if(($newsite->def_maxloss[$i]==-1) && ($newsite->def_maxlatency[$i]==-1)) $newsite->set_notify($i, $this->def_maxloss, $this->def_maxlatency); // Create the deletesite button action $deletesite=&new dialogue_box(2, 'Remove Site ?', 'Are you sure you want to remove this site ?'); $deletesite->yes->connect_object('clicked', array(&$this, 'remove'), &$newsite); $newsite->deletesite->connect_object('clicked', array(&$deletesite->widget, 'show_all')); // Add site to sitearray $this->sites[]=&$newsite; $this->widget->add($newsite->widget); $this->widget->show_all(); } // Remove a Site from the array function remove(&$site) { // Kill all the servers $site->remove_all(); $site->widget->destroy(); // Find Site $i=array_keys($this->sites, $site); // Remove Site array_splice($this->sites, $i[0], 1); unset($site); } // Add Site function add_site($window, $entry, $warninglabel) { $sitename=$entry->get_text(); // Check its not blank if($sitename=="") { $warninglabel->set_text("Please enter a site name..."); return false; } $newsite=&new site($sitename); $this->add($newsite); $window->destroy(); } // Update sitearray function update() { global $emailstatus, $pixmap_active, $mask_active, $pixmap_inactive, $mask_inactive; for($i=0; $isites); $i++) $this->report+=$this->sites[$i]->update(); if($this->report>0) $emailstatus->set($pixmap_active, $mask_active); else $emailstatus->set($pixmap_inactive, $mask_inactive); return true; } // Display Report function display_report() { global $warningstyle, $buttonstyle, $reportfont; $window=&new GtkWindow(); $window->set_title("conTest ".VERSION." Report"); $window->set_border_width(10); $window->set_position(GTK_WIN_POS_MOUSE); $vbox=&new GtkVBox(false,5); $window->add($vbox); $textbox=&new GtkText(); $textbox->insert($reportfont, NULL, NULL, $this->report()); $textbox->set_editable(false); $vbox->add($textbox); $button=&new GtkButton('OK'); $button->set_style($buttonstyle); $button->connect_object('clicked', array($window, 'destroy')); $vbox->pack_end($button, false); $window->show_all(); } // Email Report function email() { global $emailsentstatus, $pixmap_active, $mask_active, $pixmap_inactive, $mask_inactive; // If all email settings not done cancel report if(!$this->emails || !$this->replyto || !ini_get('SMTP')) $this->report=0; if($this->report>0) { $emailsentstatus->set($pixmap_active, $mask_active); mail($this->emails, "Network Status Report - Notification Level ".$this->report, $this->report(), "From:\"conTest ".VERSION."\"<$replyto>\nReply-To: $replyto"); } else $emailsentstatus->set($pixmap_inactive, $mask_inactive); $this->report=0; return true; } // Set Stats Array Size function set_sample_size($samplesize) { $this->def_samplesize=$samplesize; for($i=0; $isites); $i++) $this->sites[$i]->set_sample_size($samplesize); } // Set Ping Packet Size function set_packet_size($packetsize) { $this->def_packetsize=$packetsize; for($i=0; $isites); $i++) $this->sites[$i]->set_packet_size($packetsize); } // Set Ping Timeout function set_timeout($timeout) { $this->def_timeout=$timeout; for($i=0; $isites); $i++) $this->sites[$i]->set_timeout($timeout); } // Set Notify Levels function set_notify($level, $maxloss, $maxlatency) { $this->def_maxloss[$level]=$maxloss[$level]; $this->def_maxlatency[$level]=$maxlatency[$level]; for($i=0; $isites); $i++) $this->sites[$i]->set_notify($level, $maxloss, $maxlatency); } // sitearray Debug Display function show() { echo "Total Sites: ".count($this->sites)."\n"; echo "Array Default Sample Size: $this->def_samplesize\n"; echo "Array Default Timeout: $this->def_timeout\n"; echo "Array Default Packet Size: $this->def_packetsize\n"; echo "\n\n"; for($i=0; $isites); $i++) $this->sites[$i]->show(); return true; } // sitearray Report function report() { $report="\n"; $report.="AUTOMATIC NETWORK STATUS REPORT\n"; $report.="conTest ".VERSION." Connectivity Tester\n\n"; $report.="Performed by: ".gethostbyaddr('')."\n"; $report.="Performed on: ".date("g:ia D, M jS Y [H:i:s y/m/d]\n"); $report.="\n\n---------- Summary Report ----------\n"; for($i=0; $isites); $i++) $report.=$this->sites[$i]->report(1); $report.="\n\n---------- Detailed Report ---------\n"; for($i=0; $isites); $i++) $report.=$this->sites[$i]->report(2); $report.="\n\n"; $report.="KEY: .=Normal ,=Acceptable s=Slow X=Packet Dropped\n"; return $report; } // Set samplerate function set_samplerate($samplerate) { $this->samplerate=$samplerate; if($this->sampleid) gtk::timeout_remove($this->sampleid); $this->sampleid=gtk::timeout_add($samplerate*1000, array(&$this, 'update')); } // Set emailrate function set_emailrate($emailrate) { $this->emailrate=$emailrate; if($this->emailid) gtk::timeout_remove($this->emailid); $this->emailid=gtk::timeout_add($emailrate*1000, array(&$this, 'email')); } // Load from file function load($filename) { if(file_exists($filename)) { // Get the file contents $data=file_get_contents($filename); // Get the first sitearray preg_match("/(.*)<\/sitearray>/isU", $data, $result); $data=$result[1]; // Remove servers $garbage=""; while(preg_match("/(.*)(.*)<\/site>(.*)$/isU", $data, $result)) { $garbage.=$result[1]; $site=&new site("?"); $site->load($result[2]); $this->add($site); $data=$result[3]; } // Add what wasnt used together $data.=$garbage; // look for parameters if(preg_match("/(.*)<\/samplerate>/isU",$data, $xmlstring)) $this->set_samplerate($xmlstring[1]); if(preg_match("/(.*)<\/emailrate>/isU",$data, $xmlstring)) $this->set_emailrate($xmlstring[1]); if(preg_match("/(.*)<\/samplesize>/isU",$data, $xmlstring)) $this->def_samplesize=$xmlstring[1]; if(preg_match("/(.*)<\/packetsize>/isU",$data, $xmlstring)) $this->def_packetsize=$xmlstring[1]; if(preg_match("/(.*)<\/timeout>/isU",$data, $xmlstring)) $this->def_timeout=$xmlstring[1]; if(preg_match("/(.*)<\/emails>/isU",$data, $xmlstring)) $this->emails=$xmlstring[1]; if(preg_match("/(.*)<\/replyto>/isU",$data, $xmlstring)) $this->replyto=$xmlstring[1]; if(preg_match("/(.*)<\/mailserver>/isU",$data, $xmlstring)) ini_set(SMTP, $xmlstring[1]); // Get notification levels $garbage=""; while(preg_match("/(.*)(.*)<\/notify>(.*)$/isU", $data, $result)) { $garbage.=$result[1]; // Get notification level switch(strtolower($result[2])) { case "email": $level=0; break; case "normal": $level=1; break; case "acceptable": $level=2; break; case "warning": default: $level=3; break; } if(preg_match("/(.*)<\/maxloss>/isU",$result[3], $xmlstring)) $this->def_maxloss[$level]=$xmlstring[1]; if(preg_match("/(.*)<\/maxlatency>/isU",$result[3], $xmlstring)) $this->def_maxlatency[$level]=$xmlstring[1]; $data=$result[4]; } } else { //----dummy data $site=&new site("Local Machine"); $site->add(new server("Localhost", "127.0.0.1")); $this->add($site); $site=&new site("Internet"); $site->add(new server("www.google.com", "216.239.35.100")); $site->add(new server("www.google.co.uk", "216.239.51.99")); $this->add($site); //----dummy data $this->set_sample_size(30); $this->set_packet_size(32); $this->set_timeout(1); $this->set_samplerate(5); $this->set_emailrate(900); $this->set_notify(0, array(50, 0, 10, 50), array(600, 100, 300, 600)); $this->set_notify(1, array(50, 0, 10, 50), array(600, 100, 300, 600)); $this->set_notify(2, array(50, 0, 10, 50), array(600, 100, 300, 600)); $this->set_notify(3, array(50, 0, 10, 50), array(600, 100, 300, 600)); } } // Save to file function save($filename) { $file=fopen($filename, "w"); fputs($file,"\r\n"); fputs($file,"\r\n\r\n"); fputs($file," ".$this->samplerate."\r\n"); fputs($file," ".$this->emailrate."\r\n"); fputs($file," ".$this->def_packetsize."\r\n"); fputs($file," ".$this->def_timeout."\r\n"); fputs($file," ".$this->def_samplesize."\r\n"); fputs($file," ".$this->emails."\r\n"); fputs($file," ".$this->replyto."\r\n"); fputs($file," ".ini_get('SMTP')."\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[0].""); fputs($file,"".$this->def_maxlatency[0].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[1].""); fputs($file,"".$this->def_maxlatency[1].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[2].""); fputs($file,"".$this->def_maxlatency[2].""); fputs($file,"\r\n"); fputs($file," "); fputs($file,"".$this->def_maxloss[3].""); fputs($file,"".$this->def_maxlatency[3].""); fputs($file,"\r\n"); for($i=0; $isites); $i++) $this->sites[$i]->save($file); fputs($file,"\r\n\r\n"); fclose($file); } } //-------------------DIALOGUE BOX------------------- // Pops up an OK, a yes/no, or a yes/no/cancel box class dialogue_box { var $text; var $title; var $yes; var $no; var $widget; function dialogue_box($buttons, $title, $text) { global $warningstyle, $buttonstyle; $this->widget=&new GtkWindow(); // Window not deleteable $this->widget->connect('delete_event', 'hide'); $this->widget->set_modal(true); $this->widget->set_title($title); $this->widget->set_border_width(10); $this->widget->set_position(GTK_WIN_POS_MOUSE); $this->widget->set_policy(false, false, false); $vbox=&new GtkVBox(true,5); $this->widget->add($vbox); $label=&new GtkLabel($text); $vbox->add($label); $hbox=&new GtkHBox(true,5); $vbox->add($hbox); if($buttons>=2) $this->yes=&new GtkButton('Yes'); else $this->yes=&new GtkButton('OK'); $this->yes->set_style($buttonstyle); $this->yes->connect_object('clicked', array(&$this->widget, 'hide')); $hbox->add($this->yes); if($buttons>=2) { $this->no=&new GtkButton('No'); $this->no->set_style($buttonstyle); $this->no->connect_object('clicked', array(&$this->widget, 'hide')); $hbox->add($this->no); } if($buttons>=3) { $this->cancel=&new GtkButton('Cancel'); $this->cancel->set_style($buttonstyle); $this->cancel->connect_object('clicked', array(&$this->widget, 'hide')); $hbox->add($this->cancel); } } } //-------------------DATA ENTRY BOX------------------- // Pops up an entry box function entry_box($title, $prompt, $example, $OK) { global $warningstyle, $buttonstyle; $window=&new GtkWindow(); $window->set_title($title); $window->set_border_width(10); $window->set_position(GTK_WIN_POS_MOUSE); $window->set_policy(false, false, false); $vbox=&new GtkVBox(true,5); $window->add($vbox); $hbox=&new GtkHBox(false,5); $vbox->add($hbox); $promptlabel=&new GtkLabel($prompt); $hbox->add($promptlabel); $entry=&new GtkEntry(); $entry->set_max_length(50); $hbox->add($entry); $warninglabel=&new GtkLabel($example); $warninglabel->set_style($warningstyle); $vbox->add($warninglabel); $button=&new GtkButton('OK'); $button->set_style($buttonstyle); $button->connect_object('clicked', $OK, $window, $entry, $warninglabel); $hbox->add($button); $entry->grab_focus(); $entry->connect_object('activate', $OK, $window, $entry, $warninglabel); $window->show_all(); } //-------------------ABOUT BOX------------------- // Pops up the about box function about_box() { global $warningstyle, $buttonstyle; $window=&new GtkWindow(); $window->set_title("conTest"); $window->set_border_width(10); $window->set_position(GTK_WIN_POS_MOUSE); $window->set_policy(false, false, false); $vbox=&new GtkVBox(false,5); $window->add($vbox); $aboutlabel=&new GtkLabel("conTest ".VERSION."\nPing Based Connectivity Tester"); $vbox->add($aboutlabel); $aboutlabel=&new GtkLabel("(C)opyright FrozenMist 2003\nhttp://www.frozenmist.co.uk\nfrozenmist@frozenmist.co.uk"); $vbox->add($aboutlabel); $aboutlabel=&new GtkLabel("This software is free and comes with ABSOLUTELY NO WARRANTY.\nYou are welcome to redistribute it under the conditions in the GNU General Public License.\n For more details see http://www.gnu.org/licenses/gpl.txt"); $vbox->add($aboutlabel); $button=&new GtkButton('OK'); $button->set_style($buttonstyle); $button->connect_object('clicked', array($window, 'destroy')); $vbox->add($button); $window->show_all(); } //-------------------UPDATE SCREEN------------------- // Clears the GTK buffer (use during buisy processing) function update_screen() { while(gtk::events_pending()) gtk::main_iteration(); } //-------------------DISPLAY STATS------------------- // Output a value to a fixed decimal place with unit function display_stats($value, $round, $unit) { if($value>=0) return round($value, $round).$unit; return "-"; } //-------------------HIDE------------------- // Function to stop windows being closed and hide instead function hide($window) { $window->hide(); return true; } //-------------------SAVE CHANGES------------------- // Called when program closed function save_changes() { global $allsites; $savechanges=&new dialogue_box(3, 'Save Changes ?', 'Do you want to save your current settings ?'); $savechanges->yes->connect_object('clicked', array(&$allsites, 'save'), "conTest-sites.xml"); $savechanges->yes->connect_object('clicked', array('gtk', 'main_quit')); $savechanges->no->connect_object('clicked', array('gtk', 'main_quit')); $savechanges->widget->show_all(); return true; }