1e3f278d58127d0c9418dd1fe310293b86a2bd0d
[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 - 2013 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() == '') || (!isFileReadable(getGenericHashFileName()))) {
69         // Create filename from hashed random string
70         $fileHash = sha1(generatePassword(mt_rand(128, 256)));
71         $FQFN = sprintf('%s%s.%s%s',
72                 getPath(),
73                 getCachePath(),
74                 $fileHash,
75                 getCacheExtension()
76         );
77
78         // Generate secret key from a randomized string
79         $secretKey = sha1(generateHash(mt_rand(128, 256)));
80
81         // File hash was never created
82         writeToFile($FQFN, $secretKey);
83
84         // Is the file there?
85         if (isFileReadable($FQFN)) {
86                 // Also update configuration
87                 setConfigEntry('secret_key', $secretKey);
88
89                 // Force update
90                 updateConfiguration('file_hash', $fileHash, '', '0', TRUE);
91
92                 // Remove variables
93                 unset($secretKey);
94                 unset($fileHash);
95         } // END - if
96 } // END - if
97
98 // @TODO Rewrite this to a filter
99 if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isValidCacheInstance())) {
100         // Destroy some cache files
101         foreach (array('config', 'extension', 'filter', 'modules') as $cache) {
102                 // Use rebuildCache()
103                 rebuildCache($cache);
104         } // END - foreach
105 } // END - if
106
107 // [EOF]
108 ?>