diff --git a/indefero/src/IDF/Webhook.php b/indefero/src/IDF/Webhook.php index 9d33d09..18db4aa 100644 --- a/indefero/src/IDF/Webhook.php +++ b/indefero/src/IDF/Webhook.php @@ -1,4 +1,5 @@ array( - // fall-back to POST for old queue items - 'method' => empty($payload['method']) ? 'POST' : $payload['method'], - 'content' => $data, - 'user_agent' => 'Indefero Hook Sender (http://www.indefero.net)', - 'max_redirects' => 0, - 'timeout' => 15, - 'header'=> $sign_header.': '.$sign."\r\n" - .'Content-Type: application/json'."\r\n", - ) - ); + $url = $payload['url']; - $ctx = stream_context_create($params); - $fp = @fopen($url, 'rb', false, $ctx); - if (!$fp) { - return false; - } - $meta = stream_get_meta_data($fp); - @fclose($fp); - if (!isset($meta['wrapper_data'][0]) or $meta['timed_out']) { - return false; - } - if (0 === strpos($meta['wrapper_data'][0], 'HTTP/1.1 2') or - 0 === strpos($meta['wrapper_data'][0], 'HTTP/1.1 3')) { - return true; - } - return false; + + $curl = new ccurl($url,true, 15, 0); + $curl->setPost($data); + $curl->addHeader("$sign_header: $sign"); + $curl->addHeader("Content-Type: application/json"); + $curl->createCurl(); + + return true; } diff --git a/pluf/src/Pluf/thirdparty/ccurl.php b/pluf/src/Pluf/thirdparty/ccurl.php new file mode 100644 index 0000000..596abe7 --- /dev/null +++ b/pluf/src/Pluf/thirdparty/ccurl.php @@ -0,0 +1,146 @@ +authentication = 0; + if($use == true) $this->authentication = 1; + } + + public function setName($name){ + $this->auth_name = $name; + } + public function setPass($pass){ + $this->auth_pass = $pass; + } + + public function addHeader($head) + { + $this->_header[] = $head; + } + + public function __construct($url,$followlocation = true,$timeOut = 30,$maxRedirecs = 4,$binaryTransfer = false,$includeHeader = false,$noBody = false) + { + $this->_url = $url; + $this->_followlocation = $followlocation; + $this->_timeout = $timeOut; + $this->_maxRedirects = $maxRedirecs; + $this->_noBody = $noBody; + $this->_includeHeader = $includeHeader; + $this->_binaryTransfer = $binaryTransfer; + + $this->_cookieFileLocation = dirname(__FILE__).'/cookie.txt'; + + } + + public function setReferer($referer){ + $this->_referer = $referer; + } + + public function setCookiFileLocation($path) + { + $this->_cookieFileLocation = $path; + } + + public function setPost ($postFields) + { + $this->_post = true; + $this->_postFields = $postFields; + } + + public function setUserAgent($userAgent) + { + $this->_useragent = $userAgent; + } + + public function createCurl($url = 'nul') + { + if($url != 'nul'){ + $this->_url = $url; + } + + $s = curl_init(); + + curl_setopt($s,CURLOPT_URL,$this->_url); + + // I understand the implications here - but this isn't a client application + // if my ISP is performing MITM sniffing I have bigger fish to fry + // also the security of a CA signed certificate is questionable at best + // https://www.schneier.com/blog/archives/2012/02/verisign_hacked.html + // Email me if you want to discus this adamsna@datanethost.net + // NA - 12/10/2014 + curl_setopt($s, CURLOPT_SSL_VERIFYPEER, false); + + curl_setopt($s,CURLOPT_HTTPHEADER,$this->_header); + curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout); + curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects); + curl_setopt($s,CURLOPT_RETURNTRANSFER,true); + curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation); + curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation); + curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation); + + if($this->authentication == 1){ + curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass); + } + if($this->_post) + { + //curl_setopt($s,CURLOPT_POST,true); + curl_setopt($s, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields); + + } + + if($this->_includeHeader) + { + curl_setopt($s,CURLOPT_HEADER,true); + } + + if($this->_noBody) + { + curl_setopt($s,CURLOPT_NOBODY,true); + } + + curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent); + curl_setopt($s,CURLOPT_REFERER,$this->_referer); + + $this->_webpage = curl_exec($s); + $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE); + curl_close($s); + + } + + public function getHttpStatus() + { + return $this->_status; + } + + public function __tostring(){ + return $this->_webpage; + } +} +?> \ No newline at end of file