<?php

$dial = '**610';
// set to the number to dial
// init the output message
$message = date('Y-m-d H:i') . ' ';
try {
    // load the fritzbox_api class
    require_once __DIR__ . '/fritzbox_api.class.php';
    $fritz = new fritzbox_api();
    // update the setting
    $formfields = array('telcfg:command/Dial' => $dial);
    $fritz->doPostForm($formfields);
    $message .= 'Phone ' . $dial . ' ringed.';
} 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
<?php

// load the config
require_once 'fritzbox.conf.php';
// load the fritzbox_api class
require_once '../lib/fritzbox_api.class.php';
$dial = '**610';
// set to the number to dial
// do the job
try {
    $fritz = new fritzbox_api($password, $fritzbox_ip);
    // update the setting
    $formfields = array('getpage' => '../html/de/menus/menu2.html', 'telcfg:command/Dial' => $dial);
    $fritz->doPostForm($formfields);
    $fritz = null;
    // destroy the object to log out
} catch (Exception $e) {
    echo $e->getMessage();
}
Example #3
0
 public function upload_to_fb()
 {
     // if the user wants to save the xml to a separate file, we do so now
     if (array_key_exists('output_file', $this->config)) {
         $output = fopen($this->config['output_file'], 'w');
         if ($output) {
             fwrite($output, $this->fbxml);
             fclose($output);
         }
         return 0;
     }
     // now we upload the photo jpgs first being stored in the
     // temp directory.
     // perform an ftps-connection to copy over the photos to a specified directory
     $ftp_server = $this->config['fritzbox_ip_ftp'];
     $conn_id = ftp_ssl_connect($ftp_server);
     ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 60);
     $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
     ftp_pasv($conn_id, true);
     // create remote photo path on FRITZ!Box if it doesn't exist
     $remote_path = $this->config['usb_disk'] . "/FRITZ/fonpix";
     if (ftp_nlist($conn_id, $remote_path) == false) {
         ftp_mkdir($conn_id, $remote_path);
     }
     // now iterate through all jpg files in tempdir and upload them
     $dir = new DirectoryIterator($this->tmpdir);
     foreach ($dir as $fileinfo) {
         if (!$fileinfo->isDot()) {
             if ($fileinfo->getExtension() == "jpg") {
                 $file = $fileinfo->getFilename();
                 print " FTP-Upload: " . $file . PHP_EOL;
                 if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) {
                     // retry when a fault occurs.
                     print "  WARNING: an error occurred while uploading file " . $fileinfo->getFilename() . " - retrying" . PHP_EOL;
                     $conn_id = ftp_ssl_connect($ftp_server);
                     $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
                     ftp_pasv($conn_id, true);
                     if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) {
                         print "  ERROR: an error occurred while uploading file " . $fileinfo->getFilename() . " - giving up" . PHP_EOL;
                     }
                 }
             }
         }
     }
     // close ftp connection
     ftp_close($conn_id);
     // lets post the phonebook xml to the FRITZ!Box
     print " Uploading Phonebook XML" . PHP_EOL;
     try {
         $fritz = new fritzbox_api($this->config['fritzbox_pw'], $this->config['fritzbox_user'], $this->config['fritzbox_ip'], $this->config['fritzbox_force_local_login']);
         $formfields = array('PhonebookId' => $this->config['phonebook_number']);
         $filefileds = array('PhonebookImportFile' => array('type' => 'text/xml', 'filename' => 'updatepb.xml', 'content' => $this->fbxml));
         $raw_result = $fritz->doPostFile($formfields, $filefileds);
         // send the command
         $msg = $this->_parse_fb_result($raw_result);
         $fritz = null;
         // destroy the object to log out
         print "  FRITZ!Box returned message: '" . $msg . "'" . PHP_EOL;
     } catch (Exception $e) {
         print "  ERROR: " . $e->getMessage() . PHP_EOL;
         // show the error message in anything failed
     }
 }
{
    $start = 0;
    if (is_array($input)) {
        return luaparser($input, $start);
    } elseif (is_string($input)) {
        if (@is_file($input)) {
            return luaparser(file($input), $start);
        } else {
            return luaparser(explode("\n", $input), $start);
        }
    }
}
try {
    // load the fritzbox_api class
    require_once 'fritzbox_api.class.php';
    $fritz = new fritzbox_api();
    /*
    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 phone calls list
    $params = array('getpage' => '/net/network_user_devices.lua');
    //$fritz->doGetRequest($params);
    // get the phone calls list
    $params = array('getpage' => '/net/network_user_devices.lua', 'csv' => '1');
<?php

// load the config
require_once 'fritzbox.conf.php';
// load the fritzbox_api class
require_once '../lib/fritzbox_api.class.php';
if (count($argv) < 2 || $argv[1] != "--overwrite") {
    print "CAUTION: This will delete all current entries in your fritzbox phonebook";
    print $newline . "call with " . $argv[0] . " --overwrite" . $newline;
    die;
}
// do the job
try {
    $fritz = new fritzbox_api($password, $fritzbox_ip);
    $formfields = array('PhonebookId' => '0', 'PhonebookImportFile' => '@' . $fonbook_import_path . ';type=text/xml');
    $output = $fritz->doPostFile($formfields);
    print "Phonebook imported from " . $fonbook_import_path . $newline;
    $fritz = null;
    // destroy the object to log out
} catch (Exception $e) {
    echo $e->getMessage();
}
        if (isset($logging) && $logging == 'silent') {
            // do nothing
        } else {
            log_message($message . 'ERROR: Script was called without or with an invalid argument');
        }
    }
    exit;
}
$wpa_key = isset($argv[2]) && strlen($argv[2]) >= 8 && strlen($argv[2]) <= 63 ? $argv[2] : false;
// handle the fritzbox_api class and do the job
require_once '../lib/fritzbox_api.class.php';
try {
    if (isset($enable_remote_config) && isset($remote_config_user) && isset($remote_config_password)) {
        $fritz = new fritzbox_api($password, $fritzbox_ip, true, $remote_config_user, $remote_config_password);
    } else {
        $fritz = new fritzbox_api($password, $fritzbox_ip);
    }
    // read the current settings
    $formfields = array('getpage' => '/wlan/guest_access.lua');
    $output = $fritz->doGetRequest($formfields);
    // read down_time_activ setting
    preg_match('@name="down_time_activ"[^>]+(checked)[^>]*@', $output, $matches);
    if (isset($matches[1])) {
        $formfields['down_time_activ'] = 'on';
    }
    // read down_time_value setting
    preg_match('@name="down_time_value".*?<option value="(\\d+)"[^>]+?selected.*?</select>@s', $output, $matches);
    $formfields['down_time_value'] = isset($matches[1]) ? $matches[1] : '15';
    // read disconnect_guest_access setting
    preg_match('@name="disconnect_guest_access"[^>]+(checked)[^>]*@', $output, $matches);
    if (isset($matches[1])) {
Example #7
0
#!/usr/bin/php
<?php 
// Configure me hard!
// Please configure Fritz!Box Login Data in /lib/fritzbox_user.conf.php
$tmpFile = "/tmp/fritzdocsis.db.";
$tmpFileMaxAge = "60";
// NO NEED TO EDIT BELOW HERE!
require_once __DIR__ . "/lib/fritzbox_api.class.php";
require_once __DIR__ . "/lib/lua_parser.class.php";
require_once __DIR__ . "/lib/sbLib.php";
// Check if we have to do a new DOCSIS query
if (!file_exists($tmpFile . "downstream") || filemtime($tmpFile . "downstream") < time() - $tmpFileMaxAge) {
    // Get us a new fritzbox handler
    $fritz = new fritzbox_api();
    /*
    // Refresh the Page
    $params = array(
       'getpage'             => '../html/de/menus/menu2.html',
       'var:menu'                => 'internet',
       'var:pagename'        => 'docsis',
       'var:errorpagename'   => 'docsis',
       'var:type'            => '0',
    );
    $fritz->doPostForm($params);
    */
    // Get the "Kabel Informationen" details page
    $params = array('getpage' => '/internet/docsis_info.lua');
    $output = $fritz->doGetRequest($params);
    // Disconnect from the Webinterface
    $fritz = null;
    $dat = formatLua($output);
/**
 * Fritz!Box PHP tools CLI script to enable or disable the WLAN guest access
 *
 * Must be called via a command line, shows a help message if called without any or an invalid argument
 *
 * 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') . ' ';
    // handle the CLI arguments or give a help message
    if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1)) {
        $mode = (bool) $argv[1];
    } else {
        if ($fritz->config->getItem('logging') == 'console') {
            echo '
  Enables or disables the WLAN guest access of a Fritz!Box
  
  Usage on UNIX systems:
    /path/to/php ' . $argv[0] . ' {0|1} [optional: PASSWORD]
  
  Usage on Windows systems:
    c:\\path\\to\\php.exe ' . $argv[0] . ' {0|1} [optional: PASSWORD]
Example #9
0
 public function upload_to_fb()
 {
     // if the user wants to save the xml to a separate file, we do so now
     if (array_key_exists('output_file', $this->config)) {
         // build md5 hash of previous stored xml without <mod_time> Elements
         $oldphonebhash = md5(preg_replace("/<mod_time>(\\d{10})/", "", file_get_contents($this->config['output_file'], 'r'), -1, $debugoldtsreplace));
         $output = fopen($this->config['output_file'], 'w');
         if ($output) {
             fwrite($output, $this->fbxml);
             fclose($output);
             print " Saved to file " . $this->config['output_file'] . PHP_EOL;
         }
         if (array_key_exists('output_and_upload', $this->config) and $this->config['output_and_upload']) {
             $newphonebhash = md5(preg_replace("/<mod_time>(\\d{10})/", "", file_get_contents($this->config['output_file'], 'r'), -1, $debugnewtsreplace));
             print " INFO: Compare old and new phonebook file versions." . PHP_EOL . " INFO: old version: " . $oldphonebhash . PHP_EOL . " INFO: new version: " . $newphonebhash . PHP_EOL;
             if ($oldphonebhash === $newphonebhash) {
                 print " INFO: Same versions ==> No changes in phonebook or images" . PHP_EOL . " EXIT: No need to upload phonebook to the FRITZ!Box." . PHP_EOL;
                 return 0;
             } else {
                 print " INFO: Different versions ==> Changes in phonebook." . PHP_EOL . " INFO: Changes dedected! Continue with upload." . PHP_EOL;
             }
         } else {
             return 0;
         }
     }
     // now we upload the photo jpgs first being stored in the
     // temp directory.
     // perform an ftps-connection to copy over the photos to a specified directory
     $ftp_server = $this->config['fritzbox_ip_ftp'];
     $conn_id = ftp_ssl_connect($ftp_server);
     if ($conn_id == false) {
         print " WARNING: Secure connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL;
         $conn_id = ftp_connect($ftp_server);
     }
     if ($conn_id != false) {
         ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 60);
         $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
         if ($login_result === true) {
             ftp_pasv($conn_id, true);
             // create remote photo path on FRITZ!Box if it doesn't exist
             $remote_path = $this->config['usb_disk'] . "/FRITZ/fonpix";
             $all_existing_files = ftp_nlist($conn_id, $remote_path);
             if ($all_existing_files == false) {
                 ftp_mkdir($conn_id, $remote_path);
                 $all_existing_files = array();
             }
             // now iterate through all jpg files in tempdir and upload them if necessary
             $dir = new DirectoryIterator($this->tmpdir);
             foreach ($dir as $fileinfo) {
                 if (!$fileinfo->isDot()) {
                     if ($fileinfo->getExtension() == "jpg") {
                         $file = $fileinfo->getFilename();
                         print " FTP-Upload '" . $file . "'...";
                         if (!in_array($remote_path . "/" . $file, $all_existing_files)) {
                             if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) {
                                 // retry when a fault occurs.
                                 print " retrying... ";
                                 $conn_id = ftp_ssl_connect($ftp_server);
                                 if ($conn_id == false) {
                                     print " WARNING: Secure re-connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL;
                                     $conn_id = ftp_connect($ftp_server);
                                 }
                                 if ($conn_id == false) {
                                     print " ERROR: couldn't re-connect to FTP server '" . $ftp_server . "', abortіng." . PHP_EOL;
                                     break;
                                 }
                                 $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
                                 if ($login_result === false) {
                                     print " ERROR: couldn't re-login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL;
                                     break;
                                 }
                                 ftp_pasv($conn_id, true);
                                 if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) {
                                     print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL;
                                 } else {
                                     print " ok." . PHP_EOL;
                                 }
                             } else {
                                 print " ok." . PHP_EOL;
                             }
                             // cleanup old files
                             foreach ($all_existing_files as $existing_file) {
                                 if (strpos($existing_file, $remote_path . "/" . substr($file, 0, -10)) !== false) {
                                     print " FTP-Delete: " . $existing_file . PHP_EOL;
                                     ftp_delete($conn_id, $remote_path . "/" . basename($existing_file));
                                 }
                             }
                         } else {
                             print " already exists." . PHP_EOL;
                         }
                     }
                 }
             }
         } else {
             print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL;
         }
         // close ftp connection
         ftp_close($conn_id);
     } else {
         print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL;
     }
     // in case numeric IP is given, try to resolve to hostname. Otherwise Fritzbox may decline login, because it is determine to be (prohibited) remote access
     $hostname = $this->config['fritzbox_ip'];
     if (filter_var($hostname, FILTER_VALIDATE_IP)) {
         $hostname = gethostbyaddr($hostname);
         if ($hostname == $this->config['fritzbox_ip']) {
             print " WARNING: Unable to get hostname for IP address (" . $this->config['fritzbox_ip'] . ") <" . $hostname . "<" . PHP_EOL;
         } else {
             print " INFO: Given IP address (" . $this->config['fritzbox_ip'] . ") has hostname " . $hostname . "." . PHP_EOL;
             $this->config['fritzbox_ip'] = $hostname;
         }
     }
     // lets post the phonebook xml to the FRITZ!Box
     print " Uploading Phonebook XML to " . $this->config['fritzbox_ip'] . PHP_EOL;
     try {
         $fritz = new fritzbox_api($this->config['fritzbox_pw'], $this->config['fritzbox_user'], $this->config['fritzbox_ip'], $this->config['fritzbox_force_local_login']);
         $formfields = array('PhonebookId' => $this->config['phonebook_number']);
         $filefileds = array('PhonebookImportFile' => array('type' => 'text/xml', 'filename' => 'updatepb.xml', 'content' => $this->fbxml));
         $raw_result = $fritz->doPostFile($formfields, $filefileds);
         // send the command
         $msg = $this->_parse_fb_result($raw_result);
         unset($fritz);
         // destroy the object to log out
         print "  FRITZ!Box returned message: '" . $msg . "'" . PHP_EOL;
     } catch (Exception $e) {
         print "  ERROR: " . $e->getMessage() . PHP_EOL;
         // show the error message in anything failed
     }
 }
        if (isset($logging) && $logging == 'silent') {
            // do nothing
        } else {
            log_message($message . 'ERROR: Script was called without or with an invalid argument');
        }
    }
    exit;
}
$tam = isset($argv[2]) && $argv[2] >= 0 && $argv[2] <= 9 ? (int) $argv[2] : 0;
// handle the fritzbox_api class and do the job
require_once '../lib/fritzbox_api.class.php';
try {
    if (isset($enable_remote_config) && isset($remote_config_user) && isset($remote_config_password)) {
        $fritz = new fritzbox_api($password, $fritzbox_ip, true, $remote_config_user, $remote_config_password);
    } else {
        $fritz = new fritzbox_api($password, $fritzbox_ip);
    }
    // update the setting
    $formfields = array('getpage' => '../html/de/menus/menu2.html', 'tam:settings/TAM' . $tam . '/Active' => $mode);
    $fritz->doPostForm($formfields);
    // check if the update succeded
    $formfields = array('getpage' => '../html/de/menus/menu2.html', 'var:menu' => 'home', 'var:pagemaster' => 'fondevices', 'var:pagename' => 'fondevices');
    $output = $fritz->doPostForm($formfields);
    preg_match('@name="tam:settings/TAM' . $tam . '/Active" value="([10])"@i', $output, $matches);
    if (isset($matches[1]) && $matches[1] == $mode) {
        $message .= $mode == 1 ? 'TAM' . $tam . ' enabled' : 'TAM' . $tam . ' disabled';
    } else {
        if (isset($matches[1])) {
            $message .= 'ERROR: TAM' . $tam . ' status change failed, should be ' . $mode . ', but is ' . $matches[1];
        } else {
            $message .= 'NOTICE: TAM' . $tam . ' status change could have failed, should be ' . $mode . ' now, but I don\'t now if it actually is. Check your check section in the script.';
    } else {
        if (isset($logging) && $logging == 'silent') {
            // do nothing
        } else {
            file_put_contents($logging, $message . $newline, FILE_APPEND);
        }
    }
}
// init the output message
$message = date('Y-m-d H:i') . ' ';
// handle the fritzbox_api class and do the job
try {
    if (isset($enable_remote_config) && isset($remote_config_user) && isset($remote_config_password)) {
        $fritz = new fritzbox_api($password, $fritzbox_ip, true, $remote_config_user, $remote_config_password);
    } else {
        $fritz = new fritzbox_api($password, $fritzbox_ip);
    }
    // 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($foncallslist_path, $output);
    // set a log message
    $message .= 'Call list sucessfully downloaded';
    // destroy the object to log out
    $fritz = null;
} catch (Exception $e) {
    $message .= $e->getMessage();