2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/08/2005 *
4 * =================== Last change: 01/01/2006 *
6 * -------------------------------------------------------------------- *
7 * File : gen_sql_patches.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Patch password system after upgrading *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Patcht das Passwort-System nach DB-Update *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Check for version of sql_patches
46 if (getExtensionVersion('sql_patches') < '0.3.6') return false;
48 // Check if there is no scrambling string
49 if (getConfig('pass_scramble') == '') {
50 // Generate 40 chars long scramble string
51 $scrambleString = genScrambleString(40);
53 // ... and store it there for future usage
54 updateConfiguration('pass_scramble', $scrambleString);
56 // Remove dummy string
57 unset($scrambleString);
60 // Check if there is no master salt string
61 if (getConfig('master_salt') == '') {
62 // Generate the master salt which is the first chars minus 40 chars of this random hash
63 // We do an extra scrambling here...
64 $masterSalt = scrambleString(sha1(generatePassword(mt_rand(128, 256))));
66 // ... and store it there for future usage
67 updateConfiguration('master_salt', $masterSalt);
69 // Remove dummy string
73 if (getConfig('file_hash') == '') {
74 // Create filename from hashed random string
75 $fileHash = sha1(generatePassword(mt_rand(128, 256)));
76 $FQFN = sprintf("%sinc/.secret/.%s",
81 // Generate secret key from a randomized string
82 $secretKey = sha1(generateHash(mt_rand(128, 256)));
84 // File hash was never created
85 writeToFile($FQFN, $secretKey);
88 if (isFileReadable($FQFN)) {
89 //* DEBUG: */ removeFile($FQFN);
90 //* DEBUG: */ $test = hexdec(getSession('u_hash')) / hexdec($secretKey);
91 //* DEBUG: */ $test = generateHash(str_replace('.', '', $test));
92 //* DEBUG: */ die("Secret-Key: ".$secretKey."<br />Cookie: ".getSession('u_hash')."<br />Test: ".$test);
94 // Write $fileHash to database
95 updateConfiguration('file_hash', $fileHash);
97 // Generate FQFN for .htaccess file
98 $FQFN = sprintf("%sinc/.secret/.htaccess",
102 // Is the .htaccess file there?
103 if (!isFileReadable($FQFN)) {
104 // Also create .htaccess file
105 writeToFile($FQFN, "Deny from all\n");
108 // Also update configuration
109 setConfigEntry('secret_key', $secretKey);