Skip to content

Commit

Permalink
fix a couple of little bugs stopping it working with D9
Browse files Browse the repository at this point in the history
  • Loading branch information
harryspink authored May 18, 2021
1 parent 97119cb commit ae81152
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions dial9.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function run()
printf("*** %s CALLS ***\n", strtoupper($type));
$page = 1;
unset($logs);
while(!isset($logs) || $logs['flags']['current_page'] < $logs['flags']['total_pages'])
while(!isset($logs) || count($logs['data']))
{
$logs = $this->curlDial9('logs/historical', array('type' => $type, 'page' => $page));
if($logs === false)
Expand Down Expand Up @@ -70,22 +70,24 @@ public function run()
continue;
}

$path = sprintf('%s/%s', DIRECTORY, substr($call['timestamp'], 0, 10));
$time = str_replace(':', '-', substr($call['timestamp'], 11, 8));
@mkdir($path);
$file_name = sprintf('%s/%s-%s.wav', $path, $type == 'incoming' ? $call['source']['id'] : $call['destination']['id'], $time);
if(file_exists($file_name) && filesize($file_name) > 0 && REMOVE == 1) {
printf("Already downloaded, deleting call %d\n", $call['id']);
$res = $this->curlDial9('logs/delete_recording', array('id' => $call['id']));
$file_name = sprintf('backups/%s.wav', $call['id']);
if(file_exists($file_name) && filesize($file_name) > 0) {
printf("Already downloaded %d\n", $call['id']);
if(REMOVE == 1){
printf("deleting call %d\n", $call['id']);
$res = $this->curlDial9('logs/delete_recording', array('id' => $call['id']));
}
} else {
printf("Downloading call %d\n", $call['id']);
file_put_contents(
$file_name,
base64_decode($recording['data']['file'])
);
}
} else {
printf("* NO RECORDING\n", $call['id']);
}
printf("* NO RECORDING\n", $call['id']);
}
$page++;
}
Expand All @@ -95,22 +97,23 @@ private function curlDial9($function, array $params = array())
{
$json = sprintf('params=%s', json_encode($params));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf('https://manage.dial9.co.uk/api/v2/%s', $function));
curl_setopt($ch, CURLOPT_URL, sprintf('https://connect.dial9.co.uk/api/v2/%s', $function));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
sprintf('X-Auth-Username: %s', USERNAME),
sprintf('X-Auth-Password: %s', PASSWORD)
sprintf('X-Auth-Token: %s', USERNAME),
sprintf('X-Auth-Secret: %s', PASSWORD)
)
);
$r = curl_exec($ch);

if(curl_errno($ch) !== 0) {
printf("Curl error: %d: %s\n", curl_errno($ch), curl_error($ch));
} else {
Expand Down

0 comments on commit ae81152

Please sign in to comment.