X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fgen_sql_patches.php;h=4baf15fa48f0eb3f962e7c80bcfc7f402a279a1e;hp=2e59c8da538be64c34d2e16e8f7cfc4c727628e7;hb=9dea40187dc40c8e2b642dccae039c681cbc43f9;hpb=feebd0199748544fe8c930b70e97452001a13f76 diff --git a/inc/gen_sql_patches.php b/inc/gen_sql_patches.php index 2e59c8da53..4baf15fa48 100644 --- a/inc/gen_sql_patches.php +++ b/inc/gen_sql_patches.php @@ -1,7 +1,7 @@ Cookie: ".get_session('u_hash')."
Test: ".$test); - - // Write $file_hash to database - $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_config SET file_hash='%s' WHERE config=0 LIMIT 1", - array($file_hash), __FILE__, __LINE__); - - // Also create .htaccess file - $fp = @fopen(PATH."inc/.secret/.htaccess", 'w') or mxchange_die("Cannot write to .htaccess file!"); - if ($fp != false) - { - // Add deny line to file - fwrite($fp, "Deny from all"); - - // Close the file - fclose($fp); - } - - // Also update configuration - $_CONFIG['secret_key'] = $secretKey; unset($secretKey); - $_CONFIG['file_hash'] = $file_hash; unset($file_hash); - } -} + // Remove dummy string + unset($scrambleString); +} // END - if + +// Check if there is no master salt string +if (getConfig('master_salt') == '') { + // Generate the master salt which is the first chars minus 40 chars of this random hash + // We do an extra scrambling here... + $masterSalt = scrambleString(sha1(generatePassword(mt_rand(128, 256)))); + + // ... and store it there for future usage + updateConfiguration('master_salt', $masterSalt); + + // Remove dummy string + unset($masterSalt); +} // END - if + +if (getConfig('file_hash') == '') { + // Create filename from hashed random string + $fileHash = sha1(generatePassword(mt_rand(128, 256))); + $FQFN = sprintf("%sinc/.secret/.%s", + getConfig('PATH'), + $fileHash + ); + + // Generate secret key from a randomized string + $secretKey = sha1(generateHash(mt_rand(128, 256))); + + // File hash was never created + writeToFile($FQFN, $secretKey); + + // Is the file there? + if (isFileReadable($FQFN)) { + //* DEBUG: */ removeFile($FQFN); + //* DEBUG: */ $test = hexdec(getSession('u_hash')) / hexdec($secretKey); + //* DEBUG: */ $test = generateHash(str_replace('.', '', $test)); + //* DEBUG: */ die("Secret-Key: ".$secretKey."
Cookie: ".getSession('u_hash')."
Test: ".$test); + + // Write $fileHash to database + updateConfiguration('file_hash', $fileHash); + + // Generate FQFN for .htaccess file + $FQFN = sprintf("%sinc/.secret/.htaccess", + getConfig('PATH') + ); + + // Is the .htaccess file there? + if (!isFileReadable($FQFN)) { + // Also create .htaccess file + writeToFile($FQFN, "Deny from all\n"); + } // END - if + + // Also update configuration + setConfigEntry('secret_key', $secretKey); + + // Remove variables + unset($secretKey); + unset($fileHash); + } // END - if +} // END - if // ?> \ No newline at end of file