File: 1.01.4b/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: 		$timer=new TFNTimer();
 32: 		$ip=ip_lookup($hostname);
 33: 		if ($ip=="0") return -2; // lookup failed
 34: 		$errno=0;
 35: 		$errstr="";
 36: 		$timer->Start();
 37: 		$fp=@fsockopen($ip,$param,$errno,$errstr,$timeout);
 38: 		$elapsed=$timer->Stop();
 39: 		if ($fp===false) return -1; // open failed
 40: 		@fclose($fp);
 41: 		return $elapsed;
 42: 		}
 43: 		
 44: 	function Evaluate($result) 
 45: 		{
 46: 		if ($result<0) return 2; // failure
 47: 		return 0; // else success
 48: 		}
 49: 	
 50: 	function DisplayForm(&$row)
 51: 		{
 52: 		echo "<table border=0>";
 53: 		echo "<tr><td align=left>";
 54: 		echo "TCP Port :";
 55: 		echo "</td><td align=left>";
 56: 		echo "<input type=text name=testparam size=30 maxlength=128 value=\"".$row['testparam']."\">";
 57: 		echo "</td></tr>";
 58: 		echo "</table>";
 59: 		}
 60: 		
 61: 	}
 62: 	
 63: $params=array();
 64: $NATS->Tests->Register("tcp","FreeNATS_TCP_Test",$params,"TCP Connect",1,"FreeNATS TCP Tester");
 65: $NATS->Tests->SetUnits("tcp","Seconds","s");
 66: }
 67: 
 68: 
 69: ?>