Maybe now better, but a simple wget still gives HTTP/1.0 :(
[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 /************************************************************************
41  *      YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION!        *
42  ************************************************************************/
43
44 // Some security stuff...
45 if (!defined('__SECURITY')) {
46         die();
47 } // END - if
48
49 // Write the local config-local.php file from "template"
50 function doInstallWriteLocalConfig () {
51         // Copy the config template and verify it
52         copyFileVerified(postRequestParameter('spath') . 'inc/config-local.php.dist', getConfig('CACHE_PATH') . 'config-local.php', 0644);
53
54         // Ok, all done. So we can write the config data to the php files
55         if (postRequestParameter('spath') != getConfig('PATH')) changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'SERVER-PATH', "setConfigEntry('PATH', '", "');", postRequestParameter('spath'), 0);
56         if (postRequestParameter('burl')  != getConfig('URL'))  changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'HOST-URL', "setConfigEntry('URL', '", "');", postRequestParameter('burl'), 0);
57         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'MAIN-TITLE', "setConfigEntry('MAIN_TITLE', '", "');", postRequestParameter('title'), 0);
58         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'SLOGAN', "setConfigEntry('SLOGAN', '", "');", postRequestParameter('slogan'), 0);
59         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'WEBMASTER', "setConfigEntry('WEBMASTER', '", "');", postRequestParameter('email'), 0);
60         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'NULLPASS-WARNING', "setConfigEntry('WARN_NO_PASS', '", "');", postRequestParameter('warn_no_pass'), 0);
61         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'WRITE-FOOTER', "setConfigEntry('WRITE_FOOTER', '", "');", postRequestParameter('wfooter'), 0);
62         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'BACKLINK', "setConfigEntry('ENABLE_BACKLINK', '", "');", postRequestParameter('blink'), 0);
63         // @TODO DEACTIVATED: changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
64         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'MYSQL-HOST', "  'host'     => '", "',", postRequestParameter('mysql','host'), 0);
65         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'MYSQL-DBASE', " 'dbase'    => '", "',", postRequestParameter('mysql','dbase'), 0);
66         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'MYSQL-LOGIN', " 'login'    => '", "',", postRequestParameter('mysql','login'), 0);
67         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'MYSQL-PASSWORD', "      'password' => '", "',", postRequestParameter('mysql','pass1'), 0);
68         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'MYSQL-PREFIX', "setConfigEntry('_MYSQL_PREFIX', '", "');", postRequestParameter('mysql','prefix'), 0);
69         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'TABLE-TYPE', "setConfigEntry('_TABLE_TYPE', '", "');", postRequestParameter('mysql','type'), 0);
70         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'SMTP-HOSTNAME', "setConfigEntry('SMTP_HOSTNAME', '", "');", postRequestParameter('smtp_host'), 0);
71         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'SMTP-USER', "setConfigEntry('SMTP_USER', '", "');", postRequestParameter('smtp_user'), 0);
72         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'SMTP-PASSWORD', "setConfigEntry('SMTP_PASSWORD', '", "');", postRequestParameter('smtp_pass1'), 0);
73
74         // Generate a long site key
75         $siteKey = generatePassword(50);
76
77         // And write it
78         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'SITE-KEY', "setConfigEntry('SITE_KEY', '", "');", $siteKey, 0);
79
80         // Script is now installed
81         changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'INSTALLED', "setConfigEntry('MXCHANGE_INSTALLED', '", "');", 'Y', 0);
82 }
83
84 // Adds a given template with content to install output stream
85 function addTemplateToInstallContent ($template, $content = array()) {
86         // Load the template
87         $out = loadTemplate($template, true, $content);
88
89         // Add it to output
90         addToInstallContent($out);
91 }
92
93 // Add it to install content
94 function addToInstallContent ($out) {
95         // Set or add it...
96         if (!isset($GLOBALS['install_content'])) {
97                 // Set it
98                 $GLOBALS['install_content'] = $out;
99         } else {
100                 // Add it
101                 $GLOBALS['install_content'] .= $out;
102         } // END - if
103 }
104
105 // Read a given SQL dump
106 function readSqlDump ($FQFN) {
107         // Sanity-check if file is there (should be there, but just to make it sure)
108         if (!isFileReadable($FQFN)) {
109                 // This should not happen
110                 debug_report_bug(__FUNCTION__.': File ' . basename($FQFN) . ' is not readable!');
111         } // END - if
112
113         // Load the file
114         $content = readFromFile($FQFN);
115
116         // Remove some unwanted chars
117         $content = str_replace("\r", '', $content);
118         $content = str_replace("\n\n", "\n", $content);
119
120         // Return the content
121         return $content;
122 }
123
124 // [EOF]
125 ?>