2 /************************************************************************
3 * MXChange v0.2.1 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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Check for version of sql_patches
45 if (getExtensionVersion('sql_patches') < '0.3.6') return false;
47 // Check if there is no scrambling string
48 if (getConfig('pass_scramble') == '') {
49 // Generate 40 chars long scramble string
50 $scrambleString = genScrambleString(40);
52 // ... and store it there for future usage
53 updateConfiguration('pass_scramble', $scrambleString);
55 // Remove dummy string
56 unset($scrambleString);
59 // Check if there is no master salt string
60 if (getConfig('master_salt') == '') {
61 // Generate the master salt which is the first chars minus 40 chars of this random hash
62 // We do an extra scrambling here...
63 $masterSalt = scrambleString(sha1(generatePassword(mt_rand(128, 256))));
65 // ... and store it there for future usage
66 updateConfiguration('master_salt', $masterSalt);
68 // Remove dummy string
72 if (getConfig('file_hash') == '') {
73 // Create filename from hashed random string
74 $fileHash = sha1(generatePassword(mt_rand(128, 256)));
75 $FQFN = sprintf("%sinc/.secret/.%s",
80 // Count of chars to be taken from back of the string
81 $nums = mt_rand(40, 45);
83 // Generate secret key from a randomized string
84 $secretKey = substr(sha1(generatePassword(mt_rand(128, 256))), -$nums);
86 // File hash was never created
87 writeToFile($FQFN, $secretKey);
90 if (isFileReadable($FQFN)) {
91 //* DEBUG: */ removeFile($FQFN);
92 //* DEBUG: */ $test = hexdec(getSession('u_hash')) / hexdec($secretKey);
93 //* DEBUG: */ $test = generateHash(str_replace('.', '', $test));
94 //* DEBUG: */ die("Secret-Key: ".$secretKey."<br />Cookie: ".getSession('u_hash')."<br />Test: ".$test);
96 // Write $fileHash to database
97 updateConfiguration('file_hash', $fileHash);
99 // Generate FQFN for .htaccess file
100 $FQFN = sprintf("%sinc/.secret/.htaccess",
104 // Is the .htaccess file there?
105 if (!isFileReadable($FQFN)) {
106 // Also create .htaccess file
107 writeToFile($FQFN, "Deny from all\n");
110 // Also update configuration
111 setConfigEntry('secret_key', $secretKey);