Added more wrapper, commented out another noisy debug line
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Check if there is no scrambling string
44 if (getPassScramble() == '') {
45         // Generate 40 chars long scramble string
46         $scrambleString = genScrambleString(40);
47
48         // ... and store it there for future usage
49         updateConfiguration('pass_scramble', $scrambleString);
50
51         // Remove dummy string
52         unset($scrambleString);
53 } // END - if
54
55 // Check if there is no master salt string
56 if (getMasterSalt() == '') {
57         // Generate the master salt which is the first chars minus 40 chars of this random hash
58         // We do an extra scrambling here...
59         $masterSalt = scrambleString(sha1(generatePassword(mt_rand(128, 256))));
60
61         // ... and store it there for future usage
62         updateConfiguration('master_salt', $masterSalt);
63
64         // Remove dummy string
65         unset($masterSalt);
66 } // END - if
67
68 if (getFileHash() == '') {
69         // Create filename from hashed random string
70         $fileHash = sha1(generatePassword(mt_rand(128, 256)));
71         $FQFN = sprintf("%s%s.%s.cache",
72                 getPath(),
73                 getCachePath(),
74                 $fileHash
75         );
76
77         // Generate secret key from a randomized string
78         $secretKey = sha1(generateHash(mt_rand(128, 256)));
79
80         // File hash was never created
81         writeToFile($FQFN, $secretKey);
82
83         // Is the file there?
84         if (isFileReadable($FQFN)) {
85                 // Also update configuration
86                 setConfigEntry('secret_key', $secretKey);
87                 updateConfiguration('file_hash', $fileHash);
88
89                 // Remove variables
90                 unset($secretKey);
91                 unset($fileHash);
92         } // END - if
93 } // END - if
94
95 // @TODO Rewrite this to a filter
96 if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isCacheInstanceValid())) {
97         // Destroy some cache files
98         foreach (array('config', 'extension', 'filter', 'modules')  as $cache) {
99                 // Is the cache file there?
100                 if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
101                         // Then remove it
102                         $GLOBALS['cache_instance']->removeCacheFile();
103                 } // END - if
104         } // END - foreach
105 } // END - if
106
107 // [EOF]
108 ?>