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

Commit 37f6050

Browse files
committed
Documented the code
1 parent cd8aa23 commit 37f6050

31 files changed

+326
-25
lines changed

about.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
<!DOCTYPE html>
1+
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* About page
8+
*/
9+
?><!DOCTYPE html>
210
<html lang="en"><head>
311
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
412
<meta charset="utf-8">

account.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Account Settings page
8+
*/
29
require_once('functions.php');
310
if(!loggedin())
411
header("Location: login.php");

admin/footer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Footer for all pages
8+
*/
9+
?>
110
<hr/>
211
<div class="footer">Powered by <a href="../about.php">Codejudge</a>.</div>
312
<!-- Le javascript

admin/header.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Common header for most files
8+
*/
9+
?>
110
<!DOCTYPE html>
211
<html lang="en"><head>
312
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

admin/index.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Codjudge admin panel
8+
*/
29
require_once('../functions.php');
310
if(!loggedin())
411
header("Location: login.php");

admin/login.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Codejudge Admin Login page
8+
*/
29
require_once('../functions.php');
310
if(loggedin() and $_SESSION['username'] == 'admin')
411
header("Location: index.php");
512
else if(isset($_POST['password'])) {
613
if(trim($_POST['password']) == "")
7-
header("Location: login.php?derror=1");
14+
header("Location: login.php?derror=1"); // empty entry
815
else {
16+
// code to login the user and start a session
917
connectdb();
1018
$query = "SELECT salt,hash FROM users WHERE username='admin'";
1119
$result = mysql_query($query);

admin/logout.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Logout Script
8+
*/
29
session_start();
310
$_SESSION=array();
411
if(isset($_COOKIE[session_name()])) {

admin/preview.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* PHP script that returns for AJAX requests
8+
*/
29
if($_POST['action'] == 'preview') {
10+
// preview for the markdown problem statement
311
if($_POST['title']=="" and $_POST['text']=="")
412
echo("<div class=\"alert alert-error\">You have not entered either the title or the problem text!</div>");
513
else {
@@ -9,6 +17,7 @@
917
echo($out);
1018
}
1119
} else if($_POST['action'] == 'code' and is_numeric($_POST['id'])) {
20+
// formatting for codes
1221
include('../functions.php');
1322
connectdb();
1423
echo("<hr/><h1><small>".$_POST['name']."</small></h1>\n");

admin/problems.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Problems adding or editing page
8+
*/
29
require_once('../functions.php');
310
if(!loggedin())
411
header("Location: login.php");
@@ -38,6 +45,7 @@
3845
<ul class="nav nav-list">
3946
<li class="nav-header">ADDED PROBLEMS</li>
4047
<?php
48+
// list all the problems
4149
$query = "SELECT * FROM problems";
4250
$result = mysql_query($query);
4351
if(mysql_num_rows($result)==0)
@@ -63,6 +71,7 @@
6371
<hr/>
6472
<?php
6573
if(isset($_GET['action']) and $_GET['action']=='edit') {
74+
// edit a selected problem
6675
?>
6776
<h1><small>Edit a Problem</small></h1>
6877
<form method="post" action="update.php">
@@ -91,7 +100,8 @@
91100
<input class="btn btn-danger btn-large" type="button" value="Delete Problem" onclick="window.location='update.php?action=delete&id='+$('#id').val();"/>
92101
</form>
93102
<div id="preview"></div>
94-
<?php }else {?>
103+
<?php }else { // add a problem
104+
?>
95105
<h1><small>Add a Problem</small></h1>
96106
<form method="post" action="update.php">
97107
<input type="hidden" name="action" value="addproblem"/>

admin/profile.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Profileof the users
8+
*/
29
require_once('../functions.php');
310
if(!loggedin())
411
header("Location: login.php");
@@ -19,6 +26,7 @@
1926

2027
<div class="container">
2128
<?php
29+
// get the name, email and status
2230
$query = "SELECT email, status FROM users WHERE username='".$_GET['uname']."'";
2331
$result = mysql_query($query);
2432
$row = mysql_fetch_array($result);
@@ -35,6 +43,7 @@
3543
</tr></thead>
3644
<tbody>
3745
<?php
46+
// list all the problems attempted or solved
3847
$query = "SELECT problem_id, status, attempts FROM solve WHERE username='".$_GET['uname']."'";
3948
$result = mysql_query($query);
4049
while($row = mysql_fetch_array($result)) {

admin/update.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* script that performs some database operations
8+
*/
29
include('../functions.php');
310
connectdb();
411
if(isset($_POST['action'])){
512
if($_POST['action']=='email') {
13+
// update the admin email
614
if(trim($_POST['email']) == "")
715
header("Location: index.php?derror=1");
816
else {
917
mysql_query("UPDATE users SET email='".mysql_real_escape_string($_POST['email'])."' WHERE username='".$_SESSION['username']."'");
1018
header("Location: index.php?changed=1");
1119
}
1220
} else if($_POST['action']=='password') {
21+
// update the admin password
1322
if(trim($_POST['oldpass']) == "" or trim($_POST['newpass']) == "")
1423
header("Location: index.php?derror=1");
1524
else {
@@ -26,6 +35,7 @@
2635
header("Location: index.php?passerror=1");
2736
}
2837
} else if($_POST['action']=='settings') {
38+
// update the event settings
2939
if(trim($_POST['name']) == "")
3040
header("Location: index.php?derror=1");
3141
else {
@@ -38,6 +48,7 @@
3848
header("Location: index.php?changed=1");
3949
}
4050
} else if($_POST['action']=='addproblem') {
51+
// add a problem
4152
if(trim($_POST['title']) == "" or trim($_POST['problem']) == "")
4253
header("Location: problems.php?derror=1");
4354
else {
@@ -46,6 +57,7 @@
4657
header("Location: problems.php?added=1");
4758
}
4859
} else if($_POST['action']=='editproblem' and is_numeric($_POST['id'])) {
60+
// update an already existing problem
4961
if(trim($_POST['title']) == "" or trim($_POST['problem']) == "")
5062
header("Location: problems.php?derror=1&action=edit&id=".$_POST['id']);
5163
else {
@@ -57,14 +69,17 @@
5769
}
5870
else if(isset($_GET['action'])){
5971
if($_GET['action']=='delete' and is_numeric($_GET['id'])) {
72+
// delete an existing problem
6073
$query="DELETE FROM problems WHERE sl=".$_GET['id'];
6174
mysql_query($query);
6275
header("Location: problems.php?deleted=1");
6376
} else if($_GET['action']=='ban') {
77+
// ban a user from the event
6478
$query="UPDATE users SET status=0 WHERE username='".mysql_real_escape_string($_GET['username'])."'";
6579
mysql_query($query);
6680
header("Location: users.php?banned=1");
6781
} else if($_GET['action']=='unban') {
82+
// unban a user from the event
6883
$query="UPDATE users SET status=1 WHERE username='".mysql_real_escape_string($_GET['username'])."'";
6984
mysql_query($query);
7085
header("Location: users.php?unbanned=1");

admin/users.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/*
3+
* Codejudge
4+
* Copyright 2012, Sankha Narayan Guria ([email protected])
5+
* Licensed under MIT License.
6+
*
7+
* Shows the list of users
8+
*/
29
require_once('../functions.php');
310
if(!loggedin())
411
header("Location: login.php");
@@ -37,6 +44,7 @@
3744
$query = "SELECT username, status FROM users WHERE username!='admin'";
3845
$result = mysql_query($query);
3946
while($row = mysql_fetch_array($result)) {
47+
// lists all the users
4048
$sql = "SELECT * FROM solve WHERE (status='2' AND username='".$row['username']."')";
4149
$res = mysql_query($sql);
4250
echo("<tr><td><a href=\"profile.php?uname=".$row['username']."\">".$row['username']);

codejudge-compiler/src/codejudge/compiler/CodejudgeCompiler.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* Codejudge
3+
* Copyright 2012, Sankha Narayan Guria ([email protected])
4+
* Licensed under MIT License.
5+
*
6+
* Codejudge Compiler Server
7+
*/
8+
19
package codejudge.compiler;
210

311
import java.io.IOException;
@@ -9,10 +17,11 @@ public class CodejudgeCompiler {
917
public static void main(String args[]) {
1018
int n=0;
1119
try {
12-
ServerSocket server = new ServerSocket(3029);
20+
ServerSocket server = new ServerSocket(3029); // create a new socket to listen on
1321
System.out.println("Codejudge compilation server running ...");
1422
while(true) {
1523
n++;
24+
// accept any incoming connection and process it on a new thread
1625
Socket s = server.accept();
1726
RequestThread request = new RequestThread(s, n);
1827
request.start();

codejudge-compiler/src/codejudge/compiler/RequestThread.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* Codejudge
3+
* Copyright 2012, Sankha Narayan Guria ([email protected])
4+
* Licensed under MIT License.
5+
*
6+
* Codejudge Compiler Server : Thread that runs on each request
7+
*/
8+
19
package codejudge.compiler;
210

311
import java.io.BufferedReader;
@@ -18,9 +26,9 @@
1826

1927
public class RequestThread extends Thread {
2028

21-
Socket s;
22-
int n;
23-
File dir;
29+
Socket s; // socket connection
30+
int n; // request number
31+
File dir; // staging directory
2432

2533
public RequestThread(Socket s, int n) {
2634
this.s=s;
@@ -29,19 +37,22 @@ public RequestThread(Socket s, int n) {
2937
}
3038

3139
public void run() {
32-
dir.mkdirs();
40+
dir.mkdirs(); // create staging directory
3341
try {
3442
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
3543
PrintWriter out = new PrintWriter(s.getOutputStream(), true);
44+
// read input from the PHP script
3645
String file = in.readLine();
3746
String contents = in.readLine().replace("$_n_$", "\n");
3847
String input = in.readLine().replace("$_n_$", "\n");
3948
String lang = in.readLine();
4049
System.out.println("Compiling " + file + "...");
50+
// create the sample input file
4151
PrintWriter writer = new PrintWriter(new FileOutputStream("stage/" + n +"/in.txt"));
4252
writer.println(input);
4353
writer.close();
4454
Language l = null;
55+
// create the language specific compiler
4556
if(lang.equals("c"))
4657
l = new C(file, contents, dir.getAbsolutePath());
4758
else if(lang.equals("cpp"))
@@ -50,12 +61,13 @@ else if(lang.equals("java"))
5061
l = new Java(file, contents, dir.getAbsolutePath());
5162
else if(lang.equals("python"))
5263
l = new Python(file, contents, dir.getAbsolutePath());
53-
l.compile();
64+
l.compile(); // compile the file
5465
String errors = compileErrors();
55-
if(!errors.equals("")) {
66+
if(!errors.equals("")) { // check for compilation errors
5667
out.println("0");
5768
out.println(errors);
5869
} else {
70+
// execute the program and return output
5971
l.execute();
6072
out.println("1");
6173
out.println(execMsg());
@@ -66,6 +78,7 @@ else if(lang.equals("python"))
6678
}
6779
}
6880

81+
// method to return the compiler errors
6982
public String compileErrors() {
7083
String line, content = "";
7184
try {
@@ -80,6 +93,7 @@ public String compileErrors() {
8093
return content.trim();
8194
}
8295

96+
// method to return the execution output
8397
public String execMsg() {
8498
String line, content = "";
8599
try {

0 commit comments

Comments
 (0)