forked from FusionGen/FusionGEN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.php
114 lines (89 loc) · 3.9 KB
/
debug.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
<style type="text/css">
body {
background-color:silver;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#d9534f;
}
h1 {
font-size:24px;
font-weight:normal;
color: #363b3e;
text-transform:uppercase;
font-weight:bolder;
}
div {
padding:10px;
background-color:#5cb85c;
margin-bottom:5px;
color:#292b2c;
border-radius:2px;
font-weight:600;
}
.error {
background-color:#d9534f;
}
.realm {
margin-top:20px;
}
</style>
<h1>Connection Status</h1>
<?php
require 'application/config/database.php';
function connect($hostname, $username, $password, $port, $database = null)
{
$connection = new mysqli($hostname, $username, $password, $database, $port);
if ($connection->connect_errno) {
die("<div class='error'>[DB] mysql connection to CMS database could not be established: " . $connection->error . "</div>");
}
return $connection;
}
function select_db($connection, $database)
{
if (!$connection->select_db($database)) {
die("<div class='error'>[DB] mysql connection to CMS database could not be established: " . $connection->error . "</div>");
}
return true;
}
$cms_database_connection = connect($db['cms']['hostname'], $db['cms']['username'], $db['cms']['password'], $db['cms']['port'] ?? null);
select_db($cms_database_connection, $db['cms']['database']);
echo "<div>[DB] CMS connection successful</div>";
$auth_database_connection = connect($db['account']['hostname'], $db['account']['username'], $db['account']['password'], $db['account']['port'] ?? null);
select_db($auth_database_connection, $db['account']['database']);
echo "<div>[DB] Realmd/logon/auth connection successful</div>";
if ($cms_database_connection) {
select_db($cms_database_connection, $db['cms']['database']);
$realms = $cms_database_connection->query("SELECT * FROM realms") or die("<div class='error'>Realms table: " . $cms_database_connection->error . "</div>");
$row = $realms->fetch_assoc();
if ($realms->num_rows > 0) {
do {
$char = [
'hostname' => $row['override_hostname_char'] ?? $row['hostname'],
'username' => $row['override_username_char'] ?? $row['username'],
'password' => $row['override_password_char'] ?? $row['password'],
'port' => $row['override_port_char'] ?? $row['port'] ?? null,
];
$world = [
'hostname' => $row['override_hostname_world'] ?? $row['hostname'],
'username' => $row['override_username_world'] ?? $row['username'],
'password' => $row['override_password_world'] ?? $row['password'],
'port' => $row['override_port_world'] ?? $row['port'] ?? null,
];
$characters_connection[$row['id']] = connect($char['hostname'], $char['username'], $char['password'], $char['port']);
$world_connection[$row['id']] = connect($world['hostname'], $world['username'], $world['password'], $world['port']);
echo "<div class='realm'>[DB] Realm #" . $row['id'] . " (" . $row['realmName'] . ") connections (world & characters) successful</div>";
select_db($characters_connection[$row['id']], $row['char_database']);
select_db($world_connection[$row['id']], $row['char_database']);
try {
$connect = fsockopen($row['hostname'], $row['realm_port'], $errno, $errstr, 1.5);
echo $connect ? "<div>[SERVER] " . $row['realmName'] . " is online</div>" : "<div class='error'>[SERVER] " . $row['realmName'] . " is offline</div>";
} catch (Exception $error) {
echo "<div class='error'>" . $error->getMessage() . "</div>";
}
} while ($row = $realms->fetch_assoc());
} else {
die('"realms" table is empty');
}
} else {
die('CMS connection not available');
}