changes DEBUG SALT and SALTY from defines to variables

switched that in all places used (class loads mostly)
moved all includes at the beginning of index into bootstrap
moves *_PATH defines from config to bootstrap
config now uses defaults first, then user config
This commit is contained in:
xisi 2014-01-29 07:34:50 -05:00
parent c2b1c68699
commit 568445845a
10 changed files with 44 additions and 33 deletions

View File

@ -102,8 +102,8 @@ if (@$_SESSION['USERDATA']['is_admin'] && $user->isAdmin(@$_SESSION['USERDATA'][
$notice[] = "Strict is <u>disabled</u> - if you have memcache, you should turn this on."; $notice[] = "Strict is <u>disabled</u> - if you have memcache, you should turn this on.";
} }
// salts too short -> notice, salts default -> error // salts too short -> notice, salts default -> error
if ((strlen(SALT) < 24) || (strlen(SALTY) < 24) || SALT == 'PLEASEMAKEMESOMETHINGRANDOM' || SALTY == 'THISSHOULDALSOBERRAANNDDOOM') { if ((strlen($config['SALT']) < 24) || (strlen($config['SALTY']) < 24) || $config['SALT'] == 'PLEASEMAKEMESOMETHINGRANDOM' || $config['SALTY'] == 'THISSHOULDALSOBERRAANNDDOOM') {
if (SALT == 'PLEASEMAKEMESOMETHINGRANDOM' || SALTY == 'THISSHOULDALSOBERRAANNDDOOM') { if ($config['SALT'] == 'PLEASEMAKEMESOMETHINGRANDOM' || $config['SALTY'] == 'THISSHOULDALSOBERRAANNDDOOM') {
$error[] = "You absolutely <u>SHOULD NOT leave your SALT or SALTY default</u>"; $error[] = "You absolutely <u>SHOULD NOT leave your SALT or SALTY default</u>";
} else { } else {
$notice[] = "SALT or SALTY is too short, they should be more than 24 characters and changing them will require registering again."; $notice[] = "SALT or SALTY is too short, they should be more than 24 characters and changing them will require registering again.";

View File

@ -0,0 +1,28 @@
<?php
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
// Used for performance calculations
$dStartTime = microtime(true);
define('INCLUDE_DIR', BASEPATH . 'include');
define('CLASS_DIR', INCLUDE_DIR . '/classes');
define('PAGES_DIR', INCLUDE_DIR . '/pages');
define('THEME_DIR', BASEPATH . 'templates');
$quickstartlink = "<a href='https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide' title='MPOS Quick Start Guide'>Quick Start Guide</a>";
// Include our configuration (holding defines for the requires)
if (!include_once(BASEPATH . 'include/config/global.inc.dist.php')) die('Unable to load base global config - '.$quickstartlink);
if (!@include_once(BASEPATH . 'include/config/global.inc.php')) die('Unable to load your global config - '.$quickstartlink);
// load our security configs
if (!include_once(BASEPATH . 'include/config/security.inc.dist.php')) die('Unable to load base security config - '.$quickstartlink);
if (@file_exists(BASEPATH . 'include/config/security.inc.php')) include_once(BASEPATH . 'include/config/security.inc.php');
// Our default template to load, pages can overwrite this later
$master_template = 'master.tpl';
// Load Classes, they name defines the $ variable used
// We include all needed files here, even though our templates could load them themself
require_once(INCLUDE_DIR . '/autoloader.inc.php');
?>

View File

@ -73,4 +73,4 @@ class BitcoinWrapper extends BitcoinClient {
} }
// Load this wrapper // Load this wrapper
$bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], DEBUG, $debug, $memcache); $bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], $config['DEBUG'], $debug, $memcache);

View File

@ -97,8 +97,8 @@ class CSRFToken Extends Base {
$csrftoken = new CSRFToken(); $csrftoken = new CSRFToken();
$csrftoken->setDebug($debug); $csrftoken->setDebug($debug);
$csrftoken->setMysql($mysqli); $csrftoken->setMysql($mysqli);
$csrftoken->setSalt(SALT); $csrftoken->setSalt($config['SALT']);
$csrftoken->setSalty(SALTY); $csrftoken->setSalty($config['SALTY']);
$csrftoken->setMail($mail); $csrftoken->setMail($mail);
$csrftoken->setUser($user); $csrftoken->setUser($user);
$csrftoken->setToken($oToken); $csrftoken->setToken($oToken);

View File

@ -108,5 +108,5 @@ class Debug {
} }
// Instantiate this class // Instantiate this class
$debug = new Debug(DEBUG); $debug = new Debug($config['DEBUG']);
?> ?>

