svn:eol-style set to 'native'
[mailer.git] / inc / install-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/22/2009 *
4  * ===================                          Last change: 10/22/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : install-functions.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 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Write the local config-local.php file from "template"
44 function doInstallWriteLocalConfig () {
45         // Copy the config template and verify it
46         copyFileVerified(postRequestParameter('spath') . 'inc/config-local.php.dist', getPath() . getCachePath() . 'config-local.php', 0644);
47
48         // Ok, all done. So we can write the config data to the php files
49         if (postRequestParameter('spath') != getPath()) changeDataInInclude(getCachePath() . 'config-local.php', 'SERVER-PATH', "setConfigEntry('PATH', '", "');", postRequestParameter('spath'), 0);
50         if (postRequestParameter('burl')  != getUrl())  changeDataInInclude(getCachePath() . 'config-local.php', 'HOST-URL', "setConfigEntry('URL', '", "');", postRequestParameter('burl'), 0);
51         changeDataInInclude(getCachePath() . 'config-local.php', 'MAIN-TITLE', "setConfigEntry('MAIN_TITLE', '", "');", postRequestParameter('title'), 0);
52         changeDataInInclude(getCachePath() . 'config-local.php', 'SLOGAN', "setConfigEntry('SLOGAN', '", "');", postRequestParameter('slogan'), 0);
53         changeDataInInclude(getCachePath() . 'config-local.php', 'WEBMASTER', "setConfigEntry('WEBMASTER', '", "');", postRequestParameter('email'), 0);
54         changeDataInInclude(getCachePath() . 'config-local.php', 'NULLPASS-WARNING', "setConfigEntry('WARN_NO_PASS', '", "');", postRequestParameter('warn_no_pass'), 0);
55         changeDataInInclude(getCachePath() . 'config-local.php', 'WRITE-FOOTER', "setConfigEntry('WRITE_FOOTER', '", "');", postRequestParameter('wfooter'), 0);
56         changeDataInInclude(getCachePath() . 'config-local.php', 'BACKLINK', "setConfigEntry('ENABLE_BACKLINK', '", "');", postRequestParameter('blink'), 0);
57         // @TODO DEACTIVATED: changeDataInInclude(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
58         changeDataInInclude(getCachePath() . 'config-local.php', 'MYSQL-HOST', "        'host'     => '", "',", postRequestParameter('mysql','host'), 0);
59         changeDataInInclude(getCachePath() . 'config-local.php', 'MYSQL-DBASE', "       'dbase'    => '", "',", postRequestParameter('mysql','dbase'), 0);
60         changeDataInInclude(getCachePath() . 'config-local.php', 'MYSQL-LOGIN', "       'login'    => '", "',", postRequestParameter('mysql','login'), 0);
61         changeDataInInclude(getCachePath() . 'config-local.php', 'MYSQL-PASSWORD', "    'password' => '", "',", postRequestParameter('mysql','pass1'), 0);
62         changeDataInInclude(getCachePath() . 'config-local.php', 'MYSQL-PREFIX', "setConfigEntry('_MYSQL_PREFIX', '", "');", postRequestParameter('mysql','prefix'), 0);
63         changeDataInInclude(getCachePath() . 'config-local.php', 'TABLE-TYPE', "setConfigEntry('_TABLE_TYPE', '", "');", postRequestParameter('mysql','type'), 0);
64         changeDataInInclude(getCachePath() . 'config-local.php', 'SMTP-HOSTNAME', "setConfigEntry('SMTP_HOSTNAME', '", "');", postRequestParameter('smtp_host'), 0);
65         changeDataInInclude(getCachePath() . 'config-local.php', 'SMTP-USER', "setConfigEntry('SMTP_USER', '", "');", postRequestParameter('smtp_user'), 0);
66         changeDataInInclude(getCachePath() . 'config-local.php', 'SMTP-PASSWORD', "setConfigEntry('SMTP_PASSWORD', '", "');", postRequestParameter('smtp_pass1'), 0);
67
68         // Generate a long site key
69         $siteKey = generatePassword(50);
70
71         // And write it
72         changeDataInInclude(getCachePath() . 'config-local.php', 'SITE-KEY', "setConfigEntry('SITE_KEY', '", "');", $siteKey, 0);
73
74         // Script is now installed
75         changeDataInInclude(getCachePath() . 'config-local.php', 'INSTALLED', "setConfigEntry('MXCHANGE_INSTALLED', '", "');", 'Y', 0);
76 }
77
78 // Adds a given template with content to install output stream
79 function addTemplateToInstallContent ($template, $content = array()) {
80         // Load the template
81         $out = loadTemplate($template, true, $content);
82
83         // Add it to output
84         addToInstallContent($out);
85 }
86
87 // Add it to install content
88 function addToInstallContent ($out) {
89         // Set or add it...
90         if (!isset($GLOBALS['install_content'])) {
91                 // Set it
92                 $GLOBALS['install_content'] = $out;
93         } else {
94                 // Add it
95                 $GLOBALS['install_content'] .= $out;
96         } // END - if
97 }
98
99 // Somewhat getter for installer content
100 function getInstallerContent () {
101         // Is it here?
102         if (isset($GLOBALS['install_content'])) {
103                 // Yes, then use it
104                 $content = $GLOBALS['install_content'];
105         } else {
106                 // Nothing found, this needs fixing
107                 $content = displayMessage('{--INSTALLER_CONTENT_404--}', true);
108         }
109
110         // Return content
111         return $content;
112 }
113
114 // Read a given SQL dump
115 function readSqlDump ($FQFN) {
116         // Load the file
117         $content = readFromFile($FQFN);
118
119         // Remove some unwanted chars
120         $content = str_replace("\r", '', $content);
121         $content = str_replace("\n\n", "\n", $content);
122
123         // Return the content
124         return $content;
125 }
126
127 // [EOF]
128 ?>