X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=bc7aa6bad76029a765d1aedc32cb1c281c7ac4ec;hp=e68db149d1bfdfdc203fc6d9f24d6723ed066fe6;hb=f23709a2e9afa25b4bf3b732155fec667fbc1a2a;hpb=971c31241c59b933d563f712a893b0c54ad33557 diff --git a/inc/functions.php b/inc/functions.php index e68db149d1..bc7aa6bad7 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -88,7 +88,7 @@ function getTotalFatalErrors () { function generatePassword ($length = '0', $exclude = array()) { // Auto-fix invalid length of zero if ($length == '0') { - $length = getPassLen(); + $length = getMinPasswordLength(); } // END - if // Exclude some entries @@ -952,7 +952,7 @@ function encodeHashForCookie ($passHash) { // Fix "deleted" cookies function fixDeletedCookies ($cookies) { // Is this an array with entries? - if ((is_array($cookies)) && (count($cookies) > 0)) { + if (isFilledArray($cookies)) { // Then check all cookies if they are marked as deleted! foreach ($cookies as $cookieName) { // Is the cookie set to "deleted"? @@ -1530,7 +1530,7 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("cache=%s, inc=%s, force=%s", $cache, $inc, intval($force))); // Shall I remove the cache file? - if ((isExtensionInstalled('cache')) && (isCacheInstanceValid()) && (isHtmlOutputMode())) { + if ((isExtensionInstalled('cache')) && (isValidCacheInstance()) && (isHtmlOutputMode())) { // Rebuild cache only in HTML output-mode // @TODO This should be rewritten not to load the cache file for just checking if it is there for save removal. if ($GLOBALS['cache_instance']->loadCacheFile($cache)) { @@ -1541,7 +1541,7 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) { // Include file given? if (!empty($inc)) { // Construct FQFN - $inc = sprintf("inc/loader/load-%s.php", $inc); + $inc = sprintf('inc/loader/load-%s.php', $inc); // Is the include there? if (isIncludeReadable($inc)) { @@ -1549,8 +1549,8 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'inc=' . $inc . ' - LOADED!'); loadInclude($inc); } else { - // Include not found - logDebugMessage(__FUNCTION__, __LINE__, 'Include ' . $inc . ' not found. cache=' . $cache); + // Include not found, which needs now tracing + reportBug(__FUNCTION__, __LINE__, 'Include ' . $inc . ' not found. cache=' . $cache); } } // END - if } // END - if @@ -1682,6 +1682,21 @@ function doMonthly () { } // END - if } +// Enables the yearly reset mode and runs it +function doYearly () { + // Enable the reset mode + $GLOBALS['yearly_enabled'] = TRUE; + + // Run filters + runFilterChain('yearly'); + + // Do not update in yearly debug mode + if ((!isConfigEntrySet('DEBUG_YEARLY')) || (!isDebugYearlyEnabled())) { + // Update database + updateConfiguration('last_yearly', getYear()); + } // END - if +} + // Shuts down the mailer (e.g. closing database link, flushing output/filters, etc.) function doShutdown () { // Call the filter chain 'shutdown' @@ -1691,7 +1706,7 @@ function doShutdown () { if (isSqlLinkUp()) { // Close link sqlCloseLink(__FUNCTION__, __LINE__); - } elseif (!isInstallationPhase()) { + } elseif (!isInstaller()) { // No database link reportBug(__FUNCTION__, __LINE__, 'Database link is already down, while shutdown is running.'); } @@ -1865,7 +1880,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $ad // We found .php file but should not search for them, why? reportBug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script. (baseFile=' . $baseFile . ')'); } - } elseif (($fileExtension == $extension) || (empty($extension))) { + } elseif ((($fileExtension == $extension) || (empty($extension))) && (isFileReadable($FQFN))) { // Other, generic file found if ($addBaseDir === TRUE) { // With base path @@ -2027,7 +2042,7 @@ function encodeUrl ($url, $outputMode = '0') { } // END - if // Is there a valid session? - if ((!isSessionValid()) && (!isSpider())) { + if ((!isValidSession()) && (!isSpider())) { // Determine right separator $separator = '&'; if (!isInString('?', $url)) { @@ -2144,7 +2159,7 @@ function handleFieldWithBraces ($field) { // Converts a zero or NULL to word 'NULL' function convertZeroToNull ($number) { // Is it a valid username? - if ((!is_null($number)) && (!empty($number)) && ($number > 0)) { + if (isValidNumber($number)) { // Always secure it $number = bigintval($number); } else { @@ -2159,7 +2174,7 @@ function convertZeroToNull ($number) { // Converts a NULL|empty string|< 1 to zero function convertNullToZero ($number) { // Is it a valid username? - if ((is_null($number)) || (empty($number)) || ($number < 1)) { + if (!isValidNumber($number)) { // Is not valid or zero $number = '0'; } // END - if @@ -2694,6 +2709,22 @@ function convertCharsetToUtf8 ($str, $charset) { return $str; } +// Hash string with SHA256 and encode it to hex +function hashSha256 ($str) { + /// Hash string + $hash = mhash(MHASH_SHA256, $str); + + // Encode it to hexadecimal + $hex = ''; + for ($i = 0; $i < strlen($hash); $i++) { + // Encode char to decimal, pad it with zero, add it + $hex .= padLeftZero(dechex(ord(substr($hash, $i, 1)))); + } // END - if + + // Return it + return $hex; +} + // ---------------------------------------------------------------------------- // "Translatation" functions for points_data table // ---------------------------------------------------------------------------- @@ -2797,5 +2828,66 @@ if (!function_exists('html_entity_decode')) { } } // END - if +// "Calculates" password strength +function calculatePasswordStrength ($password, $configEntry = 'min_password_length') { + // Default score + $score = 1; + + if ((strlen($password) < 1) || (strlen($password) < getConfig($configEntry))) { + // Is to weak + return 0; + } // END - if + + // At least 8 chars long? + if (strlen($password) >= 8) { + // Add score + $score++; + } // END - if + + // At least 10 chars long? + if (strlen($password) >= 10) { + // Add score + $score++; + } // END - if + + // Lower and upper cases? + if ((preg_match('/[a-z]/', $password)) && (preg_match('/[A-Z]/', $password))) { + // Add score + $score++; + } // END - if + + // Also numbers? + if (preg_match('/[0-9]/', $password)) { + // Add score + $score++; + } // END - if + + // Special characters? + if (preg_match('/.[!,@,#,$,%,^,&,*,?,\/,_,~,+,-,(,)]/', $password)) { + // Add score + $score++; + } // END - if + + // Return password score + return $score; +} + +// "Translates" password strength/score +function translatePasswordStrength ($strength) { + // Return it translated + return '{--PASSWORD_SCORE_' . bigintval($strength) . '--}'; +} + +// Checks whether given password is strong enough +function isStrongPassword ($password) { + // Determine it + return (calculatePasswordStrength($password) >= getConfig('min_password_score')); +} + +// "Getter" for base path from theme +function getBasePathFromTheme ($theme) { + return sprintf('%stheme/%s/css/', getPath(), $theme); +} + // [EOF] ?>