This repository was archived by the owner on Feb 27, 2022. It is now read-only.
forked from rposborne/webstatsx
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck.php
More file actions
executable file
·136 lines (124 loc) · 3.54 KB
/
check.php
File metadata and controls
executable file
·136 lines (124 loc) · 3.54 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
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
<?php
//check if we only want to perform a syntax check
if(isset($_GET['c'])){
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'config.php';
echo 'true';
exit();
}
//--- vars to work with
//get the current url
$url = 'http';
if ($_SERVER["HTTPS"] == "on") {$url .= "s";}
$url .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
//possible answers
$y = '<span class="label label-success">Yes</span>'; // yes
$n = '<span class="label label-important">No</span>'; // no
$u = '<span class="label label-info">Couldn\'t be checked</span>'; // unknown
//tables of the stats plugin
$tables = array('block', 'death', 'kill', 'move', 'player');
//vars in the config
$config_vars = array('mysql_host', 'mysql_user', 'mysql_pass', 'mysql_db', 'mysql_encoding', 'prefix', 'show_avatars', 'show_online_state', 'server_ip', 'server_port', 'link_to_map', 'custom_links', 'enable_server_page');
//states of the check
$config_is_fine = false;
$connection_is_fine = false;
$all_tables_okay = true;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Minecraft WEBStatsX check</title>
<link id="bs-css" href="css/bootstrap-spacelab.css" rel="stylesheet">
</head>
<body>
<h1>Quick server check</h1>
<table class="table table-bordered table-striped" style="width:auto;">
<thead>
<tr><th>Test</th><th>Result</th></tr>
</thead>
<tbody>
<tr>
<td>config.php exists?</td>
<td>
<?php
if(file_exists('config.php')){
echo $y;
$config_is_fine = true;
} else {
echo $n;
}
?>
</td>
</tr>
<tr>
<td>No syntax errors in config?</td>
<td>
<?php
$curl = curl_init($url.'?c=1');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
$curl_result = curl_exec($curl);
curl_close($curl);
if($curl_result == 'true'){
echo $y;
} else {
echo $n.', the following error is reported:<br />'.$curl_result.'<br />The test will be stopped at this point, <b>please fix your config.php file!</b>';
$config_is_fine = false;
}
?>
</td>
</tr>
<?php
if($config_is_fine){
include 'config.php';
//check if all vars are set
foreach ($config_vars as $cv) {
echo '<tr><td>Var $'.$cv.' is in config?</td><td>';
if(isset(${$cv})){
echo $y;
} else {
echo $n;
}
echo '</td></tr>';
}
// check the connection
$mysqli = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
echo '<tr><td>Connection to database?</td><td>';
if (mysqli_connect_errno()) {
echo $n.' -> '.mysqli_connect_error();
} else {
echo $y;
$connection_is_fine = true;
}
echo '</td></tr>';
if($connection_is_fine){
foreach ($tables as $table) {
echo '<tr><td>Table '.$prefix.$table.' exists?</td><td>';
$res = mysqli_query($mysqli, 'SELECT 1 FROM '.$prefix.$table);
if($res === false){
$all_tables_okay = false;
echo $n;
} else {
echo $y;
}
echo '</td></tr>';
}
}
}
?>
</tbody>
</table>
<p>If you experience some errors, here are a few common solutions:</p>
<ul>
<li>The table prefix is wrong, try "stats_", "Stats_" or "Stats2_"</li>
<li>There is a missing semicolon in the config.php file</li>
<li>Some new settings have been added to the config during an update, please update your config</li>
</ul>
</body>
</html>