Completed
Pull Request — master (#274)
by Markus
06:26
created

checkconfig.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<!DOCTYPE html>
2
<html xmlns="http://www.w3.org/1999/xhtml">
3
<?php
4
/**
5
 * COPS (Calibre OPDS PHP Server) Configuration check
6
 *
7
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8
 * @author     Sébastien Lucas <[email protected]>
9
 *
10
 */
11
12
    require_once 'config.php';
13
    require_once 'base.php';
14
15
    header ('Content-Type:text/html; charset=UTF-8');
16
17
    $err = getURLParam('err', -1);
18
    $full = getURLParam('full');
19
    $error = NULL;
20
    switch ($err) {
21
        case 1 :
0 ignored issues
show
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
22
            $error = 'Database error';
23
            break;
24
    }
25
26
?>
27
<head>
28
    <meta charset="utf-8">
29
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
30
    <title>COPS Configuration Check</title>
31
    <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss ()) ?>" media="screen" />
32
</head>
33
<body>
34
<div class="container">
35
    <header>
36
        <div class="headcenter">
37
            <h1>COPS Configuration Check</h1>
38
        </div>
39
    </header>
40
    <div id="content" style="display: none;"></div>
41
    <section>
42
        <?php
43
        if (!is_null($error)) {
44
        ?>
45
        <article class="frontpage">
46
            <h2>You've been redirected because COPS is not configured properly</h2>
47
            <h4><?php echo $error ?></h4>
48
        </article>
49
        <?php
50
        }
51
        ?>
52
        <article class="frontpage">
53
            <h2>Check if PHP version is correct</h2>
54
            <h4>
55
            <?php
56
            if (defined('PHP_VERSION_ID')) {
57
                if (PHP_VERSION_ID >= 50300) {
58
                    echo 'OK (' . PHP_VERSION . ')';
59
                } else {
60
                    echo 'Please install PHP >= 5.3 (' . PHP_VERSION . ')';
61
                }
62
            } else {
63
                echo 'Please install PHP >= 5.3';
64
            }
65
            ?>
66
            </h4>
67
        </article>
68
        <article class="frontpage">
69
            <h2>Check if GD is properly installed and loaded</h2>
70
            <h4>
71
            <?php
72
            if (extension_loaded('gd') && function_exists('gd_info')) {
73
                echo 'OK';
74
            } else {
75
                echo 'Please install the php5-gd extension and make sure it\'s enabled';
76
            }
77
            ?>
78
            </h4>
79
        </article>
80
        <article class="frontpage">
81
            <h2>Check if Sqlite is properly installed and loaded</h2>
82
            <h4>
83
            <?php
84
            if (extension_loaded('pdo_sqlite')) {
85
                echo 'OK';
86
            } else {
87
                echo 'Please install the php5-sqlite extension and make sure it\'s enabled';
88
            }
89
            ?>
90
            </h4>
91
        </article>
92
        <article class="frontpage">
93
            <h2>Check if libxml is properly installed and loaded</h2>
94
            <h4>
95
            <?php
96
            if (extension_loaded('libxml')) {
97
                echo 'OK';
98
            } else {
99
                echo 'Please make sure libxml is enabled';
100
            }
101
            ?>
102
            </h4>
103
        </article>
104
        <article class="frontpage">
105
            <h2>Check if Json is properly installed and loaded</h2>
106
            <h4>
107
            <?php
108
            if (extension_loaded('json')) {
109
                echo 'OK';
110
            } else {
111
                echo 'Please install the php5-json extension and make sure it\'s enabled';
112
            }
113
            ?>
114
            </h4>
115
        </article>
116
        <article class="frontpage">
117
            <h2>Check if mbstring is properly installed and loaded</h2>
118
            <h4>
119
            <?php
120
            if (extension_loaded('mbstring')) {
121
                echo 'OK';
122
            } else {
123
                echo 'Please install the php5-mbstring extension and make sure it\'s enabled';
124
            }
125
            ?>
126
            </h4>
127
        </article>
128
        <article class="frontpage">
129
            <h2>Check if intl is properly installed and loaded</h2>
130
            <h4>
131
            <?php
132
            if (extension_loaded('intl')) {
133
                echo 'OK';
134
            } else {
135
                echo 'Please install the php5-intl extension and make sure it\'s enabled';
136
            }
137
            ?>
138
            </h4>
139
        </article>
140
        <article class="frontpage">
