-
-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1393 from RaspAP/maint/authenticate
Refactors existing auth mechanism
- Loading branch information
Showing
32 changed files
with
552 additions
and
856 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ yarn-error.log | |
*.swp | ||
includes/config.php | ||
rootCA.pem | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,3 +228,8 @@ button > i.fas { | |
pointer-events: none; | ||
} | ||
|
||
.close { | ||
font-weight: 400; | ||
font-size: 1.3rem; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
<?php | ||
$user = $_SERVER['PHP_AUTH_USER'] ?? ""; | ||
$pass = $_SERVER['PHP_AUTH_PW'] ?? ""; | ||
|
||
require_once RASPI_CONFIG.'/raspap.php'; | ||
$config = getConfig(); | ||
|
||
if (RASPI_AUTH_ENABLED) { | ||
$validated = ($user == $config['admin_user']) && password_verify($pass, $config['admin_pass']); | ||
if (!$validated) { | ||
header('WWW-Authenticate: Basic realm="RaspAP"'); | ||
if (function_exists('http_response_code')) { | ||
// http_response_code will respond with proper HTTP version back. | ||
http_response_code(401); | ||
$user = $_SERVER['PHP_AUTH_USER'] ?? ''; | ||
$pass = $_SERVER['PHP_AUTH_PW'] ?? ''; | ||
|
||
$auth = new \RaspAP\Auth\HTTPAuth; | ||
|
||
if (!$auth->isLogged()) { | ||
if ($auth->login($user, $pass)) { | ||
$config = $auth->getAuthConfig(); | ||
} else { | ||
header('HTTP/1.0 401 Unauthorized'); | ||
$auth->authenticate(); | ||
} | ||
exit('Not authorized'.PHP_EOL); | ||
} | ||
} else { | ||
$validated = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* PSR-4 compliant class autoloader | ||
* | ||
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md | ||
* @link https://www.php.net/manual/en/function.spl-autoload-register.php | ||
* @param string $class fully-qualified class name | ||
* @return void | ||
*/ | ||
spl_autoload_register(function ($class) { | ||
|
||
// project-specific namespace prefix | ||
$prefix = ''; | ||
|
||
// base directory for the namespace prefix | ||
$base_dir = 'src/'; | ||
|
||
// normalize the base directory with a trailing separator | ||
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; | ||
|
||
// does the class use the namespace prefix? | ||
$len = strlen($prefix); | ||
if (strncmp($prefix, $class, $len) !== 0) { | ||
// no, move to the next registered autoloader | ||
return; | ||
} | ||
|
||
// get the relative class name | ||
$relative_class = substr($class, $len); | ||
|
||
// replace the namespace prefix with the base directory, replace namespace | ||
// separators with directory separators in the relative class name, append | ||
// with .php | ||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; | ||
|
||
// if the file exists, require it | ||
if (file_exists($file)) { | ||
require $file; | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.