]> git.mxchange.org Git - mailer.git/blob - inc/gen_sql_patches.php
Several more constants rewritten to getConfig()
[mailer.git] / inc / gen_sql_patches.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/08/2005 *
4  * ===============                              Last change: 01/01/2006 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Check for version of sql_patches
46 if (GET_EXT_VERSION('sql_patches') < '0.3.6') return false;
47
48 // Check if there is no scrambling string
49 if (getConfig('pass_scramble') == '') {
50         // Generate 40 chars long scramble string
51         $scrambleString = genScrambleString(40);
52
53         // ... and store it there for future usage
54         updateConfiguration('pass_scramble', $scrambleString);
55
56         // Remove dummy string
57         unset($scrambleString);
58 } // END - if
59
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))));
65
66         // ... and store it there for future usage
67         updateConfiguration('master_salt', $masterSalt);
68
69         // Remove dummy string
70         unset($masterSalt);
71 } // END - if
72
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",
77                 getConfig('PATH'),
78                 $fileHash
79         );
80
81         // Count of chars to be taken from back of the string
82         $nums = mt_rand(40, 45);
83
84         // Generate secret key from a randomized string
85         $secretKey = substr(sha1(generatePassword(mt_rand(128, 256))), -$nums);
86
87         // File hash was never created
88         writeToFile($FQFN, $secretKey);
89
90         // Is the file there?
91         if (isFileReadable($FQFN)) {
92                 //* DEBUG: */ removeFile($FQFN);
93                 //* DEBUG: */ $test = hexdec(getSession('u_hash')) / hexdec($secretKey);
94                 //* DEBUG: */ $test = generateHash(str_replace('.', '', $test));
95                 //* DEBUG: */ die("Secret-Key: ".$secretKey."<br />Cookie: ".getSession('u_hash')."<br />Test: ".$test);
96
97                 // Write $fileHash to database
98                 updateConfiguration('file_hash', $fileHash);
99
100                 // Generate FQFN for .htaccess file
101                 $FQFN = sprintf("%sinc/.secret/.htaccess",
102                         getConfig('PATH')
103                 );
104
105                 // Is the .htaccess file there?
106                 if (!isFileReadable($FQFN)) {
107                         // Also create .htaccess file
108                         writeToFile($FQFN, "Deny from all\n");
109                 } // END - if
110
111                 // Also update configuration
112                 setConfigEntry('secret_key', $secretKey);
113
114                 // Remove variables
115                 unset($secretKey);
116                 unset($fileHash);
117         } // END - if
118 } // END - if
119
120 //
121 ?>