summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-09-12 17:18:08 +0300
committerAndrew Dolgov <[email protected]>2020-09-12 17:18:08 +0300
commit036c8f04f2a154e01c749dba4f1a69c564e423f6 (patch)
treeabc264390a8cc34e1013abcb3c2878adc3a287eb
parent069489d437f66cded1ef97b18ae832f00b6cba82 (diff)
add some basic startup sanity checks
-rw-r--r--common.php26
-rw-r--r--index.php14
-rw-r--r--login.php4
3 files changed, 35 insertions, 9 deletions
diff --git a/common.php b/common.php
new file mode 100644
index 0000000..367ae55
--- /dev/null
+++ b/common.php
@@ -0,0 +1,26 @@
+<?php
+
+function sanity_check() {
+
+ if (!is_writable(SCRATCH_DB)) {
+ die(SCRATCH_DB . " is not writable");
+ }
+
+ if (!is_writable(dirname(SCRATCH_DB))) {
+ die(dirname(SCRATCH_DB) . " directory is not writable");
+ }
+
+ try {
+ $dbh = new PDO("sqlite:" . SCRATCH_DB);
+
+ $res = $dbh->query("SELECT id FROM epube_users LIMIT 1");
+
+ if (!$res) {
+ die("Test query failed, is schema installed? (sqlite3 " . SCRATCH_DB . "< schema.sql)");
+ }
+
+ } catch (Exception $e) {
+ die($e);
+ }
+
+} \ No newline at end of file
diff --git a/index.php b/index.php
index 02f1cea..34a3fa8 100644
--- a/index.php
+++ b/index.php
@@ -7,12 +7,16 @@
die("sessions/ directory is not writable.");
}
+ require_once "config.php";
+ require_once "common.php";
+
+ sanity_check();
+
if (!isset($_COOKIE['epube_sid'])) {
header("Location: login.php");
exit;
}
- require_once "config.php";
require_once "sessions.php";
require_once "db.php";
@@ -34,14 +38,6 @@
die;
}
- if (!is_writable(SCRATCH_DB)) {
- die(SCRATCH_DB . " is not writable");
- }
-
- if (!is_writable(dirname(SCRATCH_DB))) {
- die(dirname(SCRATCH_DB) . " directory is not writable");
- }
-
// TODO: this should be unified with the service worker cache list
$check_files_mtime = [
'manifest.json',
diff --git a/login.php b/login.php
index b80792b..0e06464 100644
--- a/login.php
+++ b/login.php
@@ -1,5 +1,9 @@
<?php
require_once "config.php";
+ require_once "common.php";
+
+ sanity_check();
+
require_once "sessions.php";
@$op = $_REQUEST["op"];