summaryrefslogtreecommitdiff
blob: 393a1fe3d2ff087f3942365a346eb32a13cd9c6b (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
#!/usr/bin/php
<?php
require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ in 5.3.0
$S['conf']['debug']=true;
$interactive=posix_isatty(STDIN);
$opts=getopt('R');
$S['pdo']=new PDO('mysql:host='.$S['conf']['sqlhost'], $S['conf']['sqluser'], $S['conf']['sqlpass']);
if (isset($opts['R'])) {
	query('DROP DATABASE IF EXISTS `'.$S['conf']['sqldb'].'`');
}
query('CREATE DATABASE IF NOT EXISTS `'.$S['conf']['sqldb'].'`'); // We can add charset and collate here if we want
query('USE `'.$S['conf']['sqldb'].'`');
sql_row_obj::set_pdo_obj($S['pdo']);
foreach (get_declared_classes() as $class) {
	if (!is_subclass_of($class, 'sql_row_obj')) {
		continue;
	}
	$r=new ReflectionClass($class);
	if (!$r->isInstantiable()) continue;
	unset($r);
	$o=new $class(); // TODO this will be static once 5.3.0 is out	
	if (isset($opts['R'])) {
		query($o->drop_table());
	}
	query($o->create_table());
}
$user=new sql_user();
do {
	if ($user->email) {
		echo 'Invalid entry: '.$user->email."\n";
	}
	echo 'Admin email address: ';
	$user->email=trim(fgets(STDIN));
	if (!$interactive) {
		echo "\n";
	}
} while (!Validate::email($user->email));
do {
	if ($user->name) {
		echo 'Invalid entry: '.$user->name."\n";
	}
	echo 'Admin display name: ';
	$user->name=trim(fgets(STDIN));
	if (!$interactive) {
		echo "\n";
	}
} while (!Validate::username($user->name));
if ($interactive) {
	system('stty -echo');
}
do {
	if (isset($pass)) {
		echo "Entered passwords did not match.  Try again.\n";
	}
	echo 'Admin password: ';
	$pass=trim(fgets(STDIN));
	echo "\nRepeat password: ";
	$passconfirm=trim(fgets(STDIN));
	echo "\n";
} while (!$pass || $pass != $passconfirm);
if ($interactive) {
	system('stty echo');
}
$user->passhash=substr($pass, 0, 5)=='sha1:'?substr($pass, 5):sha1($pass);
$user->flags='a'; // Admin
$user->write();
foreach (glob(dirname(__FILE__).'/*_setup.php') as $file) { // __DIR__ 5.3.0
	require($file);
}
?>