summaryrefslogtreecommitdiffstats
path: root/install.php
blob: 0a740a5f36c11e023b6728e6c5de57b740a2c4b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
/**
 * Install
 *
 *
 * LICENSE: GNU General Public License, version 2 (GPLv2)
 * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License v2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * @package	Ampache
 * @copyright	2001 - 2011 Ampache.org
 * @license	http://opensource.org/licenses/gpl-2.0 GPLv2
 * @link	http://www.ampache.org/
 */

// Set the Error level manualy... I'm to lazy to fix notices
error_reporting(E_ALL ^ E_NOTICE);

require_once 'lib/general.lib.php';
require_once 'lib/class/config.class.php';
require_once 'lib/class/error.class.php';
require_once 'lib/class/vauth.class.php';
require_once 'lib/class/database_object.abstract.php';
require_once 'lib/class/preference.class.php';
require_once 'lib/class/access.class.php';
require_once 'lib/ui.lib.php';
require_once 'lib/log.lib.php';
require_once 'modules/horde/Browser.php';
require_once 'lib/install.php';
require_once 'lib/debug.lib.php';
require_once 'lib/gettext.php';

if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; }
else { $http_type = "http://"; }

$prefix = dirname(__FILE__);
Config::set('prefix',$prefix,'1');
$configfile = "$prefix/config/ampache.cfg.php";

set_error_handler('ampache_error_handler');

/* First things first we must be sure that they actually still need to
   install ampache
*/
if (!install_check_status($configfile)) {
	$redirect_url = "login.php";
	require_once Config::get('prefix') . '/templates/error_page.inc.php';
	exit;
}

define('INSTALL','1');
/**
 * @ignore
 */
define('INIT_LOADED','1');

/* Clean up incomming variables */
$web_path = scrub_in($_REQUEST['web_path']);
$username = scrub_in($_REQUEST['local_username']);
$password = $_REQUEST['local_pass'];
$hostname = scrub_in($_REQUEST['local_host']);
$database = scrub_in($_REQUEST['local_db']);
if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; }
else { $http_type = "http://"; }

// Correct potential \ or / in the dirname
$safe_dirname = rtrim(dirname($_SERVER['PHP_SELF']),"/\\"); 

define('WEB_PATH',$http_type . $_SERVER['HTTP_HOST'] . $safe_dirname . '/' . basename($_SERVER['PHP_SELF']));
define('WEB_ROOT',$http_type . $_SERVER['HTTP_HOST'] . $safe_dirname);

unset($safe_dirname); 

