Subversion Repositories oidplus

Rev

Rev 27 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. class OIDplus {
  21.         private static /*OIDplusDataBase*/ $database;
  22.         private static /*OIDplusConfig*/ $config;
  23.  
  24.         private function __construct() {
  25.         }
  26.  
  27.         public static function db() {
  28.                 if (is_null(self::$database)) {
  29.                         self::$database = new OIDplusDataBaseMySQL();
  30.                 }
  31.                 return self::$database;
  32.         }
  33.  
  34.         public static function config() {
  35.                 if (is_null(self::$config)) {
  36.                         self::$config = new OIDplusConfig();
  37.                 }
  38.                 return self::$config;
  39.         }
  40.  
  41.         public static function gui() {
  42.                 return new OIDplusGui();
  43.         }
  44.  
  45.         public static function authUtils() {
  46.                 return new OIDplusAuthUtils();
  47.         }
  48.  
  49.         public static function system_url() {
  50.                 return dirname($actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]").'/';
  51.         }
  52.  
  53.         public static function init($html=true) {
  54.                 // Include config file
  55.                 if (file_exists(__DIR__ . '/../config.inc.php')) {
  56.                         include_once __DIR__ . '/../config.inc.php';
  57.                 } else {
  58.                         if ($html) {
  59.                                 if (!is_dir(__DIR__.'/../setup')) {
  60.                                         echo 'Error: Setup directory missing.';
  61.                                 } else {
  62.                                         header('Location:setup');
  63.                                 }
  64.                         } else {
  65.                                 echo 'Error: Setup directory missing!';
  66.                         }
  67.                         die();
  68.                 }
  69.  
  70.                 // Auto-fill non-existing config values
  71.                 if (!defined('OIDPLUS_CONFIG_VERSION'))   define('OIDPLUS_CONFIG_VERSION',   0.0);
  72.                 if (!defined('OIDPLUS_ADMIN_PASSWORD'))   define('OIDPLUS_ADMIN_PASSWORD',   '');
  73.                 if (!defined('OIDPLUS_ADMIN_EMAIL'))      define('OIDPLUS_ADMIN_EMAIL',      '');
  74.                 if (!defined('OIDPLUS_MYSQL_HOST'))       define('OIDPLUS_MYSQL_HOST',       'localhost');
  75.                 if (!defined('OIDPLUS_MYSQL_USERNAME'))   define('OIDPLUS_MYSQL_USERNAME',   'root');
  76.                 if (!defined('OIDPLUS_MYSQL_PASSWORD'))   define('OIDPLUS_MYSQL_PASSWORD',   '');
  77.                 if (!defined('OIDPLUS_MYSQL_DATABASE'))   define('OIDPLUS_MYSQL_DATABASE',   'oidplus');
  78.                 if (!defined('OIDPLUS_TABLENAME_PREFIX')) define('OIDPLUS_TABLENAME_PREFIX', '');
  79.                 if (!defined('OIDPLUS_SESSION_SECRET'))   define('OIDPLUS_SESSION_SECRET',   '');
  80.  
  81.                 // Check version of the config file
  82.                 if (OIDPLUS_CONFIG_VERSION != 0.1) {
  83.                         if ($html) {
  84.                                 echo '<h1>Error</h1><p>The information located in <b>includes/config.inc.php</b> is outdated.</p><p>Please run <a href="setup/">setup</a> again.</p>';
  85.                         } else {
  86.                                 echo 'The information located in includes/config.inc.php is outdated. Please run setup again.';
  87.                         }
  88.                         die();
  89.                 }
  90.         }
  91. }
  92.