Installer content encapsulated in inc/install-functions.php
[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  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Write the local config-local.php file from "template"
46 function doInstallWriteLocalConfig () {
47         // Copy the config template and verify it
48         copyFileVerified(postRequestParameter('spath') . 'inc/config-local.php.dist', getCachePath() . 'config-local.php', 0644);
49
50         // Ok, all done. So we can write the config data to the php files
51         if (postRequestParameter('spath') != getPath()) changeDataInFile(getCachePath() . 'config-local.php', 'SERVER-PATH', "setConfigEntry('PATH', '", "');", postRequestParameter('spath'), 0);
52         if (postRequestParameter('burl')  != getUrl())  changeDataInFile(getCachePath() . 'config-local.php', 'HOST-URL', "setConfigEntry('URL', '", "');", postRequestParameter('burl'), 0);
53         changeDataInFile(getCachePath() . 'config-local.php', 'MAIN-TITLE', "setConfigEntry('MAIN_TITLE', '", "');", postRequestParameter('title'), 0);
54         changeDataInFile(getCachePath() . 'config-local.php', 'SLOGAN', "setConfigEntry('SLOGAN', '", "');", postRequestParameter('slogan'), 0);
55         changeDataInFile(getCachePath() . 'config-local.php', 'WEBMASTER', "setConfigEntry('WEBMASTER', '", "');", postRequestParameter('email'), 0);
56         changeDataInFile(getCachePath() . 'config-local.php', 'NULLPASS-WARNING', "setConfigEntry('WARN_NO_PASS', '", "');", postRequestParameter('warn_no_pass'), 0);
57         changeDataInFile(getCachePath() . 'config-local.php', 'WRITE-FOOTER', "setConfigEntry('WRITE_FOOTER', '", "');", postRequestParameter('wfooter'), 0);
58         changeDataInFile(getCachePath() . 'config-local.php', 'BACKLINK', "setConfigEntry('ENABLE_BACKLINK', '", "');", postRequestParameter('blink'), 0);
59         // @TODO DEACTIVATED: changeDataInFile(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
60         changeDataInFile(getCachePath() . 'config-local.php', 'MYSQL-HOST', "   'host'     => '", "',", postRequestParameter('mysql','host'), 0);
61         changeDataInFile(getCachePath() . 'config-local.php', 'MYSQL-DBASE', "  'dbase'    => '", "',", postRequestParameter('mysql','dbase'), 0);
62         changeDataInFile(getCachePath() . 'config-local.php', 'MYSQL-LOGIN', "  'login'    => '", "',", postRequestParameter('mysql','login'), 0);
63         changeDataInFile(getCachePath() . 'config-local.php', 'MYSQL-PASSWORD', "       'password' => '", "',", postRequestParameter('mysql','pass1'), 0);
64         changeDataInFile(getCachePath() . 'config-local.php', 'MYSQL-PREFIX', "setConfigEntry('_MYSQL_PREFIX', '", "');", postRequestParameter('mysql','prefix'), 0);
65         changeDataInFile(getCachePath() . 'config-local.php', 'TABLE-TYPE', "setConfigEntry('_TABLE_TYPE', '", "');", postRequestParameter('mysql','type'), 0);
66         changeDataInFile(getCachePath() . 'config-local.php', 'SMTP-HOSTNAME', "setConfigEntry('SMTP_HOSTNAME', '", "');", postRequestParameter('smtp_host'), 0);
67         changeDataInFile(getCachePath() . 'config-local.php', 'SMTP-USER', "setConfigEntry('SMTP_USER', '", "');", postRequestParameter('smtp_user'), 0);
68         changeDataInFile(getCachePath() . 'config-local.php', 'SMTP-PASSWORD', "setConfigEntry('SMTP_PASSWORD', '", "');", postRequestParameter('smtp_pass1'), 0);
69
70         // Generate a long site key
71         $siteKey = generatePassword(50);
72
73         // And write it
74         changeDataInFile(getCachePath() . 'config-local.php', 'SITE-KEY', "setConfigEntry('SITE_KEY', '", "');", $siteKey, 0);
75
76         // Script is now installed
77         changeDataInFile(getCachePath() . 'config-local.php', 'INSTALLED', "setConfigEntry('MXCHANGE_INSTALLED', '", "');", 'Y', 0);
78 }
79
80 // Adds a given template with content to install output stream
81 function addTemplateToInstallContent ($template, $content = array()) {
82         // Load the template
83         $out = loadTemplate($template, true, $content);
84
85         // Add it to output
86         addToInstallContent($out);
87 }
88
89 // Add it to install content
90 function addToInstallContent ($out) {
91         // Set or add it...
92         if (!isset($GLOBALS['install_content'])) {
93                 // Set it
94                 $GLOBALS['install_content'] = $out;
95         } else {
96                 // Add it
97                 $GLOBALS['install_content'] .= $out;
98         } // END - if
99 }
100
101 // Somewhat getter for installer content
102 function getInstallerContent () {
103         // Is it here?
104         if (isset($GLOBAS['install_content'])) {
105                 // Yes, then use it
106                 $content = $GLOBALS['install_content'];
107         } else {
108                 // Nothing found, this needs fixing
109                 $content = loadTemplate('admin_settings_saved', false, '{--INSTALLER_CONTENT_404--}');
110         }
111
112         // Return content
113         return $content;
114 }
115
116 // Read a given SQL dump
117 function readSqlDump ($FQFN) {
118         // Load the file
119         $content = readFromFile($FQFN);
120
121         // Remove some unwanted chars
122         $content = str_replace("\r", '', $content);
123         $content = str_replace("\n\n", "\n", $content);
124
125         // Return the content
126         return $content;
127 }
128
129 // [EOF]
130 ?>