Possible fix for missing ext_notes while displaying extension tasks, TODOs.txt updated
[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         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_config` SET pass_scramble='%s' WHERE config=0 LIMIT 1",
55         array($scrambleString), __FILE__, __LINE__);
56
57         // Also remember it in config
58         setConfigEntry('pass_scramble', $scrambleString);
59         unset($scrambleString);
60 } // END - if
61
62 // Check if there is no master salt string
63 if (getConfig('master_salt') == '') {
64         // Generate the master salt which is the first chars minus 40 chars of this random hash
65         // We do an extra scrambling here...
66         $masterSalt = scrambleString(substr(sha1(generatePassword(mt_rand(128, 256))), 0, -40));
67
68         // ... and store it there for future usage
69         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_config` SET master_salt='%s' WHERE config=0 LIMIT 1",
70         array($masterSalt), __FILE__, __LINE__);
71
72         // Also remember it in config
73         setConfigEntry('master_salt', $masterSalt);
74         unset($masterSalt);
75 } // END - if
76
77 if (getConfig('file_hash') == '') {
78         // Create filename from hashed random string
79         $fileHash = sha1(generatePassword(mt_rand(128, 256)));
80         $FQFN = sprintf("%sinc/.secret/.%s",
81         constant('PATH'),
82         $fileHash
83         );
84
85         // Count of chars to be taken from back of the string
86         $nums = mt_rand(40, 45);
87
88         // Generate secret key from a randomized string
89         $secretKey = substr(sha1(generatePassword(mt_rand(128, 256))), -$nums);
90
91         // File hash was never created
92         writeToFile($FQFN, $secretKey);
93
94         // Is the file there?
95         if (isFileReadable($FQFN)) {
96                 //* DEBUG: */ removeFile($FQFN);
97                 //* DEBUG: */ $test = hexdec(getSession('u_hash')) / hexdec($secretKey);
98                 //* DEBUG: */ $test = generateHash(str_replace('.', '', $test));
99                 //* DEBUG: */ die("Secret-Key: ".$secretKey."<br />Cookie: ".getSession('u_hash')."<br />Test: ".$test);
100
101                 // Write $fileHash to database
102                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_config` SET file_hash='%s' WHERE config=0 LIMIT 1",
103                 array($fileHash), __FILE__, __LINE__);
104
105                 // Generate FQFN for .htaccess file
106                 $FQFN = sprintf("%sinc/.secret/.htaccess",
107                 constant('PATH')
108                 );
109
110                 // Is the .htaccess file there?
111                 if (!isFileReadable($FQFN)) {
112                         // Also create .htaccess file
113                         writeToFile($FQFN, "Deny from all\n");
114                 } // END - if
115
116                 // Also update configuration
117                 setConfigEntry('secret_key', $secretKey);
118                 setConfigEntry('file_hash' , $fileHash);
119
120                 // Remove variables
121                 unset($secretKey);
122                 unset($fileHash);
123         } // END - if
124 } // END - if
125
126 //
127 ?>