diff options
author | 2022-08-06 22:46:28 +0200 | |
---|---|---|
committer | 2022-08-06 22:46:28 +0200 | |
commit | 2bbce8ebef8cf4f88392431aabe84a15482dc933 (patch) | |
tree | 1f5027ca69b1dfa2364bd9319e8536b86a41e928 /lib/AuthenticationMiddleware.php | |
parent | b042412416cc4ecc71c3f9c13239661a0dd588a6 (diff) | |
download | rss-bridge-2bbce8ebef8cf4f88392431aabe84a15482dc933.tar.gz rss-bridge-2bbce8ebef8cf4f88392431aabe84a15482dc933.tar.zst rss-bridge-2bbce8ebef8cf4f88392431aabe84a15482dc933.zip |
refactor: general code base refactor (#2950)
* refactor
* fix: bug in previous refactor
* chore: exclude phpcompat sniff due to bug in phpcompat
* fix: do not leak absolute paths
* refactor/fix: batch extensions checking, fix DOS issue
Diffstat (limited to 'lib/AuthenticationMiddleware.php')
-rw-r--r-- | lib/AuthenticationMiddleware.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/AuthenticationMiddleware.php b/lib/AuthenticationMiddleware.php new file mode 100644 index 00000000..430f977c --- /dev/null +++ b/lib/AuthenticationMiddleware.php @@ -0,0 +1,42 @@ +<?php + +/** + * This file is part of RSS-Bridge, a PHP project capable of generating RSS and + * Atom feeds for websites that don't have one. + * + * For the full license information, please view the UNLICENSE file distributed + * with this source code. + * + * @package Core + * @license http://unlicense.org/ UNLICENSE + * @link https://github.com/rss-bridge/rss-bridge + */ + +final class AuthenticationMiddleware +{ + public function __invoke(): void + { + $user = $_SERVER['PHP_AUTH_USER'] ?? null; + $password = $_SERVER['PHP_AUTH_PW'] ?? null; + + if ($user === null || $password === null) { + $this->renderAuthenticationDialog(); + exit; + } + if ( + Configuration::getConfig('authentication', 'username') === $user + && Configuration::getConfig('authentication', 'password') === $password + ) { + return; + } + $this->renderAuthenticationDialog(); + exit; + } + + private function renderAuthenticationDialog(): void + { + http_response_code(401); + header('WWW-Authenticate: Basic realm="RSS-Bridge"'); + print render('error.html.php', ['message' => 'Please authenticate in order to access this instance !']); + } +} |