141
            <h2>Check if Normalizer class is properly installed and loaded</h2>
142
            <h4>
143
            <?php
144
            if (class_exists('Normalizer', $autoload = false)) {
145
                echo 'OK';
146
            } else {
147
                echo 'Please make sure intl is enabled in your php.ini';
148
            }
149
            ?>
150
            </h4>
151
        </article>
152
        <article class="frontpage">
153
            <h2>Check if the rendering will be done on client side or server side</h2>
154
            <h4>
155
            <?php
156
            if (useServerSideRendering ()) {
157
                echo 'Server side rendering';
158
            } else {
159
                echo 'Client side rendering';
160
            }
161
            ?>
162
            </h4>
163
        </article>
164
<?php
165
$i = 0;
166
foreach (Base::getDbList() as $name => $database) {
167
?>
168
        <article class="frontpage">
169
            <h2>Check if Calibre database path is not an URL</h2>
170
            <h4>
171
            <?php
172
            if (!preg_match ('#^http#', $database)) {
173
                echo 'OK';
174
            } else {
175
                echo 'Calibre path has to be local (no URL allowed)';
176
            }
177
            ?>
178
            </h4>
179
        </article>
180
        <article class="frontpage">
181
            <h2>Check if Calibre database file exists and is readable</h2>
182
            <h4>
183
            <?php
184
            if (is_readable(Base::getDbFileName($i))) {
185
                echo $name . ' OK';
186
            } else {
187
                echo $name . ' File ' . Base::getDbFileName($i) . ' not found,
188
Please check
189
<ul>
190
<li>Value of $config[\'calibre_directory\'] in config_local.php</li>
191
<li>Value of <a href="http://php.net/manual/en/ini.core.php#ini.open-basedir">open_basedir</a> in your php.ini</li>
192
<li>The access rights of the Calibre Database</li>
193
<li>Synology users please read <a href="https://github.com/seblucas/cops/wiki/Howto---Synology">this</a></li>
194
</ul>';
195
            }
196
            ?>
197
            </h4>
198
        </article>
199
    <?php if (is_readable(Base::getDbFileName($i))) { ?>
200
        <article class="frontpage">
201
            <h2>Check if Calibre database file can be opened with PHP</h2>
202
            <h4>
203
            <?php
204
            try {
205
                $db = new PDO('sqlite:'. Base::getDbFileName($i));
206
                echo $name . ' OK';
207
            } catch (Exception $e) {
208
                echo $name . ' If the file is readable, check your php configuration. Exception detail : ' . $e;
209
            }
210
            ?>
211
            </h4>
212
        </article>
213
        <article class="frontpage">
214
            <h2>Check if Calibre database file contains at least some of the needed tables</h2>
215
            <h4>
216
            <?php
217
            try {
218
                $db = new PDO('sqlite:'. Base::getDbFileName($i));
219
                $count = $db->query('select count(*) FROM sqlite_master WHERE type="table" AND name in ("books", "authors", "tags", "series")')->fetchColumn();
220
                if ($count == 4) {
221
                    echo $name . ' OK';
222
                } else {
223
                    echo $name . ' Not all Calibre tables were found. Are you sure you\'re using the correct database.';
224
                }
225
            } catch (Exception $e) {
226
                echo $name . ' If the file is readable, check your php configuration. Exception detail : ' . $e;
227
            }
228
            ?>
229
            </h4>
230
        </article>
231
        <?php if ($full) { ?>
232
        <article class="frontpage">
233
            <h2>Check if all Calibre books are found</h2>
234
            <h4>
235
            <?php
236
            try {
237
                $db = new PDO('sqlite:' . Base::getDbFileName($i));
238
                $result = $db->prepare('select books.path || "/" || data.name || "." || lower (format) as fullpath from data join books on data.book = books.id');
239
                $result->execute();
240
                while ($post = $result->fetchObject())
241
                {
242
                    if (!is_file (Base::getDbDirectory($i) . $post->fullpath)) {
243
                        echo '<p>' . Base::getDbDirectory($i) . $post->fullpath . '</p>';
244
                    }
245
                }
246
            } catch (Exception $e) {
247
                echo $name . ' If the file is readable, check your php configuration. Exception detail : ' . $e;
248
            }
249
            ?>
250
            </h4>
251
        </article>
252
        <?php
253
        }
254
    }
255
    $i++;
256
}
257
?>
258
    </section>
259
    <footer></footer>
260
</div>
261
</body>
262
</html>
263