<?php
/**
* Fritz!Box PHP tools CLI script to download the calllist from the Box
*
* Must be called via a command line, shows a help message if called without any or an invalid argument
* v0.3: Changed to download the new csv-file instead of the old xml, which is empty on newer firmwares
* on older firmwares use fritzbox_get_foncallslist_xml.php instead
*
* Check the config file fritzbox.conf.php!
*
* @author Gregor Nathanael Meyer <Gregor [at] der-meyer.de>
* @license
http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
* @version 0.4 2013-01-02
* @package Fritz!Box PHP tools
*/
try
{
// load the fritzbox_api class
require_once('fritzbox_api.class.php');
$fritz = new fritzbox_api();
// init the output message
$message = date('Y-m-d H:i').' ';
if(!$_GET['text'])
{
$params = array(
'getpage' => '/data.lua?xhr=1&lang=de&page=overview&type=all&no_sidrenew=&',
);
$calls = $fritz->doGetRequest($params);
$calls = json_decode($calls);
$callcount = count($calls->data->foncalls->activecalls);
print_r($calls->data->foncalls->activecalls);
$calls = $calls->data->foncalls->activecalls[0];
$calldir = '>';
if($_GET['dir'] == 'in') $calldir = '<';
if($callcount == 1 && $calls->display != '')$callstring1 = urlencode(''.trim(preg_replace('/[^0-9]/','',$calls->fonname)).''.$calldir.' '.$calls->display);
elseif($callcount > 1 && $calls->display != '')$callstring1 = urlencode($callcount.' '.trim(preg_replace('/[^0-9]/','',$calls->fonname)).''.$calldir.' '.$calls->display);
else $callstring1 = '';
if($callcount == 1 && $calls->display != '')$callstring2 = urlencode(''.$calldir.''.$calls->display);
elseif($callcount > 1 && $calls->display != '')$callstring2 = urlencode($callcount.''.$calldir.''.$calls->display);
else $callstring2 = '';
file_put_contents('callstring1',$callstring1);
$sendername = ' ';
if($callcount > 0 && $callstring1 != '')$sendername = $callstring1;
//$sendername = 'Antenne'.urlencode(date('H:i:s'));
$params = array(
'getpage' => '/data.lua?xhr=1&lang=de&no_sidrenew=&src_name='.$sendername.'&src_url=http%3A%2F%2Fmp3.webradio.antenne.de%3A80&src_fon_cnt=1&src_fon_cnt_all=6&src_fon_1=on&SrcId=0&newSrc=0&SrcType=ir&btn_save=&oldpage=%2Fdect%2Fsource_edit.lua&',
);
$output = $fritz->doGetRequest($params);
print_r($output);
}
else
{
$sendername = urlencode($_GET['text']);
$params = array(
'getpage' => '/data.lua?xhr=1&lang=de&no_sidrenew=&src_name='.$sendername.'&src_url=http%3A%2F%2Fmp3.webradio.antenne.de%3A80&src_fon_cnt=1&src_fon_cnt_all=6&src_fon_1=on&SrcId=0&newSrc=0&SrcType=ir&btn_save=&oldpage=%2Fdect%2Fsource_edit.lua&',
);
$output = $fritz->doGetRequest($params);
print_r($output);
}
// set a log message
$message .= 'Durch';
}
catch (Exception $e)
{
$message .= $e->getMessage();
}
// log the result
if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' )
{
$fritz->logMessage($message);
}
else
{
echo($message);
}
$fritz = null; // destroy the object to log out
?>