$subdomain."\r\n";
// echo '$hostname:'.$hostname."\r\n";
// echo '$rport:'.$rport."\r\n";
foreach ($Tunnels as $k => $z) {
//
if ($protocol == $z['protocol']) {
if ($hostname == $z['hostname']) {
return $z;
}
if ($subdomain == $z['subdomain']) {
return $z;
}
if ($protocol == 'tcp') {
if ($rport == $z['rport']) {
return $z;
}
}
}
}
// array('protocol'=>$protocol,'hostname'=>'','subdomain'=>'','rport'=>0,'lhost'=>'','lport'=>80),
}
function NgrokAuth() {
$Payload = array(
'ClientId' => '',
'OS' => 'darwin',
'Arch' => 'amd64',
'Version' => '2',
'MmVersion' => '1.7',
'User' => 'user',
'Password' => '',
);
$json = array(
'Type' => 'Auth',
'Payload' => $Payload,
);
return json_encode($json);
}
function ReqTunnel($protocol, $HostName, $Subdomain, $RemotePort) {
$Payload = array(
'ReqId' => getRandChar(8),
'Protocol' => $protocol,
'Hostname' => $HostName,
'Subdomain' => $Subdomain,
'HttpAuth' => '',
'RemotePort' => $RemotePort,
);
$json = array(
'Type' => 'ReqTunnel',
'Payload' => $Payload,
);
return json_encode($json);
}
function RegProxy($ClientId) {
$Payload = array('ClientId' => $ClientId);
$json = array(
'Type' => 'RegProxy',
'Payload' => $Payload,
);
return json_encode($json);
}
function Pong() {
$Payload = (object) array();
$json = array(
'Type' => 'Pong',
'Payload' => $Payload,
);
return json_encode($json);
}
function Ping() {
$Payload = (object) array();
$json = array(
'Type' => 'Ping',
'Payload' => $Payload,
);
return json_encode($json);
}
/* 网络字节序 (只支持整型范围) */
function lentobyte($len) {
$xx = pack("N", $len);
$xx1 = pack("C4", 0, 0, 0, 0);
return $xx1 . $xx;
}
/* 机器字节序 (小端 只支持整型范围) */
function lentobyte1($len) {
$xx = pack("L", $len);
$xx1 = pack("C4", 0, 0, 0, 0);
return $xx . $xx1;
}
function sendpack($sock, $msg, $isblock = true) {
if ($isblock) {
stream_set_blocking($sock, 1); //设置为非阻塞模式
}
fwrite($sock, lentobyte1(strlen($msg)) . $msg);
if ($isblock) {
stream_set_blocking($sock, 0); //设置为非阻塞模式
}
}
function sendbuf($sock, $buf, $isblock = true) {
if ($isblock) {
stream_set_blocking($sock, 1); //设置为非阻塞模式
}
fwrite($sock, $buf);
if ($isblock) {
stream_set_blocking($sock, 0); //设置为非阻塞模式
}
}
/* 网络字节序 (只支持整型范围) */
function tolen($v) {
$array = unpack("N", $v);
return $array[1];
}
/* 机器字节序 (小端) 只支持整型范围 */
function tolen1($v) {
$array = unpack("L", $v);
return $array[1];
}
//随机生成字符串
function getRandChar($length) {
$str = null;
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($strPol) - 1;
for ($i = 0; $i < $length; $i++) {
$str .= $strPol[rand(0, $max)];
}
return $str;
}
//输出日记到命令行
function ConsoleOut($log) {
//cli
if (is_cli()) {
if (DIRECTORY_SEPARATOR == "\\") {
$log = iconv('UTF-8', 'GB2312', $log);
}
echo $log . "\r\n";
}
//web
else {
echo $log . "<br/>";
ob_flush();
flush();
// file_put_contents("ngrok.log", date("Y-m-d H:i:s:::") . $log . "\r\n", FILE_APPEND);
}
}
//判断是否命令行运行
function is_cli() {
return (php_sapi_name() === 'cli') ? true : false;
}
//注册退出执行函数
function shutdown(&$mainsocket) {
sendpack($mainsocket, 'close');
fclose($mainsocket);
}
?
Back to home |
File page
Subscribe |
Register |
Login
| N