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);
44 fputs($fp, "POST $path HTTP/1.1\r\n");
45 foreach($post as $key => $val) {
47 foreach($val as $subval) {
48 if($data != "") { $data.="&"; }
49 $data .= $key."=".$subval;
52 if($data != "") { $data.="&"; }
53 $data .= $key."=".$val;
56 fputs($fp, "Accept-Language: de-DE\r\n");
57 fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
58 fputs($fp, "Accept-Encoding: deflate\r\n");
59 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");
60 fputs($fp, "Host: ".$host."\r\n");
61 foreach($this->cookies as $cookiename => $cookievalue) {
62 fputs($fp, "Cookie: ".$cookiename."=".$cookievalue."\r\n");
64 fputs($fp, "Content-Length: ".strlen($data)."\r\n");
65 fputs($fp, "Connection: Keep-Alive\r\n");
66 fputs($fp, "Cache-Control: no-cache\r\n");
71 $res .= fread($fp, 256);
73 $exp = explode("\n", str_replace("\r", "", $res));
74 for($i=0;$i<count($exp);$i++) {
75 $expb = explode(" ",$exp[$i],2);
76 if($expb[0] == "Set-Cookie:") {
77 $cookie = explode("=", $expb[1], 2);
78 $cookieval = explode(";", $cookie[1]);
79 $this->cookies[$cookie[0]] = $cookieval[0];
80 } else if($exp[$i] == "") {
88 public function get($host) {
90 if(strtolower(substr($host, 0, 7)) == 'http://') {
91 $host = substr($host, 7);
92 } else if(strtolower(substr($host, 0, 8)) == 'https://') {
93 $host = substr($host, 8);
96 $hexp = explode('/', $host, 2);
97 $pexp = explode(':', $hexp[0]);
105 $rhost = "ssl://".$host;
108 $fp = fsockopen($rhost, $port);
109 fputs($fp, "GET $path HTTP/1.1\r\n");
110 fputs($fp, "Accept-Language: de-DE\r\n");
111 fputs($fp, "Accept-Encoding: deflate\r\n");
112 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");
113 fputs($fp, "Host: ".$host."\r\n");
114 foreach($this->cookies as $cookiename => $cookievalue) {
115 fputs($fp, "Cookie: ".$cookiename."=".$cookievalue."\r\n");
117 fputs($fp, "Connection: Keep-Alive\r\n");
118 fputs($fp, "Cache-Control: no-cache\r\n");
122 $res .= fread($fp, 256);
124 $exp = explode("\n", str_replace("\r", "", $res));
125 for($i=0;$i<count($exp);$i++) {
126 $expb = explode(" ",$exp[$i],2);
127 if($expb[0] == "Set-Cookie:") {
128 $cookie = explode("=", $expb[1], 2);
129 $cookieval = explode(";", $cookie[1]);
130 $this->cookies[$cookie[0]] = $cookieval[0];
131 } else if($exp[$i] == "") {