forked from evolution-cms/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
373 lines (355 loc) · 16.6 KB
/
install.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php
$version = '1.6.36';
error_reporting(0);
ini_set('display_errors', 0);
set_time_limit(0);
ini_set('max_execution_time', 0);
header('Content-Type: text/html; charset=utf-8');
if (extension_loaded('xdebug')) {
ini_set('xdebug.max_nesting_level', 100000);
}
$method = 0;
if (ini_get('allow_url_fopen')) {
$method = 'fopen';
} elseif (extension_loaded('curl')) {
$method = 'curl';
} else {
die('Neither allow_url_fopen or cURL is enabled');
}
$InstallData = array(
'revo3.1.0-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.1.0 pl Traditional (2024-12-18)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.1.0/modx-3.1.0-pl.zip',
'location' => 'setup/index.php'
),
'revo3.0.5-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.5 pl Traditional (2024-04-10)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.5/modx-3.0.5-pl.zip',
'location' => 'setup/index.php'
),
'revo3.0.4-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.4 pl Traditional (2023/10/03)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.4/modx-3.0.4-pl.zip',
'location' => 'setup/index.php'
),
'revo3.0.3-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.3 pl Traditional (2023/01/18)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.3/modx-3.0.3-pl.zip',
'location' => 'setup/index.php'
),
'revo3.0.3-ad' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.3 Advanced (2023/01/18)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.3/modx-3.0.3-pl-advanced.zip',
'location' => 'setup/index.php'
),
'revo3.0.3-sdk' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.3 SDK (2023/01/18)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.3/modx-3.0.3-pl-sdk.zip',
'location' => 'setup/index.php'
),
'revo3.0.2-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.2 pl Traditional (2022/11/17)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.2/modx-3.0.2-pl.zip',
'location' => 'setup/index.php'
),
'revo3.0.2-ad' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.2 Advanced (2022/11/17)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.2/modx-3.0.2-pl-advanced.zip',
'location' => 'setup/index.php'
),
'revo3.0.2-sdk' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.2 SDK (2022/11/17)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.2/modx-3.0.2-pl-sdk.zip',
'location' => 'setup/index.php'
),
'revo3.0.0-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.0 pl Traditional (2022/03/30)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.0/modx-3.0.0-pl.zip',
'location' => 'setup/index.php'
),
'revo3.0.0-ad' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.0 Advanced (2022/03/30)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.0/modx-3.0.0-pl-advanced.zip',
'location' => 'setup/index.php'
),
'revo3.0.0-sdk' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 3.0.0 SDK (2022/03/30)',
'link' => 'https://modx.s3.amazonaws.com/releases/3.0.0/modx-3.0.0-pl-sdk.zip',
'location' => 'setup/index.php'
),
'revo2.8.7-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.7 Traditional (2023/09/28)',
'link' => 'https://modx.s3.amazonaws.com/releases/2.8.7/modx-2.8.7-pl.zip',
'location' => 'setup/index.php'
),
'revo2.8.6-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.6 Traditional (2023/09/28)',
'link' => 'https://modx.s3.amazonaws.com/releases/2.8.6/modx-2.8.6-pl.zip',
'location' => 'setup/index.php'
),
'revo2.8.5-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.5 Traditional (2022/03/07)',
'link' => 'https://modx.s3.amazonaws.com/releases/2.8.5/modx-2.8.5-pl.zip',
'location' => 'setup/index.php'
),
'revo2.8.4-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.4 Traditional (2022/04/28)',
'link' => 'https://modx.s3.amazonaws.com/releases/2.8.4/modx-2.8.4-pl.zip',
'location' => 'setup/index.php'
),
'revo2.8.4-ad' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.4 Advanced (2022/04/28)',
'link' => 'https://modx.s3.amazonaws.com/releases/2.8.4/modx-2.8.4-pl-advanced.zip',
'location' => 'setup/index.php'
),
'revo2.8.4-sdk' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.4 SDK (2022/04/28)',
'link' => 'https://modx.s3.amazonaws.com/releases/2.8.4/modx-2.8.4-pl-sdk.zip',
'location' => 'setup/index.php'
),
'revo2.8.3-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.3 Traditional (2021/05/28)',
'link' => 'https://modx.com/download/direct/modx-2.8.3-pl.zip',
'location' => 'setup/index.php'
),
'revo2.8.3-ad' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.3 Advanced (2021/05/28)',
'link' => 'https://modx.com/download/direct/modx-2.8.3-pl-advanced.zip',
'location' => 'setup/index.php'
),
'revo2.8.3-sdk' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.3 SDK (2021/05/28)',
'link' => 'https://modx.com/download/direct/modx-2.8.3-pl-sdk.zip',
'location' => 'setup/index.php'
),
'revo2.8.0-pl' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.0 Traditional (10.06.2020)',
'link' => 'https://modx.com/download/direct/modx-2.8.0-pl.zip',
'location' => 'setup/index.php'
),
'revo2.8.0-ad' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.0 Advanced (10.06.2020)',
'link' => 'https://modx.com/download/direct/modx-2.8.0-pl-advanced.zip',
'location' => 'setup/index.php'
),
'revo2.8.0-sdk' => array(
'tree' => 'Revolution',
'name' => 'MODX Revolution 2.8.0 SDK (10.06.2020)',
'link' => 'https://modx.com/download/direct/modx-2.8.0-pl-sdk.zip',
'location' => 'setup/index.php'
)
);
class ModxInstaller {
static public function downloadFile($url, $path, $method) {
$newfname = $path;
$newf = null;
$file = null;
if ($method == 'fopen') {
try {
$file = fopen($url, "rb");
if ($file) {
$newf = fopen($newfname, "wb");
if ($newf) {
while (!feof($file)) {
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
}
}
}
} catch (Exception $e) {
return 'ERROR:Download ' . $e->getMessage();
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
return true;
} elseif ($method == 'curl') {
$newf = fopen($path, "wb");
if ($newf) {
$ch = curl_init(str_replace(" ", "%20", $url));
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $newf);
$safeMode = @ini_get('safe_mode');
$openBasedir = @ini_get('open_basedir');
if (empty($safeMode) && empty($openBasedir)) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$rch = curl_copy_handle($ch);
$newurl = $url;
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/i', $header, $matches);
$newurl = trim(array_pop($matches));
}
curl_close($rch);
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
$data = curl_exec($ch);
curl_close($ch);
} else {
return ("Cannot create target file.");
}
} else {
return 'Invalid method in call to downloadFile()';
}
return true;
}
static public function removeFolder($path) {
$dir = realpath($path);
if (!is_dir($dir)) {
return;
}
$it = new RecursiveDirectoryIterator($dir);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
continue;
}
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
rmdir($dir);
}
static public function copyFolder($src, $dest) {
$path = realpath($src);
$dest = realpath($dest);
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
$startsAt = substr(dirname($name), strlen($path));
self::mmkDir($dest . $startsAt);
if ($object->isDir()) {
self::mmkDir($dest . substr($name, strlen($path)));
}
if (is_writable($dest . $startsAt) and $object->isFile()) {
copy((string) $name, $dest . $startsAt . DIRECTORY_SEPARATOR . basename($name));
}
}
}
static public function mmkDir($folder, $perm = 0755) {
if (!is_dir($folder)) {
mkdir($folder, $perm);
}
}
}
if (!empty($_GET['modx']) && is_scalar($_GET['modx']) && isset($InstallData[$_GET['modx']])) {
$rowInstall = $InstallData[$_GET['modx']];
//run unzip and install
$success = ModxInstaller::downloadFile($rowInstall['link'], "modx.zip", $method);
if ($success !== true) {
die($success);
}
$zip = new ZipArchive;
$success = $zip->open(dirname(__FILE__) . "/modx.zip");
if ($success !== true) {
die('Failed to open zip file');
}
if (! is_dir(dirname(__FILE__) . '/temp')) {
ModxInstaller::mmkDir(dirname(__FILE__) . '/temp');
}
$success = $zip->extractTo(dirname(__FILE__) . '/temp/');
if ($success !== true) {
$zip->close();
die('Failed to extract from zip file');
}
$zip->close();
unlink(dirname(__FILE__) . '/modx.zip');
if ($handle = opendir(dirname(__FILE__) . '/temp')) {
while (false !== ($name = readdir($handle))) {
if ($name != "." && $name != "..") {
$dir = $name;
}
}
closedir($handle);
}
ModxInstaller::copyFolder(dirname(__FILE__) . '/temp/' . $dir, dirname(__FILE__) . '/');
ModxInstaller::removeFolder(dirname(__FILE__) . '/temp');
unlink(basename(__FILE__));
header('Location: ' . $rowInstall['location']);
} else {
$ItemGrid = array();
foreach ($InstallData as $ver => $item) {
$ItemGrid[$item['tree']][$ver] = $item;
}
//@TODO : add check installer version
echo '
<!DOCTYPE html>
<html>
<head>
<title>MODX Installer v' . $version . '</title>
<meta charset="utf-8">
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=PT+Serif:400,700&subset=latin,cyrillic);article,aside,audio,b,body,canvas,dd,details,div,dl,dt,em,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,img,label,li,mark,menu,nav,ol,p,section,span,strong,summary,table,tbody,td,tfoot,th,thead,time,tr,u,ul,video{margin:0;padding:0;border:0;outline:0;vertical-align:baseline;background:0 0;font-size:100%}a{margin:0;padding:0;font-size:100%;vertical-align:baseline;background:0 0}table{border-collapse:collapse;border-spacing:0}td,td img{vertical-align:top}button,input,select,textarea{margin:0;font-size:100%}input[type=password],input[type=text],textarea{padding:0}input[type=checkbox]{vertical-align:bottom}input[type=radio]{vertical-align:text-bottom}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}html{overflow-y:scroll}body{color:#111;text-align:left;font:12px Verdana,"Geneva CY","DejaVu Sans",sans-serif}button,input,select,textarea{font-family:Verdana,"Geneva CY","DejaVu Sans",sans-serif}a,a:active,a:focus,a:hover,a:visited,button,input[type=button],input[type=submit],label{cursor:pointer}::selection{background:#84d5e8;color:#fff;text-shadow:none}html{position:relative;background:#f8f8f8 url(http://installer.evolution-cms.com/img/base.png)}body{background:0 0;font-size:14px;line-height:22px;font-family:"Helvetica Neue",helvetica,arial,sans-serif;text-shadow:0 1px 0 #fff}a{color:#0f7096}.button,button{color:#fff;display:inline-block;padding:15px;font-size:20px;text-decoration:none;border:5px solid #fff;border-radius:8px;background-color:#67a749;background-image:linear-gradient(to top,#67a749 0,#67a749 27.76%,#a1c755 100%);text-shadow:0 0 2px rgba(0,0,0,.64)}a.button{padding:5px 15px}h1,h2,h3,h4,h5{font-family:"PT Serif",helvetica,arial,sans-serif;line-height:28px}h1{font-size:26px}h2{font-size:22px}h3{font-size:18px}h4{font-size:16px}h5{font-size:14px}.header{-moz-box-sizing: border-box;float:left;width:100%;box-sizing:border-box;background:#fff;background:linear-gradient(to bottom,#fff,#f2f2f2);padding:20px;border-bottom:1px solid #fff}.header img{float:left;width:180px;margin:0 5px 0 0}.header h1.main-heading{color:#137899;font-size:32px;line-height:40px}.header-button-wrapper{float:right}.main-heading>span{display:none}.main-heading>sup{color:#ccc;font-weight:400}.content{float:left;padding:30px}.content h2{margin:0;line-height:20px}.content form{margin:10px 0 50px}.content form .column{float:left;box-sizing:border-box;width:500px;margin:20px 0}.column h3{display:inline-block;padding:0 0 5px;margin:0 0 20px;border-bottom:2px solid #000}.column label{float:left;width:100%;clear:both;padding:3px 0}form button{float:left;width:200px;clear:both}label>span{border-bottom:1px dotted #555}label>input{margin:0 5px 0 0}.footer{position:absolute;bottom:20px;right:20px;font-size:10px;color:#ccc}.footer a{color:#aaa}
</style>
</head>
<body>
<div class="header">
<h1 class="main-heading"><span>MODX</span>MODX Installer <sup>v' . $version . '</sup> </h1>
<div class="header-button-wrapper">
<!--<a href="#" class="button">New version</a> -->
<a href="https://github.com/sottwell/installer" target="_blank" class="button">GitHub</a>
</div>
</div>
</div>
<div class="content">';
echo '<h2>Choose MODX version for Install</h2>
<form>';
foreach ($ItemGrid as $tree => $item) {
echo '<div class="column">
<h3>' . strtoupper($tree) . '</h3>';
foreach ($item as $version => $itemInfo) {
echo '<label><input type="radio" name="modx" value="' . $version . '"> <span>' . $itemInfo['name'] . '</span></label><br>';
}
echo '</div>';
}
if ($method) {
echo "<h2> Using " . $method . "</h2>";
echo '<br><button>Install →</button>';
} else {
echo '<h2>Cannot download the files - allow_url_fopen is not enabled on this server.</h2>';
}
echo '</form>
<div class="footer">
<p>Created by <a href="http://ga-alex.com" target="_blank" title="">Bumkaka</a> & <a href="http://dmi3yy.com" target="_blank" title="">Dmi3yy</a></p>
<p>Modified for Revolution only and update maintained by <a href="http://sottwell.com" target="_blank" title="">sottwell</a></p>
<p>Designed by <a href="http://a-sharapov.com" target="_blank" title="">Sharapov</a></p>
</div>
</body>
</html>
';
}
?>