2018-06-27 20:09:41 +03:00
|
|
|
<?php
|
|
|
|
class Authentication {
|
|
|
|
|
|
|
|
public static function showPromptIfNeeded() {
|
|
|
|
|
|
|
|
if(Configuration::getConfig('authentication', 'enable') === true) {
|
|
|
|
if(!Authentication::verifyPrompt()) {
|
2018-11-05 21:28:47 +03:00
|
|
|
header('WWW-Authenticate: Basic realm="RSS-Bridge"', true, 401);
|
2018-06-27 20:09:41 +03: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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|