forked from jens-maus/fritzbox_api_php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fritzbox_get_foncallslist_xml.php
72 lines (64 loc) · 2.26 KB
/
fritzbox_get_foncallslist_xml.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?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
* works only with older firmwares, since AVM changed the file format, on newer firmwares restults in an empty file
* use new fritzbox_get_foncallslist.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.3 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 ( !$fritz->config->getItem('foncallslist_path') )
{
throw new Exception('Mandatory config Item foncallslist_path not set.');
}
if ( ( file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable($fritz->config->getItem('foncallslist_path')) ) || ( !file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable(dirname($fritz->config->getItem('foncallslist_path'))) ) )
{
throw new Exception('Config item foncallslist_path (' . $fritz->config->getItem('foncallslist_path') . ') is not writeable.');
}
// get the frontend-page to refresh the list
$params = array(
'getpage' => '../html/de/menus/menu2.html',
'var:menu' => 'fon',
'var:pagename' => 'foncalls',
'var:errorpagename' => 'foncalls',
'var:type' => '0',
);
$fritz->doPostForm($params);
// get the phone calls list
$params = array(
'getpage' => '../html/de/home/foncallsdaten.xml',
);
$output = $fritz->doGetRequest($params);
// write out the call list to the desired path
file_put_contents($fritz->config->getItem('foncallslist_path'), $output);
// set a log message
$message .= 'Call list sucessfully downloaded';
}
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
?>