/** * Verify the disponibility of the tunnel * * @return bool */ function checkStatus() { try { $http_client = new CHTTPClient($this->address); $http_client->setOption(CURLOPT_HEADER, true); $http_client->setOption(CURLOPT_TIMEOUT, 10); $http_client->setOption(CURLOPT_CUSTOMREQUEST, "CMD TEST"); if ($this->ca_file) { $http_client->setSSLPeer($this->ca_file); } $result = $http_client->executeRequest(); } catch (Exception $e) { $this->_message_status = $e->getMessage(); $result = ""; } $return = preg_match("#200#", $result) ? "1" : "0"; if ($this->status !== $return) { $this->status = $return; if ($return && !$this->start_date) { $this->start_date = "now"; } else { $this->start_date = ""; } $this->store(); } return $return; }
/** * Get an HTTP client based on cURL * * @param string $location SOAP URL * @param string $ca_file Certification authority file path * @param array $headers HTTP headers * * @return CHTTPClient */ protected function getHttpClient($location, $ca_file, $headers) { $http_client = new CHTTPClient($location); if ($this->local_cert) { $http_client->setSSLAuthentification($this->local_cert, $this->passphrase); } if ($ca_file) { $http_client->setSSLPeer($ca_file); } $http_client->header = $headers; return $http_client; }
* * @category EAI * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ $action = CValue::get("action", null); $id = CValue::get("idTunnel", null); $param = CValue::get("param", null); $tunnel = new CHTTPTunnelObject(); $tunnel->load($id); $http_client = new CHTTPClient($tunnel->address); if ($tunnel->ca_file) { $http_client->setSSLPeer($tunnel->ca_file); } $result = ""; switch ($action) { case "restart": $http_client->setOption(CURLOPT_CUSTOMREQUEST, "CMD RESTART"); $result = $http_client->executeRequest(); break; case "stop": $http_client->setOption(CURLOPT_CUSTOMREQUEST, "CMD STOP"); $result = $http_client->executeRequest(); break; case "stat": $http_client->setOption(CURLOPT_CUSTOMREQUEST, "CMD STAT"); $result = $http_client->executeRequest(); $result = json_decode($result, true);
/** * Check the URL disponibility * * @param String $url URL site * @param String[] $option Option array * @param Boolean $return_body Return the content of the page * * @return bool|int */ static function checkUrl($url, $option = null, $return_body = false) { try { $http_client = new CHTTPClient($url); if ($option) { if (CMbArray::get($option, "ca_cert")) { $http_client->setSSLPeer($option["ca_cert"]); } if (CMbArray::get($option, "username") || CMbArray::get($option, "password")) { $http_client->setHTTPAuthentification($option["username"], $option["password"]); } if (CMbArray::get($option, "local_cert")) { $http_client->setSSLAuthentification($option["local_cert"], $option["passphrase"]); } } $http_client->setOption(CURLOPT_HEADER, true); $result = $http_client->get(); } catch (Exception $e) { return false; } if ($return_body) { return $result; } return preg_match("|200|", $result); }