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

Commit ea79937

Browse files
committed
added the installer
1 parent e054646 commit ea79937

File tree

3 files changed

+139
-2
lines changed

3 files changed

+139
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*~
2-
2+
dbinfo.php

admin/problems.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
connectdb();
1010
?>
1111
<li class="active"><a href="#">Admin Panel</a></li>
12-
<li><a href="http://github.com/%3Cspan%20class="x x-first x-last">#about">Users</a></li>
12+
<li><a href="http://github.com/%3Cspan%20class="x x-first x-last">users.php">Users</a></li>
1313
<li><a href="logout.php">Logout</a></li>
1414
</ul>
1515
</div><!--/.nav-collapse -->

install.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
require_once('functions.php');
3+
if(isset($_POST['host'])) {
4+
$fp = fopen('dbinfo.php','w');
5+
$l1 = '$host="'.$_POST['host'].'";';
6+
$l2 = '$user="'.$_POST['username'].'";';
7+
$l3 = '$password="'.$_POST['password'].'";';
8+
$l4 = '$database="'.$_POST['name'].'";';
9+
fwrite($fp, "<?php\n$l1\n$l2\n$l3\n$l4\n?>");
10+
fclose($fp);
11+
include('dbinfo.php');
12+
mysql_connect($host,$user,$password);
13+
mysql_query("CREATE DATABASE $database");
14+
mysql_select_db($database) or die('Error connecting to database.');
15+
mysql_query("CREATE TABLE `prefs` (
16+
`name` varchar(30) NOT NULL,
17+
`accept` int(11) NOT NULL,
18+
`c` int(11) NOT NULL,
19+
`cpp` int(11) NOT NULL,
20+
`java` int(11) NOT NULL,
21+
`python` int(11) NOT NULL
22+
)");
23+
mysql_query("INSERT INTO `prefs` (`name`, `accept`, `c`, `cpp`, `java`, `python`) VALUES
24+
('Codejudge', 1, 1, 1, 1, 1)");
25+
mysql_query("CREATE TABLE IF NOT EXISTS `problems` (
26+
`sl` int(11) NOT NULL AUTO_INCREMENT,
27+
`name` varchar(200) NOT NULL,
28+
`text` text NOT NULL,
29+
`input` text NOT NULL,
30+
`output` text NOT NULL,
31+
PRIMARY KEY (`sl`)
32+
)");
33+
mysql_query("CREATE TABLE IF NOT EXISTS `solve` (
34+
`sl` int(11) NOT NULL AUTO_INCREMENT,
35+
`problem_id` int(11) NOT NULL,
36+
`username` varchar(25) NOT NULL,
37+
`status` int(11) NOT NULL DEFAULT '1',
38+
`attempts` int(11) NOT NULL DEFAULT '1',
39+
`soln` text NOT NULL,
40+
`filename` varchar(25) NOT NULL,
41+
`lang` varchar(20) NOT NULL,
42+
PRIMARY KEY (`sl`)
43+
)");
44+
mysql_query("CREATE TABLE IF NOT EXISTS `users` (
45+
`sl` int(11) NOT NULL AUTO_INCREMENT,
46+
`username` varchar(25) NOT NULL,
47+
`salt` varchar(6) NOT NULL,
48+
`hash` varchar(80) NOT NULL,
49+
`email` varchar(100) NOT NULL,
50+
`status` int(11) NOT NULL DEFAULT '1',
51+
PRIMARY KEY (`sl`)
52+
)");
53+
$salt=randomAlphaNum(5);
54+
$pass="admin";
55+
$hash=crypt($pass,$salt);
56+
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('$pass', '$salt', '$hash', '".$_POST['email']."')";
57+
mysql_query($sql);
58+
mkdir("solution");
59+
header("Location: install.php?installed=1");
60+
}
61+
?>
62+
<!DOCTYPE html>
63+
<html lang="en"><head>
64+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
65+
<meta charset="utf-8">
66+
<title>Codejudge Setup</title>
67+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
68+
<meta name="description" content="">
69+
<meta name="author" content="">
70+
71+
<!-- Le styles -->
72+
<link href="css/bootstrap.css" rel="stylesheet">
73+
<style>
74+
body {
75+
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
76+
}
77+
78+
.footer {
79+
text-align: center;
80+
font-size: 11px;
81+
}
82+
</style>
83+
<link href="css/bootstrap-responsive.css" rel="stylesheet">
84+
85+
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
86+
<!--[if lt IE 9]>
87+
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
88+
<![endif]-->
89+
90+
<!-- Le fav and touch icons -->
91+
<link rel="shortcut icon" href="http://twitter.github.com/bootstrap/assets/ico/favicon.ico">
92+
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-144-precomposed.png">
93+
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-114-precomposed.png">
94+
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-72-precomposed.png">
95+
<link rel="apple-touch-icon-precomposed" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-57-precomposed.png">
96+
</head>
97+
98+
<body>
99+
100+
<div class="navbar navbar-fixed-top">
101+
<div class="navbar-inner">
102+
<div class="container">
103+
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
104+
<span class="icon-bar"></span>
105+
<span class="icon-bar"></span>
106+
<span class="icon-bar"></span>
107+
</a>
108+
<a class="brand" href="#">Codejudge Setup</a>
109+
</div>
110+
</div>
111+
</div>
112+
113+
<div class="container">
114+
<?php
115+
if(isset($_GET['installed'])) {?>
116+
<div class="alert alert-success">Codejudge is successfully installed!</div>
117+
118+
You can login to the admin panel <a href="admin/">here</a> with the password <strong>admin</strong>. You can change it once you login to the admin panel.
119+
<?php }else if(!file_exists("dbinfo.php")){ ?>
120+
Welcome to the Codejudge setup. This will help you set up Codejudge on your server. Make sure that you have MySQL running before you proceed.
121+
<h1><small>Details</small></h1>
122+
<form action="install.php" method="post">
123+
Database Host: <input type="text" name="host" value="localhost"/><br/>
124+
Username: <input type="text" name="username"/><br/>
125+
Password: <input type="password" name="password"/><br/>
126+
Database Name: <input type="text" name="name" value="codejudge"/><br/>
127+
Email: <input type="email" name="email"/><br/>
128+
<input type="submit" class="btn btn-primary" value="Install"/>
129+
</form>
130+
<?php } else {?>
131+
<div class="alert alert-error">Codejudge is already installed. Please remove the files and re-install it.</div>
132+
<?php } ?>
133+
</div> <!-- /container -->
134+
135+
<?php
136+
include('footer.php');
137+
?>

0 commit comments

Comments
 (0)