function mod_mysqllog()
 {
     global $conf;
     $this->modtype = "log";
     $this->modname = "MySQL logging";
     if (!($cid = @mysql_pconnect($conf["global"]["mysqlloghost"][0], $conf["global"]["mysqlloguser"][0], $conf["global"]["mysqllogpassword"][0]))) {
         errexit("Unable to connect to database");
     }
     mysql_close($cid);
 }
示例#2
0
function nanoweb_init($conffile)
{
    global $conf, $themes, $cmdline_conf_overrides, $cmdline_conf_adds, $modules, $posix_av, $pcntl_av, $gz_av, $mime, $access_policy, $sysusr, $sysgrp, $icnt, $banned_ips, $srvlog_levels;
    $dc = get_defined_constants();
    foreach ($dc as $cname => $cval) {
        if (substr($cname, 0, 6) == "NW_EL_") {
            $srvlog_levels[strtolower(substr($cname, 6))] = $cval;
        }
    }
    $iconf = parseconfig(file($conffile));
    if (is_string($iconf)) {
        if ($icnt) {
            techo($iconf, NW_EL_WARNING);
            return false;
        } else {
            errexit($iconf);
        }
    } else {
        if (is_array($iconf)) {
            $conf = $iconf;
        }
    }
    $conf = cmdline_conf_upd($conf, $cmdline_conf_overrides, $cmdline_conf_adds);
    $modules = load_modules($conf);
    modules_init();
    $themes = load_themes($conf);
    ++$icnt;
    $ap_aliases = array("parseext" => "_parseext", "alias" => "_aliases", "errordocument" => "_errordocument", "errorheader" => "_errorheader");
    $access_policy = array();
    foreach ($conf["global"]["accessoverride"] as $ov_dir) {
        if ($ov_dir) {
            $access_policy[strtolower($ov_dir)] = "override";
        }
    }
    foreach ($conf["global"]["accessmerge"] as $mg_dir) {
        if ($mg_dir) {
            $access_policy[strtolower($mg_dir)] = "merge";
        }
    }
    foreach ($conf["global"]["accessblock"] as $bl_dir) {
        if ($bl_dir) {
            $access_policy[strtolower($bl_dir)] = "block";
        }
    }
    foreach ($ap_aliases as $rk => $ak) {
        if ($access_policy[$rk]) {
            $access_policy[$ak] = $access_policy[$rk];
        }
    }
    $posix_av = is_callable("posix_setuid");
    $pcntl_av = is_callable("pcntl_fork");
    $gz_av = is_callable("gzencode");
    if (count($themes) == 0) {
        techo("WARN: No theme loaded, server generated content is disabled", NW_EL_WARNING);
    }
    if ($posix_av) {
        foreach ($conf as $vconf) {
            if ($u = $vconf["user"][0]) {
                $sysusr[$u] = @posix_getpwnam($u);
            }
            if ($g = $vconf["group"][0]) {
                $sysgrp[$g] = @posix_getgrnam($g);
            }
        }
    }
    if (!$conf["global"]["singleprocessmode"][0] && (!$posix_av || !$pcntl_av || $conf["global"]["servermode"][0] == "inetd")) {
        techo("WARN: forcing single process mode", NW_EL_WARNING);
        $conf["global"]["singleprocessmode"][0] = true;
    }
    if ($conf["global"]["servermode"][0] == "inetd") {
        unset($conf["global"]["logtoconsole"]);
        unset($conf["global"]["pidfile"]);
    }
    if ($conf["global"]["singleprocessmode"][0]) {
        $conf["global"]["loggerprocess"] = 0;
        if ($conf["global"]["keepalive"][0]) {
            techo("WARN: KeepAlive should be set to 0 in single process mode", NW_EL_WARNING);
        }
    }
    if ($pcntl_av) {
        pcntl_signal(SIGTERM, "nanoweb_shutdown");
        pcntl_signal(SIGHUP, "nanoweb_reload");
    }
    $mime = array();
    if (!@is_readable($conf["global"]["mimetypes"][0])) {
        techo("WARN: unable to read mime types file (" . $conf["global"]["mimetypes"][0] . "), using internals", NW_EL_WARNING);
        $mime = array("html" => "text/html", "xml" => "text/xml", "gif" => "image/gif", "jpeg" => "image/jpeg", "png" => "image/png", "tgz" => "application/gtar");
    } else {
        if ($mimetypes = @file($conf["global"]["mimetypes"][0])) {
            foreach ($mimetypes as $s) {
                if (trim($s) && $s[0] != "#") {
                    if (ereg("([a-zA-Z0-9/.-]+)[ \t]+([a-zA-Z0-9 -]+)", $s, $res)) {
                        if ($exts = explode(" ", trim($res[2]))) {
                            foreach ($exts as $ext) {
                                if (trim($res[1]) && trim($ext)) {
                                    $mime[$ext] = trim($res[1]);
                                }
                            }
                        }
                    }
                }
            }
            unset($mimetypes);
        }
    }
    if ($at = $conf["global"]["addtype"]) {
        foreach ($at as $adt) {
            $mt = strtok(trim($adt), " ");
            while ($s = strtok(" ")) {
                $mime[ltrim($s, ".")] = $mt;
            }
        }
    }
    $conf["_complete"] = true;
    $banned_ips = array();
    if (is_array($conf["global"]["blockipaddr"])) {
        foreach ($conf["global"]["blockipaddr"] as $ip) {
            nw_block_ip_address($ip, "PERM", "config.BlockIPAddr");
        }
    }
    return true;
}