Subversion Repositories oidplus

Rev

Rev 632 | Rev 641 | 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 - 2021 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. // Before we do ANYTHING, check for dependencies! Do not include anything (except the GMP supplement) yet.
  21.  
  22. define('INSIDE_OIDPLUS', true);
  23.  
  24. require_once __DIR__ . '/functions.inc.php'; // Required for _L()
  25.  
  26. if (version_compare(PHP_VERSION, '7.0.0') < 0) {
  27.         // More information about the required PHP version:
  28.         // doc/developer_notes/php7_compat
  29.         echo '<!DOCTYPE HTML>';
  30.         echo '<html><head><title>'._L('OIDplus error').'</title></head><body>';
  31.         echo '<h1>'._L('OIDplus error').'</h1>';
  32.         echo '<p>'._L('OIDplus requires at least PHP version %1! You are currently using version %2','7.0',PHP_VERSION).'</p>'."\n";
  33.         echo '</body></html>';
  34.         die();
  35. }
  36.  
  37. require_once __DIR__ . '/../vendor/autoload.php';
  38.  
  39. include_once __DIR__ . '/../vendor/danielmarschall/php_utils/gmp_supplement.inc.php';
  40. include_once __DIR__ . '/../vendor/symfony/polyfill-mbstring/bootstrap.php';
  41. include_once __DIR__ . '/../vendor/danielmarschall/php_utils/simplexml_supplement.inc.php';
  42.  
  43. require_once __DIR__ . '/oidplus_dependency.inc.php';
  44.  
  45. $missing_dependencies = oidplus_get_missing_dependencies();
  46.  
  47. if (count($missing_dependencies) >= 1) {
  48.         echo '<!DOCTYPE HTML>';
  49.         echo '<html><head><title>'._L('OIDplus error').'</title></head><body>';
  50.         echo '<h1>'._L('OIDplus error').'</h1>';
  51.         echo '<p>'._L('The following PHP extensions need to be installed in order to run OIDplus:').'</p>';
  52.         echo '<ul>';
  53.         foreach ($missing_dependencies as $dependency) {
  54.                 echo '<li>'.$dependency.'<br><br></li>';
  55.         }
  56.         echo '</ul>';
  57.         echo '</body></html>';
  58.         die();
  59. }
  60.  
  61. unset($missing_dependencies);
  62.  
  63. // Now we can continue!
  64.  
  65. if (PHP_SAPI != 'cli') {
  66.         // TODO: Plugins should be able to extend CSP
  67.         header('X-Content-Type-Options: nosniff');
  68.         header('X-XSS-Protection: 1; mode=block');
  69.         header("Content-Security-Policy: default-src 'self' blob: https://fonts.gstatic.com https://www.google.com/ https://www.gstatic.com/ https://cdnjs.cloudflare.com/; ".
  70.                "style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com/; ".
  71.                "img-src blob: data: http: https:; ".
  72.                "script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: https://www.google.com/ https://www.gstatic.com/ https://cdnjs.cloudflare.com/ https://polyfill.io/; ".
  73.                "frame-ancestors 'none'; ".
  74.                "object-src 'none'");
  75.         header('X-Frame-Options: SAMEORIGIN');
  76.         header('Referrer-Policy: no-referrer-when-downgrade');
  77. }
  78.  
  79. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/oid_utils.inc.php';
  80. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/xml_utils.inc.php';
  81. require_once __DIR__ . '/../vendor/danielmarschall/uuid_mac_utils/includes/uuid_utils.inc.php';
  82. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/color_utils.inc.php';
  83. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/ipv4_functions.inc.php';
  84. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/ipv6_functions.inc.php';
  85. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/anti_xss.inc.php';
  86.  
  87. // ---
  88.  
  89. spl_autoload_register(function ($class_name) {
  90.         static $class_refs = null;
  91.  
  92.         if (is_null($class_refs)) {
  93.                 $valid_plugin_folders = array(
  94.                         'adminPages',
  95.                         'auth',
  96.                         'database',
  97.                         'design',
  98.                         'language',
  99.                         'logger',
  100.                         'objectTypes',
  101.                         'publicPages',
  102.                         'raPages',
  103.                         'sqlSlang'
  104.                 );
  105.  
  106.                 $func = function(&$class_refs, $class_files, $namespace='') {
  107.                         foreach ($class_files as $filename) {
  108.                                 $cn = strtolower(basename($filename));
  109.                                 $cn = preg_replace('@(\\.class){0,1}\\.php$@', '', $cn);
  110.                                 if (!empty($namespace)) {
  111.                                         if (substr($namespace,-1,1) !== '\\') $namespace .= '\\';
  112.                                         $cn = strtolower($namespace) . $cn;
  113.                                 }
  114.                                 if (!isset($class_refs[$cn])) {
  115.                                         $class_refs[$cn] = $filename;
  116.                                 }
  117.                         }
  118.                 };
  119.  
  120.                 $class_files = array();
  121.  
  122.                 // Global namespace / OIDplus
  123.                 // (the last has the highest priority)
  124.                 foreach ($valid_plugin_folders as $folder) {
  125.                         $class_files = array_merge($class_files, glob(__DIR__ . '/../plugins/'.'*'.'/'.$folder.'/'.'*'.'/'.'*'.'.class.php'));
  126.                 }
  127.                 $class_files = array_merge($class_files, glob(__DIR__ . '/classes/'.'*'.'.class.php'));
  128.                 $class_files = array_merge($class_files, glob(__DIR__ . '/../vendor/danielmarschall/fileformats/'.'*'.'.class.php'));
  129.                 $class_files = array_merge($class_files, glob(__DIR__ . '/../vendor/danielmarschall/php_utils/'.'*'.'.class.php'));
  130.                 $func($class_refs, $class_files);
  131.         }
  132.  
  133.         $class_name = strtolower($class_name);
  134.         if (isset($class_refs[$class_name])) {
  135.                 require $class_refs[$class_name];
  136.                 unset($class_refs[$class_name]); // this emulates a "require_once" and is faster
  137.         }
  138. });
  139.