diff --git a/install/bundle/Dockerfile b/install/bundle/Dockerfile index f7e1b82..8add775 100644 --- a/install/bundle/Dockerfile +++ b/install/bundle/Dockerfile @@ -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 diff --git a/install/bundle/install.sh b/install/bundle/install.sh index 486539c..9efbc30 100644 --- a/install/bundle/install.sh +++ b/install/bundle/install.sh @@ -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 </var/svn/uoj/hooks/post-commit </var/svn/judge_client/hooks/post-commit </var/svn/problem/new_problem.sh <\$path/conf/svnserve.conf <\$path/conf/passwd <\$path/hooks/post-commit </var/svn/problem/post-commit.sh < 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 < 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 <uoj_judger/include/uoj_work_path.h < 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 diff --git a/install/judge_client/Dockerfile b/install/judge_client/Dockerfile index 70054df..5a240d8 100644 --- a/install/judge_client/Dockerfile +++ b/install/judge_client/Dockerfile @@ -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 \ diff --git a/install/judge_client/config_judge_client b/install/judge_client/config_judge_client index d1cba13..93d3c48 100644 --- a/install/judge_client/config_judge_client +++ b/install/judge_client/config_judge_client @@ -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 } diff --git a/install/judge_client/install b/install/judge_client/install index 8e53e83..72105bb 100644 --- a/install/judge_client/install +++ b/install/judge_client/install @@ -11,11 +11,8 @@ chown judger /var/uoj_data_copy su judger <uoj_judger/include/uoj_work_path.h make diff --git a/judge_client/1/judge_client b/judge_client/1/judge_client index c620bf5..6791c2b 100644 --- a/judge_client/1/judge_client +++ b/judge_client/1/judge_client @@ -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 diff --git a/uoj/1/app/.default-config.php b/uoj/1/app/.default-config.php index 427a0c7..232a0b8 100644 --- a/uoj/1/app/.default-config.php +++ b/uoj/1/app/.default-config.php @@ -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 diff --git a/uoj/1/app/controllers/judge/submit.php b/uoj/1/app/controllers/judge/submit.php index 92f165e..29cd2cc 100644 --- a/uoj/1/app/controllers/judge/submit.php +++ b/uoj/1/app/controllers/judge/submit.php @@ -1,6 +1,6 @@ \ No newline at end of file +?> diff --git a/uoj/1/app/controllers/judge/sync_judge_client.php b/uoj/1/app/controllers/judge/sync_judge_client.php index 2c14dc2..ba7ee51 100644 --- a/uoj/1/app/controllers/judge/sync_judge_client.php +++ b/uoj/1/app/controllers/judge/sync_judge_client.php @@ -1,6 +1,5 @@ - -

{$myUser['username']}您好,

-

您的SVN密码是:{$myUser['svn_password']}

-

{$oj_name}

- - -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( +<<alert('上传成功!')"; }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 ""; }else{ @@ -153,61 +128,16 @@ EOD; $download_url = HTML::url("/download.php?type=problem&id={$problem['id']}"); $info_form->appendHTML(<< - -
-
- - svn://{$http_host}/problem/{$problem['id']} -
-
- - - EOD ); $info_form->appendHTML(<<' . $ret . '返回'); } @@ -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('
' . $ret . '
返回'); } }; $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'] = '清空题目数据'; diff --git a/uoj/1/app/controllers/problem_managers_manage.php b/uoj/1/app/controllers/problem_managers_manage.php index 1cd9bb1..415a543 100644 --- a/uoj/1/app/controllers/problem_managers_manage.php +++ b/uoj/1/app/controllers/problem_managers_manage.php @@ -1,6 +1,5 @@ submit_button_config['align'] = 'right'; $new_problem_form->submit_button_config['class_str'] = 'btn btn-primary'; diff --git a/uoj/1/app/libs/uoj-svn-lib.php b/uoj/1/app/libs/uoj-data-lib.php similarity index 78% rename from uoj/1/app/libs/uoj-svn-lib.php rename to uoj/1/app/libs/uoj-data-lib.php index 14b6e4e..93ab34c 100644 --- a/uoj/1/app/libs/uoj-svn-lib.php +++ b/uoj/1/app/libs/uoj-data-lib.php @@ -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("download.zip : 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( -<<