Exemplo n.º 1
0
function load_pset_info()
{
    global $ConfSitePATH, $Conf, $PsetInfo, $PsetOverrides;
    // 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($Conf, $pk, $p);
            $Conf->register_pset($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) && get($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 (!get($PsetInfo, "_messagedefs")) {
        $PsetInfo->_messagedefs = (object) array();
    }
    if (!get($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 ($Conf->psets() 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]);
            }
        }
    }
    // update repository regrade requests
    if ($Conf->sversion == 107) {
        updateSchema($Conf);
    }
}
Exemplo n.º 2
0
 function load_settings()
 {
     global $Now;
     // load settings from database
     $this->settings = array();
     $this->settingTexts = array();
     foreach ($this->opt_override ?: [] as $k => $v) {
         if ($v === null) {
             unset($this->opt[$k]);
         } else {
             $this->opt[$k] = $v;
         }
     }
     $this->opt_override = [];
     $this->_pc_seeall_cache = null;
     $this->deadlineCache = null;
     $result = $this->q_raw("select name, value, data from Settings");
     while ($result && ($row = $result->fetch_row())) {
         $this->settings[$row[0]] = (int) $row[1];
         if ($row[2] !== null) {
             $this->settingTexts[$row[0]] = $row[2];
         }
         if (substr($row[0], 0, 4) == "opt.") {
             $okey = substr($row[0], 4);
             $this->opt_override[$okey] = get($this->opt, $okey);
             $this->opt[$okey] = $row[2] === null ? (int) $row[1] : $row[2];
         }
     }
     Dbl::free($result);
     // update schema
     $this->sversion = $this->settings["allowPaperOption"];
     if ($this->sversion < 108) {
         require_once "updateschema.php";
         $old_nerrors = Dbl::$nerrors;
         updateSchema($this);
         Dbl::$nerrors = $old_nerrors;
     }
     // invalidate all caches after loading from backup
     if (isset($this->settings["frombackup"]) && $this->invalidate_caches()) {
         $this->qe_raw("delete from Settings where name='frombackup' and value=" . $this->settings["frombackup"]);
         unset($this->settings["frombackup"]);
     } else {
         $this->invalidate_caches(["rf" => true]);
     }
     // update options
     if (isset($this->opt["ldapLogin"]) && !$this->opt["ldapLogin"]) {
         unset($this->opt["ldapLogin"]);
     }
     if (isset($this->opt["httpAuthLogin"]) && !$this->opt["httpAuthLogin"]) {
         unset($this->opt["httpAuthLogin"]);
     }
     // set conferenceKey
     if (!isset($this->opt["conferenceKey"])) {
         if (!isset($this->settingTexts["conf_key"]) && ($key = hotcrp_random_bytes(32)) !== false) {
             $this->save_setting("conf_key", 1, $key);
         }
         $this->opt["conferenceKey"] = get($this->settingTexts, "conf_key", "");
     }
     // set capability key
     if (!get($this->settings, "cap_key") && !get($this->opt, "disableCapabilities") && !(($key = hotcrp_random_bytes(16)) !== false && ($key = base64_encode($key)) && $this->save_setting("cap_key", 1, $key))) {
         $this->opt["disableCapabilities"] = true;
     }
     // GC old capabilities
     if (defval($this->settings, "__capability_gc", 0) < $Now - 86400) {
         foreach (array($this->dblink, Contact::contactdb()) as $db) {
             if ($db) {
                 Dbl::ql($db, "delete from Capability where timeExpires>0 and timeExpires<{$Now}");
             }
         }
         $this->q_raw("insert into Settings (name, value) values ('__capability_gc', {$Now}) on duplicate key update value=values(value)");
         $this->settings["__capability_gc"] = $Now;
     }
     $this->crosscheck_settings();
     $this->crosscheck_options();
 }
