summaryrefslogtreecommitdiff
path: root/www/setup.php
blob: 00aa9ed87a3ce234488616debef509cce860aabc (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
<?

/*Sets up the database with the user table. Add ?drop to drop _everything_*/

$db = new SQLite3("../database/sqlite.db");

foreach ($_GET as $name => $value) {
	if(preg_match("/drop(ped)?/i",$name)){
		$bool=true;
	}
}

if($bool){
	if($db->exec("
		BEGIN TRANSACTION;
		PRAGMA writable_schema = 1;
		delete from sqlite_master where type = 'table';
		PRAGMA writable_schema = 0;
		COMMIT;
		VACUUM;")
	){
		echo "dropped everything";
	} else {
		echo "error with database";
	}
} else {
	$cleartext_password="password";
	$salt = uniqid(mt_rand(), true);
	$password = "$salt"."$cleartext_password";
	$hash_password = md5($password);
	for($i=0;$i<15000;$i++)
		$hash_password = md5($hash_password);


	if($db->exec("
		BEGIN TRANSACTION;
		CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY, name TEXT UIQUE, senpai INTEGER, key TEXT, status INTEGER, invites INTEGER, salt TEXT, password TEXT, email TEXT UNIQUE);
		INSERT INTO user (id, name, senpai, key, status, invites, salt, password, email) VALUES (NULL, 'admin', 0, '11111', 1, 5, '$salt', '$hash_password', 'admin@iamfabulous.de');
		COMMIT;")
	) {
		echo "Success!";
	} else {
		echo "Failure! :( <br>";
		echo "Salt: $salt, password: $hash_password";
	}
}
//	INSERT INT0 user (id, name, salt, password, status, invites, email, senpai, key) VALUES (NULL, 'admin', '$salt', '$hash_password', 1, 5, 'admin@iamfabulous.de', 0, '11111');