Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $post_data = array(
- 'username'=> $USER,
- 'password'=> $PASS
- );
- $options = array(
- CURLOPT_URL => $urlCdr,
- CURLOPT_HEADER => true,
- CURLOPT_VERBOSE => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_SSL_VERIFYPEER => false, // for https
- // CURLOPT_USERPWD => $USER . ":" . $PASS,
- CURLOPT_HTTPAUTH => CURLAUTH_DIGEST,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => http_build_query($post_data)
- );
- $ch = curl_init();
- curl_setopt_array( $ch, $options );
- try {
- $raw_response = curl_exec( $ch );
- } catch(Exception $ex) {
- if ($ch != null) curl_close($ch);
- throw new Exception($ex);
- }
- if ($ch != null) curl_close($ch);
- $header = explode("\n", $raw_response)[3];
- $re = "/([a-z]+)=\"(.*?)\"/";
- preg_match_all($re, $header, $matches);
- $cnonce = time();
- $credentials[] = 'username="' . $USER . '"';
- $credentials[] = 'digest-uri="' . $urlCdr . '"';
- $credentials[] = 'cnonce="' . $cnonce . '"';
- $credentials[] = 'nc-value="1"';
- $credentials[] = 'responce="'. md5($USER . ':1' . ':' . $cnonce) .'"';
- foreach ($matches[1] as $k => $v) {
- $credentials[] = $v . '="' . $matches[2][$k] . '"';
- }
- $header = "Authorization: Digest " . implode(",\n", $credentials);
- $request = xmlrpc_encode_request("getAccountCDRs", array(
- 'username'=> $USER,
- 'password'=> $PASS
- ));
- $context = stream_context_create(array('http' => array(
- 'header' => "Content-type: text/xml\n" . $header,
- 'content' => $request
- )));
- // $file = file_get_contents($urlCdr, false, $context);
- $response = xmlrpc_decode($file);
- if ($response && xmlrpc_is_fault($response)) {
- trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
- } else {
- print_r($response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement