-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate.php
More file actions
90 lines (83 loc) · 2.61 KB
/
update.php
File metadata and controls
90 lines (83 loc) · 2.61 KB
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
<?php
/**
* update.php
* Created with PhpStorm
* User: Robin | Juraji
* Date: 12 okt 2015
* Time: 12:48
*/
define('BASEPATH', realpath(dirname(__FILE__)));
require_once(BASEPATH . '/app/php/classes/Configuration.class.php');
$config = new Configuration();
$updatesDir = array_diff(scandir(BASEPATH . '/updates'), [
'.',
'..',
'current_version.txt',
'roadmap.txt',
]);
$updateInstalledTo = -1;
$installedUpdates = '';
$notification = [];
$updateNotes = [];
if (touch(BASEPATH . '/app/content/vars/current_version.txt')) {
$currentUpdate = @file_get_contents(BASEPATH . '/app/content/vars/current_version.txt');
} else {
throw new Exception('Could not read or create current version file! Make sure your webserver has write access to the "./app/content/vars" folder');
}
foreach ($updatesDir as $updateScript) {
if (preg_match('/unreleased/i', $updateScript)) {
continue;
}
$updateNo = floatval(str_replace('.php', '', $updateScript));
if ($updateNo > floatval($currentUpdate)) {
require_once(BASEPATH . '/updates/' . $updateScript);
$installedUpdates .= '<li>Installed update: ' . $updateNo . '</li>';
$updateInstalledTo = $updateNo;
}
}
if ($updateInstalledTo > -1) {
@file_put_contents(BASEPATH . '/app/content/vars/current_version.txt', $updateInstalledTo);
$notification[] = 'Updates Installed!';
$notification[] = 'You are now on version ' . $updateInstalledTo . '!';
} else {
$notification[] = 'No updates available.';
$notification[] = 'You are on version ' . $currentUpdate . '!';
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link href="/app/css/<?= (array_key_exists('theme', $config->paths) ? $config->paths['theme'] : 'style_dark') ?>.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page-wrapper">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">PhantomBot Control Panel <br/><span
class="panel-version text-muted">version <?= ($config->version ? $config->version : 'new install') ?></span></a>
</div>
</div>
</nav>
<div class="panel panel-primary">
<div class="panel-heading">
<h4 class="panel-title"><?= $notification[0] ?></span></h4>
</div>
<div class="panel-body">
<div class="update-info">
<ul class="list-unstyled">
<?= $installedUpdates ?>
</ul>
<p><?=join('<br /><br />', $updateNotes)?></p>
<?= $notification[1] ?>
<p>
Proceed to <a href="/">login</a>!
</p>
</div>
</div>
</div>
</div>
</body>
</html>