Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enlever les prérequis (extension XMLRPC, Curl, json) #3

Closed
Progi1984 opened this issue Mar 16, 2013 · 7 comments
Closed

Enlever les prérequis (extension XMLRPC, Curl, json) #3

Progi1984 opened this issue Mar 16, 2013 · 7 comments

Comments

@Progi1984
Copy link
Owner

No description provided.

@spin0us
Copy link

spin0us commented Mar 26, 2013

Pour Metaglances (qui interroge également l'interface XML-RPC de glances), je n'utilise ni l’extension PHP-Curl, ni l’extension PHP-XML-RPC.

Pour remplacer Curl, j'utilise la fonction suivante :

function do_post_request($url, $data, $optional_headers = null) {
    $params = array('http' => array(
        'method' => 'POST',
        'content' => $data
        ));

    if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $stream = @fopen($url, 'rb', false, $ctx);
    if (!$stream) {
        if(isset($php_errormsg) && preg_match("/401/", $php_errormsg)) header("HTTP/1.1 401 Authentication failed");
        else header("HTTP/1.1 403 Forbidden");
        die();
    }
    $response = @stream_get_contents($stream);
    fclose($stream);
    if ($response === false || empty($response)) {
        throw new Exception("Problem reading data from $url");
    }
    return $response;
}

Et pour remplacer XML-RPC :

$authorization_header = (isset($_POST['pass']) && !empty($_POST['pass'])) ? "Authorization: Basic ".base64_encode("glances:".$_POST['pass'])."\r\n" : null;
$getAll = '<?xml version="1.0"?><methodCall><methodName>getAll</methodName></methodCall>';
$output = do_post_request('http://'.$ipv4.':'.$port.'/RPC2', $getAll, $authorization_header);
$xml = simplexml_load_string($output);
$json = json_decode($xml->params->param->value->string);

json_decode requiert PHP 5 >= 5.2.0 et PECL json >= 1.2.0
simplexml_load_string requiert PHP 5
Dans les deux cas on doit pouvoir trouver des codes sources pour remplacer ces deux fonctions pour les anciennes versions de PHP.

@Progi1984
Copy link
Owner Author

Je travaille actuellement à enlever le support de XMLRPC, puis j'enleverais le support de CURL, et finalement JSON.

Le problème de ta solution est d'utiliser simplexml_load_string($output) donc réutiliser une autre extension.

Actuellement, je cherche une solution à xmlrpc_decode et j'ai pensé à utiliser des regex, voire travailler avec du substr et strpos.

@Progi1984
Copy link
Owner Author

Extension XMLRPC : désactivé : OK !

@Progi1984
Copy link
Owner Author

Extension CURL: désactivé : OK !

@Progi1984
Copy link
Owner Author

Extension JSON: désactivé : OK !

@Progi1984
Copy link
Owner Author

Manque l'alternative à simplexml_load_string.

@Progi1984
Copy link
Owner Author

Extension SimpleXML: désactivé : OK !

Progi1984 added a commit that referenced this issue Jul 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants