File: 1.09.2b/server/base/tests/tcp.inc.php (View as HTML)

  1: <?php // tcp.inc.php -- TCP test module
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008 PurplePixie Systems
  6: 
  7: FreeNATS is free software: you can redistribute it and/or modify
  8: it under the terms of the GNU General Public License as published by
  9: the Free Software Foundation, either version 3 of the License, or
 10: (at your option) any later version.
 11: 
 12: FreeNATS is distributed in the hope that it will be useful,
 13: but WITHOUT ANY WARRANTY; without even the implied warranty of
 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15: GNU General Public License for more details.
 16: 
 17: You should have received a copy of the GNU General Public License
 18: along with FreeNATS.  If not, see www.gnu.org/licenses
 19: 
 20: For more information see www.purplepixie.org/freenats
 21: -------------------------------------------------------------- */
 22: 
 23: 
 24: if (isset($NATS))
 25: {
 26: class FreeNATS_TCP_Test extends FreeNATS_Local_Test
 27: 	{
 28: 		
 29: 	function DoTest($testname,$param,$hostname,$timeout,$params)
 30: 		{ 
 31: 		global $NATS;
 32: 		$timer=new TFNTimer();
 33: 		if ($timeout<=0) $timeout=$NATS->Cfg->Get("test.tcp.timeout",0); // if no test-specific param use sys default
 34: 		if ($timeout<=0) $timeout=60; // if sys default is <=0 then default to 60 seconds
 35: 		$ip=ip_lookup($hostname);
 36: 		if ($ip=="0") return -2; // lookup failed
 37: 		$errno=0;
 38: 		$errstr="";
 39: 		$timer->Start();
 40: 		$fp=@fsockopen($ip,$param,$errno,$errstr,$timeout);
 41: 		$elapsed=$timer->Stop();
 42: 		if ($fp===false) return -1; // open failed
 43: 		@fclose($fp);
 44: 		return $elapsed;
 45: 		}
 46: 		
 47: 	function Evaluate($result) 
 48: 		{
 49: 		if ($result<0) return 2; // failure
 50: 		return 0; // else success
 51: 		}
 52: 	
 53: 	function DisplayForm(&$row)
 54: 		{
 55: 		echo "<table border=0>";
 56: 		echo "<tr><td align=left>";
 57: 		echo "TCP Port :";
 58: 		echo "</td><td align=left>";
 59: 		echo "<input type=text name=testparam size=30 maxlength=128 value=\"".$row['testparam']."\">";
 60: 		echo "</td></tr>";
 61: 		echo "</table>";
 62: 		}
 63: 		
 64: 	}
 65: 	
 66: $params=array();
 67: $NATS->Tests->Register("tcp","FreeNATS_TCP_Test",$params,"TCP Connect",1,"FreeNATS TCP Tester");
 68: $NATS->Tests->SetUnits("tcp","Seconds","s");
 69: }
 70: 
 71: 
 72: ?>