function dohandshake($buffer)
{
    // Hixie-76 Handshake
    ////////$this->log("\nRequesting handshake...");
    ////////////$this->log($buffer);
    list($resource, $host, $origin, $key1, $key2, $l8b) = getheaders($buffer);
    /////////$this->log("Handshaking...");
    //$port = explode(":",$host);
    //$port = $port[1];
    //$this->log($origin."\r\n".$host);
    $upgrade = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $origin . "\r\n" . "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" . "\r\n" . calcKey($key1, $key2, $l8b) . "\r\n";
    // .
    //"\r\n";
    //socket_write($user->socket,$upgrade.chr(0),strlen($upgrade.chr(0)));
    return $upgrade;
}
Esempio n. 2
0
function dohandshake($user, $buffer)
{
    console("\nRequesting handshake...");
    #console($buffer);
    list($resource, $host, $origin, $strkey, $data) = getheaders($buffer);
    if (strlen($strkey) == 0) {
        socket_close($user->socket);
        console('failed');
        return false;
    }
    $hash_data = base64_encode(sha1($strkey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true));
    $upgrade = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" . "Upgrade: webSocket\r\n" . "Connection: Upgrade\r\n" . "WebSocket-Origin: " . $origin . "\r\n" . "WebSocket-Location: ws://" . $host . $resource . "\r\n" . "Sec-WebSocket-Accept:" . $hash_data . "\r\n\r\n";
    socket_write($user->socket, $upgrade, strlen($upgrade));
    $user->handshake = true;
    #console($upgrade);
    console("Done handshaking...\n");
    return true;
}
Esempio n. 3
0
function dohandshake($user, $buffer)
{
    console("\nRequesting handshake...");
    console($buffer);
    /*        
      GET {resource} HTTP/1.1
      Upgrade: WebSocket
      Connection: Upgrade
      Host: {host}
      Origin: {origin}
      \r\n
    */
    list($resource, $host, $origin) = getheaders($buffer);
    //$resource = "/phpwebsocketchat/server.php";
    //$host     = "localhost:12345";
    //$origin   = "http://localhost";
    console("Handshaking...");
    $upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "WebSocket-Origin: " . $origin . "\r\n" . "WebSocket-Location: ws://" . $host . $resource . "\r\n" . "\r\n";
    socket_write($user->socket, $upgrade . chr(0), strlen($upgrade . chr(0)));
    $user->handshake = true;
    console($upgrade);
    console("Done handshaking...");
    return true;
}
Esempio n. 4
0
function dohandshake($user, $buffer)
{
    console("\nRequesting handshake...");
    console($buffer);
    list($resource, $host, $origin, $strkey1, $strkey2, $data) = getheaders($buffer);
    console("Handshaking...");
    $pattern = '/[^\\d]*/';
    $replacement = '';
    $numkey1 = preg_replace($pattern, $replacement, $strkey1);
    $numkey2 = preg_replace($pattern, $replacement, $strkey2);
    $pattern = '/[^ ]*/';
    $replacement = '';
    $spaces1 = strlen(preg_replace($pattern, $replacement, $strkey1));
    $spaces2 = strlen(preg_replace($pattern, $replacement, $strkey2));
    if ($spaces1 == 0 || $spaces2 == 0 || $numkey1 % $spaces1 != 0 || $numkey2 % $spaces2 != 0) {
        socket_close($user->socket);
        console('failed');
        return false;
    }
    $ctx = hash_init('md5');
    hash_update($ctx, pack("N", $numkey1 / $spaces1));
    hash_update($ctx, pack("N", $numkey2 / $spaces2));
    hash_update($ctx, $data);
    $hash_data = hash_final($ctx, true);
    $upgrade = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $origin . "\r\n" . "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" . "\r\n" . $hash_data;
    socket_write($user->socket, $upgrade . chr(0), strlen($upgrade . chr(0)));
    $user->handshake = true;
    console($upgrade);
    console("Done handshaking...");
    return true;
}
 function dohandshake($user, $buffer)
 {
     $this->console("\nRequesting handshake...");
     $this->console($buffer);
     list($resource, $host, $origin, $strkey1, $strkey2, $data, $version) = getheaders($buffer);
     console("Handshaking...");
     $pattern = '/[^\\d]*/';
     $replacement = '';
     $numkey1 = preg_replace($pattern, $replacement, $strkey1);
     $numkey2 = preg_replace($pattern, $replacement, $strkey2);
     $pattern = '/[^ ]*/';
     $replacement = '';
     $spaces1 = strlen(preg_replace($pattern, $replacement, $strkey1));
     $spaces2 = strlen(preg_replace($pattern, $replacement, $strkey2));
     $user->version = $version;
     if ($version >= 8) {
         if (!$strkey1) {
             $this->closeConnection($user->socket);
             $this->console('failed');
             return false;
         }
         $this->console(trim($strkey1));
         $accept = base64_encode(sha1(trim($strkey1) . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true));
         $upgrade = "HTTP/1.1 101 Switching Protocols\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Accept: {$accept}\r\n" . "\r\n";
         socket_write($user->socket, $upgrade . chr(0), strlen($upgrade . chr(0)));
     } else {
         if ($spaces1 == 0 || $spaces2 == 0 || fmod($numkey1, $spaces1) != 0 || fmod($numkey2, $spaces2) != 0) {
             $this->closeConnection($user->socket);
             $this->console('failed');
             return false;
         }
         $ctx = hash_init('md5');
         hash_update($ctx, pack("N", $numkey1 / $spaces1));
         hash_update($ctx, pack("N", $numkey2 / $spaces2));
         hash_update($ctx, $data);
         $hash_data = hash_final($ctx, true);
         $upgrade = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $origin . "\r\n" . "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" . "\r\n" . $hash_data;
         socket_write($user->socket, $upgrade . chr(0), strlen($upgrade . chr(0)));
     }
     $user->handshake = true;
     $this->console($upgrade);
     $this->console("Done handshaking...");
     return true;
 }
