root/trunk/install.php

Revision 1783, 7.8 kB (checked in by vollmerk, 5 weeks ago)

verify that they at least typed in the right db information, before creating the config file for them

Line 
1<?php
2/*
3
4 Copyright (c) Ampache.org
5 All rights reserved.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License v2
9 as published by the Free Software Foundation
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20*/
21
22// Set the Error level manualy... I'm to lazy to fix notices
23error_reporting(E_ALL ^ E_NOTICE);
24
25require_once 'lib/general.lib.php';
26require_once 'lib/class/config.class.php';
27require_once 'lib/class/vauth.class.php';
28require_once 'lib/class/database_object.abstract.php';
29require_once 'lib/ui.lib.php';
30require_once 'lib/log.lib.php'; 
31require_once 'modules/horde/Browser.php';
32require_once 'lib/install.php';
33require_once 'lib/debug.lib.php';
34require_once 'lib/gettext.php';
35
36if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; }
37else { $http_type = "http://"; }
38
39$prefix = dirname(__FILE__); 
40Config::set('prefix',$prefix,'1'); 
41$configfile = "$prefix/config/ampache.cfg.php";
42
43set_error_handler('ampache_error_handler');
44
45/* First things first we must be sure that they actually still need to
46   install ampache
47*/
48if (!install_check_status($configfile)) { 
49        Error::display('general'); 
50        exit; 
51}
52
53// Define that we are doing an install so the includes will work
54define('INSTALL','1'); 
55define('INIT_LOADED','1');
56
57/* Clean up incomming variables */
58$web_path = scrub_in($_REQUEST['web_path']);
59$username = scrub_in($_REQUEST['local_username']);
60$password = $_REQUEST['local_pass'];
61$hostname = scrub_in($_REQUEST['local_host']);
62$database = scrub_in($_REQUEST['local_db']);
63if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; }
64else { $http_type = "http://"; }
65
66define('WEB_PATH',$http_type . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/' . basename($_SERVER['PHP_SELF']));
67define('WEB_ROOT',$http_type . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF'])); 
68
69/* Catch the Current Action */
70switch ($_REQUEST['action']) { 
71        case 'create_db':
72                /* Get the variables for the language */
73                $htmllang = $_REQUEST['htmllang'];
74                $charset  = $_REQUEST['charset'];
75
76                // Set the lang in the conf array
77                Config::set('lang', $htmllang,'1');
78                Config::set('site_charset', $charset, '1');
79                load_gettext();
80
81                if (!install_insert_db($username,$password,$hostname,$database)) {
82                        require_once 'templates/show_install.inc.php';
83                        break;
84                }
85               
86                header ("Location: " . WEB_PATH . "?action=show_create_config&local_db=$database&local_host=$hostname&htmllang=$htmllang&charset=$charset");
87               
88        break;
89        case 'create_config':
90
91                // Test and make sure that the values they give us actually work
92                if (!check_database($hostname,$username,$password)) { 
93                        Error::add('config',_('Error: Unable to make Database Connection') . mysql_error());
94                } 
95
96                if (!Error::occurred()) { 
97                        $created_config = install_create_config($web_path,$username,$password,$hostname,$database);
98                } 
99
100                require_once 'templates/show_install_config.inc.php';
101        break;
102        case 'show_create_config':
103       
104                /* Attempt to Guess the Web_path */
105                $web_path = dirname($_SERVER['PHP_SELF']);
106                $web_path = rtrim($web_path,"\/");
107
108                /* Get the variables for the language */
109                $htmllang = $_REQUEST['htmllang'];
110                $charset  = $_REQUEST['charset'];
111
112                // Set the lang in the conf array
113                Config::set('lang',$htmllang,'1');
114
115                // We need the charset for the different languages
116                $charsets = array('de_DE' => 'ISO-8859-15',
117                                  'en_US' => 'iso-8859-1',
118                                  'en_GB' => 'UTF-8',
119                                  'ja_JP' => 'UTF-8',
120                                  'es_ES' => 'iso-8859-1',
121                                  'fr_FR' => 'iso-8859-1',
122                                  'el_GR' => 'el_GR.utf-8',
123                                  'it_IT' => 'UTF-8',
124                                  'nl_NL' => 'ISO-8859-15',
125                                  'tr_TR' => 'iso-8859-9',
126                                  'zh_CN' => 'GBK');
127                $charset = $charsets[$_REQUEST['htmllang']];
128               
129                // Set the site_charset in the conf array
130                Config::set('site_charset',$charsets[$_REQUEST['htmllang']],'1');
131               
132                /* load_gettext mojo */
133                load_gettext();
134                header ("Content-Type: text/html; charset=" . Config::get('site_charset'));
135               
136                require_once 'templates/show_install_config.inc.php';
137        break;
138        case 'create_account':
139
140                $results = parse_ini_file($configfile);
141                Config::set_by_array($results,'1');
142
143                /* Get the variables for the language */
144                $htmllang = $_REQUEST['htmllang'];
145                $charset  = $_REQUEST['charset'];
146
147                // Set the lang in the conf array
148                Config::set('lang', $htmllang,'1');
149                Config::set('site_charset', $charset, '1');
150                load_gettext();
151
152                $password2 = scrub_in($_REQUEST['local_pass2']); 
153
154                if (!install_create_account($username,$password,$password2)) { 
155                        require_once Config::get('prefix') . '/templates/show_install_account.inc.php';
156                        break;
157                }
158
159                header ("Location: " . WEB_ROOT . "/login.php");
160        break; 
161        case 'show_create_account':
162       
163                $results = parse_ini_file($configfile);
164
165                /* Get the variables for the language */
166                $htmllang = $_REQUEST['htmllang'];
167                $charset  = $_REQUEST['charset'];
168
169                // Set the lang in the conf array
170                Config::set('lang', $htmllang,'1');
171                Config::set('site_charset', $charset, '1');
172                load_gettext();
173
174                /* Make sure we've got a valid config file */
175                if (!check_config_values($results)) { 
176                        Error::add('general',_('Error: Config file not found or Unreadable')); 
177                        require_once Config::get('prefix') . '/templates/show_install_config.inc.php'; 
178                        break;
179                }
180
181                /* Get the variables for the language */
182                $htmllang = $_REQUEST['htmllang'];
183                $charset  = $_REQUEST['charset'];
184               
185                // Set the lang in the conf array
186                Config::set('lang',$htmllang,'1');
187
188                // We need the charset for the different languages
189                $charsets = array('de_DE' => 'ISO-8859-15',
190                                  'en_US' => 'iso-8859-1',
191                                  'ja_JP' => 'UTF-8',
192                                  'en_GB' => 'UTF-8',
193                                  'es_ES' => 'iso-8859-1',
194                                  'fr_FR' => 'iso-8859-1',
195                                  'it_IT' => 'UTF-8',
196                                  'nl_NL' => 'ISO-8859-15',
197                                  'tr_TR' => 'iso-8859-9',
198                                  'zh_CN' => 'GBK');
199                $charset = $charsets[$_REQUEST['htmllang']];
200               
201                // Set the site_charset in the conf array
202                Config::set('site_charset',$charsets[$_REQUEST['htmllang']],'1');
203               
204                /* load_gettext mojo */
205                load_gettext();
206                header ("Content-Type: text/html; charset=" . Config::get('site_charset'));
207               
208                require_once Config::get('prefix') . '/templates/show_install_account.inc.php';
209        break;
210        case 'init':
211                /* First step of installation */
212                // Get the language
213                $htmllang = $_POST['htmllang'];
214
215                // Set the lang in the conf array
216                Config::set('lang',$htmllang,'1');
217
218                // We need the charset for the different languages
219                $charsets = array('de_DE' => 'ISO-8859-15',
220                                  'en_US' => 'iso-8859-1',
221                                  'ja_JP' => 'UTF-8',
222                                  'en_GB' => 'UTF-8',
223                                  'es_ES' => 'iso-8859-1',
224                                  'fr_FR' => 'iso-8859-1',
225                                  'it_IT' => 'UTF-8',
226                                  'nl_NL' => 'ISO-8859-15',
227                                  'tr_TR' => 'iso-8859-9',
228                                  'zh_CN' => 'GBK');
229                $charset = $charsets[$_POST['htmllang']];
230
231                // Set the site_charset in the conf array
232                Config::set('site_charset',$charsets[$_POST['htmllang']],'1');
233                       
234                // Now we make voodoo with the Load gettext mojo
235                load_gettext();
236
237                // Page ready  :)
238                header ("Content-Type: text/html; charset=$charset");
239                require_once 'templates/show_install.inc.php';
240        break;
241        default:
242                if ($_ENV['LANG']) {
243                        $lang = $_ENV['LANG'];
244                } else {
245                        $lang = "en_US";
246                }
247                if(strpos($lang, ".")) {
248                        $langtmp = split("\.", $lang);
249                        $htmllang = $langtmp[0];
250                        $charset = $langtmp[1];
251                } else {
252                        $htmllang = $lang;
253                        $charset = "UTF-8";
254                }
255                Config::set('lang',$htmllang,'1');
256                Config::set('site_charset', $charset, '1');
257                load_gettext();
258
259                /* Show the language options first */
260                require_once 'templates/show_install_lang.inc.php';
261        break;
262} // end action switch
263
264?>
Note: See TracBrowser for help on using the browser.