This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.php
210 lines (205 loc) · 9.67 KB
/
app.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/* --------------------------------------------------------------------
Chevereto Installer
http://chevereto.com/
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
__ __
____/ / ___ _ _____ _______ / /____
/ __/ _ \/ -_) |/ / -_) __/ -_) __/ _ \
\__/_//_/\__/|___/\__/_/ \__/\__/\___/
--------------------------------------------------------------------- */
declare(strict_types=1);
const APP_NAME = 'Chevereto Installer';
const APP_VERSION = '4.0.0';
const APP_URL = 'https://github.com/chevereto/installer';
const PHP_VERSION_MIN = '8.0';
const PHP_VERSION_RECOMMENDED = '8.0';
const VENDOR = [
'name' => 'Chevereto',
'url' => 'https://chevereto.com',
'apiUrl' => 'https://chevereto.com/api',
'apiLicense' => 'https://chevereto.com/api/license/check',
];
const APPLICATION = [
'name' => 'Chevereto',
'version' => '4',
'license' => 'Paid',
'url' => 'https://chevereto.com',
'zipball' => 'https://chevereto.com/api/download/%tag%',
'folder' => 'chevereto',
'vendor' => VENDOR,
];
const APPLICATION_FULL_NAME = APPLICATION['name'] . ' V' . APPLICATION['version'];
const INSTALLER_FILEPATH = __FILE__;
const INSTALLER_FRONT_BASENAME = 'index.php';
const LOCK_FILEPATH = __DIR__ . '/installer.lock';
$phpSettings = [
'error_reporting' => E_ALL ^ E_NOTICE,
'log_errors' => true,
'display_errors' => true,
'error_log' => __DIR__ . '/installer.error.log',
'time_limit' => 0,
'default_charset' => 'utf-8',
'LC_ALL' => 'en_US.UTF8',
];
define('ERROR_LOG_FILEPATH', $phpSettings['error_log']);
include __DIR__ . '/src/functions.php';
include __DIR__ . '/src/ini-set.php';
include __DIR__ . '/src/setErrorExceptionHandler.php';
include __DIR__ . '/src/Logger.php';
include __DIR__ . '/src/ZipArchiveExt.php';
include __DIR__ . '/src/Requirements.php';
include __DIR__ . '/src/RequirementsCheck.php';
include __DIR__ . '/src/Runtime.php';
include __DIR__ . '/src/JsonResponse.php';
include __DIR__ . '/src/Database.php';
include __DIR__ . '/src/Controller.php';
$logger = new Logger(APP_NAME . ' ' . APP_VERSION);
$requirements = new Requirements(
phpMinimum: PHP_VERSION_MIN,
phpRecommended: PHP_VERSION_RECOMMENDED,
phpExtensions: [
'curl',
'hash',
'json',
'mbstring',
'PDO',
'PDO_MYSQL',
'session',
],
phpClasses: [
'DateTime',
'DirectoryIterator',
'Exception',
'PDO',
'PDOException',
'RegexIterator',
'RecursiveIteratorIterator',
'ZipArchive',
]
);
$themeColor = '#ecf0f1';
$shortcutIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAMAAABOo35HAAAAM1BMVEUjqOD////J6vcxreKR1PDy+v1avuit3/PW7/nk9PtMuOY/s+R2yexow+q75PWf2fKEzu6NmHjuAAAHmklEQVR4XuzAAQ0AAADCIPundu8BCwAAAAAAAAAAAAAAAAAAAAAAAADA2bGbHQdhIAbA45n8ECCB93/aldrLVkVbc9hDFX+PYIHjpB8ND37smxGmtdaM35bdLknsDW9atzcSKeNSDXslj6iuLS9pSW8AmLRkG/jbsCexM+OT56EoM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YwppM+9pA+IYUo45LHLlae8RRBDdd5IQWwywybrtySGSsbAiZHd4nc9ObEoRG46dhejkn4tRpf8JlwlC0dU8vpj07FGdRjgxLg0HTOD9BHKJacVJlT6cNWLSE09SwK0Osi/I04/5s883SzC0SS68f/frzvjY/33nGIe8cfliTO/rOi3HaTw/QRQQgHYBxv2duwAGALAlh5f8WmRUoY/ICuQ06B/2oFjAgAAAIRB9k9thv2wCgAAAAAAAAAAAAAAAAAAAAAAAADgRsdoeIKK/iEAAAAASUVORK5CYII=';
$runtime = new Runtime(settings: $phpSettings, logger: $logger);
$runtime->run();
include __DIR__ . '/src/lock-check.php';
$opts = getopt('a:') ?? null;
if(!empty($_POST)) {
$params = $_POST;
} else if(!empty($opts)) {
$action = $opts['a'];
if(is_array($action)) {
$action = $action[0];
}
$params = ['action' => $action];
switch($action) {
case 'checkLicense':
$opts = getopt('a:l:');
$params['license'] = $opts['l'] ?? null;
break;
case 'checkDatabase':
$opts = getopt('a:h:p:n:u:x:');
$params['host'] = $opts['h'] ?? null;
$params['port'] = $opts['p'] ?? null;
$params['name'] = $opts['n'] ?? null;
$params['user'] = $opts['u'] ?? null;
$params['userPassword'] = $opts['x'] ?? null;
break;
case 'download':
$opts = getopt('a:t:l:');
$params['tag'] = $opts['t'] ?? null;
$params['license'] = $opts['l'] ?? null;
break;
case 'extract':
$opts = getopt('a:p:f:');
$params['workingPath'] = $opts['p'] ?? null;
$params['filePath'] = $opts['f'] ?? null;
break;
case 'createEnv':
$opts = getopt('a:h:p:n:u:x:f:');
$params['host'] = $opts['h'] ?? null;
$params['port'] = $opts['p'] ?? null;
$params['name'] = $opts['n'] ?? null;
$params['user'] = $opts['u'] ?? null;
$params['userPassword'] = $opts['x'] ?? null;
$params['filePath'] = $opts['f'] ?? null;
break;
case 'selfDestruct':
$opts = getopt('a:p:f:');
$params['workingPath'] = $opts['p'] ?? null;
$params['installerFilepath'] = $opts['f'] ?? null;
break;
case 'lock':
break;
}
}
$requirementsCheck = new RequirementsCheck($requirements, $runtime);
if (isset($params)) {
$jsonResponse = new JsonResponse();
if (!empty($requirementsCheck->errors)) {
$errorsPlain = array_map(function ($v) {
return trim(strip_tags($v));
}, $requirementsCheck->errors);
$jsonResponse->setResponse('Missing server requirements', 500);
$jsonResponse->addData('errors', $errorsPlain);
} else {
try {
$controller = new Controller($params, $runtime);
$jsonResponse->setResponse($controller->response, $controller->code);
if (!empty($controller->data)) {
$jsonResponse->setData($controller->data);
}
} catch (Throwable $e) {
error_log($e->getMessage() . '***' . $e->getTraceAsString());
$jsonResponse->setResponse($e->getMessage(), $e->getCode());
$jsonResponse->send(255);
}
}
$jsonResponse->send(0);
} else {
if (isset($_GET['getNginxRules'])) {
require __DIR__ . '/template/nginx.php';
die();
}
if(!empty($opts)) {
die();
}
$pageId = $requirementsCheck->errors ? 'error' : 'install';
$doctitle = APP_NAME;
$css = file_get_contents('html/style.css');
$script = file_get_contents('html/script.js');
$svgLogo = file_get_contents('html/logo.svg');
$jsVars = $runtime;
ob_start();
require __DIR__ . '/template/content.php';
$content = ob_get_clean();
}
?>
<!DOCTYPE html>
<html lang="en" id="<?php echo $pageId; ?>">
<head>
<meta name="generator" content="<?php echo APP_NAME . ' v' . APP_VERSION; ?>">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="theme-color" content="<?php echo $themeColor; ?>">
<title><?php echo $doctitle; ?></title>
<link rel="shortcut icon" type="image/png" href="<?php echo $shortcutIcon; ?>">
<style>
<?php echo $css; ?>
</style>
<script>
const appUrl = <?php echo json_encode(APP_URL); ?>;
const runtime = <?php echo json_encode($jsVars); ?>;
const applicationFullName = <?php echo json_encode(APPLICATION_FULL_NAME); ?>;
</script>
</head>
<body class="body--flex">
<main>
<?php echo $content; ?>
</main>
<script>
<?php echo $script; ?>
</script>
</body>
</html>