Subversion Repositories oidplus

Rev

Rev 1248 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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 PHP version and dependencies!
  21. // Do not include anything (except the supplements) yet.
  22. // Keep this file clean from fancy syntax sugar, otherwise old PHP versions
  23. // will get a compilation error and then they won't see our friendly error message.
  24. // More information about the required PHP version:  doc/developer_notes/php7_compat.txt
  25.  
  26. const INSIDE_OIDPLUS = true;
  27.  
  28. if (version_compare(PHP_VERSION, $oidplus_min_version='7.0.0') < 0) {
  29.         // Note: These strings are not translated, because in case of an incompatible
  30.         // PHP version, we are not able to load language plugins at all.
  31.         $message = '<p>'.sprintf('OIDplus requires at least PHP version %s!<br>You are currently using version %s',$oidplus_min_version,PHP_VERSION).'</p>';
  32.         oidplus_dependency_panic($message);
  33. }
  34. unset($oidplus_min_version);
  35.  
  36. // We need the autoloader now, otherwise openssl_supplement won't work (it needs to check if phpseclib is existing)
  37. // Autoloader of "vendor/" (PSR-4 *.php)
  38.  
  39. require_once __DIR__ . '/../vendor/autoload.php';
  40.  
  41. // Polyfills/Supplements to implement some missing dependencies if possible
  42.  
  43. include_once __DIR__ . '/../vendor/danielmarschall/php_utils/openssl_supplement.inc.php';
  44. include_once __DIR__ . '/../vendor/danielmarschall/php_utils/gmp_supplement.inc.php';
  45. include_once __DIR__ . '/../vendor/symfony/polyfill-mbstring/bootstrap.php';
  46. include_once __DIR__ . '/../vendor/danielmarschall/php_utils/simplexml_supplement.inc.php';
  47.  
  48. // Now check for things like missing PHP libraries (which could not be implemented using the polyfills)
  49.  
  50. require_once __DIR__ . '/oidplus_dependency.inc.php';
  51. $missing_dependencies = oidplus_get_missing_dependencies();
  52. if (count($missing_dependencies) >= 1) {
  53.         // Note that there are no translations _L() because if we get an error at this
  54.         // stage, then we have no language plugins anyways.
  55.         $message  = '<p>The following PHP extensions need to be installed in order to run OIDplus:</p>';
  56.         $message .= '<p><ul>';
  57.         foreach ($missing_dependencies as $dependency) {
  58.                 $message .= '<li>'.$dependency.'<br><br></li>';
  59.         }
  60.         $message .= '</ul></p>';
  61.         oidplus_dependency_panic($message);
  62. }
  63. unset($missing_dependencies);
  64.  
  65. // Now we can continue!
  66.  
  67. require_once __DIR__ . '/functions.inc.php';
  68. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/oid_utils.inc.php';
  69. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/xml_utils.inc.php';
  70. require_once __DIR__ . '/../vendor/danielmarschall/uuid_mac_utils/includes/uuid_utils.inc.php';
  71. require_once __DIR__ . '/../vendor/danielmarschall/uuid_mac_utils/includes/mac_utils.inc.php';
  72. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/color_utils.inc.php';
  73. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/ipv4_functions.inc.php';
  74. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/ipv6_functions.inc.php';
  75. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/anti_xss.inc.php';
  76. //require_once __DIR__ . '/../vendor/danielmarschall/php_utils/git_utils.inc.php';
  77. //require_once __DIR__ . '/../vendor/danielmarschall/php_utils/svn_utils.inc.php';
  78. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/aid_decoder.inc.php';
  79. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/misc_functions.inc.php';
  80. require_once __DIR__ . '/../vendor/danielmarschall/php_utils/vts_crypt.inc.php';
  81.  
  82. // Autoloader for all OIDplus base classes and plugins (*.class.php)
  83.  
  84. require_once __DIR__ . '/oidplus_autoloader.inc.php';
  85.  
  86. // Functions
  87.  
  88. /**
  89.  * @param string $message
  90.  * @return void
  91.  */
  92. function oidplus_dependency_panic(/*string*/ $message)/*: never*/ {
  93.         $title = 'OIDplus startup error';
  94.         if (PHP_SAPI === 'cli') {
  95.                 $message = str_replace('<li>', "- ", $message);
  96.                 $message = str_replace('<br>', "\n", $message);
  97.                 $message = str_replace('</p>', "\n\n", $message);
  98.                 $message = trim(strip_tags($message));
  99.                 fprintf(STDERR, "$title\n\n$message\n\n");
  100.                 exit(1);
  101.         } else {
  102.                 @http_response_code(500);
  103.                 echo '<!DOCTYPE HTML>';
  104.                 echo '<html><head><title>'.$title.'</title></head><body>';
  105.                 echo '<h1>'.$title.'</h1>';
  106.                 echo $message;
  107.                 echo '</body></html>';
  108.                 die();
  109.         }
  110. }
  111.