Exemplo n.º 3
0
 function load_settings()
 {
     global $Opt, $OptOverride, $Now, $OK;
     // load settings from database
     $this->settings = array();
     $this->settingTexts = array();
     $result = $this->q("select name, value, data from Settings");
     while ($result && ($row = $result->fetch_row())) {
         $this->settings[$row[0]] = (int) $row[1];
         if ($row[2] !== null) {
             $this->settingTexts[$row[0]] = $row[2];
         }
         if (substr($row[0], 0, 4) == "opt.") {
             $okey = substr($row[0], 4);
             if (!array_key_exists($okey, $OptOverride)) {
                 $OptOverride[$okey] = get($Opt, $okey);
             }
             $Opt[$okey] = $row[2] === null ? (int) $row[1] : $row[2];
         }
     }
     Dbl::free($result);
     // update schema
     $this->sversion = $this->settings["allowPaperOption"];
     if ($this->sversion < 132) {
         require_once "updateschema.php";
         $oldOK = $OK;
         updateSchema($this);
         $OK = $oldOK;
     }
     if ($this->sversion < 73) {
         self::msg_error("Warning: The database could not be upgraded to the current version; expect errors. A system administrator must solve this problem.");
     }
     // invalidate caches after loading from backup
     if (isset($this->settings["frombackup"]) && $this->invalidateCaches()) {
         $this->qe("delete from Settings where name='frombackup' and value=" . $this->settings["frombackup"]);
         unset($this->settings["frombackup"]);
     } else {
         $this->invalidateCaches(array("rf" => true));
     }
     // update options
     if (isset($Opt["ldapLogin"]) && !$Opt["ldapLogin"]) {
         unset($Opt["ldapLogin"]);
     }
     if (isset($Opt["httpAuthLogin"]) && !$Opt["httpAuthLogin"]) {
         unset($Opt["httpAuthLogin"]);
     }
     // set conferenceKey
     if (!isset($Opt["conferenceKey"])) {
         if (!isset($this->settingTexts["conf_key"]) && ($key = hotcrp_random_bytes(32)) !== false) {
             $this->save_setting("conf_key", 1, $key);
         }
         $Opt["conferenceKey"] = defval($this->settingTexts, "conf_key", "");
     }
     // set capability key
     if (!get($this->settings, "cap_key") && !get($Opt, "disableCapabilities") && !(($key = hotcrp_random_bytes(16)) !== false && ($key = base64_encode($key)) && $this->save_setting("cap_key", 1, $key))) {
         $Opt["disableCapabilities"] = true;
     }
     // GC old capabilities
     if (defval($this->settings, "__capability_gc", 0) < $Now - 86400) {
         foreach (array($this->dblink, Contact::contactdb()) as $db) {
             if ($db) {
                 Dbl::ql($db, "delete from Capability where timeExpires>0 and timeExpires<{$Now}");
             }
         }
         $this->q("insert into Settings (name, value) values ('__capability_gc', {$Now}) on duplicate key update value=values(value)");
         $this->settings["__capability_gc"] = $Now;
     }
     $this->crosscheck_settings();
     $this->crosscheck_options();
 }
Exemplo n.º 4
0
<?php

include_once 'config.php';
include_once 'schema.php';
include_once 'util.php';
include 'models/Event.php';
include 'models/EventTime.php';
$database = new fDatabase('mysql', $DBDB, $DBUSER, $DBPASS, $DBHOST);
fORMDatabase::attach($database);
$schema = updateSchema($database);
fORMSchema::attach($schema);
/**
 * Automatically includes classes
 *
 * @throws Exception
 *
 * @param  string $class_name  Name of the class to load
 * @return void
 */
function __autoload($class_name)
{
    // Customize this to your root Flourish directory
    $flourish_root = getcwd() . '/../vendor/flourish/';
    $file = $flourish_root . $class_name . '.php';
    if (file_exists($file)) {
        include $file;
        return;
    }
    throw new Exception('The class ' . $class_name . ' could not be loaded');
}