]> git.mxchange.org Git - mailer.git/blob - inc/install-inc.php
Missing variable fixed, array initialization moved
[mailer.git] / inc / install-inc.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/29/2003 *
4  * ===================                          Last change: 11/11/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : install-inc.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for installation procedure             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer die Installationsroutine         *
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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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 /************************************************************************
39  *      YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION!        *
40  ************************************************************************/
41
42 // Some security stuff...
43 if (!defined('__SECURITY')) {
44         die();
45 } // END - if
46
47 // Load extension timezone
48 loadExtension('timezone', 'test');
49
50 // Set config entry
51 setConfigEntry('timezone', 'Europe/Berlin');
52
53 // And init timezone
54 FILTER_INIT_TIMEZONE();
55
56 // Init variables
57 $GLOBALS['install_mysql'] = array();
58 if ((isPostRequestParameterSet('mysql')) && (is_array(postRequestParameter('mysql')))) {
59         // Transfer 'mysql' array
60         $GLOBALS['install_mysql'] = postRequestParameter('mysql');
61 } // END - if
62
63 // Check if both passwords from SMTP are matching
64 if ((isGetRequestParameterSet('page') && (getRequestParameter('page') == 5))) {
65         // Okay, we have to check it
66         if (isPostRequestParameterSet('smtp_user') && (!isPostRequestParameterSet('smtp_host'))) {
67                 // Hostname not set
68                 addToInstallContent('<div class="para">{--INSTALL_SMTP_HOSTNAME_EMPTY--}</div>');
69                 setGetRequestParameter('page', 3);
70         } // END - if
71
72         if ((!isPostRequestParameterSet('smtp_pass1')) && (isPostRequestParameterSet('smtp_pass2'))) {
73                 // Password is empty
74                 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS1_EMPTY--}</div>');
75                 setGetRequestParameter('page', 3);
76         } // END - if
77
78         if ((isPostRequestParameterSet('smtp_pass1')) && (!isPostRequestParameterSet('smtp_pass2'))) {
79                 // Password repeat is empty
80                 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS2_EMPTY--}</div>');
81                 setGetRequestParameter('page', 3);
82         } // END - if
83
84         if (postRequestParameter('smtp_pass1') != postRequestParameter('smtp_pass1')) {
85                 // Passwords are not matching
86                 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS_MISMATCH--}</div>');
87                 setGetRequestParameter('page', 3);
88         } // END - if
89 } // END - if
90
91 // Is the mailer installed or no admin registered so far?
92 if ((!isInstalled()) || (!isAdminRegistered())) {
93         // Output page for entered value
94         switch (getRequestParameter('page')) {
95                 case 'welcome': // Welcome to the installation!
96                         addTemplateToInstallContent('install_welcome');
97                         break;
98
99                 case '1': // Server path, base URL
100                         // Load template
101                         addTemplateToInstallContent('install_page1');
102                         break;
103
104                 case '2': // Database login data
105                         if (empty($GLOBALS['install_mysql']['dbase']))  $GLOBALS['install_mysql']['dbase']  = 'your_database';
106                         if (empty($GLOBALS['install_mysql']['login']))  $GLOBALS['install_mysql']['login']  = 'your_login';
107                         if (empty($GLOBALS['install_mysql']['host']))   $GLOBALS['install_mysql']['host']   = 'localhost';
108                         if (empty($GLOBALS['install_mysql']['prefix'])) $GLOBALS['install_mysql']['prefix'] = 'mailer';
109                         if (empty($GLOBALS['install_mysql']['type']))   $GLOBALS['install_mysql']['type']   = 'MyISAM';
110                         if (ifFatalErrorsDetected()) {
111                                 addToInstallContent('<div class="install_fatal"><ul>');
112                                 foreach (getFatalArray() as $key => $err) {
113                                         addToInstallContent('<li> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '</li>');
114                                 } // END - foreach
115                                 addToInstallContent('</ol></div>');
116                         } // END - if
117
118                         $content['mysql_host']   = $GLOBALS['install_mysql']['host'];
119                         $content['mysql_dbase']  = $GLOBALS['install_mysql']['dbase'];
120                         $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
121                         $content['mysql_login']  = $GLOBALS['install_mysql']['login'];
122                         $content['table_type']   = $GLOBALS['install_mysql']['type'];
123                         $content['spath']        = postRequestParameter('spath');
124                         $content['burl']         = postRequestParameter('burl');
125                         $content['title']        = postRequestParameter('title');
126                         $content['slogan']       = postRequestParameter('slogan');
127                         $content['email']        = postRequestParameter('email');
128
129                         // Load template
130                         addTemplateToInstallContent('install_page2', $content);
131                         break;
132
133                 case '3':
134                         // Set more values
135                         $content['spath']      = postRequestParameter('spath');
136                         $content['burl']       = postRequestParameter('burl');
137                         $content['title']      = postRequestParameter('title');
138                         $content['slogan']     = postRequestParameter('slogan');
139                         $content['email']      = postRequestParameter('email');
140
141                         // Use default SMTP data
142                         $smtpHost  = '{?SMTP_HOSTNAME?}';
143                         $smtpUser  = '{?SMTP_USER?}';
144                         $smtpPass1 = '{?SMTP_PASSWORD?}';
145                         $smtpPass2 = '{?SMTP_PASSWORD?}';
146
147                         // Overwrite it with the data from sent (failed) form
148                         if (isPostRequestParameterSet('smtp_host')) $smtpHost = postRequestParameter('smtp_host');
149                         if (isPostRequestParameterSet('smtp_user')) $smtpUser = postRequestParameter('smtp_user');
150                         if (isPostRequestParameterSet('smtp_pass')) {
151                                 $smtpPass1 = postRequestParameter('smtp_pass');
152                                 $smtpPass2 = postRequestParameter('smtp_pass');
153                         } // END - if
154
155                         // Database login data
156                         $content['mysql_host']   = $GLOBALS['install_mysql']['host'];
157                         $content['mysql_dbase']  = $GLOBALS['install_mysql']['dbase'];
158                         $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
159                         $content['table_type']   = $GLOBALS['install_mysql']['type'];
160                         $content['mysql_login']  = $GLOBALS['install_mysql']['login'];
161                         $content['mysql_pass1']  = $GLOBALS['install_mysql']['pass1'];
162                         $content['mysql_pass2']  = $GLOBALS['install_mysql']['pass2'];
163
164                         // Set constants for SMTP data
165                         $content['smtp_host']  = $smtpHost;
166                         $content['smtp_user']  = $smtpUser;
167                         $content['smtp_pass1'] = $smtpPass1;
168                         $content['smtp_pass2'] = $smtpPass2;
169
170                         // Load template
171                         addTemplateToInstallContent('install_page3', $content);
172                         break;
173
174                 case '5': // Misc settings
175                         // General settings
176                         $content['spath']  = postRequestParameter('spath');
177                         $content['burl']   = postRequestParameter('burl');
178                         $content['title']  = postRequestParameter('title');
179                         $content['slogan'] = postRequestParameter('slogan');
180                         $content['email']  = postRequestParameter('email');
181
182                         // SMTP settings
183                         $content['smtp_host'] = postRequestParameter('smtp_host');
184                         $content['smtp_user'] = postRequestParameter('smtp_user');
185                         $content['smtp_pass'] = postRequestParameter('smtp_pass1');
186
187                         // Database login data
188                         $OUT = '';
189                         foreach ($GLOBALS['install_mysql'] as $key => $value) {
190                                 $OUT .= '    <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
191                         } // END - foreach
192                         $content['mysql_hidden'] = $OUT;
193
194                         // Load template
195                         addTemplateToInstallContent('install_page5', $content);
196                         break;
197
198                 case 'finalize': // Write captured data to files
199                         if ((isPostRequestParameterSet('finalize')) && (!isInstalled())) {
200                                 // You have submitted data then we have to reset the SQLs
201                                 initSqls();
202
203                                 // Restore PHPs error handler to prevent ours to handle errors,
204                                 // e.g. failed connection attempts. We want to handle them on
205                                 // our own.
206                                 restore_error_handler();
207
208                                 // Connect to database server
209                                 SQL_CONNECT($GLOBALS['install_mysql']['host'], $GLOBALS['install_mysql']['login'], $GLOBALS['install_mysql']['pass1'], __FILE__, __LINE__);
210
211                                 // Is the link up?
212                                 if (SQL_IS_LINK_UP()) {
213                                         // Seems to work, also right database?
214                                         if (SQL_SELECT_DB($GLOBALS['install_mysql']['dbase'], __FILE__, __LINE__) === true) {
215                                                 // Check for dumps
216                                                 if ((!isFileReadable(postRequestParameter('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestParameter('spath') . 'install/menu-'.getLanguage().'.sql'))) {
217                                                         // Installation area not found
218                                                         addFatalMessage(__FILE__, __LINE__, '{--INSTALL_MISSING_DUMPS--}');
219                                                         return;
220                                                 } // END - if
221
222                                                 // Any errors detected?
223                                                 if (!ifFatalErrorsDetected()) {
224                                                         // Set type and prefix from POST data
225                                                         setConfigEntry('_TABLE_TYPE'  , postRequestParameter('mysql', 'type'));
226                                                         setConfigEntry('_MYSQL_PREFIX', postRequestParameter('mysql', 'prefix'));
227
228                                                         // Both exists so import them
229                                                         foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
230                                                                 // Should be save here because file_exists() is there but we check it again. :)
231                                                                 $FQFN = postRequestParameter('spath') . 'install/' . $dump . '.sql';
232
233                                                                 // Is the file readable?
234                                                                 if (isFileReadable($FQFN)) {
235                                                                         // Read the file
236                                                                         $fileContent = readSqlDump($FQFN);
237
238                                                                         // Split it up against ";\n" and merge it into existing SQLs
239                                                                         mergeSqls(explode(";\n", $fileContent), 'install');
240                                                                 } else {
241                                                                         // Not readable!
242                                                                         debug_report_bug(__FILE__, __LINE__, sprintf("SQL dump %s is not readable!", $dump));
243                                                                 }
244                                                         } // END - foreach
245                                                         //* DEBUG: */ die(__FUNCTION__.'['.__LINE__.']:'<pre>'.print_r(getSqls(), true).'</pre>');
246
247                                                         // Are some SQLs found?
248                                                         if (countSqls() == 0) {
249                                                                 // Abort here
250                                                                 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_SQL_IMPORT_FAILED--}');
251                                                                 return;
252                                                         } // END - if
253
254                                                         // Now run all queries through and try to keep out empty or comment queries
255                                                         runFilterChain('run_sqls');
256
257                                                         // Copy the config template and verify it
258                                                         doInstallWriteLocalConfig();
259                                                 } // END - if
260                                         } // END - if
261                                 } // END - if
262
263                                 if (ifFatalErrorsDetected()) {
264                                         $OUT = '';
265                                         foreach (getFatalArray() as $value) {
266                                                 $OUT .= '    <li>' . $value . '</li>';
267                                         } // END foreach
268                                         $content['fatal_errors'] = $OUT;
269                                         $OUT = '';
270                                         foreach ($GLOBALS['install_mysql'] as $key => $value) {
271                                                 $OUT .= '    <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
272                                         } // END foreach
273                                         $content['mysql_hidden'] = $OUT;
274                                         $content['spath']      = postRequestParameter('spath');
275                                         $content['burl']       = postRequestParameter('burl');
276                                         $content['title']      = postRequestParameter('title');
277                                         $content['smtp_host']  = postRequestParameter('smtp_host');
278                                         $content['smtp_user']  = postRequestParameter('smtp_user');
279                                         $content['smtp_pass']  = postRequestParameter('smtp_pass1');
280
281                                         // Load template
282                                         addTemplateToInstallContent('install_fatal_errors', $content);
283
284                                         // We have handled all fatal errors here
285                                         initFatalMessages();
286                                 } else {
287                                         // Installation is done!
288                                         redirectToUrl('install.php?page=finished');
289                                 }
290                         } else {
291                                 // Something goes wrong during installation! :-(
292                                 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_FINALIZER_FAILED--}');
293                         }
294                         break;
295
296                 case 'finished':
297                         if (isInstalled()) {
298                                 // Load template that we are finished
299                                 addTemplateToInstallContent('install_finished');
300                         } else {
301                                 // Not finished
302                                 redirectToUrl('install.php');
303                         }
304                         break;
305
306                 default:
307                         logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestParameter('page')));
308                         addTemplateToInstallContent('admin_settings_unsaved', '{--WRONG_PAGE--}');
309                         break;
310         } // END - switch
311 } else {
312         // Already installed!
313         addFatalMessage(__FILE__, __LINE__, '{--ALREADY_INSTALLED--}');
314 }
315
316 // [EOF]
317 ?>