1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| <?php
/*========================*/
/* Initialisation */
/*========================*/
$avant = array('<','>');
$apres = array('<','>');
$opts = [
CURLOPT_URL => 'http://192.168.1.1/api/1.0/?method=auth.getToken',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 60,
CURLOPT_TIMEOUT => 60,
CURLOPT_VERBOSE => true,
CURLOPT_COOKIESESSION => true
];
/*===========================================*/
/* Extraction numéro d'authorisation */
/*===========================================*/
$curl = curl_init();
curl_setopt_array($curl, $opts);
$xml = simplexml_load_string(curl_exec($curl), "SimpleXMLElement", LIBXML_NOCDATA);
$token = $xml->auth['token'];
/*=======================*/
/* Hash du Login */
/*=======================*/
$login = 'admin';
$hash1 = hash_hmac('sha256',hash('sha256',$login),$token);
/*==========================*/
/* Hash du Password */
/*==========================*/
$password = '????????????????????';
$hash2 = hash_hmac('sha256',hash('sha256',$password),$token);
/*========================================*/
/* Nouveau numéro d'authorisation */
/*========================================*/
$opts[CURLOPT_URL] = 'http://192.168.1.1/api/1.0/?method=auth.checkToken&token='.$token.'&hash='.$hash1.$hash2;
unset ($hash1,$hash2);
curl_setopt_array($curl, $opts);
$xml = simplexml_load_string(curl_exec($curl), "SimpleXMLElement", LIBXML_NOCDATA);
$token = $xml->auth['token'];
?> |
Partager