forked from alexzhang2015/online-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.php
executable file
·164 lines (130 loc) · 4.6 KB
/
submit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
//Reconfiguration the framework to support the real paralle request,
//just use the apache's paralle essentially . I want to design own
//paralle architecture with c++ and thread pool ,but it's complicated.
//With paralle ,every request is isolated. But the identification is
//the microtime_float,so does it be the same time of two request? 2011.04.01
//$filename=date("Y.m.d");
function microtime_float() //since the Unix Epoch (0:00:00 January 1, 1970 GMT)
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
//use the session as the unique identification of paralle request.
//But ,this will be a problem, during one session ,all the request just be processed by order in the waiting queue.
session_start();
$file=$_POST["cfile"];
$time_start = microtime_float();
$filename=$time_start ;
$full_filename;
if($file==".c"){
$fp = fopen( "/var/www/exec/$time_start.c", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
//session_start();
$_SESSION['file_name'] = $time_start.".c";
// setcookie("file_name" , $time_start.".c", time() + 20);
$full_filename = $time_start.".c";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp,stripslashes($_POST["stdin"]));
fclose($fp);
}
else if($file==".cpp"){
$fp = fopen( "/var/www/exec/$time_start.cpp", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
//session_start();
$_SESSION['file_name'] = $time_start.".cpp";
$full_filename = $time_start.".cpp";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp, stripslashes($_POST["stdin"]));
fclose($fp);
}
else if($file==".java"){
$fp = fopen( "/var/www/exec/$time_start.java", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
//session_start();
$_SESSION['file_name'] = $time_start.".java";
$full_filename = $time_start.".java";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp, stripslashes($_POST["stdin"]));
fclose($fp);
}
else if($file==".go"){
$fp = fopen( "/var/www/exec/$time_start.go", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
//session_start();
$_SESSION['file_name'] = $time_start.".go";
$full_filename = $time_start.".go";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp, stripslashes($_POST["stdin"]));
fclose($fp);
}
else if($file==".py"){
$fp = fopen( "/var/www/exec/$time_start.py", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
//session_start();
$_SESSION['file_name'] = $time_start.".py";
$full_filename = $time_start.".py";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp, stripslashes($_POST["stdin"]));
fclose($fp);
}
else if($file==".hs"){
$fp = fopen ("/var/www/exec/$time_start.hs", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
//session_start();
$_SESSION['file_nmae'] = $time_start.".hs";
$full_filename = $time_start.".hs";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp, stripslashes($_POST["stdin"]));
fclose($fp);
}
else if($file==".pl"){
$fp = fopen( "/var/www/exec/$time_start.pl", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
//session_start();
$_SESSION['file_name'] = $time_start.".pl";
$full_filename = $time_start.".pl";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp, stripslashes($_POST["stdin"]));
fclose($fp);
}
else if($file==".lua"){
$fp = fopen( "/var/www/exec/$time_start.lua", "w" );
fwrite($fp,$_POST["text"]);
fclose($fp);
// session_start();
$_SESSION['file_name'] = $time_start.".lua";
$full_filename = $time_start.".lua";
$fp = fopen( "/var/www/output/stdin.$full_filename", "w" );
fwrite($fp, stripslashes($_POST["stdin"]));
fclose($fp);
}
//Compiler part!
system("./compiler_module $full_filename >> /var/www/log/log.txt");
# system("sleep 2");
//sleep(3); //ensure change the tmp file ,and the daemon can lock the lockfile ,
//use the process page replace the sleep();
if($file==".py")
header('Location:/output/processpython.html');
else if( $file==".cpp")
header('Location:/output/processcpp.html');
else if($file==".c")
header('Location:/output/processc.html');
else if($file==".java")
header('Location:/output/processjava.html');
else if($file==".go")
header('Location:/output/processgo.html');
else if($file==".hs")
header('Location:/output/processhaskell.html');
else if($file==".pl")
header('Location:/output/processprolog.html');
else if($file==".lua")
header('Location:/output/processlua.html');
?>