Was missing...
[mailer.git] / inc / gen_sql_patches.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 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 (!defined('__SECURITY')) {
41         die();
42 }
43
44 // Check for version of sql_patches
45 if (getExtensionVersion('sql_patches') < '0.3.6') return false;
46
47 // Check if there is no scrambling string
48 if (getConfig('pass_scramble') == '') {
49         // Generate 40 chars long scramble string
50         $scrambleString = genScrambleString(40);
51
52         // ... and store it there for future usage
53         updateConfiguration('pass_scramble', $scrambleString);
54
55         // Remove dummy string
56         unset($scrambleString);
57 } // END - if
58
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))));
64
65         // ... and store it there for future usage
66         updateConfiguration('master_salt', $masterSalt);
67
68         // Remove dummy string
69         unset($masterSalt);
70 } // END - if
71
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",
76                 getConfig('PATH'),
77                 $fileHash
78         );
79
80         // Generate secret key from a randomized string
81         $secretKey = sha1(generateHash(mt_rand(128, 256)));
82
83         // File hash was never created
84         writeToFile($FQFN, $secretKey);
85
86         // Is the file there?
87         if (isFileReadable($FQFN)) {
88                 //* DEBUG: */ removeFile($FQFN);
89                 //* DEBUG: */ $test = hexdec(getSession('u_hash')) / hexdec($secretKey);
90                 //* DEBUG: */ $test = generateHash(str_replace('.', '', $test));
91                 //* DEBUG: */ die("Secret-Key: ".$secretKey."<br />Cookie: ".getSession('u_hash')."<br />Test: ".$test);
92
93                 // Write $fileHash to database
94                 updateConfiguration('file_hash', $fileHash);
95
96                 // Generate FQFN for .htaccess file
97                 $FQFN = sprintf("%sinc/.secret/.htaccess",
98                         getConfig('PATH')
99                 );
100
101                 // Is the .htaccess file there?
102                 if (!isFileReadable($FQFN)) {
103                         // Also create .htaccess file
104                         writeToFile($FQFN, "Deny from all\n");
105                 } // END - if
106
107                 // Also update configuration
108                 setConfigEntry('secret_key', $secretKey);
109
110                 // Remove variables
111                 unset($secretKey);
112                 unset($fileHash);
113         } // END - if
114 } // END - if
115
116 //
117 ?>