增大编译时限

This commit is contained in:
Harry-zklcdc 2019-09-30 21:05:37 +08:00
commit ed16473d92
8 changed files with 77 additions and 29 deletions

View File

@ -38,7 +38,7 @@
## 文档
[http://docs.onlinejudge.me/](http://docs.onlinejudge.me/)
[https://docs.onlinejudge.me/](https://docs.onlinejudge.me/)
## 截图

View File

@ -40,7 +40,7 @@ Follow me: [https://github.com/Harry-zklcdc/OnlineJudgeDeploy/tree/2.0](https:/
## Documents
[http://docs.onlinejudge.me/](http://docs.onlinejudge.me/)
[https://docs.onlinejudge.me/](https://docs.onlinejudge.me/)
## Screenshots

View File

@ -1,7 +1,11 @@
import functools
import hashlib
import time
from problem.models import Problem
from contest.models import Contest, ContestType, ContestStatus, ContestRuleType
from utils.api import JSONResponse, APIError
from utils.constants import CONTEST_PASSWORD_SESSION_KEY
from .models import ProblemPermission
@ -55,6 +59,32 @@ class problem_permission_required(admin_role_required):
return True
def check_contest_password(password, contest_password):
if not (password and contest_password):
return False
if password == contest_password:
return True
else:
# sig#timestamp 这种形式的密码也可以,但是在界面上没提供支持
# sig = sha256(contest_password + timestamp)[:8]
if "#" in password:
s = password.split("#")
if len(s) != 2:
return False
sig, ts = s[0], s[1]
if sig == hashlib.sha256((contest_password + ts).encode("utf-8")).hexdigest()[:8]:
try:
ts = int(ts)
except Exception:
return False
return int(time.time()) < ts
else:
return False
else:
return False
def check_contest_permission(check_type="details"):
"""
只供Class based view 使用检查用户是否有权进入该contest, check_type 可选 details, problems, ranks, submissions
@ -89,8 +119,8 @@ def check_contest_permission(check_type="details"):
if self.contest.contest_type == ContestType.PASSWORD_PROTECTED_CONTEST:
# password error
if self.contest.id not in request.session.get("accessible_contests", []):
return self.error("Password is required.")
if not check_contest_password(request.session.get(CONTEST_PASSWORD_SESSION_KEY, {}).get(self.contest.id), self.contest.password):
return self.error("Wrong password or password expired")
# regular user get contest problems, ranks etc. before contest started
if self.contest.status == ContestStatus.CONTEST_NOT_START and check_type != "details":

View File

@ -7,10 +7,10 @@ from django.core.cache import cache
from problem.models import Problem
from utils.api import APIView, validate_serializer
from utils.constants import CacheKey
from utils.constants import CacheKey, CONTEST_PASSWORD_SESSION_KEY
from utils.shortcuts import datetime2str, check_is_id
from account.models import AdminType
from account.decorators import login_required, check_contest_permission
from account.decorators import login_required, check_contest_permission, check_contest_password
from utils.constants import ContestRuleType, ContestStatus
from ..models import ContestAnnouncement, Contest, OIContestRank, ACMContestRank
@ -76,13 +76,13 @@ class ContestPasswordVerifyAPI(APIView):
contest = Contest.objects.get(id=data["contest_id"], visible=True, password__isnull=False)
except Contest.DoesNotExist:
return self.error("Contest does not exist")
if contest.password != data["password"]:
return self.error("Wrong password")
if not check_contest_password(data["password"], contest.password):
return self.error("Wrong password or password expired")
# password verify OK.
if "accessible_contests" not in request.session:
request.session["accessible_contests"] = []
request.session["accessible_contests"].append(contest.id)
if CONTEST_PASSWORD_SESSION_KEY not in request.session:
request.session[CONTEST_PASSWORD_SESSION_KEY] = {}
request.session[CONTEST_PASSWORD_SESSION_KEY][contest.id] = data["password"]
# https://docs.djangoproject.com/en/dev/topics/http/sessions/#when-sessions-are-saved
request.session.modified = True
return self.success(True)
@ -94,7 +94,12 @@ class ContestAccessAPI(APIView):
contest_id = request.GET.get("contest_id")
if not contest_id:
return self.error()
return self.success({"access": int(contest_id) in request.session.get("accessible_contests", [])})
try:
contest = Contest.objects.get(id=contest_id, visible=True, password__isnull=False)
except Contest.DoesNotExist:
return self.error("Contest does not exist")
session_pass = request.session.get(CONTEST_PASSWORD_SESSION_KEY, {}).get(contest.id)
return self.success({"access": check_contest_password(session_pass, contest.password)})
class ContestRankAPI(APIView):

View File

@ -1,5 +1,15 @@
{
"update": [
{
"version": "2019-09-22",
"level": "Recommend",
"title": "2019-09-22",
"details": [
"Fix bugs in contest password verification",
"Do not delete test case files when contest is deleted",
"Update some compiler runtime config"
]
},
{
"version": "2019-04-05",
"level": "Recommend",

View File

@ -24,9 +24,9 @@ int main() {
"compile": {
"src_name": "main.c",
"exe_name": "main",
"max_cpu_time": 3000,
"max_cpu_time": 10000,
"max_real_time": 10000,
"max_memory": 256 * 1024 * 1024,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -w -fmax-errors=3 -std=c11 {src_path} -lm -o {exe_path}",
},
"run": {
@ -57,9 +57,9 @@ int main() {
"compile": {
"src_name": "main.c",
"exe_name": "main",
"max_cpu_time": 3000,
"max_cpu_time": 10000,
"max_real_time": 10000,
"max_memory": 256 * 1024 * 1024,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c11 {src_path} -lm -o {exe_path}",
},
"run": {
@ -72,7 +72,7 @@ int main() {
_c_lang_spj_compile = {
"src_name": "spj-{spj_version}.c",
"exe_name": "spj-{spj_version}",
"max_cpu_time": 3000,
"max_cpu_time": 10000,
"max_real_time": 10000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c11 {src_path} -lm -o {exe_path}"
@ -105,9 +105,9 @@ int main() {
"compile": {
"src_name": "main.cpp",
"exe_name": "main",
"max_cpu_time": 3000,
"max_cpu_time": 10000,
"max_real_time": 10000,
"max_memory": 512 * 1024 * 1024,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/g++ -DONLINE_JUDGE -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}",
},
"run": {
@ -138,9 +138,9 @@ int main() {
"compile": {
"src_name": "main.cpp",
"exe_name": "main",
"max_cpu_time": 3000,
"max_real_time": 10000,
"max_memory": 512 * 1024 * 1024,
"max_cpu_time": 10000,
"max_real_time": 20000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}",
},
"run": {
@ -153,8 +153,8 @@ int main() {
_cpp_lang_spj_compile = {
"src_name": "spj-{spj_version}.cpp",
"exe_name": "spj-{spj_version}",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_cpu_time": 10000,
"max_real_time": 20000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}"
}
@ -177,8 +177,8 @@ _java_lang_config = {
"compile": {
"src_name": "Main.java",
"exe_name": "Main",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_cpu_time": 5000,
"max_real_time": 10000,
"max_memory": -1,
"compile_command": "/usr/bin/javac {src_path} -d {exe_dir} -encoding UTF8"
},

View File

@ -430,9 +430,9 @@ class ContestProblemAPI(ProblemBase):
ensure_created_by(problem.contest, request.user)
if Submission.objects.filter(problem=problem).exists():
return self.error("Can't delete the problem as it has submissions")
d = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id)
if os.path.isdir(d):
shutil.rmtree(d, ignore_errors=True)
# d = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id)
# if os.path.isdir(d):
# shutil.rmtree(d, ignore_errors=True)
problem.delete()
return self.success()

View File

@ -31,3 +31,6 @@ class Difficulty(Choices):
LOW = "Low"
MID = "Mid"
HIGH = "High"
CONTEST_PASSWORD_SESSION_KEY = "contest_password"