应某人的邀请,把网上的python版本的代码改写成了php版本了。
将自己的账号密码Mac地址添加到文件中保存
网关登陆:http://abc.com/srun.php?do=login
网关退出:http://abc.com/srun.php?do=logout
P.S.代码如下(地址):
<?php
/*
*Creat At 2012/10/25 23:29
*Author: Austin
*URL: http://imnerd.org
*Mail: [email protected]
*Description: Srun Authorize Login & Logout By PHP
*/
//网关登陆:http://abc.com/srun.php?do=login
//网关退出:http://abc.com/srun.php?do=logout
//将自己的账号,密码,Mac地址填写到两个分号中
define('username', '');
define('password', '');
define('mac', '');//Mac地址的格式为aa:bb:cc:dd,全部为小写
/*下面的就不用改了,嘻嘻!*/
define('host', '202.204.105.195');
function curl($data, $url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
switch($_GET['do']) {
case 'login':
$data = 'username='.username.'&password='.password.'&mac='.mac.'&n=99&type=3';
$url = 'http://'.host.':3333/cgi-bin/do_login';
$uid = curl($data, $url);
echo file_put_contents('uid.txt', $uid) ? 'Success!' : 'Failed!';
break;
case 'logout':
if(file_exists('uid.txt')) {
$uid = file_get_contents('uid.txt');
} else {
die('not login yet!');
}
$data = 'uid='.$uid;
$url = 'http://'.host.':3333/cgi-bin/do_logout';
$result = curl($data, $url);
print_r($result);
break;
default:
die('Bug for u!');
break;
}
?>
|