| Current Path : /var/www/html/venkat/check/ |
| Current File : //var/www/html/venkat/check/main.php |
<?php
include "index.php";
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
$section = $_POST["section"];
$type = $_POST["type"];
$sec = $section;
$no = $_POST["no"];
$uploaddir = "file/".$section."/";
$uploadfile1 ='1';
if($_FILES["file"]["name"])
{
$uploadfile1 = $_FILES["file"]["name"];
$uploadfile1 = str_replace(" ", "_", $uploadfile1);
}
$type1= substr($uploadfile1, strrpos($uploadfile1, '.')+1);
$type11 = $type1;
if($type1 == "c" || $type1 == "cpp" || $type1 == "plx" || $type1 == "py"){
$type1="allow";
}
$uploadfile2 = $uploaddir.$uploadfile1;
$upload= strstr($uploadfile2, '.', true);
$pyce = "234";
$sec1=$sec."dec.txt";
//$filemd5 = shell_exec("md5sum $uploadfile2");
//echo $filemd5;
//$filemd5 = strstr($filemd5, ' ', true);
//echo $filemd5;
//$md5comp = shell_exec("cat $sec1 | grep $filemd5");
if ( $type1== "allow" && move_uploaded_file($_FILES["file"]["tmp_name"],$uploadfile2)) {
$filemd5 = shell_exec("md5sum $uploadfile2");
$filemd5 = strstr($filemd5, ' ', true);
$md5comp = shell_exec("cat $sec1 | grep $filemd5");
if ($md5comp != ""){
echo "<center><font color ='red'> Already Submitted </font> </center>";
}
else {
if ($type == "C++" && $type11 == "cpp") {
$w = shell_exec("g++ $uploadfile2 -o $upload.out");
}
if ($type == "C" && $type11 == "c") {
$w = shell_exec("gcc $uploadfile2 -o $upload.out");
}
if ($type == "Python" && $type11 == "py") {
$section12=$section.$no;
$w = shell_exec("timeout 0.1s python $uploadfile2 < file/$section12.txt");
}
if ($type == "Perl" && $type11 == "plx") {
$w = shell_exec("timeout 0.1s perl $uploadfile2");
}
if (isset($w) && !$w)
{
$pyce="1";
}
/*if($w == "")
{
$we = "No";
}
else
{
$we = "Yes";
}*/
$time = shell_exec("date +%x-%r");
$time1 = strstr($time, 'M', true);
$v="Not_executed";
if (file_exists($upload.".out") && $type!= "Python") {
$section12=$section.$no;
//$v = shell_exec("timeout 0.1s ./$upload.out");
$v = shell_exec("timeout 0.1s ./$upload.out < file/$section12.txt");
$we="1";
}
else if ( ($type == "Python" || $type == "Perl") && $pyce != "1"){
$v = $w;
$we="1";
}
else {
$we="Compile_Error";
}
if($we == "1") {
//$filmd5= strstr($v, '\n', true);
$co = trim(preg_replace('/\s+/','', $v));
//$filemd5 = shell_exec("md5sum $uploadfile2");
$sectionout = $section."out".$no;
$machineoutput = shell_exec("cat file/$sectionout.txt");
$mco = trim(preg_replace('/\s+/','', $machineoutput));
$mco = strtolower ($mco);
$co1 = $co;
$co = strtolower ($co);
similar_text($co, $mco, $percent);
$percent = round($percent);
//echo $percent;
if($mco == $co) {
$dec="Correct";
}
else {
$dec="Wrong";
}
// $filemd5 = strstr($filemd5, ' ', true);
// $md5comp = shell_exec("cat $sec1 | grep $filemd5");
// if($md5comp !="") {
// $md5comp = strstr($md5comp, ' ', true);
// $dec = "copied from:".$md5comp;
// }
$ip = $_SERVER['REMOTE_ADDR'];
?>
<br> <center>
<table width="60%" border="1" cellpadding="0">
<tr>
<td><b> <center> File Name </center> </b></td>
<td><b> <center> MD5sum of File </center> </b></td>
<td><b> <center> Output </center> </b> </td>
<td><b> <center> Compressed Output </center> </b> </td>
<!--<td><b> <center> Time </center> </b> </td>
<td><b> <center>Error(if any)<center> </b> </td>-->
<td><b> <center> O/P % Match </center> </b> </td>
<td><b> <center> Decision </center> </b> </td>
</tr>
<tr>
<td> <?php echo($uploadfile1); ?> </td>
<td> <?php echo($filemd5); ?> </td>
<td> <?php echo("<pre>".$v."</pre>"); ?> </td>
<td> <?php echo($co1); ?> </td>
<td> <center> <?php echo($percent); ?> </center> </td>
<!-- <td> <center> <?//php echo($we); ?> </center> </td>i -->
<td> <font color="red"><center> <?php echo($dec); ?> </center> </font> </td>
</tr>
</table> </center>
<?php
$myFile=$sec."dec.txt";
$fh = fopen($myFile, 'a');
$stringData = $uploadfile1. " | ".$ip. " | " . $time1. " | ". $filemd5. " | " . $percent . " | " .$dec."\n" ;
fwrite($fh, $stringData);
shell_exec("rm $upload.out");
}
else {
echo "<center> <font color = 'red'> Compilation Error </font> </center>";
}
}
}
else {
echo "<center> <font color = 'red'> Uploading Error or ExtensionError </font> </center>";
}
?>