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