This repository was archived by the owner on Feb 27, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 507
/
Copy pathloader.php
194 lines (162 loc) · 6.94 KB
/
loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/* --------------------------------------------------------------------
This file is part of Chevereto Free.
https://chevereto.com/free
(c) Rodolfo Berrios <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
--------------------------------------------------------------------- */
// This file is used to load G and your G APP
// If you need to hook elements to this loader you can add them in loader-hook.php
namespace CHV;
use G;
use Exception;
if (!defined('access') or !access) {
die('This file cannot be directly accessed.');
}
// settings.php workaround
if (!is_readable(__DIR__ . '/settings.php')) {
if (!@fopen(__DIR__ . '/settings.php', 'w')) {
die("Chevereto can't create the app/settings.php file. You must manually create this file.");
}
}
if(getenv('CHEVERETO_SERVICING') == 'docker') {
require_once __DIR__ . '/settings-env.php';
}
// G thing
(file_exists(dirname(__FILE__, 2) . '/lib/G/G.php'))
? require_once dirname(__FILE__, 2) . '/lib/G/G.php'
: die("Can't find lib/G/G.php");
// Require at least X memory to do the thing
$min_memory = '256M';
$memory_limit = ini_get('memory_limit');
$memory_limit_bytes = $memory_limit ? G\get_ini_bytes($memory_limit) : 0;
if ($memory_limit_bytes < G\get_ini_bytes($min_memory)) {
@ini_set('memory_limit', $min_memory); // Careful with that Axe, Eugene
}
// Cipher thing
if ($_SESSION['crypt'] == false) {
$cipher = 'AES-128-CBC';
$ivlen = openssl_cipher_iv_length($cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
$_SESSION['crypt'] = [
'cipher' => $cipher,
'ivlen' => $ivlen,
'iv' => $iv,
];
}
// CHV\DB instance
// CHV\Settings Instance
try {
if (G\settings_has_db_info()) {
DB::getInstance();
}
Settings::getInstance();
} catch (Exception $e) {
if (access !== 'install') {
G\exception_to_error($e);
}
}
if (Settings::get('cdn')) {
define('CHV_ROOT_CDN_URL', Settings::get('cdn_url'));
}
define('G_HTTP_HOST', $_SERVER['HTTP_HOST']);
switch (Settings::get('website_https')) {
default:
case 'auto':
$http_protocol = 'http' . ((((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || $settings['https']) ? 's' : null);
break;
case 'forced':
$http_protocol = 'https';
break;
case 'disabled':
$http_protocol = 'http';
break;
}
define('G_HTTP_PROTOCOL', $http_protocol);
// Set the URLs
define('G_ROOT_URL', G_HTTP_PROTOCOL . '://' . G_HTTP_HOST . G_ROOT_PATH_RELATIVE); // http(s)://www.mysite.com/chevereto/
define('G_ROOT_LIB_URL', G\absolute_to_url(G_ROOT_LIB_PATH)); // not used
define('G_APP_LIB_URL', G\absolute_to_url(G_APP_PATH_LIB));
// Folders definitions
define('CHV_FOLDER_IMAGES', !is_null(Settings::get('chevereto_version_installed')) ? Settings::get('upload_image_path') : 'images');
// CHV APP path definitions
define('CHV_APP_PATH_INSTALL', G_APP_PATH . 'install/');
define('CHV_APP_PATH_CONTENT', G_APP_PATH . 'content/');
define('CHV_APP_PATH_LIB_VENDOR', G_APP_PATH . 'vendor/');
require_once CHV_APP_PATH_LIB_VENDOR . 'autoload.php';
define('CHV_APP_PATH_CONTENT_SYSTEM', CHV_APP_PATH_CONTENT . 'system/');
define('CHV_APP_PATH_CONTENT_LOCKS', CHV_APP_PATH_CONTENT . 'locks/');
// CHV paths
define('CHV_PATH_IMAGES', G_ROOT_PATH . CHV_FOLDER_IMAGES . '/');
define('CHV_PATH_CONTENT', G_ROOT_PATH . 'content/');
define('CHV_PATH_CONTENT_IMAGES_SYSTEM', CHV_PATH_CONTENT . 'images/system/');
define('CHV_PATH_CONTENT_IMAGES_USERS', CHV_PATH_CONTENT . 'images/users/');
define('CHV_PATH_CONTENT_PAGES', CHV_PATH_CONTENT . 'pages/');
define('CHV_PATH_PEAFOWL', G_ROOT_LIB_PATH . 'Peafowl/');
define('CHV_ROOT_URL', G_ROOT_URL);
define('CHV_HTTP_HOST', G_HTTP_HOST);
define('CHV_ROOT_URL_STATIC', defined('CHV_ROOT_CDN_URL') ? CHV_ROOT_CDN_URL : G_ROOT_URL);
// Define the app theme
define('G_APP_PATH_THEMES', G_APP_PATH . 'themes/');
if (!file_exists(G_APP_PATH_THEMES)) {
die("G\: Theme path doesn't exists!");
}
if (isset($settings['theme']) and file_exists(G_APP_PATH_THEMES . $settings['theme'])) {
define('G_APP_PATH_THEME', G_APP_PATH_THEMES . $settings['theme'] . '/');
define('BASE_URL_THEME', G\absolute_to_url(G_APP_PATH_THEME));
}
// Set some hard constants
define('CHV_MAX_INVALID_REQUESTS_PER_DAY', 25);
if (isset($_REQUEST['session_id'])) {
session_id($_REQUEST['session_id']);
}
// Can work with sessions?
if (!@session_start()) {
die("G\: Sessions are not working on this server (session_start).");
}
// Define the app theme
if (!defined('G_APP_PATH_THEME')) {
$theme_path = G_APP_PATH_THEMES;
if (Settings::get('chevereto_version_installed')) {
$theme_path .= Settings::get('theme') . '/';
}
if (is_dir($theme_path)) {
define('G_APP_PATH_THEME', $theme_path);
define('BASE_URL_THEME', G\absolute_to_url(G_APP_PATH_THEME, CHV_ROOT_URL_STATIC));
} else {
die(sprintf("Theme path %s doesn't exists.", G\absolute_to_relative($theme_path)));
}
}
// Set some url paths
define('CHV_URL_PEAFOWL', G\absolute_to_url(CHV_PATH_PEAFOWL, CHV_ROOT_URL_STATIC));
// Always test the current installation
(file_exists(G_APP_PATH_LIB . 'integrity-check.php')) ? require_once G_APP_PATH_LIB . 'integrity-check.php' : die("Can't find app/lib/integrity-check.php");
check_system_integrity();
if (access !== 'install' and Settings::get('chevereto_version_installed')) {
// Error reporting by DB config
if (Settings::get('error_reporting') === false) {
error_reporting(0);
}
// Set the default timezone by DB config
if (G\is_valid_timezone(Settings::get('default_timezone'))) {
date_default_timezone_set(Settings::get('default_timezone'));
}
if (access !== 'cli') {
$upload_max_filesize_mb_db = Settings::get('upload_max_filesize_mb');
$upload_max_filesize_mb_bytes = G\get_bytes($upload_max_filesize_mb_db . 'MB');
// Fix upload_max_filesize_mb if needed
$ini_upload_max_filesize = G\get_ini_bytes(ini_get('upload_max_filesize'));
$ini_post_max_size = ini_get('post_max_size') == 0 ? $ini_upload_max_filesize : G\get_ini_bytes(ini_get('post_max_size'));
Settings::setValue('true_upload_max_filesize', min($ini_upload_max_filesize, $ini_post_max_size));
if (Settings::get('true_upload_max_filesize') < $upload_max_filesize_mb_bytes) {
Settings::update([
'upload_max_filesize_mb' => G\bytes_to_mb(Settings::get('true_upload_max_filesize')),
]);
}
}
}
(file_exists(G_APP_PATH_LIB . 'l10n.php')) ? require_once(G_APP_PATH_LIB . 'l10n.php') : die("Can't find app/lib/l10n.php");
if (access !== 'cli') {
require 'web.php';
}