2 /************************************************************************
3 * MXChange v0.2.1 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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 /************************************************************************
35 * YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION! *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
46 if ((REQUEST_ISSET_POST(('mysql'))) && (is_array(REQUEST_POST('mysql')))) $mysql = REQUEST_POST('mysql');
48 // Check if both passwords from SMTP are matching
49 if ((REQUEST_ISSET_GET(('page')) && (REQUEST_GET('page') == 5))) {
50 // Okay, we have to check it
51 if (REQUEST_ISSET_POST(('smtp_user')) && (!REQUEST_ISSET_POST(('smtp_host')))) {
53 OUTPUT_HTML(getMessage('INSTALL_SMTP_HOSTNAME_EMPTY')."<br />");
54 REQUEST_SET_GET('page', 3);
57 if ((!REQUEST_ISSET_POST(('smtp_pass1'))) && (REQUEST_ISSET_POST(('smtp_pass2')))) {
59 OUTPUT_HTML(getMessage('INSTALL_SMTP_PASS1_EMPTY')."<br />");
60 REQUEST_SET_GET('page', 3);
63 if ((REQUEST_ISSET_POST(('smtp_pass1'))) && (!REQUEST_ISSET_POST(('smtp_pass2')))) {
64 // Password repeat is empty
65 OUTPUT_HTML(getMessage('INSTALL_SMTP_PASS2_EMPTY')."<br />");
66 REQUEST_SET_GET('page', 3);
69 if (REQUEST_POST('smtp_pass1') != REQUEST_POST('smtp_pass1')) {
70 // Passwords are not matching
71 OUTPUT_HTML(getMessage('INSTALL_SMTP_PASS_MISMATCH')."<br />");
72 REQUEST_SET_GET('page', 3);
76 // Is MXChange installed or no admin registered so far?
77 if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndTrue('admin_registered')))
79 // Set URL for FORM actions
80 define('__BURL_ACTION', constant('URL'));
82 // Output page for entered value
83 switch (REQUEST_GET('page'))
85 case "welcome": // Welcome to the installation!
86 LOAD_TEMPLATE("install_welcome");
89 case "1": // Server path, base URL
90 // @Profi-Concept: Hab meine Meinung doch geaendert! :-)
92 LOAD_TEMPLATE("install_page1");
95 case "2": // MySQL data (alone!)
96 if (empty($mysql['dbase'])) $mysql['dbase'] = "your_database";
97 if (empty($mysql['login'])) $mysql['login'] = "your_login";
98 if (empty($mysql['host'])) $mysql['host'] = "localhost";
99 if (empty($mysql['prefix'])) $mysql['prefix'] = "mxchange_";
100 if (getTotalFatalErrors() > 0) {
101 OUTPUT_HTML("<span class=\"install_fatal\">");
102 foreach (getFatalArray() as $key => $err) {
103 OUTPUT_HTML(" <strong>·</strong> {--FATAL_NO--}".($key + 1).": ".$err."<br />");
105 OUTPUT_HTML("</span><br />");
107 define('__MYSQL_HOST' , $mysql['host']);
108 define('__MYSQL_DBASE' , $mysql['dbase']);
109 define('__MYSQL_PREFIX', $mysql['prefix']);
110 define('__MYSQL_LOGIN' , $mysql['login']);
111 define('__SPATH_VALUE' , REQUEST_POST('spath'));
112 define('__BURL_VALUE' , REQUEST_POST('burl'));
113 define('__TITLE_VALUE' , REQUEST_POST('title'));
114 define('__SLOGAN_VALUE', REQUEST_POST('slogan'));
115 define('__EMAIL_VALUE' , REQUEST_POST('email'));
118 LOAD_TEMPLATE("install_page2");
123 define('__SPATH_VALUE' , REQUEST_POST('spath'));
124 define('__BURL_VALUE' , REQUEST_POST('burl'));
125 define('__TITLE_VALUE' , REQUEST_POST('title'));
126 define('__SLOGAN_VALUE' , REQUEST_POST('slogan'));
127 define('__EMAIL_VALUE' , REQUEST_POST('email'));
129 // Use default SMTP data
130 $smtpHost = constant('SMTP_HOSTNAME');
131 $smtpUser = constant('SMTP_USER');
132 $smtpPass1 = constant('SMTP_PASSWORD');
133 $smtpPass2 = constant('SMTP_PASSWORD');
135 // Overwrite it with the data from sent (failed) form
136 if (REQUEST_ISSET_POST(('smtp_host'))) $smtpHost = REQUEST_POST('smtp_host');
137 if (REQUEST_ISSET_POST(('smtp_user'))) $smtpUser = REQUEST_POST('smtp_user');
140 define('__MYSQL_HOST' , $mysql['host']);
141 define('__MYSQL_DBASE' , $mysql['dbase']);
142 define('__MYSQL_PREFIX' , $mysql['prefix']);
143 define('__MYSQL_LOGIN' , $mysql['login']);
144 define('__MYSQL_PASS1' , $mysql['pass1']);
145 define('__MYSQL_PASS2' , $mysql['pass2']);
147 // Set constants for SMTP data
148 define('__SMTP_HOST' , $smtpHost);
149 define('__SMTP_USER' , $smtpUser);
150 define('__SMTP_PASS1' , $smtpPass1);
151 define('__SMTP_PASS2' , $smtpPass2);
154 LOAD_TEMPLATE("install_page3");
157 case "5": // Misc settings
159 define('__SPATH_VALUE' , REQUEST_POST('spath'));
160 define('__BURL_VALUE' , REQUEST_POST('burl'));
161 define('__TITLE_VALUE' , REQUEST_POST('title'));
162 define('__SLOGAN_VALUE' , REQUEST_POST('slogan'));
163 define('__EMAIL_VALUE' , REQUEST_POST('email'));
166 define('__MYSQL_HOST' , $mysql['host']);
167 define('__MYSQL_DBASE' , $mysql['dbase']);
168 define('__MYSQL_PREFIX' , $mysql['prefix']);
169 define('__MYSQL_LOGIN' , $mysql['login']);
172 define('__SMTP_HOST' , REQUEST_POST('smtp_host'));
173 define('__SMTP_USER' , REQUEST_POST('smtp_user'));
174 define('__SMTP_PASS' , REQUEST_POST('smtp_pass1'));
175 OUTPUT_HTML("<form action=\"{!__BURL_ACTION!}/install.php?page=finalize\" method=\"POST\" target=\"_self\">
176 <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"install_content\">
178 <td colspan=\"2\" align=\"center\">
179 <div class=\"install\">{--HEADER_TEXT_PAGE5--}</strong>
182 <tr><td colspan=\"2\" height=\"21\" class=\"seperator\"> </td></tr>
184 <td colspan=\"2\"><span class=\"install_intro\">
188 <tr><td colspan=\"2\" height=\"21\" class=\"seperator\"> </td></tr>
190 <td class=\"install\" align=\"right\">{--LANG_OUTPUT_MODE--}: </td>
192 <select name=\"omode\" size=\"1\" class=\"install_select\">
193 <option value=\"render\"");
194 if (constant('OUTPUT_MODE') == "render") OUTPUT_HTML(" selected=\"selected\"");
195 OUTPUT_HTML(">{--MODE_RENDER--}</option>
196 <option value=\"direct\"");
197 if (constant('OUTPUT_MODE') == "direct") OUTPUT_HTML(" selected=\"selected\"");
198 OUTPUT_HTML(">{--MODE_DIRECT--}</option>
202 <tr><td colspan=\"2\" height=\"10\" class=\"seperator\"> </td></tr>
204 <td class=\"install\" align=\"right\">{--WARN_NO_PASSWORD--}: </td>
206 <select name=\"warn_no_pass\" size=\"1\" class=\"install_select\">
207 <option value=\"true\"");
208 if (isBooleanConstantAndTrue('warn_no_pass')) OUTPUT_HTML(" selected=\"selected\"");
209 OUTPUT_HTML(">{--YES--}</option>
210 <option value=\"false\"");
211 if (!isBooleanConstantAndTrue('warn_no_pass')) OUTPUT_HTML(" selected=\"selected\"");
212 OUTPUT_HTML(">{--NO--}</option>
216 <tr><td colspan=\"2\" height=\"10\" class=\"seperator\"> </td></tr>
218 <td class=\"install\" align=\"right\">{--LANG_WRITE_FOOTER--}: </td>
220 <select name=\"wfooter\" size=\"1\" class=\"install_select\">
221 <option value=\"true\"");
222 if (isBooleanConstantAndTrue('WRITE_FOOTER')) OUTPUT_HTML(" selected=\"selected\"");
223 OUTPUT_HTML(">{--YES--}</option>
224 <option value=\"false\"");
225 if (!isBooleanConstantAndTrue('WRITE_FOOTER')) OUTPUT_HTML(" selected=\"selected\"");
226 OUTPUT_HTML(">{--NO--}</option>
230 <tr><td colspan=\"2\" height=\"10\" class=\"seperator\"> </td></tr>
232 <td class=\"install\" align=\"right\">{--INSTALL_ENABLE_BACKLINK--}: </td>
234 <select name=\"blink\" size=\"1\" class=\"install_select\">
235 <option value=\"true\"");
236 if (isBooleanConstantAndTrue('ENABLE_BACKLINK')) OUTPUT_HTML(" selected=\"selected\"");
237 OUTPUT_HTML(">{--YES--}</option>
238 <option value=\"false\"");
239 if (!isBooleanConstantAndTrue('ENABLE_BACKLINK')) OUTPUT_HTML(" selected=\"selected\"");
240 OUTPUT_HTML(">{--NO--}</option>
244 <tr><td colspan=\"2\" height=\"21\" class=\"seperator\"> </td></tr>
246 <td colspan=\"2\" align=\"center\">");
247 foreach ($mysql as $key => $value) {
248 OUTPUT_HTML(" <input type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\">");
250 OUTPUT_HTML(" <input type=\"hidden\" name=\"spath\" value=\"{!__SPATH_VALUE!}\">
251 <input type=\"hidden\" name=\"burl\" value=\"{!__BURL_VALUE!}\" />
252 <input type=\"hidden\" name=\"title\" value=\"{!__TITLE_VALUE!}\" />
253 <input type=\"hidden\" name=\"slogan\" value=\"{!__SLOGAN_VALUE!}\" />
254 <input type=\"hidden\" name=\"email\" value=\"{!__EMAIL_VALUE!}\" />
255 <input type=\"hidden\" name=\"smtp_host\" value=\"{!__SMTP_HOST!}\" />
256 <input type=\"hidden\" name=\"smtp_user\" value=\"{!__SMTP_USER!}\" />
257 <input type=\"hidden\" name=\"smtp_pass\" value=\"{!__SMTP_PASS!}\" />
258 <input type=\"submit\" class=\"admin_submit submit\" name=\"finalize\" value=\"{--NEXT_PAGE--}\" class=\"install_submit\" />
261 <tr><td colspan=\"2\" height=\"21\" class=\"seperator\"> </td></tr>
266 case "finalize": // Write captured data to files
267 if ((REQUEST_ISSET_POST(('finalize'))) && (!isBooleanConstantAndTrue('mxchange_installed'))) {
268 // You have submitted data then we have to reset the fatal messages
271 // Connect to MySQL server
272 SQL_CONNECT($mysql['host'], $mysql['login'], $mysql['pass1'], __FILE__, __LINE__);
273 if (SQL_IS_LINK_UP()) {
274 // Seems to work, also right database?
275 if (SQL_SELECT_DB($mysql['dbase'], __FILE__, __LINE__) === true) {
276 // Automatically run install.sql
277 if ((FILE_READABLE(REQUEST_POST('spath')."install/tables.sql")) && (FILE_READABLE(REQUEST_POST('spath')."install/menu-".GET_LANGUAGE().".sql"))) {
278 // Both exists so import them
279 foreach (array("tables.sql", "menu-".GET_LANGUAGE().".sql") as $dump) {
280 // Should be save here because file_exists() is there but we check it again. :)
281 $FQFN = secureString(REQUEST_POST('spath')) . "install/" . $dump;
282 if (FILE_READABLE($FQFN)) {
284 $SQLs = READ_FILE($FQFN, true);
286 // And split it up against ;\n ...
287 $SQLs = merge_array($SQLs, explode(";\n", $sql));
290 debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
294 // Are some SQLs found?
295 if (count($SQLs) == 0) {
297 addFatalMessage(getMessage('INSTALL_SQL_IMPORT_FAILED'));
301 // Now run all queries through and try to keep out empty or comment queries
302 foreach ($SQLs as $sql) {
306 // Is this query not empty and not a comment?
307 if ((!empty($sql)) && (substr($sql, 0, 2) != "--") && (substr($sql, 0, 1) != "#")) {
309 SQL_QUERY($sql, __FILE__, __LINE__);
313 // Ok, all done. So we can write the config data to the php files
314 if (REQUEST_POST('spath') != constant('PATH')) changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SERVER-PATH", "define('PATH', \"", "\");", REQUEST_POST('spath'), 0);
315 if (REQUEST_POST('burl') != constant('URL')) changeDataInFile(REQUEST_POST('spath')."inc/config.php", "HOST-URL", "define('URL', \"", "\");", REQUEST_POST('burl'), 0);
316 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MAIN_TITLE", "define('MAIN_TITLE', \"", "\");", REQUEST_POST('title'), 0);
317 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SLOGAN", "define('SLOGAN', \"", "\");", REQUEST_POST('slogan'), 0);
318 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "WEBMASTER", "define('WEBMASTER', \"", "\");", REQUEST_POST('email'), 0);
319 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "NULLPASS-WARNING", "define('warn_no_pass', ", ");", REQUEST_POST('warn_no_pass'), 0);
320 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "WRITE-FOOTER", "define('WRITE_FOOTER', ", ");", REQUEST_POST('wfooter'), 0);
321 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "BACKLINK", "define('ENABLE_BACKLINK', ", ");", REQUEST_POST('blink'), 0);
322 // DEACTIVATED: changeDataInFile(REQUEST_POST('spath')."inc/config.php", "OUTPUT-MODE", "define('OUTPUT_MODE', \"", "\");", REQUEST_POST('omode'), 0);
323 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-HOST", " 'host' => \"", "\",", $mysql['host'], 0);
324 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-DBASE", " 'dbase' => \"", "\",", $mysql['dbase'], 0);
325 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-LOGIN", " 'login' => \"", "\",", $mysql['login'], 0);
326 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-PASSWORD", " 'password' => \"", "\",", $mysql['pass1'], 0);
327 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-PREFIX", "define('_MYSQL_PREFIX', \"", "\");", $mysql['prefix'], 0);
328 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SMTP-HOSTNAME", "define('SMTP_HOSTNAME', \"", "\");", REQUEST_POST('smtp_host'), 0);
329 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SMTP-USER", "define('SMTP_USER', \"", "\");", REQUEST_POST('smtp_user'), 0);
330 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SMTP-PASSWORD", "define('SMTP_PASSWORD', \"", "\");", REQUEST_POST('smtp_pass1'), 0);
331 changeDataInFile(REQUEST_POST('spath')."inc/config.php", "INSTALLED", "define('mxchange_installed', ", ");", "true", 0);
333 // Installation area not found!
334 addFatalMessage(getMessage('INSTALL_MISSING_DUMPS'));
339 if (getTotalFatalErrors() > 0) {
341 foreach (getFatalArray() as $value) {
342 $OUT .= " <li>".$value."</li>\n";
344 define('__FATAL_ERROR_LI', $OUT);
346 foreach ($mysql as $key => $value) {
347 $OUT .= " <input type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\">\n";
349 define('__MYSQL_DATA' , $OUT);
350 define('__SPATH_VALUE' , REQUEST_POST('spath'));
351 define('__BURL_VALUE' , REQUEST_POST('burl'));
352 define('__TITLE_VALUE' , REQUEST_POST('title'));
353 define('__SMTP_HOST' , REQUEST_POST('smtp_host'));
354 define('__SMTP_USER' , REQUEST_POST('smtp_user'));
355 define('__SMTP_PASS' , REQUEST_POST('smtp_pass1'));
358 LOAD_TEMPLATE("install_fatal_errors");
360 // Installation is done!
361 LOAD_URL("install.php?page=finalize");
363 } elseif (isBooleanConstantAndTrue('mxchange_installed')) {
364 // Redirection after writing data... :-)
365 LOAD_TEMPLATE("install_finished");
367 // Something goes wrong during installation! :-(
368 addFatalMessage(getMessage('INSTALL_FINALIZER_FAILED'));
369 LOAD_INC("inc/fatal_errors.php");
374 DEBUG_LOG(__FILE__, __LINE__, sprintf("Wrong page %s detected", REQUEST_GET('page')));
375 OUTPUT_HTML(" <div class=\"install_error\">{--WRONG_PAGE--}</strong>");
379 // Already installed!
380 addFatalMessage(getMessage('ALREADY_INSTALLED'));