File: 1.19.1b/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-2017 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: } 56: function Evaluate($result) 57: { 58: if ($result<0) return 2; // failed 59: return 0; // passed 60: } 61: function DisplayForm(&$row) 62: { 63: echo ""; 64: echo ""; 69: echo ""; 74: echo ""; 75: echo ""; 88: echo ""; 93: echo ""; 94: echo ""; 101: echo ""; 102: echo "
"; 65: echo "Host/Domain/IP :"; 66: echo ""; 67: echo ""; 68: echo "
"; 70: echo "Nameserver :"; 71: echo ""; 72: echo ""; 73: echo "
Leave blank to use the node's hostname
"; 76: echo "Query Type :"; 77: echo ""; 78: echo ""; 87: echo "
"; 89: echo "Port :"; 90: echo ""; 91: echo ""; 92: echo "
Leave blank to use protocol default port (53)
"; 95: echo "TCP :"; 96: echo ""; 97: if ($row['testparam4']==1) $s=" checked"; 98: else $s=""; 99: echo ""; 100: echo "
Uses UDP if unchecked
";
103: } 104: 105: 106: } 107: 108: $params=array(); 109: $NATS->Tests->Register("dns","FreeNATS_DNSAPI_Test",$params,"DNS Query",2,"FreeNATS DNS Tester"); 110: $NATS->Tests->SetUnits("dns","Seconds","s"); 111: } 112: 113: ?> 114: