File: 1.13.3b/server/base/tests/nats-dns.inc.php (View as HTML)

  1: <?php
  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: // requires that the phpdns API already be included
 23: 
 24: if (isset($NATS))
 25: {
 26: class FreeNATS_DNSAPI_Test extends FreeNATS_Local_Test
 27: 	{
 28: 	function DoTest($testname,$param,$hostname,$timeout,$params)
 29: 		{
 30: 		$timer=new TFNTimer();
 31: 		if ($param=="") $dnsserver=$hostname;
 32: 		else $dnsserver=$param;
 33: 		if ($dnsserver=="") return -3;
 34: 		if ($timeout<=0) $timeout=60;
 35: 		if ($params[4]==1) $udp=false; // use TCP
 36: 		else $udp=true;
 37: 		if (($params[3]=="")||($params[3]==0)) $port=53;
 38: 		else $port=$params[3];
 39: 		
 40: 		$dns_query=new DNSQuery($dnsserver,$port,$timeout,$udp,false); // run with debug off
 41: 		$type=$params[2];
 42: 		$query=$params[1];
 43: 		
 44: 		$timer->Start();
 45: 		$answer=$dns_query->Query($query,$type);
 46: 		$elapsedTime=$timer->Stop();
 47: 		
 48: 		if ( ($answer===false) || ($dns_query->error) ) return -2; // query error
 49: 		if ($answer->count<=0) return -1; // no records returned
 50: 		
 51: 		// otherwise we've got some results ok
 52: 		$elapsedTime=round($elapsedTime,4);
 53: 		if ($elapsedTime<=0) return 0.0001;
 54: 		return $elapsedTime;
 55: 		break;
 56: 		}
 57: 	function Evaluate($result) 
 58: 		{
 59: 		if ($result<0) return 2; // failed
 60: 		return 0; // passed
 61: 		}
 62: 	function DisplayForm(&$row)
 63: 		{
 64: 		echo "<table border=0>";
 65: 		echo "<tr><td align=left>";
 66: 		echo "Host/Domain/IP :";
 67: 		echo "</td><td align=left>";
 68: 		echo "<input type=text name=testparam1 size=30 maxlength=128 value=\"".$row['testparam1']."\">";
 69: 		echo "</td></tr>";
 70: 		echo "<tr><td align=left>";
 71: 		echo "Nameserver :";
 72: 		echo "</td><td align=left>";
 73: 		echo "<input type=text name=testparam size=30 maxlength=128 value=\"".$row['testparam']."\">";
 74: 		echo "</td></tr>";
 75: 		echo "<tr><td colspan=2><i>Leave blank to use the node's hostname</i></td></tr>";
 76: 		echo "<tr><td align=left>";
 77: 		echo "Query Type :";
 78: 		echo "</td><td align=left>";
 79: 		echo "<select name=testparam2>";
 80: 		if ($row['testparam2']!="") 
 81: 			echo "<option value=".$row['testparam2'].">".$row['testparam2']."</option>";
 82: 		echo "<option value=A>A</option>";
 83: 		echo "<option value=MX>MX</option>";
 84: 		echo "<option value=MX>NS</option>";
 85: 		echo "<option value=PTR>PTR</option>";
 86: 		echo "<option value=MX>SOA</option>";
 87: 		echo "</select>";
 88: 		echo "</td></tr>";
 89: 		echo "<tr><td align=left>";
 90: 		echo "Port :";
 91: 		echo "</td><td align=left>";
 92: 		echo "<input type=text name=testparam3 size=10 maxlength=128 value=\"".$row['testparam3']."\">";
 93: 		echo "</td></tr>";
 94: 		echo "<tr><td colspan=2><i>Leave blank to use protocol default port (53)</i></td></tr>";
 95: 		echo "<tr><td align=left>";
 96: 		echo "TCP :";
 97: 		echo "</td><td align=left>";
 98: 		if ($row['testparam4']==1) $s=" checked";
 99: 		else $s="";
100: 		echo "<input type=checkbox name=testparam4 value=1".$s.">";
101: 		echo "</td></tr>";
102: 		echo "<tr><td colspan=2><i>Uses UDP if unchecked</i></td></tr>";
103: 		echo "</table>";
104: 		}
105: 	
106: 	
107: 	}
108: 	
109: $params=array();
110: $NATS->Tests->Register("dns","FreeNATS_DNSAPI_Test",$params,"DNS Query",2,"FreeNATS DNS Tester");
111: $NATS->Tests->SetUnits("dns","Seconds","s");
112: }
113: 
114: ?>
115: