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