/* Catch the Current Action */
switch ($_REQUEST['action']) {
	case 'create_db':
		/* Get the variables for the language */
		$htmllang = $_REQUEST['htmllang'];
		$charset  = $_REQUEST['charset'];

		// Set the lang in the conf array
		Config::set('lang', $htmllang,'1');
		Config::set('site_charset', $charset, '1');
		load_gettext();

		if (!install_insert_db($username,$password,$hostname,$database)) {
			require_once 'templates/show_install.inc.php';
			break;
		}

		// Now that it's inserted save the lang preference
		Preference::update('lang','-1',$htmllang);

		header ("Location: " . WEB_PATH . "?action=show_create_config&local_db=$database&local_host=$hostname&htmllang=$htmllang&charset=$charset");

	break;
	case 'create_config':

		$htmllang = $_REQUEST['htmllang'];
		$charset  = $_REQUEST['charset'];
		// Test and make sure that the values they give us actually work
		if (!check_database($hostname,$username,$password)) {
			Error::add('config',_('Error: Unable to make Database Connection') . mysql_error());
		}

		if (!Error::occurred()) {
			$created_config = install_create_config($web_path,$username,$password,$hostname,$database);
		}

		require_once 'templates/show_install_config.inc.php';
	break;
	case 'show_create_config':

                /* Attempt to Guess the Web_path */
		$web_path = dirname($_SERVER['PHP_SELF']);
		$web_path = rtrim($web_path,"\/");

		/* Get the variables for the language */
		$htmllang = $_REQUEST['htmllang'];
		$charset  = $_REQUEST['charset'];

		// Set the lang in the conf array
		Config::set('lang',$htmllang,'1');

		// We need the charset for the different languages
		$charsets = array(
				  'ar_SA' => 'UTF-8',
				  'de_DE' => 'ISO-8859-15',
				  'en_US' => 'iso-8859-1',
				  'en_GB' => 'UTF-8',
				  'ja_JP' => 'UTF-8',
				  'es_ES' => 'iso-8859-1',
				  'fr_FR' => 'iso-8859-1',
				  'el_GR' => 'el_GR.utf-8',
				  'it_IT' => 'UTF-8',
				  'nl_NL' => 'ISO-8859-15',
				  'tr_TR' => 'iso-8859-9',
				  'zh_CN' => 'GBK');
		$charset = $charsets[$_REQUEST['htmllang']];

		// Set the site_charset in the conf array
		Config::set('site_charset',$charsets[$_REQUEST['htmllang']],'1');

		/* load_gettext mojo */
		load_gettext();
		header ("Content-Type: text/html; charset=" . Config::get('site_charset'));

		require_once 'templates/show_install_config.inc.php';
	break;
	case 'create_account':

		$results = parse_ini_file($configfile);
		Config::set_by_array($results,'1');

		/* Get the variables for the language */
		$htmllang = $_REQUEST['htmllang'];
		$charset  = $_REQUEST['charset'];

		// Set the lang in the conf array
		Config::set('lang', $htmllang,'1');
		Config::set('site_charset', $charset, '1');
		load_gettext();

		$password2 = scrub_in($_REQUEST['local_pass2']);

		if (!install_create_account($username,$password,$password2)) {
			require_once Config::get('prefix') . '/templates/show_install_account.inc.php';
			break;
		}

		header ("Location: " . WEB_ROOT . "/login.php");
	break;
	case 'show_create_account':

		$results = parse_ini_file($configfile);

		/* Get the variables for the language */
		$htmllang = $_REQUEST['htmllang'];
		$charset  = $_REQUEST['charset'];

		// Set the lang in the conf array
		Config::set('lang', $htmllang,'1');
		Config::set('site_charset', $charset, '1');
		load_gettext();

		/* Make sure we've got a valid config file */
		if (!check_config_values($results)) {
			Error::add('general',_('Error: Config file not found or Unreadable'));
			require_once Config::get('prefix') . '/templates/show_install_config.inc.php';
			break;
		}

		/* Get the variables for the language */
		$htmllang = $_REQUEST['htmllang'];
		$charset  = $_REQUEST['charset'];

		// Set the lang in the conf array
		Config::set('lang',$htmllang,'1');

		// We need the charset for the different languages
		$charsets = array(
				  'ar_SA' => 'UTF-8',
				  'de_DE' => 'ISO-8859-15',
				  'en_US' => 'iso-8859-1',
				  'ja_JP' => 'UTF-8',
				  'en_GB' => 'UTF-8',
				  'es_ES' => 'iso-8859-1',
				  'fr_FR' => 'iso-8859-1',
				  'it_IT' => 'UTF-8',
				  'nl_NL' => 'ISO-8859-15',
				  'tr_TR' => 'iso-8859-9',
				  'zh_CN' => 'GBK');
		$charset = $charsets[$_REQUEST['htmllang']];

		// Set the site_charset in the conf array
		Config::set('site_charset',$charsets[$_REQUEST['htmllang']],'1');

		/* load_gettext mojo */
		load_gettext();
		header ("Content-Type: text/html; charset=" . Config::get('site_charset'));

		require_once Config::get('prefix') . '/templates/show_install_account.inc.php';
	break;
        case 'init':
		/* First step of installation */
		// Get the language
		$htmllang = $_POST['htmllang'];

		// Set the lang in the conf array
		Config::set('lang',$htmllang,'1');

		// We need the charset for the different languages
		$charsets = array(
				  'ar_SA' => 'UTF-8',
				  'de_DE' => 'ISO-8859-15',
				  'en_US' => 'iso-8859-1',
				  'cs_CZ' => 'UTF-8',
				  'ja_JP' => 'UTF-8',
				  'en_GB' => 'UTF-8',
				  'es_ES' => 'iso-8859-1',
				  'fr_FR' => 'iso-8859-1',
				  'it_IT' => 'UTF-8',
				  'nl_NL' => 'ISO-8859-15',
				  'tr_TR' => 'iso-8859-9',
				  'zh_CN' => 'GBK');
		$charset = $charsets[$_POST['htmllang']];

		// Set the site_charset in the conf array
 	        Config::set('site_charset',$charsets[$_POST['htmllang']],'1');

		// Now we make voodoo with the Load gettext mojo
		load_gettext();

		// Page ready  :)
		header ("Content-Type: text/html; charset=$charset");
		require_once 'templates/show_install.inc.php';
	break;
        default:
		if ($_ENV['LANG']) {
			$lang = $_ENV['LANG'];
		} else {
			$lang = "en_US";
		}
		if(strpos($lang, ".")) {
			$langtmp = explode(".", $lang);
			$htmllang = $langtmp[0];
			$charset = $langtmp[1];
		} else {
			$htmllang = $lang;
			$charset = "UTF-8";
		}
		Config::set('lang',$htmllang,'1');
		Config::set('site_charset', $charset, '1');
		load_gettext();

		/* Show the language options first */
		require_once 'templates/show_install_lang.inc.php';
	break;
} // end action switch

?>