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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
46 function install_WriteData ($file, $comment, $prefix, $suffix, $DATA, $SNEAK=0)
48 $done = false; $SNEAK++;
49 if (file_exists($file))
51 $search = "CFG: ".$comment;
53 $fp = @fopen($file, 'r') or OUTPUT_HTML("<STRONG>READ:</STRONG> ".$file."<BR>");
54 if (is_resource($fp)) {
55 $fp_tmp = @fopen($tmp, 'w') or OUTPUT_HTML("<STRONG>WRITE:</STRONG> ".$tmp."<BR>");
56 if (is_resource($fp_tmp)) {
58 $line = fgets ($fp, 10240);
59 if (strpos($line, $search) > -1) $next = 0;
61 if ($next == $SNEAK) {
63 $line = $prefix.$DATA.$suffix."\n";
68 fputs($fp_tmp, $line);
71 // Finished writing tmp file
75 // Close source directory
78 if (($done) && (is_writeable($file))) {
79 // Copy back tmp file and delete tmp :-)
83 OUTPUT_HTML("<STRONG>TMP:</STRONG> UNDONE!");
87 OUTPUT_HTML("<STRONG>404:</STRONG> ".$file."<BR>");
93 if (isset($_POST['mysql']) && is_array($_POST['mysql'])) $mysql = $_POST['mysql'];
95 if (URL != "http://your-server.com")
97 // Already installed???
103 $burl = "http://".$SERVER_NAME.$_SERVER['PHP_SELF'];
104 $burl = substr($burl, 0, strpos($burl, "install.php"));
107 if ((!mxchange_installed) || (!admin_registered))
109 // Set URL for FORM actions
110 define('__BURL_ACTION', $burl);
112 // Output page for entered value
113 switch ($_GET['page'])
115 case "welcome": // Welcome to the installation!
116 LOAD_TEMPLATE("install_welcome");
119 case "1": // Server path, base URL
120 define('__PATH_LEN' , strlen(PATH));
121 define('__BURL_LEN' , strlen($burl));
122 define('__TITLE_LEN' , strlen(MAIN_TITLE));
123 define('__SLOGAN_LEN' , strlen(SLOGAN));
124 define('__WEBMASTER_LEN', (strlen(WEBMASTER) * 3));
127 LOAD_TEMPLATE("install_page1");
130 case "2": // MySQL data (alone!)
131 if (empty($mysql['dbase'])) $mysql['dbase'] = "your_database";
132 if (empty($mysql['login'])) $mysql['login'] = "your_login";
133 if (empty($mysql['host'])) $mysql['host'] = "localhost";
134 if (empty($mysql['prefix'])) $mysql['prefix'] = "mxchange_";
135 if ((sizeof($FATAL) > 0) || (!empty($FATAL[0])))
137 OUTPUT_HTML("<SPAN class=\"install_fatal\">");
138 foreach ($FATAL as $key=>$err)
140 OUTPUT_HTML(" <STRONG>·</STRONG> ".FATAL_NO.($key + 1).": ".$err."<BR>\n");
142 OUTPUT_HTML("</SPAN><BR>");
144 define('__MYSQL_HOST' , $mysql['host']);
145 define('__MYSQL_DBASE' , $mysql['dbase']);
146 define('__MYSQL_PREFIX', $mysql['prefix']);
147 define('__MYSQL_LOGIN' , $mysql['login']);
148 define('__SPATH_VALUE' , $_POST['spath']);
149 define('__BURL_VALUE' , $_POST['burl']);
150 define('__TITLE_VALUE' , $_POST['title']);
151 define('__SLOGAN_VALUE', $_POST['slogan']);
152 define('__EMAIL_VALUE' , $_POST['email']);
155 LOAD_TEMPLATE("install_page2");
158 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']);
164 OUTPUT_HTML("<FORM action=\"".__BURL_ACTION."/install.php?page=finalize\" method=\"POST\" target=\"_self\">
165 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"install_content\">
167 <TD colspan=\"2\" align=\"center\">
168 <STRONG class=\"install\">".HEADER_TEXT_PAGE5."</STRONG>
171 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
173 <TD colspan=\"2\"><SPAN class=\"install_intro\">
177 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
179 <TD class=\"install\" align=\"right\">".LANG_OUTPUT_MODE.": </TD>
181 <SELECT name=\"omode\" size=\"1\" class=\"install_select\">
182 <OPTION value=\"render\"");
183 if (OUTPUT_MODE == "render") OUTPUT_HTML(" selected=\"selected\"");
184 OUTPUT_HTML(">".MODE_RENDER."</OPTION>
185 <OPTION value=\"direct\"");
186 if (OUTPUT_MODE == "direct") OUTPUT_HTML(" selected=\"selected\"");
187 OUTPUT_HTML(">".MODE_DIRECT."</OPTION>
191 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
193 <TD class=\"install\" align=\"right\">".WARN_NO_PASSWORD.": </TD>
195 <SELECT name=\"warn_no_pass\" size=\"1\" class=\"install_select\">
196 <OPTION value=\"true\"");
197 if (warn_no_pass) OUTPUT_HTML(" selected=\"selected\"");
198 OUTPUT_HTML(">".YES."</OPTION>
199 <OPTION value=\"false\"");
200 if (!warn_no_pass) OUTPUT_HTML(" selected=\"selected\"");
201 OUTPUT_HTML(">".NO."</OPTION>
205 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
207 <TD class=\"install\" align=\"right\">".LANG_WRITE_FOOTER.": </TD>
209 <SELECT name=\"wfooter\" size=\"1\" class=\"install_select\">
210 <OPTION value=\"true\"");
211 if (WRITE_FOOTER) OUTPUT_HTML(" selected=\"selected\"");
212 OUTPUT_HTML(">".YES."</OPTION>
213 <OPTION value=\"false\"");
214 if (!WRITE_FOOTER) OUTPUT_HTML(" selected=\"selected\"");
215 OUTPUT_HTML(">".NO."</OPTION>
219 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
221 <TD class=\"install\" align=\"right\">".LANG_FRAMESET_ACTIVE.": </TD>
223 <SELECT name=\"frameset\" size=\"1\" class=\"install_select\">
224 <OPTION value=\"true\"");
225 if (frameset_active) OUTPUT_HTML(" selected=\"selected\"");
226 OUTPUT_HTML(">".YES."</OPTION>
227 <OPTION value=\"false\"");
228 if (!frameset_active) OUTPUT_HTML(" selected=\"selected\"");
229 OUTPUT_HTML(">".NO."</OPTION>
233 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
235 <TD class=\"install\" align=\"right\">".INSTALL_ENABLE_BACKLINK.": </TD>
237 <SELECT name=\"blink\" size=\"1\" class=\"install_select\">
238 <OPTION value=\"true\"");
239 if (ENABLE_BACKLINK) OUTPUT_HTML(" selected=\"selected\"");
240 OUTPUT_HTML(">".YES."</OPTION>
241 <OPTION value=\"false\"");
242 if (!ENABLE_BACKLINK) OUTPUT_HTML(" selected=\"selected\"");
243 OUTPUT_HTML(">".NO."</OPTION>
247 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
249 <TD colspan=\"2\" align=\"center\">");
250 foreach ($mysql as $key=>$value)
252 OUTPUT_HTML(" <INPUT type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\">");
254 OUTPUT_HTML(" <INPUT type=\"hidden\" name=\"spath\" value=\"".__SPATH_VALUE."\">
255 <INPUT type=\"hidden\" name=\"burl\" value=\"".__BURL_VALUE."\">
256 <INPUT type=\"hidden\" name=\"title\" value=\"".__TITLE_VALUE."\">
257 <INPUT type=\"hidden\" name=\"slogan\" value=\"".__SLOGAN_VALUE."\">
258 <INPUT type=\"hidden\" name=\"email\" value=\"".__EMAIL_VALUE."\">
259 <INPUT type=\"submit\" class=\"admin_submit submit\" name=\"finalize\" value=\"".NEXT_PAGE."\" class=\"install_submit\">
262 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
267 case "finalize": // Write captured data to files
268 if (!empty($_POST['finalize']))
270 // You have submitted data then we have to reset the fatal messages
273 // Connect to MySQL server
274 $link = SQL_CONNECT($mysql['host'], $mysql['login'], $mysql['pass1'], __FILE__, __LINE__);
277 // Seems to work, also right database?
278 $db = SQL_SELECT_DB($mysql['dbase'], $link, __FILE__, __LINE__);
281 // Automatically run install.sql
282 if (file_exists($_POST['spath']."install/tables.sql"))
284 $ERRORS = $_POST['spath']."inc/sql.err";
286 // "Dump" tha' s*** up... ;-) > /dev/null
287 "mysql ".$mysql['dbase']." --force --host=".$mysql['host']." --user=".$mysql['login']." --password=".$mysql['pass1']." < ".$_POST['spath']."install/tables.sql",
288 "mysql ".$mysql['dbase']." --force --host=".$mysql['host']." --user=".$mysql['login']." --password=".$mysql['pass1']." < ".$_POST['spath']."install/menu-".GET_LANGUAGE().".sql"
296 if ((file_exists($ERRORS)) && (filesize($ERRORS) > 0))
298 ADD_FATAL(MYSQLDUMP_ERROR);
300 elseif (!mxchange_installed)
302 // Remove error file if empty
303 if (file_exists($ERRORS)) @unlink ($ERRORS);
305 // Ok, all done. So we can write the config data to the php files
306 if ($_POST['spath'] != PATH) install_WriteData($_POST['spath']."inc/config.php", "SERVER-PATH", "define ('PATH', \"", "\");", $_POST['spath'], 0);
307 if ($_POST['burl'] != URL) install_WriteData($_POST['spath']."inc/config.php", "HOST-URL", "define ('URL', \"", "\");", $_POST['burl'], 0);
308 install_WriteData($_POST['spath']."inc/config.php", "MAIN_TITLE", "define ('MAIN_TITLE', \"", "\");", $_POST['title'], 0);
309 install_WriteData($_POST['spath']."inc/config.php", "SLOGAN", "define ('SLOGAN', \"", "\");", $_POST['slogan'], 0);
310 install_WriteData($_POST['spath']."inc/config.php", "WEBMASTER", "define ('WEBMASTER', \"", "\");", $_POST['email'], 0);
311 install_WriteData($_POST['spath']."inc/config.php", "NULLPASS-WARNING", "define ('warn_no_pass', ", ");", $_POST['warn_no_pass'], 0);
312 install_WriteData($_POST['spath']."inc/config.php", "WRITE-FOOTER", "define ('WRITE_FOOTER', ", ");", $_POST['wfooter'], 0);
313 install_WriteData($_POST['spath']."inc/config.php", "BACKLINK", "define ('ENABLED_BACKLINK', ", ");", $_POST['blink'], 0);
314 // install_WriteData($_POST['spath']."inc/config.php", "FRAMESET", "define ('frameset_active', ", ");", $_POST['frameset'], 0);
315 // install_WriteData($_POST['spath']."inc/config.php", "OUTPUT-MODE", "define ('OUTPUT_MODE', \"", "\");", $_POST['omode'], 0);
316 install_WriteData($_POST['spath']."inc/config.php", "MYSQL-HOST", " 'host' => \"", "\",", $mysql['host'], 0);
317 install_WriteData($_POST['spath']."inc/config.php", "MYSQL-DBASE", " 'dbase' => \"", "\",", $mysql['dbase'], 0);
318 install_WriteData($_POST['spath']."inc/config.php", "MYSQL-LOGIN", " 'login' => \"", "\",", $mysql['login'], 0);
319 install_WriteData($_POST['spath']."inc/config.php", "MYSQL-PASSWORD", " 'password' => \"", "\",", $mysql['pass1'], 0);
320 install_WriteData($_POST['spath']."inc/config.php", "MYSQL-PREFIX", "define ('_MYSQL_PREFIX', \"", "\");", $mysql['prefix'], 0);
321 install_WriteData($_POST['spath']."inc/config.php", "INSTALLED", "define ('mxchange_installed', ", ");", "true", 0);
324 SQL_CLOSE($link, __FILE__, __LINE__);
328 ADD_FATAL(INSTALL_MAYBE_DONE);
333 // Installation area not found!
334 ADD_FATAL(INSTALL_MISSING_DUMPS);
338 if ((sizeof($FATAL) > 0) || ($FATAL[0] != ""))
341 foreach ($FATAL as $value)
343 $OUT .= " <LI>".$value."</LI>\n";
345 define('__FATAL_ERROR_LI', $OUT);
347 foreach ($mysql as $key=>$value)
349 $OUT .= " <INPUT type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\">\n";
351 define('__MYSQL_DATA' , $OUT);
352 define('__SPATH_VALUE', $_POST['spath']);
353 define('__BURL_VALUE' , $_POST['burl']);
354 define('__TITLE_VALUE', $_POST['title']);
356 OUTPUT_HTML("<FORM action=\"".__BURL_ACTION."/install.php?page=2\" method=\"POST\">
357 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"install_content\">
359 <TD align=\"center\">
360 <STRONG class=\"install\">".HEADER_MYSQL_ERRORS."</STRONG>
363 <TR><TD colspan=\"2\" height=\"21\" class=\"seperator\"> </TD></TR>
365 <TD><SPAN class=\"install_intro\">
366 ".TEXT_MYSQL_ERRORS."
370 <TD align=\"center\"><STRONG>
375 <INPUT type=\"hidden\" name=\"spath\" value=\"".__SPATH_VALUE."\">
376 <INPUT type=\"hidden\" name=\"burl\" value=\"".__BURL_VALUE."\">
377 <INPUT type=\"hidden\" name=\"title\" value=\"".__TITLE_VALUE."\">
378 <INPUT type=\"submit\" class=\"admin_submit\" name=\"ok\" value=\"".RETURN_MYSQL_PAGE."\">
386 // Installation is done!
387 $URL = $burl."/install.php?page=finalize";
391 elseif (mxchange_installed)
393 // Redirection after writing data... :-)
394 OUTPUT_HTML("<SPAN class=\"install_finished\">".INSTALL_FINISHED."</SPAN><BR>
396 <SPAN class=\"install_security\">".INSTALL_FIN_SECU."</SPAN><BR>
398 <FORM action=\"modules.php\" method=\"GET\">
399 <INPUT type=\"hidden\" name=\"module\" value=\"admin\">
400 <INPUT type=\"submit\" class=\"admin_submit submit\" value=\"".CONTINUE_ADMIN."\" class=\"install_submit\">
405 // Something goes wrong during installation! :-(
406 ADD_FATAL(INSTALL_FINALIZER_FAILED);
407 include ("inc/fatal_errors.php");
412 OUTPUT_HTML(" <STRONG class=\"install_error\">".WRONG_PAGE."</STRONG>");
418 ADD_FATAL(ALREADY_INSTALLED);