Пример #1
0
 /**
  * Méthode permettant de tester si le service d'extraction Tika est actif
  *
  * @return string
  */
 function loadTikaInfos()
 {
     $conf_host = trim(CAppUI::conf("search tika_host"));
     $conf_port = trim(CAppUI::conf("search tika_port"));
     $client = new CHTTPClient("http://{$conf_host}:{$conf_port}/tika");
     return $client->get();
 }
Пример #2
0
 /**
  * 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;
 }
 /**
  * Test if the WSDL is reachable, and create the object SOAPClient
  *
  * @param string  $rooturl        The url of the WSDL
  * @param string  $login          The login
  * @param string  $password       The password
  * @param string  $type           Exchange type
  * @param array   $options        The options
  * @param boolean $loggable       Log the exchanges
  * @param string  $stream_context HTTP method (GET, POST, HEAD, PUT, ...)
  * @param string  $local_cert     Path of the certifacte
  * @param string  $passphrase     Pass phrase for the certificate
  * @param boolean $safe_mode      Safe mode
  * @param boolean $verify_peer    Require verification of SSL certificate used
  * @param string  $cafile         Location of Certificate Authority file on local filesystem
  * @param String  $wsdl_external  Location of external wsdl
  * @param int     $socket_timeout Default timeout (in seconds) for socket based streams
  *
  * @throws CMbException
  *
  * @return CMbSOAPClient | CNuSOAPClient
  */
 public function make($rooturl, $login = null, $password = null, $type = null, $options = array(), $loggable = null, $stream_context = null, $local_cert = null, $passphrase = null, $safe_mode = false, $verify_peer = false, $cafile = null, $wsdl_external = null, $socket_timeout = null)
 {
     if ($login && $password || array_key_exists('login', $options) && array_key_exists('password', $options)) {
         $login = $login ? $login : $options['login'];
         if (preg_match('#\\%u#', $rooturl)) {
             $rooturl = str_replace('%u', $login, $rooturl);
         } else {
             $options['login'] = $login;
         }
         $password = $password ? $password : $options['password'];
         if (preg_match('#\\%p#', $rooturl)) {
             $rooturl = str_replace('%p', $password, $rooturl);
         } else {
             $options['password'] = $password;
         }
     }
     $check_option["local_cert"] = $local_cert;
     $check_option["ca_cert"] = $cafile;
     $check_option["passphrase"] = $passphrase;
     $check_option["username"] = $login;
     $check_option["password"] = $password;
     if (!$safe_mode) {
         if (!CHTTPClient::checkUrl($rooturl, $check_option)) {
             throw new CMbException("CSourceSOAP-unreachable-source", $rooturl);
         }
     }
     switch ($this->type_client) {
         case 'CNuSOAPClient':
             $this->client = new CNuSOAPClient($rooturl, $type, $options, $loggable, $local_cert, $passphrase, $safe_mode, $verify_peer, $cafile);
             break;
         default:
             $this->client = new CMbSOAPClient($rooturl, $type, $options, $loggable, $local_cert, $passphrase, $safe_mode, $verify_peer, $cafile, $wsdl_external, $socket_timeout);
             break;
     }
     if (!$this->client) {
         throw new CMbException("CSourceSOAP-soapclient-impossible");
     }
     return $this->client;
 }
 /**
  * Check service availability
  *
  * @throws CMbException
  *
  * @return void
  */
 public function checkServiceAvailability()
 {
     $url = $this->wsdl_url;
     if ($this->wsdl_original) {
         $url = $this->wsdl_original;
     }
     $xml = file_get_contents($url);
     $dom = new CMbXMLDocument();
     $dom->loadXML($xml);
     $xpath = new CMbXPath($dom);
     $xpath->registerNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
     $xpath->registerNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
     $xpath->registerNamespace("soap12", "http://schemas.xmlsoap.org/wsdl/soap12");
     $login = CMbArray::get($this->options, "login");
     $password = CMbArray::get($this->options, "password");
     $service_nodes = $xpath->query("//wsdl:service");
     foreach ($service_nodes as $_service_node) {
         $service_name = $_service_node->getAttribute("name");
         $port_nodes = $xpath->query("wsdl:port", $_service_node);
         foreach ($port_nodes as $_port_node) {
             $address = $xpath->queryAttributNode("soap:address|soap12:address", $_port_node, "location");
             if (!$address) {
                 continue;
             }
             if ($login && $password) {
                 $address = str_replace("://", "://{$login}:{$password}@", $address);
             }
             // Url exist
             $url_exist = CHTTPClient::checkUrl($address, $this->check_option);
             if (!$url_exist) {
                 throw new CMbException("Service '{$service_name}' injoignable à l'adresse : <em>{$address}</em>");
             }
         }
     }
 }
Пример #5
0
/**
 * $Id$
 *  
 * @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");
Пример #6
0
 /**
  * If source is reachable
  *
  * @return bool|void
  */
 function isReachableSource()
 {
     $check_option["local_cert"] = $this->local_cert;
     $check_option["ca_cert"] = $this->cafile;
     $check_option["passphrase"] = $this->getPassword($this->passphrase, "iv_passphrase");
     $check_option["username"] = $this->user;
     $check_option["password"] = $this->getPassword();
     if (!$this->safe_mode) {
         if (!CHTTPClient::checkUrl($this->host, $check_option)) {
             $this->_reachable = 0;
             $this->_message = CAppUI::tr("CSourceSOAP-unreachable-source", $this->host);
             return false;
         }
     }
     return true;
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
0
<?php

/**
 * $Id$
 *  
 * @category Search
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html 
 * @link     http://www.mediboard.org */
CCanDo::checkAdmin();
$request = CValue::get("request");
$type = CValue::get("type_request");
$content = "";
if ($request && !strripos($request, "delete")) {
    $client = new CHTTPClient($request);
    switch ($type) {
        case "get":
            $content = $client->get();
            break;
        case "put":
            $content = $client->putFile($request);
            break;
        case "post":
            $content = $client->post($request);
            break;
        default:
            $content = $client->get();
    }
}
$content = json_decode($content, true);
Пример #9
0
 /**
  * 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);
 }