aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/install.php
blob: 50ce9fb4e5764f3b7cce286de1322f9d770029b5 (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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?php
/***************************************************************************
 *                                 install.php
 *                            -------------------
 *   begin                : Tuesday, Sept 11, 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : supportphpbb.com
 *
 *   $Id$
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/
//
// First thing to check for is the case that we couldn't write the config
// file and they chose to have use send it to them.
//

if($HTTP_POST_VARS['send_file'] == 1)
{
	header("Content-Type: text/x-delimtext; name=\"config.php\"");
	header("Content-disposition: attachment; filename=config.php");
	if(get_magic_quotes_gpc())
	{
		$HTTP_POST_VARS['config_data'] = stripslashes($HTTP_POST_VARS['config_data']);
	}
	echo $HTTP_POST_VARS['config_data'];
	exit();
}

$phpbb_root_path='./';
include($phpbb_root_path.'extension.inc');


/***************************************************************************
 *								Install Customization Section
 *
 *		This section can be modified to set up some basic default information
 * 	used by the install script.  Specifically the default theme data
 *		and the default template.
 *
 **************************************************************************/
$userdata = "some false data"; 
$theme = array(
	'themes_id' => '2',
	'themes_name' => 'Default',
	'template_name' => 'Default',
	'td_color1' => 'CCCCCC', 
	'td_color2' => 'DDDDDD'
);
$default_language = 'english';
$default_template = 'Default';
					
$available_dbms[] = array(
	"LABEL" => "MySQL",
	"VALUE" => "mysql"
);
$available_dbms[] = array(
	"LABEL" => "MS SQL",
	"VALUE" => "mssql"
);
$available_dbms[] = array(
	"LABEL" => "Postgres",
	"VALUE" => "postgres"
);
$available_dbms[] = array(
	"LABEL" => "ODBC - MSAccess",
	"VALUE" => "odbc:access"
);
$available_dbms[] = array(
	"LABEL" => "ODBC - DB2",
	"VALUE" => "odbc:db2"
);
/***************************************************************************
*		
*						End Install Customization Section
*
***************************************************************************/

//
//	Fill an array with a list of available languages.
//

$dir = opendir($phpbb_root_path.'/language');
while($file = readdir($dir))
{
	if(preg_match("/^lang_(.*)\.$phpEx/", $file, $matches))
	{
		$available_lang[] = $matches[1];
	}
}

//
// Bring in the extra files that contain functions we need.
//

$language = ($HTTP_POST_VARS['language']) ? $HTTP_POST_VARS['language'] : $default_language;
include($phpbb_root_path.'includes/sql_parse.'.$phpEx);
include($phpbb_root_path.'includes/constants.'.$phpEx);
include($phpbb_root_path.'includes/template.'.$phpEx);
include($phpbb_root_path.'includes/functions.'.$phpEx);
include($phpbb_root_path.'language/lang_'.$language.'.'.$phpEx);

//
// Create an instance of the template class.
//
$template = new Template($phpbb_root_path . "templates/" . $default_template);

 
if(file_exists('config.'.$phpEx))
{
	include('config.'.$phpEx);
}
if($installed)
{
	//
	// Sorry this has already been installed can't do anything more with it
	//
	$template->set_filenames(array(
		"body" => "install_error.tpl")
	);
	$template->assign_vars(array(
		"L_TITLE" => $lang['Installer_Error'],
		"L_ERROR" => $lang['Previous_Install'])
	);
	$template->pparse('body');
	die();
}
//
// Ok we haven't installed before so lets work our way through the various
// steps of the install process.  This could turn out to be quite a lengty 
// process.
//
$installStep = ($HTTP_POST_VARS['installStep']) ? $HTTP_POST_VARS['installStep']: $HTTP_GET_VARS['installStep'];
$dbms = ($HTTP_POST_VARS['dbms']);
if( (!isset($installStep) || $installStep == 0) || ($HTTP_POST_VARS['admin_pass1'] != $HTTP_POST_VARS['admin_pass2']) )
{
	//
	// Step 0 gather the pertinant info for database setup...
	// Namely dbms, dbhost, dbname, dbuser, and dbpasswd.
	//
	$Instruct = $lang['Inst_Step_0'];
	if( $HTTP_POST_VARS['admin_pass1'] != $HTTP_POST_VARS['admin_pass2'] )
	{
		$Instruct = $lang['Password_mismatch'] . '<br>' . $Instruct;
	}
	$template->set_filenames(array(
		"body" => "install.tpl")
	);
	$template->assign_vars(array(
		"L_INSTRUCT" => $Instruct,
		"L_SUBMIT" => $lang['Start_Install'],
		"S_FORM_ACTION" => 'install.'.$phpEx)
	);
	$template->assign_block_vars("hidden_fields", array(
		"NAME" => "installStep",
		"VALUE" => "1")
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "dbhost",
		"TYPE" => "text",
		"VALUE" => $HTTP_POST_VARS['dbhost'],
		"L_LABEL" => $lang['DB_Host'] . ':')
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "dbname",
		"TYPE" => "text",
		"VALUE" => $HTTP_POST_VARS['dbname'],
		"L_LABEL" => $lang['DB_Name'] . ':')
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "dbuser",
		"TYPE" => "text",
		"VALUE" => $HTTP_POST_VARS['dbuser'],
		"L_LABEL" => $lang['Database'] . ' ' . $lang['Username'] . ':')
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "dbpasswd",
		"TYPE" => "password",
		"VALUE" => $HTTP_POST_VARS['dbpasswd'],
		"L_LABEL" => $lang['Database'] . ' ' . $lang['Password'] . ':')
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "prefix",
		"TYPE" => "text",
		"VALUE" => (!empty($HTTP_POST_VARS['prefix'])) ? $HTTP_POST_VARS['prefix'] : "phpbb_",
		"L_LABEL" => $lang['Table_Prefix'] . ':')
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "admin_name",
		"TYPE" => "text",
		"VALUE" => $HTTP_POST_VARS['admin_name'],
		"L_LABEL" => $lang['Administrator'] . ' ' . $lang['Username'] . ':')
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "admin_pass1",
		"TYPE" => "password",
		"VALUE" => $HTTP_POST_VARS['admin_pass1'],
		"L_LABEL" => $lang['Administrator'] . ' ' . $lang['Password'] . ':')
	);
	$template->assign_block_vars("inputs", array(
		"NAME" => "admin_pass2",
		"TYPE" => "password",
		"VALUE" => $HTTP_POST_VARS['admin_pass2'],
		"L_LABEL" => $lang['Confirm'] . ' ' . $lang['Password'] . ':')
	);
	$template->assign_block_vars("selects", array(
		"NAME" => "language",
		"L_LABEL" => $lang['Install_lang'])
	);
	for($i = 0; $i < count($available_lang); $i++)
	{
		$template->assign_block_vars("selects.options", array(
			"LABEL" => $available_lang[$i],
			"DEFAULT" => ($available_lang[$i] == $HTTP_POST_VARS['language'])?'SELECTED':'',
			"VALUE" => $available_lang[$i])
		);
	}
	$template->assign_block_vars("selects", array(
		"NAME" => "dbms",
		"L_LABEL" => $lang['dbms'])
	);
	for($i = 0; $i < count($available_dbms); $i++)
	{
		$template->assign_block_vars("selects.options", array(
			"LABEL" => $available_dbms[$i]['LABEL'],
			"DEFAULT" => ($available_dbms[$i]['VALUE'] == $HTTP_POST_VARS['dbms'])?'SELECTED':'',
			"VALUE" => $available_dbms[$i]['VALUE'])
		);
	}
	$template->pparse("body");
	exit();
}
//
// If the dbms is set to be odbc then we need to skip most of the 
// steps and go straight to writing the config file.  We'll spit
// out some additional instructions later on what to do after installation
// for the odbc DBMS.
//
if (ereg(':', $dbms) && $installStep < 2)
{
	$dbms = explode(':', $dbms);
	$dbhost = $dbms[1] . ':' . $dbhost;
	$dbms = $dbms[0];
	$installStep = 2;
}
elseif ( isset($dbms) ) 
{
	include($phpbb_root_path.'includes/db.'.$phpEx);
}

