File: 1.15.0a/server/base/tests/smb.inc.php (View as HTML)

  1: <?php // smtp.inc.php -- SMTP test
  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 "<table border=0>";
 90: 		echo "<tr><td align=left>";
 91: 		echo "Share :";
 92: 		echo "</td><td align=left>";
 93: 		echo "<input type=text name=testparam size=30 maxlength=128 value=\"".$row['testparam']."\">";
 94: 		echo "</td></tr>";
 95: 		echo "<tr><td colspan=2><i>Use full share with forward slashes i.e. //server/sharename</i></td></tr>";
 96: 		echo "<tr><td align=left>";
 97: 		echo "Username :";
 98: 		echo "</td><td align=left>";
 99: 		echo "<input type=text name=testparam1 size=30 maxlength=128 value=\"".$row['testparam1']."\">";
100: 		echo "</td></tr>";
101: 		echo "<tr><td colspan=2><i>Leave username blank to attempt anonymous authentication</i></td></tr>";
102: 		echo "<tr><td align=left>";
103: 		echo "Password :";
104: 		echo "</td><td align=left>";
105: 		echo "<input type=text name=testparam2 size=30 maxlength=128 value=\"\">";
106: 		echo "<input type=hidden name=keepparam2 value=1>";
107: 		echo "</td></tr>";
108: 		echo "<tr><td colspan=2><i>Leave blank to not change or <input type=checkbox name=clearparam2 value=1> click to clear</i></td></tr>";
109: 		echo "</table>";
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: ?>