Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit 0a75df5

Browse files
committed
create database config file only if connected to db
1 parent 1fe1d71 commit 0a75df5

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

install.php

+34-37
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,27 @@
88
*/
99
require_once('functions.php');
1010
if(isset($_POST['host'])) {
11-
12-
1311
// connect to the MySQL server
1412
$link=mysql_connect($_POST['host'],$_POST['username'],$_POST['password']);
1513
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` (
3532
`name` varchar(30) NOT NULL,
3633
`start` int(11) NOT NULL,
3734
`end` int(11) NOT NULL,
@@ -41,11 +38,11 @@
4138
`python` int(11) NOT NULL,
4239
`formula` text NOT NULL
4340
)");
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
4643
('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` (
4946
`sl` int(11) NOT NULL AUTO_INCREMENT,
5047
`name` varchar(200) NOT NULL,
5148
`text` text NOT NULL,
@@ -55,8 +52,8 @@
5552
`points` int(11) NOT NULL,
5653
PRIMARY KEY (`sl`)
5754
)");
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` (
6057
`sl` int(11) NOT NULL AUTO_INCREMENT,
6158
`problem_id` int(11) NOT NULL,
6259
`username` varchar(25) NOT NULL,
@@ -68,8 +65,8 @@
6865
`time` bigint(20) NOT NULL,
6966
PRIMARY KEY (`sl`)
7067
)");
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` (
7370
`sl` int(11) NOT NULL AUTO_INCREMENT,
7471
`username` varchar(25) NOT NULL,
7572
`salt` varchar(6) NOT NULL,
@@ -79,14 +76,14 @@
7976
`score` float NOT NULL,
8077
PRIMARY KEY (`sl`)
8178
)");
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+
}
9087
}
9188
?>
9289
<!DOCTYPE html>

0 commit comments

Comments
 (0)