-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathadmin.php
287 lines (262 loc) · 7.98 KB
/
admin.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
<?php
// This page is not secure.
// It should not be deployed in a production environment.
require_once __DIR__.'/_phoenix.php';
require_once $settings['onces'].'once.sanitize.admin.php';
require_once $settings['functions'].'function.mysqli.drop.table.php';
require_once $settings['functions'].'function.mysqli.create.database.php';
// Tables Exist
$tables = array('peers', 'tasks', 'torrents');
$actual = 0;
foreach ( $tables as $table ) {
$sql = 'SELECT TABLE_NAME '.
'FROM `information_schema`.`TABLES` '.
'WHERE TABLE_SCHEMA = \''.$settings['db_name'].'\' '.
'AND TABLE_NAME = \''.$settings['db_prefix'].$table.'\';';
$result = mysqli_query($connection, $sql);
$count = mysqli_num_rows($result);
if ( !$count ) {
} else {
$actual += $count;
}
}
if ( count($tables) == $actual ) {
$tables_installed = true;
} else {
$tables_installed = false;
}
if (
$Process == 'setup' &&
(
$settings['db_reset'] ||
!$tables_installed
)
) {
// MySQL Setup
$success = true;
if ( $tables_installed ) {
if (
!drop_table($connection, $settings, 'peers') ||
!drop_table($connection, $settings, 'tasks') ||
!drop_table($connection, $settings, 'torrents')
) {
$success = false;
}
}
// Create the databases.
if ( !create_database($connection, $settings) ) {
$success = false;
}
if ( $success ) {
$Message = 'Your MySQL Tracker Database has been setup.';
require_once $settings['functions'].'function.task.log.php';
$result = task_log($connection, $settings, 'install', $time);
$tables_installed = true;
} else {
$Message = 'Could not setup the MySQL Database.';
}
} else if ( $Process == 'clean' ) {
require_once $settings['functions'].'function.task.clean.php';
if ( task_clean($connection, $settings, $time) ) {
$Message = 'The peers list has been cleaned.';
} else {
$Message = 'Could not clean the peers list.';
}
} else if ( $Process == 'optimize' ) {
require_once $settings['functions'].'function.task.optimize.php';
if ( task_optimize($connection, $settings, $time) ) {
$Message = 'Your MySQL Tracker Database has been optimized.';
} else {
$Message = 'Could not optimize the MySQL Database.';
}
}
?><!DOCTYPE html>
<html lang="en">
<head>
<title>Phoenix Diagnostics and Utilities</title>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/gh/jquery/jquery@3/dist/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.mysql').submit(function() {
$('input[type="submit"]').attr('disabled','disabled');
});
});
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/combine/gh/eustasy/Colors.css@1/colors.min.css,gh/necolas/normalize.css@8/normalize.min.css">
<style>
body {
margin: 0 auto;
max-width: 600px;
padding: 1% 10%;
text-align: center;
width: 80%;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: normal;
}
a {
text-decoration: none;
}
input {
border: none;
}
input:disabled {
background: #ecf0f1;
color: #7f8c8d;
}
.box {
padding: 1em;
}
.button {
border-radius: .2em;
padding: .3em;
}
p .button {
margin-top: -.3em;
}
.button.p-like {
margin: 0.7em 0;
}
.clear {
clear: both;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
.text-center {
text-align: center;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
</style>
</head>
<body>
<?php
echo '
<h1>Compatibility Check</h1>
<p class="text-center color-9">'.$settings['phoenix_version'].'</p>';
// PHP Version
$php_version = PHP_VERSION;
// >= 5.3
if ( version_compare(PHP_VERSION, '5.5.0', '>=') ) {
echo '
<p class="box background-green-sea color-clouds">Your PHP version is >= 5.5</td>
<p class="color-asbestos">PHP Version: '.$php_version.'</p>';
$php_compat = true;
// >= 5.0
} else if ( version_compare(PHP_VERSION, '5.0.0', '>=') ) {
echo '
<p class="box background-sun-flower color-midnight-blue">Your PHP version is >= 5.0, but < 5.5.
We recommend updating to PHP >= 5.5</p]>
<p class="color-asbestos">PHP Version: '.$php_version.'</p>';
$php_compat = 'Partial';
// < 5
} else {
echo '
<p class="box background-pomegranate color-clouds">Phoenix is unable to run. Your PHP version is < 5.0</td>
<p class="color-asbestos">PHP Version: '.$php_version.'</p>';
$php_compat = false;
}
// No MySQL
if ( !class_exists('mysqli') ) {
echo '
<p class="box background-pomegranate color-clouds">Your server does not support MySQL.</td>';
$mysql_compat = false;
// Yes MySQL
} else {
// Version
$mysql_version = mysqli_get_client_info();
$mysql_version = trim(substr($mysql_version, 0, strpos($mysql_version, '-')), 'mysqlnd ');
echo '
<p class="box background-green-sea color-clouds">Your server supports MySQL.</td>
<p class="color-asbestos">MySQL Version: '.$mysql_version.'</p>';
$mysql_compat = true;
if ( $tables_installed ) {
$table_size_query = 'SELECT `data_length` AS `Data`, `index_length` AS `Indexes`, SUM( `data_length` + `index_length` ) AS `Total`, SUM( `data_free` ) AS `Free` FROM `information_schema`.`TABLES` WHERE `table_schema` = \''.$settings['db_name'].'\' AND `table_name` = \'__TABLE_NAME__\' GROUP BY `table_schema`;';
foreach ( $tables as $table ) {
$size = str_replace('__TABLE_NAME__', $settings['db_prefix'].$table, $table_size_query);
$size = mysqli_query($connection, $size, MYSQLI_STORE_RESULT);
if ( $size ) {
$table_size[$table] = mysqli_fetch_assoc($size);
}
}
$database_size = 'SELECT `data_length` AS `Data`, `index_length` AS `Indexes`, SUM( `data_length` + `index_length` ) AS `Total`, SUM( `data_free` ) AS `Free` FROM `information_schema`.`TABLES` WHERE `table_schema` = \''.$settings['db_name'].'\' GROUP BY `table_schema`;';
$database_size = mysqli_query($connection, $database_size, MYSQLI_STORE_RESULT);
if ( $database_size ) {
$database_size = mysqli_fetch_assoc($database_size);
}
echo '
<p class="box background-green-sea color-clouds">All your tables are installed.';
if ( $database_size ) {
echo ' Their current size is '.number_format($database_size['Total']).' bytes.';
}
echo '</td>';
} else {
echo '
<p class="box background-pomegranate color-clouds">Some or all of your tables are not installed.</p>';
}
// Database Utilities
echo '
<br>
<h1>Utilities</h1>';
// $Messages
if ( isset($Message) ) {
echo '
<div class="box background-wisteria color-clouds">
<h3>'.$Message.'</div></h3>
</div>';
}
if (
$settings['db_reset'] ||
!$tables_installed
) {
echo '
<form class="mysql" action="" method="POST">
<p class="box background-pomegranate color-clouds">You should set
<code>$settings[\'db_reset\']</code>
to false to disable resets,<br>
or delete <code>admin.php</code> when you\'re up and running.</p>
<p class="float-left text-left">Install, Upgrade, and Reset</p>
<input type="hidden" name="process" value="setup">
<input class="button background-belize-hole color-clouds float-right" type="submit" name="submit" value="Setup">
<div class="clear"></div>
</form>';
} else {
echo '
<p class="text-left color-asbestos">Install, Upgrade, and Reset
<span class="button background-clouds float-right">Disabled</span></p>
<div class="clear"></div>';
}
if ( $tables_installed ) {
echo '
<form class="mysql" action="" method="POST">
<p class="float-left text-left">Clean out redundant peers</p>
<input type="hidden" name="process" value="clean">
<input class="button background-belize-hole color-clouds float-right p-like" type="submit" name="submit" value="Clean">
<div class="clear"></div>
</form>';
echo '
<form class="mysql" action="" method="POST">
<p class="float-left text-left">Check, Analyze, Repair, and Optimize</p>
<input type="hidden" name="process" value="optimize">
<input class="button background-belize-hole color-clouds float-right p-like" type="submit" name="submit" value="Optimize">
<div class="clear"></div>
</form>';
}
}
echo '
</body>
</html>';