コード例 #1
0
function new_config()
{
    #Begin creation of config.php
    $config = "<?php\n";
    #Define all the required variables for config.php
    $needed = array("os_ip", "os_pw", "pass_file", "cache_file", "log_file", "lang", "weather_provider", "wapikey");
    #Cycle through each needed key
    foreach ($needed as $key) {
        #If required variable is not submitted then fail
        if (!isset($_REQUEST[$key])) {
            fail();
        }
        $data = $_REQUEST[$key];
        #If processing OS IP then check if the IP is valid and if not, fail with error code 2
        if ($key == "os_ip") {
            if (!isValidUrl("http://" . $data)) {
                echo 2;
                exit;
            }
            $config .= "\$is_ospi = " . isOSPi("http://" . $data) . ";\n";
        }
        #If processing password file then go ahead and generate it with proper username/password hash
        if ($key == "pass_file") {
            #If username or password is not submitted fail
            if (!isset($_REQUEST["username"]) || !isset($_REQUEST["password"])) {
                fail();
            }
            $file = fopen($data, 'w');
            #If unable to open the pass file fail
            if (!$file) {
                fail();
            } else {
                $r = fwrite($file, $_REQUEST["username"] . ":" . base64_encode(sha1($_REQUEST["password"])));
                if (!$r) {
                    fail();
                }
                fclose($file);
            }
        }
        #Attempt to make the cache file and log file file
        if ($key == "cache_file" || $key == "log_file") {
            make_file($data);
        }
        #Append current key/data pair to config.php string.
        $config .= "\$" . $key . " = '" . $data . "';\n";
    }
    if (isset($_REQUEST["force_ssl"])) {
        $config .= "\$force_ssl=1;\n";
    } else {
        $config .= "\$force_ssl=0;\n";
    }
    if (isset($_REQUEST["local_assets"])) {
        $config .= "\$local_assets=1;\n";
    } else {
        $config .= "\$local_assets=0;\n";
    }
    #Attempt to open config.php for writing
    $file = fopen("config.php", 'w');
    #If unable, fail
    if (!$file) {
        fail();
    }
    #Write the config out
    $r = fwrite($file, $config . "?>");
    #If unable to write the config, fail
    if (!$r) {
        fail();
    }
    try {
        #Add the watcher for logs to crontab
        $output = shell_exec('crontab -l');
        if (strpos($output, "/watcher.php >/dev/null 2>&1") === false) {
            file_put_contents('/tmp/crontab.txt', $output . '* * * * * cd ' . dirname(__FILE__) . '; php ' . dirname(__FILE__) . '/watcher.php >/dev/null 2>&1' . PHP_EOL);
            exec('crontab /tmp/crontab.txt');
        }
    } catch (Exception $e) {
        echo 3;
        exit;
    }
    #Tell javascript action was succesful
    echo 1;
}
コード例 #2
0
ファイル: main.php プロジェクト: yatishextreme/Sprinklers-PHP
    $local_assets = 0;
}
if (!isset($auto_delay)) {
    changeConfig("auto_delay", 0, "i");
    $auto_delay = 0;
}
if (!isset($auto_mm)) {
    changeConfig("auto_mm", 0, "i");
    $auto_mm = 0;
}
if (!isset($auto_delay_duration)) {
    changeConfig("auto_delay_duration", 24, "i");
    $auto_delay_duration = 24;
}
if (!isset($is_ospi)) {
    isOSPi();
}
#Configure weather
if (!isset($weather_provider)) {
    $weather_provider = "yahoo";
    changeConfig("weather_provider", $weather_provider, "s");
}
if (!isset($woeid)) {
    $woeid = get_woeid();
    changeConfig("woeid", $woeid, "i");
}
if (!isset($lid)) {
    $lid = get_wunderground_lid();
    changeConfig("lid", $lid, "s");
}
#Get Base URL of Site