$dbms_schema = 'db/'.$dbms.'_schema.sql';
$dbms_basic = 'db/'.$dbms.'_basic.sql';
$remove_remarks = ($dbms == 'mysql')?'remove_remarks':'remove_comments';
$delimiter = ( $dbms == 'mssql' )?'GO':';'; 
switch ( $installStep )
{
	case 1:
		//
		// Ok we have the db info go ahead and read in the relevant schema
		// and work on building the table.. probably ought to provide some
		// kind of feedback to the user as we are working here in order
		// to let them know we are actually doing something.
		//
		$sql_query = fread(fopen($dbms_schema, 'r'), filesize($dbms_schema));
		$sql_query = $remove_remarks($sql_query);
		$sql_query = split_sql_file($sql_query, $delimiter);
		$sql_count = count($sql_query);
		$sql_query = preg_replace('/phpbb_/', $HTTP_POST_VARS['prefix'], $sql_query);
		for($i = 0; $i < $sql_count; $i++)
		{
			$result = $db->sql_query($sql_query[$i]);
			if( !$result )
			{
				$error = $db->sql_error();
				$template->set_filenames(array(
					"body" => "install_error.tpl")
				);
				$template->assign_vars(array(
					"L_TITLE" => $lang['Installer_Error'],
					"L_ERROR" => $lang['Install_db_error'] . '<br>' . $error['message'])
				);
				$template->pparse('body');
				die();
			}
		}
		//
		// Ok tables have been built, let's fill in the basic information
		//
		$sql_query = fread(fopen($dbms_basic, 'r'), filesize($dbms_basic));
		$sql_query = $remove_remarks($sql_query);
		$sql_query = split_sql_file($sql_query, $delimiter);
		$sql_count = count($sql_query);
		$sql_query = preg_replace('/phpbb_/', $HTTP_POST_VARS['prefix'], $sql_query);
		for($i = 0; $i < $sql_count; $i++)
		{
			$result = $db->sql_query($sql_query[$i]);
			if( !$result )
			{
				$error = $db->sql_error();
				$template->set_filenames(array(
					"body" => "install_error.tpl")
				);
				$template->assign_vars(array(
					"L_TITLE" => $lang['Installer_Error'],
					"L_ERROR" => $lang['Install_db_error'] . "<br>" . $error["message"])
				);
				$template->pparse('body');
				die();
			}
		}
		//
		// Ok at this point they have entered their admin password, let's go 
		// ahead and create the admin account with some basic default information
		// that they can customize later, and write out the config file.  After
		// this we are going to pass them over to the admin_forum.php script
		// to set up their forum defaults.
		//
		if( $dbms == 'odbc' )
		{
			//
			// Output the instructions for the odbc...
			//
			$template->set_filenames(array(
				"body" => "install.tpl")
			);
			
			$template->assign_vars(array(
				"L_INSTRUCT" => $lang['ODBC_Instructs'],
				"L_SUBMIT" => $lang['OK'],
				"S_FORM_ACTION" => 'install.'.$phpEx)
			);
			$template->assign_block_vars("hidden_fields", array(
				"NAME" => "installStep",
				"VALUE" => '3')
			);
			exit();
		}
		else
		{
			//
			// Update the default admin user with their information.
			//
			$sql = "UPDATE ".$HTTP_POST_VARS['prefix']."users 
						SET username='".$HTTP_POST_VARS['admin_name']."',
							user_password='".md5($HTTP_POST_VARS['admin_pass1'])."'
						WHERE username = 'Admin'";
			$result = $db->sql_query($sql);
			if( !$result )
			{
				$error = $db->sql_error();
				$template->set_filenames(array(
					"body" => "install_error.tpl")
				);
				$template->assign_vars(array(
					"L_TITLE" => $lang['Installer_Error'],
					"L_ERROR" => $lang['Install_db_error'] . '<br>' . $error['message'])
				);
				$template->pparse('body');
				die();
			}
			//
			// Write out the config file.
			//
			$config_data = '<?php'."\n";
			$config_data.= '$dbms = "'.$dbms.'";'."\n";
			$config_data.= '$dbhost = "'.$dbhost.'";'."\n";
			$config_data.= '$dbname = "'.$dbname.'";'."\n";
			$config_data.= '$dbuser = "'.$dbuser.'";'."\n";
			$config_data.= '$dbpasswd = "'.$dbpasswd.'";'."\n";
			$config_data.= '$installed = True;'."\n";	
			$config_data.= '$table_prefix = "'.$HTTP_POST_VARS['prefix'].'";'."\n";
			$config_data.= '?>';
			@umask(0111);
			$noOpen = False;
			$fp = @fopen('config.php', 'w');
			if(!$fp)
			{
				//
				// Unable to open the file writeable do something here as an attempt
				// to get around that...
				$template->set_filenames(array(
						"body" => "install.tpl")
				);
				$template->assign_vars(array(
					"L_INSTRUCT" => $lang['UnWrite_Config'],
					"L_SUBMIT" => $lang['Send_Config'],
					"S_FORM_ACTION" => 'install.'.$phpEx)
				);
				$template->assign_block_vars("hidden_fields", array(
					"NAME" => "config_data",
					"VALUE" => htmlspecialchars($config_data) )
				);
				$template->assign_block_vars("hidden_fields", array(
					"NAME" => "send_file",
					"VALUE" => "1")
				);
				$template->pparse('body');
				exit();
			}
			$result = fputs($fp, $config_data, strlen($config_data));
			fclose($fp);
			//
			// Ok we are basically done with the install process let's go on 
			// and let the user configure their board now.
			// We are going to do this by calling the admin_board.php from the
			// normal board admin section.
			//
			$template->set_filenames(array(
				"body" => "install.tpl")
			);
			$template->assign_vars(array(
				"L_INSTRUCT" => $lang['Inst_Step_2'],
				"L_SUBMIT" => $lang['Finish_Install'],
				"S_FORM_ACTION" => 'login.'.$phpEx)
			);
			
			$template->assign_block_vars("hidden_fields", array(
				"NAME" => 'username',
				"VALUE" => $admin_name)
			);
			$template->assign_block_vars("hidden_fields", array(
				"NAME" => 'password',
				"VALUE" => $admin_pass1)
			);
			$template->assign_block_vars("hidden_fields", array(
				"NAME" => 'submit',
				"VALUE" => 'Login')
			);
			$template->assign_block_vars("hidden_fields", array(
				"NAME" => 'forward_page',
				"VALUE" => 'admin/admin_board.'.$phpEx.'?mode=config')
			);
			$template->pparse('body');
			exit();
		}
		break;
}