/** * 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; }
* @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); break; case "test": $http_client->setOption(CURLOPT_HEADER, true); $result = $http_client->executeRequest(); break;
/** * Send the request on the server * * @param String $url URL * @param String[] $post Parameters POST * * @return bool|string */ static function serverCall($url, $post = null) { CSessionHandler::writeClose(); global $rootName, $version; $session_name = preg_replace("/[^a-z0-9]/i", "", $rootName); $cookie = CValue::cookie($session_name); $result = array("code" => "", "body" => ""); try { $http_client = new CHTTPClient($url); $http_client->setCookie("{$session_name}={$cookie}"); $http_client->setUserAgent("Mediboard-" . $version["version"]); $http_client->setOption(CURLOPT_FOLLOWLOCATION, true); if ($post) { $request = $http_client->post(http_build_query($post)); } else { $request = $http_client->get(); } } catch (Exception $e) { CSessionHandler::start(); $result["body"] = $e->getMessage(); return $result; } CSessionHandler::start(); $result["code"] = $http_client->last_information["http_code"]; $result["body"] = $request; return $result; }
/** * 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); }