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