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

1: 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 ""; 65: echo ""; 70: echo ""; 75: echo ""; 76: echo ""; 89: echo ""; 94: echo ""; 95: echo ""; 102: echo ""; 103: echo "
"; 66: echo "Host/Domain/IP :"; 67: echo ""; 68: echo ""; 69: echo "
"; 71: echo "Nameserver :"; 72: echo ""; 73: echo ""; 74: echo "
Leave blank to use the node's hostname
"; 77: echo "Query Type :"; 78: echo ""; 79: echo ""; 88: echo "
"; 90: echo "Port :"; 91: echo ""; 92: echo ""; 93: echo "
Leave blank to use protocol default port (53)
"; 96: echo "TCP :"; 97: echo ""; 98: if ($row['testparam4']==1) $s=" checked"; 99: else $s=""; 100: echo ""; 101: echo "
Uses UDP if unchecked
";
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: