2018-06-27 19:09:41 +02:00
|
|
|
<?php
|
|
|
|
class Authentication {
|
|
|
|
|
|
|
|
public static function showPromptIfNeeded() {
|
|
|
|
|
|
|
|
if(Configuration::getConfig('authentication', 'enable') === true) {
|
|
|
|
if(!Authentication::verifyPrompt()) {
|
2018-11-05 19:28:47 +01:00
|
|
|
header('WWW-Authenticate: Basic realm="RSS-Bridge"', true, 401);
|
2018-06-27 19:09:41 +02:00
|
|
|
die('Please authenticate in order to access this instance !');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function verifyPrompt() {
|
|
|
|
|
|
|
|
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
|
|
|
if(Configuration::getConfig('authentication', 'username') === $_SERVER['PHP_AUTH_USER']
|
|
|
|
&& Configuration::getConfig('authentication', 'password') === $_SERVER['PHP_AUTH_PW']) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
error_log('[RSS-Bridge] Failed authentication attempt from ' . $_SERVER['REMOTE_ADDR']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|