2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/29/2003 *
4 * =================== Last change: 11/11/2004 *
6 * -------------------------------------------------------------------- *
7 * File : install-inc.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for installation procedure *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer die Installationsroutine *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
36 ************************************************************************/
38 /************************************************************************
39 * YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION! *
40 ************************************************************************/
42 // Some security stuff...
43 if (!defined('__SECURITY')) {
47 // Load extension timezone
48 loadExtension('timezone', 'test');
51 setConfigEntry('timezone', 'Europe/Berlin');
54 FILTER_INIT_TIMEZONE();
57 $GLOBALS['install_mysql'] = array();
58 if ((isPostRequestParameterSet('mysql')) && (is_array(postRequestParameter('mysql')))) {
59 // Transfer 'mysql' array
60 $GLOBALS['install_mysql'] = postRequestParameter('mysql');
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'))) {
68 addToInstallContent('<div class="para">{--INSTALL_SMTP_HOSTNAME_EMPTY--}</div>');
69 setGetRequestParameter('page', 3);
72 if ((!isPostRequestParameterSet('smtp_pass1')) && (isPostRequestParameterSet('smtp_pass2'))) {
74 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS1_EMPTY--}</div>');
75 setGetRequestParameter('page', 3);
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);
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);
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');
99 case '1': // Server path, base URL
101 addTemplateToInstallContent('install_page1');
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>');
115 addToInstallContent('</ol></div>');
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');
130 addTemplateToInstallContent('install_page2', $content);
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');
141 // Use default SMTP data
142 $smtpHost = '{?SMTP_HOSTNAME?}';
143 $smtpUser = '{?SMTP_USER?}';
144 $smtpPass1 = '{?SMTP_PASSWORD?}';
145 $smtpPass2 = '{?SMTP_PASSWORD?}';
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');
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'];
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;
171 addTemplateToInstallContent('install_page3', $content);
174 case '5': // Misc 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');
183 $content['smtp_host'] = postRequestParameter('smtp_host');
184 $content['smtp_user'] = postRequestParameter('smtp_user');
185 $content['smtp_pass'] = postRequestParameter('smtp_pass1');
187 // Database login data
189 foreach ($GLOBALS['install_mysql'] as $key => $value) {
190 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
192 $content['mysql_hidden'] = $OUT;
195 addTemplateToInstallContent('install_page5', $content);
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
203 // Restore PHPs error handler to prevent ours to handle errors,
204 // e.g. failed connection attempts. We want to handle them on
206 restore_error_handler();
208 // Connect to database server
209 SQL_CONNECT($GLOBALS['install_mysql']['host'], $GLOBALS['install_mysql']['login'], $GLOBALS['install_mysql']['pass1'], __FILE__, __LINE__);
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) {
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--}');
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'));
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';
233 // Is the file readable?
234 if (isFileReadable($FQFN)) {
236 $fileContent = readSqlDump($FQFN);
238 // Split it up against ";\n" and merge it into existing SQLs
239 mergeSqls(explode(";\n", $fileContent), 'install');
242 debug_report_bug(__FILE__, __LINE__, sprintf("SQL dump %s is not readable!", $dump));
245 //* DEBUG: */ die(__FUNCTION__.'['.__LINE__.']:'<pre>'.print_r(getSqls(), true).'</pre>');
247 // Are some SQLs found?
248 if (countSqls() == 0) {
250 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_SQL_IMPORT_FAILED--}');
254 // Now run all queries through and try to keep out empty or comment queries
255 runFilterChain('run_sqls');
257 // Copy the config template and verify it
258 doInstallWriteLocalConfig();
263 if (ifFatalErrorsDetected()) {
265 foreach (getFatalArray() as $value) {
266 $OUT .= ' <li>' . $value . '</li>';
268 $content['fatal_errors'] = $OUT;
270 foreach ($GLOBALS['install_mysql'] as $key => $value) {
271 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
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');
282 addTemplateToInstallContent('install_fatal_errors', $content);
284 // We have handled all fatal errors here
287 // Installation is done!
288 redirectToUrl('install.php?page=finished');
291 // Something goes wrong during installation! :-(
292 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_FINALIZER_FAILED--}');
298 // Load template that we are finished
299 addTemplateToInstallContent('install_finished');
302 redirectToUrl('install.php');
307 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestParameter('page')));
308 addTemplateToInstallContent('admin_settings_unsaved', '{--WRONG_PAGE--}');
312 // Already installed!
313 addFatalMessage(__FILE__, __LINE__, '{--ALREADY_INSTALLED--}');