-
Notifications
You must be signed in to change notification settings - Fork 0
/
database-offline.php
executable file
·220 lines (195 loc) · 8.77 KB
/
database-offline.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
<?php
/* ------------------------------------------------------
* INCLUDE CLASS DEFINITION PRIOR TO INITIALIZING
* ------------------------------------------------------ */
require_once 'classes/MySQLHandler.php';
/* Read ldap configuration file and populate class parameters */
require_once(__SITE_ROOT__ . '/includes/ldap-config.inc');
$lErrorMessage = "";
$lDatabaseHostResolvedIP = "";
$lDatabasePortScanMessage = "";
$lDatabasePingResult = "";
$lDatabaseTracerouteResult = "";
$lDatabaseHost = MySQLHandler::$mMySQLDatabaseHost;
$lDatabaseUsername = MySQLHandler::$mMySQLDatabaseUsername;
$lDatabasePassword = MySQLHandler::$mMySQLDatabasePassword;
$lDatabaseName = MySQLHandler::$mMySQLDatabaseName;
$lDatabasePort = MySQLHandler::$mMySQLDatabasePort;
$lLDAPHostResolvedIP = "";
$lLDAPPortScanMessage = "";
$lLDAPPingResult = "";
$lLDAPTracerouteResult = "";
$lLDAPHost = LDAP_HOST;
$lLDAPPort = LDAP_PORT;
$lLDAPBaseDN = LDAP_BASE_DN;
$lLDAPBindDN = LDAP_BIND_DN;
$lLDAPBindPassword = LDAP_BIND_PASSWORD;
$lSocketErrorCode = "";
$lSocketErrorMessage = "";
try{
$lDatabaseHostResolvedIP = gethostbyname($lDatabaseHost);
}catch (Exception $e){
// do nothing
} //end try
try{
$lDatabasePingResult = shell_exec("ping -c 1 $lDatabaseHost");
}catch (Exception $e){
// do nothing
} //end try
try{
$lDatabaseTracerouteResult = shell_exec("traceroute --max-hops=2 --wait=2 $lDatabaseHost 2>&1");
}catch (Exception $e){
// do nothing
} //end try
try{
$lTracerouteTCPResult = shell_exec("traceroute --max-hops=2 --wait=2 --tcp -p $lDatabasePort $lDatabaseHost 2>&1");
}catch (Exception $e){
// do nothing
} //end try
try{
$lWaitTimeoutInSeconds = 2;
if($fp = fsockopen($lDatabaseHost,$lDatabasePort,$lSocketErrorCode,$lSocketErrorMessage,$lWaitTimeoutInSeconds)){
$lDatabasePortScanMessage = "The database is reachable. Connected to database host " . $lDatabaseHost . " on port " . $lDatabasePort;
} else {
$lDatabasePortScanMessage = "Cound not connect to database host $lDatabaseHost on port $lDatabasePort. The hostname or port may be incorrect, the server offline, the service is down, or a firewall is blocking the connection. $lSocketErrorCode - $lSocketErrorMessage";
} // end if
if (is_resource($fp)){
fclose($fp);
} // end if
}catch (Exception $e){
// do nothing
} //end try
try {
MySQLHandler::databaseAvailable();
} catch (Exception $e) {
$lErrorMessage = $e->getMessage();
}// end try MySQLHandler::databaseAvailable()
try{
$lLDAPHostResolvedIP = gethostbyname($lLDAPHost);
}catch (Exception $e){
// do nothing
} //end try
try{
$lLDAPPingResult = shell_exec("ping -c 1 $lLDAPHost");
}catch (Exception $e){
// do nothing
} //end try
try{
$lLDAPTracerouteResult = shell_exec("traceroute --max-hops=2 --wait=2 $lLDAPHost 2>&1");
}catch (Exception $e){
// do nothing
} //end try
try{
$lTracerouteTCPResult = shell_exec("traceroute --max-hops=2 --wait=2 --tcp -p $lLDAPPort $lLDAPHost 2>&1");
}catch (Exception $e){
// do nothing
} //end try
try{
$lWaitTimeoutInSeconds = 2;
if($fp = fsockopen($lLDAPHost,$lLDAPPort,$lSocketErrorCode,$lSocketErrorMessage,$lWaitTimeoutInSeconds)){
$lLDAPPortScanMessage = "The LDAP service is reachable. Connected to LDAP service host " . $lLDAPHost . " on port " . $lLDAPPort;
} else {
$lLDAPPortScanMessage = "Cound not connect to LDAP service host $lLDAPHost on port $lLDAPPort. The hostname or port may be incorrect, the server offline, the service is down, or a firewall is blocking the connection. $lSocketErrorCode - $lSocketErrorMessage";
} // end if
if (is_resource($fp)){
fclose($fp);
} // end if
}catch (Exception $e){
// do nothing
} //end try
if (session_status() == PHP_SESSION_NONE){
session_start();
}// end if
$lSubmitButtonClicked = isSet($_REQUEST["database-offline-php-submit-button"]);
if ($lSubmitButtonClicked) {
$_SESSION["UserOKWithDatabaseFailure"] = "TRUE";
header("Location: index.php", true, 302);
}//end if
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="./styles/global-styles.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Database Offline</title>
</head>
<div> </div>
<div class="page-title">The database server at
<span class="label" style="color: #cc3333">
<?php echo MySQLHandler::$mMySQLDatabaseHost ?>
</span>
appears to be offline.
</div>
<table>
<tr>
<td>
<ol>
<li><a class="label" href="set-up-database.php">Click here</a> to attempt to setup the database. Sometimes this works.</li>
<li>Be sure the username and password to MySQL is the same as configured in includes/database-config.inc</li>
<li>Be aware that MySQL disables password authentication for root user upon installation or update in some systems. This may happen even for a minor update. Please check the username and password to MySQL is the same as configured in includes/database-config.inc</li>
<li>A <a style="font-weight: bold" href="https://www.youtube.com/watch?v=sG5Z4JqhRx8" target="_blank">video is available</a> to help reset MySQL root password</li>
<li>Check the error message below for more hints</li>
<li>If you think this message is a false-positive, you can opt-out of these warnings below</li>
</ol>
</td>
</tr>
<tr>
<td style="width:700px;">
<div class="warning-message">Database Diagnostics Information</div>
<div> </div>
<div><span class="label">Database Error message: </span><?php echo $lErrorMessage; ?></div>
<div> </div>
<div><span class="label">Database host: </span><?php echo $lDatabaseHost; ?></div>
<div><span class="label">Database post: </span><?php echo $lDatabasePort; ?></div>
<div><span class="label">Database username: </span><?php echo $lDatabaseUsername; ?></div>
<div><span class="label">Database password: </span><?php echo $lDatabasePassword; ?></div>
<div><span class="label">Database name: </span><?php echo $lDatabaseName; ?></div>
<div> </div>
<div><span class="label">IP resolved from database hostname: </span><?php echo $lDatabaseHostResolvedIP; ?></div>
<div> </div>
<div><span class="label">Ping database results: </span><pre><?php echo $lDatabasePingResult; ?></pre></div>
<div><span class="label">Traceroute database results: </span><pre><?php echo $lDatabaseTracerouteResult; ?></pre></div>
<div><span class="label">Port scan database results: </span><?php echo $lDatabasePortScanMessage; ?></div>
</td>
</tr>
<tr>
<td style="width:700px;">
<div> </div>
<div class="warning-message">LDAP Diagnostics Information</div>
<div> </div>
<div><span class="label">LDAP host: </span><?php echo $lLDAPHost; ?></div>
<div><span class="label">LDAP post: </span><?php echo $lLDAPPort; ?></div>
<div><span class="label">LDAP username: </span><?php echo $lLDAPBindDN; ?></div>
<div><span class="label">LDAP password: </span><?php echo $lLDAPBindPassword; ?></div>
<div><span class="label">LDAP base DN: </span><?php echo $lLDAPBaseDN; ?></div>
<div> </div>
<div><span class="label">IP resolved from LDAP service hostname: </span><?php echo $lLDAPHostResolvedIP; ?></div>
<div> </div>
<div><span class="label">Ping LDAP service results: </span><pre><?php echo $lLDAPPingResult; ?></pre></div>
<div><span class="label">Traceroute LDAP service results: </span><pre><?php echo $lLDAPTracerouteResult; ?></pre></div>
<div><span class="label">Port scan LDAP service results: </span><?php echo $lLDAPPortScanMessage; ?></div>
</td>
</tr>
</table>
<div>
<form action="database-offline.php"
method="post"
enctype="application/x-www-form-urlencoded"
id="idDatabaseOffline">
<table>
<tr><td> </td></tr>
<tr>
<td colspan="2" class="form-header">Opt out of database warnings</td>
</tr>
<tr><td></td></tr>
<tr>
<td class="label">You can opt out of database connection warnings for the remainder of this session</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
<input name="database-offline-php-submit-button" class="button" type="submit" value="Opt Out" />
</td>
</tr>
</table>
</form>
</div>