所以我在我的linux机器上安装了这个php脚本,在运行时,它只是“挂起”
我已经安装了所需的所有必需的PHP依赖项,我在同一文件夹中也有“settings.php”,在文件夹和文件上使用(chmod 777)。 代码:
<?php
$f = fopen( 'php://stdin', 'r' );
while( $input = fgets( $f ) ) {
//while( $input = readline() ) {
if ($pid = pcntl_fork()) { return; }
acctstart($input);
fclose($f);
}
function acctstart($input) {
require_once("settings.php");
$input = $input;
$delimiter1 = "The new session";
$delimiter2 = "has been created";
$pos1 = strpos($input, $delimiter1) + strlen($delimiter1) + 2;
$pos2 = strpos($input, $delimiter2) - 2;
$sstrlen = $pos2 - $pos1;
$sessid = substr($input, $pos1, $sstrlen);
exec($vpncmd." ".$softetherip." /SERVER /HUB:".$hubname." /PASSWORD:".$apipass." /CSV /CMD SessionGet ".$sessid, $SessionGet);
if(strpos($SessionGet[0],"rror occurred") != FALSE) { die("Error - SessionGet resulted in error"); }
foreach ($SessionGet as $line){
list($key,$val) = explode(",",$line,2);
$result[$key] = $val;
}
$recheck = 0;
dhcptest:
sleep(2);
exec($vpncmd." ".$softetherip." /SERVER /HUB:".$hubname." /PASSWORD:".$apipass." /CSV /CMD IpTable", $IpTable);
$ok=0;
foreach ($IpTable as $line){
if(strpos($line,$sessid)){
if(strpos($line,"DHCP")){
list(,$key,$val) = explode(",",$line);
list($framedip) = explode(" ",$val);
#$result2[$key] = $val;
$ok=1;
}
}
}
if($ok==0){
if($recheck==4) {die("Error - could not find session in retrived IpTable data");}
sleep(2);
$recheck = $recheck + 1;
goto dhcptest;
}
if( file_exists( $database ) )
{
echo "The file $filename exists";
}
else
{
echo "The file $filename does not exist";
}
$db = new SQLite3($database);
$db->exec('CREATE TABLE IF NOT EXISTS sessions (sessionid varchar(255), username varchar (255), clientip varchar (255), inputoctets varchar (255), ' .
'outputoctets varchar (255), framedip varchar (255), nasip varchar (255), nasport varchar (255), acctstarttime varchar (255), '.
'acctsessiontime varchar (255), PRIMARY KEY(sessionid))');
$query = $db->escapeString('INSERT OR REPLACE INTO sessions (sessionid, username, clientip, inputoctets, outputoctets, framedip, nasip, nasport, acctstarttime, acctsessiontime) VALUES ("'.$sessid.'","'.$result["User Name (Authentication)"].'","'.$result["Client IP Address"].'",NULL,NULL,"'.$framedip.'","'.$result["Server IP Address (Reported)"].'","'.$result["Server Port (Reported)"].'","'.$result["Connection Started at"].'",NULL)');
$db->exec($query);
$sessid = $db->escapeString($sessid);
$results = $db->querySingle("SELECT * FROM sessions WHERE sessionid = '".$sessid."'", true);
$tmpfname = tempnam($tmpdir, "acctstarttmp_");
$handle = fopen($tmpfname, "w");
$packet = "Service-Type = Framed-User"."\n".
"Framed-Protocol = PPP"."\n".
"NAS-Port = ".$results['nasport']."\n".
"NAS-Port-Type = Async"."\n".
"User-Name = '".$results['username']."'"."\n".
"Calling-Station-Id = '".$results['clientip']."'"."\n".
"Called-Station-Id = '".$results['nasip']."'"."\n".
"Acct-Session-Id = '".$sessid."'"."\n".
"Framed-IP-Address = ".$results['framedip']."\n".
"Acct-Authentic = RADIUS"."\n".
"Event-Timestamp = ".time()."\n".
"Acct-Status-Type = Start"."\n".
"NAS-Identifier = '".$results['nasip']."'"."\n".
"Acct-Delay-Time = 0"."\n". // handle?
"NAS-IP-Address = ".$results['nasip']."\n";
fwrite($handle, $packet);
fclose($handle);
exec("radclient ".$radiussrv.":".$radiusport." acct ".$radiuspass." -f ".$tmpfname);
unlink($tmpfname);
$db->close();
}
//fclose( $f );
?>
任何想法有什么不对?
此致
答案 0 :(得分:2)
根据事物的外观,它“挂起”因为它正在等待用户输入(也就是在键盘上打字)
答案 1 :(得分:0)
为什么你不在控制台中使用curl?那个特别执行你的php文件。
例如,如果您想要转储标头,请使用:
curl -D /var/radius/acctstart.php
如果您没有安装curl,只需将此方法用于Debian
sudo apt-get install curl
要检查PHP错误,这是使用此网站的最佳方式: