Subversion Repositories oidplus

Rev

Rev 486 | Rev 511 | 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. // Before we do ANYTHING, check for dependencies! Do not include anything (except the GMP supplement) yet.
  21.  
  22. require_once __DIR__ . '/functions.inc.php'; // Required for _L()
  23.  
  24. if (version_compare(PHP_VERSION, '7.0.0') < 0) {
  25.         // Reasons why we currently require PHP 7.0:
  26.         // - Return values (e.g. "function foo(): array") (added 2020-04-06 at the database classes)
  27.         //   Note: By removing these return values (e.g. removing ": array"), you *might* be
  28.         //   able to run OIDplus with PHP lower than version 7.0 (not tested)
  29.         //
  30.         // Currently we do NOT require 7.1, because some (old-)stable distros are still using PHP 7.0
  31.         // (e.g. Debian 9 which has LTS support till May 2022).
  32.         // Therefore we commented out following features which would require PHP 7.1:
  33.         // - Nullable return values (e.g. "function foo(): ?array")
  34.         // - void return value (e.g. "function foo(): void")
  35.         // - private/protected/public consts
  36.         echo '<!DOCTYPE HTML>';
  37.         echo '<html><head><title>'._L('OIDplus error').'</title></head><body>';
  38.         echo '<h1>'._L('OIDplus error').'</h1>';
  39.         echo '<p>'._L('OIDplus requires at least PHP version %1! You are currently using version %2','7.0',PHP_VERSION).'</p>'."\n";
  40.         echo '</body></html>';
  41.         die();
  42. }
  43.  
  44. include_once __DIR__ . '/gmp_supplement.inc.php';
  45. include_once __DIR__ . '/mbstring_supplement.inc.php';
  46. include_once __DIR__ . '/simplexml_supplement.inc.php';
  47.  
  48. require_once __DIR__ . '/oidplus_dependency.inc.php';
  49.  
  50. $missing_dependencies = oidplus_get_missing_dependencies();
  51.  
  52. if (count($missing_dependencies) >= 1) {
  53.         echo '<!DOCTYPE HTML>';
  54.         echo '<html><head><title>'._L('OIDplus error').'</title></head><body>';
  55.         echo '<h1>'._L('OIDplus error').'</h1>';
  56.         echo '<p>'._L('The following PHP extensions need to be installed in order to run OIDplus:').'</p>';
  57.         echo '<ul>';
  58.         foreach ($missing_dependencies as $dependency) {
  59.                 echo '<li>'.$dependency.'<br><br></li>';
  60.         }
  61.         echo '</ul>';
  62.         echo '</body></html>';
  63.         die();
  64. }
  65.  
  66. unset($missing_dependencies);
  67.  
  68. // Now we can continue!
  69.  
  70. if (PHP_SAPI != 'cli') {
  71.         // TODO: Plugins should be able to extend CSP
  72.         header('X-Content-Type-Options: nosniff');
  73.         header('X-XSS-Protection: 1; mode=block');
  74.         header("Content-Security-Policy: default-src 'self' blob: https://fonts.gstatic.com https://www.google.com/ https://www.gstatic.com/ https://cdnjs.cloudflare.com/; ".
  75.                "style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com/; ".
  76.                "img-src blob: data: http: https:; ".
  77.                "script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: https://www.google.com/ https://www.gstatic.com/ https://cdnjs.cloudflare.com/ https://polyfill.io/; ".
  78.                "frame-ancestors 'none'; ".
  79.                "object-src 'none'");
  80.         header('X-Frame-Options: SAMEORIGIN');
  81.         header('Referrer-Policy: no-referrer-when-downgrade');
  82. }
  83.  
  84. require_once __DIR__ . '/../3p/0xbb/Sha3.php';
  85.  
  86. require_once __DIR__ . '/oid_utils.inc.php';
  87. require_once __DIR__ . '/uuid_utils.inc.php';
  88. require_once __DIR__ . '/color_utils.inc.php';
  89. require_once __DIR__ . '/ipv4_functions.inc.php';
  90. require_once __DIR__ . '/ipv6_functions.inc.php';
  91. require_once __DIR__ . '/anti_xss.inc.php';
  92.  
  93. if (PHP_SAPI != 'cli') {
  94.         include_once __DIR__ . '/../3p/vts_vnag/vnag_framework.inc.php';
  95. }
  96.  
  97. include_once __DIR__ . '/../3p/vts_fileformats/VtsFileTypeDetect.class.php';
  98.  
  99. // ---
  100.  
  101. spl_autoload_register(function ($class_name) {
  102.         static $class_refs = null;
  103.  
  104.         if (is_null($class_refs)) {
  105.                 $class_refs = array();
  106.  
  107.                 $class_files = array_merge(
  108.                         glob(__DIR__ . '/classes/'.'*'.'.class.php'),
  109.                         glob(__DIR__ . '/../plugins/'.'*'.'/'.'*'.'/'.'*'.'.class.php')
  110.                 );
  111.                 foreach ($class_files as $filename) {
  112.                         $cn = basename($filename, '.class.php');
  113.                         if (!isset($class_refs[$cn])) {
  114.                                 $class_refs[$cn] = $filename;
  115.                         }
  116.                 }
  117.         }
  118.  
  119.         if (isset($class_refs[$class_name])) {
  120.                 require_once $class_refs[$class_name];
  121.         }
  122. });
  123.