feat(install, svn): remove svn (#45)

* feat(install, svn): remove svn

Remove everything related to svn.
Rename uoj-svn-lib to uoj-data-lib.
Save preparing problem data to /var/uoj_data/prepare/problem_id.

* Typo: uoj_date -> uoj_data

* add: backward compatibility

BREAKING CHANGE: Preparing problem data location is changed
You need to move files from /var/svn/problem/{id}/cur/{id}/1 to
/var/uoj_data/upload/{id}
This commit is contained in:
mcfx0 2019-06-14 23:30:02 +08:00 committed by Masco Skray
parent 94fbfea97f
commit 69912ba9b3
13 changed files with 61 additions and 302 deletions

View File

@ -16,7 +16,6 @@ fi\n\
service ntp start\n\
service mysql start\n\
service apache2 start\n\
svnserve -d -r /var/svn\n\
su local_main_judger -c \"~/judge_client/judge_client start\"\n\
exec bash\n" >/root/up && chmod +x /root/up

View File

@ -7,8 +7,6 @@ _database_password_=root
_judger_socket_port_=2333
_judger_socket_password_=$(genRandStr 32)
_main_judger_password_=$(genRandStr 32)
_svn_ourroot_password_=$(genRandStr 32)
_svn_certroot_password_=$(genRandStr 32)
getAptPackage(){
printf "\n\n==> Getting environment packages\n"
@ -18,7 +16,7 @@ getAptPackage(){
#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/pinepain/libv8/ubuntu artful main" | tee /etc/apt/sources.list.d/pinepain-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 60C60AA4
apt-get update && apt-get install -y vim ntp zip unzip curl wget subversion 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-6.6-dev libyaml-dev python python3 python-requests
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-6.6-dev libyaml-dev python python3 python-requests
#Install PHP extensions
cp -a /opt/libv8*/* /usr && printf "\n\n" | pecl install v8js yaml
}
@ -81,94 +79,10 @@ sql-mode=ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_Z
UOJEOF
}
setSVNServe(){
printf "\n\n==> Setting SVN server\n"
#Make SVN work dir
mkdir /var/svn && svnserve -d -r /var/svn
mkdir /var/svn/problem && chown -R www-data /var/svn/problem
svnadmin create /var/svn/uoj && svnadmin create /var/svn/judge_client
#Set SVN server config file and password db
sed -i -e 's/# store-plaintext-passwords = no/store-plaintext-passwords = yes/g' /etc/subversion/servers
sed -i -e 's/# anon-access/anon-access/g' -e 's/# auth-access/auth-access/g' -e 's/# password-db/password-db/g' /var/svn/uoj/conf/svnserve.conf
rm -r /var/svn/judge_client/conf/passwd && ln -s /var/svn/uoj/conf/passwd /var/svn/judge_client/conf/passwd
cat /var/svn/uoj/conf/svnserve.conf >/var/svn/judge_client/conf/svnserve.conf
cat >/var/svn/uoj/conf/passwd <<UOJEOF
[users]
root = _svn_certroot_password_
UOJEOF
#Set SVN hook scripts
cat >/var/svn/uoj/hooks/post-commit <<UOJEOF
#!/bin/sh
cd /var/svn/uoj/cur/uoj && svn update --username root --password _svn_certroot_password_
UOJEOF
chmod +x /var/svn/uoj/hooks/post-commit
cat >/var/svn/judge_client/hooks/post-commit <<UOJEOF
#!/bin/sh
su local_main_judger -c '~/judge_client/judge_client update'
exit \$?
UOJEOF
chmod +x /var/svn/judge_client/hooks/post-commit
cat >/var/svn/problem/new_problem.sh <<UOJEOF
if [ \$# -ne 1 ]
then
echo 'invalid argument'
exit 1
fi
path=/var/svn/problem/\$1
mkdir \$path
svnadmin create \$path
cat >\$path/conf/svnserve.conf <<EOD
[general]
anon-access = none
auth-access = write
password-db = passwd
EOD
svnusr="our-root"
svnpwd="_svn_ourroot_password_"
cat >\$path/conf/passwd <<EOD
[users]
\$svnusr = \$svnpwd
EOD
mkdir \$path/cur && cd \$path/cur
svn checkout svn://127.0.0.1/problem/\$1 --username \$svnusr --password \$svnpwd
mkdir /var/uoj_data/\$1
cat >\$path/hooks/post-commit <<EODEOD
#!/bin/sh
/var/svn/problem/post-commit.sh \$1
EODEOD
chmod +x \$path/hooks/post-commit
UOJEOF
chmod +x /var/svn/problem/new_problem.sh
cat >/var/svn/problem/post-commit.sh <<UOJEOF
#!/bin/sh
svnusr="our-root"
svnpwd="_svn_ourroot_password_"
cd /var/svn/problem/\$1/cur/\$1
svn update --username \$svnusr --password \$svnpwd
chown -R www-data /var/svn/problem/\$1
UOJEOF
chmod +x /var/svn/problem/post-commit.sh
#Precheckout to cur folder
mkdir /var/svn/uoj/cur /var/svn/judge_client/cur
svn co svn://127.0.0.1/uoj --username root --password '_svn_certroot_password_' /var/svn/uoj/cur/uoj
svn co svn://127.0.0.1/judge_client --username root --password '_svn_certroot_password_' /var/svn/judge_client/cur/judge_client
chown -R local_main_judger /var/svn/judge_client/cur/judge_client
}
setWebConf(){
printf "\n\n==> Setting web files\n"
#Commit web source file
svn co svn://127.0.0.1/uoj --username root --password '_svn_certroot_password_'
cp -r ../../uoj/1 uoj/1 && cd uoj
svn add 1 && svn ci -m "Installtion commit" --username root --password '_svn_certroot_password_'
cd .. && rm -r uoj
#Set webroot path
ln -sf /var/svn/uoj/cur/uoj/1 /var/www/uoj
cp -r ../../uoj/1 /var/www/uoj
chown -R www-data /var/www/uoj/app/storage
#Set web config file
php -a <<UOJEOF
@ -184,18 +98,13 @@ UOJEOF
setJudgeConf(){
printf "\n\n==> Setting judge_client files\n"
#Commit judge_client source file
svn co svn://127.0.0.1/judge_client --username root --password '_svn_certroot_password_'
cp -r ../../judge_client/1 judge_client/1 && cd judge_client
svn add 1 && svn ci -m "Installation commit" --username root --password '_svn_certroot_password_'
cd .. && rm -r judge_client
#Set uoj_data path
mkdir /var/uoj_data
mkdir /var/uoj_data/prepare
chown -R www-data /var/uoj_data && chgrp -R www-data /var/uoj_data
#Compile judge_client and set runtime
su local_main_judger <<EOD
svn update /var/svn/judge_client/cur/judge_client --username root --password '_svn_certroot_password_'
ln -s /var/svn/judge_client/cur/judge_client/1 ~/judge_client
cp -r ../../judge_client/1 ~/judge_client
ln -s /var/uoj_data ~/judge_client/uoj_judger/data
cd ~/judge_client && chmod +x judge_client
cat >uoj_judger/include/uoj_work_path.h <<UOJEOF
@ -218,9 +127,7 @@ EOD
"judger_name": "main_judger",
"judger_password": "_main_judger_password_",
"socket_port": $_judger_socket_port_,
"socket_password": "_judger_socket_password_",
"svn_username": "root",
"svn_password": "_svn_certroot_password_"
"socket_password": "_judger_socket_password_"
}
UOJEOF
chmod 600 /home/local_main_judger/judge_client/.conf.json
@ -230,8 +137,6 @@ UOJEOF
initProgress(){
printf "\n\n==> Doing initial config and start service\n"
#Replace password placeholders
sed -i "s/_svn_ourroot_password_/$_svn_ourroot_password_/g" /var/svn/problem/new_problem.sh /var/svn/problem/post-commit.sh /var/www/uoj/app/.config.php
sed -i "s/_svn_certroot_password_/$_svn_certroot_password_/g" /var/svn/uoj/conf/passwd /var/svn/uoj/hooks/post-commit /home/local_main_judger/judge_client/.conf.json
sed -i -e "s/_main_judger_password_/$_main_judger_password_/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /home/local_main_judger/judge_client/.conf.json
sed -i -e "s/salt0/$(genRandStr 32)/g" -e "s/salt1/$(genRandStr 16)/g" -e "s/salt2/$(genRandStr 16)/g" -e "s/salt3/$(genRandStr 16)/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /var/www/uoj/app/.config.php
#Import judge_client to MySQL database
@ -245,12 +150,11 @@ initProgress(){
service apache2 restart
su local_main_judger -c '~/judge_client/judge_client start'
#Touch SetupDone flag file
touch /var/svn/.UOJSetupDone
printf "\n\n***Installation complete. Enjoy!***\n"
}
prepProgress(){
getAptPackage;getOracleJDK;setLAMPConf;setSVNServe;setWebConf;setJudgeConf
getAptPackage;getOracleJDK;setLAMPConf;setWebConf;setJudgeConf
}
if [ $# -le 0 ] ;then

View File

@ -9,7 +9,7 @@ RUN apt-get install -y vim \
build-essential \
python \
python-requests \
subversion \
git \
unzip
COPY docker/jdk-7u76-linux-x64.tar.gz \

View File

@ -28,7 +28,6 @@ with open('conf.json', 'w') as f:
print >>f
translate_table = {
'svn_cert': '--username %s --password %s' % (conf['svn_username'], conf['svn_password']),
'uoj_host': ip
}

View File

@ -11,11 +11,8 @@ chown judger /var/uoj_data_copy
su judger <<EOD
cd ~
mkdir judge_client_svn
cd judge_client_svn
svn co svn://__uoj_host__/judge_client __svn_cert__
cd ~
ln -s judge_client_svn/judge_client/1 judge_client
git clone https://github.com/Universal/UOJ-System.git
ln -s UOJ-System/judge_client/1 judge_client
cd judge_client
echo '#define UOJ_WORK_PATH "/home/judger/judge_client/uoj_judger"' >uoj_judger/include/uoj_work_path.h
make

View File

@ -57,8 +57,6 @@ def init():
assert 'judger_password' in jconf
assert 'socket_port' in jconf
assert 'socket_password' in jconf
assert 'svn_username' in jconf
assert 'svn_password' in jconf
# socket server
def socket_server_loop():
@ -138,7 +136,6 @@ def handle_task():
task = taskQ.get_nowait()
if task['cmd'] == 'update':
execute('make clean && svn update --username %s --password %s && make' % (jconf['svn_username'], jconf['svn_password']))
if jconf['judger_name'] == 'main_judger':
uoj_sync_judge_client()
need_restart = True

View File

@ -50,12 +50,6 @@ return [
'password' => '_judger_socket_password_'
]
],
'svn' => [
'our-root' => [
'username' => 'our-root',
'password' => '_svn_ourroot_password_'
]
],
'switch' => [
'web-analytics' => false,
'blog-use-subdomain' => false

View File

@ -1,6 +1,6 @@
<?php
requirePHPLib('judger');
requirePHPLib('svn');
requirePHPLib('data');
if (!authenticateJudger()) {
become404Page();
@ -83,7 +83,7 @@
if ($result['score']) {
list($problem_id) = DB::selectFirst("select problem_id from hacks where id = ${_POST['id']}", MYSQLI_NUM);
if (validateUploadedFile('hack_input') && validateUploadedFile('std_output')) {
svnAddExtraTest(queryProblemBrief($problem_id), $_FILES["hack_input"]["tmp_name"], $_FILES["std_output"]["tmp_name"]);
dataAddExtraTest(queryProblemBrief($problem_id), $_FILES["hack_input"]["tmp_name"], $_FILES["std_output"]["tmp_name"]);
} else {
error_log("hack successfully but received no data. id: ${_POST['id']}");
}
@ -209,4 +209,4 @@
}
echo json_encode($submission);
?>
?>

View File

@ -1,6 +1,5 @@
<?php
requirePHPLib('judger');
requirePHPLib('svn');
if (!authenticateJudger()) {
become404Page();

View File

@ -1,7 +1,7 @@
<?php
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('svn');
requirePHPLib('data');
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
@ -13,34 +13,6 @@
$oj_name = UOJConfig::$data['profile']['oj-name'];
$problem_extra_config = getProblemExtraConfig($problem);
if (isset($_POST['getsvn'])) {
if (Auth::check()) {
$html = <<<EOD
<base target="_blank" />
<p>{$myUser['username']}您好,</p>
<p>您的SVN密码是{$myUser['svn_password']}</p>
<p>{$oj_name}</p>
<style type="text/css">
body{font-size:14px;font-family:arial,verdana,sans-serif;line-height:1.666;padding:0;margin:0;overflow:auto;white-space:normal;word-wrap:break-word;min-height:100px}
pre {white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word}
</style>
EOD;
$mailer = UOJMail::noreply();
$mailer->addAddress($myUser['email'], $myUser['username']);
$mailer->Subject = "SVN密码";
$mailer->msgHTML($html);
if ($mailer->send()) {
echo 'good';
} else {
error_log('PHPMailer: '.$mailer->ErrorInfo);
}
die();
}
}
$data_dir = "/var/uoj_data/${problem['id']}";
function echoFileNotFound($file_name) {
@ -84,9 +56,16 @@ EOD;
move_uploaded_file($_FILES["problem_data_file"]["tmp_name"], $up_filename);
$zip = new ZipArchive;
if ($zip->open($up_filename) === TRUE){
$zip->extractTo("/var/svn/problem/{$problem['id']}/cur/{$problem['id']}/1");
$zip->extractTo("/var/uoj_data/upload/{$problem['id']}");
$zip->close();
svnCommitZipData($problem['id'], 'data');
exec(
<<<EOD
cd /var/uoj_data/upload/$problem['id']
for sub_dir in `find -maxdepth 1 -type d ! -name .`; do
mv -f \$sub_dir/* . && rm -rf \$sub_dir
done
EOD
);
echo "<script>alert('上传成功!')</script>";
}else{
$errmsg = "解压失败!";
@ -103,10 +82,7 @@ EOD;
//添加配置文件
if($_POST['problem_settings_file_submit']=='submit'){
if($_POST['use_builtin_checker'] and $_POST['n_tests'] and $_POST['input_pre'] and $_POST['input_suf'] and $_POST['output_pre'] and $_POST['output_suf'] and $_POST['time_limit'] and $_POST['memory_limit']){
if(!is_dir("/var/svn/problem/{$problem['id']}/cur/{$problem['id']}/1/")){
mkdir("/var/svn/problem/{$problem['id']}/cur/{$problem['id']}/1/");
}
$set_filename="/var/svn/problem/{$problem['id']}/cur/{$problem['id']}/1/problem.conf";
$set_filename="/var/uoj_data/upload/{$problem['id']}/problem.conf";
$has_legacy=false;
if(file_exists($set_filename)){
$has_legacy=true;
@ -135,7 +111,6 @@ EOD;
fwrite($setfile, "time_limit ".$_POST['time_limit']."\n");
fwrite($setfile, "memory_limit ".$_POST['memory_limit']."\n");
fclose($setfile);
svnCommitZipData($problem['id'], 'conf');
if(!$has_legacy){
echo "<script>alert('添加成功!')</script>";
}else{
@ -153,61 +128,16 @@ EOD;
$download_url = HTML::url("/download.php?type=problem&id={$problem['id']}");
$info_form->appendHTML(<<<EOD
<div class="form-group">
<label class="col-sm-3 control-label">SVN地址</label>
<div class="col-sm-9">
<div class="form-control-static">
<button id="button-getsvn" type="button" class="btn btn-info btn-xs pull-right">查看/发送SVN密码</button>
<a>svn://{$http_host}/problem/{$problem['id']}</a>
</div>
</div>
<!--<label class="col-sm-3 control-label">zip上传数据</label>
<div class="col-sm-9">
<div class="form-control-static">
<row>
<button type="button" style="width:30%" class="btn btn-primary" data-toggle="modal" data-target="#UploadDataModal">上传数据</button>
<button type="submit" style="width:30%" id="button-submit-data" name="submit-data" value="data" class="btn btn-danger">与SVN仓库同步</button>
<button type="submit" style="width:30%" id="button-submit-data" name="submit-data" value="data" class="btn btn-danger">检验配置并同步数据</button>
</row>
</div>
</div>-->
</div>
<script type="text/javascript">
$('#button-getsvn').click(function(){
if (!confirm("您的SVN密码是{$myUser['svn_password']}。是否要发送SVN密码到${myUser['email']}")) {
return;
}
$.post('${_SERVER['REQUEST_URI']}', {
getsvn : ''
}, function(res) {
if (res == "good") {
BootstrapDialog.show({
title : "操作成功",
message : "SVN密码已经发送至您的邮箱请查收。",
type : BootstrapDialog.TYPE_SUCCESS,
buttons: [{
label: '好的',
action: function(dialog) {
dialog.close();
}
}],
});
} else {
BootstrapDialog.show({
title : "操作失败",
message : "邮件未发送成功",
type : BootstrapDialog.TYPE_DANGER,
buttons: [{
label: '好吧',
action: function(dialog) {
dialog.close();
}
}],
});
}
});
});
</script>
EOD
);
$info_form->appendHTML(<<<EOD
@ -527,7 +457,7 @@ EOD
global $problem;
$problem['hackable'] = !$problem['hackable'];
//$problem['hackable'] = 0;
$ret = svnSyncProblemData($problem);
$ret = dataSyncProblemData($problem);
if ($ret) {
becomeMsgPage('<div>' . $ret . '</div><a href="/problem/'.$problem['id'].'/manage/data">返回</a>');
}
@ -543,19 +473,19 @@ EOD
$data_form->handle = function() {
global $problem, $myUser;
set_time_limit(60 * 5);
$ret = svnSyncProblemData($problem, $myUser);
$ret = dataSyncProblemData($problem, $myUser);
if ($ret) {
becomeMsgPage('<div>' . $ret . '</div><a href="/problem/'.$problem['id'].'/manage/data">返回</a>');
}
};
$data_form->submit_button_config['class_str'] = 'btn btn-danger btn-block';
$data_form->submit_button_config['text'] = '与SVN仓库同步';
$data_form->submit_button_config['text'] = '检验配置并同步数据';
$data_form->submit_button_config['smart_confirm'] = '';
$clear_data_form = new UOJForm('clear_data');
$clear_data_form->handle = function() {
global $problem;
svnClearProblemData($problem);
dataClearProblemData($problem);
};
$clear_data_form->submit_button_config['class_str'] = 'btn btn-danger btn-block';
$clear_data_form->submit_button_config['text'] = '清空题目数据';

View File

@ -1,6 +1,5 @@
<?php
requirePHPLib('form');
requirePHPLib('svn');
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
@ -23,10 +22,6 @@
} else if ($type == '-') {
DB::query("delete from problems_permissions where problem_id = ${problem['id']} and username = '$username'");
}
},
function() {
global $problem;
svnRefreshPasswordOfProblem($problem['id']);
}
);

View File

@ -1,7 +1,7 @@
<?php
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('svn');
requirePHPLib('data');
if (isSuperUser($myUser)) {
$new_problem_form = new UOJForm('new_problem');
@ -9,7 +9,7 @@
DB::query("insert into problems (title, is_hidden, submission_requirement) values ('New Problem', 1, '{}')");
$id = DB::insert_id();
DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '', '')");
svnNewProblem($id);
dataNewProblem($id);
};
$new_problem_form->submit_button_config['align'] = 'right';
$new_problem_form->submit_button_config['class_str'] = 'btn btn-primary';

View File

@ -2,21 +2,12 @@
// Actually, these things should be done by main_judger so that the code would be much simpler.
// However, this lib exists due to some history issues.
function svnNewProblem($id) {
exec("/var/svn/problem/new_problem.sh $id");
svnRefreshPasswordOfProblem($id);
function dataNewProblem($id) {
mkdir("/var/uoj_data/upload/$id");
mkdir("/var/uoj_data/$id");
exec("cd /var/uoj_data; rm $id.zip; zip $id.zip $id -r -q");
}
function svnRefreshPasswordOfProblem($id) {
$result = DB::query("select user_info.username, svn_password from problems_permissions, user_info where problem_id = $id and user_info.username = problems_permissions.username");
$content = "[users]\n";
$content .= UOJConfig::$data['svn']['our-root']['username']." = ".UOJConfig::$data['svn']['our-root']['password']."\n";
while ($row = DB::fetch($result, MYSQLI_NUM)) {
$content .= "${row[0]} = ${row[1]}\n";
}
file_put_contents("/var/svn/problem/$id/conf/passwd", $content);
}
class UOJProblemConfException extends Exception {
public function __construct($message) {
@ -29,21 +20,21 @@
}
}
function svnClearProblemData($problem) {
function dataClearProblemData($problem) {
$id = $problem['id'];
if (!validateUInt($id)) {
error_log("svnClearProblemData: hacker detected");
error_log("dataClearProblemData: hacker detected");
return "invalid problem id";
}
exec("rm /var/svn/problem/$id -r");
exec("rm /var/uoj_data/upload/$id -r");
exec("rm /var/uoj_data/$id -r");
svnNewProblem($id);
dataNewProblem($id);
}
class SvnSyncProblemDataHandler {
class SyncProblemDataHandler {
private $problem, $user;
private $svn_data_dir, $data_dir, $prepare_dir;
private $upload_dir, $data_dir, $prepare_dir;
private $requirement, $problem_extra_config;
private $problem_conf, $final_problem_conf;
private $allow_files;
@ -62,9 +53,9 @@
if (!isset($this->allow_files[$file_name])) {
throw new UOJFileNotFoundException($file_name);
}
$src = escapeshellarg("{$this->svn_data_dir}/$file_name");
$src = escapeshellarg("{$this->upload_dir}/$file_name");
$dest = escapeshellarg("{$this->prepare_dir}/$file_name");
if (isset($this->problem_extra_config['dont_use_formatter']) || !is_file("{$this->svn_data_dir}/$file_name")) {
if (isset($this->problem_extra_config['dont_use_formatter']) || !is_file("{$this->upload_dir}/$file_name")) {
exec("cp $src $dest -r", $output, $ret);
} else {
exec("$uojMainJudgerWorkPath/run/formatter <$src >$dest", $output, $ret);
@ -75,7 +66,7 @@
}
private function copy_file_to_prepare($file_name) {
global $uojMainJudgerWorkPath;
if (!isset($this->allow_files[$file_name]) || !is_file("{$this->svn_data_dir}/$file_name")) {
if (!isset($this->allow_files[$file_name]) || !is_file("{$this->upload_dir}/$file_name")) {
throw new UOJFileNotFoundException($file_name);
}
$this->copy_to_prepare($file_name);
@ -158,11 +149,11 @@
public function handle() {
$id = $this->problem['id'];
if (!validateUInt($id)) {
error_log("svnSyncProblemData: hacker detected");
error_log("dataSyncProblemData: hacker detected");
return "invalid problem id";
}
$this->svn_data_dir = "/var/svn/problem/$id/cur/$id/1";
$this->upload_dir = "/var/uoj_data/upload/$id";
$this->data_dir = "/var/uoj_data/$id";
$this->prepare_dir = "/var/uoj_data/prepare_$id";
@ -175,11 +166,11 @@
$this->problem_extra_config = json_decode($this->problem['extra_config'], true);
mkdir($this->prepare_dir, 0755);
if (!is_file("{$this->svn_data_dir}/problem.conf")) {
if (!is_file("{$this->upload_dir}/problem.conf")) {
throw new UOJFileNotFoundException("problem.conf");
}
$this->problem_conf = getUOJConf("{$this->svn_data_dir}/problem.conf");
$this->problem_conf = getUOJConf("{$this->upload_dir}/problem.conf");
$this->final_problem_conf = $this->problem_conf;
if ($this->problem_conf === -1) {
throw new UOJFileNotFoundException("problem.conf");
@ -187,14 +178,14 @@
throw new UOJProblemConfException("syntax error");
}
$this->allow_files = array_flip(array_filter(scandir($this->svn_data_dir), function($x){return $x !== '.' && $x !== '..';}));
$this->allow_files = array_flip(array_filter(scandir($this->upload_dir), function($x){return $x !== '.' && $x !== '..';}));
$zip_file = new ZipArchive();
if ($zip_file->open("{$this->prepare_dir}/download.zip", ZipArchive::CREATE) !== true) {
throw new Exception("<strong>download.zip</strong> : failed to create the zip file");
}
if (isset($this->allow_files['require']) && is_dir("{$this->svn_data_dir}/require")) {
if (isset($this->allow_files['require']) && is_dir("{$this->upload_dir}/require")) {
$this->copy_to_prepare('require');
}
@ -307,10 +298,10 @@
}
putUOJConf("{$this->prepare_dir}/problem.conf", $this->final_problem_conf);
if (isset($this->allow_files['download']) && is_dir("{$this->svn_data_dir}/download")) {
foreach (scandir("{$this->svn_data_dir}/download") as $file_name) {
if (is_file("{$this->svn_data_dir}/download/{$file_name}")) {
$zip_file->addFile("{$this->svn_data_dir}/download/{$file_name}", $file_name);
if (isset($this->allow_files['download']) && is_dir("{$this->upload_dir}/download")) {
foreach (scandir("{$this->upload_dir}/download") as $file_name) {
if (is_file("{$this->upload_dir}/download/{$file_name}")) {
$zip_file->addFile("{$this->upload_dir}/download/{$file_name}", $file_name);
}
}
}
@ -336,18 +327,15 @@
}
}
function svnSyncProblemData($problem, $user = null) {
return (new SvnSyncProblemDataHandler($problem, $user))->handle();
function dataSyncProblemData($problem, $user = null) {
return (new SyncProblemDataHandler($problem, $user))->handle();
}
function svnAddExtraTest($problem, $input_file_name, $output_file_name) {
function dataAddExtraTest($problem, $input_file_name, $output_file_name) {
$id = $problem['id'];
$svnusr = UOJConfig::$data['svn']['our-root']['username'];
$svnpwd = UOJConfig::$data['svn']['our-root']['password'];
$cur_dir = "/var/uoj_data/upload/$id";
$cur_dir = "/var/svn/problem/$id/cur/$id";
$problem_conf = getUOJConf("{$cur_dir}/1/problem.conf");
$problem_conf = getUOJConf("{$cur_dir}/problem.conf");
if ($problem_conf == -1 || $problem_conf == -2) {
return $problem_conf;
}
@ -356,57 +344,14 @@
$new_input_name = getUOJProblemExtraInputFileName($problem_conf, $problem_conf['n_ex_tests']);
$new_output_name = getUOJProblemExtraOutputFileName($problem_conf, $problem_conf['n_ex_tests']);
putUOJConf("$cur_dir/1/problem.conf", $problem_conf);
move_uploaded_file($input_file_name, "$cur_dir/1/$new_input_name");
move_uploaded_file($output_file_name, "$cur_dir/1/$new_output_name");
putUOJConf("$cur_dir/problem.conf", $problem_conf);
move_uploaded_file($input_file_name, "$cur_dir/$new_input_name");
move_uploaded_file($output_file_name, "$cur_dir/$new_output_name");
exec(
<<<EOD
cd $cur_dir
svn add 1/$new_input_name --username $svnusr --password $svnpwd
svn add 1/$new_output_name --username $svnusr --password $svnpwd
svn commit -m "add new extra test." --username $svnusr --password $svnpwd
EOD
);
if (svnSyncProblemData($problem) === '') {
if (dataSyncProblemData($problem) === '') {
rejudgeProblemAC($problem);
} else {
error_log('hack successfully but sync failed.');
}
}
function svnCommitZipData($problem, $type) {
$id = $problem['id'];
$cur_dir = "/var/svn/problem/$id/cur/$id";
$svnusr = UOJConfig::$data['svn']['our-root']['username'];
$svnpwd = UOJConfig::$data['svn']['our-root']['password'];
if($type=='conf'){
exec(
<<<EOD
cd $cur_dir
svn add 1/problem.conf --username $svnusr --password $svnpwd
svn commit -m "update problem.conf by online conf editor." --username $svnusr --password $svnpwd
EOD
);
}
else if($type=='data'){
exec(
<<<EOD
cd $cur_dir/1
for sub_dir in `find -maxdepth 1 -type d ! -name .`; do
mv -f \$sub_dir/* . && rm -rf \$sub_dir
done
cd $cur_dir
svn add * --username $svnusr --password $svnpwd
svn commit -m "add testdata from zip file online." --username $svnusr --password $svnpwd
EOD
);
}
else{
error_log("svnCommitZipData: invalid argument");
return "invalid argument";
}
}
?>