Move passhass to options.

This commit is contained in:
Lars Jung 2015-05-13 14:07:21 +02:00
parent 37fbca2ead
commit 4932dda11c
5 changed files with 24 additions and 26 deletions

View file

@ -2,19 +2,26 @@
class Context {
private static $DEFAULT_PASSHASH = 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e';
private static $AS_ADMIN_SESSION_KEY = 'AS_ADMIN';
private $session;
private $request;
private $setup;
private $options;
private $passhash;
public function __construct($session, $request, $setup) {
$this->session = $session;
$this->request = $request;
$this->setup = $setup;
$this->options = Util::load_commented_json($this->setup->get('APP_PATH') . '/conf/options.json');
$this->passhash = $this->query_option('passhash', '');
$this->options['hasCustomPasshash'] = strcasecmp($this->passhash, Context::$DEFAULT_PASSHASH) !== 0;
unset($this->options['passhash']);
}
public function get_session() {
@ -49,8 +56,7 @@ class Context {
public function login_admin($pass) {
$hash = $this->setup->get('PASSHASH');
$this->session->set(Context::$AS_ADMIN_SESSION_KEY, strcasecmp(hash('sha512', $pass), $hash) === 0);
$this->session->set(Context::$AS_ADMIN_SESSION_KEY, strcasecmp(hash('sha512', $pass), $this->passhash) === 0);
return $this->session->get(Context::$AS_ADMIN_SESSION_KEY);
}

View file

@ -2,8 +2,6 @@
class Setup {
private static $DEFAULT_PASSHASH = 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e';
private $store;
private $refresh;
@ -15,7 +13,6 @@ class Setup {
$this->add_globals_and_envs();
$this->add_php_checks();
$this->add_app_metadata();
$this->add_admin_check();
$this->add_server_metadata_and_check();
$this->add_paths();
$this->add_sys_cmd_checks();
@ -56,7 +53,6 @@ class Setup {
$this->set('PHP_VERSION', PHP_VERSION);
$this->set('MIN_PHP_VERSION', MIN_PHP_VERSION);
$this->set('PASSHASH', PASSHASH);
$this->set('REQUEST_METHOD', getenv('REQUEST_METHOD'));
$this->set('REQUEST_HREF', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH));
@ -83,11 +79,6 @@ class Setup {
$this->set('FILE_PREFIX', '_{{pkg.name}}');
}
private function add_admin_check() {
$this->set('HAS_CUSTOM_PASSHASH', strtolower(PASSHASH) !== Setup::$DEFAULT_PASSHASH);
}
private function add_server_metadata_and_check() {
$server_software = $this->get('SERVER_SOFTWARE');
@ -117,8 +108,8 @@ class Setup {
$this->set('ROOT_HREF', Util::normalize_path(dirname($this->get('APP_HREF')), true));
$this->set('ROOT_PATH', Util::normalize_path(dirname($this->get('APP_PATH')), false));
$this->set('PUBLIC_HREF', $this->get('APP_HREF') . 'public/');
$this->set('INDEX_HREF', $this->get('APP_HREF') . 'public/index.php');
$this->set('PUBLIC_HREF', Util::normalize_path($this->get('APP_HREF') . '/public', true));
$this->set('INDEX_HREF', Util::normalize_path($this->get('APP_HREF') . '/public/index.php', false));
$this->set('CACHE_HREF', Util::normalize_path($this->get('APP_HREF') . '/public/cache', true));
$this->set('CACHE_PATH', Util::normalize_path($this->get('APP_PATH') . '/public/cache', false));
@ -157,9 +148,7 @@ class Setup {
$keys = [
'APP_HREF',
'ROOT_HREF',
'VERSION',
'HAS_CUSTOM_PASSHASH'
'VERSION'
];
if ($as_admin) {

View file

@ -6,6 +6,16 @@ Options
*/
{
/*
Password hash.
SHA512 hash of the info page password, the preset password is the empty string.
Online hash generator: http://md5hashing.net/hashing/sha512
*/
"passhash": "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e",
/*
General view options.

View file

@ -1,7 +0,0 @@
<?php
/*********************************************************************************
SHA512 hash of the info page password, the preset password is the empty string.
Online hash generator: http://md5hashing.net/hashing/sha512
**********************************************************************************/
define('PASSHASH', 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e');

View file

@ -14,8 +14,8 @@ modulejs.define('main/info', ['$', 'config', 'core/server'], function ($, config
'<span id="login">login</span>' +
'<span id="logout">logout</span>' +
'<div id="hint">' +
'The preset password is the empty string, just hit login. ' +
'Change it in \'_h5ai/conf/passhash.php\'.' +
'The preset password is the empty string, just click login. ' +
'Change it in \'_h5ai/conf/options.json\'.' +
'</div>' +
'</div>';
var setup = config.setup;
@ -146,7 +146,7 @@ modulejs.define('main/info', ['$', 'config', 'core/server'], function ($, config
$('#login').on('click', onLogin);
$('#logout').remove();
}
if (setup.HAS_CUSTOM_PASSHASH) {
if (config.options.hasCustomPasshash) {
$('#hint').remove();
}
}