summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-02-26 18:14:59 +0300
committerAndrew Dolgov <[email protected]>2017-02-26 18:14:59 +0300
commit4059638262e135e4497e3f790914bd9cc476389e (patch)
tree741384e60619122da1a92e89b17ab6ac75283a08
parent7c123353b57cb96d84fb7a6b311b0df1e56fa035 (diff)
show 401 errors if no http auth user is present
-rw-r--r--backend.php3
-rw-r--r--index.php15
2 files changed, 10 insertions, 8 deletions
diff --git a/backend.php b/backend.php
index c7d7ebc..b7298fa 100644
--- a/backend.php
+++ b/backend.php
@@ -12,7 +12,8 @@
$owner = SQLite3::escapeString($_SERVER["PHP_AUTH_USER"]);
if (!$owner) {
- print json_encode(["error" => "NOT_AUTHENTICATED"]);
+ header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
+ echo "Unauthorized";
die;
}
diff --git a/index.php b/index.php
index e7ecb17..8df4f26 100644
--- a/index.php
+++ b/index.php
@@ -1,6 +1,14 @@
<?php
require_once "config.php";
+ $owner = SQLite3::escapeString($_SERVER["PHP_AUTH_USER"]);
+
+ if (!$owner) {
+ header($_SERVER["SERVER_PROTOCOL"]." 401 Unauthorized");
+ echo "Unauthorized";
+ die;
+ }
+
if (!is_writable(SCRATCH_DB)) {
die(SCRATCH_DB . " is not writable");
}
@@ -95,13 +103,6 @@
require_once "config.php";
- $owner = SQLite3::escapeString($_SERVER["PHP_AUTH_USER"]);
-
- if (!$owner) {
- print "<h1>Not authenticated</h1>";
- die;
- }
-
$db = new SQLite3(CALIBRE_DB, SQLITE3_OPEN_READONLY);
if ($query) {