File: 1.13.3b/server/base/tests/smb.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: if (!isset($smbclientBinary)) $smbclientBinary="/usr/bin/smbclient"; 24: 25: 26: 27: function smb_connect_time($share,$username,$password) 28: { 29: global $smbclientBinary,$NATS; 30: $timer=new TFNTimer(); 31: 32: $cmd=$smbclientBinary." "; 33: if ($password!="") $username=$username."%".$password; 34: if ($username!="") $cmd.="--user ".$username." "; 35: $cmd.="-N "; 36: $cmd.="-c exit"; 37: $cmd.=" ".$share; 38: $timer->Start(); 39: //echo $cmd; 40: $output=array(); 41: $line=exec($cmd); 42: //echo $line; 43: $time=$timer->Stop(); 44: // Domain= 45: if ( (strlen($line)>7) ) 46: { 47: $dom=substr($line,0,7); 48: if ($dom=="Domain=") 49: { 50: $result=true; 51: } 52: else $result=false; 53: } 54: else if ($line=="") 55: { 56: $result=true; // blank weird output 57: } 58: else 59: { 60: $result=false; 61: if (isset($NATS)) 62: { 63: $NATS->Event("SMB Failed: ".$line,2,"Test","SMB"); 64: } 65: } 66: 67: 68: if (!$result) return -1; // connect failed 69: $time=round($time,4); 70: if ($time==0) $time=0.0001; 71: return $time; 72: } 73: 74: if (isset($NATS)) 75: { 76: class FreeNATS_SMB_Test extends FreeNATS_Local_Test 77: { 78: function DoTest($testname,$param,$hostname,$timeout,$params) 79: { 80: return smb_connect_time($params[0],$params[1],$params[2]); 81: } 82: function Evaluate($result) 83: { 84: if ($result<0) return 2; // failed 85: return 0; // passed 86: } 87: function DisplayForm(&$row) 88: { 89: echo ""; 90: echo ""; 95: echo ""; 96: echo ""; 101: echo ""; 102: echo ""; 108: echo ""; 109: echo "
"; 91: echo "Share :"; 92: echo ""; 93: echo ""; 94: echo "
Use full share with forward slashes i.e. //server/sharename
"; 97: echo "Username :"; 98: echo ""; 99: echo ""; 100: echo "
Leave username blank to attempt anonymous authentication
"; 103: echo "Password :"; 104: echo ""; 105: echo ""; 106: echo ""; 107: echo "
Leave blank to not change or click to clear
";
110: } 111: 112: function ProtectOutput(&$test) 113: { 114: $test['testparam2']=""; 115: } 116: 117: } 118: $params=array(); 119: $NATS->Tests->Register("smb","FreeNATS_SMB_Test",$params,"SMB Connect",1,"FreeNATS SMB Tester"); 120: $NATS->Tests->SetUnits("smb","Seconds","s"); 121: } 122: 123: 124: ?>