2 /* HTTPConnector.class.php - HTTP Connector Class - ZNCAdmin
3 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 private $cookies = array();
22 public function post($host, $post) {
24 if(strtolower(substr($host, 0, 7)) == 'http://') {
25 $host = substr($host, 7);
26 } else if(strtolower(substr($host, 0, 8)) == 'https://') {
27 $host = substr($host, 8);
30 $hexp = explode('/', $host, 2);
31 $pexp = explode(':', $hexp[0]);
39 $rhost = "ssl://".$host;
43 $fp = fsockopen($rhost, $port);
46 fputs($fp, "POST $path HTTP/1.1\r\n");
47 foreach($post as $key => $val) {
49 foreach($val as $subval) {
50 if($data != "") { $data.="&"; }
51 $data .= $key."=".$subval;
54 if($data != "") { $data.="&"; }
55 $data .= $key."=".$val;
58 fputs($fp, "Accept-Language: de-DE\r\n");
59 fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
60 fputs($fp, "Accept-Encoding: deflate\r\n");
61 fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)\r\n");
62 fputs($fp, "Host: ".$host."\r\n");
63 foreach($this->cookies as $cookiename => $cookievalue) {
64 fputs($fp, "Cookie: ".$cookiename."=".$cookievalue."\r\n");
66 fputs($fp, "Content-Length: ".strlen($data)."\r\n");
67 fputs($fp, "Connection: Keep-Alive\r\n");
68 fputs($fp, "Cache-Control: no-cache\r\n");
73 $res .= fread($fp, 256);
75 $exp = explode("\n", str_replace("\r", "", $res));
76 for($i=0;$i<count($exp);$i++) {
77 $expb = explode(" ",$exp[$i],2);
78 if($expb[0] == "Set-Cookie:") {
79 $cookie = explode("=", $expb[1], 2);
80 $cookieval = explode(";", $cookie[1]);
81 $this->cookies[$cookie[0]] = $cookieval[0];
82 } else if($exp[$i] == "") {
90 public function get($host) {
92 if(strtolower(substr($host, 0, 7)) == 'http://') {
93 $host = substr($host, 7);
94 } else if(strtolower(substr($host, 0, 8)) == 'https://') {
95 $host = substr($host, 8);
98 $hexp = explode('/', $host, 2);
99 $pexp = explode(':', $hexp[0]);
107 $rhost = "ssl://".$host;
110 $fp = fsockopen($rhost, $port);
113 fputs($fp, "GET $path HTTP/1.1\r\n");
114 fputs($fp, "Accept-Language: de-DE\r\n");
115 fputs($fp, "Accept-Encoding: deflate\r\n");
116 fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)\r\n");
117 fputs($fp, "Host: ".$host."\r\n");
118 foreach($this->cookies as $cookiename => $cookievalue) {
119 fputs($fp, "Cookie: ".$cookiename."=".$cookievalue."\r\n");
121 fputs($fp, "Connection: Keep-Alive\r\n");
122 fputs($fp, "Cache-Control: no-cache\r\n");
126 $res .= fread($fp, 256);
128 $exp = explode("\n", str_replace("\r", "", $res));
129 for($i=0;$i<count($exp);$i++) {
130 $expb = explode(" ",$exp[$i],2);
131 if($expb[0] == "Set-Cookie:") {
132 $cookie = explode("=", $expb[1], 2);
133 $cookieval = explode(";", $cookie[1]);
134 $this->cookies[$cookie[0]] = $cookieval[0];
135 } else if($exp[$i] == "") {