示例#1
0
文件: scrd.php 项目: nikkiii/php-scrd
<?php
$args = arguments($argv);

if(isset($args['conf'])) {
	$conf = readconf($args['conf']);
} else {
	$conf = readconf("/usr/local/etc/scrd.conf");
}

$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, 0, 12909) or die('Could not bind to address');
socket_listen($sock);

echo "Listening\n";

while(true) {
	$client = socket_accept($sock);
	$addr = "";
	socket_getpeername($client, $addr);
	echo "Socket opened: $addr\n";
	if(in_array($addr, $conf['white'])) {
		$resp = array();
		$resp['hostname'] = hostname();
		$resp['who'] = who();
		$resp['uplo'] = array_merge(array("uptime" => uptime()), loadavg());
		$resp['ram'] = memory();
		$resp['ips'] = ip_addresses();
		$reps['disk'] = diskusage();
		socket_write($client, json_encode($resp));
	} else {
		socket_write($client, json_encode(array("error" => "Unauthorized")));
示例#2
0
/**
 * Main entry point for churchtools.
 * This will be called from /index.php
 * Function loads i18n, configuration, check data security.
 * If everything is ok, it calls churchtools_processRequest()
 */
function churchtools_app()
{
    global $q, $q_orig, $currentModule, $add_header, $config, $mapping, $content, $base_url, $files_dir, $user, $embedded, $i18n;
    include_once CHURCHCORE . "/churchcore_db.php";
    $files_dir = DEFAULT_SITE;
    // which module is requested?
    $q = $q_orig = readVar("q", userLoggedIn() ? "home" : readConf("site_startpage", "home"));
    // $currentModule is needed for class autoloading and maybe other include paths
    list($currentModule) = explode('/', readVar("q"));
    // get first part of $q or churchcore
    $embedded = readVar("embedded", false);
    $base_url = getBaseUrl();
    $config = loadConfig();
    if ($config) {
        if (db_connect()) {
            // DBConfig overwrites the config files
            loadDBConfig();
            date_default_timezone_set(variable_get("timezone", "Europe/Berlin"));
            if (isset($_COOKIE["language"])) {
                $config["language"] = $_COOKIE["language"];
            }
            // Load i18n churchcore-bundle
            if (!isset($config["language"])) {
                if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                    $config["language"] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
                } else {
                    $config["language"] = "de";
                }
            }
            $i18n = new TextBundle(CHURCHCORE . "/resources/messages");
            $i18n->load("churchcore", $config["language"] != null ? $config["language"] : null);
            // Session Init
            if (!file_exists($files_dir . "/tmp")) {
                @mkdir($files_dir . "/tmp", 0775, true);
            }
            if (!file_exists($files_dir . "/tmp")) {
                // Admin should act accordingly, default suggestion is 0755.
                addErrorMessage(t("permission.denied.write.dir", $files_dir));
            } else {
                session_save_path($files_dir . "/tmp");
            }
            session_name("ChurchTools_" . $config["db_name"]);
            session_start();
            register_shutdown_function('handleShutdown');
            // Check for offline mode. If it's activated display message and return false;
            if (readConf("site_offline") == 1) {
                if (!isset($_SESSION["user"]) || !in_array($_SESSION["user"]->id, readconf("admin_ids"))) {
                    echo t("site.is.down");
                    return false;
                }
            }
            $embedded = readVar("embedded", false);
            $mapping = loadMapping();
            $success = true;
            // Check for DB-Updates and loginstr only if this is not an ajax call.
            if (strrpos($q, "ajax") === false) {
                $success = checkForDBUpdates();
            }
            if ($success) {
                // Is there a loginstr which does not fit to the current logged in user?
                if (readVar("loginstr") && readVar("id") && userLoggedIn() && $_SESSION["user"]->id != readVar("id")) {
                    logout_current_user();
                    session_start();
                } else {
                    loadUserObjectInSession();
                }
            }
            if ($success) {
                if (isset($_SESSION['user'])) {
                    $user = $_SESSION['user'];
                }
                // Accept data security?
                if (userLoggedIn() && !isset($_SESSION["simulate"]) && $q != "logout" && isset($config["accept_datasecurity"]) && $config["accept_datasecurity"] == 1 && !isset($user->acceptedsecurity)) {
                    $content .= pleaseAcceptDatasecurity();
                } else {
                    $content .= churchtools_processRequest($q);
                }
            }
        }
    }
    include INCLUDES . "/header.php";
    echo $content;
    include INCLUDES . "/body.php";
}