Exemple #1
0
 private function __construct()
 {
     self::$CONFIG = parse_ini_file('config.ini', true);
     self::$_ROOT = realpath(dirname(__FILE__) . '/../');
     $OAUTH_CONFIG = parse_ini_file(realpath(dirname(__FILE__) . '/oauth_config.ini'), true);
     register_shutdown_function('Bootstrap::fatalErrorHandler');
     $mv = parse_ini_file('version.ini');
     self::$_INI_VERSION = $mv['version'];
     $this->_setIncludePath();
     spl_autoload_register('Bootstrap::loadClass');
     require_once 'Predis/autoload.php';
     if (stripos(PHP_SAPI, 'cli') === false) {
         register_shutdown_function('Bootstrap::sessionClose');
         INIT::$PROTOCOL = isset($_SERVER['HTTPS']) ? "https" : "http";
         INIT::$HTTPHOST = INIT::$PROTOCOL . "://" . $_SERVER['HTTP_HOST'];
     } else {
         if (INIT::$DEBUG) {
             echo "\nPHP Running in CLI mode.\n\n";
         }
         //Possible CLI configurations. We definitly don't want sessions in our cron scripts
     }
     INIT::$OAUTH_CONFIG = $OAUTH_CONFIG['OAUTH_CONFIG'];
     INIT::obtain();
     INIT::$ROOT = self::$_ROOT;
     // Accesible by Apache/PHP
     INIT::$BASEURL = "/";
     // Accesible by the browser
     INIT::$TIME_TO_EDIT_ENABLED = false;
     INIT::$DEFAULT_NUM_RESULTS_FROM_TM = 3;
     INIT::$THRESHOLD_MATCH_TM_NOT_TO_SHOW = 50;
     //get the environment configuration
     self::getEnvConfig();
     INIT::$LOG_REPOSITORY = INIT::$STORAGE_DIR . "/log_archive";
     INIT::$UPLOAD_REPOSITORY = INIT::$STORAGE_DIR . "/upload";
     INIT::$FILES_REPOSITORY = INIT::$STORAGE_DIR . "/files_storage/files";
     INIT::$CACHE_REPOSITORY = INIT::$STORAGE_DIR . "/files_storage/cache";
     INIT::$CONVERSIONERRORS_REPOSITORY = INIT::$STORAGE_DIR . "/conversion_errors";
     INIT::$CONVERSIONERRORS_REPOSITORY_WEB = INIT::$BASEURL . "storage/conversion_errors";
     INIT::$TMP_DOWNLOAD = INIT::$STORAGE_DIR . "/tmp_download";
     INIT::$REFERENCE_REPOSITORY = INIT::$STORAGE_DIR . "/reference_files";
     INIT::$TEMPLATE_ROOT = INIT::$ROOT . "/lib/View";
     INIT::$MODEL_ROOT = INIT::$ROOT . '/lib/Model';
     INIT::$CONTROLLER_ROOT = INIT::$ROOT . '/lib/Controller';
     INIT::$UTILS_ROOT = INIT::$ROOT . '/lib/Utils';
     if (!is_dir(INIT::$STORAGE_DIR)) {
         mkdir(INIT::$STORAGE_DIR, 0755, true);
     }
     if (!is_dir(INIT::$LOG_REPOSITORY)) {
         mkdir(INIT::$LOG_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$UPLOAD_REPOSITORY)) {
         mkdir(INIT::$UPLOAD_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$FILES_REPOSITORY)) {
         mkdir(INIT::$FILES_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$CACHE_REPOSITORY)) {
         mkdir(INIT::$CACHE_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$CONVERSIONERRORS_REPOSITORY)) {
         mkdir(INIT::$CONVERSIONERRORS_REPOSITORY, 0755, true);
     }
     //auth sections
     INIT::$AUTHSECRET_PATH = INIT::$ROOT . '/inc/login_secret.dat';
     //if secret is set in file
     if (file_exists(INIT::$AUTHSECRET_PATH)) {
         //fetch it
         INIT::$AUTHSECRET = file_get_contents(INIT::$AUTHSECRET_PATH);
     } else {
         //try creating the file and the fetch it
         //generate pass
         $secret = self::generate_password(512);
         //put file
         file_put_contents(INIT::$AUTHSECRET_PATH, $secret);
         //if put succeed
         if (file_exists(INIT::$AUTHSECRET_PATH)) {
             //restrict permissions
             chmod(INIT::$AUTHSECRET_PATH, 0400);
         } else {
             //if couldn't create due to permissions, use default secret
             INIT::$AUTHSECRET = 'ScavengerOfHumanSorrow';
         }
     }
 }