View File

@ -861,7 +861,7 @@ public function isAuthenticated($logout=true) {
$user = new User(); $user = new User();
$user->setDebug($debug); $user->setDebug($debug);
$user->setMysql($mysqli); $user->setMysql($mysqli);
$user->setSalt(SALT); $user->setSalt($config['SALT']);
$user->setSmarty($smarty); $user->setSmarty($smarty);
$user->setConfig($config); $user->setConfig($config);
$user->setMail($mail); $user->setMail($mail);

View File

@ -19,14 +19,9 @@ $config['skip_config_tests'] = false;
* Debug setting and salts for hashing passwords * Debug setting and salts for hashing passwords
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-defines--salts * https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-defines--salts
*/ */
define('DEBUG', 0); $config['DEBUG'] = 0;
define('SALT', 'PLEASEMAKEMESOMETHINGRANDOM'); $config['SALT'] = 'PLEASEMAKEMESOMETHINGRANDOM';
define('SALTY', 'THISSHOULDALSOBERRAANNDDOOM'); $config['SALTY'] = 'THISSHOULDALSOBERRAANNDDOOM';
define('INCLUDE_DIR', BASEPATH . 'include');
define('CLASS_DIR', INCLUDE_DIR . '/classes');
define('PAGES_DIR', INCLUDE_DIR . '/pages');
define('THEME_DIR', BASEPATH . 'templates');
/** /**
* Coin Algorithm * Coin Algorithm

View File

@ -170,7 +170,7 @@ if ($motd = $setting->getValue('system_motd'))
$_SESSION['POPUP'][] = array('CONTENT' => $motd, 'TYPE' => 'info'); $_SESSION['POPUP'][] = array('CONTENT' => $motd, 'TYPE' => 'info');
// So we can display additional info // So we can display additional info
$smarty->assign('DEBUG', DEBUG); $smarty->assign('DEBUG', $config['DEBUG']);
// Make it available in Smarty // Make it available in Smarty
$smarty->assign('PATH', 'site_assets/' . THEME); $smarty->assign('PATH', 'site_assets/' . THEME);

View File

@ -32,28 +32,16 @@ if (SECHASH_CHECK) {
function cfip() { return (@defined('SECURITY')) ? 1 : 0; } function cfip() { return (@defined('SECURITY')) ? 1 : 0; }
} }
// Used for performance calculations
$dStartTime = microtime(true);
// This should be okay // This should be okay
// No but Its now, - Aim // No but Its now, - Aim
define("BASEPATH", dirname(__FILE__) . "/"); define("BASEPATH", dirname(__FILE__) . "/");
// Include our configuration (holding defines for the requires) // all our includes and config etc are now in bootstrap
if (!include_once(BASEPATH . 'include/config/global.inc.php')) die('Unable to load site configuration'); include_once('include/bootstrap.php');
if (!include_once(BASEPATH . 'include/config/security.inc.dist.php')) die('Unable to load security configuration');
if (@file_exists(BASEPATH . 'include/config/security.inc.php')) include_once(BASEPATH . 'include/config/security.inc.php');
// switch to https if config option is enabled // switch to https if config option is enabled
$hts = ($config['strict__https_only'] && (!empty($_SERVER['QUERY_STRING']))) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'] : "https://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; $hts = ($config['strict__https_only'] && (!empty($_SERVER['QUERY_STRING']))) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'] : "https://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
($config['strict__https_only'] && @!$_SERVER['HTTPS']) ? exit(header($hts)):0; ($config['strict__https_only'] && @!$_SERVER['HTTPS']) ? exit(header("Location: ".$hts)):0;
// Our default template to load, pages can overwrite this later
$master_template = 'master.tpl';
// Load Classes, they name defines the $ variable used
// We include all needed files here, even though our templates could load them themself
require_once(INCLUDE_DIR . '/autoloader.inc.php');
if ($config['memcache']['enabled'] && ($config['mc_antidos']['enabled'] || $config['strict'])) { if ($config['memcache']['enabled'] && ($config['mc_antidos']['enabled'] || $config['strict'])) {
if (PHP_OS == 'WINNT') { if (PHP_OS == 'WINNT') {

View File

@ -8,8 +8,8 @@ class TestDistConfig extends PHPUnit_Framework_Testcase {
* Test to make sure SALT is sane * Test to make sure SALT is sane
*/ */
function testSaltLength() { function testSaltLength() {
$this->assertNotEmpty(SALT); $this->assertNotEmpty($config['SALT']);
$this->assertGreaterThan(1, strlen(SALT)); $this->assertGreaterThan(1, strlen($config['SALTY']));
} }
} }