phpwatch icon indicating copy to clipboard operation
phpwatch copied to clipboard

One more quick question - https

Open kmayeux opened this issue 12 years ago • 3 comments

One more quick question - is it/will it be possible to do pattern matching using HTTPS? I can't get it working with HTTPS pages.

Thanks!

kmayeux avatar Apr 21 '13 06:04 kmayeux

Not the best way, but solved it by adding to the queryMonitor function:

public function queryMonitor() { if ($this->port == 443) $prefix = "ssl://"; else $prefix = "";

$sock = @fsockopen($prefix .$this->hostname, $this->port, $errno, $errstr, intval($this->config['timeout']));

kmayeux avatar Apr 22 '13 07:04 kmayeux

Thank you for posting this. It doesn't work with SNI though:

[Sun Apr 03 20:59:34.879104 2016] [ssl:error] [pid 12463:tid 3084380239616] AH02031: Hostname frederik-braun.com provided via SNI, but no hostname provided in HTTP request

freddyb avatar Apr 03 '16 21:04 freddyb

It's working here. queryMonitor now looks like this for me:

        public function queryMonitor()
        {
            if ($this->port == 443) {
                $ctx = stream_context_create(
                        array('http' =>
                                array('timeout' => intval($this->config['timeout']))
                               )
                );
                $resp = @file_get_contents("https://" . $this->hostname ."/". $this->config['path']);
                $valid = $this->isValid($resp);
            }
            else {
                    $sock = @fsockopen($this->hostname, $this->port, $errno, $errstr, intval($this->config['timeout']));
                    if(!$sock)
                         return false;
                     $req  = "GET /" . $this->config['path'] . " HTTP/1.1\r\n";
                     $req .= "Host: " . $this->hostname . "\r\n";
                     $req .= "Connection: Close\r\n\r\n";
                     fwrite($sock, $req);

                     $resp = '';
                     while(!feof($sock))
                     {
                         $resp .= fread($sock, 1024);
                     }

                     $valid = $this->isValid($resp);
                     fclose($sock);
            }
            if($this->getMode() == HttpValidationMonitor::$MODE_DOES_CONTAIN)
                return $valid;
            else
                return !$valid;
        }

freddyb avatar Apr 04 '16 21:04 freddyb