Compare commits
5 Commits
c22c788cfa
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba36cfdfa2 | ||
| 5a27c07bba | |||
| 418674806b | |||
| 9b13c95e8a | |||
| 0e5cac3d4e |
@@ -1,5 +1,7 @@
|
|||||||
# 调试说明
|
# 调试说明
|
||||||
|
|
||||||
|
该项目为局域网本地项目。不需要考虑安全问题。
|
||||||
|
|
||||||
## 调试环境
|
## 调试环境
|
||||||
|
|
||||||
- 目标网址:http://192.168.0.96/
|
- 目标网址:http://192.168.0.96/
|
||||||
@@ -15,3 +17,11 @@
|
|||||||
3. 打开网页端提供的 git pull API 触发更新,使服务器拉取最新代码。
|
3. 打开网页端提供的 git pull API 触发更新,使服务器拉取最新代码。
|
||||||
|
|
||||||
如需验证调试环境,优先使用上述账号登录目标网址,并通过网页端 git pull API 完成代码同步。
|
如需验证调试环境,优先使用上述账号登录目标网址,并通过网页端 git pull API 完成代码同步。
|
||||||
|
|
||||||
|
## 数据库
|
||||||
|
```
|
||||||
|
static $DB_HOST="localhost"; //数据库服务器ip或域名
|
||||||
|
static $DB_NAME="jol"; //数据库名
|
||||||
|
static $DB_USER="debian-sys-maint"; //数据库账户
|
||||||
|
static $DB_PASS="GJfFMuAmScKHHa32"; //数据库密码
|
||||||
|
```
|
||||||
@@ -1220,6 +1220,17 @@ void addreinfo(int solution_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_system_error_info(int solution_id, const char *message)
|
||||||
|
{
|
||||||
|
FILE *fp = fopen("error.out", "a");
|
||||||
|
if (fp != NULL)
|
||||||
|
{
|
||||||
|
fprintf(fp, "system:%s\n", message);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
addreinfo(solution_id);
|
||||||
|
}
|
||||||
|
|
||||||
void adddiffinfo(int solution_id)
|
void adddiffinfo(int solution_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -1670,7 +1681,7 @@ int check_mysql_conn(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
void _get_solution_mysql(int solution_id, char *work_dir, int lang)
|
bool _get_solution_mysql(int solution_id, char *work_dir, int lang)
|
||||||
{
|
{
|
||||||
char sql[BUFFER_SIZE], src_pth[BUFFER_SIZE];
|
char sql[BUFFER_SIZE], src_pth[BUFFER_SIZE];
|
||||||
// get the source code
|
// get the source code
|
||||||
@@ -1678,7 +1689,8 @@ void _get_solution_mysql(int solution_id, char *work_dir, int lang)
|
|||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
sprintf(sql, "SELECT source FROM source_code WHERE solution_id=%d",
|
sprintf(sql, "SELECT source FROM source_code WHERE solution_id=%d",
|
||||||
solution_id);
|
solution_id);
|
||||||
mysql_real_query(conn, sql, strlen(sql));
|
if (mysql_real_query(conn, sql, strlen(sql)))
|
||||||
|
return false;
|
||||||
res = mysql_store_result(conn);
|
res = mysql_store_result(conn);
|
||||||
|
|
||||||
// create the src file
|
// create the src file
|
||||||
@@ -1691,16 +1703,23 @@ void _get_solution_mysql(int solution_id, char *work_dir, int lang)
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
printf("Main=%s", src_pth);
|
printf("Main=%s", src_pth);
|
||||||
FILE *fp_src = fopen(src_pth, "we");
|
FILE *fp_src = fopen(src_pth, "we");
|
||||||
|
if (fp_src == NULL) {
|
||||||
|
mysql_free_result(res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
fprintf(fp_src, "%s", row[0]);
|
fprintf(fp_src, "%s", row[0]);
|
||||||
mysql_free_result(res); // free the memory
|
mysql_free_result(res); // free the memory
|
||||||
res = NULL;
|
res = NULL;
|
||||||
row = NULL;
|
row = NULL;
|
||||||
fclose(fp_src);
|
fclose(fp_src);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
mysql_free_result(res);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void _get_solution_http(int solution_id, char *work_dir, int lang)
|
bool _get_solution_http(int solution_id, char *work_dir, int lang)
|
||||||
{
|
{
|
||||||
char src_pth[BUFFER_SIZE];
|
char src_pth[BUFFER_SIZE];
|
||||||
|
|
||||||
@@ -1716,22 +1735,26 @@ void _get_solution_http(int solution_id, char *work_dir, int lang)
|
|||||||
FILE *pout = read_cmd_output(cmd2, solution_id, src_pth, http_baseurl, http_apipath);
|
FILE *pout = read_cmd_output(cmd2, solution_id, src_pth, http_baseurl, http_apipath);
|
||||||
|
|
||||||
pclose(pout);
|
pclose(pout);
|
||||||
|
return access(src_pth, R_OK) == 0;
|
||||||
}
|
}
|
||||||
void get_solution(int solution_id, char *work_dir, int lang,int p_id)
|
bool get_solution(int solution_id, char *work_dir, int lang,int p_id)
|
||||||
{
|
{
|
||||||
char src_pth[BUFFER_SIZE];
|
char src_pth[BUFFER_SIZE];
|
||||||
|
bool ret = false;
|
||||||
sprintf(src_pth, "Main.%s", lang_ext[lang]);
|
sprintf(src_pth, "Main.%s", lang_ext[lang]);
|
||||||
if (http_judge)
|
if (http_judge)
|
||||||
{
|
{
|
||||||
_get_solution_http(solution_id, work_dir, lang);
|
ret = _get_solution_http(solution_id, work_dir, lang);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
_get_solution_mysql(solution_id, work_dir, lang);
|
ret = _get_solution_mysql(solution_id, work_dir, lang);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (!ret)
|
||||||
|
return false;
|
||||||
if(lang == LANG_PYTHON ){ // 从源码中搜索python2字样,失败的结果非零默认python3,成功的结果为0是python2
|
if(lang == LANG_PYTHON ){ // 从源码中搜索python2字样,失败的结果非零默认python3,成功的结果为0是python2
|
||||||
py2 = execute_cmd("/bin/grep 'python2' %s/Main.py > /dev/null", work_dir);
|
py2 = execute_cmd("/bin/grep 'python2' %s/Main.py > /dev/null", work_dir);
|
||||||
execute_cmd("sed -i 's/import.*os//g' %s/%s", work_dir, src_pth);
|
execute_cmd("sed -i 's/import.*os//g' %s/%s", work_dir, src_pth);
|
||||||
@@ -1740,6 +1763,7 @@ void get_solution(int solution_id, char *work_dir, int lang,int p_id)
|
|||||||
execute_cmd("cp %s/../data/%d/sb3/%d.sb3 %s", work_dir,p_id,solution_id, src_pth);
|
execute_cmd("cp %s/../data/%d/sb3/%d.sb3 %s", work_dir,p_id,solution_id, src_pth);
|
||||||
}
|
}
|
||||||
execute_cmd("chown judge %s/%s", work_dir, src_pth);
|
execute_cmd("chown judge %s/%s", work_dir, src_pth);
|
||||||
|
return access(src_pth, R_OK) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
@@ -1804,7 +1828,7 @@ void get_custominput(int solution_id, char *work_dir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
void _get_solution_info_mysql(int solution_id, int & p_id, char * user_id,
|
bool _get_solution_info_mysql(int solution_id, int & p_id, char * user_id,
|
||||||
int & lang,int &cid) {
|
int & lang,int &cid) {
|
||||||
|
|
||||||
MYSQL_RES *res;
|
MYSQL_RES *res;
|
||||||
@@ -1818,7 +1842,8 @@ void _get_solution_info_mysql(int solution_id, int & p_id, char * user_id,
|
|||||||
"insert into solution2 select * FROM solution where solution_id=%d",
|
"insert into solution2 select * FROM solution where solution_id=%d",
|
||||||
solution_id);
|
solution_id);
|
||||||
//printf("%s\n",sql);
|
//printf("%s\n",sql);
|
||||||
mysql_real_query(conn, sql, strlen(sql));
|
if (mysql_real_query(conn, sql, strlen(sql)))
|
||||||
|
return false;
|
||||||
sprintf(sql,
|
sprintf(sql,
|
||||||
"SELECT problem_id, user_id, language,contest_id FROM solution2 where solution_id=%d",
|
"SELECT problem_id, user_id, language,contest_id FROM solution2 where solution_id=%d",
|
||||||
solution_id);
|
solution_id);
|
||||||
@@ -1831,9 +1856,16 @@ void _get_solution_info_mysql(int solution_id, int & p_id, char * user_id,
|
|||||||
solution_id);
|
solution_id);
|
||||||
}
|
}
|
||||||
//printf("%s\n",sql);
|
//printf("%s\n",sql);
|
||||||
mysql_real_query(conn, sql, strlen(sql));
|
if (mysql_real_query(conn, sql, strlen(sql)))
|
||||||
|
return false;
|
||||||
res = mysql_store_result(conn);
|
res = mysql_store_result(conn);
|
||||||
|
if (res == NULL)
|
||||||
|
return false;
|
||||||
row = mysql_fetch_row(res);
|
row = mysql_fetch_row(res);
|
||||||
|
if (row == NULL) {
|
||||||
|
mysql_free_result(res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
p_id = atoi(row[0]);
|
p_id = atoi(row[0]);
|
||||||
strcpy(user_id, row[1]);
|
strcpy(user_id, row[1]);
|
||||||
lang = atoi(row[2]);
|
lang = atoi(row[2]);
|
||||||
@@ -1844,9 +1876,10 @@ void _get_solution_info_mysql(int solution_id, int & p_id, char * user_id,
|
|||||||
mysql_free_result(res); // free the memory
|
mysql_free_result(res); // free the memory
|
||||||
res=NULL;
|
res=NULL;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void _get_solution_info_http(int solution_id, int & p_id, char * user_id,
|
bool _get_solution_info_http(int solution_id, int & p_id, char * user_id,
|
||||||
int & lang,int & cid) {
|
int & lang,int & cid) {
|
||||||
|
|
||||||
login();
|
login();
|
||||||
@@ -1854,26 +1887,29 @@ void _get_solution_info_http(int solution_id, int & p_id, char * user_id,
|
|||||||
const char *cmd =
|
const char *cmd =
|
||||||
"wget --post-data=\"getsolutioninfo=1&sid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s%s\"";
|
"wget --post-data=\"getsolutioninfo=1&sid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s%s\"";
|
||||||
FILE *pout = read_cmd_output(cmd, solution_id, http_baseurl, http_apipath);
|
FILE *pout = read_cmd_output(cmd, solution_id, http_baseurl, http_apipath);
|
||||||
if(1!=fscanf(pout, "%d", &p_id)) printf("http problem_id read fail...\n");
|
bool ret = true;
|
||||||
if(1!=fscanf(pout, "%s", user_id)) printf("http user_id read fail ... \n") ;
|
if(1!=fscanf(pout, "%d", &p_id)) { printf("http problem_id read fail...\n"); ret = false; }
|
||||||
if(1!=fscanf(pout, "%d", &lang)) printf("http language read fail ... \n") ;
|
if(1!=fscanf(pout, "%s", user_id)) { printf("http user_id read fail ... \n") ; ret = false; }
|
||||||
if(1!=fscanf(pout, "%d", &cid)) printf("http contest_id read fail ... \n") ;
|
if(1!=fscanf(pout, "%d", &lang)) { printf("http language read fail ... \n") ; ret = false; }
|
||||||
|
if(1!=fscanf(pout, "%d", &cid)) { printf("http contest_id read fail ... \n") ; ret = false; }
|
||||||
pclose(pout);
|
pclose(pout);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
void get_solution_info(int solution_id, int & p_id, char * user_id,
|
bool get_solution_info(int solution_id, int & p_id, char * user_id,
|
||||||
int & lang,int & cid) {
|
int & lang,int & cid) {
|
||||||
|
|
||||||
if (http_judge) {
|
if (http_judge) {
|
||||||
_get_solution_info_http(solution_id, p_id, user_id, lang,cid);
|
return _get_solution_info_http(solution_id, p_id, user_id, lang,cid);
|
||||||
} else {
|
} else {
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
_get_solution_info_mysql(solution_id, p_id, user_id, lang,cid);
|
return _get_solution_info_mysql(solution_id, p_id, user_id, lang,cid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
void _get_problem_info_mysql(int p_id, double &time_lmt, int &mem_lmt,
|
bool _get_problem_info_mysql(int p_id, double &time_lmt, int &mem_lmt,
|
||||||
int &spj)
|
int &spj)
|
||||||
{
|
{
|
||||||
// get the problem info from Table:problem
|
// get the problem info from Table:problem
|
||||||
@@ -1883,9 +1919,16 @@ void _get_problem_info_mysql(int p_id, double &time_lmt, int &mem_lmt,
|
|||||||
sprintf(sql,
|
sprintf(sql,
|
||||||
"SELECT time_limit,memory_limit,spj FROM problem where problem_id=%d",
|
"SELECT time_limit,memory_limit,spj FROM problem where problem_id=%d",
|
||||||
p_id);
|
p_id);
|
||||||
mysql_real_query(conn, sql, strlen(sql));
|
if (mysql_real_query(conn, sql, strlen(sql)))
|
||||||
|
return false;
|
||||||
res = mysql_store_result(conn);
|
res = mysql_store_result(conn);
|
||||||
|
if (res == NULL)
|
||||||
|
return false;
|
||||||
row = mysql_fetch_row(res);
|
row = mysql_fetch_row(res);
|
||||||
|
if (row == NULL) {
|
||||||
|
mysql_free_result(res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
time_lmt = atof(row[0]);
|
time_lmt = atof(row[0]);
|
||||||
mem_lmt = atoi(row[1]);
|
mem_lmt = atoi(row[1]);
|
||||||
spj = atoi(row[2]);
|
spj = atoi(row[2]);
|
||||||
@@ -1894,9 +1937,10 @@ void _get_problem_info_mysql(int p_id, double &time_lmt, int &mem_lmt,
|
|||||||
mysql_free_result(res); // free the memory
|
mysql_free_result(res); // free the memory
|
||||||
res = NULL;
|
res = NULL;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void _get_problem_info_http(int p_id, double &time_lmt, int &mem_lmt,
|
bool _get_problem_info_http(int p_id, double &time_lmt, int &mem_lmt,
|
||||||
int &spj)
|
int &spj)
|
||||||
{
|
{
|
||||||
//login();
|
//login();
|
||||||
@@ -1904,27 +1948,32 @@ void _get_problem_info_http(int p_id, double &time_lmt, int &mem_lmt,
|
|||||||
const char *cmd =
|
const char *cmd =
|
||||||
"wget --post-data=\"getprobleminfo=1&pid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s%s\"";
|
"wget --post-data=\"getprobleminfo=1&pid=%d\" --load-cookies=cookie --save-cookies=cookie --keep-session-cookies -q -O - \"%s%s\"";
|
||||||
FILE *pout = read_cmd_output(cmd, p_id, http_baseurl, http_apipath);
|
FILE *pout = read_cmd_output(cmd, p_id, http_baseurl, http_apipath);
|
||||||
if(1!=fscanf(pout, "%lf", &time_lmt)) printf("http read time_limit fail...\n");
|
bool ret = true;
|
||||||
if(1!=fscanf(pout, "%d", &mem_lmt) ) printf("http read memory_limit fail...\n");
|
if(1!=fscanf(pout, "%lf", &time_lmt)) { printf("http read time_limit fail...\n"); ret = false; }
|
||||||
if(1!=fscanf(pout, "%d", &spj) ) printf("http read special judge fail...\n");
|
if(1!=fscanf(pout, "%d", &mem_lmt) ) { printf("http read memory_limit fail...\n"); ret = false; }
|
||||||
|
if(1!=fscanf(pout, "%d", &spj) ) { printf("http read special judge fail...\n"); ret = false; }
|
||||||
pclose(pout);
|
pclose(pout);
|
||||||
if(DEBUG) printf("time_lmt:%g\n",time_lmt);
|
if(DEBUG) printf("time_lmt:%g\n",time_lmt);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_problem_info(int p_id, double &time_lmt, int &mem_lmt, int &spj)
|
bool get_problem_info(int p_id, double &time_lmt, int &mem_lmt, int &spj)
|
||||||
{
|
{
|
||||||
if (http_judge)
|
if (http_judge)
|
||||||
{
|
{
|
||||||
_get_problem_info_http(p_id, time_lmt, mem_lmt, spj);
|
if (!_get_problem_info_http(p_id, time_lmt, mem_lmt, spj))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
_get_problem_info_mysql(p_id, time_lmt, mem_lmt, spj);
|
if (!_get_problem_info_mysql(p_id, time_lmt, mem_lmt, spj))
|
||||||
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (time_lmt <= 0)
|
if (time_lmt <= 0)
|
||||||
time_lmt = 1;
|
time_lmt = 1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
char *escape(char s[], char t[])
|
char *escape(char s[], char t[])
|
||||||
{
|
{
|
||||||
@@ -3455,6 +3504,8 @@ int main(int argc, char **argv)
|
|||||||
double time_lmt;
|
double time_lmt;
|
||||||
char time_space_table[BUFFER_SIZE*100];
|
char time_space_table[BUFFER_SIZE*100];
|
||||||
int time_space_index=0;
|
int time_space_index=0;
|
||||||
|
time_space_table[0]=0;
|
||||||
|
user_id[0]=0;
|
||||||
umask(0077);
|
umask(0077);
|
||||||
init_parameters(argc, argv, solution_id, runner_id);
|
init_parameters(argc, argv, solution_id, runner_id);
|
||||||
|
|
||||||
@@ -3489,7 +3540,27 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (http_judge)
|
if (http_judge)
|
||||||
if(!system("/bin/ln -s ../cookie ./")) printf("cookie link fail \n");
|
if(!system("/bin/ln -s ../cookie ./")) printf("cookie link fail \n");
|
||||||
get_solution_info(solution_id, p_id, user_id, lang,cid);
|
if (!get_solution_info(solution_id, p_id, user_id, lang,cid)) {
|
||||||
|
add_system_error_info(solution_id, "solution info not found");
|
||||||
|
update_solution(solution_id, OJ_RE, 0, 0, 0, 0, 0.0);
|
||||||
|
#ifdef _mysql_h
|
||||||
|
if (!http_judge)
|
||||||
|
mysql_close(conn);
|
||||||
|
#endif
|
||||||
|
clean_workdir(work_dir);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (lang < 0 || lang >= (int)(sizeof(lang_ext) / sizeof(lang_ext[0]))) {
|
||||||
|
add_system_error_info(solution_id, "invalid language id");
|
||||||
|
update_solution(solution_id, OJ_RE, 0, 0, 0, 0, 0.0);
|
||||||
|
if(!turbo_mode)update_user(user_id);
|
||||||
|
#ifdef _mysql_h
|
||||||
|
if (!http_judge)
|
||||||
|
mysql_close(conn);
|
||||||
|
#endif
|
||||||
|
clean_workdir(work_dir);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
//get the limit
|
//get the limit
|
||||||
|
|
||||||
if (p_id == 0)
|
if (p_id == 0)
|
||||||
@@ -3500,11 +3571,33 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
get_problem_info(p_id, time_lmt, mem_lmt, spj);
|
if (!get_problem_info(p_id, time_lmt, mem_lmt, spj)) {
|
||||||
|
add_system_error_info(solution_id, "problem info not found");
|
||||||
|
update_solution(solution_id, OJ_RE, 0, 0, 0, 0, 0.0);
|
||||||
|
if(!turbo_mode)update_user(user_id);
|
||||||
|
if(!turbo_mode)update_problem(p_id,cid);
|
||||||
|
#ifdef _mysql_h
|
||||||
|
if (!http_judge)
|
||||||
|
mysql_close(conn);
|
||||||
|
#endif
|
||||||
|
clean_workdir(work_dir);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//copy source file
|
//copy source file
|
||||||
|
|
||||||
get_solution(solution_id, work_dir, lang,p_id);
|
if (!get_solution(solution_id, work_dir, lang,p_id)) {
|
||||||
|
add_system_error_info(solution_id, "source code not found");
|
||||||
|
update_solution(solution_id, OJ_RE, 0, 0, 0, 0, 0.0);
|
||||||
|
if(!turbo_mode)update_user(user_id);
|
||||||
|
if(!turbo_mode)update_problem(p_id,cid);
|
||||||
|
#ifdef _mysql_h
|
||||||
|
if (!http_judge)
|
||||||
|
mysql_close(conn);
|
||||||
|
#endif
|
||||||
|
clean_workdir(work_dir);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
//java and other VM language are lucky to have the global bonus in judge.conf
|
//java and other VM language are lucky to have the global bonus in judge.conf
|
||||||
if (lang >= LANG_JAVA && lang != LANG_OBJC && lang != LANG_CLANG && lang != LANG_CLANGPP && lang != LANG_GO )
|
if (lang >= LANG_JAVA && lang != LANG_OBJC && lang != LANG_CLANG && lang != LANG_CLANGPP && lang != LANG_GO )
|
||||||
@@ -3581,11 +3674,18 @@ int main(int argc, char **argv)
|
|||||||
if(p_id > 0 && namelist_len == -1 ){
|
if(p_id > 0 && namelist_len == -1 ){
|
||||||
|
|
||||||
write_log("No such dir:%s!\n", fullpath);
|
write_log("No such dir:%s!\n", fullpath);
|
||||||
|
char error[BUFFER_SIZE];
|
||||||
|
snprintf(error, BUFFER_SIZE - 1, "test data directory not found: %s", fullpath);
|
||||||
|
add_system_error_info(solution_id, error);
|
||||||
|
update_solution(solution_id, OJ_RE, 0, 0, 0, 0, 0.0);
|
||||||
|
if(!turbo_mode)update_user(user_id);
|
||||||
|
if(!turbo_mode)update_problem(p_id,cid);
|
||||||
#ifdef _mysql_h
|
#ifdef _mysql_h
|
||||||
if (!http_judge)
|
if (!http_judge)
|
||||||
mysql_close(conn);
|
mysql_close(conn);
|
||||||
#endif
|
#endif
|
||||||
exit(-1);
|
clean_workdir(work_dir);
|
||||||
|
exit(0);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if(DEBUG){
|
if(DEBUG){
|
||||||
@@ -3702,6 +3802,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
}
|
}
|
||||||
char last_name[BUFFER_SIZE];
|
char last_name[BUFFER_SIZE];
|
||||||
|
last_name[0]=0;
|
||||||
int minus_mark=0;
|
int minus_mark=0;
|
||||||
char path_buf[BUFFER_SIZE];
|
char path_buf[BUFFER_SIZE];
|
||||||
sprintf(path_buf,"%s/data/%d/",oj_home,p_id);
|
sprintf(path_buf,"%s/data/%d/",oj_home,p_id);
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ static $OJ_BENCHMARK_MODE=false; //此选项仅供测试用,不是正常功
|
|||||||
static $OJ_CONTEST_RANK_FIX_HEADER=false; //比赛排名水平滚动时固定名单
|
static $OJ_CONTEST_RANK_FIX_HEADER=false; //比赛排名水平滚动时固定名单
|
||||||
static $OJ_NOIP_KEYWORD="noip"; // 标题包含此关键词,激活noip模式,赛中不显示结果,仅保留最后一次提交。
|
static $OJ_NOIP_KEYWORD="noip"; // 标题包含此关键词,激活noip模式,赛中不显示结果,仅保留最后一次提交。
|
||||||
static $OJ_BEIAN=false; // 如果有备案号,填写备案号
|
static $OJ_BEIAN=false; // 如果有备案号,填写备案号
|
||||||
static $OJ_RANK_HIDDEN="'admin','super','szx','sen'"; // 管理员不显示在排名中
|
static $OJ_RANK_HIDDEN="'admin','super','szx','sen','copilot'"; // 管理员不显示在排名中
|
||||||
static $OJ_FRIENDLY_LEVEL=0; //系统友好级别,暂定0-9级,级别越高越傻瓜,系统易用度高的同时将降低安全性,仅供非专业用途,造成泄题、抄袭概不负责。
|
static $OJ_FRIENDLY_LEVEL=0; //系统友好级别,暂定0-9级,级别越高越傻瓜,系统易用度高的同时将降低安全性,仅供非专业用途,造成泄题、抄袭概不负责。
|
||||||
static $OJ_FREE_PRACTICE=true; //自由练习,不受比赛作业用题限制
|
static $OJ_FREE_PRACTICE=true; //自由练习,不受比赛作业用题限制
|
||||||
static $OJ_SUBMIT_COOLDOWN_TIME=1; //提交冷却时间,连续两次提交的最小间隔,单位秒。
|
static $OJ_SUBMIT_COOLDOWN_TIME=1; //提交冷却时间,连续两次提交的最小间隔,单位秒。
|
||||||
|
|||||||
248
web/reinfo.php
248
web/reinfo.php
@@ -102,6 +102,145 @@ function dedup_runtimeinfo($text, &$dedup_count) {
|
|||||||
return implode("\n", $out);
|
return implode("\n", $out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把 runtimeinfo.error 解析为结构化的 diff blocks
|
||||||
|
* 返回 [['name' => 'test1.out', 'expected' => [...], 'yours' => [...], 'full_mode' => bool], ...]
|
||||||
|
* 解析失败返回空数组
|
||||||
|
*/
|
||||||
|
function parse_diff_blocks($text) {
|
||||||
|
$blocks = array();
|
||||||
|
if (empty($text)) return $blocks;
|
||||||
|
|
||||||
|
// 先按 "\n\n" 切分(simple mode 每个测试点之间有空行)
|
||||||
|
$chunks = preg_split('/\n\s*\n/', $text);
|
||||||
|
foreach ($chunks as $chunk) {
|
||||||
|
$chunk = trim($chunk);
|
||||||
|
if ($chunk === '') continue;
|
||||||
|
|
||||||
|
// 格式 1: 整段就是一个 =====[name]===== 块(包含表头+数据+结尾 ====)
|
||||||
|
// 形如 "========[test1.out]========\nExpected | Yours\nFail | Fall\n=============================="
|
||||||
|
if (preg_match('/^=+\[([^\]]+)\]\=+(.+?)\n=+\s*$/s', $chunk, $m)) {
|
||||||
|
$name = trim($m[1]);
|
||||||
|
$body = $m[2];
|
||||||
|
// body 形如 "\nExpected | Yours\nFail | Fall"
|
||||||
|
// 去掉首尾的换行符
|
||||||
|
$body = trim($body, "\n\r");
|
||||||
|
$lines_in_body = explode("\n", $body);
|
||||||
|
$expected = array();
|
||||||
|
$yours = array();
|
||||||
|
$found_header = false;
|
||||||
|
foreach ($lines_in_body as $bl) {
|
||||||
|
$bl = rtrim($bl);
|
||||||
|
if ($bl === '') continue;
|
||||||
|
// 跳过表头
|
||||||
|
if (!$found_header && preg_match('/^Expected.*\|.*Yours/i', $bl)) {
|
||||||
|
$found_header = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$found_header && (preg_match('/^\|?--\s*\|/', $bl) || trim($bl) === '--')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$parsed = parse_one_diff_line($bl);
|
||||||
|
if ($parsed !== null) {
|
||||||
|
$expected[] = $parsed[0];
|
||||||
|
$yours[] = $parsed[1];
|
||||||
|
$found_header = true;
|
||||||
|
} else {
|
||||||
|
$expected[] = $bl;
|
||||||
|
$yours[] = '';
|
||||||
|
$found_header = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($expected)) {
|
||||||
|
$blocks[] = array(
|
||||||
|
'name' => $name,
|
||||||
|
'expected' => $expected,
|
||||||
|
'yours' => $yours,
|
||||||
|
'full_mode' => true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式 2: simple mode "test1.out\n--\n|Expected|Yours\n|--|--\n|row1|row2"
|
||||||
|
if (preg_match('/^([^\n=|]+)\n--\n([\s\S]+)$/', $chunk, $m)) {
|
||||||
|
$name = trim($m[1]);
|
||||||
|
$body = $m[2];
|
||||||
|
$lines_in_body = explode("\n", $body);
|
||||||
|
$expected = array();
|
||||||
|
$yours = array();
|
||||||
|
$found_header = false;
|
||||||
|
foreach ($lines_in_body as $bl) {
|
||||||
|
$bl = rtrim($bl);
|
||||||
|
if ($bl === '') continue;
|
||||||
|
if (!$found_header && preg_match('/Expected.*\|.*Yours/i', $bl)) {
|
||||||
|
$found_header = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$found_header && (preg_match('/^\|?--\s*\|/', $bl) || trim($bl) === '--')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$parsed = parse_one_diff_line($bl);
|
||||||
|
if ($parsed !== null) {
|
||||||
|
$expected[] = $parsed[0];
|
||||||
|
$yours[] = $parsed[1];
|
||||||
|
$found_header = true;
|
||||||
|
} else {
|
||||||
|
$expected[] = $bl;
|
||||||
|
$yours[] = '';
|
||||||
|
$found_header = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($expected)) {
|
||||||
|
$blocks[] = array(
|
||||||
|
'name' => $name,
|
||||||
|
'expected' => $expected,
|
||||||
|
'yours' => $yours,
|
||||||
|
'full_mode' => false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析单行 "expected | yours" 格式
|
||||||
|
* 支持 "|a|b"、"a | b"、"a|b" 等
|
||||||
|
* 返回 [left, right] 或 null(无法解析)
|
||||||
|
*/
|
||||||
|
function parse_one_diff_line($line) {
|
||||||
|
$line = rtrim($line);
|
||||||
|
if ($line === '') return null;
|
||||||
|
|
||||||
|
// 格式 A: "|a|b" (首尾带 |)
|
||||||
|
if ($line[0] === '|') {
|
||||||
|
$rest = substr($line, 1);
|
||||||
|
$pos = strpos($rest, '|');
|
||||||
|
if ($pos !== false) {
|
||||||
|
return array(substr($rest, 0, $pos), substr($rest, $pos + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式 B: "a | b" 或 "a | b"(带空格的 markdown 风格)
|
||||||
|
// 注意:可能行内有空格,所以用 " | " 或 " | " 等宽松匹配
|
||||||
|
if (preg_match('/^(.*?)\s+\|\s+(.*)$/', $line, $m)) {
|
||||||
|
// 确保左右两边都非空
|
||||||
|
$left = trim($m[1]);
|
||||||
|
$right = trim($m[2]);
|
||||||
|
if ($left !== '' || $right !== '') {
|
||||||
|
return array($left, $right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式 C: "a<b" 或 "a>b"(diff -y 风格)
|
||||||
|
if (preg_match('/^(.*?)\s+([<>])\s+(.*)$/', $line, $m)) {
|
||||||
|
return array($m[1], $m[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$view_reinfo = "";
|
$view_reinfo = "";
|
||||||
$view_reinfo_raw = ""; // 原始(管理员/有权限者看)
|
$view_reinfo_raw = ""; // 原始(管理员/有权限者看)
|
||||||
$view_reinfo_summary = ""; // 折叠后(普通用户看)
|
$view_reinfo_summary = ""; // 折叠后(普通用户看)
|
||||||
@@ -120,7 +259,9 @@ if($ok){
|
|||||||
$rt = pdo_query($sql,$id);
|
$rt = pdo_query($sql,$id);
|
||||||
$raw_error = "";
|
$raw_error = "";
|
||||||
if(isset($rt[0])){
|
if(isset($rt[0])){
|
||||||
$raw_error = str_replace("\n\r","\n",$rt[0]['error']);
|
$raw_error = $rt[0]['error'];
|
||||||
|
// 统一换行符:先替换 \r\n,再替换单独的 \r
|
||||||
|
$raw_error = str_replace(array("\r\n", "\r"), "\n", $raw_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// === 阶段 1:基于 solution.result 给"主解释"(永远非空)===
|
// === 阶段 1:基于 solution.result 给"主解释"(永远非空)===
|
||||||
@@ -215,111 +356,6 @@ if($ok){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 把 runtimeinfo.error 解析为结构化的 diff blocks
|
|
||||||
* 返回 [['name' => 'test1.out', 'expected' => [...], 'yours' => [...], 'full_mode' => bool], ...]
|
|
||||||
* 解析失败返回空数组
|
|
||||||
*/
|
|
||||||
function parse_diff_blocks($text) {
|
|
||||||
$blocks = array();
|
|
||||||
if (empty($text)) return $blocks;
|
|
||||||
|
|
||||||
// 先按 "\n\n" 切分(simple mode 每个测试点之间有空行)
|
|
||||||
// 但要避免切分 full mode 里的内容
|
|
||||||
$chunks = preg_split('/\n\s*\n/', $text);
|
|
||||||
foreach ($chunks as $chunk) {
|
|
||||||
$chunk = trim($chunk);
|
|
||||||
if ($chunk === '') continue;
|
|
||||||
|
|
||||||
// full mode: 形如 "========[test1.out]=========" 开头
|
|
||||||
if (preg_match('/^=+\[([^\]]+)\]=+$/m', $chunk, $m_head)) {
|
|
||||||
$name = $m_head[1];
|
|
||||||
// 提取 "------diff out 200 lines-----" 后面的内容
|
|
||||||
if (preg_match('/------diff out[^\n]*-+\n(.*?)\n=+\s*$/s', $chunk, $m_diff)) {
|
|
||||||
$diff_text = trim($m_diff[1]);
|
|
||||||
} else {
|
|
||||||
continue; // 没找到 diff 段,跳过
|
|
||||||
}
|
|
||||||
$lines = parse_diff_side_by_side($diff_text);
|
|
||||||
if (!empty($lines)) {
|
|
||||||
$blocks[] = array(
|
|
||||||
'name' => $name,
|
|
||||||
'expected' => $lines['expected'],
|
|
||||||
'yours' => $lines['yours'],
|
|
||||||
'full_mode' => true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// simple mode: 形如 "test1.out\n--\n|Expected|Yours\n|--|--\n|..."
|
|
||||||
if (preg_match('/^([^\n|]+)\n--\n\|Expected\|Yours\n\|--\|--\n(.*)$/s', $chunk, $m)) {
|
|
||||||
$name = trim($m[1]);
|
|
||||||
$table = $m[2];
|
|
||||||
$lines = parse_pipe_diff_table($table);
|
|
||||||
if (!empty($lines)) {
|
|
||||||
$blocks[] = array(
|
|
||||||
'name' => $name,
|
|
||||||
'expected' => $lines['expected'],
|
|
||||||
'yours' => $lines['yours'],
|
|
||||||
'full_mode' => false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析 "|expected|yours\n" 格式的表格
|
|
||||||
* 已知边角:每行以 | 开头和 | 分隔;空字段表示没有该行
|
|
||||||
*/
|
|
||||||
function parse_pipe_diff_table($text) {
|
|
||||||
$expected = array();
|
|
||||||
$yours = array();
|
|
||||||
$lines = explode("\n", $text);
|
|
||||||
foreach ($lines as $line) {
|
|
||||||
if (strlen($line) < 2 || $line[0] !== '|') continue;
|
|
||||||
// 形如 "|a|b" 拆出 a 和 b
|
|
||||||
$rest = substr($line, 1);
|
|
||||||
// 找第一个 |
|
|
||||||
$pos = strpos($rest, '|');
|
|
||||||
if ($pos === false) continue;
|
|
||||||
$left = substr($rest, 0, $pos);
|
|
||||||
$right = substr($rest, $pos + 1);
|
|
||||||
$expected[] = $left;
|
|
||||||
$yours[] = $right;
|
|
||||||
}
|
|
||||||
if (empty($expected)) return array();
|
|
||||||
return array('expected' => $expected, 'yours' => $yours);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析 `diff -y` 格式: " < expected > yours"
|
|
||||||
* 中间用 | 或 / 分隔(取决于 GNU diff 版本)
|
|
||||||
*/
|
|
||||||
function parse_diff_side_by_side($text) {
|
|
||||||
$expected = array();
|
|
||||||
$yours = array();
|
|
||||||
$lines = explode("\n", $text);
|
|
||||||
foreach ($lines as $line) {
|
|
||||||
// 找中间的 | 或 / (GNU diff -y 格式)
|
|
||||||
// 形如 " line1 | line2 " 或 " line1 < line2 "
|
|
||||||
if (preg_match('/^(.*?)\s+[<>|]\s+(.*)$/', $line, $m)) {
|
|
||||||
$expected[] = $m[1];
|
|
||||||
$yours[] = $m[2];
|
|
||||||
} elseif (trim($line) === '') {
|
|
||||||
// 空行:两边都空
|
|
||||||
} else {
|
|
||||||
// 单边(一边空):整行属于另一边
|
|
||||||
$expected[] = $line;
|
|
||||||
$yours[] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($expected)) return array();
|
|
||||||
return array('expected' => $expected, 'yours' => $yours);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 不是本人的提交,且不是 source_browser
|
// 不是本人的提交,且不是 source_browser
|
||||||
else{
|
else{
|
||||||
if($spj[0][0]!=2) $view_errors = $MSG_WARNING_ACCESS_DENIED;
|
if($spj[0][0]!=2) $view_errors = $MSG_WARNING_ACCESS_DENIED;
|
||||||
|
|||||||
@@ -3,19 +3,37 @@ require_once "include/db_info.inc.php";
|
|||||||
require_once "include/my_func.inc.php";
|
require_once "include/my_func.inc.php";
|
||||||
require_once "include/email.class.php";
|
require_once "include/email.class.php";
|
||||||
require_once "include/base64.php";
|
require_once "include/base64.php";
|
||||||
|
require_once "include/const.inc.php";
|
||||||
|
|
||||||
|
$is_ajax_submit = isset($_GET['ajax']) || isset($_POST['ajax']);
|
||||||
|
|
||||||
|
function submit_error($message) {
|
||||||
|
global $OJ_TEMPLATE, $is_ajax_submit, $view_errors;
|
||||||
|
|
||||||
|
if ($is_ajax_submit) {
|
||||||
|
header("Content-Type: text/plain; charset=UTF-8");
|
||||||
|
$text = trim(html_entity_decode(strip_tags($message), ENT_QUOTES, "UTF-8"));
|
||||||
|
if ($text === "") {
|
||||||
|
$text = "Submit failed.";
|
||||||
|
}
|
||||||
|
echo $text;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$view_errors = $message;
|
||||||
|
require "template/".$OJ_TEMPLATE."/error.php";
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($OJ_CSRF) && $OJ_CSRF && $OJ_TEMPLATE=="syzoj" && !isset($_SESSION[$OJ_NAME.'_'.'http_judge']))
|
if(isset($OJ_CSRF) && $OJ_CSRF && $OJ_TEMPLATE=="syzoj" && !isset($_SESSION[$OJ_NAME.'_'.'http_judge']))
|
||||||
require_once(dirname(__FILE__)."/include/csrf_check.php");
|
require_once(dirname(__FILE__)."/include/csrf_check.php");
|
||||||
|
|
||||||
if (!isset($_SESSION[$OJ_NAME . '_' . 'user_id'])) {
|
if (!isset($_SESSION[$OJ_NAME . '_' . 'user_id'])) {
|
||||||
|
|
||||||
$view_errors = "<a href=loginpage.php>$MSG_Login</a>";
|
submit_error("<a href=loginpage.php>$MSG_Login</a>");
|
||||||
require("template/".$OJ_TEMPLATE."/error.php");
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once "include/memcache.php";
|
require_once "include/memcache.php";
|
||||||
require_once "include/const.inc.php";
|
|
||||||
|
|
||||||
$now = strftime("%Y-%m-%d %H:%M", time());
|
$now = strftime("%Y-%m-%d %H:%M", time());
|
||||||
$user_id = $_SESSION[$OJ_NAME.'_'.'user_id'];
|
$user_id = $_SESSION[$OJ_NAME.'_'.'user_id'];
|
||||||
@@ -41,10 +59,8 @@ if (!$OJ_BENCHMARK_MODE) {
|
|||||||
$_SESSION[$OJ_NAME.'_'."vcode"] = null;
|
$_SESSION[$OJ_NAME.'_'."vcode"] = null;
|
||||||
$err_str = $err_str.$MSG_VCODE_WRONG."\n";
|
$err_str = $err_str.$MSG_VCODE_WRONG."\n";
|
||||||
$err_cnt++;
|
$err_cnt++;
|
||||||
$view_errors = $err_str;
|
|
||||||
$_SESSION[ $OJ_NAME . '_' . "vfail" ]=true;
|
$_SESSION[ $OJ_NAME . '_' . "vfail" ]=true;
|
||||||
require "template/".$OJ_TEMPLATE."/error.php";
|
submit_error($err_str);
|
||||||
exit(0);
|
|
||||||
}else{
|
}else{
|
||||||
$_SESSION[ $OJ_NAME . '_' . "vfail" ]=false;
|
$_SESSION[ $OJ_NAME . '_' . "vfail" ]=false;
|
||||||
}
|
}
|
||||||
@@ -74,24 +90,13 @@ else {
|
|||||||
if(!$test_run){
|
if(!$test_run){
|
||||||
$res = mysql_query_cache($sql);
|
$res = mysql_query_cache($sql);
|
||||||
if (isset($res) && count($res)<1 && !isset($_SESSION[$OJ_NAME.'_'.'administrator']) && !((isset($cid)&&$cid<=0) || (isset($id)&&$id<=0))) {
|
if (isset($res) && count($res)<1 && !isset($_SESSION[$OJ_NAME.'_'.'administrator']) && !((isset($cid)&&$cid<=0) || (isset($id)&&$id<=0))) {
|
||||||
$view_errors = $MSG_LINK_ERROR."<br>";
|
submit_error($MSG_LINK_ERROR."<br>");
|
||||||
require "template/".$OJ_TEMPLATE."/error.php";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($res[0][1]!='N' && !($test_run||isset($_SESSION[$OJ_NAME.'_'.'administrator']))) {
|
if (!$test_run && isset($res[0]) && $res[0][1]!='N' && !isset($_SESSION[$OJ_NAME.'_'.'administrator'])) {
|
||||||
// echo "res:$res,count:".count($res);
|
// echo "res:$res,count:".count($res);
|
||||||
// echo "$sql";
|
// echo "$sql";
|
||||||
$view_errors = $MSG_PROBLEM_RESERVED."<br>";
|
submit_error($MSG_PROBLEM_RESERVED."<br>".$res[0][1]);
|
||||||
|
|
||||||
if (isset($_POST['ajax'])) {
|
|
||||||
echo $view_errors.$res[0][1];
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
require "template/".$OJ_TEMPLATE."/error.php";
|
|
||||||
}
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = "";
|
$title = "";
|
||||||
@@ -118,10 +123,7 @@ else if (isset($_POST['pid']) && isset($_POST['cid']) && $_POST['cid']!=0) {
|
|||||||
$rows_cnt = count($result);
|
$rows_cnt = count($result);
|
||||||
|
|
||||||
if ($rows_cnt != 1) {
|
if ($rows_cnt != 1) {
|
||||||
$view_errors .= $MSG_NOT_IN_CONTEST;
|
submit_error($MSG_NOT_IN_CONTEST);
|
||||||
|
|
||||||
require "template/" . $OJ_TEMPLATE . "/error.php";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$row = $result[0];
|
$row = $result[0];
|
||||||
@@ -137,9 +139,7 @@ else if (isset($_POST['pid']) && isset($_POST['cid']) && $_POST['cid']!=0) {
|
|||||||
$ccnt = intval($row[0]);
|
$ccnt = intval($row[0]);
|
||||||
|
|
||||||
if ($ccnt==0 && !isset($_SESSION[$OJ_NAME.'_'.'administrator'])) {
|
if ($ccnt==0 && !isset($_SESSION[$OJ_NAME.'_'.'administrator'])) {
|
||||||
$view_errors = $MSG_NOT_INVITED."\n";
|
submit_error($MSG_NOT_INVITED."\n");
|
||||||
require "template/" . $OJ_TEMPLATE . "/error.php";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,9 +150,7 @@ else if (isset($_POST['pid']) && isset($_POST['cid']) && $_POST['cid']!=0) {
|
|||||||
$rows_cnt = count($result);
|
$rows_cnt = count($result);
|
||||||
|
|
||||||
if ($rows_cnt != 1) {
|
if ($rows_cnt != 1) {
|
||||||
$view_errors = $MSG_NO_PROBLEM."\n";
|
submit_error($MSG_NO_PROBLEM."\n");
|
||||||
require "template/".$OJ_TEMPLATE."/error.php";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$row = $result[0];
|
$row = $result[0];
|
||||||
@@ -182,12 +180,10 @@ if ($language > count($language_name) || $language < 0) {
|
|||||||
$language = strval($language);
|
$language = strval($language);
|
||||||
|
|
||||||
if ($langmask&(1<<$language)) {
|
if ($langmask&(1<<$language)) {
|
||||||
$view_errors = $MSG_NO_PLS."\n[$language][$langmask][".($langmask&(1<<$language))."]";
|
submit_error($MSG_NO_PLS."\n[$language][$langmask][".($langmask&(1<<$language))."]");
|
||||||
require "template/".$OJ_TEMPLATE."/error.php";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$source = $_POST['source'];
|
$source = isset($_POST['source']) ? $_POST['source'] : "";
|
||||||
$input_text = "";
|
$input_text = "";
|
||||||
|
|
||||||
if (isset($_POST['input_text'])) {
|
if (isset($_POST['input_text'])) {
|
||||||
@@ -206,7 +202,7 @@ if ($test_run) {
|
|||||||
$id = -$id;
|
$id = -$id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tempfile = $_FILES ["answer"] ["tmp_name"];
|
$tempfile = (isset($_FILES["answer"]) && isset($_FILES["answer"]["tmp_name"])) ? $_FILES["answer"]["tmp_name"] : "";
|
||||||
if($tempfile!=""){
|
if($tempfile!=""){
|
||||||
if($language!=23){
|
if($language!=23){
|
||||||
|
|
||||||
@@ -217,7 +213,7 @@ if($tempfile!=""){
|
|||||||
$source="Main.sb3";
|
$source="Main.sb3";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$origin_name=trim($_FILES ["answer"]['name']);
|
$origin_name=(isset($_FILES["answer"]) && isset($_FILES["answer"]['name'])) ? trim($_FILES["answer"]['name']) : "";
|
||||||
$solution_file = "$OJ_DATA/$id/solution.name";
|
$solution_file = "$OJ_DATA/$id/solution.name";
|
||||||
if(file_exists($solution_file)){
|
if(file_exists($solution_file)){
|
||||||
$solution_name=trim(file_get_contents($solution_file));
|
$solution_name=trim(file_get_contents($solution_file));
|
||||||
@@ -255,7 +251,7 @@ if ($test_run) {
|
|||||||
$id = 0;
|
$id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($language!=23) $len = strlen($source);else $len = $_FILES['answer']['size'];
|
if($language!=23) $len = strlen($source);else $len = (isset($_FILES['answer']) ? intval($_FILES['answer']['size']) : 0);
|
||||||
//echo $source;
|
//echo $source;
|
||||||
|
|
||||||
setcookie('lastlang', $language, time()+360000);
|
setcookie('lastlang', $language, time()+360000);
|
||||||
@@ -270,15 +266,11 @@ if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
|||||||
|
|
||||||
|
|
||||||
if ($len < 2) {
|
if ($len < 2) {
|
||||||
$view_errors = $MSG_TOO_SHORT.$tempfile."<br>";
|
submit_error($MSG_TOO_SHORT.$tempfile."<br>");
|
||||||
require "template/".$OJ_TEMPLATE."/error.php";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($len > 65536) {
|
if ($len > 65536) {
|
||||||
$view_errors = $MSG_TOO_LONG."<br>";
|
submit_error($MSG_TOO_LONG."<br>");
|
||||||
require "template/" . $OJ_TEMPLATE . "/error.php";
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$OJ_BENCHMARK_MODE) {
|
if (!$OJ_BENCHMARK_MODE) {
|
||||||
@@ -295,8 +287,8 @@ if (!$OJ_BENCHMARK_MODE) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
// 预防WAF抽风
|
// 预防WAF抽风
|
||||||
*/
|
*/
|
||||||
if(isset($_GET['ajax'])){
|
if($is_ajax_submit){
|
||||||
echo -1;
|
submit_error(str_replace("10",$OJ_SUBMIT_COOLDOWN_TIME,$MSG_BREAK_TIME));
|
||||||
}else{
|
}else{
|
||||||
$statusURI = "status.php?user_id=".$_SESSION[$OJ_NAME.'_'.'user_id'];
|
$statusURI = "status.php?user_id=".$_SESSION[$OJ_NAME.'_'.'user_id'];
|
||||||
if (isset($cid)) {
|
if (isset($cid)) {
|
||||||
@@ -373,6 +365,7 @@ if (~$OJ_LANGMASK&(1<<$language)) {
|
|||||||
|
|
||||||
////remote oj
|
////remote oj
|
||||||
$result=0;
|
$result=0;
|
||||||
|
if (!$test_run && isset($OJ_REMOTE_JUDGE) && $OJ_REMOTE_JUDGE) {
|
||||||
$sql="select remote_oj from problem where problem_id=?";
|
$sql="select remote_oj from problem where problem_id=?";
|
||||||
$remote_oj=pdo_query($sql,$id);
|
$remote_oj=pdo_query($sql,$id);
|
||||||
if(isset($remote_oj[0])){
|
if(isset($remote_oj[0])){
|
||||||
@@ -383,6 +376,7 @@ if (~$OJ_LANGMASK&(1<<$language)) {
|
|||||||
pdo_query($sql,$remote_oj,$insert_id);
|
pdo_query($sql,$remote_oj,$insert_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////poison robot account,give system resources to the REAL people
|
////poison robot account,give system resources to the REAL people
|
||||||
if(isset($OJ_POISON_BOT_COUNT) && $OJ_POISON_BOT_COUNT >0 &&
|
if(isset($OJ_POISON_BOT_COUNT) && $OJ_POISON_BOT_COUNT >0 &&
|
||||||
@@ -501,11 +495,11 @@ if (isset($cid)) {
|
|||||||
$statusURI .= "&cid=$cid&fixed=";
|
$statusURI .= "&cid=$cid&fixed=";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$test_run&&!isset($_GET['ajax'])) {
|
if (!$test_run&&!$is_ajax_submit) {
|
||||||
header("Location: $statusURI");
|
header("Location: $statusURI");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isset($_GET['ajax'])) {
|
if ($is_ajax_submit) {
|
||||||
echo $insert_id;
|
echo $insert_id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -650,6 +650,7 @@ i.icon.spinning {
|
|||||||
var maxInterval = 8000; // 最长 8s
|
var maxInterval = 8000; // 最长 8s
|
||||||
var countdown = 0;
|
var countdown = 0;
|
||||||
var stopped = false;
|
var stopped = false;
|
||||||
|
var completed = false;
|
||||||
|
|
||||||
function showStatus(text){
|
function showStatus(text){
|
||||||
var el = document.getElementById('auto-refresh-status');
|
var el = document.getElementById('auto-refresh-status');
|
||||||
@@ -688,6 +689,7 @@ i.icon.spinning {
|
|||||||
// 判题完成,刷新页面拿到完整错误信息
|
// 判题完成,刷新页面拿到完整错误信息
|
||||||
showStatus('判题完成,正在刷新...');
|
showStatus('判题完成,正在刷新...');
|
||||||
setTimeout(function(){ location.reload(); }, 400);
|
setTimeout(function(){ location.reload(); }, 400);
|
||||||
|
completed = true;
|
||||||
stopped = true;
|
stopped = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -712,7 +714,8 @@ i.icon.spinning {
|
|||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
stopped = true;
|
stopped = true;
|
||||||
hideStatus();
|
hideStatus();
|
||||||
} else if (!stopped) {
|
} else if (!completed) {
|
||||||
|
stopped = false;
|
||||||
countdown = 0;
|
countdown = 0;
|
||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,6 +215,15 @@
|
|||||||
border-top: 1px solid rgba(0,0,5,0.08);
|
border-top: 1px solid rgba(0,0,5,0.08);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.submit-top-actions {
|
||||||
|
justify-content: flex-end;
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 16px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
border-top: 0;
|
||||||
|
border-bottom: 1px solid rgba(0,0,5,0.08);
|
||||||
|
}
|
||||||
|
|
||||||
.submit-actions .actions-left {
|
.submit-actions .actions-left {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
@@ -388,7 +397,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="<?php echo $OJ_CDN_URL?>include/checksource.js"></script>
|
<script src="<?php echo $OJ_CDN_URL?>include/checksource.js"></script>
|
||||||
<form id="frmSolution" action="submit.php<?php if (isset($_GET['spa'])) echo "?spa" ?>" method="post" onsubmit="do_submit()" enctype="multipart/form-data">
|
<form id="frmSolution" action="submit.php<?php if (isset($_GET['spa'])) echo "?spa" ?>" method="post" onsubmit="do_submit();return false;" enctype="multipart/form-data">
|
||||||
|
|
||||||
|
<div class="submit-actions submit-top-actions">
|
||||||
|
<div class="actions-left">
|
||||||
|
<button id="Submit" type="button" class="btn btn-primary" onclick="do_submit();">
|
||||||
|
<i class="paper plane icon"></i> <?php echo $MSG_SUBMIT?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="submit-toolbar">
|
<div class="submit-toolbar">
|
||||||
<?php if (!isset($_GET['spa']) || $solution_name ) {?>
|
<?php if (!isset($_GET['spa']) || $solution_name ) {?>
|
||||||
@@ -485,11 +502,9 @@
|
|||||||
<h2 class="solution-name-title">📎 <?php echo $solution_name?></h2>
|
<h2 class="solution-name-title">📎 <?php echo $solution_name?></h2>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
<?php if ((isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name) || (isset($OJ_ENCODE_SUBMIT)&&$OJ_ENCODE_SUBMIT) || (isset($OJ_BLOCKLY)&&$OJ_BLOCKLY)){?>
|
||||||
<div class="submit-actions">
|
<div class="submit-actions">
|
||||||
<div class="actions-left">
|
<div class="actions-left">
|
||||||
<button id="Submit" type="button" class="btn btn-primary" onclick="do_submit();">
|
|
||||||
<i class="paper plane icon"></i> <?php echo $MSG_SUBMIT?>
|
|
||||||
</button>
|
|
||||||
<?php if ( isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name ){?>
|
<?php if ( isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name ){?>
|
||||||
<button id="TestRun" type="button" class="btn btn-info" onclick="do_test_run();">
|
<button id="TestRun" type="button" class="btn btn-info" onclick="do_test_run();">
|
||||||
<i class="play icon"></i> <?php echo $MSG_TR?>
|
<i class="play icon"></i> <?php echo $MSG_TR?>
|
||||||
@@ -510,11 +525,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<?php }?>
|
<?php }?>
|
||||||
</div>
|
</div>
|
||||||
|
<?php }?>
|
||||||
|
|
||||||
<div id="blockly" class="center"></div>
|
<div id="blockly" class="center"></div>
|
||||||
|
|
||||||
<?php if (isset($id)){?>
|
<?php if (isset($id)){?>
|
||||||
<input id="problem_id" type="hidden" value="<?php echo $id?>" name="problem_id">
|
<input id="problem_id" type="hidden" value="<?php echo $id?>" name="id">
|
||||||
<?php }else{?>
|
<?php }else{?>
|
||||||
<input id="cid" type="hidden" value="<?php echo $cid?>" name="cid">
|
<input id="cid" type="hidden" value="<?php echo $cid?>" name="cid">
|
||||||
<input id="pid" type="hidden" value="<?php echo $pid?>" name="pid">
|
<input id="pid" type="hidden" value="<?php echo $pid?>" name="pid">
|
||||||
@@ -618,6 +634,69 @@ return ret+"";
|
|||||||
}
|
}
|
||||||
var count=0;
|
var count=0;
|
||||||
|
|
||||||
|
function htmlEscape(text){
|
||||||
|
return $("<div>").text(text).html();
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanSubmitMessage(data){
|
||||||
|
var text=$("<div>").html(String(data)).text();
|
||||||
|
text=$.trim(text.replace(/\s+/g," "));
|
||||||
|
if(text=="") text="Submit failed.";
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSubmitMessage(data){
|
||||||
|
var tb=window.document.getElementById('result');
|
||||||
|
var text=cleanSubmitMessage(data);
|
||||||
|
if(tb!=null){
|
||||||
|
tb.innerHTML="<span class='badge badge-danger'>"+htmlEscape(text)+"</span>";
|
||||||
|
}else{
|
||||||
|
alert(text);
|
||||||
|
}
|
||||||
|
if($("#vcode-img")!=null) $("#vcode-img").click();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setSubmitDisabled(disabled){
|
||||||
|
$("#Submit").prop('disabled', disabled);
|
||||||
|
$("#TestRun").prop('disabled', disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
function startSubmitCooldown(){
|
||||||
|
count=<?php echo isset($OJ_SUBMIT_COOLDOWN_TIME)?$OJ_SUBMIT_COOLDOWN_TIME:5 ?> * 2 ;
|
||||||
|
handler_interval= window.setTimeout("resume();",1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitSolutionAjax(isTestRun){
|
||||||
|
var form=document.getElementById("frmSolution");
|
||||||
|
var formData=new FormData(form);
|
||||||
|
$.ajax({
|
||||||
|
url:"submit.php?ajax<?php if(isset($_GET['spa'])) echo '&spa'; ?>",
|
||||||
|
type:"POST",
|
||||||
|
data:formData,
|
||||||
|
processData:false,
|
||||||
|
contentType:false,
|
||||||
|
success:function(data){
|
||||||
|
var text=$.trim(String(data));
|
||||||
|
var sid=/^\d+$/.test(text)?parseInt(text,10):0;
|
||||||
|
if(sid>0){
|
||||||
|
if(isTestRun){
|
||||||
|
fresh_result(sid);
|
||||||
|
startSubmitCooldown();
|
||||||
|
}else{
|
||||||
|
window.location.href="reinfo.php?sid="+sid;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
showSubmitMessage(text);
|
||||||
|
setSubmitDisabled(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error:function(xhr){
|
||||||
|
showSubmitMessage(xhr.responseText || "Submit failed.");
|
||||||
|
setSubmitDisabled(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function encoded_submit(){
|
function encoded_submit(){
|
||||||
|
|
||||||
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
|
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
|
||||||
@@ -643,7 +722,7 @@ function encoded_submit(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function do_submit(){
|
function do_submit(){
|
||||||
$("#Submit").attr("disabled","true");
|
setSubmitDisabled(true);
|
||||||
if(using_blockly)
|
if(using_blockly)
|
||||||
translate();
|
translate();
|
||||||
if(typeof(editor) != "undefined"){
|
if(typeof(editor) != "undefined"){
|
||||||
@@ -656,37 +735,8 @@ function do_submit(){
|
|||||||
else
|
else
|
||||||
problem_id.value='<?php if (isset($cid))echo $cid?>';
|
problem_id.value='<?php if (isset($cid))echo $cid?>';
|
||||||
document.getElementById("frmSolution").target="_self";
|
document.getElementById("frmSolution").target="_self";
|
||||||
|
submitSolutionAjax(false);
|
||||||
<?php if(isset($_GET['spa'])){?>
|
|
||||||
<?php if($solution_name) { ?>document.getElementById("frmSolution").submit(); <?php } ?>
|
|
||||||
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){
|
|
||||||
var sid=parseInt(data);
|
|
||||||
if(sid>0){
|
|
||||||
window.location.href="reinfo.php?sid="+sid;
|
|
||||||
}else{
|
|
||||||
fresh_result(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$("#Submit").prop('disabled', true);
|
|
||||||
$("#TestRun").prop('disabled', true);
|
|
||||||
count=<?php echo $OJ_SUBMIT_COOLDOWN_TIME?> * 2 ;
|
|
||||||
handler_interval= window.setTimeout("resume();",1000);
|
|
||||||
<?php if(isset($OJ_REMOTE_JUDGE)&&$OJ_REMOTE_JUDGE) {?>$("#sk").attr("src","remote.php"); <?php } ?>
|
<?php if(isset($OJ_REMOTE_JUDGE)&&$OJ_REMOTE_JUDGE) {?>$("#sk").attr("src","remote.php"); <?php } ?>
|
||||||
<?php }else{?>
|
|
||||||
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){
|
|
||||||
var sid=parseInt(data);
|
|
||||||
if(sid>0){
|
|
||||||
window.location.href="reinfo.php?sid="+sid;
|
|
||||||
}else{
|
|
||||||
fresh_result(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$("#Submit").prop('disabled', true);
|
|
||||||
$("#TestRun").prop('disabled', true);
|
|
||||||
count=<?php echo $OJ_SUBMIT_COOLDOWN_TIME?> * 2 ;
|
|
||||||
handler_interval= window.setTimeout("resume();",1000);
|
|
||||||
<?php }?>
|
|
||||||
|
|
||||||
}
|
}
|
||||||
var handler_interval;
|
var handler_interval;
|
||||||
function do_test_run(){
|
function do_test_run(){
|
||||||
@@ -705,12 +755,9 @@ function do_test_run(){
|
|||||||
var problem_id=document.getElementById(mark);
|
var problem_id=document.getElementById(mark);
|
||||||
problem_id.value=-problem_id.value;
|
problem_id.value=-problem_id.value;
|
||||||
document.getElementById("frmSolution").target="testRun";
|
document.getElementById("frmSolution").target="testRun";
|
||||||
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){fresh_result(data);});
|
setSubmitDisabled(true);
|
||||||
$("#Submit").prop('disabled', true);
|
submitSolutionAjax(true);
|
||||||
$("#TestRun").prop('disabled', true);
|
|
||||||
problem_id.value=-problem_id.value;
|
problem_id.value=-problem_id.value;
|
||||||
count=<?php echo isset($OJ_SUBMIT_COOLDOWN_TIME)?$OJ_SUBMIT_COOLDOWN_TIME:5 ?> * 2 ;
|
|
||||||
handler_interval= window.setTimeout("resume();",1000);
|
|
||||||
}
|
}
|
||||||
function resume(){
|
function resume(){
|
||||||
count--;
|
count--;
|
||||||
|
|||||||
Reference in New Issue
Block a user