Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/tabs/test.php
<?php

$radius=$oreon->database->getradiusconfiguration($_SESSION['locID']);
echo "
<br>
<table border=2 width=540 bgcolor=\"#666699\"  bordercolordark=#ffffe0 bordercolorlight=#000000  cellpadding=1 cellspacing=1>
<tr bgcolor=\"#666699\" valign=top>
<td class=\"bl\ width=340></td>
<td class=\"bl\  width=200>

<table border=2 width=100%  cellpadding=2 cellspacing=0>
        <tr bgcolor=\"#666699\" align=right valign=top><th>
         <font color=\"white\">User $login Test Page</font>&nbsp
</th></tr>
</table>
</td></tr>
<tr bgcolor=\"#666699\" valign=top><td colspan=2>";
if (isset($_POST['UserName']))  
	$pullUser=$_POST['UserName'];
if (isset($_POST['test_user']))  
	$test_user=$_POST['test_user'];
if (isset($_POST['passwd']))  
	$passwd=$_POST['passwd'];
if (isset($_POST['server']))  
	$server=$_POST['server'];
if (isset($_POST['port']))  
	$port=$_POST['port'];
if (isset($_POST['auth_proto']))  
	$auth_proto=$_POST['auth_proto'];

if ($server == '' || !preg_match('/^[\w\.]+$/',$server))
	$server = $radius_server;
if ($port == 0 || !is_numeric($port))
	$port = $radius_server_port;
if ($auth_proto == '')
	$auth_proto = $general_radius_server_auth_proto;

$selected[$auth_proto] = 'selected';
if ($debug) {
	echo " AUTH PROTO ".$auth_proto;
	echo " server ".$server."\n";
	echo " passwd ".$passwd."\n";
	echo " test_user ".$pullUser."\n";
	echo " RADIUSE SECRET ".$radiussecret."\n";
}
if ($test_user == 1){
	$tmp_file = tempnam("/tmp/",'DA');
	
	$comm = "radclient" . " $radius_server:$radius_server_port" . ' auth ' . $radiussecret
		. ' >' . $tmp_file;
	$fp = popen($comm,"w");

	if ($fp){
	  
	  fwrite($fp, "User-Name = $pullUser\n");
	  if ($auth_proto == 'chap')
	    fwrite($fp, "CHAP-Password = \"$passwd\"\n");
	  else
	    fwrite($fp, "User-Password = \"$passwd\"\n");
	  if (strlen($extra))
				fwrite($fp,$extra);
	  pclose($fp);
	  
	  $reply = file($tmp_file);
	  unlink($tmp_file);
	  $msg = "<b>" . strftime('%A, %e %B %Y, %T %Z') . "</b><br>\n";
	  $msg .= "<b>Server: </b><i>$server:$port</i><br><br>\n";
	  if (ereg('code 2', $reply[0]))
	    $msg .= "<b>Authentication was <font color=green>successful</font>";
	  else if (ereg('code 3',$reply[0]))
	    $msg .= "<b>Authentication <font color=red>failed</font>";
	  else if (ereg('no response from server', $reply[0]))
	    $msg .= "<b><font color=red>No response from server</font>";
	  else if (ereg('Connection refused',$reply[0]))
	    $msg .= "<b><font color=red>Connection was refused</font>";
	  
	  $msg .= "</b><br>\n";
	  array_shift($reply);
	  if (count($reply))
	    {
	      $msg .= "<br><b>Server response:</b><br>\n";
	      foreach ($reply as $val)
		{
		  $msg .= "<i>$val</i><br>\n";
		}
	    }
	}
}
echo "<form method=post>
      <input type=hidden name=login value=$pullUser>
      <input type=hidden name=tab value='d'>
      <input type=hidden name=test_user value=\"0\">
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor=\"#ffffe0\" valign=top>
<tr>
<td align=right class=\"bl\" >User Password</td>
<td>
<input type=password name=passwd value='$password' size=25>
</td>
</tr>
<tr>
<td align=right class=\"bl\">Radius Server</td>
<td>
<input type=text name=server value='$radius_server' size=25>
</td>
</tr>
<tr>
<td align=right class=\"bl\" >Radius Server Port</td>
<td>
<input type=text name=port value='$radius_server_port' size=25>
</td>
</tr>
<tr>
<td align=right class=\"bl\">Extra Attributes</td>
<td>
<textarea name=\"extra\" cols=\"35\" wrap=\"PHYSICAL\" rows=\"4\">$extra</textarea>
</td>
</tr>
<tr>
<td align=right class=\"bl\">Authentication Protocol</td>
<td>
<select name=\"auth_proto\" editable>
<option $selected[pap] value=\"pap\">PAP
<option $selected[chap] value=\"chap\">CHAP
</select>
</td>
<input type=submit class=button value=\"Run Test\" OnClick=\"this.form.test_user.value=1\">
</form></td></tr></table><center>";
if ($test_user == 1){
echo "<br><small>$msg";
}

echo "
</tr>
</table>";
?>
Return current item: phpMyPrepaid