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 ((isset($_POST['mysql'])) && (is_array($_POST['mysql']))) $mysql = $_POST['mysql'];
48 // Check if both passwords from SMTP are matching
49 if ((isset($_GET['page']) && ($_GET['page'] == 5))) {
50 // Okay, we have to check it
51 if (!empty($_POST['smtp_user']) && (empty($_POST['smtp_host']))) {
53 OUTPUT_HTML(getMessage('INSTALL_SMTP_HOSTNAME_EMPTY')."<br />");
57 if ((empty($_POST['smtp_pass1'])) && (!empty($_POST['smtp_pass2']))) {
59 OUTPUT_HTML(getMessage('INSTALL_SMTP_PASS1_EMPTY')."<br />");
63 if ((!empty($_POST['smtp_pass1'])) && (empty($_POST['smtp_pass2']))) {
64 // Password repeat is empty
65 OUTPUT_HTML(getMessage('INSTALL_SMTP_PASS2_EMPTY')."<br />");
69 if ($_POST['smtp_pass1'] != $_POST['smtp_pass1']) {
70 // Passwords are not matching
71 OUTPUT_HTML(getMessage('INSTALL_SMTP_PASS_MISMATCH')."<br />");
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 ($_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 ($FATAL 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' , $_POST['spath']);
112 define('__BURL_VALUE' , $_POST['burl']);
113 define('__TITLE_VALUE' , $_POST['title']);
114 define('__SLOGAN_VALUE', $_POST['slogan']);
115 define('__EMAIL_VALUE' , $_POST['email']);
118 LOAD_TEMPLATE("install_page2");
123 define('__SPATH_VALUE' , $_POST['spath']);
124 define('__BURL_VALUE' , $_POST['burl']);
125 define('__TITLE_VALUE' , $_POST['title']);
126 define('__SLOGAN_VALUE' , $_POST['slogan']);
127 define('__EMAIL_VALUE' , $_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 (!empty($_POST['smtp_host'])) $smtpHost = $_POST['smtp_host'];
137 if (!empty($_POST['smtp_user'])) $smtpUser = $_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' , $_POST['spath']);
160 define('__BURL_VALUE' , $_POST['burl']);
161 define('__TITLE_VALUE' , $_POST['title']);
162 define('__SLOGAN_VALUE' , $_POST['slogan']);
163 define('__EMAIL_VALUE' , $_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' , $_POST['smtp_host']);
173 define('__SMTP_USER' , $_POST['smtp_user']);
174 define('__SMTP_PASS' , $_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 ((!empty($_POST['finalize'])) && (!isBooleanConstantAndTrue('mxchange_installed'))) {
268 // You have submitted data then we have to reset the fatal messages
271 // Connect to MySQL server
272 $link = SQL_CONNECT($mysql['host'], $mysql['login'], $mysql['pass1'], __FILE__, __LINE__);
274 // Seems to work, also right database?
275 $db = SQL_SELECT_DB($mysql['dbase'], $link, __FILE__, __LINE__);
277 // Automatically run install.sql
278 if ((FILE_READABLE($_POST['spath']."install/tables.sql")) && (FILE_READABLE($_POST['spath']."install/menu-".GET_LANGUAGE().".sql"))) {
279 // Both exists so import them
280 foreach (array("tables.sql", "menu-".GET_LANGUAGE().".sql") as $dump) {
281 // Should be save here because file_exists() is there but we check it again. :)
282 $FQFN = secureString($_POST['spath']) . "install/" . $dump;
283 if (FILE_READABLE($FQFN)) {
285 $SQLs = READ_FILE($FQFN, true);
287 // And split it up against ;\n ...
288 $SQLs = merge_array($SQLs, explode(";\n", $sql));
291 debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
295 // Are some SQLs found?
296 if (count($SQLs) == 0) {
298 addFatalMessage(getMessage('INSTALL_SQL_IMPORT_FAILED'));
302 // Now run all queries through and try to keep out empty or comment queries
303 foreach ($SQLs as $sql) {
307 // Is this query not empty and not a comment?
308 if ((!empty($sql)) && (substr($sql, 0, 2) != "--") && (substr($sql, 0, 1) != "#")) {
310 SQL_QUERY($sql, __FILE__, __LINE__);
314 // Ok, all done. So we can write the config data to the php files
315 if ($_POST['spath'] != constant('PATH')) changeDataInFile($_POST['spath']."inc/config.php", "SERVER-PATH", "define('PATH', \"", "\");", $_POST['spath'], 0);
316 if ($_POST['burl'] != constant('URL')) changeDataInFile($_POST['spath']."inc/config.php", "HOST-URL", "define('URL', \"", "\");", $_POST['burl'], 0);
317 changeDataInFile($_POST['spath']."inc/config.php", "MAIN_TITLE", "define('MAIN_TITLE', \"", "\");", $_POST['title'], 0);
318 changeDataInFile($_POST['spath']."inc/config.php", "SLOGAN", "define('SLOGAN', \"", "\");", $_POST['slogan'], 0);
319 changeDataInFile($_POST['spath']."inc/config.php", "WEBMASTER", "define('WEBMASTER', \"", "\");", $_POST['email'], 0);
320 changeDataInFile($_POST['spath']."inc/config.php", "NULLPASS-WARNING", "define('warn_no_pass', ", ");", $_POST['warn_no_pass'], 0);
321 changeDataInFile($_POST['spath']."inc/config.php", "WRITE-FOOTER", "define('WRITE_FOOTER', ", ");", $_POST['wfooter'], 0);
322 changeDataInFile($_POST['spath']."inc/config.php", "BACKLINK", "define('ENABLE_BACKLINK', ", ");", $_POST['blink'], 0);
323 // changeDataInFile($_POST['spath']."inc/config.php", "OUTPUT-MODE", "define('OUTPUT_MODE', \"", "\");", $_POST['omode'], 0);
324 changeDataInFile($_POST['spath']."inc/config.php", "MYSQL-HOST", " 'host' => \"", "\",", $mysql['host'], 0);
325 changeDataInFile($_POST['spath']."inc/config.php", "MYSQL-DBASE", " 'dbase' => \"", "\",", $mysql['dbase'], 0);
326 changeDataInFile($_POST['spath']."inc/config.php", "MYSQL-LOGIN", " 'login' => \"", "\",", $mysql['login'], 0);
327 changeDataInFile($_POST['spath']."inc/config.php", "MYSQL-PASSWORD", " 'password' => \"", "\",", $mysql['pass1'], 0);
328 changeDataInFile($_POST['spath']."inc/config.php", "MYSQL-PREFIX", "define('_MYSQL_PREFIX', \"", "\");", $mysql['prefix'], 0);
329 changeDataInFile($_POST['spath']."inc/config.php", "SMTP-HOSTNAME", "define('SMTP_HOSTNAME', \"", "\");", $_POST['smtp_host'], 0);
330 changeDataInFile($_POST['spath']."inc/config.php", "SMTP-USER", "define('SMTP_USER', \"", "\");", $_POST['smtp_user'], 0);
331 changeDataInFile($_POST['spath']."inc/config.php", "SMTP-PASSWORD", "define('SMTP_PASSWORD', \"", "\");", $_POST['smtp_pass'], 0);
332 changeDataInFile($_POST['spath']."inc/config.php", "INSTALLED", "define('mxchange_installed', ", ");", "true", 0);
334 // Installation area not found!
335 addFatalMessage(getMessage('INSTALL_MISSING_DUMPS'));
340 if (getTotalFatalErrors() > 0) {
342 foreach ($FATAL as $value) {
343 $OUT .= " <li>".$value."</li>\n";
345 define('__FATAL_ERROR_LI', $OUT);
347 foreach ($mysql as $key => $value) {
348 $OUT .= " <input type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\">\n";
350 define('__MYSQL_DATA' , $OUT);
351 define('__SPATH_VALUE' , $_POST['spath']);
352 define('__BURL_VALUE' , $_POST['burl']);
353 define('__TITLE_VALUE' , $_POST['title']);
354 define('__SMTP_HOST' , $_POST['smtp_host']);
355 define('__SMTP_USER' , $_POST['smtp_user']);
356 define('__SMTP_PASS' , $_POST['smtp_pass']);
359 LOAD_TEMPLATE("install_fatal_errors");
361 // Installation is done!
362 LOAD_URL("install.php?page=finalize");
364 } elseif (isBooleanConstantAndTrue('mxchange_installed')) {
365 // Redirection after writing data... :-)
366 LOAD_TEMPLATE("install_finished");
368 // Something goes wrong during installation! :-(
369 addFatalMessage(getMessage('INSTALL_FINALIZER_FAILED'));
370 LOAD_INC("inc/fatal_errors.php");
375 DEBUG_LOG(__FILE__, __LINE__, sprintf("Wrong page %s detected", $_GET['page']));
376 OUTPUT_HTML(" <div class=\"install_error\">{--WRONG_PAGE--}</strong>");
380 // Already installed!
381 addFatalMessage(getMessage('ALREADY_INSTALLED'));