function OVH() { global $ovh_status; // -- Detection des arguments -- $args = func_get_args(); if (sizeof($args) < 2) { return false; } $api = $args[0]; if (!is_string($api)) { return false; } $ssid = $args[1]; if (sizeof($args) > 2) { $params = $args[2]; } else { $params = null; } if (is_array($ssid)) { list($params, $ssid) = array($ssid, $params); } if (is_array($ssid) || !is_array($params) && !is_null($params)) { return false; } if (!is_null($ssid)) { $full_params[] = $ssid; } if (!is_null($params)) { $full_params[] = $params; } // -- Temporisation -- $delay = 250; list($usec, $sec) = explode(" ", microtime()); $t = round((double) $usec * 1000 + (double) $sec * 1000); static $time = 0; if ($time == 0) { $time = $t - $delay; } if ($t - $time < $delay) { usleep($delay - ($t - $time)); } $time = $t; // -- Initialisation du client SOAP -- static $soap_client, $options; static $init = false; $return = false; if (!$init) { require "SOAP/Client.php"; $soap_client = new SOAP_Client("http://ovh.com:1663"); $soap_client->setEncoding("UTF-8"); $options = array("namespace" => "urn:manager", "trace" => 1, "timeout" => 10); $init = true; } // -- Verrouillage -- if ($api == "ClearNicSessions") { if (defined("OVHCLEARNIC")) { return $return; } else { define("OVHCLEARNIC", true); } } // -- Execution de la fonction API -- $result = $soap_client->call($api, $full_params, $options); if (!PEAR::isError($result)) { $result = get_object_vars($result); // -- Conversion des objets en tableaux -- if (!function_exists('OVH_OBJ_CONV')) { function OVH_OBJ_CONV($r) { if (is_object($r)) { $r = get_object_vars($r); } if (is_array($r)) { $r = array_map('OVH_OBJ_CONV', $r); } return $r; } } $result = array_map('OVH_OBJ_CONV', $result); // -- Traitement du resultat -- if (!isset($result["status"]) && isset($result["value"])) { if (is_numeric($result["value"])) { $ovh_status = $result["value"]; } else { $ovh_status = $result["status"]; } } else { $ovh_status = $result["status"]; } if (isset($result["ie"])) { $ovh_status .= "/" . $result["ie"]; } if (isset($result["msg"])) { $ovh_status .= " - " . $result["msg"]; } switch ($result["status"]) { case 100: $return = $result; break; case 304: if (ovh("ClearNicSessions", $params) !== false) { $return = ovh($api, $ssid, $params); } break; } } return $return; }
/** * Fetch data from SOAP service * * Requests the SOAP service for the given username/password * combination. * * @param string Username * @param string Password * @return mixed Returns the SOAP response or false if something went wrong */ function fetchData($username, $password) { // check if all required options are set if (array_intersect($this->_requiredOptions, array_keys($this->_options)) != $this->_requiredOptions) { return false; } else { // create a SOAP client and set encoding $soapClient = new SOAP_Client($this->_options['endpoint']); $soapClient->setEncoding($this->_options['encoding']); } // assign username and password fields $usernameField = new SOAP_Value($this->_options['usernamefield'], 'string', $username); $passwordField = new SOAP_Value($this->_options['passwordfield'], 'string', $password); $SOAPParams = array($usernameField, $passwordField); // assign optional features foreach ($this->_features as $fieldName => $fieldValue) { $SOAPParams[] = new SOAP_Value($fieldName, 'string', $fieldValue); } // make SOAP call $this->soapResponse = $soapClient->call($this->_options['method'], $SOAPParams, array('namespace' => $this->_options['namespace'])); if (!PEAR::isError($this->soapResponse)) { if ($this->_options['matchpasswords']) { // check if passwords match if ($password == $this->soapResponse->{$this->_options['passwordfield']}) { return true; } else { return false; } } else { return true; } } else { return false; } }