Subversion Repositories oidplus

Rev

Rev 1073 | Rev 1090 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
1073 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
2 daniel-mar 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
 
1068 daniel-mar 20
// Before we do ANYTHING, check for PHP version and dependencies!
21
// Do not include anything (except the supplements) yet.
1069 daniel-mar 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.
1071 daniel-mar 24
// More information about the required PHP version:  doc/developer_notes/php7_compat.txt
236 daniel-mar 25
 
1086 daniel-mar 26
define('INSIDE_OIDPLUS', true);
27
 
1068 daniel-mar 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.
1072 daniel-mar 31
        $message = '<p>'.sprintf('OIDplus requires at least PHP version %s!<br>You are currently using version %s',$oidplus_min_version,PHP_VERSION).'</p>';
1071 daniel-mar 32
        oidplus_dependency_panic($message);
236 daniel-mar 33
}
1069 daniel-mar 34
unset($oidplus_min_version);
236 daniel-mar 35
 
1073 daniel-mar 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
 
1069 daniel-mar 41
// Polyfills/Supplements to implement some missing dependencies if possible
597 daniel-mar 42
 
827 daniel-mar 43
include_once __DIR__ . '/../vendor/danielmarschall/php_utils/openssl_supplement.inc.php';
603 daniel-mar 44
include_once __DIR__ . '/../vendor/danielmarschall/php_utils/gmp_supplement.inc.php';
597 daniel-mar 45
include_once __DIR__ . '/../vendor/symfony/polyfill-mbstring/bootstrap.php';
603 daniel-mar 46
include_once __DIR__ . '/../vendor/danielmarschall/php_utils/simplexml_supplement.inc.php';
236 daniel-mar 47
 
1071 daniel-mar 48
// Now check for things like missing PHP libraries (which could not be implemented using the polyfills)
1068 daniel-mar 49
 
463 daniel-mar 50
require_once __DIR__ . '/oidplus_dependency.inc.php';
51
$missing_dependencies = oidplus_get_missing_dependencies();
236 daniel-mar 52
if (count($missing_dependencies) >= 1) {
1069 daniel-mar 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.
1071 daniel-mar 55
        $message  = '<p>'.sprintf('The following PHP extensions need to be installed in order to run OIDplus:').'</p>';
1072 daniel-mar 56
        $message .= '<p><ul>';
236 daniel-mar 57
        foreach ($missing_dependencies as $dependency) {
1071 daniel-mar 58
                $message .= '<li>'.$dependency.'<br><br></li>';
236 daniel-mar 59
        }
1072 daniel-mar 60
        $message .= '</ul></p>';
1071 daniel-mar 61
        oidplus_dependency_panic($message);
236 daniel-mar 62
}
63
unset($missing_dependencies);
64
 
65
// Now we can continue!
66
 
1069 daniel-mar 67
require_once __DIR__ . '/functions.inc.php';
603 daniel-mar 68
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/oid_utils.inc.php';
606 daniel-mar 69
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/xml_utils.inc.php';
603 daniel-mar 70
require_once __DIR__ . '/../vendor/danielmarschall/uuid_mac_utils/includes/uuid_utils.inc.php';
71
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/color_utils.inc.php';
72
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/ipv4_functions.inc.php';
73
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/ipv6_functions.inc.php';
74
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/anti_xss.inc.php';
1069 daniel-mar 75
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/git_utils.inc.php';
76
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/svn_utils.inc.php';
77
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/aid_decoder.inc.php';
78
require_once __DIR__ . '/../vendor/danielmarschall/php_utils/misc_functions.inc.php';
2 daniel-mar 79
 
1073 daniel-mar 80
// Autoloader for all OIDplus base classes and plugins (*.class.php)
2 daniel-mar 81
 
1073 daniel-mar 82
require_once __DIR__ . '/oidplus_autoloader.inc.php';
1071 daniel-mar 83
 
84
// Functions
85
 
86
function oidplus_dependency_panic($message)/*: never*/ {
87
        $title = sprintf('OIDplus startup error');
88
        if (PHP_SAPI === 'cli') {
89
                $message = str_replace('<li>', "- ", $message);
90
                $message = str_replace('<br>', "\n", $message);
91
                $message = str_replace('</p>', "\n\n", $message);
92
                $message = trim(strip_tags($message));
93
                fprintf(STDERR, "$title\n\n$message\n\n");
94
                exit(1);
95
        } else {
96
                @http_response_code(500);
97
                echo '<!DOCTYPE HTML>';
98
                echo '<html><head><title>'.$title.'</title></head><body>';
99
                echo '<h1>'.$title.'</h1>';
1072 daniel-mar 100
                echo $message;
1071 daniel-mar 101
                echo '</body></html>';
102
                die();
103
        }
104
}