|
8 | 8 | */ |
9 | 9 | require_once('functions.php'); |
10 | 10 | if(isset($_POST['host'])) { |
11 | | - // create file 'dbinfo.php' |
12 | | - $fp = fopen('dbinfo.php','w'); |
13 | | - $l1 = '$host="'.$_POST['host'].'";'; |
14 | | - $l2 = '$user="'.$_POST['username'].'";'; |
15 | | - $l3 = '$password="'.$_POST['password'].'";'; |
16 | | - $l4 = '$database="'.$_POST['name'].'";'; |
17 | | - $l5 = '$compilerhost="'.$_POST['chost'].'";'; |
18 | | - $l6 = '$compilerport='.$_POST['cport'].';'; |
19 | | - fwrite($fp, "<?php\n$l1\n$l2\n$l3\n$l4\n$l5\n$l6\n?>"); |
20 | | - fclose($fp); |
21 | | - include('dbinfo.php'); |
22 | 11 | // connect to the MySQL server |
23 | | - mysql_connect($host,$user,$password); |
24 | | - // create the database |
25 | | - mysql_query("CREATE DATABASE $database"); |
26 | | - mysql_select_db($database) or die('Error connecting to database.'); |
27 | | - // create the preferences table |
28 | | - mysql_query("CREATE TABLE IF NOT EXISTS `prefs` ( |
| 12 | + $link=mysql_connect($_POST['host'],$_POST['username'],$_POST['password']); |
| 13 | + if (!$link) { |
| 14 | + die('Could not connect'); |
| 15 | + } else { |
| 16 | + // create file 'dbinfo.php' |
| 17 | + $fp = fopen('dbinfo.php','w'); |
| 18 | + $l1 = '$host="'.$_POST['host'].'";'; |
| 19 | + $l2 = '$user="'.$_POST['username'].'";'; |
| 20 | + $l3 = '$password="'.$_POST['password'].'";'; |
| 21 | + $l4 = '$database="'.$_POST['name'].'";'; |
| 22 | + $l5 = '$compilerhost="'.$_POST['chost'].'";'; |
| 23 | + $l6 = '$compilerport='.$_POST['cport'].';'; |
| 24 | + fwrite($fp, "<?php\n$l1\n$l2\n$l3\n$l4\n$l5\n$l6\n?>"); |
| 25 | + fclose($fp); |
| 26 | + include('dbinfo.php'); |
| 27 | + // create the database |
| 28 | + mysql_query("CREATE DATABASE $database"); |
| 29 | + mysql_select_db($database) or die('Error connecting to database.'); |
| 30 | + // create the preferences table |
| 31 | + mysql_query("CREATE TABLE IF NOT EXISTS `prefs` ( |
29 | 32 | `name` varchar(30) NOT NULL, |
30 | 33 | `start` int(11) NOT NULL, |
31 | 34 | `end` int(11) NOT NULL, |
|
35 | 38 | `python` int(11) NOT NULL, |
36 | 39 | `formula` text NOT NULL |
37 | 40 | )"); |
38 | | - // fill it with default preferences |
39 | | - mysql_query("INSERT INTO `prefs` (`name`, `start`, 'end', `c`, `cpp`, `java`, `python`, `forumla`) VALUES |
| 41 | + // fill it with default preferences |
| 42 | + mysql_query("INSERT INTO `prefs` (`name`, `start`, 'end', `c`, `cpp`, `java`, `python`, `forumla`) VALUES |
40 | 43 | ('Codejudge', 01/01/70 00:00:00, 01/01/70 00:00:00, 1, 1, 1,'\$score = \$points / \$attempts')"); |
41 | | - // create the problems table |
42 | | - mysql_query("CREATE TABLE IF NOT EXISTS `problems` ( |
| 44 | + // create the problems table |
| 45 | + mysql_query("CREATE TABLE IF NOT EXISTS `problems` ( |
43 | 46 | `sl` int(11) NOT NULL AUTO_INCREMENT, |
44 | 47 | `name` varchar(200) NOT NULL, |
45 | 48 | `text` text NOT NULL, |
|
49 | 52 | `points` int(11) NOT NULL, |
50 | 53 | PRIMARY KEY (`sl`) |
51 | 54 | )"); |
52 | | - // create the solve table |
53 | | - mysql_query("CREATE TABLE IF NOT EXISTS `solve` ( |
| 55 | + // create the solve table |
| 56 | + mysql_query("CREATE TABLE IF NOT EXISTS `solve` ( |
54 | 57 | `sl` int(11) NOT NULL AUTO_INCREMENT, |
55 | 58 | `problem_id` int(11) NOT NULL, |
56 | 59 | `username` varchar(25) NOT NULL, |
|
62 | 65 | `time` bigint(20) NOT NULL, |
63 | 66 | PRIMARY KEY (`sl`) |
64 | 67 | )"); |
65 | | - // create the users table |
66 | | - mysql_query("CREATE TABLE IF NOT EXISTS `users` ( |
| 68 | + // create the users table |
| 69 | + mysql_query("CREATE TABLE IF NOT EXISTS `users` ( |
67 | 70 | `sl` int(11) NOT NULL AUTO_INCREMENT, |
68 | 71 | `username` varchar(25) NOT NULL, |
69 | 72 | `salt` varchar(6) NOT NULL, |
|
73 | 76 | `score` float NOT NULL, |
74 | 77 | PRIMARY KEY (`sl`) |
75 | 78 | )"); |
76 | | - // create the user 'admin' with password 'admin' |
77 | | - $salt=randomAlphaNum(5); |
78 | | - $pass="admin"; |
79 | | - $hash=crypt($pass,$salt); |
80 | | - $sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('$pass', '$salt', '$hash', '".$_POST['email']."')"; |
81 | | - mysql_query($sql); |
82 | | - header("Location: install.php?installed=1"); |
83 | | - } |
| 79 | + // create the user 'admin' with password 'admin' |
| 80 | + $salt=randomAlphaNum(5); |
| 81 | + $pass="admin"; |
| 82 | + $hash=crypt($pass,$salt); |
| 83 | + $sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('$pass', '$salt', '$hash', '".$_POST['email']."')"; |
| 84 | + mysql_query($sql); |
| 85 | + header("Location: install.php?installed=1"); |
| 86 | + } |
| 87 | + } |
84 | 88 | ?> |
85 | 89 | <!DOCTYPE html> |
86 | 90 | <html lang="en"><head> |
|
0 commit comments