/*
    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');
    $output = $fritz->doGetRequest($params);
    // write out the call list to the desired path
    $getNetworkdevices = $output;
    $getNetworkdevices = explode("MQUERIES", $getNetworkdevices);
    $getNetworkdevices = explode("CONFIG", $getNetworkdevices[1]);
    $luadata = 'MQUERIES' . $getNetworkdevices[0];
    $fritzBoxList = makePhpArray($luadata);
    foreach ($fritzBoxList['landevice:settings/landevice/list(name,ip,mac,UID,dhcp,wlan,ethernet,active,static_dhcp,manu_name,wakeup,deleteable,source,online,speed,wlan_UIDs,auto_wakeup,guest,url,wlan_station_type,vendorname,parentname,parentuid,ethernet_port,wlan_show_in_monitor,plc,ipv6_ifid)'] as $networkDevice) {
        echo $networkDevice['name'] . ' (' . $networkDevice['mac'] . ') ' . $networkDevice['active'] . '<br />';
        $networkDevices[] = $networkDevice;
    }
} catch (Exception $e) {
    $message .= $e->getMessage();
}
// log the result
if (isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api') {
        }
    }
    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])) {
        $formfields['disconnect_guest_access'] = 'on';
    }
    // read guest_ssid setting
    preg_match('@name="guest_ssid"[^>]+value="([^"]*)"[^>]*@', $output, $matches);