flatpress/fp-includes/core/core.system.php
real_nowhereman c0642e4f0f huge security commit, this should be an almost hassle-free hash salt: the salt is created on setup and then STORED in fp-content/config/hashsalt.conf.php
(you can change the name of the file from defaults.php); 

as salt is based on the path on the server, if you had to move to another directory or to another server, then you wouldn't be able to login anymore and you had to reinstall, now this shouldn't be needed anymore; moreover as this is now safe in a file we can add additional security by
* concatenating the default paths+random blog id to another random number, which is not written anywhere else
* changing the contents with your very own salt string: then re-run setup and overwrite your old user: the hashsalt won't be overwritten (this needs testing)
2008-02-10 14:20:09 +00:00

187 lines
3.8 KiB
PHP
Executable File

<?php
/**
* system.php
* string-to-php and general system functions
*/
/**
* function system_save
*
* This function saves a list of variables provided after $file
* encapsulated in an array where KEY is the var name
* in a php file.
*
* Example usage:
* <code>
* <?php
* // Let's suppose you want to save an array called $my_arr
* // in file $my_file
* $my_file = 'path/to/file'
* $my_arr = array ('val1', 'val2', 'val3');
* $save_arr = array('$my_arr' => $my_arr); //same as: $save_arr['$my_arr'] = $my_arr);
* system_save($my_file, $my_arr);
* // now the file $my_file will contain the following lines:
* // global $my_arr;
* // $my_arr = array (
* // '$my_arr' => val1',
* // '$my_arr' => 'val2',
* // '$my_arr' => 'val3'
* // );
* ?>
* </code>
*
* @param string $file file path where $array contents will be saved
* @array $var_list list of vars to be saved
* @return bool
*
* @see config_save, config_load
*
*/
function system_save($file, $array ) {
//if ( ( $numargs = func_num_args() ) > 1) {
$string = "<?php\n\n";
//$arg_list = func_get_args();
foreach ($array as $key => $arg) {
//$vname = utils_vname ($arg);
//var_export($arg);
$s = /*" global {$key};\n*/ "\${$key} = " .
var_export($arg, true) . ";\n";
$string .= $s;
}
$string .= "\n?>";
return io_write_file($file, $string);
//} else die('Wrong number of parameters!');
}
function system_hashsalt_save($force=false) {
global $fp_config;
if ($force || !file_exists(HASHSALT_FILE))
return system_save(HASHSALT_FILE, array('fp_hashsalt'=>$fp_config['general']['blogid'] . ABS_PATH . BLOG_BASEURL .mt_rand()));
return true;
}
define('SYSTEM_VER', '0.704');
function system_ver() {
return 'fp-' . SYSTEM_VER;
}
function system_generate_id($string) {
return 'fp-'.dechex(crc32($string) ^ mt_rand());
}
function system_guessblogroot() {
return substr($_SERVER['REQUEST_URI'], 0,strrpos($_SERVER['REQUEST_URI'],'/')+1);
}
function system_guessbaseurl() {
return 'http://'.$_SERVER['HTTP_HOST']. BLOG_ROOT;
}
function system_getindex() {
if (MOD_BLOG != INDEX)
return MOD_BLOG;
else
return 'index.php';
}
function system_unregister_globals() {
$v = @ini_get('register_globals');
// on error we unregister anyway
if ($v || is_null($v)) {
foreach ($_REQUEST as $var => $val) {
unset($GLOBALS[$var]);
}
}
}
function system_sanitizequery() {
$err = false;
foreach ($_GET as $k => $v) {
if (preg_match('![<>]|://!', $v)) {
$err = true;
break;
}
}
if ($err) {
// @todo add log handler
utils_redirect();
}
}
function system_init() {
system_sanitizequery();
system_unregister_globals();
$GLOBALS['fpdb'] =& new FPDB;
$GLOBALS['fp_widgets'] =& new widget_indexer;
$GLOBALS['smarty'] =& $GLOBALS['_FP_SMARTY'];
$smarty =& $GLOBALS['smarty'];
$GLOBALS['fp_config'] =& config_load();
$GLOBALS['theme'] =& theme_loadsettings();
$GLOBALS['lang'] =& lang_load();
cookie_setup();
sess_setup();
user_loggedin();
plugin_loadall();
// init smarty
$smarty->compile_dir = CACHE_DIR;
$smarty->cache_dir = SMARTY_DIR . 'cache/';
$smarty->caching = 0;
do_action('init');
}
function system_seterr($module, $val) {
if ($module)
$elem = 'success_'.$module;
else
$elem = 'success';
sess_add($elem, $val);
}
function system_geterr($module='') {
if ($module)
$elem = 'success_'.$module;
else
$elem = 'success';
return sess_remove($elem);
}
/* delayed print */
function system_dpr($action, $content) {
$p = print_r($content,1);
$f = create_function('', "echo '<pre style=\'position:absolute\'>$p</pre>';");
add_action($action, $f);
}
?>