forked from seblucas/cops
-
Notifications
You must be signed in to change notification settings - Fork 7
/
checkconfig.php
342 lines (338 loc) · 10.7 KB
/
checkconfig.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
/**
* COPS (Calibre OPDS PHP Server) Configuration check
* URL format: checkconfig.php?err={err}&full={full}
*
* Keep as fallback endpoint for any CheckHandler issues for now
*
* @license GPL v2 or later (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <[email protected]>
* @author mikespub
*/
use SebLucas\Cops\Calibre\Database;
use SebLucas\Cops\Input\ProxyRequest;
use SebLucas\Cops\Input\Request;
use SebLucas\Cops\Input\Route;
use SebLucas\Cops\Routing\UriGenerator;
require_once __DIR__ . '/config/config.php';
/** @var array<mixed> $config */
$request = new Request();
$err = $request->get('err', -1);
$full = $request->get('full');
$error = null;
switch ($err) {
case 1:
$error = 'Database error';
break;
}
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>COPS Configuration Check</title>
<link rel="stylesheet" type="text/css" href="<?php echo UriGenerator::path($request->style()) ?>" media="screen" />
</head>
<body>
<div class="container">
<header>
<div class="headcenter">
<h1>COPS Configuration Check</h1>
</div>
</header>
<div id="content" style="display: none;"></div>
<section>
<?php
if (!is_null($error)) {
?>
<article class="frontpage">
<h2>You've been redirected because COPS is not configured properly</h2>
<h4><?php echo $error ?></h4>
</article>
<?php
}
?>
<article class="frontpage">
<h2>Check if PHP version is correct</h2>
<h4>
<?php
if (defined('PHP_VERSION_ID')) {
if (PHP_VERSION_ID >= 70400) {
echo 'OK (' . PHP_VERSION . ')';
} else {
echo 'Please install PHP >= 7.4 (' . PHP_VERSION . ')';
}
} else {
echo 'Please install PHP >= 7.4';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if GD is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('gd') && function_exists('gd_info')) {
echo 'OK';
} else {
echo 'Please install the php-gd extension and make sure it\'s enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if Sqlite is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('pdo_sqlite')) {
echo 'OK';
} else {
echo 'Please install the php-sqlite / php-sqlite3 extension and make sure it\'s enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if libxml is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('libxml')) {
echo 'OK';
} else {
echo 'Please make sure libxml is enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if DOM is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('dom')) {
echo 'OK';
} else {
echo 'Please install the php-xml extension and make sure DOM is enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if XMLWriter is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('xmlwriter')) {
echo 'OK';
} else {
echo 'Please install the php-xml extension and make sure XMLWriter is enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if Json is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('json')) {
echo 'OK';
} else {
echo 'Please install the php-json extension and make sure it\'s enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if mbstring is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('mbstring')) {
echo 'OK';
} else {
echo 'Please install the php-mbstring extension and make sure it\'s enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if intl is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('intl')) {
echo 'OK';
} else {
echo 'Please install the php-intl extension and make sure it\'s enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if Normalizer class is properly installed and loaded</h2>
<h4>
<?php
if (class_exists('Normalizer', $autoload = false)) {
echo 'OK';
} else {
echo 'Please make sure intl is enabled in your php.ini';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if zlib is properly installed and loaded</h2>
<h4>
<?php
if (extension_loaded('zlib')) {
echo 'OK';
} else {
echo 'Please make sure zlib is enabled';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if the base URL looks OK</h2>
<h4>
<?php
$base = dirname((string) $_SERVER['SCRIPT_NAME']);
if (!str_ends_with($base, '/')) {
$base .= '/';
}
echo 'Base URL detected by the script: ' . $base . '<br>';
echo 'Full URL specified in $config[\'cops_full_url\']: ' . $config['cops_full_url'] . '<br>';
if (ProxyRequest::hasTrustedProxies()) {
echo 'Trusted proxies configured: ' . $config['cops_trusted_proxies'] . '<br>';
echo 'Trusted headers configured: ' . json_encode($config['cops_trusted_headers']) . '<br>';
foreach ($config['cops_trusted_headers'] as $name) {
$header = 'HTTP_' . strtoupper(str_replace('-', '_', $name));
echo $header . ': ' . ($_SERVER[$header] ?? '') . '<br>';
}
echo 'Base URL via trusted proxies: ' . UriGenerator::base() . '<br>';
}
echo 'REMOTE_ADDR: ' . ($_SERVER['REMOTE_ADDR'] ?? '') . '<br>';
echo '<br>';
echo 'SCRIPT_NAME: ' . ($_SERVER['SCRIPT_NAME'] ?? '') . '<br>';
echo 'HTTP_HOST: ' . ($_SERVER['HTTP_HOST'] ?? '') . '<br>';
echo 'SERVER_NAME: ' . ($_SERVER['SERVER_NAME'] ?? '') . '<br>';
echo 'SERVER_ADDR: ' . ($_SERVER['SERVER_ADDR'] ?? '') . '<br>';
echo 'SERVER_PORT: ' . ($_SERVER['SERVER_PORT'] ?? '') . '<br>';
echo 'REQUEST_SCHEME: ' . ($_SERVER['REQUEST_SCHEME'] ?? '') . '<br>';
echo 'REQUEST_URI: ' . ($_SERVER['REQUEST_URI'] ?? '') . '<br>';
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if the rendering will be done on client side or server side</h2>
<h4>
<?php
if ($request->render()) {
echo 'Server side rendering';
} else {
echo 'Client side rendering';
}
?>
</h4>
<h2>User agent detected</h2>
<h4><?php echo $_SERVER["HTTP_USER_AGENT"] ?></h4>
</article>
<?php
$i = 0;
foreach (Database::getDbList() as $name => $database) {
?>
<article class="frontpage">
<h2>Check if Calibre database path is not an URL</h2>
<h4>
<?php
if (!preg_match('#^http#', $database)) {
echo $name . ' OK';
} else {
echo $name . ' Calibre path has to be local (no URL allowed)';
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if Calibre database file exists and is readable</h2>
<h4>
<?php
if (is_readable(Database::getDbFileName($i))) {
echo $name . ' OK';
} else {
echo $name . ' File ' . Database::getDbFileName($i) . ' not found,
Please check
<ul>
<li>Value of $config[\'calibre_directory\'] in config/local.php <strong>(Does it end with a \'/\'?)</strong></li>
<li>Value of <a href="http://php.net/manual/en/ini.core.php#ini.open-basedir">open_basedir</a> in your php.ini</li>
<li>The access rights of the Calibre Database</li>
<li>Synology users please read <a href="https://github.com/seblucas/cops/wiki/Howto---Synology">this</a></li>
<li>Note that hosting your Calibre Library in /home is almost impossible due to access rights restriction</li>
</ul>';
}
?>
</h4>
</article>
<?php if (is_readable(Database::getDbFileName($i))) { ?>
<article class="frontpage">
<h2>Check if Calibre database file can be opened with PHP</h2>
<h4>
<?php
try {
$db = new PDO('sqlite:' . Database::getDbFileName($i));
echo $name . ' OK';
} catch (Exception $e) {
echo $name . ' If the file is readable, check your php configuration. Exception detail : ' . $e;
}
?>
</h4>
</article>
<article class="frontpage">
<h2>Check if Calibre database file contains at least some of the needed tables</h2>
<h4>
<?php
try {
$db = new PDO('sqlite:' . Database::getDbFileName($i));
$count = $db->query('select count(*) FROM sqlite_master WHERE type="table" AND name in ("books", "authors", "tags", "series")')->fetchColumn();
if ($count == 4) {
echo $name . ' OK';
} else {
echo $name . ' Not all Calibre tables were found. Are you sure you\'re using the correct database.';
}
} catch (Exception $e) {
echo $name . ' If the file is readable, check your php configuration. Exception detail : ' . $e;
}
?>
</h4>
</article>
<?php if ($full) { ?>
<article class="frontpage">
<h2>Check if all Calibre books are found</h2>
<h4>
<?php
echo "This option has been disabled by default - uncomment if you are sure you want to do this...";
/**
try {
$db = new PDO('sqlite:' . Database::getDbFileName($i));
$result = $db->prepare('select books.path || "/" || data.name || "." || lower (format) as fullpath from data join books on data.book = books.id');
$result->execute();
while ($post = $result->fetchObject()) {
if (!is_file(Database::getDbDirectory($i) . $post->fullpath)) {
echo '<p>' . Database::getDbDirectory($i) . $post->fullpath . '</p>';
}
}
} catch (Exception $e) {
echo $name . ' If the file is readable, check your php configuration. Exception detail : ' . $e;
}
*/
?>
</h4>
</article>
<?php
}
}
$i++;
}
?>
</section>
<footer></footer>
</div>
</body>
</html>