├── CHANGELOG.txt
├── README.md
├── bin
├── example_pb.xml
├── fritzbox.conf.php
├── fritzbox_diversity0on.php
├── fritzbox_get_foncallslist.php
├── fritzbox_guestlan_on_off.php
├── fritzbox_guestwlan_on_off.php
├── fritzbox_phonebook_export.php
├── fritzbox_phonebook_import.php
├── fritzbox_reboot.php
├── fritzbox_ring_phone.php
└── fritzbox_tam_on_off.php
└── lib
└── fritzbox_api.class.php
/CHANGELOG.txt:
--------------------------------------------------------------------------------
1 | 0.5 2012-09-23
2 | ---
3 |
4 | * added doPostFile() to upload and download Files (for example the phonebook) to and from the box
5 | * added sample script to reboot (thanks to godghost)
6 | * added sample script to download/upload phonebook (CAUTION: the upload will overwrite your current phonebook)!
7 | * restructured code in folders
8 |
9 |
10 | 0.4.1 2012-03-15:
11 | ---
12 |
13 | * added a new script fritzbox_guestlan_on_off.php to switch the new Guest-LAN on and off
14 | * tested all builtin scripts with new FRITZ!OS 05.20
15 |
16 |
17 | 0.4 2011-05-15:
18 | ---
19 |
20 | * added support for the new .lua forms like the WLAN guest access settings
21 |
22 |
23 | 0.3 2010-05-19:
24 | ---
25 |
26 | * added a doGetRequest method in the API
27 | * some minor changes
28 | * a new module for downloading the foncalls list
29 |
30 |
31 | 0.2 2010-04-07:
32 | ---
33 |
34 | * added a capability to use the Fritz!Box remote admin mode
35 | Important limitation: does not check the certificate, so the password is sent to any computer responding at the configured address.
36 | Feel free to hack the cURL calls to accept only a given certrificate
37 |
38 |
39 | 0.1:
40 | ---
41 |
42 | * First release
43 |
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FritzBox! PHP API
2 |
3 | Provides an interface to your FritzBox! using the webinterface. Thus, no modification the to firmware (aka FritzOS) is required!
4 |
5 | ### Requirements
6 | * PHP 5 (tested with 5.3)
7 | * PHP-curl
8 |
9 | Install on Debian/Ubuntu: sudo apt-get install php5-cli php5-curl
10 |
11 | ###Sample Scripts
12 |
13 | * Enable/Disable TAM
14 | * Download Phone call list
15 | * Enable/Disable Guest (W)LAN
16 | * Ring a Phone
17 | * Reboot
18 | * Export the Phonebook
19 | * **Import the Phonebook (only tested with FB 71xx) [not available in the original version]**
20 |
21 | **Newer Version available at**: [IPF discussion thread](http://www.ip-phone-forum.de/showthread.php?t=196309)
22 |
23 | AUTHORS: [Gregor Nathanael Meyer](http://spackmat.de/spackblog), Karl Glatz, (maybe others)
24 |
25 | ----------
26 |
27 | ### Important! ###
28 | Do not use Windows Notepad as it will break the files due to their UTF-8 coding and UNIX linebreaks. Download a serious editor like Notepad++ instead.
29 | Also do not use or modify this scripts, if you do not know, what you do. This script is itended for advanced users
30 |
31 |
32 |
33 | ### Basic usage advisory ####
34 |
35 | The scripts are well documented, please take a look to understand them.
36 | This is also the right moment to check the config file "fritzbox.conf.php"!
37 |
38 | All files must be in the same directory. If this condition is fulfilled, you don't need to pay any more attention to "fritzbox_api.class.php".
39 |
40 | To use "fritzbox_tam_on_off.php", you have to call it in a terminal, it will then explain its usage. This script is a reference implementation of the PHP Fritz!Box API, use it as a base for your own implementations
41 |
42 |
43 |
44 | ### Usage on a Windows system ###
45 |
46 | The script works fine on my Windows Vista machine and a simply extraced PHP 5.3.0 distribution (get it at http://windows.php.net/download/, PHP 5.4.0 works as well). The cURL extension and the mbstring extenstion must be enabled in the php.ini and the correct timezone must be set. To do this, copy the php.ini-production to php.ini and uncomment/change the following directives:
47 |
48 | extension_dir = "ext"
49 | extension=php_curl.dll
50 | extension=php_mbstring.dll
51 | date.timezone = Europe/Berlin
52 |
53 | After you have done that, you can call the script in a terminal:
54 |
55 | C:\>path\to\php.exe path\to\fritzbox_tam_on_off.php
56 |
57 | i.e. if you extracted PHP to c:\php and the Fritz!Box PHP API to a subfolder named fritz_api, you call it this way:
58 | C:\>cd php
59 | C:\php>php fritz_api\fritzbox_tam_on_off.php
60 |
61 | If you use the Windows taskplanner, configure the logger to a logfile or to silent mode and call via php-win.exe instead of php.exe. This will prevent the terminal from being opened.
62 |
63 |
64 |
65 | ### Usage on a UNIX system ###
66 |
67 | If you use UNIX, you should be familiar with calling a PHP script via the PHP-CLI. If you don't have the PHP-CLI installed, you can edit the $argv part in "fritz_tam_on_off.php" to work with PHP-CGI and $_GET or you hardcode the necessary arguments.
68 |
69 | Ensure that the cURL and the mbstring extensions are available and a valid timezone is set. The script was tested on a Ubuntu Server machine with PHP 5.2.
70 |
71 |
72 |
73 | ### Feedback, license, support ###
74 | You are welcome to send me feedback via email (Gregor [at] der-meyer.de) or visit my personal blog at http://spackmat.de/spackblog (in German)
75 |
76 | The whole work is licensed under a Creative Commons cc-by-sa license (http://creativecommons.org/licenses/by-sa/3.0/de/). You are free to use and modify it, even for commercial use. If you redistribute it, you have to ensure my name is kept in the code and you use the same conditions.
77 |
78 | Feel free to add (and contribute) other nice scripts. The API class should work with any config item, which is available in the Fritz!Box Web UI. Use Firebug or LiveHeaders to figure out the name of the proper POST-Field.
79 |
80 | I won't give any personal support for this script, unless you pay for it. :) I'm a freelance IT-consultant and webdeveloper, loocated in Düsseldorf, Germany.
81 |
--------------------------------------------------------------------------------
/bin/example_pb.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/carlos22/fritzbox_api_php/dfae25b28830cb797f42dbb8af80d6f356a1d15a/bin/example_pb.xml
--------------------------------------------------------------------------------
/bin/fritzbox.conf.php:
--------------------------------------------------------------------------------
1 | '../html/de/menus/menu2.html',
19 | 'telcfg:settings/Diversity' . $diversity . '/Active' => $mode,
20 | );
21 | $fritz->doPostForm($formfields);
22 | $fritz = null; // destroy the object to log out
23 | }
24 | catch (Exception $e)
25 | {
26 | echo $e->getMessage();
27 | }
28 | ?>
29 |
--------------------------------------------------------------------------------
/bin/fritzbox_get_foncallslist.php:
--------------------------------------------------------------------------------
1 |
11 | * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
12 | * @version 0.1
13 | * @package Fritz!Box PHP tools
14 | */
15 |
16 | // load the config and the API class
17 | require_once(dirname(__FILE__) . '/fritzbox.conf.php');
18 | require_once(dirname(__FILE__) . '../lib/fritzbox_api.class.php');
19 |
20 | function log_message($message)
21 | {
22 | global $logging;
23 | global $newline;
24 |
25 | if (!isset($logging) || (isset($logging) && $logging == 'console'))
26 | {
27 | echo $message;
28 | }
29 | else if (isset($logging) && $logging == 'silent')
30 | {
31 | // do nothing
32 | }
33 | else
34 | {
35 | file_put_contents($logging, $message . $newline, FILE_APPEND);
36 | }
37 | }
38 |
39 | // init the output message
40 | $message = date('Y-m-d H:i') . ' ';
41 |
42 |
43 | // handle the fritzbox_api class and do the job
44 | try
45 | {
46 | if ( isset($enable_remote_config) && isset($remote_config_user) && isset($remote_config_password) )
47 | {
48 | $fritz = new fritzbox_api($password, $fritzbox_ip, true, $remote_config_user, $remote_config_password);
49 | }
50 | else
51 | {
52 | $fritz = new fritzbox_api($password, $fritzbox_ip);
53 | }
54 |
55 | // get the frontend-page to refresh the list
56 | $params = array(
57 | 'getpage' => '../html/de/menus/menu2.html',
58 | 'var:menu' => 'fon',
59 | 'var:pagename' => 'foncalls',
60 | 'var:errorpagename' => 'foncalls',
61 | 'var:type' => '0',
62 | //'telcfg:settings/UseJournal' => '1',
63 | );
64 | $fritz->doPostForm($params);
65 |
66 | // get the phone calls list
67 | $params = array(
68 | 'getpage' => '../html/de/home/foncallsdaten.xml',
69 | //'getpage' => '../html/de/FRITZ!Box_Anrufliste.csv',
70 | );
71 | $output = $fritz->doGetRequest($params);
72 |
73 | // write out the call list to the desired path
74 | file_put_contents($foncallslist_path, $output);
75 |
76 | // set a log message
77 | $message .= 'Call list sucessfully downloaded';
78 |
79 | // destroy the object to log out
80 | $fritz = null;
81 | }
82 | catch (Exception $e)
83 | {
84 | $message .= $e->getMessage();
85 | }
86 |
87 | // log the result
88 | log_message($message);
89 | ?>
90 |
--------------------------------------------------------------------------------
/bin/fritzbox_guestlan_on_off.php:
--------------------------------------------------------------------------------
1 |
11 | * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
12 | * @version 0.1 2012-03-14
13 | * @package Fritz!Box PHP tools
14 | */
15 |
16 | // load the config
17 | require_once('fritzbox.conf.php');
18 |
19 | function log_message($message)
20 | {
21 | global $logging;
22 | global $newline;
23 |
24 | if (!isset($logging) || (isset($logging) && $logging == 'console'))
25 | {
26 | echo $message;
27 | }
28 | else if (isset($logging) && $logging == 'silent')
29 | {
30 | // do nothing
31 | }
32 | else
33 | {
34 | file_put_contents($logging, $message . $newline, FILE_APPEND);
35 | }
36 | }
37 |
38 | // init the output message
39 | $message = date('Y-m-d H:i') . ' ';
40 |
41 | // handle the CLI arguments or give a help message
42 | if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) )
43 | {
44 | $mode = (bool)$argv[1];
45 | }
46 | else
47 | {
48 | if (!isset($logging) || (isset($logging) && $logging == 'console'))
49 | {
50 | echo '
51 | Enables or disables the LAN4 guest access of a Fritz!Box
52 |
53 | Usage on UNIX systems:
54 | /path/to/php ' . $argv[0] . ' {0|1}
55 |
56 | Usage on Windows systems:
57 | "c:\path\to\php.exe" ' . $argv[0] . ' {0|1}
58 |
59 | 0 disables the guest access
60 | 1 enables the guest access
61 | ';
62 | }
63 | else if (isset($logging) && $logging == 'silent')
64 | {
65 | // do nothing
66 | }
67 | else
68 | {
69 | log_message($message . 'ERROR: Script was called without or with an invalid argument');
70 | }
71 | exit;
72 | }
73 |
74 |
75 | // handle the fritzbox_api class and do the job
76 | require_once('../lib/fritzbox_api.class.php');
77 | try
78 | {
79 | if ( isset($enable_remote_config) && isset($remote_config_user) && isset($remote_config_password) )
80 | {
81 | $fritz = new fritzbox_api($password, $fritzbox_ip, true, $remote_config_user, $remote_config_password);
82 | }
83 | else
84 | {
85 | $fritz = new fritzbox_api($password, $fritzbox_ip);
86 | }
87 |
88 | // read the current settings
89 | $formfields = array(
90 | 'getpage' => '/net/network_settings.lua',
91 | );
92 | $output = $fritz->doGetRequest($formfields);
93 |
94 |
95 | // read time_server_activ setting
96 | preg_match('@name="time_server_activ"[^>]+(checked)[^>]*@', $output, $matches);
97 | if ( isset($matches[1]) )
98 | {
99 | $formfields['time_server_activ'] = 'on';
100 | }
101 | // read time_server setting
102 | preg_match('@name="time_server"[^>]+value="([^"]*)"[^>]*@', $output, $matches);
103 | $formfields['time_server'] = isset($matches[1]) ? $matches[1] : '0.europe.pool.ntp.org';
104 | // read other_prefix_allowed setting
105 | preg_match('@name="other_prefix_allowed"[^>]+(checked)[^>]*@', $output, $matches);
106 | if ( isset($matches[1]) )
107 | {
108 | $formfields['other_prefix_allowed'] = 'on';
109 | }
110 | // read dnsv6_server_activ setting
111 | preg_match('@name="dnsv6_server_activ"[^>]+(checked)[^>]*@', $output, $matches);
112 | if ( isset($matches[1]) )
113 | {
114 | $formfields['dnsv6_server_activ'] = 'on';
115 | }
116 |
117 | // set new given setting
118 | if ( $mode == true )
119 | {
120 | $formfields['guest_enabled'] = 'on';
121 | }
122 |
123 | // do the update
124 | $formfields['btnSave'] = '';
125 | $output = $fritz->doPostForm($formfields);
126 |
127 | preg_match('@name="guest_enabled"[^>]+(checked)[^>]*@', $output, $matches);
128 | if ( isset($matches[1]) && $mode == true )
129 | {
130 | $message .= 'LAN4 guest access is now active.';
131 | }
132 | else if ( !isset($matches[1]) && $mode == false )
133 | {
134 | $message .= 'LAN4 guest access is now inactive.';
135 | }
136 | else if ( isset($matches[1]) && $mode == false )
137 | {
138 | $message .= 'ERROR: LAN4 guest access status change failed, should be inactive, but is still active.';
139 | }
140 | else if ( !isset($matches[1]) && $mode == true )
141 | {
142 | $message .= 'ERROR: LAN4 guest access status change failed, should be active, but is still inactive.';
143 | }
144 | $fritz = null; // destroy the object to log out
145 | }
146 | catch (Exception $e)
147 | {
148 | $message .= $e->getMessage();
149 | }
150 |
151 | // log the result
152 | log_message($message);
153 | ?>
154 |
--------------------------------------------------------------------------------
/bin/fritzbox_guestwlan_on_off.php:
--------------------------------------------------------------------------------
1 |
11 | * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons cc-by-sa
12 | * @version 0.1 2011-06-15
13 | * @package Fritz!Box PHP tools
14 | */
15 |
16 | // load the config
17 | require_once('fritzbox.conf.php');
18 |
19 | function log_message($message)
20 | {
21 | global $logging;
22 | global $newline;
23 |
24 | if (!isset($logging) || (isset($logging) && $logging == 'console'))
25 | {
26 | echo $message;
27 | }
28 | else if (isset($logging) && $logging == 'silent')
29 | {
30 | // do nothing
31 | }
32 | else
33 | {
34 | file_put_contents($logging, $message . $newline, FILE_APPEND);
35 | }
36 | }
37 |
38 | // init the output message
39 | $message = date('Y-m-d H:i') . ' ';
40 |
41 | // handle the CLI arguments or give a help message
42 | if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) )
43 | {
44 | $mode = (bool)$argv[1];
45 | }
46 | else
47 | {
48 | if (!isset($logging) || (isset($logging) && $logging == 'console'))
49 | {
50 | echo '
51 | Enables or disables the WLAN guest access of a Fritz!Box
52 |
53 | Usage on UNIX systems:
54 | /path/to/php ' . $argv[0] . ' {0|1} [optional: PASSWORD]
55 |
56 | Usage on Windows systems:
57 | c:\path\to\php.exe ' . $argv[0] . ' {0|1} [optional: PASSWORD]
58 |
59 | 0 disables the guest access
60 | 1 enables the guest access
61 |
62 | The optional argument PASSWORD sets a new guest access password (min 8 chars)
63 | Defaults to false, so the current password is kept.
64 | ';
65 | }
66 | else if (isset($logging) && $logging == 'silent')
67 | {
68 | // do nothing
69 | }
70 | else
71 | {
72 | log_message($message . 'ERROR: Script was called without or with an invalid argument');
73 | }
74 | exit;
75 | }
76 | $wpa_key = (isset($argv[2]) && strlen($argv[2]) >= 8 && strlen($argv[2]) <= 63) ? $argv[2] : false;
77 |
78 |
79 | // handle the fritzbox_api class and do the job
80 | require_once('../lib/fritzbox_api.class.php');
81 | try
82 | {
83 | if ( isset($enable_remote_config) && isset($remote_config_user) && isset($remote_config_password) )
84 | {
85 | $fritz = new fritzbox_api($password, $fritzbox_ip, true, $remote_config_user, $remote_config_password);
86 | }
87 | else
88 | {
89 | $fritz = new fritzbox_api($password, $fritzbox_ip);
90 | }
91 |
92 | // read the current settings
93 | $formfields = array(
94 | 'getpage' => '/wlan/guest_access.lua',
95 | );
96 | $output = $fritz->doGetRequest($formfields);
97 |
98 | // read down_time_activ setting
99 | preg_match('@name="down_time_activ"[^>]+(checked)[^>]*@', $output, $matches);
100 | if ( isset($matches[1]) )
101 | {
102 | $formfields['down_time_activ'] = 'on';
103 | }
104 | // read down_time_value setting
105 | preg_match('@name="down_time_value".*?