Esempio n. 6
0
function dohandshake($user, $buffer)
{
    console("\nRequesting handshake...");
    console($buffer);
    list($resource, $host, $origin, $key) = getheaders($buffer);
    console("Handshaking...");
    $upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Accept: " . base64_encode(sha1($key . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true)) . "\r\n" . "\r\n";
    socket_write($user->socket, $upgrade);
    $user->handshake = true;
    console($upgrade);
    console("Done handshaking...");
    return true;
}
Esempio n. 7
0
function dohandshake($user, $buffer)
{
    list($resource, $host, $origin, $strkey) = getheaders($buffer);
    $strkey .= "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
    $hash_data = base64_encode(sha1($strkey, true));
    $upgrade = "HTTP/1.1 101 Switching Protocols\r\n" . "Upgrade: websocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Accept: " . $hash_data . "\r\n" . "Sec-WebSocket-Protocol: websocket\r\n" . "\r\n";
    socket_write($user->socket, $upgrade, strlen($upgrade));
    $user->handshake = true;
    return true;
}
Esempio n. 8
0
function dohandshake($user, $buffer)
{
    global $sockets, $port;
    console("\nRequesting handshake...");
    console($buffer);
    if (substr($buffer, 0, 22) == "<policy-file-request/>") {
        console("Responding with policy file request...");
        $response = '<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">' . "\n" . '<cross-domain-policy><allow-access-from domain="*" to-ports="' . $port . '"/></cross-domain-policy>';
        socket_write($user->socket, $response, strlen($response));
        $index = array_search($user->socket, $sockets);
        if ($index >= 0) {
            array_splice($sockets, $index, 1);
        }
        socket_close($user->socket);
        return false;
    }
    list($resource, $host, $origin, $version, $strkey, $strkey1, $strkey2, $data) = getheaders($buffer);
    console("Handshaking...");
    $user->version = $version && intval($version);
    if ($version && intval($version) >= 8) {
        $accept = base64_encode(sha1($strkey . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true));
        $upgrade = "HTTP/1.1 101 Switching Protocols\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Accept: " . $accept . "\r\n" . "\r\n";
        socket_write($user->socket, $upgrade, strlen($upgrade));
    } else {
        $pattern = '/[^\\d]*/';
        $replacement = '';
        $numkey1 = preg_replace($pattern, $replacement, $strkey1);
        $numkey2 = preg_replace($pattern, $replacement, $strkey2);
        $pattern = '/[^ ]*/';
        $replacement = '';
        $spaces1 = strlen(preg_replace($pattern, $replacement, $strkey1));
        $spaces2 = strlen(preg_replace($pattern, $replacement, $strkey2));
        if ($spaces1 == 0 || $spaces2 == 0 || fmod($numkey1, $spaces1) != 0 || fmod($numkey2, $spaces2) != 0) {
            $index = array_search($user->socket, $sockets);
            if ($index >= 0) {
                array_splice($sockets, $index, 1);
            }
            socket_close($user->socket);
            console('failed');
            return false;
        }
        $ctx = hash_init('md5');
        hash_update($ctx, pack("N", $numkey1 / $spaces1));
        hash_update($ctx, pack("N", $numkey2 / $spaces2));
        hash_update($ctx, $data);
        $hash_data = hash_final($ctx, true);
        $upgrade = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $origin . "\r\n" . "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" . "\r\n" . $hash_data;
        socket_write($user->socket, $upgrade . chr(0), strlen($upgrade . chr(0)));
    }
    $user->handshake = true;
    console($upgrade);
    console("Done handshaking...");
    return true;
}
Esempio n. 9
0
         } else {
             $connectsuccess = true;
         }
     }
 }
 if (!$connectsuccess) {
     echo "" . "An Error Occurred: " . $imaplasterror . "<hr>";
 } else {
     $headers = imap_headers($mbox);
     $emailcount = count($headers);
     echo "" . "Email Count: " . $emailcount . "<hr>";
     if ($emailcount) {
         $msgno = 1;
         while ($msgno <= $emailcount) {
             $sections = $attachments = "";
             $header_info = getheaders($mbox, $msgno);
             $structure = imap_fetchstructure($mbox, $msgno);
             if (1 < sizeof($structure->parts)) {
                 $sections = parse($structure);
                 $attachments = get_attachments($sections);
             }
             $msgBody = get_part($mbox, $msgno, "TEXT/PLAIN");
             if (!$msgBody) {
                 $msgBody = get_part($mbox, $msgno, "TEXT/HTML");
                 $msgBody = strip_tags($msgBody);
             }
             if (!$msgBody) {
                 $msgBody = "No message found.";
             }
             $msgBody = str_replace("&nbsp;", " ", $msgBody);
             $attachmentslist = "";
Esempio n. 10
0
<?php

/*
* Get  all message headers of the HTTP request with php.
*
*/
$res = getheaders(1, 0);
echo $res;
function getheaders($env = 1, $all = false)
{
    $cr = $env ? "\n" : "</br>";
    $string = '';
    foreach ($_SERVER as $k => $v) {
        if ($all) {
            $string .= "{$k}" . "=>" . $v . $cr . $cr;
        } elseif ('HTTP' == substr($k, 0, 4)) {
            $string .= "{$k}" . "=>" . $v . $cr . $cr;
        }
    }
    return $string;
}