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