File: 1.13.3b/server/base/tests/imap.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: 23: function imap_test_connect($host,$user,$pass,$timeout=-1,$protocol="imap",$port=-1,$ssl=false,$debug=false) 24: { 25: global $NATS; 26: if ($timeout>0) $timeout=$timeout; // use specific for test if set 27: else 28: { 29: // otherwise use system if available 30: if (isset($NATS)) $timeout=$NATS->Cfg->Get("test.imap.timeout",0); 31: if ($timeout<=0) $timeout=0; // unset specifically or in environment 32: } 33: 34: if ($timeout>0) imap_timeout(IMAP_OPENTIMEOUT,$timeout); 35: 36: if ($port<=0) 37: { 38: $port=143; // default 39: if ( ($protocol=="imap") && ($ssl) ) $port=993; 40: else if ($protocol=="pop3") 41: { 42: if ($ssl) $port=995; 43: else $port=110; 44: } 45: } 46: 47: $mailbox="{".$host.":".$port."/service=".$protocol; 48: if ($ssl) $mailbox.="/ssl"; 49: $mailbox.="/novalidate-cert"; 50: $mailbox.="}INBOX"; 51: if ($debug) echo $user.":".$pass."@".$mailbox."\n"; 52: $imap=@imap_open($mailbox,$user,$pass); 53: if ($imap===false) return -1; // failed to connect/open 54: 55: @imap_close($imap); 56: return 1; 57: } 58: 59: function imap_test_time($host,$user,$pass,$timeout=-1,$protocol="imap",$port=-1,$ssl=false,$debug=false) 60: { 61: $timer=new TFNTimer(); 62: $timer->Start(); 63: $res=imap_test_connect($host,$user,$pass,$timeout,$protocol,$port,$ssl,$debug); 64: $time=$timer->Stop(); 65: if ($res<=0) return $res; // test failed to connect 66: $time=round($time,4); 67: if ($time==0) $time=0.0001; 68: return $time; 69: } 70: 71: if (isset($NATS)) 72: { 73: class FreeNATS_IMAP_Test extends FreeNATS_Local_Test 74: { 75: function DoTest($testname,$param,$hostname,$timeout,$params) 76: { // 0: host, 1: user, 2: pass, 3: protocol, 4: port, 5: ssl (1/0) 77: if ($params[5]==1) $ssl=true; 78: else $ssl=false; 79: 80: $ip=ip_lookup($params[0]); 81: if ($ip=="0") return -1; 82: 83: return imap_test_time($ip,$params[1],$params[2],$timeout,$params[3],$params[4],$ssl); 84: 85: } 86: function Evaluate($result) 87: { 88: if ($result<=0) return 2; // failed 89: return 0; // passed 90: } 91: 92: function ProtectOutput(&$test) 93: { 94: $test['testparam2']=""; 95: } 96: 97: function DisplayForm(&$row) 98: { 99: echo ""; 100: echo ""; 105: echo ""; 110: echo ""; 117: echo ""; 118: echo ""; 129: echo ""; 134: echo ""; 135: echo ""; 142: echo "
"; 101: echo "Hostname :"; 102: echo ""; 103: echo ""; 104: echo "
"; 106: echo "Username :"; 107: echo ""; 108: echo ""; 109: echo "
"; 111: echo "Password :"; 112: echo ""; 113: //echo ""; // debug 114: echo ""; 115: echo ""; 116: echo "
Leave blank to not change or click to clear
"; 119: echo "Protocol :"; 120: echo ""; 121: if ($row['testparam3']=="") $protocol="imap"; 122: else $protocol=$row['testparam3']; 123: echo ""; 128: echo "
"; 130: echo "Port :"; 131: echo ""; 132: echo ""; 133: echo "
Leave blank use protocol default port (110, 143 etc)
"; 136: echo "SSL :"; 137: echo ""; 138: if ($row['testparam5']==1) $s=" checked"; 139: else $s=""; 140: echo ""; 141: echo "
";
143: } 144: 145: } 146: $params=array(); 147: $NATS->Tests->Register("imap","FreeNATS_IMAP_Test",$params,"IMAP Connect",2,"FreeNATS IMAP/POP Tester"); 148: $NATS->Tests->SetUnits("imap","Seconds","s"); 149: } 150: 151: 152: ?>