// read wpa_key setting
 preg_match('@name="wpa_key"[^>]+value="([^"]*)"[^>]*@', $output, $matches);
 $formfields['wpa_key'] = isset($matches[1]) ? $matches[1] : 'defaultwpakey';
 // read wpa_modus setting
 preg_match('@name="wpa_modus".*?<option value="(\\d+)"[^>]+?selected.*?</select>@s', $output, $matches);
 $formfields['wpa_modus'] = isset($matches[1]) ? $matches[1] : 'x';
 // set new given setting
 if ($mode == true) {
     $formfields['activate_guest_access'] = 'on';
     if ($wpa_key !== false) {
         $formfields['wpa_key'] = $wpa_key;
     }
 }
 // do the update
 $formfields['btnSave'] = '';
 $output = $fritz->doPostForm($formfields);
 preg_match('@name="activate_guest_access"[^>]+(checked)[^>]*@', $output, $matches);
 if (isset($matches[1]) && $mode == true) {
     preg_match('@name="wpa_key"[^>]+value="([^"]*)"[^>]*@', $output, $matches);
     if (isset($matches[1])) {
         $message .= 'WLAN guest access is now active. WPA-Key is "' . $matches[1] . '"';
     }
 } else {
     if (!isset($matches[1]) && $mode == false) {
         $message .= 'WLAN guest access is now inactive.';
     } else {
         if (isset($matches[1]) && $mode == false) {
             $message .= 'ERROR: WLAN guest access status change failed, should be inactive, but is still active.';
         } else {
             if (!isset($matches[1]) && $mode == true) {
                 $message .= 'ERROR: WLAN guest access status change failed, should be active, but is still inactive.';
<?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();
}
        } 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();
}
// log the result
log_message($message);