예제 #1
0
 static function init()
 {
     global $Opt;
     assert(self::$original_opt === null);
     self::$original_opt = $Opt;
     $confid = get($Opt, "confid");
     if (!$confid && PHP_SAPI == "cli") {
         $cliopt = getopt("n:", array("name:"));
         if (get($cliopt, "n")) {
             $confid = $cliopt["n"];
         } else {
             if (get($cliopt, "name")) {
                 $confid = $cliopt["name"];
             }
         }
     } else {
         if (!$confid) {
             $base = Navigation::site_absolute(true);
             if ($multis = get($Opt, "multiconferenceAnalyzer")) {
                 foreach (is_array($multis) ? $multis : array($multis) as $multi) {
                     list($match, $replace) = explode(" ", $multi);
                     if (preg_match("`\\A{$match}`", $base, $m)) {
                         $confid = $replace;
                         for ($i = 1; $i < count($m); ++$i) {
                             $confid = str_replace("\${$i}", $m[$i], $confid);
                         }
                         break;
                     }
                 }
             } else {
                 if (preg_match(',/([^/]+)/\\z,', $base, $m)) {
                     $confid = $m[1];
                 }
             }
         }
     }
     if (!$confid) {
         $confid = "__nonexistent__";
     } else {
         if (!preg_match(',\\A[-a-zA-Z0-9_][-a-zA-Z0-9_.]*\\z,', $confid)) {
             $confid = "__invalid__";
         }
     }
     self::assign_confid($Opt, $confid);
 }
예제 #2
0
파일: init.php 프로젝트: benesch/peteramati
function load_pset_info()
{
    global $ConfSitePATH, $Conf, $PsetInfo, $PsetOverrides, $Opt;
    // read initial messages
    Messages::$main = new Messages();
    $x = json_decode(file_get_contents("{$ConfSitePATH}/src/messages.json"));
    foreach ($x as $j) {
        Messages::$main->add($j);
    }
    // read psets
    $PsetInfo = load_psets_json(false);
    // parse psets
    foreach ($PsetInfo as $pk => $p) {
        if (!is_object($p) || !isset($p->psetid)) {
            continue;
        }
        object_merge_recursive($p, $PsetInfo->_defaults);
        try {
            $pset = new Pset($pk, $p);
            Pset::register($pset);
        } catch (Exception $exception) {
            // Want to give a good error message, so discover where the error is.
            // - create pset landmark object
            $locinfo = (object) array();
            foreach (psets_json_data(false) as $fname => $data) {
                $x = Json::decode_landmarks($data, $fname);
                object_replace_recursive($locinfo, $x);
            }
            $locp = $locinfo->{$pk};
            if (isset($locinfo->_defaults)) {
                object_merge_recursive($locp, $locinfo->_defaults);
            }
            // - lookup exception path in landmark object
            $path = $exception instanceof PsetConfigException ? $exception->path : array();
            for ($pathpos = 0; $pathpos < count($path) && $locp && !is_string($locp); ++$pathpos) {
                $component = $path[$pathpos];
                $locp = is_array($locp) ? $locp[$component] : $locp->{$component};
            }
            // - report error
            if (is_object($locp) && @$locp->__LANDMARK__) {
                $locp = $locp->__LANDMARK__;
            } else {
                if (!is_string($locp)) {
                    $locp = $locinfo->{$pk}->__LANDMARK__;
                }
            }
            Multiconference::fail_message($locp . ": Configuration error: " . $exception->getMessage());
        }
    }
    // read message data
    if (!@$PsetInfo->_messagedefs) {
        $PsetInfo->_messagedefs = (object) array();
    }
    if (!@$PsetInfo->_messagedefs->SYSTEAM) {
        $PsetInfo->_messagedefs->SYSTEAM = "cs61-staff";
    }
    foreach ($PsetInfo->_messagedefs as $k => $v) {
        Messages::$main->define($k, $v);
    }
    // also create log/ and repo/ directories
    foreach (array("{$ConfSitePATH}/log", "{$ConfSitePATH}/repo") as $d) {
        if (!is_dir($d) && !mkdir($d, 02770, true)) {
            $e = error_get_last();
            Multiconference::fail_message("`{$d}` missing and cannot be created (" . $e["message"] . ").");
        }
        if (!file_exists("{$d}/.htaccess") && ($x = file_get_contents("{$ConfSitePATH}/src/.htaccess")) !== false && file_put_contents("{$d}/.htaccess", $x) != strlen($x)) {
            Multiconference::fail_message("Error creating `{$d}/.htaccess`");
        }
    }
    // if any anonymous problem sets, create anonymous usernames
    foreach (Pset::$all as $p) {
        if (!$p->disabled && $p->anonymous) {
            while ($row = Dbl::fetch_first_row(Dbl::qe("select contactId from ContactInfo where anon_username is null limit 1"))) {
                Dbl::q("update ContactInfo set anon_username='******' where contactId=?", $row[0]);
            }
        }
    }
}
예제 #3
0
    }
}
if (!get($Opt, "loaded") || get($Opt, "missing")) {
    Multiconference::fail_bad_options();
}
if (get($Opt, "dbLogQueries")) {
    Dbl::log_queries($Opt["dbLogQueries"]);
}
// Allow lots of memory
function set_memory_limit()
{
    global $Opt;
    if (!get($Opt, "memoryLimit")) {
        $suf = array("" => 1, "k" => 1 << 10, "m" => 1 << 20, "g" => 1 << 30);
        if (preg_match(',\\A(\\d+)\\s*([kmg]?)\\z,', strtolower(ini_get("memory_limit")), $m) && $m[1] * $suf[$m[2]] < 128 << 20) {
            $Opt["memoryLimit"] = "128M";
        }
    }
    if (get($Opt, "memoryLimit")) {
        ini_set("memory_limit", $Opt["memoryLimit"]);
    }
}
set_memory_limit();
// Create the conference
global $Conf;
if (!$Conf) {
    $Conf = Conf::$g = new Conf(Dbl::make_dsn($Opt));
}
if (!$Conf->dblink) {
    Multiconference::fail_bad_database();
}