X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=4733b66422ba70a677c7b9a6eeb43bbb011604d6;hp=d9a2388fcb08bff8c790d39f182ef296fb475c5c;hb=41e2891fb998d13b22b8d7984358f258cc85267d;hpb=b80ee4c24c8786ed4098d9e3526fe78da0e73c0b
diff --git a/inc/functions.php b/inc/functions.php
index d9a2388fcb..4733b66422 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -899,7 +899,7 @@ function LOAD_URL($URL, $addUrlData=true) {
print("
");
debug_print_backtrace();
die("
URL={$URL}");
- */
+ /**/
@header ("Location: ".str_replace("&", "&", $URL));
} else {
// Output error message
@@ -1182,6 +1182,7 @@ function GEN_RANDOM_CODE($length, $code, $uid, $DATA="") {
// At least 10 numbers shall be secure enought!
$len = $_CONFIG['code_length'];
+ if ($len == 0) $len = $length;
if ($len == 0) $len = 10;
// Cut off requested counts of number
@@ -1939,11 +1940,11 @@ function generateHash ($plainText, $salt = "") {
// Generate SHA1 sum from modula of number and the prime number
$sha1 = sha1(($a % _PRIME).$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a);
- //* DEBUG: */ echo "SHA1=".$sha1." (".strlen($sha1).")
";
+ //* DEBUG: */ echo "SHA1=".$sha1." (".strlen($sha1).")
";
$sha1 = scrambleString($sha1);
- //* DEBUG: */ echo "Scrambled=".$sha1." (".strlen($sha1).")
";
+ //* DEBUG: */ echo "Scrambled=".$sha1." (".strlen($sha1).")
";
//* DEBUG: */ $sha1b = descrambleString($sha1);
- //* DEBUG: */ echo "Descrambled=".$sha1b." (".strlen($sha1b).")
";
+ //* DEBUG: */ echo "Descrambled=".$sha1b." (".strlen($sha1b).")
";
// Generate the password salt string
$salt = substr($sha1, 0, $_CONFIG['salt_length']);
@@ -2096,12 +2097,12 @@ function generatePassString($passHash) {
}
$mod = substr(round($mod), 0, 4);
$mod = str_repeat('0', 4-strlen($mod)).$mod;
- //* DEBUG: */ echo "*".$start."=".$mod."*
";
+ //* DEBUG: */ echo "*".$start."=".$mod."*
";
$start += 4;
$newHash .= $mod;
} // END - for
- //* DEBUG: */ print($passHash."
".$newHash." (".strlen($newHash).")");
+ //* DEBUG: */ print($passHash."
".$newHash." (".strlen($newHash).")");
$ret = generateHash($newHash, $_CONFIG['master_salt']);
//* DEBUG: */ print($ret."
\n");
} else {
@@ -2195,28 +2196,43 @@ function set_session ($var, $value) {
return session_register($var);
} elseif (!empty($value)) {
// Update session
+ //* DEBUG: */ echo "UPDATE:".$var."=".$value."
\n";
$_SESSION[$var] = $value;
- } else {
- // Something bad happens!
- return false; // Hope this doesn't make so much trouble???
+ return true;
}
- // Return always true if the session variable is already set.
- // Keept me busy for a longer while...
+ // Ignored (but valid)
//* DEBUG: */ echo "IGNORED:".$var."=".$value."
\n";
return true;
}
// Check wether a boolean constant is set
// Taken from user comments in PHP documentation for function constant()
-function isBooleanConstantAndTrue($constname) { // : Boolean
+function isBooleanConstantAndTrue($constName) { // : Boolean
+ global $constCache;
+
+ // Failed by default
$res = false;
- if (defined($constname)) $res = (constant($constname) === true);
- return($res);
+
+ // In cache?
+ if (isset($constCache[$constName])) {
+ // Use cache
+ $res = $constCache[$constName];
+ } else {
+ // Check constant
+ if (defined($constName)) $res = (constant($constName) === true);
+
+ // Set cache
+ $constCache[$constName] = $res;
+ }
+
+ // Return value
+ return $res;
}
// Check wether a session variable is set
function isSessionVariableSet($var) {
+ //* DEBUG: */ echo __FUNCTION__.":var={$var}
\n";
return (isset($_SESSION[$var]));
}
// Returns wether the value of the session variable or NULL if not set
@@ -2289,6 +2305,7 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
$file = $baseDir.$baseFile;
// Is this a valid reset file?
+ //* DEBUG: */ echo __FUNCTION__.":baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}
\n";
if ((is_file($file)) && (is_readable($file)) && (substr($baseFile, 0, strlen($prefix)) == $prefix) && (substr($baseFile, -4, 4) == ".php")) {
// Remove both for extension name
$extName = substr($baseFile, strlen($prefix), -4);
@@ -2300,6 +2317,9 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
// Then add this file
$INCs[] = $file;
+ } elseif ($extId == 0) {
+ // Add non-extension files as well
+ $INCs[] = $file;
}
} // END - if
} // END - while
@@ -2419,9 +2439,75 @@ function CONVERT_SELECTIONS_TO_TIMESTAMP(&$POST, &$DATA, &$id, &$skip) {
}
// Reverts the german decimal comma into Computer decimal dot
function REVERT_COMMA ($str) {
- $float = (float)str_replace(",", ".", $str);
+ // Default float is not a float... ;-)
+ $float = false;
+
+ // Which language is selected?
+ switch (GET_LANGUAGE()) {
+ case "de": // German language
+ // Remove german thousand dots first
+ $str = str_replace(".", "", $str);
+
+ // Replace german commata with decimal dot and cast it
+ $float = (float)str_replace(",", ".", $str);
+ break;
+
+ default: // US and so on
+ // Remove thousand dots first and cast
+ $float = (float)str_replace(",", "", $str);
+ break;
+ }
+
+ // Return float
return $float;
}
+// Handle menu-depending failed logins and return the rendered content
+function HANDLE_LOGIN_FAILTURES ($accessLevel) {
+ // Default output is empty ;-)
+ $OUT = "";
+
+ // Is the session data set?
+ if ((isSessionVariableSet('mxchange_'.$accessLevel.'_failtures')) && (isSessionVariableSet('mxchange_'.$accessLevel.'_last_fail'))) {
+ // Ignore zero values
+ if (get_session('mxchange_'.$accessLevel.'_failtures') > 0) {
+ // Non-guest has login failtures found, get both data and prepare it for template
+ //* DEBUG: */ echo __FUNCTION__.":accessLevel={$accessLevel}
\n";
+ $content = array(
+ 'login_failtures' => get_session('mxchange_'.$accessLevel.'_failtures'),
+ 'last_failture' => MAKE_DATETIME(get_session('mxchange_'.$accessLevel.'_last_fail'), "2")
+ );
+
+ // Load template
+ $OUT = LOAD_TEMPLATE("login_failtures", true, $content);
+ } // END - if
+
+ // Reset session data
+ set_session('mxchange_'.$accessLevel.'_failtures', "");
+ set_session('mxchange_'.$accessLevel.'_last_fail', "");
+ } // END - if
+
+ // Return rendered content
+ return $OUT;
+}
+// Rebuild cache
+function REBUILD_CACHE ($cache, $inc="") {
+ global $cacheInstance;
+
+ // Shall I remove the cache file?
+ if ((EXT_IS_ACTIVE("cache")) && (is_object($cacheInstance))) {
+ // Rebuild cache
+ if ($cacheInstance->cache_file("admins", true)) {
+ // Destroy it
+ $cacheInstance->cache_destroy();
+
+ // Include file given?
+ if (!empty($inc)) {
+ // And rebuild it from scratch
+ require_once(PATH."inc/loader/load_cache-".$inc.".php");
+ } // END - if
+ } // END - if
+ } // END - if
+}
//
//////////////////////////////////////////////////
// //