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

Commit 4b875a0

Browse files
committed
web interface updated for new compiler server and installer updated
1 parent d85f0df commit 4b875a0

File tree

6 files changed

+35
-46
lines changed

6 files changed

+35
-46
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1+
# Codejudge .gitignore
12
*~
2-
<<<<<<< HEAD
33
dbinfo.php
4-
=======
5-
6-
>>>>>>> ec6f72dda3d9d255fe3de2835f2748dee17e879b
4+
*.class

admin/problems.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
connectdb();
1010
?>
1111
<li class="active"><a href="#">Admin Panel</a></li>
12-
<<<<<<< HEAD
1312
<li><a href="users.php">Users</a></li>
14-
=======
15-
<li><a href="#about">Users</a></li>
16-
>>>>>>> ec6f72dda3d9d255fe3de2835f2748dee17e879b
1713
<li><a href="logout.php">Logout</a></li>
1814
</ul>
1915
</div><!--/.nav-collapse -->

eval.php

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
require_once('functions.php');
3+
include('dbinfo.php');
34
connectdb();
45
$query = "SELECT * FROM prefs";
56
$result = mysql_query($query);
@@ -17,43 +18,35 @@
1718
$query = "UPDATE solve SET lang='".$_POST['lang']."', attempts='".($fields['attempts']+1)."', soln='".mysql_real_escape_string($_POST['soln'])."', filename='".mysql_real_escape_string($_POST['filename'])."' WHERE (username='".$_SESSION['username']."' AND problem_id='".$_POST['id']."')";
1819
}
1920
mysql_query($query);
20-
$filename = "solution/".$_SESSION['username']."/".$_POST['filename'];
21-
$fp = fopen($filename, 'w');
22-
fwrite($fp, $_POST['soln']);
23-
fclose($fp);
24-
if($_POST['lang']=='c' and $accept['c'] == 1)
25-
include('lang/c.php');
26-
else if($_POST['lang']=='cpp' and $accept['cpp'] == 1)
27-
include('lang/cpp.php');
28-
else if($_POST['lang']=='java' and $accept['java'] == 1)
29-
include('lang/java.php');
30-
else if($_POST['lang']=='python' and $accept['python'] == 1)
31-
include('lang/python.php');
32-
else
33-
header("Location: solve.php?lerror=1&id=".$_POST['id']);
34-
$res=lang_compile($filename, $_POST['id']);
35-
if($res == 1 or $res == 2) {
36-
$fp = fopen("$filename.err", 'r');
37-
$contents = fread($fp, filesize("$filename.err"));
38-
fclose($fp);
39-
}
40-
unlink("$filename");
41-
unlink("$filename.in");
42-
unlink("$filename.out");
43-
unlink("$filename.err");
44-
if($res == 1) {
21+
$socket = fsockopen($compilerhost, $compilerport);
22+
fwrite($socket, $_POST['filename']."\n");
23+
$soln = str_replace("\n", '$_n_$', treat($_POST['soln']));
24+
fwrite($socket, $soln."\n");
25+
$query = "SELECT input, output FROM problems WHERE sl='".$_POST['id']."'";
26+
$result = mysql_query($query);
27+
$fields = mysql_fetch_array($result);
28+
$input = str_replace("\n", '$_n_$', treat($fields['input']));
29+
fwrite($socket, $input."\n");
30+
fwrite($socket, $_POST['lang']."\n");
31+
$status = fgets($socket);
32+
$contents = "";
33+
while(!feof($socket))
34+
$contents = $contents."\n".fgets($socket);
35+
if($status == 0) {
4536
$query = "UPDATE solve SET status=1 WHERE (username='".$_SESSION['username']."' AND problem_id='".$_POST['id']."')";
4637
mysql_query($query);
47-
$_SESSION['cerror'] = nl2br(trim($contents));
38+
$_SESSION['cerror'] = trim($contents);
4839
header("Location: solve.php?cerror=1&id=".$_POST['id']);
49-
} else if($res == 2) {
50-
$query = "UPDATE solve SET status=1 WHERE (username='".$_SESSION['username']."' AND problem_id='".$_POST['id']."')";
51-
mysql_query($query);
52-
header("Location: solve.php?oerror=1&id=".$_POST['id']);
53-
} else if($res == 0) {
54-
$query = "UPDATE solve SET status=2 WHERE (username='".$_SESSION['username']."' AND problem_id='".$_POST['id']."')";
55-
mysql_query($query);
56-
header("Location: index.php?success=1");
40+
} else if($status == 1) {
41+
if(trim($contents) == trim(treat($fields['output']))) {
42+
$query = "UPDATE solve SET status=2 WHERE (username='".$_SESSION['username']."' AND problem_id='".$_POST['id']."')";
43+
mysql_query($query);
44+
header("Location: index.php?success=1");
45+
} else {
46+
$query = "UPDATE solve SET status=1 WHERE (username='".$_SESSION['username']."' AND problem_id='".$_POST['id']."')";
47+
mysql_query($query);
48+
header("Location: solve.php?oerror=1&id=".$_POST['id']);
49+
}
5750
}
5851
}
5952
?>

install.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
$l2 = '$user="'.$_POST['username'].'";';
77
$l3 = '$password="'.$_POST['password'].'";';
88
$l4 = '$database="'.$_POST['name'].'";';
9-
fwrite($fp, "<?php\n$l1\n$l2\n$l3\n$l4\n?>");
9+
$l5 = '$compilerhost="'.$_POST['chost'].'";';
10+
$l6 = '$compilerport='.$_POST['cport'].';';
11+
fwrite($fp, "<?php\n$l1\n$l2\n$l3\n$l4\n$l5\n$l6\n?>");
1012
fclose($fp);
1113
include('dbinfo.php');
1214
mysql_connect($host,$user,$password);
@@ -55,7 +57,6 @@
5557
$hash=crypt($pass,$salt);
5658
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('$pass', '$salt', '$hash', '".$_POST['email']."')";
5759
mysql_query($sql);
58-
mkdir("solution");
5960
header("Location: install.php?installed=1");
6061
}
6162
?>
@@ -125,6 +126,8 @@
125126
Password: <input type="password" name="password"/><br/>
126127
Database Name: <input type="text" name="name" value="codejudge"/><br/>
127128
Email: <input type="email" name="email"/><br/>
129+
Compiler Server Host: <input type="text" name="chost" value="localhost"/><br/>
130+
Compiler Server Port: <input type="text" name="cport" value="3029"/><br/>
128131
<input type="submit" class="btn btn-primary" value="Install"/>
129132
</form>
130133
<?php } else {?>

login.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
$hash = crypt($_POST['password'], $salt);
2626
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('".$_POST['username']."', '$salt', '$hash', '".$_POST['email']."')";
2727
mysql_query($sql);
28-
mkdir("solution/".$_POST['username']);
2928
header("Location: login.php?registered=1");
3029
}
3130
}

solve.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="container">
2121
<?php
2222
if(isset($_GET['cerror']))
23-
echo("<div class=\"alert alert-error\">\n<strong>The following errors occured:</strong><br/>\n".$_SESSION['cerror']."\n</div>");
23+
echo("<div class=\"alert alert-error\">\n<strong>The following errors occured:</strong><br/>\n<pre>\n".$_SESSION['cerror']."\n</pre>\n</div>");
2424
else if(isset($_GET['oerror']))
2525
echo("<div class=\"alert alert-error\">\nYour program output did not match the solution for the problem. Please check your program and try again.\n</div>");
2626
else if(isset($_GET['lerror']))

0 commit comments

Comments
 (0)