Example #1
0
function test_writeConfigFile()
{
    appendTestMessage(NEW_LINE_LOG . " >> Tests writing of config file..." . NEW_LINE_LOG);
    appendTestMessage("No config: User = admin, key = timezone_offset_minutes");
    $ret = getConfiguration(ADMIN_NAME, CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if (isNullOrEmptyString($ret)) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("No config: User = cUser, key = timezone_offset_minutes");
    $ret = getConfiguration('cUser', CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if (isNullOrEmptyString($ret)) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Delete missing config file: User = cUser");
    $ret = resetConfig('cUser');
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Delete missing config file: User = admin");
    $ret = resetConfig(ADMIN_NAME);
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Set config: User = admin, , key = timezone_offset_minutes (set server)");
    $ret = setConfiguration(ADMIN_NAME, CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, '10');
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = admin, key = timezone_offset_minutes");
    $ret = getConfiguration(ADMIN_NAME, CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if ($ret == '10') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = cUser, key = timezone_offset_minutes");
    $ret = getConfiguration('cUser', CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, false);
    if ($ret == '') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = cUser, key = timezone_offset_minutes");
    $ret = getConfiguration('cUser', CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if ($ret == '10') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Set config: User = dUser, key = track_expiration_days (set user and server)");
    $ret = setConfiguration('dUser', CONFIG_KEY_TRACK_EXPIRATION_DAYS, 'aa');
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = admin, key = timezone_offset_minutes");
    $ret = getConfiguration(ADMIN_NAME, CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if ($ret == '10') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = admin, key = track_expiration_days");
    $ret = getConfiguration(ADMIN_NAME, CONFIG_KEY_TRACK_EXPIRATION_DAYS, true);
    if ($ret == 'aa') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = dUser, key = timezone_offset_minutes");
    $ret = getConfiguration('dUser', CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if ($ret == '10') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = dUser, key = track_expiration_days");
    $ret = getConfiguration('dUser', CONFIG_KEY_TRACK_EXPIRATION_DAYS, true);
    if ($ret == 'aa') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Set config: User = admin, , key = track_expiration_days (set server only)");
    $ret = setConfiguration(ADMIN_NAME, CONFIG_KEY_TRACK_EXPIRATION_DAYS, '15');
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Set config: User = dUser, , key = track_expiration_days (set user only)");
    $ret = setConfiguration('dUser', CONFIG_KEY_TRACK_EXPIRATION_DAYS, 'dd');
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = admin, key = timezone_offset_minutes");
    $ret = getConfiguration(ADMIN_NAME, CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if ($ret == '10') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = admin, key = track_expiration_days");
    $ret = getConfiguration(ADMIN_NAME, CONFIG_KEY_TRACK_EXPIRATION_DAYS, true);
    if ($ret == '15') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = dUser, key = timezone_offset_minutes");
    $ret = getConfiguration('dUser', CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if ($ret == '10') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = dUser, key = track_expiration_days");
    $ret = getConfiguration('dUser', CONFIG_KEY_TRACK_EXPIRATION_DAYS, true);
    if ($ret == 'dd') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Set config en bloc: User = dUser, track_expiration_days=0, timezone_offset_minutes=-60");
    $param = CONFIG_KEY_TRACK_EXPIRATION_DAYS . '=0' . PHP_EOL . CONFIG_KEY_TIMEZONE_OFFSET_MINUTES . '=-60';
    $ret = setConfigurationEnBloc('dUser', $param);
    if (ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = dUser, key = track_expiration_days = 0");
    $ret = getConfiguration('dUser', CONFIG_KEY_TRACK_EXPIRATION_DAYS, true);
    if ($ret == '0') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Get config: User = dUser, key = timezone_offset_minutes = -60");
    $ret = getConfiguration('dUser', CONFIG_KEY_TIMEZONE_OFFSET_MINUTES, true);
    if ($ret == '-60') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    //---------
    // Test the cleanup
    cleanUp('eUser');
    appendTestMessage("User dir 'eUser' is there after clean up for 'eUser' that has an expiration time of 15 days");
    $dirToOld = USER_DIR . DIRECTORY_SEPARATOR . 'eUser';
    if (is_dir($dirToOld)) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("User dir 'dUser' was removed by the clean up for 'dUser' that has an expiration time of 0 days.");
    $dirToOld = USER_DIR . DIRECTORY_SEPARATOR . 'dUser';
    if (!is_dir($dirToOld)) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("Remove test users");
    $ret = removeTestUsers();
    if ($ret) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    resetConfig(ADMIN_NAME);
    return true;
}
Example #2
0
    return;
}
// server info for admin only
$phpInfo = getParam('phpInfo');
if (!isNullOrEmptyString($phpInfo)) {
    if (!preg_match('/admin/i', $user)) {
        setServerError("Failed to get php infos (not allowed) for user {$user}.");
        return;
    }
    phpinfo();
    return;
}
// set configurations (expiration day, timezone offset, write tracks,...)
$setConfiguration = getParam('set_configuration');
if (!isNullOrEmptyString($setConfiguration)) {
    if (!setConfigurationEnBloc($user, $setConfiguration)) {
        setServerError("Failed to write postion for user {$user}.");
        return;
    }
    setServerResponse("Ok, server wrote configuration for user {$user}.");
    return;
}
// get configurations (expiration day, timezone offset, write tracks,...)
$getConfiguration = getParam('get_configuration');
if (!isNullOrEmptyString($getConfiguration)) {
    $configs = getConfigurations($user);
    setServerResponse($configs);
    return;
}
// Write single position
$lat = getParam('lat');