Skip to content

Commit

Permalink
Merge pull request #135 from UniversalOJ/develop
Browse files Browse the repository at this point in the history
合并 develop 分支近期更改
  • Loading branch information
renbaoshuo authored Jun 20, 2024
2 parents 25b16d0 + 2f3295b commit d2c9aca
Show file tree
Hide file tree
Showing 36 changed files with 456 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
4 changes: 3 additions & 1 deletion install/bundle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ MAINTAINER MascoSkray <[email protected]>
ARG CLONE_ADDFLAG

WORKDIR /opt
ENV DEBIAN_FRONTEND=noninteractive
#Update apt and install git
RUN apt-get update && apt-get install -y git
RUN apt-get update && apt-get install -y apache2 cmake curl fp-compiler g++ git gnupg libapache2-mod-php libapache2-mod-xsendfile libyaml-dev make mysql-server ntp openjdk-11-jdk openjdk-8-jdk php php-dev php-mbstring php-mysql php-pear php-zip python python3 python3-requests re2c unzip vim wget zip --no-install-recommends
#Clone the latest UOJ Community verison to local
RUN git clone https://github.com/UniversalOJ/UOJ-System.git --depth 1 --single-branch ${CLONE_ADDFLAG} uoj
#Install environment and set startup script
RUN cd uoj/install/bundle && sh install.sh -p && echo "\
#!/bin/sh\n\
rm -rf /run/mysqld/*\n\
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld\n\
if [ ! -f \"/var/uoj_data/.UOJSetupDone\" ]; then\n\
cd /opt/uoj/install/bundle && sh install.sh -i\n\
Expand Down
7 changes: 5 additions & 2 deletions install/bundle/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ getAptPackage(){
export DEBIAN_FRONTEND=noninteractive
(echo "mysql-server mysql-server/root_password password $_database_password_";echo "mysql-server mysql-server/root_password_again password $_database_password_") | debconf-set-selections
#Update apt sources and install
dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg)
echo "deb http://ppa.launchpad.net/stesie/libv8/ubuntu bionic main" | tee /etc/apt/sources.list.d/stesie-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D858A0DF
apt-get update && apt-get install -y vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile libapache2-mod-php php php-dev php-pear php-zip php-mysql php-mbstring mysql-server cmake fp-compiler re2c libv8-7.5-dev libyaml-dev python python3 python3-requests openjdk-8-jdk openjdk-11-jdk
apt-get update && apt-get install -y libv8-7.5-dev
#Install PHP extensions
yes | pecl install yaml
git clone https://github.com/phpv8/v8js.git --depth=1 /tmp/pear/download/v8js-master && cd /tmp/pear/download/v8js-master
Expand Down Expand Up @@ -84,6 +83,10 @@ UOJEOF

setJudgeConf(){
printf "\n\n==> Setting judger files\n"
#specify environment
cat > /etc/environment <<UOJEOF
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
UOJEOF
#Add local_main_judger user
useradd -m local_main_judger && usermod -a -G www-data local_main_judger
#Set uoj_data path
Expand Down
21 changes: 21 additions & 0 deletions install/db/app_uoj233.sql
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,27 @@ LOCK TABLES `user_system_msg` WRITE;
/*!40000 ALTER TABLE `user_system_msg` DISABLE KEYS */;
/*!40000 ALTER TABLE `user_system_msg` ENABLE KEYS */;
UNLOCK TABLES;

create table pastes
(
`index` varchar(20) null,
creator varchar(20) null,
created_at datetime null,
content text null
);

create unique index pastes_index_uindex
on pastes (`index`);

create index pastes_created_at_index
on pastes (created_at);

alter table pastes
add constraint pastes_pk
primary key (`index`);



/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
Expand Down
2 changes: 1 addition & 1 deletion install/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:18.04
FROM ubuntu:20.04
MAINTAINER MascoSkray <[email protected]>
ARG CLONE_ADDFLAG

Expand Down
10 changes: 6 additions & 4 deletions install/web/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ getAptPackage(){
export DEBIAN_FRONTEND=noninteractive
dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg)
echo "deb http://ppa.launchpad.net/stesie/libv8/ubuntu bionic main" | tee /etc/apt/sources.list.d/stesie-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D858A0DF
apt-get update && apt-get install -y vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile libapache2-mod-php php php-dev php-pear php-zip php-mysql php-mbstring g++ cmake re2c libv8-7.5-dev libyaml-dev
apt-get update && apt-get install -y git vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile libapache2-mod-php php php-dev php-pear php-zip php-mysql php-mbstring g++ cmake re2c libv8-7.5-dev libyaml-dev
#Install PHP extensions
printf "/opt/libv8-7.5\n\n" | pecl install v8js yaml
yes | pecl install yaml
git clone https://github.com/phpv8/v8js.git --depth=1 /tmp/pear/download/v8js-master && cd /tmp/pear/download/v8js-master
phpize && ./configure --with-php-config=/usr/bin/php-config --with-v8js=/opt/libv8-7.5 && make install && cd -
}

