-
Notifications
You must be signed in to change notification settings - Fork 347
/
diagnostic.php
296 lines (252 loc) · 8.45 KB
/
diagnostic.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
288
289
290
291
292
293
294
295
296
<?php
/**
* Diagnostic
*
* Check for missing PHP extensions, files or misconfigurations
*
* TRANSLATION: do NOT translate these error messages since they need to stay in English for technical support.
*
* @package RosarioSIS
*/
$error = [];
$warning = [];
// FJ check PHP version.
if ( version_compare( PHP_VERSION, '5.5.9' ) == -1 )
{
$error[] = 'RosarioSIS requires PHP 5.5.9 to run, your version is : ' . PHP_VERSION;
}
// FJ verify PHP extensions and php.ini.
$inipath = php_ini_loaded_file();
if ( $inipath )
{
$inipath = ' Loaded php.ini: ' . $inipath;
}
else
$inipath = ' Note: No php.ini file is loaded!';
if ( count( $error ) )
{
echo _ErrorMessage( $error, 'fatal' );
}
if ( ! file_exists( './Warehouse.php' ) )
{
$error[] = 'The diagnostic.php file needs to be in the RosarioSIS directory to be able to run. Please move it there, and run it again.';
}
elseif ( ! include_once './config.inc.php' )
{
$error[] = 'config.inc.php file not found. Please read the installation directions.';
}
else
{
if ( ! @opendir( $RosarioPath . 'functions' ) )
{
$error[] = 'The value for $RosarioPath in the config.inc.php file is not correct or else the functions directory does not have the correct permissions to be read by the webserver. Make sure $RosarioPath points to the RosarioSIS installation directory and that it is readable by the `' . $_SERVER['USER'] . '` user.';
}
if ( empty( $DatabaseType ) )
{
// @since 10.0 Add $DatabaseType configuration variable
$DatabaseType = 'postgresql';
}
if ( $DatabaseType !== 'postgresql'
&& $DatabaseType !== 'mysql' )
{
$error[] = 'The value for $DatabaseType in the config.inc.php file is not correct. $DatabaseType value is either postgresql or mysql.';
}
elseif ( $DatabaseType === 'postgresql'
&& ! function_exists( 'pg_connect' ) )
{
$error[] = 'PHP extensions: RosarioSIS relies on the pgsql extension (used to connect to the PostgreSQL database). Please install and activate it.';
}
elseif ( $DatabaseType === 'mysql'
&& ! function_exists( 'mysqli_connect' ) )
{
$error[] = 'PHP extensions: RosarioSIS relies on the mysql (or mysqli) extension (used to connect to the MySQL database). Please install and activate it.';
}
else
{
require_once './database.inc.php';
$db_connection = db_start( false );
if ( ! $db_connection )
{
$error[] = 'RosarioSIS cannot connect to the ' . ( $DatabaseType === 'mysql' ? 'MySQL' : 'PostgreSQL' ) . ' database server. Please review the database configuration variables in the config.inc.php file.';
$error[] = ( $DatabaseType === 'mysql' ? mysqli_connect_error() : error_get_last()['message'] );
}
else
{
$result = db_query( 'SELECT * FROM config', false );
if ( $result === false )
{
$errstring = ( $DatabaseType === 'mysql' ?
mysqli_errno( $db_connection ) . ' ' . mysqli_error( $db_connection ) :
pg_last_error( $db_connection ) );
if ( mb_strpos( $errstring, 'permission denied' ) !== false )
{
$error[] = 'The database was created with the wrong permissions. The user specified in the config.inc.php file does not have permission to access the database.';
}
elseif ( mb_strpos( $errstring, 'elation "config" does not exist' ) !== false
|| ( mb_strpos( $errstring, '1146' ) !== false && mb_strpos( $errstring, 'config' ) !== false ) ) // MySQL
{
$error[] = 'At least one of the database tables does not exist. To install the database, access the <a href="InstallDatabase.php">InstallDatabase.php</a> page.';
}
elseif ( $errstring )
{
$error[] = $errstring;
}
}
else
{
// OK, we can connect to database & config table exists.
$result = db_query( "SELECT * FROM staff WHERE SYEAR='" . $DefaultSyear . "'" );
if ( ! db_fetch_row( $result ) )
{
$error[] = 'The value for $DefaultSyear in the config.inc.php file is incorrect.';
}
else
{
require_once './Warehouse.php';
// OK, $DefaultSyear is correct so we can login.
if ( ( isset( $_SESSION['STAFF_ID'] )
&& $_SESSION['STAFF_ID'] < 1 )
|| User( 'PROFILE' ) !== 'admin' )
{
// @since 9.0 Restrict diagnostic access to logged in admin.
$error[] = 'Please login as an administrator before accessing the diagnostic.php page.';
// Exit.
echo _ErrorMessage( $error, 'fatal' );
}
}
}
}
}
}
if ( ! is_array( $RosarioLocales )
|| empty( $RosarioLocales ) )
{
$error[] = 'The value for $RosarioLocales in the config.inc.php file is not correct.';
}
// Check wkhtmltopdf binary exists.
if ( ! empty( $wkhtmltopdfPath )
&& ( ! file_exists( $wkhtmltopdfPath )
|| strpos( basename( $wkhtmltopdfPath ), 'wkhtmltopdf' ) !== 0 ) )
{
$error[] = 'The value for $wkhtmltopdfPath in the config.inc.php file is not correct.';
}
if ( ! empty( $pg_dumpPath )
&& empty( $DatabaseDumpPath )
&& $DatabaseType === 'postgresql' )
{
// @since 10.0 Rename $pg_dumpPath configuration variable to $DatabaseDumpPath
$DatabaseDumpPath = $pg_dumpPath;
}
// Check pg_dump binary exists.
if ( ! empty( $DatabaseDumpPath )
&& $DatabaseType === 'postgresql'
&& ( ! file_exists( $DatabaseDumpPath )
|| strpos( basename( $DatabaseDumpPath ), 'pg_dump' ) !== 0 ) )
{
$error[] = 'The value for $DatabaseDumpPath in the config.inc.php file is not correct. pg_dump utility not found.';
}
// Check mysqldump or mariadb-dump binary exists.
if ( ! empty( $DatabaseDumpPath )
&& $DatabaseType === 'mysql'
&& ( ! file_exists( $DatabaseDumpPath )
|| ( strpos( basename( $DatabaseDumpPath ), 'mysqldump' ) !== 0
&& strpos( basename( $DatabaseDumpPath ), 'mariadb-dump' ) !== 0 ) ) )
{
$error[] = 'The value for $DatabaseDumpPath in the config.inc.php file is not correct. mysqldump or mariadb-dump utility not found.';
}
// Check for gd extension.
if ( ! extension_loaded( 'gd' ) )
{
$warning[] = 'PHP extensions: RosarioSIS relies on the gd extension (used to resize and compress images). Please install and activate it.';
}
// Check for zip extension.
if ( ! extension_loaded( 'zip' ) )
{
$warning[] = 'PHP extensions: RosarioSIS relies on the zip extension (used to upload add-ons). Please install and activate it.';
}
// Check for curl extension.
if ( ! extension_loaded( 'curl' ) )
{
$warning[] = 'PHP extensions: RosarioSIS relies on the curl extension (used to make external API calls). Please install and activate it.';
}
// Check for intl extension.
if ( ! extension_loaded( 'intl' ) )
{
$warning[] = 'PHP extensions: RosarioSIS relies on the intl extension (used for internationalization). Please install and activate it.';
}
// Check for gettext extension (not on Windows).
if ( ! extension_loaded( 'gettext' )
&& strtoupper( substr( PHP_OS, 0, 3 ) ) !== 'WIN' )
{
$warning[] = 'PHP extensions: RosarioSIS relies on the gettext extension (used for translations). Please install and activate it.';
}
// Check session.auto_start.
if ( (bool) ini_get( 'session.auto_start' ) )
{
$error[] = 'session.auto_start is set to On in your PHP configuration. See the php.ini file to deactivate it.' . $inipath;
}
echo _ErrorMessage( $error, 'error' );
echo _ErrorMessage( $warning, 'warning' );
if ( ! count( $error ) )
{
echo '<h3>Your RosarioSIS installation is properly configured.</h3>';
}
/**
* Error Message
*
* Local function
*
* @param array $error Errors.
* @param string $code error|fatal|warning.
*
* @return string Errors HTML, exits if fatal error
*/
function _ErrorMessage( $error, $code = 'error' )
{
if ( $error )
{
$return = '<table cellpadding="10"><tr><td style="text-align:left;"><p style="font-size:larger;">';
if ( count( $error ) == 1 )
{
if ( $code === 'error'
|| $code === 'fatal' )
{
$return .= '<b><span style="color:#CC0000">Error:</span></b> ';
}
elseif ( $code === 'warning' )
{
$return .= '<b><span style="color:orange">Warning:</span></b> ';
}
else
$return .= '<b><span style="color:#00CC00">Note:</span></b> ';
$return .= reset( $error );
}
else
{
if ( $code === 'error'
|| $code === 'fatal' )
{
$return .= '<b><span style="color:#CC0000">Errors:</span></b>';
}
elseif ( $code === 'warning' )
{
$return .= '<b><span style="color:orange">Warnings:</span></b> ';
}
else
$return .= '<b><span style="color:#00CC00">Notes:</span></b>';
$return .= '<ul>';
foreach ( (array) $error as $value )
{
$return .= '<li>' . $value . '</li>';
}
$return .= '</ul>';
}
$return .= '</p></td></tr></table><br />';
if ( $code === 'fatal' )
{
echo $return;
exit;
}
return $return;
}
}