Пример #1
0
     }
     if ($js['Type'] == 'AuthResp') {
         $ClientId = $js['Payload']['ClientId'];
         $pingtime = time();
         sendpack($sock, Ping());
         foreach ($Tunnels as $tunnelinfo) {
             //注册端口
             sendpack($sock, ReqTunnel($tunnelinfo['protocol'], $tunnelinfo['hostname'], $tunnelinfo['subdomain'], $tunnelinfo['rport']));
         }
     }
     if ($js['Type'] == 'NewTunnel') {
         if ($js['Payload']['Error'] != null) {
             ConsoleOut('Add tunnel failed,' . $js['Payload']['Error']);
             sleep(30);
         } else {
             ConsoleOut('Add tunnel ok,type:' . $js['Payload']['Protocol'] . ' url:' . $js['Payload']['Url']);
         }
     }
 }
 //远程代理连接
 if ($sockinfo['type'] == 2) {
     //未连接本地
     if ($sockinfo['linkstate'] == 1) {
         if ($js['Type'] == 'StartProxy') {
             $loacladdr = getloacladdr($Tunnels, $js['Payload']['Url']);
             $newsock = connectlocal($loacladdr['lhost'], $loacladdr['lport']);
             if ($newsock) {
                 $socklist[] = array('sock' => $newsock, 'linkstate' => 0, 'type' => 3, 'tosock' => $sock);
                 //把本地连接覆盖上去
                 $sockinfo['tosock'] = $newsock;
                 $sockinfo['linkstate'] = 2;
Пример #2
0
function ngrok_auth($clientid)
{
    $host = 'www.ngrok.cc';
    $port = 80;
    $fp = @fsockopen($host, $port, $errno, $errstr, 10);
    if (!$fp) {
        ConsoleOut('连接认证服务器: http://www.ngrok.cc 错误.');
        sleep(10);
        exit;
    }
    $header = "GET " . "/api/clientid/clientid/%s" . " HTTP/1.1" . "\r\n";
    $header .= "Host: %s" . "\r\n";
    $header .= "\r\n";
    $buf = sprintf($header, $clientid, $host);
    $write = fputs($fp, $buf);
    $body = null;
    while (!feof($fp)) {
        $line = fgets($fp, 1024);
        //去除请求包的头只显示页面的返回数据
        if ($line == "\n" || $line == "\r\n") {
            $body = fread($fp, 1024);
            break;
        }
    }
    fclose($fp);
    $authData = json_decode($body, true);
    if ($authData['status'] != 200) {
        ConsoleOut('认证错误:' . $authData['status'] . ' ErrorCode:' . $authData['msg']);
        sleep(10);
        exit;
    }
    ConsoleOut('认证成功,正在连接服务器...');
    return $authData['data'];
}
Пример #3
0
function natapp_auth($token)
{
    global $is_verify_peer;
    $host = 'auth.natapp.cn';
    $port = 443;
    $fp = stream_socket_client('tcp://' . $host . ':' . $port, $errno, $errstr, 10);
    if (!$fp) {
        ConsoleOut('连接认证服务器: https://auth.natapp.cn 错误.');
        sleep(10);
        exit;
    }
    if ($is_verify_peer == false) {
        stream_context_set_option($fp, 'ssl', 'verify_host', false);
        stream_context_set_option($fp, 'ssl', 'verify_peer_name', false);
        stream_context_set_option($fp, 'ssl', 'verify_peer', false);
        stream_context_set_option($fp, 'ssl', 'allow_self_signed', false);
    }
    stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT);
    $data = array('Authtoken' => $token['authtoken'], 'Clienttoken' => $token['clienttoken'], 'Token' => 'fffeephptokenkhd672');
    $query = json_encode($data);
    $header = "POST " . "/auth" . " HTTP/1.1" . "\r\n";
    $header .= "Content-Type: text/html" . "\r\n";
    $header .= "Host: %s" . "\r\n";
    $header .= "Content-Length: %d" . "\r\n";
    $header .= "\r\n" . "%s";
    $buf = sprintf($header, $host, strlen($query), $query);
    $write = fputs($fp, $buf);
    $body = null;
    while (!feof($fp)) {
        $line = fgets($fp, 1024);
        //去除请求包的头只显示页面的返回数据
        if ($line == "\n" || $line == "\r\n") {
            $chunk_size = (int) hexdec(fgets($fp, 1024));
            if ($chunk_size > 0) {
                $body = fread($fp, $chunk_size);
                break;
            }
        }
    }
    fclose($fp);
    $authData = json_decode($body, true);
    if ($authData['success'] == false) {
        ConsoleOut('认证错误:' . $authData['msg'] . ' ErrorCode:' . $authData['errorCode']);
        sleep(10);
        exit;
    }
    ConsoleOut('认证成功,正在连接服务器...');
    $proto = explode(':', $authData['data']['ServerAddr']);
    return $proto;
}