setLAMPConf(){
Expand Down Expand Up @@ -45,7 +47,7 @@ UOJEOF
a2enmod rewrite headers && sed -i -e '172s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
#Create UOJ session save dir and make PHP extensions available
mkdir --mode=733 /var/lib/php/uoj_sessions && chmod +t /var/lib/php/uoj_sessions
sed -i -e '865a\extension=v8js.so\nextension=yaml.so' /etc/php/7.2/apache2/php.ini
sed -i -e '912a\extension=v8js.so\nextension=yaml.so' /etc/php/7.2/apache2/php.ini
}

setWebConf(){
Expand All @@ -66,7 +68,7 @@ UOJEOF
cat >include/uoj_work_path.h <<UOJEOF
#define UOJ_WORK_PATH "/opt/uoj/judger/uoj_judger"
#define UOJ_JUDGER_BASESYSTEM_UBUNTU1804
#define UOJ_JUDGER_PYTHON3_VERSION "3.6"
#define UOJ_JUDGER_PYTHON3_VERSION "3.8"
#define UOJ_JUDGER_FPC_VERSION "3.0.4"
UOJEOF
make runner -j$(($(nproc) + 1)) && cd ../../install/web
Expand Down
20 changes: 20 additions & 0 deletions judger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.conf.json
log/*
!/log/.gitkeep
uoj_judger/builtin/checker/*
!uoj_judger/builtin/checker/*.cpp
!uoj_judger/builtin/checker/*.h
uoj_judger/builtin/judger/*
!uoj_judger/builtin/judger/*.cpp
!uoj_judger/builtin/judger/*.h
uoj_judger/data
uoj_judger/include/uoj_work_path.h
uoj_judger/main_judger
uoj_judger/run/*
!uoj_judger/run/*.cpp
!uoj_judger/run/*.h
uoj_judger/work/*
uoj_judger/result/*
!uoj_judger/work/.gitkeep
!uoj_judger/result/.gitkeep

4 changes: 2 additions & 2 deletions judger/judge_client
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def handle_task():
uoj_download('/judger', 'judger_update.zip')
execute('unzip -o judger_update.zip && cd %s && make clean && make' % uoj_judger_path())
except:
print(sys.stderr, "error when update")
print("error when update", file=sys.stderr)
if jconf['judger_name'] == 'main_judger':
uoj_sync_judge_client()
need_restart = True
Expand All @@ -149,7 +149,7 @@ def handle_task():
socket_server_thread.join()

print_judge_client_status()
print(sys.stderr, "goodbye!")
print("goodbye!", file=sys.stderr)

sys.exit(0)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion judger/uoj_judger/builtin/judger/judger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void ordinary_test() {
po.scr = scale_score(po.scr, conf_int("point_score", i, 100 / n));
add_point_info(po);
}
} else if (nT == 1) {
} else if (nT == 1 && conf_str("subtask_type", 1, "packed") == "packed") {
for (int i = 1; i <= n; i++) {
report_judge_status_f("Judging Test #%d", i);
PointInfo po = test_point("answer", i);
Expand Down
31 changes: 18 additions & 13 deletions judger/uoj_judger/include/uoj_judger.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <cstring>
#include <string>
#include <cstdarg>
#include <locale>
#include <codecvt>

#include <unistd.h>
#include <sys/file.h>
Expand Down Expand Up @@ -69,22 +71,25 @@ int executef(const char *fmt, ...) {
/*========================= file ====================== */

string file_preview(const string &name, const size_t &len = 100) {
FILE *f = fopen(name.c_str(), "r");
if (f == NULL) {
std::wifstream f(name);
if (!f)
return "";
f.imbue(std::locale("C.UTF-8"));

std::vector<wchar_t> buf(len + 5, 0);
f.read(&buf[0], len + 4);

auto it = std::find(buf.begin(), buf.end(), 0);
if (it - buf.begin() > len + 3) {
buf.resize(len);
for (wchar_t c: "...")
buf.push_back(c);
}
string res = "";
int c;
while (c = fgetc(f), c != EOF && res.size() < len + 4) {
res += c;
}
if (res.size() > len + 3) {
res.resize(len);
res += "...";
}
fclose(f);
return res;

std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> cv;
return cv.to_bytes(&buf[0]);
}

void file_hide_token(const string &name, const string &token) {
executef("cp %s %s.bak", name.c_str(), name.c_str());

Expand Down
10 changes: 8 additions & 2 deletions judger/uoj_judger/run/run_program_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ inline bool is_writable_file(string name) {
if (name == "/") {
return writable_file_name_set.count("system_root");
}
return is_in_set_smart(name, writable_file_name_set) || is_in_set_smart(realpath(name), readable_file_name_set);
return is_in_set_smart(name, writable_file_name_set) || is_in_set_smart(realpath(name), writable_file_name_set);
}
inline bool is_readable_file(const string &name) {
if (is_writable_file(name)) {
Expand Down Expand Up @@ -193,6 +193,7 @@ int syscall_max_cnt_list_default[][2] = {
{__NR_write , -1},
{__NR_readv , -1},
{__NR_writev , -1},
{__NR_pread64 , -1},
{__NR_open , -1},
{__NR_unlink , -1},
{__NR_close , -1},
Expand Down Expand Up @@ -395,7 +396,7 @@ void init_conf(const RunProgramConfig &config) {
statable_file_name_set.insert("/usr/bin");
statable_file_name_set.insert("/usr/lib");
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
statable_file_name_set.insert("/usr/lib/python36.zip");
statable_file_name_set.insert("/usr/lib/python38.zip");
# endif
} else if (config.type == "java8") {
syscall_max_cnt[__NR_gettid ] = -1;
Expand All @@ -408,6 +409,7 @@ void init_conf(const RunProgramConfig &config) {
syscall_max_cnt[__NR_clone ] = 13;

syscall_max_cnt[__NR_getdents ] = 4;
syscall_max_cnt[__NR_getdents64 ] = 4;

syscall_max_cnt[__NR_clock_getres ] = 2;

Expand Down Expand Up @@ -455,6 +457,7 @@ void init_conf(const RunProgramConfig &config) {
syscall_max_cnt[__NR_clone ] = 14;

syscall_max_cnt[__NR_getdents ] = 4;
syscall_max_cnt[__NR_getdents64 ] = 4;

syscall_max_cnt[__NR_clock_getres ] = 2;

Expand All @@ -474,6 +477,7 @@ void init_conf(const RunProgramConfig &config) {
syscall_max_cnt[__NR_pread64 ] = -1;
syscall_max_cnt[__NR_prctl ] = -1;
syscall_max_cnt[__NR_nanosleep ] = -1;
syscall_max_cnt[__NR_clock_nanosleep] = -1;
# endif

syscall_should_soft_ban[__NR_socket ] = true;
Expand Down Expand Up @@ -518,6 +522,7 @@ void init_conf(const RunProgramConfig &config) {

syscall_max_cnt[__NR_setrlimit ] = -1;
syscall_max_cnt[__NR_pipe ] = -1;
syscall_max_cnt[__NR_pipe2 ] = -1;

syscall_max_cnt[__NR_getdents64 ] = -1;
syscall_max_cnt[__NR_getdents ] = -1;
Expand All @@ -544,6 +549,7 @@ void init_conf(const RunProgramConfig &config) {
syscall_max_cnt[__NR_pread64 ] = -1;
syscall_max_cnt[__NR_prctl ] = -1;
syscall_max_cnt[__NR_nanosleep ] = -1;
syscall_max_cnt[__NR_clock_nanosleep] = -1;
syscall_max_cnt[__NR_socketpair ] = -1;
# endif

Expand Down
7 changes: 7 additions & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
.idea
.php_cs.cache
app/.config.php
app/storage/tmp/*
app/storage/submission/*
app/storage/paste/*
!app/storage/tmp/.gitkeep
!app/storage/submission/.gitkeep
!app/storage/paste/.gitkeep
5 changes: 5 additions & 0 deletions web/app/.default-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@
'switch' => [
'web-analytics' => false,
'blog-domain-mode' => 3
],
'tools' => [
// 请仅在https下启用以下功能.
// 非https下, chrome无法进行复制.
'map-copy-enabled' => false,
]
];
4 changes: 2 additions & 2 deletions web/app/controllers/contest_members.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function($contest, $num) {
echo '<tr>';
} else {
if ($ip_owner[$user['remote_addr']] != $user['username']) {
echo '<tr class="danger">';
echo '<tr class="table-danger">';
} else {
echo '<tr>';
}
Expand All @@ -108,4 +108,4 @@ function($contest, $num) {
)
);
?>
<?php echoUOJPageFooter() ?>
<?php echoUOJPageFooter() ?>
3 changes: 2 additions & 1 deletion web/app/controllers/contests.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ function echoContest($contest) {
);

if ($rest_second <= 86400) {
$notification = json_encode($upcoming_contest_name . " 已经开始了。是否要跳转到比赛页面?");
echo <<<EOD
<div class="text-center bot-buffer-lg">
<div class="text-warning">$upcoming_contest_name 倒计时</div>
<div id="contest-countdown"></div>
<script type="text/javascript">
$('#contest-countdown').countdown($rest_second, function() {
if (confirm('$upcoming_contest_name 已经开始了。是否要跳转到比赛页面?')) {
if (confirm($notification)) {
window.location.href = "$upcoming_contest_href";
}
});
Expand Down
12 changes: 6 additions & 6 deletions web/app/controllers/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
</div>
<div id="collapseThree" class="collapse">
<div class="card-body">
<p>默认的测评环境是 Ubuntu Linux 18.04 LTS x64。</p>
<p>C的编译器是 gcc 7.4.0,编译命令:<code>gcc code.c -o code -lm -O2 -DONLINE_JUDGE</code>。</p>
<p>C++的编译器是 g++ 7.4.0,编译命令:<code>g++ code.cpp -o code -lm -O2 -DONLINE_JUDGE</code>。如果选择C++11会在编译命令后面添加<code>-std=c++11</code>。</p>
<p>Java8的JDK版本是 openjdk 1.8.0_222,编译命令:<code>javac code.java</code>。</p>
<p>Java11的JDK版本是 openjdk 11.0.4,编译命令:<code>javac code.java</code>。</p>
<p>默认的测评环境是 Ubuntu Linux 20.04 LTS x64。</p>
<p>C的编译器是 gcc 9.3.0,编译命令:<code>gcc code.c -o code -lm -O2 -DONLINE_JUDGE</code>。</p>
<p>C++的编译器是 g++ 9.3.0,编译命令:<code>g++ code.cpp -o code -lm -O2 -DONLINE_JUDGE</code>。如果选择C++11会在编译命令后面添加<code>-std=c++11</code>。</p>
<p>Java8的JDK版本是 openjdk 1.8.0_275,编译命令:<code>javac code.java</code>。</p>
<p>Java11的JDK版本是 openjdk 11.0.9,编译命令:<code>javac code.java</code>。</p>
<p>Pascal的编译器是 fpc 3.0.4,编译命令:<code>fpc code.pas -O2</code>。</p>
<p>Python会先编译为优化过的字节码<samp>.pyo</samp>文件。支持的Python版本分别为Python 2.7和3.6。</p>
<p>Python会先编译为优化过的字节码<samp>.pyo</samp>文件。支持的Python版本分别为Python 2.7和3.8。</p>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit d2c9aca

Please sign in to comment.