├── .gitignore ├── .travis.yml ├── README.md ├── client.py ├── client_ruby.rb ├── daemon ├── Compiling mysql client on windows.txt ├── INI1.26.h ├── Makefile ├── Makefile_linux ├── Makefile_win ├── call_ruc.cpp ├── cena_validator.cpp ├── chat_server.js ├── conf_items.h ├── config.ini ├── database.cpp ├── http.cpp ├── inet_aton.c ├── json_builder.cpp ├── judge.cpp ├── judge_daemon.h ├── libsablebox │ ├── 1003.in │ ├── 1003.out │ ├── 1003re │ ├── 1003re.cpp │ ├── 1500.in │ ├── 1500.out │ ├── 1500ac │ ├── 1500ac.cpp │ ├── 2000.in │ ├── 2000.out │ ├── 2000mle │ ├── 2000mle.cpp │ ├── 3172.in │ ├── block │ ├── block.c │ ├── caller_helloworld.c │ ├── futex_test │ ├── futex_test.cpp │ ├── helloworld │ ├── helloworld.c │ ├── makefile │ ├── mle_dyn │ ├── mle_dyn.cpp │ ├── mle_static │ ├── mle_static.cpp │ ├── re_div0 │ ├── re_div0.cpp │ ├── re_seg │ ├── re_seg.cpp │ ├── sable-syscallent.h │ ├── sablebox.c │ ├── sablebox.h │ ├── scaffold │ ├── scaffold.c │ ├── scaffold.o │ ├── syscallnum.h │ ├── t.in │ ├── t.out │ ├── t.txt │ ├── tle │ ├── tle.c │ ├── tle.cpp │ └── tmp.c ├── manager.cpp ├── monitor │ └── oj_monitor.c ├── mysql │ └── mysql_win │ │ ├── decimal.h │ │ ├── errmsg.h │ │ ├── keycache.h │ │ ├── libmysql.a │ │ ├── m_ctype.h │ │ ├── m_string.h │ │ ├── my_alloc.h │ │ ├── my_attribute.h │ │ ├── my_compiler.h │ │ ├── my_config.h │ │ ├── my_dbug.h │ │ ├── my_dir.h │ │ ├── my_getopt.h │ │ ├── my_global.h │ │ ├── my_list.h │ │ ├── my_net.h │ │ ├── my_pthread.h │ │ ├── my_sys.h │ │ ├── my_xml.h │ │ ├── mysql.h │ │ ├── mysql │ │ ├── client_plugin.h │ │ ├── innodb_priv.h │ │ ├── plugin.h │ │ ├── plugin_audit.h │ │ ├── plugin_auth.h │ │ ├── plugin_auth_common.h │ │ ├── plugin_ftparser.h │ │ ├── psi │ │ │ ├── mysql_file.h │ │ │ ├── mysql_thread.h │ │ │ ├── psi.h │ │ │ ├── psi_abi_v1.h │ │ │ └── psi_abi_v2.h │ │ ├── service_my_snprintf.h │ │ ├── service_thd_alloc.h │ │ ├── service_thd_wait.h │ │ ├── service_thread_scheduler.h │ │ ├── services.h │ │ └── thread_pool_priv.h │ │ ├── mysql_com.h │ │ ├── mysql_embed.h │ │ ├── mysql_time.h │ │ ├── mysql_version.h │ │ ├── mysqld_ername.h │ │ ├── mysqld_error.h │ │ ├── plugin.h │ │ ├── plugin_audit.h │ │ ├── plugin_ftparser.h │ │ ├── sql_common.h │ │ ├── sql_state.h │ │ ├── sslopt-case.h │ │ ├── sslopt-longopts.h │ │ ├── sslopt-vars.h │ │ └── typelib.h ├── readconfig.cpp ├── runner_linux.c ├── test │ ├── README │ └── validator_test │ │ ├── 1817_data │ │ └── 1817 │ │ │ ├── a1.in │ │ │ ├── a1.out │ │ │ ├── a2.in │ │ │ └── a2.out │ │ ├── filelines_test │ │ ├── blank.txt │ │ ├── filelines │ │ ├── filelines.c │ │ ├── makefile │ │ └── validator.c │ │ ├── makefile │ │ ├── std1.txt │ │ ├── std2.txt │ │ ├── std_identical.txt │ │ ├── std_invalid.txt │ │ ├── std_multi.txt │ │ ├── test_validator │ │ ├── test_validator.c │ │ ├── user.txt │ │ ├── user1.txt │ │ ├── user2.txt │ │ ├── user_identical.txt │ │ ├── user_invalid.txt │ │ ├── user_multi.txt │ │ └── validator.c ├── validator.c ├── win32_ruc │ ├── win32_ruc │ │ ├── ruc.cpp │ │ ├── win32_ruc.sln │ │ ├── win32_ruc.suo │ │ ├── win32_ruc.vcproj │ │ └── win32_ruc.vcproj.MICROSOF-E7F3D7.Administrator.user │ └── win32_run_compiler │ │ ├── main.cpp │ │ ├── win32_run_compiler.vcproj │ │ └── win32_run_compiler.vcproj.MICROSOF-E7F3D7.Administrator.user └── windows_binary │ ├── config.ini │ ├── daemon.exe │ ├── libgcrypt-11.dll │ ├── libgmp.dll │ ├── libgnutls-28.dll │ ├── libgpg-error-0.dll │ ├── libiconv-2.dll │ ├── libintl-8.dll │ ├── libmicrohttpd-10.dll │ ├── libmysql.dll │ ├── libplibc-1.dll │ ├── pthreadGC2.dll │ ├── win32_ruc.exe │ ├── win32_run_compiler.exe │ └── zlib1.dll ├── doc ├── database_convert.sql ├── database_convert.txt ├── diagram_daemon.png ├── init.sql ├── init_score.py ├── nginx.conf └── spj_example.c ├── test_mutex.rb └── web ├── assets ├── Mathjax │ └── README.md ├── css │ ├── bootstrap-responsive.css │ ├── bootstrap.css │ ├── cerulean.min.css │ ├── docs.css │ ├── ex.css │ ├── font-awesome-ie7.min.css │ ├── font-awesome.min.css │ ├── ie6.min.css │ ├── images │ │ ├── animated-overlay.gif │ │ ├── ui-bg_flat_0_aaaaaa_40x100.png │ │ ├── ui-bg_flat_75_ffffff_40x100.png │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ ├── ui-bg_highlight-soft_75_cccccc_1x100.png │ │ ├── ui-icons_222222_256x240.png │ │ ├── ui-icons_2e83ff_256x240.png │ │ ├── ui-icons_454545_256x240.png │ │ ├── ui-icons_888888_256x240.png │ │ └── ui-icons_cd0a0a_256x240.png │ ├── jquery-ui.min.css │ ├── jquery.plupload.queue.css │ └── jquery.ui.plupload.css ├── fonts │ ├── Font-Awesome │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff │ ├── euler.otf │ └── telex.woff ├── ico │ └── favicon.ico ├── img │ ├── glyphicons-halflings-white.png │ ├── glyphicons-halflings.png │ ├── loading.gif │ ├── logo.jpg │ ├── ok-icon.png │ ├── plupload.png │ ├── rotate.gif │ └── wrong-icon.png └── js │ ├── bbcode.js │ ├── bootstrap-affix.js │ ├── bootstrap-alert.js │ ├── bootstrap-button.js │ ├── bootstrap-carousel.js │ ├── bootstrap-collapse.js │ ├── bootstrap-dropdown.js │ ├── bootstrap-modal.js │ ├── bootstrap-popover.js │ ├── bootstrap-scrollspy.js │ ├── bootstrap-tab.js │ ├── bootstrap-tooltip.js │ ├── bootstrap-transition.js │ ├── bootstrap-typeahead.js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── chat.js │ ├── common.js │ ├── google-code-prettify │ ├── prettify.css │ └── prettify.js │ ├── highcharts-more.js │ ├── highcharts.js │ ├── html5.js │ ├── jquery-ui.min.js │ ├── jquery.js │ ├── jquery.plupload.queue.min.js │ ├── jquery.ui.plupload.min.js │ └── plupload.full.min.js └── code ├── about.php ├── admin.php ├── admin_auth.php ├── ajax_admin.php ├── ajax_deleteprob.php ├── ajax_mailfunc.php ├── ajax_message.php ├── ajax_opensource.php ├── ajax_preferences.php ├── ajax_profile.php ├── ajax_saveproblem.php ├── ajax_search.php ├── ajax_testcase.php ├── ajax_usage.php ├── ajax_user.php ├── ajax_usernote.php ├── auth.php ├── backupcode.php ├── board.php ├── control.php ├── download.php ├── edit.php ├── editproblem.php ├── head.php ├── inc ├── checklogin.php ├── checkpwd.php ├── cookie.php ├── database.php ├── lang_conf.php ├── mail_flags.php ├── mathjax_head.php ├── mutex.php ├── preferences.php ├── problem_flags.php ├── result_type.php ├── tgz.lib.php └── userlogin.php ├── index.php ├── level.php ├── login.php ├── logoff.php ├── mail.php ├── marked.php ├── newproblem.php ├── page_header.php ├── postmessage.php ├── problempage.php ├── problemset.php ├── problemset_table.php ├── profile.php ├── proxy.php ├── ranklist.php ├── record.php ├── reg.php ├── rejudge.php ├── search.php ├── searchuser.php ├── solved.php ├── sourcecode.php ├── submit.php ├── testcase.php ├── upload.php └── wait.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | .DS_Store 4 | daemon/daemon 5 | daemon/runner_linux 6 | *.swp 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | before_install: 5 | - sudo apt-get update -qq 6 | - sudo apt-get install -y libmicrohttpd-dev libmysqlclient-dev 7 | script: cd daemon && make -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 安装方法 2 | === 3 | 4 | Web 5 | --- 6 | 7 | 1. 安装并配置好一个可用的php服务器,如apache,nginx等,Linux用户建议安装php扩展[sysvsem] 8 | 2. 安装并启动mysql服务器,运行`doc/init.sql`初始化数据库,修改`web/code/inc/database.php`中的数据库连接信息 9 | 3. 如需显示数学公式,下载Mathjax并解压到`web/assets/Mathjax/` 10 | 4. 将web目录下的全部内容复制到网站根目录下,保证服务器用户(如www)有读写权限(770) 11 | 5. 测试能否访问http://localhost/code/index.php 12 | 13 | Daemon 14 | --- 15 | 16 | **Windows用户:(Deprecated)** 17 | 18 | 1. 修改`daemon/windows_binary/config.ini`中的数据目录,mysql密码等信息 19 | 2. 运行`daemon/windows_binary/daemon.exe` 20 | 3. 如果提示"Started successfully.Waiting for submitting...",说明daemon启动成功,提交一个题目测试 21 | 22 | **Linux用户:** 23 | 24 | 1. 安装编译工具,要求: 25 | - G++ >=4.6 26 | - libmicrohttpd >= 0.9.21 27 | - libmysqlclient 对应mysql版本 28 | 2. 在`daemon/`中运行 29 | 30 | `make` 31 | 32 | 3. 如果没有出错,修改`daemon/config.ini`中的数据目录,mysql密码等信息 33 | 4. 在`daemon/`中运行 34 | 35 | `./daemon` 36 | 37 | 5. 如果提示"Started successfully.Waiting for submitting...",说明daemon启动成功,提交一个题目测试 38 | 39 | [sysvsem]: http://php.net/manual/en/book.sem.php 40 | 41 | 配置文件 42 | === 43 | 44 | 45 | Daemon 46 | --- 47 | 48 | ####config.ini 49 | 50 | 51 | * DATABASE_USER/DATABASE_PASS 为mysql数据库的连接用户名密码,密码可以留空 52 | * datadir 为存放评测数据的目录,该目录存放以题号命名的目录,每个以题号命名的目录下存放该题的测试数据,测试数据输入输出文件名配对即可,例如: 53 | - /home/judge/data/1000/a1.in 54 | - /home/judge/data/1000/a1.out 55 | - /home/judge/data/1000/hello.in 56 | - /home/judge/data/1000/hello.out 57 | - /home/judge/data/1001/abc.in 58 | - /home/judge/data/1001/abc.out 59 | - /home/judge/data/1001/c2.in 60 | - /home/judge/data/1001/c2.out 61 | * [lang*] 允许的提交语言及相应的编译选项,与web端的配置lang_conf.php对应 62 | 63 | Web 64 | --- 65 | 66 | ####lang_conf.php 67 | 68 | 69 | * LANG_NAME 设置各种语言的显示名称 70 | * LANG_EXT 设置各种语言的源文件扩展名 71 | 72 | ####cookie.php 73 | 74 | * cookie_key 设置一个复杂的字符串用于对cookie加密,在生产环境中部署时务必修改,避免伪造cookie 75 | * cookie_expire cookie的过期时间(用于记住登录) 76 | 77 | ####checklogin.php 78 | 79 | * REQUIRE_AUTH 是否要求全局认证,即登录后才能参看OJ的题目等 80 | 81 | Update 82 | --- 83 | 84 | ### 可以测试提交答案题。 85 | 86 | * 添加方式:在`edit.php`里将`judge`的方式改为`Submit`。 87 | * 更新用户下载的输入文件:在`problempage.php`里单击`Update`按扭 (如果要添加附加文件请把`addition.zip`放在测试数据的目录中)。 88 | 89 | #### 更改了测试数据的排序方式:将输入文件的长度作为第一关键字,字典序作为第二关键字。 90 | 91 | #### 在浮点数比较中判断了用户的输出是否为`nan`。 92 | -------------------------------------------------------------------------------- /client_ruby.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'net/http' 4 | require 'json' 5 | 6 | USER = 'NOI' 7 | PASSWD = 'NOINOI' 8 | LANGS = {"G++" => 0, "GCC" => 1, "Pascal" => 2, "G++(0x)" => 3}; 9 | HOST = 'oj.bashu.com.cn' 10 | PORT = 80 11 | CODE2MSG = {0 => "Correct", 2 => "Time Out", 3 => "MLE", 4 => "Wrong Answer", 5 => "Runtime Error", 99 => "Validator Error"}; 12 | CODE2COLOR = {0 => 42, 2 => 43, 3 => 43, 4 => 41, 5 => 46, 99 => 40}; 13 | 14 | def die message, code = 1 15 | puts message.to_s 16 | exit code 17 | end 18 | 19 | def with_color fore, back = nil 20 | unless back 21 | print "\x1B[0;#{fore}m" 22 | else 23 | print "\x1B[0;#{fore};#{back}m" 24 | end 25 | yield 26 | puts "\x1B[0m" 27 | end 28 | 29 | #Check arguments... 30 | die "Usage: #{__FILE__} filename problem_id lang" if ARGV.size != 3 31 | 32 | #Read the F**king Source Code 33 | source = "" 34 | begin 35 | File.open(ARGV[0], 'r') {|f| source = f.read } 36 | rescue SystemCallError => e 37 | die e 38 | end 39 | 40 | die "No such problem - " + ARGV[1] unless ARGV[1] =~ /^\d+$/ 41 | die "No such language : lang = [G++ | GCC | Pascal | G++(0x)]" unless LANGS.has_key? ARGV[2] 42 | 43 | #Login 44 | puts "User : #{USER}" 45 | puts 'Login ...Wait...' 46 | 47 | conn = Net::HTTP.new HOST, PORT 48 | post_data = URI.encode_www_form('uid' => USER, 'pwd' => PASSWD, 'url' => 'index.php') 49 | resp = conn.post '/code/login.php', post_data, {} 50 | die "Can't connect to OJ, check your network. HTTP Code - " + resp.code if resp.code != '302' && resp.code != '200' 51 | die 'Invalid username or password. ' if resp.body.size != 0 52 | 53 | cookie = resp.response['set-cookie'] 54 | 55 | #Submit 56 | puts printf 'Submit ...Wait...' 57 | post_data = URI.encode_www_form('source' => source, 'problem' => ARGV[1], 'language' => LANGS[ARGV[2]]) 58 | resp = conn.post '/code/submit.php', post_data, {'Cookie' => cookie} 59 | die "Connection closed without indication" if resp.code != '302' && resp.code != '200' 60 | 61 | #Show result 62 | query_key = resp.response['location'][-32 .. -1] 63 | puts 'Judging...' + query_key 64 | 65 | retry_times = 3 66 | info_reted = 0 67 | loop do 68 | begin 69 | resp = conn.get 'proxy.php?url=query_' + query_key 70 | raise Exception if resp.code != '200' 71 | rescue Exception 72 | die "Connection closed without indication, please contact with ZYX" if retry_times == 0 73 | retry_times -= 1 74 | retry 75 | end 76 | 77 | info = JSON.load resp.body 78 | detail = info['detail'] 79 | len = detail.size - 1; 80 | if len > info_reted 81 | case detail[0][0] 82 | when 7 83 | with_color 31 do 84 | puts "Compile Error" 85 | with_color(30, 47) {puts detail[0][3]} 86 | end 87 | when 100 88 | with_color 31 do 89 | puts "System Error" 90 | with_color(30, 47) {puts "Please contact with the admin."} 91 | end 92 | else 93 | for i in info_reted ... len 94 | code = detail[i][0] 95 | with_color(37, CODE2COLOR[code]) do 96 | print (printf "%3d %15s %6d ms %7d KB", i, CODE2MSG[code], detail[i][1], detail[i][2]) 97 | end 98 | puts detail[i][3] if (4 .. 5).member? code 99 | puts "------------------------------------------------\n\n" 100 | end 101 | end 102 | info_reted = len 103 | end 104 | die 'Done...', 0 if info['state'] == 'finish' 105 | end 106 | -------------------------------------------------------------------------------- /daemon/Compiling mysql client on windows.txt: -------------------------------------------------------------------------------- 1 | reimp -d libmysql.lib 2 | dlltool -k -d libmysql.def -l libmysql.a 3 | 4 | from: http://blog.csdn.net/mzlogin/article/details/5605320 -------------------------------------------------------------------------------- /daemon/Makefile: -------------------------------------------------------------------------------- 1 | ifdef SystemRoot 2 | include Makefile_win 3 | else 4 | include Makefile_linux 5 | endif 6 | -------------------------------------------------------------------------------- /daemon/Makefile_linux: -------------------------------------------------------------------------------- 1 | all: daemon sablebox runner_linux 2 | daemon: http.o judge.o manager.o readconfig.o database.o cena_validator.o validator.o json_builder.o call_ruc.o 3 | g++ -std=c++0x -O -o daemon http.o database.o judge.o manager.o readconfig.o cena_validator.o validator.o json_builder.o call_ruc.o `pkg-config --libs libmicrohttpd` `pkg-config --libs mysqlclient` -L/usr/lib64/mysql -L/usr/lib/mysql -lmysqlclient -pthread 4 | http.o: http.cpp judge_daemon.h 5 | g++ -std=c++0x -c -O http.cpp `pkg-config --cflags libmicrohttpd` 6 | judge.o: judge.cpp judge_daemon.h 7 | g++ -std=c++0x -c -O judge.cpp 8 | manager.o: manager.cpp judge_daemon.h 9 | g++ -std=c++0x -c -O manager.cpp 10 | readconfig.o: readconfig.cpp judge_daemon.h 11 | g++ -std=c++0x -c -O readconfig.cpp 12 | database.o: database.cpp judge_daemon.h 13 | g++ -std=c++0x -c -O database.cpp `pkg-config --cflags mysqlclient` -I/usr/include/mysql 14 | validator.o: validator.c 15 | gcc -c -O2 validator.c 16 | json_builder.o: json_builder.cpp judge_daemon.h 17 | g++ -std=c++0x -c -O json_builder.cpp 18 | call_ruc.o: call_ruc.cpp 19 | g++ -c -O call_ruc.cpp 20 | cena_validator.o: cena_validator.cpp 21 | g++ -c -O2 cena_validator.cpp 22 | 23 | sablebox: 24 | make -C ./libsablebox 25 | 26 | runner_linux: runner_linux.c libsablebox/libsablebox.a 27 | gcc -I./libsablebox -L./libsablebox runner_linux.c -lsablebox -o runner_linux 28 | 29 | -------------------------------------------------------------------------------- /daemon/Makefile_win: -------------------------------------------------------------------------------- 1 | all: windows_binary/daemon.exe 2 | windows_binary/daemon.exe: http.o inet_aton.o judge.o manager.o readconfig.o database.o cena_validator.o validator.o json_builder.o call_ruc.o 3 | g++ -std=c++0x -O -L./mysql/mysql_win -o windows_binary/daemon.exe http.o inet_aton.o judge.o manager.o json_builder.o call_ruc.o readconfig.o cena_validator.o database.o validator.o -lmysql -lmicrohttpd -lboost_thread-mgw47-mt-1_50 -lboost_system-mgw47-mt-1_50 -lboost_chrono-mgw47-mt-1_50 -lws2_32 4 | http.o: http.cpp judge_daemon.h 5 | g++ -std=c++0x -c -O http.cpp 6 | judge.o: judge.cpp judge_daemon.h 7 | g++ -c -O judge.cpp 8 | manager.o: manager.cpp judge_daemon.h 9 | g++ -std=c++0x -c -O manager.cpp 10 | readconfig.o: readconfig.cpp judge_daemon.h 11 | g++ -std=c++0x -c -O readconfig.cpp 12 | win32_run.o: win32_run.cpp judge_daemon.h 13 | g++ -c -O win32_run.cpp 14 | database.o: database.cpp judge_daemon.h 15 | g++ -std=c++0x -c -O database.cpp -I./mysql/mysql_win 16 | cena_validator.o: cena_validator.cpp 17 | g++ -c -O2 cena_validator.cpp 18 | validator.o: validator.c 19 | gcc -c -O2 validator.c 20 | json_builder.o: json_builder.cpp judge_daemon.h 21 | g++ -std=c++0x -c -O json_builder.cpp 22 | call_ruc.o: call_ruc.cpp 23 | g++ -std=c++0x -c -O call_ruc.cpp 24 | inet_aton.o: inet_aton.c 25 | gcc -c -DHAVE_WINSOCK2_H -O inet_aton.c 26 | -------------------------------------------------------------------------------- /daemon/call_ruc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "judge_daemon.h" 6 | 7 | #ifdef _WIN32 8 | #include 9 | #define RUC_NAME "..\\win32_ruc " 10 | #else 11 | #define RUC_NAME "../runner_linux " 12 | #endif 13 | 14 | #define SPJ_MAX_TIME 5000 15 | #define SPJ_MAX_MEM 1073741824 16 | #define MAX_REPORT_LENGTH 64 17 | 18 | 19 | int run_judge(const char *target, const char *input, const char *output, int time, int mem, execute_info* info) 20 | { 21 | std::ostringstream command; 22 | static char info_str[128]; 23 | command << RUC_NAME << target << ' ' << time 24 | << ' ' << mem << " \"" << input << "\" \"" << output << "\""; 25 | const std::string &str = command.str(); 26 | //puts(str.c_str()); 27 | int ret = system(str.c_str()); 28 | if(ret) { 29 | sprintf(info_str, "Error: RUC exited with %d", ret); 30 | applog(info_str); 31 | return ret; 32 | } 33 | FILE *run_info = fopen("run.info", "r"); 34 | char type[20]; 35 | int val; 36 | if(!run_info) { 37 | applog("Can't open run.info"); 38 | return 1; 39 | } 40 | info->str = NULL; 41 | while(fscanf(run_info, "%s%*s", type) > 0) { 42 | if(!strcmp(type, "Info")) { 43 | fgets(info_str, 100, run_info); 44 | info->str = info_str; 45 | }else if(!strcmp(type, "Time")) { 46 | fscanf(run_info, "%d", &val); 47 | info->time = val; 48 | }else if(!strcmp(type, "Memory")) { 49 | fscanf(run_info, "%d", &val); 50 | info->memory = val; 51 | }else if(!strcmp(type, "State")) { 52 | fscanf(run_info, "%d", &val); 53 | info->state = val; 54 | } 55 | } 56 | 57 | fclose(run_info); 58 | return ret; 59 | } 60 | validator_info run_spj(char *datafile_out, char *datafile_in, int *score, char *data_dir) 61 | { 62 | std::ostringstream cmd; 63 | validator_info info; 64 | info.ret = -1; 65 | #ifdef _WIN32 66 | system("del /f /q /s score.log report.log"); 67 | CopyFile(datafile_in, "user.in", 0); 68 | CopyFile(datafile_out, "std.ans", 0); 69 | 70 | cmd << RUC_NAME << data_dir << "\\spj.exe " << SPJ_MAX_TIME << ' ' << SPJ_MAX_MEM << " \"\" \"\" -spj " << *score << " std.ans"; 71 | #else 72 | system("rm -f -r score.log report.log"); 73 | system((std::string("cp ")+datafile_in+" user.in").c_str()); 74 | system((std::string("cp ")+datafile_out+" std.ans").c_str()); 75 | cmd << "test -x spj.exe || g++ '" << data_dir << "/spj.cpp' -o spj.exe"; 76 | if(system(cmd.str().c_str())) { 77 | applog("Error: Cannot find spj"); 78 | return info; 79 | } 80 | cmd.str(""); 81 | cmd << RUC_NAME << "./spj.exe " << SPJ_MAX_TIME << ' ' << SPJ_MAX_MEM << " '' '' -spj " << *score << " std.ans"; 82 | #endif 83 | 84 | int ret = system(cmd.str().c_str()); 85 | if(ret) { 86 | char msg[64]; 87 | sprintf(msg, "Error: RUC for spj exited with %d", ret); 88 | applog(msg); 89 | return info; 90 | } 91 | 92 | { 93 | FILE *fscore = fopen("score.log", "r"); 94 | if(!fscore) { 95 | applog("Error: Cannot open score.log"); 96 | return info; 97 | } 98 | 99 | double t; 100 | if(1 != fscanf(fscore, "%lf", &t)) { 101 | applog("Error: Invalid score.log"); 102 | fclose(fscore); 103 | return info; 104 | } 105 | info.ret = 4; //must be 4 for spj 106 | *score = (int)t; 107 | fclose(fscore); 108 | } 109 | 110 | { 111 | info.user_mismatch = (char *)malloc(MAX_REPORT_LENGTH); 112 | info.user_mismatch[0] = '\0'; 113 | FILE *freport = fopen("report.log", "r"); 114 | if(freport) { 115 | fgets(info.user_mismatch, MAX_REPORT_LENGTH, freport); 116 | fclose(freport); 117 | } 118 | } 119 | 120 | return info; 121 | } 122 | -------------------------------------------------------------------------------- /daemon/cena_validator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | from: https://cena.googlecode.com/svn/trunk/lib/diffu.pas 3 | translated into C by zyx 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | struct validator_info{ 10 | int ret; 11 | char* user_mismatch; 12 | char* std_mismatch; 13 | }; 14 | 15 | 16 | #define VAL_FUCKED (-1) 17 | #define VAL_IDENTICAL 0 18 | #define VAL_MISMATCH 1 19 | #define VAL_LONGER 2 20 | #define VAL_SHORTER 3 21 | 22 | static int fs[2], line, col[2]; 23 | static FILE *f[2]; 24 | struct Tchar 25 | { 26 | bool have, he; 27 | int eml; 28 | char c; 29 | }chars[2]; 30 | 31 | void GetChar(int fi) 32 | { 33 | char ch, last; 34 | last = 0; 35 | for(;;) { 36 | ch = fgetc(f[fi]); 37 | if(ch == EOF) 38 | return; 39 | if(ch == 10) { 40 | if(last != 13) 41 | chars[fi].eml++; 42 | col[fi] = 0; 43 | chars[fi].he = false; 44 | }else if(ch == 13) { 45 | chars[fi].eml++; 46 | col[fi] = 0; 47 | chars[fi].he = false; 48 | }else { 49 | col[fi]++; 50 | if(ch==' ') { 51 | if(chars[fi].eml == 0) 52 | chars[fi].he = true; 53 | }else { 54 | chars[fi].c = ch; 55 | break; 56 | } 57 | } 58 | last = ch; 59 | } 60 | chars[fi].have = true; 61 | if(fi == 0) 62 | line += chars[fi].eml; 63 | } 64 | int CheckNow() 65 | { 66 | int result; 67 | col[0] = col[1] = fs[0] = fs[1] = line = 0; 68 | memset(chars, 0, sizeof(chars)); 69 | 70 | result = VAL_IDENTICAL; 71 | chars[0].eml = chars[1].eml = 1; 72 | 73 | for(;;) { 74 | GetChar(0); 75 | GetChar(1); 76 | 77 | if(!chars[0].have && !chars[1].have) 78 | return result; 79 | 80 | if(chars[0].have && !chars[1].have) { 81 | result = VAL_LONGER; 82 | return result; 83 | } 84 | if(!chars[0].have && chars[1].have) { 85 | result = VAL_SHORTER; 86 | return result; 87 | } 88 | if(chars[0].eml > chars[1].eml) { 89 | result = VAL_MISMATCH; 90 | return result; 91 | } 92 | if(chars[1].eml > chars[0].eml) { 93 | result = VAL_MISMATCH; 94 | return result; 95 | } 96 | if(chars[0].he != chars[1].he || chars[0].c != chars[1].c) { 97 | result =VAL_MISMATCH; 98 | return result; 99 | } 100 | 101 | memset(chars, 0 ,sizeof(chars)); 102 | } 103 | return VAL_FUCKED; 104 | } 105 | 106 | struct validator_info validator_cena(FILE* fstd, FILE* fuser) 107 | { 108 | validator_info result; 109 | 110 | f[0] = fuser; 111 | f[1] = fstd; 112 | /* 113 | if(!fstd || fseek(fstd, 0, SEEK_END) || (fs[1]=ftell(fstd))==-1) 114 | return VAL_FUCKED; 115 | if(!fuser || fseek(fuser, 0, SEEK_END) || (fs[0]=ftell(fuser))==-1) 116 | return VAL_FUCKED; 117 | 118 | rewind(fstd); 119 | rewind(fuser); 120 | */ 121 | result.ret = CheckNow(); 122 | if(result.ret == VAL_MISMATCH) { 123 | result.user_mismatch = (char*) malloc(3); 124 | result.std_mismatch = (char*) malloc(3); 125 | 126 | *result.user_mismatch = *result.std_mismatch = 0; 127 | } 128 | 129 | return result; 130 | } 131 | /* 132 | int main() 133 | { 134 | FILE* f1 = fopen("A.txt", "r"); 135 | FILE* f2 = fopen("B.txt", "r"); 136 | struct validator_info ret = validator_cena(f1, f2); 137 | 138 | if(ret.ret == VAL_FUCKED) 139 | printf("Error\n"); 140 | else if(ret.ret == VAL_IDENTICAL) 141 | printf("Identical\n"); 142 | else if(ret.ret == VAL_MISMATCH){ 143 | printf("Mismatch\n"); 144 | printf("user output: %s\n", ret.user_mismatch); 145 | printf("std output: %s\n", ret.std_mismatch); 146 | }else if(ret.ret == VAL_SHORTER) 147 | printf("Shorter\n"); 148 | else 149 | printf("Longer\n"); 150 | return 0; 151 | } 152 | */ 153 | -------------------------------------------------------------------------------- /daemon/chat_server.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var WebSocketServer = require('ws').Server; 3 | 4 | var crypto = require('crypto'); 5 | var iv='7284565820000000'; 6 | var key=crypto.createHash('sha256').update('my)(password_xx0').digest(); 7 | 8 | function decode_user_id(str) 9 | { 10 | var decoded; 11 | try { 12 | var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); 13 | decoded = decipher.update(str, 'base64', 'utf8'); 14 | decoded += decipher.final('utf8'); 15 | if(!(/^id-\w+$/.test(decoded))) 16 | throw 0; 17 | decoded = decoded.substring(3); 18 | }catch(e) { 19 | return null; 20 | } 21 | return decoded; 22 | } 23 | function getTime() 24 | { 25 | var now = new Date(); 26 | var h = now.getHours(), m = now.getMinutes(), s = now.getSeconds(); 27 | return '['+(h < 10 ? '0' : '')+h+':'+(m < 10 ? '0' : '')+m+':'+(s < 10 ? '0' : '')+s+']'; 28 | } 29 | 30 | var clients = {}, total = 0, online = 0; 31 | 32 | var srv = http.createServer(); 33 | srv.listen(6844, function() { 34 | console.log('Server started.'); 35 | var wss = new WebSocketServer({server : srv}); 36 | 37 | wss.on('connection', function(ws) { 38 | var client_id = ++total; 39 | ++online; 40 | console.log('connected %d', client_id); 41 | clients[client_id] = ws; 42 | 43 | ws.on('message', function(message) { 44 | console.log('received: %s', message); 45 | 46 | if(!ws.hasOwnProperty('user_id')){ 47 | var user = decode_user_id(message); 48 | if(user === null) 49 | ws.close(); 50 | ws.user_id = user; 51 | return; 52 | } 53 | 54 | var msg = getTime() + '[' + ws.user_id + '] ' + message; 55 | for(var i in clients) { 56 | clients[i].send(msg); 57 | } 58 | }); 59 | ws.on('close', function(){ 60 | --online; 61 | delete clients[client_id]; 62 | console.log('close %d', client_id); 63 | }); 64 | }); 65 | }); -------------------------------------------------------------------------------- /daemon/conf_items.h: -------------------------------------------------------------------------------- 1 | #ifndef CONF_ITEM_H_ 2 | #define CONF_ITEM_H_ 3 | 4 | //Configure variables defined in readconf.cpp 5 | 6 | extern char DATABASE_HOST[], DATABASE_USER[], DATABASE_PASS[], DATABASE_NAME[]; 7 | extern char HTTP_BIND_IP[]; 8 | extern uint16_t HTTP_BIND_PORT; 9 | 10 | extern bool lang_exist[]; 11 | extern int lang_extra_mem[]; 12 | extern std::string lang_ext[], lang_compiler[]; 13 | 14 | extern char DataDir[]; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /daemon/config.ini: -------------------------------------------------------------------------------- 1 | [system] 2 | datadir=/home/judge/data 3 | DATABASE_USER=root 4 | DATABASE_PASS= 5 | 6 | [lang1] 7 | ext=cpp 8 | extra_mem=20480 9 | compiler=timeout -s SIGKILL 5s g++ -static -fno-asm -s -w -O -DONLINE_JUDGE -o target.exe 10 | 11 | [lang2] 12 | ext=c 13 | extra_mem=20480 14 | compiler=timeout -s SIGKILL 5s gcc -static -fno-asm -s -w -O -DONLINE_JUDGE -O -o target.exe 15 | 16 | [lang3] 17 | ext=pas 18 | extra_mem=20480 19 | compiler=timeout -s SIGKILL 5s fpc -Xs -Sgic -dONLINE_JUDGE -otarget.exe 20 | 21 | [lang4] 22 | ext=cpp 23 | extra_mem=20480 24 | compiler=timeout -s SIGKILL 5s g++ -static --std=gnu++0x -O -DONLINE_JUDGE -o target.exe 25 | 26 | [lang5] 27 | ext=txt 28 | extra_mem=0 29 | compiler=Submit Answer -------------------------------------------------------------------------------- /daemon/json_builder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "judge_daemon.h" 5 | 6 | class encoder 7 | { 8 | char *buf; 9 | public: 10 | encoder(std::string &in) 11 | { 12 | buf = (char*)malloc((in.size() << 1)+3); 13 | if(!buf) 14 | throw "encoder: Can't allocate memory"; 15 | char *p = buf; 16 | *(p++) = '"'; 17 | for(char &c : in) { 18 | switch (c) { 19 | case '"': 20 | *(p++) = '\\'; 21 | *(p++) = '"'; 22 | break; 23 | case '\\': 24 | *(p++) = '\\'; 25 | *(p++) = '\\'; 26 | break; 27 | case '\n': 28 | *(p++) = '\\'; 29 | *(p++) = 'n'; 30 | break; 31 | case '\r': 32 | *(p++) = '\\'; 33 | *(p++) = 'r'; 34 | break; 35 | default: 36 | *(p++) = c; 37 | } 38 | } 39 | *(p++) = '"'; 40 | *p = 0; 41 | } 42 | ~encoder() 43 | { 44 | free(buf); 45 | } 46 | friend std::ostream& operator<<(std::ostream &os,const encoder &me) 47 | { 48 | os << me.buf; 49 | return os; 50 | } 51 | }; 52 | 53 | void json_builder(std::ostringstream &json, solution *target) 54 | { 55 | if(target->timestamp != 0) 56 | json<<"{\"state\":\"finish\",\"detail\":["; 57 | else 58 | json<<"{\"state\":\"wait\",\"detail\":["; 59 | /*if(target->error_code == RES_CE){ 60 | json<last_state)<<"]}"; 61 | return; 62 | }*/ 63 | for(case_info &c : target->detail_results) 64 | json<<"["< 2 | #include 3 | #include 4 | 5 | struct case_info 6 | { 7 | int error_code, time, memory; 8 | std::string info; 9 | int score; 10 | }; 11 | 12 | struct solution 13 | { 14 | int problem, compare_way, lang, time_limit, mem_limit, score, error_code; 15 | bool public_code; 16 | unsigned char type; 17 | volatile bool judge_done; 18 | std::string code, user, key, last_state; 19 | std::vector detail_results; 20 | void *mutex_for_query;//use void* to avoid including 21 | time_t timestamp; 22 | #ifdef DUMP_FOR_DEBUG 23 | std::string raw_post_data; 24 | #endif 25 | const char *target_path; 26 | 27 | solution(); 28 | ~solution(); 29 | void copy_setting(const solution &) throw (); 30 | bool compile() throw (const char *); 31 | void judge() throw (const char *); 32 | void write_database() throw (const char *); 33 | }; 34 | 35 | struct execute_info 36 | { 37 | int state, time, memory; 38 | char *str; 39 | }; 40 | 41 | struct validator_info{ 42 | int ret; 43 | char* user_mismatch; 44 | char* std_mismatch; 45 | }; 46 | 47 | enum {TYPE_normal=0, TYPE_rejudge=1}; 48 | enum {MSG_problem, MSG_lang, MSG_time, MSG_mem, MSG_score, MSG_code, MSG_user, MSG_key, MSG_share, MSG_compare, MSG_rejudge}; 49 | enum {RES_AC=0, RES_CE=7, RES_TLE=2, RES_MLE=3, RES_WA=4, RES_RE=5, RES_VE=99, RES_SE=100}; 50 | 51 | typedef int (*run_compiler_def)(const char *, char *, int); 52 | typedef int (*run_judge_def)(const char *, const char *, const char *, int, int, execute_info*); 53 | 54 | const char* getTargetPath(); 55 | void applog(const char *str, const char *info = "") throw (); 56 | bool read_config(); 57 | bool start_http_interface(); 58 | bool init_mysql_con() throw (); 59 | char *JUDGE_get_progress(const char*); 60 | char *JUDGE_accept_submit(solution *&sol); 61 | char *JUDGE_start_rejudge(solution *&sol); 62 | bool clean_files() throw (); 63 | int get_next_solution_id() throw (const char *); 64 | void write_result_to_database(int, solution*) throw (const char *); 65 | void get_exist_solution_info(int solution_id, solution* sol) throw (const char *); 66 | void update_exist_solution_info(int solution_id, solution* sol) throw (const char *); 67 | void refresh_users_problem(int problem_id) throw (const char *); 68 | void get_solution_list(std::vector &rejudge_list, int problem_id) throw (const char *); 69 | 70 | struct validator_info validator_cena(FILE* fstd, FILE* fuser); 71 | extern "C" { 72 | struct validator_info validator(FILE* fstd, FILE* fuser); 73 | struct validator_info validator_int(FILE* fstd, FILE* fuser); 74 | struct validator_info validator_float(FILE* fstd, FILE* fuser, int); 75 | } 76 | 77 | int run_judge(const char *, const char *, const char *, int, int, execute_info*); 78 | validator_info run_spj(char *datafile_out, char *datafile_in, int *score, char *data_dir); 79 | 80 | 81 | -------------------------------------------------------------------------------- /daemon/libsablebox/1003.in: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /daemon/libsablebox/1003.out: -------------------------------------------------------------------------------- 1 | 1 6 -------------------------------------------------------------------------------- /daemon/libsablebox/1003re: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/1003re -------------------------------------------------------------------------------- /daemon/libsablebox/1003re.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int N,k,i,a[3*N],b[N+1],head,tail; 6 | cin>>N; 7 | head=1;tail=N+1;k=1; 8 | for(i=1;i<=N;i++) a[i]=i; 9 | while(1) 10 | {b[a[head]]=k;k++; 11 | if(k>N) break; 12 | head++; 13 | a[tail]=a[head];tail++;head++; 14 | a[tail]=a[head];tail++;head++;} 15 | for(i=1;i<=N;i++) cout< 2 | #include 3 | #include 4 | using namespace std; 5 | long long f[1001][1001]; 6 | int l[1001],m[1001]; 7 | long long max(long long a,long long b,long long c) 8 | { 9 | long long ans=a; 10 | if(b>ans) ans=b; 11 | if(c>ans) ans=c; 12 | return ans; 13 | } 14 | int main() 15 | { 16 | int n,lo,hi,i,j,w; 17 | cin>>n>>lo>>hi; 18 | memset(f,0,sizeof(f)); 19 | for(i=1;i<=n;i++){scanf("%d",&l[i]);l[i]+=l[i-1];} 20 | for(i=1;i<=n;i++){scanf("%d",&m[i]);m[i]+=m[i-1];} 21 | for(i=1;i<=n;i++) 22 | for(j=i;j<=n;j++) 23 | { 24 | w=0; 25 | if(l[j]-l[i-1]>=lo&&l[j]-l[i-1]<=hi) w=m[j]-m[i-1]; 26 | f[i][j]=max(f[i-1][j],f[i][j-1],f[i-1][j-1]+w); 27 | } 28 | cout< 2 | using namespace std; 3 | long long a[200001],b[9999999]; 4 | void fac(long q,long p) 5 | {long i=q,j=p,mid=a[(p+q)/2],t; 6 | while (i<=j) 7 | {while(a[i]mid)j--; 9 | if (a[i]>=a[j] ) 10 | {t=a[i]; 11 | a[i]=a[j]; 12 | a[j]=t; 13 | i++; 14 | j--;} 15 | if (i>n; 23 | for (i=1;i<=n;i++){cin>>a[i];b[a[i]]++;} 24 | fac(1,n); 25 | for (i=1;i<=n;i++){cout< 2 | int main() 3 | { 4 | int i; 5 | for(;;) 6 | scanf("%d", &i); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /daemon/libsablebox/caller_helloworld.c: -------------------------------------------------------------------------------- 1 | #include "sablebox.h" 2 | #include 3 | 4 | #define CASE(STA)\ 5 | case STA: \ 6 | puts( #STA ); 7 | 8 | #define deftest(pathname) \ 9 | int test##pathname () \ 10 | {\ 11 | struct sablebox sbox;\ 12 | struct profile ret;\ 13 | sable_init(&sbox, #pathname, "t.in", "t.out", 3000, 1024*30, 0);\ 14 | ret = sable_run(&sbox);\ 15 | switch(ret.status){\ 16 | CASE(PROF_SUCCESS)\ 17 | break;\ 18 | CASE(PROF_NOTSET)\ 19 | break;\ 20 | CASE(PROF_RUNTIME_ERROR)\ 21 | printf("%s\n", ret.info);\ 22 | break;\ 23 | CASE(PROF_TIME_LIMIT_EXCEED)\ 24 | break;\ 25 | CASE(PROF_MEMORY_LIMIT_EXCEED)\ 26 | break;\ 27 | CASE(PROF_SYSTEM_ERROR)\ 28 | break;\ 29 | }\ 30 | printf("Memory: %ld\nTime: %ld\n", ret.memory, ret.time);\ 31 | puts("");\ 32 | } 33 | deftest(re_seg) 34 | deftest(re_div0) 35 | 36 | int main(int argc, char** argv) 37 | { 38 | testre_div0(); 39 | testre_seg(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /daemon/libsablebox/futex_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/futex_test -------------------------------------------------------------------------------- /daemon/libsablebox/futex_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define clear(x) memset((x),0,sizeof(x)) 4 | #define N 64 5 | struct _e{ 6 | int to,next; 7 | }e[512],re[512]; 8 | int n,top[N],head[N],rhead[N],belong[N],oppo[N],SCC,cnt,tot; 9 | bool flag[N],slt[N]; 10 | void add(int a,int b){ 11 | e[++tot].to=b; 12 | e[tot].next=head[a]; 13 | head[a]=tot; 14 | 15 | re[tot].to=a; 16 | re[tot].next=rhead[b]; 17 | rhead[b]=tot; 18 | } 19 | void dfs(int v){ 20 | flag[v]=1; 21 | for(int i=head[v];i;i=e[i].next) 22 | if(!flag[e[i].to]) 23 | dfs(e[i].to); 24 | top[++cnt]=v; 25 | } 26 | void shrink(int v){ 27 | belong[v]=SCC; 28 | for(int i=rhead[v];i;i=re[i].next) 29 | if(!belong[re[i].to]) 30 | shrink(re[i].to); 31 | } 32 | void kosaraju(){ 33 | clear(flag); 34 | clear(belong); 35 | SCC=cnt=0; 36 | for(int i=1;i<=n;i++) 37 | if(!flag[i]) 38 | dfs(i); 39 | for(int i=cnt;i;i--) 40 | if(!belong[top[i]]){ 41 | SCC++; 42 | shrink(top[i]); 43 | } 44 | } 45 | int other(int i){ 46 | return (i&1)?i+1:i-1; 47 | } 48 | int main(){ 49 | int m; 50 | while(scanf("%d%d",&n,&m),n){ 51 | tot=0;clear(head);clear(rhead);clear(slt); 52 | add(2,1); 53 | while(m--){ 54 | int x,y;char sx,sy; 55 | scanf("%d%c%d%c",&x,&sx,&y,&sy); 56 | x++;y++; 57 | add(x*2-int(sx=='h'),y*2-int(sy=='w')); 58 | add(y*2-int(sy=='h'),x*2-int(sx=='w')); 59 | } 60 | n=n*2; 61 | kosaraju(); 62 | for(int i=1;i<=n;i+=2) 63 | if(belong[i]==belong[i+1]){ 64 | puts("bad luck");goto over; 65 | } 66 | for(int i=1;i<=n;i++) 67 | oppo[belong[i]]=belong[other(i)]; 68 | for(int i=SCC;i;i--) 69 | if(!slt[oppo[i]]) 70 | slt[i]=1; 71 | for(int i=3;i<=n;i+=2){ 72 | printf("%d%c ",i>>1,slt[belong[i]]?'w':'h'); 73 | } 74 | puts(""); 75 | over:; 76 | } 77 | } -------------------------------------------------------------------------------- /daemon/libsablebox/helloworld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/helloworld -------------------------------------------------------------------------------- /daemon/libsablebox/helloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("%d\n", time(0)); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /daemon/libsablebox/makefile: -------------------------------------------------------------------------------- 1 | libsablebox.a: sablebox.o 2 | ar -rs libsablebox.a sablebox.o 3 | 4 | scaffold: scaffold.o sablebox.o 5 | gcc scaffold.o sablebox.o -o scaffold 6 | 7 | scaffold.o: sablebox.h scaffold.c 8 | gcc scaffold.c -c 9 | 10 | sablebox.o: sablebox.h sablebox.c 11 | gcc sablebox.c -c 12 | 13 | #helloworld: helloworld.c 14 | # gcc helloworld.c -static -o helloworld 15 | #re_seg: re_seg.cpp 16 | # g++ re_seg.cpp -static -o re_seg 17 | #re_div0: re_div0.cpp 18 | # g++ re_div0.cpp -static -o re_div0 19 | #mle_dyn: mle_dyn.cpp 20 | # g++ mle_dyn.cpp -static -o mle_dyn 21 | #mle_static: mle_static.cpp 22 | # g++ mle_static.cpp -static -o mle_static 23 | #tle: tle.cpp 24 | # g++ tle.cpp -static -o tle 25 | #1003re: 1003re.cpp 26 | # g++ 1003re.cpp -static -o 1003re 27 | #1500ac: 1500ac.cpp 28 | # g++ 1500ac.cpp -static -o 1500ac 29 | #2000mle: 2000mle.cpp 30 | # g++ 2000mle.cpp -static -o 2000mle 31 | #block: block.c 32 | # gcc block.c -static -o block 33 | futex_test: futex_test.cpp 34 | g++ futex_test.cpp -lrt --static -o futex_test 35 | 36 | test: scaffold helloworld re_seg re_div0 mle_dyn mle_static 1003re 1500ac 2000mle tle block futex_test 37 | ./scaffold 38 | 39 | -------------------------------------------------------------------------------- /daemon/libsablebox/mle_dyn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/mle_dyn -------------------------------------------------------------------------------- /daemon/libsablebox/mle_dyn.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | 4 | { 5 | for(;;); 6 | int *p = new int[5000*5000]; 7 | p[2500] = 1; 8 | delete[] p; 9 | return 0; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /daemon/libsablebox/mle_static: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/mle_static -------------------------------------------------------------------------------- /daemon/libsablebox/mle_static.cpp: -------------------------------------------------------------------------------- 1 | int a[5000][5000]; 2 | 3 | int main() 4 | { 5 | 6 | a[2500][2500] = 0; 7 | return 0 ; 8 | } 9 | -------------------------------------------------------------------------------- /daemon/libsablebox/re_div0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/re_div0 -------------------------------------------------------------------------------- /daemon/libsablebox/re_div0.cpp: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int a = 0; 4 | int b = 5/a; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /daemon/libsablebox/re_seg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/re_seg -------------------------------------------------------------------------------- /daemon/libsablebox/re_seg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int main() 5 | { 6 | char* p = NULL; 7 | *p = 'a'; 8 | cout< 3 | #include 4 | 5 | #define CASE(STA)\ 6 | case STA: \ 7 | puts( #STA ); 8 | 9 | #define deftest(name, pathname, fin, fout) \ 10 | int test_##name () \ 11 | {\ 12 | if(fork() == 0){\ 13 | struct sablebox sbox;\ 14 | struct profile ret;\ 15 | puts("------------" #name "-------------------\n");\ 16 | sable_init(&sbox, #pathname, NULL, #fin, #fout, 1000, 1024*50, 0);\ 17 | ret = sable_run(&sbox);\ 18 | switch(ret.status){\ 19 | CASE(PROF_SUCCESS)\ 20 | break;\ 21 | CASE(PROF_NOTSET)\ 22 | break;\ 23 | CASE(PROF_RUNTIME_ERROR)\ 24 | printf("%s\n", ret.info);\ 25 | break;\ 26 | CASE(PROF_TIME_LIMIT_EXCEED)\ 27 | break;\ 28 | CASE(PROF_MEMORY_LIMIT_EXCEED)\ 29 | break;\ 30 | CASE(PROF_SYSTEM_ERROR)\ 31 | break;\ 32 | }\ 33 | printf("Memory: %ld\nTime: %ld\n", ret.memory, ret.time);\ 34 | puts("");\ 35 | puts("----------------------------------------\n");\ 36 | exit(0);\ 37 | }else{\ 38 | wait(0);\ 39 | }\ 40 | } 41 | deftest(re_seg, ./re_seg, t.in, t.out) 42 | deftest(re_div0, ./re_div0, t.in, t.out) 43 | deftest(helloworld, ./helloworld, t.in, t.out) 44 | deftest(mle_static, ./mle_static, t.in, t.out) 45 | deftest(mle_dyn, ./mle_dyn, t.in, t.out) 46 | deftest(1003re, ./1003re, 1003.in, 1003.out) 47 | deftest(1500ac, ./1500ac, 1500.in, 1500.out) 48 | deftest(2000mle, ./2000mle, 2000.in, 2000.out) 49 | deftest(tle, ./tle, t.in, t.out) 50 | deftest(block, ./block, t.in, t.out) 51 | deftest(futex_test, ./futex_test, 3172.in, t.out) 52 | 53 | int main(int argc, char** argv) 54 | { 55 | test_tle(); 56 | test_helloworld(); 57 | test_re_div0(); 58 | test_re_seg(); 59 | test_mle_static(); 60 | test_mle_dyn(); 61 | test_1003re(); 62 | test_1500ac(); 63 | test_2000mle(); 64 | test_block(); 65 | test_futex_test(); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /daemon/libsablebox/scaffold.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/scaffold.o -------------------------------------------------------------------------------- /daemon/libsablebox/t.in: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /daemon/libsablebox/t.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/t.out -------------------------------------------------------------------------------- /daemon/libsablebox/t.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/t.txt -------------------------------------------------------------------------------- /daemon/libsablebox/tle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/libsablebox/tle -------------------------------------------------------------------------------- /daemon/libsablebox/tle.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | for(;;); 4 | } -------------------------------------------------------------------------------- /daemon/libsablebox/tle.cpp: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | while(1) 4 | ; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /daemon/monitor/oj_monitor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define JUDGE_USER_NAME "judge" 13 | #define DAEMON_PATH "/home/zhang/daemon" 14 | 15 | #define MY_SPECIAL_CODE 135 16 | 17 | struct passwd * user_info; 18 | uid_t judge_uid; 19 | pid_t cpid; 20 | int stopped; 21 | 22 | void signal_handle(int p) 23 | { 24 | kill(-cpid, SIGKILL); 25 | stopped = 1; 26 | } 27 | int main(int argc, char *argv[]) 28 | { 29 | if(0 != getuid()) { 30 | puts("getuid() != 0"); 31 | exit(EXIT_FAILURE); 32 | } 33 | if(!(user_info = getpwnam(JUDGE_USER_NAME))) { 34 | puts("Cannot find judge user"); 35 | exit(EXIT_FAILURE); 36 | } 37 | judge_uid = user_info->pw_uid; 38 | 39 | if(0 == fork()) { 40 | int fd; 41 | fd = open("/var/lock/ojdaemon.lock", O_WRONLY|O_CREAT); 42 | if(fd==-1 || flock(fd, LOCK_EX|LOCK_NB)) { 43 | puts("Cannot get lock"); 44 | exit(EXIT_FAILURE); 45 | } 46 | 47 | if(-1 == setsid()) { 48 | perror("setsid"); 49 | exit(EXIT_FAILURE); 50 | } 51 | if(SIG_ERR == signal(SIGTERM, signal_handle)) { 52 | perror("signal"); 53 | exit(EXIT_FAILURE); 54 | } 55 | 56 | openlog("bashu-onlinejudge", LOG_PERROR|LOG_PID, LOG_DAEMON); 57 | 58 | puts("Monitor started"); 59 | for(;;) { 60 | cpid = fork(); 61 | if (cpid == -1) { 62 | perror("fork"); 63 | syslog(LOG_ERR, "Can't fork"); 64 | exit(EXIT_FAILURE); 65 | } 66 | 67 | if (cpid == 0) { 68 | freopen("/var/log/onlinejudge.log", "a", stdout); 69 | 70 | if(-1 == setsid()) { 71 | perror("setsid"); 72 | _exit(MY_SPECIAL_CODE); 73 | } 74 | 75 | setuid(judge_uid); 76 | 77 | if(-1 == execl(DAEMON_PATH, DAEMON_PATH, NULL)) { 78 | perror("Cannot execute daemon"); 79 | _exit(MY_SPECIAL_CODE); 80 | } 81 | } else { 82 | pid_t w; 83 | int status; 84 | 85 | syslog(LOG_INFO, "Child PID is %ld\n", (long) cpid); 86 | syslog(LOG_INFO, "Set UID %ld\n", (long) judge_uid); 87 | 88 | w = waitpid(cpid, &status, WUNTRACED); 89 | if (w == -1) { 90 | syslog(LOG_ERR, "waitpid failed"); 91 | perror("waitpid"); 92 | exit(EXIT_FAILURE); 93 | } 94 | 95 | kill(-cpid, SIGKILL); //kill runner 96 | 97 | if (WIFEXITED(status)) { 98 | syslog(LOG_ERR, "exited, status=%d\n", WEXITSTATUS(status)); 99 | if(MY_SPECIAL_CODE == WEXITSTATUS(status)) 100 | break; 101 | } else if (WIFSIGNALED(status)) { 102 | syslog(LOG_ERR, "killed by signal %d\n", WTERMSIG(status)); 103 | } else if (WIFSTOPPED(status)) { 104 | int ign; 105 | waitpid(cpid, &ign, 0); //avoid zombie 106 | syslog(LOG_ERR, "stopped by signal %d\n", WSTOPSIG(status)); 107 | } else if (WIFCONTINUED(status)) { 108 | syslog(LOG_ERR, "continued\n"); 109 | } 110 | 111 | if(stopped) { 112 | syslog(LOG_INFO, "Monitor stopped...\n"); 113 | break; 114 | } 115 | syslog(LOG_INFO, "Sleep 2s...\n"); 116 | sleep(2); 117 | } 118 | } 119 | flock(fd, LOCK_UN); 120 | close(fd); 121 | } 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/libmysql.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/mysql/mysql_win/libmysql.a -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/my_alloc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | /* 17 | Data structures for mysys/my_alloc.c (root memory allocator) 18 | */ 19 | 20 | #ifndef _my_alloc_h 21 | #define _my_alloc_h 22 | 23 | #define ALLOC_MAX_BLOCK_TO_DROP 4096 24 | #define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef struct st_used_mem 31 | { /* struct for once_alloc (block) */ 32 | struct st_used_mem *next; /* Next block in use */ 33 | unsigned int left; /* memory left in block */ 34 | unsigned int size; /* size of block */ 35 | } USED_MEM; 36 | 37 | 38 | typedef struct st_mem_root 39 | { 40 | USED_MEM *free; /* blocks with free memory in it */ 41 | USED_MEM *used; /* blocks almost without free memory */ 42 | USED_MEM *pre_alloc; /* preallocated block */ 43 | /* if block have less memory it will be put in 'used' list */ 44 | size_t min_malloc; 45 | size_t block_size; /* initial block size */ 46 | unsigned int block_num; /* allocated blocks counter */ 47 | /* 48 | first free block in queue test counter (if it exceed 49 | MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list) 50 | */ 51 | unsigned int first_block_usage; 52 | 53 | void (*error_handler)(void); 54 | } MEM_ROOT; 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/my_attribute.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | /* 17 | Helper macros used for setting different __attributes__ 18 | on functions in a portable fashion 19 | */ 20 | 21 | #ifndef _my_attribute_h 22 | #define _my_attribute_h 23 | 24 | #if defined(__GNUC__) 25 | # ifndef GCC_VERSION 26 | # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 27 | # endif 28 | #endif 29 | 30 | /* 31 | Disable __attribute__() on gcc < 2.7, g++ < 3.4, and non-gcc compilers. 32 | Some forms of __attribute__ are actually supported in earlier versions of 33 | g++, but we just disable them all because we only use them to generate 34 | compilation warnings. 35 | */ 36 | #ifndef __attribute__ 37 | # if !defined(__GNUC__) 38 | # define __attribute__(A) 39 | # elif GCC_VERSION < 2008 40 | # define __attribute__(A) 41 | # elif defined(__cplusplus) && GCC_VERSION < 3004 42 | # define __attribute__(A) 43 | # endif 44 | #endif 45 | 46 | /* 47 | __attribute__((format(...))) is only supported in gcc >= 2.8 and g++ >= 3.4 48 | But that's already covered by the __attribute__ tests above, so this is 49 | just a convenience macro. 50 | */ 51 | #ifndef ATTRIBUTE_FORMAT 52 | # define ATTRIBUTE_FORMAT(style, m, n) __attribute__((format(style, m, n))) 53 | #endif 54 | 55 | /* 56 | 57 | __attribute__((format(...))) on a function pointer is not supported 58 | until gcc 3.1 59 | */ 60 | #ifndef ATTRIBUTE_FORMAT_FPTR 61 | # if (GCC_VERSION >= 3001) 62 | # define ATTRIBUTE_FORMAT_FPTR(style, m, n) ATTRIBUTE_FORMAT(style, m, n) 63 | # else 64 | # define ATTRIBUTE_FORMAT_FPTR(style, m, n) 65 | # endif /* GNUC >= 3.1 */ 66 | #endif 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/my_dir.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef MY_DIR_H 17 | #define MY_DIR_H 18 | 19 | #include "my_global.h" 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Defines for my_dir and my_stat */ 28 | 29 | #define MY_S_IFMT S_IFMT /* type of file */ 30 | #define MY_S_IFDIR S_IFDIR /* directory */ 31 | #define MY_S_IFCHR S_IFCHR /* character special */ 32 | #define MY_S_IFBLK S_IFBLK /* block special */ 33 | #define MY_S_IFREG S_IFREG /* regular */ 34 | #define MY_S_IFIFO S_IFIFO /* fifo */ 35 | #define MY_S_ISUID S_ISUID /* set user id on execution */ 36 | #define MY_S_ISGID S_ISGID /* set group id on execution */ 37 | #define MY_S_ISVTX S_ISVTX /* save swapped text even after use */ 38 | #define MY_S_IREAD S_IREAD /* read permission, owner */ 39 | #define MY_S_IWRITE S_IWRITE /* write permission, owner */ 40 | #define MY_S_IEXEC S_IEXEC /* execute/search permission, owner */ 41 | 42 | #define MY_S_ISDIR(m) (((m) & MY_S_IFMT) == MY_S_IFDIR) 43 | #define MY_S_ISCHR(m) (((m) & MY_S_IFMT) == MY_S_IFCHR) 44 | #define MY_S_ISBLK(m) (((m) & MY_S_IFMT) == MY_S_IFBLK) 45 | #define MY_S_ISREG(m) (((m) & MY_S_IFMT) == MY_S_IFREG) 46 | #define MY_S_ISFIFO(m) (((m) & MY_S_IFMT) == MY_S_IFIFO) 47 | 48 | #define MY_DONT_SORT 512 /* my_lib; Don't sort files */ 49 | #define MY_WANT_STAT 1024 /* my_lib; stat files */ 50 | 51 | /* typedefs for my_dir & my_stat */ 52 | 53 | #ifdef USE_MY_STAT_STRUCT 54 | 55 | typedef struct my_stat 56 | { 57 | dev_t st_dev; /* major & minor device numbers */ 58 | ino_t st_ino; /* inode number */ 59 | ushort st_mode; /* file permissons (& suid sgid .. bits) */ 60 | short st_nlink; /* number of links to file */ 61 | ushort st_uid; /* user id */ 62 | ushort st_gid; /* group id */ 63 | dev_t st_rdev; /* more major & minor device numbers (???) */ 64 | off_t st_size; /* size of file */ 65 | time_t st_atime; /* time for last read */ 66 | time_t st_mtime; /* time for last contens modify */ 67 | time_t st_ctime; /* time for last inode or contents modify */ 68 | } MY_STAT; 69 | 70 | #else 71 | 72 | #if(_MSC_VER) 73 | #define MY_STAT struct _stati64 /* 64 bit file size */ 74 | #else 75 | #define MY_STAT struct stat /* Orginal struct have what we need */ 76 | #endif 77 | 78 | #endif /* USE_MY_STAT_STRUCT */ 79 | 80 | /* Struct describing one file returned from my_dir */ 81 | typedef struct fileinfo 82 | { 83 | char *name; 84 | MY_STAT *mystat; 85 | } FILEINFO; 86 | 87 | typedef struct st_my_dir /* Struct returned from my_dir */ 88 | { 89 | /* 90 | These members are just copies of parts of DYNAMIC_ARRAY structure, 91 | which is allocated right after the end of MY_DIR structure (MEM_ROOT 92 | for storing names is also resides there). We've left them here because 93 | we don't want to change code that uses my_dir. 94 | */ 95 | struct fileinfo *dir_entry; 96 | uint number_off_files; 97 | } MY_DIR; 98 | 99 | extern MY_DIR *my_dir(const char *path,myf MyFlags); 100 | extern void my_dirend(MY_DIR *buffer); 101 | extern MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags); 102 | extern int my_fstat(int filenr, MY_STAT *stat_area, myf MyFlags); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* MY_DIR_H */ 109 | 110 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/my_list.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef _list_h_ 17 | #define _list_h_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct st_list { 24 | struct st_list *prev,*next; 25 | void *data; 26 | } LIST; 27 | 28 | typedef int (*list_walk_action)(void *,void *); 29 | 30 | extern LIST *list_add(LIST *root,LIST *element); 31 | extern LIST *list_delete(LIST *root,LIST *element); 32 | extern LIST *list_cons(void *data,LIST *root); 33 | extern LIST *list_reverse(LIST *root); 34 | extern void list_free(LIST *root,unsigned int free_data); 35 | extern unsigned int list_length(LIST *); 36 | extern int list_walk(LIST *,list_walk_action action,unsigned char * argument); 37 | 38 | #define list_rest(a) ((a)->next) 39 | #define list_push(a,b) (a)=list_cons((b),(a)) 40 | #define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old); my_free(old); } 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/my_net.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | /* 17 | This file is also used to make handling of sockets and ioctl() 18 | portable accross systems. 19 | 20 | */ 21 | 22 | #ifndef _my_net_h 23 | #define _my_net_h 24 | 25 | #include "my_global.h" /* C_MODE_START, C_MODE_END */ 26 | 27 | C_MODE_START 28 | 29 | #include 30 | #ifdef HAVE_SYS_SOCKET_H 31 | #include 32 | #endif 33 | #ifdef HAVE_NETINET_IN_H 34 | #include 35 | #endif 36 | #ifdef HAVE_ARPA_INET_H 37 | #include 38 | #endif 39 | #ifdef HAVE_POLL 40 | #include 41 | #endif 42 | #ifdef HAVE_SYS_IOCTL_H 43 | #include 44 | #endif 45 | 46 | #if !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) 47 | #include 48 | #include 49 | #include 50 | #if !defined(alpha_linux_port) 51 | #include 52 | #endif 53 | #endif 54 | 55 | #if defined(__WIN__) 56 | #define O_NONBLOCK 1 /* For emulation of fcntl() */ 57 | 58 | /* 59 | SHUT_RDWR is called SD_BOTH in windows and 60 | is defined to 2 in winsock2.h 61 | #define SD_BOTH 0x02 62 | */ 63 | #define SHUT_RDWR 0x02 64 | 65 | #endif 66 | 67 | /* 68 | On OSes which don't have the in_addr_t, we guess that using uint32 is the best 69 | possible choice. We guess this from the fact that on HP-UX64bit & FreeBSD64bit 70 | & Solaris64bit, in_addr_t is equivalent to uint32. And on Linux32bit too. 71 | */ 72 | #ifndef HAVE_IN_ADDR_T 73 | #define in_addr_t uint32 74 | #endif 75 | 76 | 77 | C_MODE_END 78 | #endif 79 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/my_xml.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2000 MySQL AB 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | 17 | #ifndef _my_xml_h 18 | #define _my_xml_h 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | #define MY_XML_OK 0 26 | #define MY_XML_ERROR 1 27 | 28 | /* 29 | A flag whether to use absolute tag names in call-back functions, 30 | like "a", "a.b" and "a.b.c" (used in character set file parser), 31 | or relative names like "a", "b" and "c". 32 | */ 33 | #define MY_XML_FLAG_RELATIVE_NAMES 1 34 | 35 | /* 36 | A flag whether to skip normilization of text values before calling 37 | call-back functions: i.e. skip leading/trailing spaces, 38 | \r, \n, \t characters. 39 | */ 40 | #define MY_XML_FLAG_SKIP_TEXT_NORMALIZATION 2 41 | 42 | enum my_xml_node_type 43 | { 44 | MY_XML_NODE_TAG, /* can have TAG, ATTR and TEXT children */ 45 | MY_XML_NODE_ATTR, /* can have TEXT children */ 46 | MY_XML_NODE_TEXT /* cannot have children */ 47 | }; 48 | 49 | typedef struct xml_stack_st 50 | { 51 | int flags; 52 | enum my_xml_node_type current_node_type; 53 | char errstr[128]; 54 | char attr[128]; 55 | char *attrend; 56 | const char *beg; 57 | const char *cur; 58 | const char *end; 59 | void *user_data; 60 | int (*enter)(struct xml_stack_st *st,const char *val, size_t len); 61 | int (*value)(struct xml_stack_st *st,const char *val, size_t len); 62 | int (*leave_xml)(struct xml_stack_st *st,const char *val, size_t len); 63 | } MY_XML_PARSER; 64 | 65 | void my_xml_parser_create(MY_XML_PARSER *st); 66 | void my_xml_parser_free(MY_XML_PARSER *st); 67 | int my_xml_parse(MY_XML_PARSER *st,const char *str, size_t len); 68 | 69 | void my_xml_set_value_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, 70 | const char *, 71 | size_t len)); 72 | void my_xml_set_enter_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, 73 | const char *, 74 | size_t len)); 75 | void my_xml_set_leave_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, 76 | const char *, 77 | size_t len)); 78 | void my_xml_set_user_data(MY_XML_PARSER *st, void *); 79 | 80 | size_t my_xml_error_pos(MY_XML_PARSER *st); 81 | uint my_xml_error_lineno(MY_XML_PARSER *st); 82 | 83 | const char *my_xml_error_string(MY_XML_PARSER *st); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* _my_xml_h */ 90 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/innodb_priv.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | #ifndef INNODB_PRIV_INCLUDED 17 | #define INNODB_PRIV_INCLUDED 18 | 19 | /** @file Declaring server-internal functions that are used by InnoDB. */ 20 | 21 | #include 22 | 23 | class THD; 24 | 25 | int get_quote_char_for_identifier(THD *thd, const char *name, uint length); 26 | bool schema_table_store_record(THD *thd, TABLE *table); 27 | void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); 28 | bool check_global_access(THD *thd, ulong want_access); 29 | uint strconvert(CHARSET_INFO *from_cs, const char *from, 30 | CHARSET_INFO *to_cs, char *to, uint to_length, 31 | uint *errors); 32 | void sql_print_error(const char *format, ...); 33 | 34 | 35 | 36 | #endif /* INNODB_PRIV_INCLUDED */ 37 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/plugin_auth.h: -------------------------------------------------------------------------------- 1 | #ifndef MYSQL_PLUGIN_AUTH_INCLUDED 2 | /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; version 2 of the License. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 16 | 17 | /** 18 | @file 19 | 20 | Authentication Plugin API. 21 | 22 | This file defines the API for server authentication plugins. 23 | */ 24 | 25 | #define MYSQL_PLUGIN_AUTH_INCLUDED 26 | 27 | #include 28 | 29 | #define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0100 30 | 31 | #include 32 | 33 | /* defines for MYSQL_SERVER_AUTH_INFO.password_used */ 34 | 35 | #define PASSWORD_USED_NO 0 36 | #define PASSWORD_USED_YES 1 37 | #define PASSWORD_USED_NO_MENTION 2 38 | 39 | 40 | /** 41 | Provides server plugin access to authentication information 42 | */ 43 | typedef struct st_mysql_server_auth_info 44 | { 45 | /** 46 | User name as sent by the client and shown in USER(). 47 | NULL if the client packet with the user name was not received yet. 48 | */ 49 | char *user_name; 50 | 51 | /** 52 | Length of user_name 53 | */ 54 | unsigned int user_name_length; 55 | 56 | /** 57 | A corresponding column value from the mysql.user table for the 58 | matching account name 59 | */ 60 | const char *auth_string; 61 | 62 | /** 63 | Length of auth_string 64 | */ 65 | unsigned long auth_string_length; 66 | 67 | /** 68 | Matching account name as found in the mysql.user table. 69 | A plugin can override it with another name that will be 70 | used by MySQL for authorization, and shown in CURRENT_USER() 71 | */ 72 | char authenticated_as[MYSQL_USERNAME_LENGTH+1]; 73 | 74 | 75 | /** 76 | The unique user name that was used by the plugin to authenticate. 77 | Plugins should put null-terminated UTF-8 here. 78 | Available through the @@EXTERNAL_USER variable. 79 | */ 80 | char external_user[512]; 81 | 82 | /** 83 | This only affects the "Authentication failed. Password used: %s" 84 | error message. has the following values : 85 | 0 : %s will be NO. 86 | 1 : %s will be YES. 87 | 2 : there will be no %s. 88 | Set it as appropriate or ignore at will. 89 | */ 90 | int password_used; 91 | 92 | /** 93 | Set to the name of the connected client host, if it can be resolved, 94 | or to its IP address otherwise. 95 | */ 96 | const char *host_or_ip; 97 | 98 | /** 99 | Length of host_or_ip 100 | */ 101 | unsigned int host_or_ip_length; 102 | 103 | } MYSQL_SERVER_AUTH_INFO; 104 | 105 | /** 106 | Server authentication plugin descriptor 107 | */ 108 | struct st_mysql_auth 109 | { 110 | int interface_version; /** version plugin uses */ 111 | /** 112 | A plugin that a client must use for authentication with this server 113 | plugin. Can be NULL to mean "any plugin". 114 | */ 115 | const char *client_auth_plugin; 116 | /** 117 | Function provided by the plugin which should perform authentication (using 118 | the vio functions if necessary) and return 0 if successful. The plugin can 119 | also fill the info.authenticated_as field if a different username should be 120 | used for authorization. 121 | */ 122 | int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info); 123 | }; 124 | #endif 125 | 126 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/psi/psi_abi_v1.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software Foundation, 14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 15 | 16 | /** 17 | @file mysql/psi/psi_abi_v1.h 18 | ABI check for mysql/psi/psi.h, when using PSI_VERSION_1. 19 | This file is only used to automate detection of changes between versions. 20 | Do not include this file, include mysql/psi/psi.h instead. 21 | */ 22 | #define USE_PSI_1 23 | #define HAVE_PSI_INTERFACE 24 | #define _global_h 25 | #include "mysql/psi/psi.h" 26 | 27 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/psi/psi_abi_v2.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software Foundation, 14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 15 | 16 | /** 17 | @file mysql/psi/psi_abi_v1.h 18 | ABI check for mysql/psi/psi.h, when using PSI_VERSION_2. 19 | This file is only used to automate detection of changes between versions. 20 | Do not include this file, include mysql/psi/psi.h instead. 21 | */ 22 | #define USE_PSI_2 23 | #define HAVE_PSI_INTERFACE 24 | #define _global_h 25 | #include "mysql/psi/psi.h" 26 | 27 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/service_my_snprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef MYSQL_SERVICE_MY_SNPRINTF_INCLUDED 2 | /* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; version 2 of the License. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 16 | 17 | /** 18 | @file 19 | my_snprintf service 20 | 21 | Portable and limited vsnprintf() implementation. 22 | 23 | This is a portable, limited vsnprintf() implementation, with some 24 | extra features. "Portable" means that it'll produce identical result 25 | on all platforms (for example, on Windows and Linux system printf %e 26 | formats the exponent differently, on different systems %p either 27 | prints leading 0x or not, %s may accept null pointer or crash on 28 | it). "Limited" means that it does not support all the C89 features. 29 | But it supports few extensions, not in any standard. 30 | 31 | my_vsnprintf(to, n, fmt, ap) 32 | 33 | @param[out] to A buffer to store the result in 34 | @param[in] n Store up to n-1 characters, followed by an end 0 35 | @param[in] fmt printf-like format string 36 | @param[in] ap Arguments 37 | 38 | @return a number of bytes written to a buffer *excluding* terminating '\0' 39 | 40 | @post 41 | The syntax of a format string is generally the same: 42 | % 43 | where everithing but the format is optional. 44 | 45 | Three one-character flags are recognized: 46 | '0' has the standard zero-padding semantics; 47 | '-' is parsed, but silently ignored; 48 | '`' (backtick) is only supported for strings (%s) and means that the 49 | string will be quoted according to MySQL identifier quoting rules. 50 | 51 | Both and can be specified as numbers or '*'. 52 | 53 | can be 'l', 'll', or 'z'. 54 | 55 | Supported formats are 's' (null pointer is accepted, printed as 56 | "(null)"), 'b' (extension, see below), 'c', 'd', 'i', 'u', 'x', 'o', 57 | 'X', 'p' (works as 0x%x). 58 | 59 | Standard syntax for positional arguments $n is supported. 60 | 61 | Extensions: 62 | 63 | Flag '`' (backtick): see above. 64 | 65 | Format 'b': binary buffer, prints exactly bytes from the 66 | argument, without stopping at '\0'. 67 | */ 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | #ifndef MYSQL_ABI_CHECK 74 | #include 75 | #include 76 | #endif 77 | 78 | extern struct my_snprintf_service_st { 79 | size_t (*my_snprintf_type)(char*, size_t, const char*, ...); 80 | size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); 81 | } *my_snprintf_service; 82 | 83 | #ifdef MYSQL_DYNAMIC_PLUGIN 84 | 85 | #define my_vsnprintf my_snprintf_service->my_vsnprintf_type 86 | #define my_snprintf my_snprintf_service->my_snprintf_type 87 | 88 | #else 89 | 90 | size_t my_snprintf(char* to, size_t n, const char* fmt, ...); 91 | size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); 92 | 93 | #endif 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #define MYSQL_SERVICE_MY_SNPRINTF_INCLUDED 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/service_thd_wait.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef MYSQL_SERVICE_THD_WAIT_INCLUDED 17 | #define MYSQL_SERVICE_THD_WAIT_INCLUDED 18 | 19 | /** 20 | @file include/mysql/service_thd_wait.h 21 | This service provides functions for plugins and storage engines to report 22 | when they are going to sleep/stall. 23 | 24 | SYNOPSIS 25 | thd_wait_begin() - call just before a wait begins 26 | thd Thread object 27 | Use NULL if the thd is NOT known. 28 | wait_type Type of wait 29 | 1 -- short wait (e.g. for mutex) 30 | 2 -- medium wait (e.g. for disk io) 31 | 3 -- large wait (e.g. for locked row/table) 32 | NOTES 33 | This is used by the threadpool to have better knowledge of which 34 | threads that currently are actively running on CPUs. When a thread 35 | reports that it's going to sleep/stall, the threadpool scheduler is 36 | free to start another thread in the pool most likely. The expected wait 37 | time is simply an indication of how long the wait is expected to 38 | become, the real wait time could be very different. 39 | 40 | thd_wait_end() called immediately after the wait is complete 41 | 42 | thd_wait_end() MUST be called if thd_wait_begin() was called. 43 | 44 | Using thd_wait_...() service is optional but recommended. Using it will 45 | improve performance as the thread pool will be more active at managing the 46 | thread workload. 47 | */ 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | /* 54 | One should only report wait events that could potentially block for a 55 | long time. A mutex wait is too short of an event to report. The reason 56 | is that an event which is reported leads to a new thread starts 57 | executing a query and this has a negative impact of usage of CPU caches 58 | and thus the expected gain of starting a new thread must be higher than 59 | the expected cost of lost performance due to starting a new thread. 60 | 61 | Good examples of events that should be reported are waiting for row locks 62 | that could easily be for many milliseconds or even seconds and the same 63 | holds true for global read locks, table locks and other meta data locks. 64 | Another event of interest is going to sleep for an extended time. 65 | */ 66 | typedef enum _thd_wait_type_e { 67 | THD_WAIT_SLEEP= 1, 68 | THD_WAIT_DISKIO= 2, 69 | THD_WAIT_ROW_LOCK= 3, 70 | THD_WAIT_GLOBAL_LOCK= 4, 71 | THD_WAIT_META_DATA_LOCK= 5, 72 | THD_WAIT_TABLE_LOCK= 6, 73 | THD_WAIT_USER_LOCK= 7, 74 | THD_WAIT_BINLOG= 8, 75 | THD_WAIT_GROUP_COMMIT= 9, 76 | THD_WAIT_SYNC= 10, 77 | THD_WAIT_LAST= 11 78 | } thd_wait_type; 79 | 80 | extern struct thd_wait_service_st { 81 | void (*thd_wait_begin_func)(MYSQL_THD, int); 82 | void (*thd_wait_end_func)(MYSQL_THD); 83 | } *thd_wait_service; 84 | 85 | #ifdef MYSQL_DYNAMIC_PLUGIN 86 | 87 | #define thd_wait_begin(_THD, _WAIT_TYPE) \ 88 | thd_wait_service->thd_wait_begin_func(_THD, _WAIT_TYPE) 89 | #define thd_wait_end(_THD) thd_wait_service->thd_wait_end_func(_THD) 90 | 91 | #else 92 | 93 | void thd_wait_begin(MYSQL_THD thd, int wait_type); 94 | void thd_wait_end(MYSQL_THD thd); 95 | 96 | #endif 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/service_thread_scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; version 2 of the License. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 | */ 17 | 18 | #ifndef SERVICE_THREAD_SCHEDULER_INCLUDED 19 | #define SERVICE_THREAD_SCHEDULER_INCLUDED 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | struct scheduler_functions; 26 | 27 | extern struct my_thread_scheduler_service { 28 | int (*set)(struct scheduler_functions *scheduler); 29 | int (*reset)(); 30 | } *my_thread_scheduler_service; 31 | 32 | #ifdef MYSQL_DYNAMIC_PLUGIN 33 | 34 | #define my_thread_scheduler_set(F) my_thread_scheduler_service->set((F)) 35 | #define my_thread_scheduler_reset() my_thread_scheduler_service->reset() 36 | 37 | #else 38 | 39 | /** 40 | Set the thread scheduler to use for the server. 41 | 42 | @param scheduler Pointer to scheduler callbacks to use. 43 | @retval 0 Scheduler installed correctly. 44 | @retval 1 Invalid value (NULL) used for scheduler. 45 | */ 46 | int my_thread_scheduler_set(struct scheduler_functions *scheduler); 47 | 48 | /** 49 | Restore the previous thread scheduler. 50 | 51 | @note If no thread scheduler was installed previously with 52 | thd_set_thread_scheduler, this function will report an error. 53 | 54 | @retval 0 Scheduler installed correctly. 55 | @retval 1 No scheduler installed. 56 | */ 57 | int my_thread_scheduler_reset(); 58 | 59 | #endif 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* SERVICE_THREAD_SCHEDULER_INCLUDED */ 66 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql/services.h: -------------------------------------------------------------------------------- 1 | #ifndef MYSQL_SERVICES_INCLUDED 2 | /* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; version 2 of the License. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #define MYSQL_SERVICES_INCLUDED 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql_embed.h: -------------------------------------------------------------------------------- 1 | #ifndef MYSQL_EMBED_INCLUDED 2 | #define MYSQL_EMBED_INCLUDED 3 | 4 | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; version 2 of the License. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 18 | 19 | /* Defines that are unique to the embedded version of MySQL */ 20 | 21 | #ifdef EMBEDDED_LIBRARY 22 | 23 | /* Things we don't need in the embedded version of MySQL */ 24 | /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */ 25 | 26 | #undef HAVE_DLOPEN /* No udf functions */ 27 | #undef HAVE_SMEM /* No shared memory */ 28 | 29 | #endif /* EMBEDDED_LIBRARY */ 30 | #endif /* MYSQL_EMBED_INCLUDED */ 31 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql_time.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2004 MySQL AB 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | #ifndef _mysql_time_h_ 17 | #define _mysql_time_h_ 18 | 19 | /* 20 | Time declarations shared between the server and client API: 21 | you should not add anything to this header unless it's used 22 | (and hence should be visible) in mysql.h. 23 | If you're looking for a place to add new time-related declaration, 24 | it's most likely my_time.h. See also "C API Handling of Date 25 | and Time Values" chapter in documentation. 26 | */ 27 | 28 | enum enum_mysql_timestamp_type 29 | { 30 | MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, 31 | MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 32 | }; 33 | 34 | 35 | /* 36 | Structure which is used to represent datetime values inside MySQL. 37 | 38 | We assume that values in this structure are normalized, i.e. year <= 9999, 39 | month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions 40 | in server such as my_system_gmt_sec() or make_time() family of functions 41 | rely on this (actually now usage of make_*() family relies on a bit weaker 42 | restriction). Also functions that produce MYSQL_TIME as result ensure this. 43 | There is one exception to this rule though if this structure holds time 44 | value (time_type == MYSQL_TIMESTAMP_TIME) days and hour member can hold 45 | bigger values. 46 | */ 47 | typedef struct st_mysql_time 48 | { 49 | unsigned int year, month, day, hour, minute, second; 50 | unsigned long second_part; 51 | my_bool neg; 52 | enum enum_mysql_timestamp_type time_type; 53 | } MYSQL_TIME; 54 | 55 | #endif /* _mysql_time_h_ */ 56 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/mysql_version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Abandoned 1996, 1999, 2001 MySQL AB 2 | This file is public domain and comes with NO WARRANTY of any kind */ 3 | 4 | /* Version numbers for protocol & mysqld */ 5 | 6 | #ifndef _mysql_version_h 7 | #define _mysql_version_h 8 | #ifdef _CUSTOMCONFIG_ 9 | #include 10 | #else 11 | #define PROTOCOL_VERSION 10 12 | #define MYSQL_SERVER_VERSION "5.5.22" 13 | #define MYSQL_BASE_VERSION "mysqld-5.5" 14 | #define MYSQL_SERVER_SUFFIX_DEF "" 15 | #define FRM_VER 6 16 | #define MYSQL_VERSION_ID 50522 17 | #define MYSQL_PORT 3306 18 | #define MYSQL_PORT_DEFAULT 0 19 | #define MYSQL_UNIX_ADDR "/tmp/mysql.sock" 20 | #define MYSQL_CONFIG_NAME "my" 21 | #define MYSQL_COMPILATION_COMMENT "MySQL Community Server (GPL)" 22 | 23 | /* mysqld compile time options */ 24 | #endif /* _CUSTOMCONFIG_ */ 25 | 26 | #ifndef LICENSE 27 | #define LICENSE GPL 28 | #endif /* LICENSE */ 29 | 30 | #endif /* _mysql_version_h */ 31 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/sslopt-case.h: -------------------------------------------------------------------------------- 1 | #ifndef SSLOPT_CASE_INCLUDED 2 | #define SSLOPT_CASE_INCLUDED 3 | 4 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; version 2 of the License. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 18 | 19 | #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) 20 | case OPT_SSL_KEY: 21 | case OPT_SSL_CERT: 22 | case OPT_SSL_CA: 23 | case OPT_SSL_CAPATH: 24 | case OPT_SSL_CIPHER: 25 | /* 26 | Enable use of SSL if we are using any ssl option 27 | One can disable SSL later by using --skip-ssl or --ssl=0 28 | */ 29 | opt_use_ssl= 1; 30 | break; 31 | #endif 32 | #endif /* SSLOPT_CASE_INCLUDED */ 33 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/sslopt-longopts.h: -------------------------------------------------------------------------------- 1 | #ifndef SSLOPT_LONGOPTS_INCLUDED 2 | #define SSLOPT_LONGOPTS_INCLUDED 3 | 4 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; version 2 of the License. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 18 | 19 | #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) 20 | 21 | {"ssl", OPT_SSL_SSL, 22 | "Enable SSL for connection (automatically enabled with other flags).", 23 | &opt_use_ssl, &opt_use_ssl, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, 24 | {"ssl-ca", OPT_SSL_CA, 25 | "CA file in PEM format (check OpenSSL docs, implies --ssl).", 26 | &opt_ssl_ca, &opt_ssl_ca, 0, GET_STR, REQUIRED_ARG, 27 | 0, 0, 0, 0, 0, 0}, 28 | {"ssl-capath", OPT_SSL_CAPATH, 29 | "CA directory (check OpenSSL docs, implies --ssl).", 30 | &opt_ssl_capath, &opt_ssl_capath, 0, GET_STR, REQUIRED_ARG, 31 | 0, 0, 0, 0, 0, 0}, 32 | {"ssl-cert", OPT_SSL_CERT, "X509 cert in PEM format (implies --ssl).", 33 | &opt_ssl_cert, &opt_ssl_cert, 0, GET_STR, REQUIRED_ARG, 34 | 0, 0, 0, 0, 0, 0}, 35 | {"ssl-cipher", OPT_SSL_CIPHER, "SSL cipher to use (implies --ssl).", 36 | &opt_ssl_cipher, &opt_ssl_cipher, 0, GET_STR, REQUIRED_ARG, 37 | 0, 0, 0, 0, 0, 0}, 38 | {"ssl-key", OPT_SSL_KEY, "X509 key in PEM format (implies --ssl).", 39 | &opt_ssl_key, &opt_ssl_key, 0, GET_STR, REQUIRED_ARG, 40 | 0, 0, 0, 0, 0, 0}, 41 | #ifdef MYSQL_CLIENT 42 | {"ssl-verify-server-cert", OPT_SSL_VERIFY_SERVER_CERT, 43 | "Verify server's \"Common Name\" in its cert against hostname used " 44 | "when connecting. This option is disabled by default.", 45 | &opt_ssl_verify_server_cert, &opt_ssl_verify_server_cert, 46 | 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, 47 | #endif 48 | #endif /* HAVE_OPENSSL */ 49 | #endif /* SSLOPT_LONGOPTS_INCLUDED */ 50 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/sslopt-vars.h: -------------------------------------------------------------------------------- 1 | #ifndef SSLOPT_VARS_INCLUDED 2 | #define SSLOPT_VARS_INCLUDED 3 | 4 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; version 2 of the License. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 18 | 19 | #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) 20 | #ifdef SSL_VARS_NOT_STATIC 21 | #define SSL_STATIC 22 | #else 23 | #define SSL_STATIC static 24 | #endif 25 | SSL_STATIC my_bool opt_use_ssl = 0; 26 | SSL_STATIC char *opt_ssl_ca = 0; 27 | SSL_STATIC char *opt_ssl_capath = 0; 28 | SSL_STATIC char *opt_ssl_cert = 0; 29 | SSL_STATIC char *opt_ssl_cipher = 0; 30 | SSL_STATIC char *opt_ssl_key = 0; 31 | #ifdef MYSQL_CLIENT 32 | SSL_STATIC my_bool opt_ssl_verify_server_cert= 0; 33 | #endif 34 | #endif 35 | #endif /* SSLOPT_VARS_INCLUDED */ 36 | -------------------------------------------------------------------------------- /daemon/mysql/mysql_win/typelib.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 15 | 16 | 17 | #ifndef _typelib_h 18 | #define _typelib_h 19 | 20 | #include "my_alloc.h" 21 | 22 | typedef struct st_typelib { /* Different types saved here */ 23 | unsigned int count; /* How many types */ 24 | const char *name; /* Name of typelib */ 25 | const char **type_names; 26 | unsigned int *type_lengths; 27 | } TYPELIB; 28 | 29 | extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); 30 | extern int find_type_or_exit(const char *x, TYPELIB *typelib, 31 | const char *option); 32 | #define FIND_TYPE_BASIC 0 33 | /** makes @c find_type() require the whole name, no prefix */ 34 | #define FIND_TYPE_NO_PREFIX (1 << 0) 35 | /** always implicitely on, so unused, but old code may pass it */ 36 | #define FIND_TYPE_NO_OVERWRITE (1 << 1) 37 | /** makes @c find_type() accept a number */ 38 | #define FIND_TYPE_ALLOW_NUMBER (1 << 2) 39 | /** makes @c find_type() treat ',' as terminator */ 40 | #define FIND_TYPE_COMMA_TERM (1 << 3) 41 | 42 | extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); 43 | extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); 44 | extern const char *get_type(TYPELIB *typelib,unsigned int nr); 45 | extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from); 46 | 47 | extern TYPELIB sql_protocol_typelib; 48 | 49 | my_ulonglong find_set_from_flags(const TYPELIB *lib, unsigned int default_name, 50 | my_ulonglong cur_set, my_ulonglong default_set, 51 | const char *str, unsigned int length, 52 | char **err_pos, unsigned int *err_len); 53 | 54 | #endif /* _typelib_h */ 55 | -------------------------------------------------------------------------------- /daemon/readconfig.cpp: -------------------------------------------------------------------------------- 1 | #include "INI1.26.h" // "feather-ini-parser" on googlecode 2 | #include "judge_daemon.h" 3 | #include "conf_items.h" 4 | #include //for MAXPATHLEN 5 | 6 | using std::string; 7 | 8 | #define MAXLANG 10 9 | 10 | int lang_extra_mem[MAXLANG]; 11 | bool lang_exist[MAXLANG]; 12 | string lang_ext[MAXLANG]; 13 | string lang_compiler[MAXLANG]; 14 | 15 | char DATABASE_HOST[64], DATABASE_USER[128], DATABASE_PASS[128], DATABASE_NAME[128]; 16 | char HTTP_BIND_IP[32]; 17 | uint16_t HTTP_BIND_PORT; 18 | 19 | char DataDir[MAXPATHLEN+16]; 20 | 21 | typedef INI ini_t; 22 | 23 | bool read_config() 24 | { 25 | ini_t ini("config.ini", false); 26 | if(!ini.Parse()) { 27 | applog("Error: Cannot open config.ini, Exit..."); 28 | exit(1); 29 | } 30 | 31 | ini.Select("system"); 32 | std::string tmp = ini.Get(std::string("datadir"), std::string("")); 33 | if(tmp==""){ 34 | applog("Error: We don't know your data directory."); 35 | return false; 36 | } 37 | strncpy(DataDir, tmp.c_str(), MAXPATHLEN); 38 | 39 | tmp = ini.Get(std::string("DATABASE_HOST"), std::string("localhost")); 40 | strncpy(DATABASE_HOST, tmp.c_str(), 62); 41 | 42 | tmp = ini.Get(std::string("DATABASE_USER"), std::string("root")); 43 | strncpy(DATABASE_USER, tmp.c_str(), 120); 44 | 45 | tmp = ini.Get(std::string("DATABASE_PASS"), std::string("")); 46 | strncpy(DATABASE_PASS, tmp.c_str(), 120); 47 | 48 | tmp = ini.Get(std::string("DATABASE_NAME"), std::string("bsoj")); 49 | strncpy(DATABASE_NAME, tmp.c_str(), 120); 50 | 51 | tmp = ini.Get(std::string("HTTP_BIND_IP"), std::string("0.0.0.0")); 52 | strncpy(HTTP_BIND_IP, tmp.c_str(), 30); 53 | 54 | HTTP_BIND_PORT = ini.Get("HTTP_BIND_PORT", 8881u); 55 | 56 | for(auto i = ini.sections.begin(); i != ini.sections.end(); ++i) { 57 | const string &lang = i->first; 58 | if(lang.find("lang") != 0) 59 | continue; 60 | int num = atoi(lang.c_str() + 4); 61 | if(!num || num > MAXLANG) { 62 | applog("Info: Language number is not correct."); 63 | return false; 64 | } 65 | num--; 66 | std::map &keys = *(i->second); 67 | if(keys.count(string("extra_mem"))) 68 | lang_extra_mem[num] = Convert(keys[string("extra_mem")]); 69 | else 70 | lang_extra_mem[num] = 0; 71 | 72 | if(keys.count(string("compiler"))) 73 | lang_compiler[num] = keys[string("compiler")]; 74 | else 75 | return false; 76 | 77 | if(keys.count(string("ext"))) 78 | lang_ext[num] = keys[string("ext")]; 79 | else 80 | return false; 81 | 82 | lang_exist[num] = true; 83 | } 84 | /* 85 | for(int i = 0; i < MAXLANG; i++) { 86 | if(lang_exist[i]) { 87 | printf("extra_mem: %d\n", lang_extra_mem[i]); 88 | printf("lang_compiler: %s\n", lang_compiler[i].c_str()); 89 | printf("ext: %s\n", lang_ext[i].c_str()); 90 | } 91 | } 92 | */ 93 | return true; 94 | } -------------------------------------------------------------------------------- /daemon/runner_linux.c: -------------------------------------------------------------------------------- 1 | #include "sablebox.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static struct scmask safe_syscall; 8 | 9 | static const int sc_safe[] = { 10 | #ifdef __x86_64__ 11 | 0, 1, 3, 5, 8, 9, 10, 11, 12, 13, 16, 19, 20, 21, 25, 63, 89, 97, 100, 158, 201, 231 12 | #else 13 | 3, 4, 6, 108, 19, 90, 125, 91, 45, 174, 54, 145, 146, 33, 163, 122, 85, 76, 43, 13, 252, 140, 192, 197, 224, 243 14 | #endif 15 | //read, write, close, fstat, lseek, mmap, mprotect, munmap, brk, rt_sigaction, ioctl, readv, writev, access, mremap, uname, readlink, getrlimit, times, arch_prctl, time, exit_group, _llseek, mmap2, fstat64, gettid, set_thread_area 16 | }; 17 | 18 | static void init_safe_syscall() 19 | { 20 | memset(&safe_syscall, 0, sizeof(struct scmask)); 21 | int i, len = sizeof(sc_safe) / sizeof(int); 22 | for(i=0; i 7 && strcmp(argv[6], "-spj")==0) { // to run spj validator 52 | int cnt = argc - 7, i; 53 | args = (char**)malloc((cnt + 2) * sizeof(char*)); 54 | args[0] = argv[1]; 55 | for(i = 7; i>10, &safe_syscall); 69 | ret = sable_run(&sbox); 70 | 71 | switch(ret.status){ 72 | case PROF_SUCCESS: 73 | state = 0; 74 | if(ret.exit_code != 0) { 75 | state = 5; 76 | ret.info = "Exit code is not zero"; 77 | } 78 | break; 79 | case PROF_NOTSET: 80 | sys_error = 1; 81 | break; 82 | case PROF_RUNTIME_ERROR: 83 | state = 5; 84 | break; 85 | case PROF_TIME_LIMIT_EXCEED: 86 | state = 2; 87 | break; 88 | case PROF_MEMORY_LIMIT_EXCEED: 89 | state = 3; 90 | break; 91 | case PROF_SYSTEM_ERROR: 92 | sys_error = 1; 93 | break; 94 | default: 95 | sys_error = 1; 96 | break; 97 | } 98 | if(sys_error) 99 | return 2; 100 | 101 | if(isspj) { 102 | if(ret.info) 103 | printf("spj: %s\n", ret.info); 104 | return (state == 0) ? 0 : 10+state;//whether validator exited successfully 105 | } 106 | run_info = fopen("run.info", "w"); 107 | if(!run_info) 108 | return 3; 109 | 110 | fprintf(run_info, "Time = %ld\n", ret.time); 111 | fprintf(run_info, "Memory = %ld\n", ret.memory); 112 | fprintf(run_info, "State = %d\n", state); 113 | if(ret.info) 114 | fprintf(run_info, "Info = %s\n", ret.info); 115 | fclose(run_info); 116 | 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /daemon/test/README: -------------------------------------------------------------------------------- 1 | This directory was created by YangZX in Nov.24, 2012 to fix a bug in validator.c 2 | -------------------------------------------------------------------------------- /daemon/test/validator_test/1817_data/1817/a1.in: -------------------------------------------------------------------------------- 1 | 13 2 | 23 3 | 44 4 | 45 5 | 29 6 | -------------------------------------------------------------------------------- /daemon/test/validator_test/1817_data/1817/a1.out: -------------------------------------------------------------------------------- 1 | 7639 2 | 101821927 3 | 106465954658531465 4 | 289841389106439413 5 | 35866550869 6 | -------------------------------------------------------------------------------- /daemon/test/validator_test/1817_data/1817/a2.in: -------------------------------------------------------------------------------- 1 | 10 2 | 20 3 | 30 4 | 40 5 | 50 6 | 49 7 | 48 8 | 47 9 | -------------------------------------------------------------------------------- /daemon/test/validator_test/1817_data/1817/a2.out: -------------------------------------------------------------------------------- 1 | 507 2 | 5622109 3 | 95991365288 4 | 1954002050661819 5 | 4262465330 6 | 16033495247557039074 7 | 5873225808361331954 8 | 2152814945971655556 9 | -------------------------------------------------------------------------------- /daemon/test/validator_test/filelines_test/blank.txt: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /daemon/test/validator_test/filelines_test/filelines: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/test/validator_test/filelines_test/filelines -------------------------------------------------------------------------------- /daemon/test/validator_test/filelines_test/filelines.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long filelines(FILE* stream) 5 | { 6 | fseek(stream, 0, SEEK_SET); 7 | int c, tmp = 0, sum = 0, non_empty = 0; 8 | while(c = getc(stream)){ 9 | if(c == EOF) 10 | break; 11 | if(c == '\n'){ 12 | tmp++; 13 | }else{ 14 | sum += tmp; 15 | tmp = 0; 16 | non_empty = 1; 17 | } 18 | } 19 | return sum + non_empty; 20 | } 21 | 22 | #define should(left, op, right) \ 23 | if(!(left op right)){ \ 24 | puts("Failed!!!" #left #op #right);\ 25 | printf("%s = %d, %s = %d\n\n", #left, left, #right, right); \ 26 | }else{\ 27 | puts("Passed!!!" #left #op #right);\ 28 | } 29 | 30 | void test_blank() 31 | { 32 | { 33 | system("echo \"\n\n\" > blank.txt"); 34 | FILE* fp = fopen("blank.txt", "r"); 35 | should(filelines(fp), ==, 0); 36 | } 37 | 38 | { 39 | system("echo \"\" > blank.txt"); 40 | FILE* fp = fopen("blank.txt", "r"); 41 | should(filelines(fp), ==, 0); 42 | } 43 | } 44 | 45 | void test_ordinary() 46 | { 47 | { 48 | system("echo \"123\" > blank.txt"); 49 | FILE* fp = fopen("blank.txt", "r"); 50 | should(filelines(fp), ==, 1); 51 | } 52 | { 53 | system("echo \"123\n123\n\n\n\" > blank.txt"); 54 | FILE* fp = fopen("blank.txt", "r"); 55 | should(filelines(fp), ==, 2); 56 | } 57 | { 58 | system("echo \"123\n\n123\" > blank.txt"); 59 | FILE* fp = fopen("blank.txt", "r"); 60 | should(filelines(fp), ==, 3); 61 | } 62 | { 63 | system("echo \"haha\" > blank.txt"); 64 | FILE* fp = fopen("blank.txt", "r"); 65 | should(filelines(fp), ==, 1); 66 | } 67 | } 68 | 69 | void test_invalid() 70 | { 71 | FILE* fp = fopen("blank.txt", "w"); 72 | fprintf(fp, "123"); 73 | fclose(fp); 74 | { 75 | FILE* fp = fopen("blank.txt", "r"); 76 | should(filelines(fp), ==, 1); 77 | } 78 | } 79 | 80 | int main() 81 | { 82 | test_blank(); 83 | test_ordinary(); 84 | test_invalid(); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /daemon/test/validator_test/filelines_test/makefile: -------------------------------------------------------------------------------- 1 | test:filelines 2 | ./filelines 3 | -------------------------------------------------------------------------------- /daemon/test/validator_test/makefile: -------------------------------------------------------------------------------- 1 | test_validator: validator.c test_validator.c 2 | gcc validator.c test_validator.c -o test_validator 3 | test: test_validator 4 | ./test_validator 5 | -------------------------------------------------------------------------------- /daemon/test/validator_test/std1.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 456 3 | 789 4 | -------------------------------------------------------------------------------- /daemon/test/validator_test/std2.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 123 3 | -------------------------------------------------------------------------------- /daemon/test/validator_test/std_identical.txt: -------------------------------------------------------------------------------- 1 | 123455 -------------------------------------------------------------------------------- /daemon/test/validator_test/std_invalid.txt: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /daemon/test/validator_test/std_multi.txt: -------------------------------------------------------------------------------- 1 | 507 2 | 5622109 3 | 95991365288 4 | 1954002050661819 5 | 4262465330 6 | 16033495247557039074 7 | 5873225808361331954 8 | 2152814945971655556 9 | -------------------------------------------------------------------------------- /daemon/test/validator_test/test_validator: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/test/validator_test/test_validator -------------------------------------------------------------------------------- /daemon/test/validator_test/test_validator.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define VAL_FUCKED (-1) 6 | #define VAL_IDENTICAL 0 7 | #define VAL_MISMATCH 1 8 | #define VAL_LONGER 2 9 | #define VAL_SHORTER 3 10 | 11 | struct validator_info validator(FILE* fstd, FILE* fuser); 12 | 13 | struct validator_info{ 14 | int ret; 15 | char* user_mismatch; 16 | char* std_mismatch; 17 | }; 18 | 19 | #define should(left, op, right) \ 20 | if(!(left op right)){ \ 21 | puts("Failed!!!" #left #op #right);\ 22 | printf("%s = %d, %s = %d\n\n", #left, left, #right, right); \ 23 | }else{\ 24 | puts("Passed!!!" #left #op #right);\ 25 | } 26 | 27 | void test_shorter() 28 | { 29 | /*user output is shorter than standart output.*/ 30 | FILE* fu = fopen("user1.txt", "r"); 31 | FILE* fs = fopen("std1.txt", "r"); 32 | struct validator_info info = validator(fs, fu); 33 | should(info.ret, ==, VAL_SHORTER); 34 | } 35 | 36 | void test_longer() 37 | { 38 | /*user output is shorter than longer output.*/ 39 | FILE* fu = fopen("user2.txt", "r"); 40 | FILE* fs = fopen("std2.txt", "r"); 41 | struct validator_info info = validator(fs, fu); 42 | should(info.ret, ==, VAL_LONGER); 43 | } 44 | 45 | void test_multi() 46 | { 47 | FILE* fu = fopen("user_multi.txt", "r"); 48 | FILE* fs = fopen("std_multi.txt", "r"); 49 | struct validator_info info = validator(fs, fu); 50 | should(info.ret, ==, VAL_SHORTER); 51 | } 52 | 53 | void test_indentical() 54 | { 55 | system("echo \"123456\n123\" > user_identical.txt"); 56 | system("echo \"123456\n123\" > std_identical.txt"); 57 | FILE* fu = fopen("user_identical.txt", "r"); 58 | FILE* fs = fopen("std_identical.txt", "r"); 59 | struct validator_info info = validator(fs, fu); 60 | should(info.ret, ==, VAL_IDENTICAL); 61 | } 62 | 63 | void test_invaliddata() 64 | { 65 | FILE* fu = fopen("user_invalid.txt", "w+"); 66 | FILE* fs = fopen("std_invalid.txt", "w+"); 67 | fprintf(fu, "123\n\n\n"); 68 | fprintf(fs, "123\n"); 69 | struct validator_info info = validator(fs, fu); 70 | should(info.ret, ==, VAL_IDENTICAL); 71 | } 72 | 73 | void test_singleline() 74 | { 75 | { 76 | FILE* fu = fopen("user_identical.txt", "w"); 77 | fprintf(fu, "\n"); 78 | fclose(fu); 79 | 80 | FILE* fs = fopen("std_identical.txt", "w"); 81 | fprintf(fs, "123455"); 82 | fclose(fs); 83 | } 84 | FILE* fu = fopen("user_identical.txt", "r"); 85 | FILE* fs = fopen("std_identical.txt", "r"); 86 | struct validator_info info = validator(fs, fu); 87 | should(info.ret, ==, VAL_SHORTER); 88 | } 89 | 90 | int main() 91 | { 92 | test_shorter(); 93 | test_longer(); 94 | test_multi(); 95 | test_indentical(); 96 | test_invaliddata(); 97 | test_singleline(); 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /daemon/test/validator_test/user.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 3 | -------------------------------------------------------------------------------- /daemon/test/validator_test/user1.txt: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /daemon/test/validator_test/user2.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 123 3 | 123 4 | -------------------------------------------------------------------------------- /daemon/test/validator_test/user_identical.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /daemon/test/validator_test/user_invalid.txt: -------------------------------------------------------------------------------- 1 | 123 2 | 3 | 4 | -------------------------------------------------------------------------------- /daemon/test/validator_test/user_multi.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/test/validator_test/user_multi.txt -------------------------------------------------------------------------------- /daemon/win32_ruc/win32_ruc/win32_ruc.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "win32_ruc", "win32_ruc.vcproj", "{FAF4AEE2-72DB-4010-BC68-2DED57619525}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "win32_run_compiler", "..\win32_run_compiler\win32_run_compiler.vcproj", "{549BB008-902C-4FF0-8191-E79D062F6476}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {FAF4AEE2-72DB-4010-BC68-2DED57619525}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {FAF4AEE2-72DB-4010-BC68-2DED57619525}.Debug|Win32.Build.0 = Debug|Win32 16 | {FAF4AEE2-72DB-4010-BC68-2DED57619525}.Release|Win32.ActiveCfg = Release|Win32 17 | {FAF4AEE2-72DB-4010-BC68-2DED57619525}.Release|Win32.Build.0 = Release|Win32 18 | {549BB008-902C-4FF0-8191-E79D062F6476}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {549BB008-902C-4FF0-8191-E79D062F6476}.Debug|Win32.Build.0 = Debug|Win32 20 | {549BB008-902C-4FF0-8191-E79D062F6476}.Release|Win32.ActiveCfg = Release|Win32 21 | {549BB008-902C-4FF0-8191-E79D062F6476}.Release|Win32.Build.0 = Release|Win32 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /daemon/win32_ruc/win32_ruc/win32_ruc.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/win32_ruc/win32_ruc/win32_ruc.suo -------------------------------------------------------------------------------- /daemon/win32_ruc/win32_ruc/win32_ruc.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/win32_ruc/win32_ruc/win32_ruc.vcproj -------------------------------------------------------------------------------- /daemon/win32_ruc/win32_ruc/win32_ruc.vcproj.MICROSOF-E7F3D7.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /daemon/win32_ruc/win32_run_compiler/main.cpp: -------------------------------------------------------------------------------- 1 | #define _WIN32_WINNT 0x0500 2 | #include 3 | #include 4 | #include 5 | #pragma comment(lib,"Psapi.lib") 6 | 7 | #define compiler_max_time 20000 8 | //#define compiler_max_memory 1024*1024*1024 //1GB 9 | HANDLE hJOB; 10 | HANDLE create_child_process(const char *cmd) 11 | { 12 | PROCESS_INFORMATION pi = {0}; 13 | STARTUPINFO si = {sizeof(si)}; 14 | 15 | hJOB = CreateJobObject(NULL, NULL); 16 | if(!hJOB) { 17 | return NULL; 18 | } 19 | 20 | /*JOBOBJECT_SECURITY_LIMIT_INFORMATION security_info = {0}; 21 | security_info.SecurityLimitFlags = JOB_OBJECT_SECURITY_NO_ADMIN; 22 | if(!SetInformationJobObject(hJOB, JobObjectSecurityLimitInformation, &security_info, sizeof security_info)) { 23 | CloseHandle(hJOB); 24 | return NULL; 25 | }*/ 26 | freopen("err.out", "w", stderr); 27 | freopen("cmpr.out", "w", stdout); 28 | 29 | BOOL bSuccess = CreateProcess(NULL, (LPSTR)(void*)cmd, NULL, NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); 30 | if(!bSuccess) { 31 | CloseHandle(hJOB); 32 | return NULL; 33 | } 34 | if(!AssignProcessToJobObject(hJOB, pi.hProcess)) { 35 | CloseHandle(hJOB); 36 | CloseHandle(pi.hThread); 37 | TerminateProcess(pi.hProcess, 0); 38 | CloseHandle(pi.hProcess); 39 | return NULL; 40 | } 41 | if(-1 == ResumeThread(pi.hThread)) { 42 | CloseHandle(hJOB); 43 | CloseHandle(pi.hThread); 44 | TerminateProcess(pi.hProcess, 0); 45 | CloseHandle(pi.hProcess); 46 | return NULL; 47 | } 48 | CloseHandle(pi.hThread); 49 | return pi.hProcess; 50 | } 51 | int run_compiler(const char *cmd, int *exit_code) 52 | { 53 | HANDLE hChild = create_child_process(cmd); 54 | if(!hChild) { 55 | return 1; 56 | } 57 | *exit_code = 0; 58 | if(WAIT_TIMEOUT == WaitForSingleObject(hChild, compiler_max_time + 200)) { 59 | *exit_code = 2; 60 | TerminateJobObject(hJOB, 1); 61 | //WaitForSingleObject(hChild, INFINITE); 62 | } 63 | if(! *exit_code) 64 | GetExitCodeProcess(hChild, (LPDWORD)exit_code); 65 | 66 | CloseHandle(hChild); 67 | CloseHandle(hJOB); 68 | 69 | return 0; 70 | } 71 | 72 | int main(int argc, char **argv) 73 | { 74 | if(argc < 2) { 75 | puts("usage: win32_run_compiler cmd"); 76 | return 1; 77 | } 78 | int exit_code; 79 | int ret = run_compiler(argv[1], &exit_code); 80 | if(ret) 81 | return ret; 82 | if(exit_code == 0) 83 | fprintf(stderr, "@~good~@\n"); 84 | fclose(stderr); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /daemon/win32_ruc/win32_run_compiler/win32_run_compiler.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/win32_ruc/win32_run_compiler/win32_run_compiler.vcproj -------------------------------------------------------------------------------- /daemon/win32_ruc/win32_run_compiler/win32_run_compiler.vcproj.MICROSOF-E7F3D7.Administrator.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /daemon/windows_binary/config.ini: -------------------------------------------------------------------------------- 1 | [system] 2 | datadir=d:/data 3 | DATABASE_USER=root 4 | DATABASE_PASS= 5 | 6 | [lang1] 7 | ext=cpp 8 | extra_mem=0 9 | compiler=g++ -fno-asm -s -w -O -DONLINE_JUDGE -o target.exe 10 | 11 | [lang2] 12 | ext=c 13 | extra_mem=0 14 | compiler=gcc -fno-asm -s -w -O -DONLINE_JUDGE -O -o target.exe 15 | 16 | [lang3] 17 | ext=pas 18 | extra_mem=0 19 | compiler=fpc -Xs -Sgic -dONLINE_JUDGE -otarget.exe 20 | 21 | [lang4] 22 | ext=cpp 23 | extra_mem=0 24 | compiler=g++ --std=gnu++0x -O -DONLINE_JUDGE -o target.exe 25 | -------------------------------------------------------------------------------- /daemon/windows_binary/daemon.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/daemon.exe -------------------------------------------------------------------------------- /daemon/windows_binary/libgcrypt-11.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libgcrypt-11.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libgmp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libgmp.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libgnutls-28.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libgnutls-28.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libgpg-error-0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libgpg-error-0.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libiconv-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libiconv-2.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libintl-8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libintl-8.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libmicrohttpd-10.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libmicrohttpd-10.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libmysql.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libmysql.dll -------------------------------------------------------------------------------- /daemon/windows_binary/libplibc-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/libplibc-1.dll -------------------------------------------------------------------------------- /daemon/windows_binary/pthreadGC2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/pthreadGC2.dll -------------------------------------------------------------------------------- /daemon/windows_binary/win32_ruc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/win32_ruc.exe -------------------------------------------------------------------------------- /daemon/windows_binary/win32_run_compiler.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/win32_run_compiler.exe -------------------------------------------------------------------------------- /daemon/windows_binary/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/daemon/windows_binary/zlib1.dll -------------------------------------------------------------------------------- /doc/database_convert.txt: -------------------------------------------------------------------------------- 1 | 数据库先对blob解码(password,source),再将编码转为utf-8 2 | 清空loginlog 3 | 清除solution中的waiting(10000) 4 | 更新users中的solved和submit 5 | PE,OE全部转为WA; 1,6 -> 4 6 | SE转为RE; 98 -> 5 7 | 一些表的列功能发生变化 -------------------------------------------------------------------------------- /doc/diagram_daemon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/doc/diagram_daemon.png -------------------------------------------------------------------------------- /doc/init_score.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os,sys; 3 | import MySQLdb as mdb; 4 | 5 | data_dir='/root/data/'; 6 | database_pass=''; 7 | max_prob=3542; 8 | 9 | def count_in(dir): 10 | num=0; 11 | files=os.listdir(dir); 12 | for line in files: 13 | line=os.path.join(dir,line); 14 | if os.path.isfile(line): 15 | if line.endswith('.in'): 16 | num=num+1; 17 | # print dir,num 18 | return num; 19 | 20 | con=mdb.connect('localhost','root',database_pass,'bsoj'); 21 | 22 | def update(p,s): 23 | global con; 24 | print p,s; 25 | con.cursor().execute("update problem set case_score="+str(s)+" where problem_id="+str(p)); 26 | 27 | for i in range(1000,max_prob-1): 28 | n=count_in(data_dir+str(i)); 29 | if n==0: 30 | continue; 31 | elif n<40: 32 | update(i,100/n); 33 | else: 34 | update(i,200/n); 35 | -------------------------------------------------------------------------------- /doc/nginx.conf: -------------------------------------------------------------------------------- 1 | #reference configuration for nginx 2 | 3 | user ojwww ojwww; 4 | #should be existing user and group 5 | 6 | worker_processes 4; 7 | 8 | error_log logs/error.log; 9 | #error_log logs/error.log notice; 10 | #error_log logs/error.log info; 11 | 12 | pid logs/nginx.pid; 13 | 14 | events { 15 | worker_connections 1024; 16 | } 17 | 18 | 19 | http { 20 | include mime.types; 21 | default_type application/octet-stream; 22 | 23 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 24 | '$status $body_bytes_sent "$http_referer" ' 25 | '"$http_user_agent" "$http_x_forwarded_for"'; 26 | 27 | #access_log logs/access.log main; 28 | access_log off; 29 | 30 | sendfile on; 31 | #tcp_nopush on; 32 | 33 | #keepalive_timeout 0; 34 | keepalive_timeout 10; 35 | 36 | gzip on; 37 | gzip_min_length 2000; 38 | gzip_buffers 4 8k; 39 | gzip_types text/plain application/x-javascript text/css application/xml; 40 | 41 | server { 42 | listen 8080; 43 | server_name _; 44 | 45 | root /var/nginx/html; 46 | #should be changed to your real path 47 | 48 | index index.html index.htm index.php; 49 | 50 | #pass to OJ daemon 51 | location ^~ /query/ { 52 | proxy_pass http://127.0.0.1:8888/; 53 | } 54 | location ^~ /assets/ { 55 | expires 10d; 56 | } 57 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 58 | location ~ \.php$ { 59 | fastcgi_pass 127.0.0.1:9000; 60 | fastcgi_index index.php; 61 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 62 | include fastcgi_params; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /doc/spj_example.c: -------------------------------------------------------------------------------- 1 | //Linux平台下保存为spj.cpp放到题目的数据目录下 2 | //Windows平台编译为spj.exe放到题目的数据目录下 3 | #include 4 | 5 | FILE *fscore,*freport,*fstd,*fin,*fout; 6 | int score; 7 | int main(int argc,char *argv[]) 8 | { 9 | fscore=fopen("score.log","w");//打开得分文件,写入一个数字表示测试点得分 10 | freport=fopen("report.log","w");//打开报告文件,用于反馈信息给选手 11 | fstd=fopen(argv[2],"r");//打开测试点标准输出文件 12 | score=atoi(argv[1]);//取得测试点的满分 13 | 14 | fin=fopen("user.in","r");//测试数据的输入 15 | fout=fopen("user.out","r");//选手的输出 16 | 17 | //评测 18 | 19 | if (/*完全正确*/) 20 | { 21 | fprintf(fscore,"%d",score);//返回满分 22 | fprintf(freport,"right");//报告用户结果,内容任意 23 | } 24 | else if (/*部分正确*/) 25 | { 26 | fprintf(fscore,"%d",/*部分分*/); 27 | fprintf(freport,/*输出错误信息*/); 28 | } 29 | else 30 | { 31 | fprintf(fscore,"%d",0);//返回0分 32 | fprintf(freport,"wrong");//报告用户结果,内容任意 33 | } 34 | 35 | fclose(fscore);//关闭得分文件 36 | fclose(freport);//关闭报告文件 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test_mutex.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'net/http' 4 | 5 | USER = 'NOI' 6 | PASSWD = 'NOINOI' 7 | HOST = 'oj.bashu.com.cn' 8 | 9 | def die message, code = 1 10 | puts message.to_s 11 | exit code 12 | end 13 | 14 | puts "User : #{USER}" 15 | puts 'Login ...Wait...' 16 | 17 | conn = Net::HTTP.new HOST 18 | post_data = URI.encode_www_form('uid' => USER, 'pwd' => PASSWD, 'url' => 'index.php') 19 | resp = conn.post '/code/login.php', post_data, {} 20 | die "Can't connect to OJ, check your network. HTTP Code - " + resp.code if resp.code != '302' && resp.code != '200' 21 | die 'Invalid username or password. ' if resp.body.size != 0 22 | 23 | cookie = resp.response['set-cookie'] 24 | 25 | (1..1000).each do |i| 26 | post_data = URI.encode_www_form 'message' => "testing...", 'detail' => "mutex is evil" 27 | conn.post '/code/postmessage.php', post_data, {'Cookie' => cookie} 28 | puts i 29 | end 30 | -------------------------------------------------------------------------------- /web/assets/Mathjax/README.md: -------------------------------------------------------------------------------- 1 | **Please extract Mathjax files here** 2 | -------------------------------------------------------------------------------- /web/assets/css/ex.css: -------------------------------------------------------------------------------- 1 | .btn-grey{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#662299;*background-color:#662299;background-image:-moz-linear-gradient(top,#662299,#662299);background-image:-webkit-gradient(linear,0 0,0 100%,from(#662299),to(#662299));background-image:-webkit-linear-gradient(top,#662299,#662299);background-image:-o-linear-gradient(top,#662299,#662299);background-image:linear-gradient(to bottom,#662299,#662299);background-repeat:repeat-x;border-color:#662299 #662299 #913800;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff662299',endColorstr='#ff662299',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-grey:hover,.btn-grey:focus,.btn-grey:active,.btn-grey.active,.btn-grey.disabled,.btn-grey[disabled]{color:#fff;background-color:#662299;*background-color:#c44c00}.btn-grey:active,.btn-grey.active{background-color:#aa4200 \9} 2 | .btn-emmm{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25);background-color:#2f4f6f;*background-color:#2f4f6f;background-image:-moz-linear-gradient(top,#2f4f6f,#2f4f6f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#2f4f6f),to(#2f4f6f));background-image:-webkit-linear-gradient(top,#2f4f6f,#2f4f6f);background-image:-o-linear-gradient(top,#2f4f6f,#2f4f6f);background-image:linear-gradient(to bottom,#2f4f6f,#2f4f6f);background-repeat:repeat-x;border-color:#2f4f6f #2f4f6f #913800;border-color:rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff2f4f6f',endColorstr='#ff2f4f6f',GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-emmm:hover,.btn-emmm:focus,.btn-emmm:active,.btn-emmm.active,.btn-emmm.disabled,.btn-emmm[disabled]{color:#fff;background-color:#2f4f6f;*background-color:#c44c00}.btn-emmm:active,.btn-emmm.active{background-color:#aa4200 \9} 3 | .btn-item{ 4 | display:block; 5 | padding-top: 0.928571em; 6 | padding-right: 1.14286em; 7 | padding-bottom: 0.928571em; 8 | padding-left: 1.14286em; 9 | } 10 | .active{ 11 | color:#2f2f2f; 12 | } -------------------------------------------------------------------------------- /web/assets/css/images/animated-overlay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/animated-overlay.gif -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_flat_0_aaaaaa_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_flat_0_aaaaaa_40x100.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_flat_75_ffffff_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_flat_75_ffffff_40x100.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /web/assets/css/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/css/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /web/assets/fonts/Font-Awesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/fonts/Font-Awesome/FontAwesome.otf -------------------------------------------------------------------------------- /web/assets/fonts/Font-Awesome/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/fonts/Font-Awesome/fontawesome-webfont.eot -------------------------------------------------------------------------------- /web/assets/fonts/Font-Awesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/fonts/Font-Awesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /web/assets/fonts/Font-Awesome/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/fonts/Font-Awesome/fontawesome-webfont.woff -------------------------------------------------------------------------------- /web/assets/fonts/euler.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/fonts/euler.otf -------------------------------------------------------------------------------- /web/assets/fonts/telex.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/fonts/telex.woff -------------------------------------------------------------------------------- /web/assets/ico/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/ico/favicon.ico -------------------------------------------------------------------------------- /web/assets/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /web/assets/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /web/assets/img/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/loading.gif -------------------------------------------------------------------------------- /web/assets/img/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/logo.jpg -------------------------------------------------------------------------------- /web/assets/img/ok-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/ok-icon.png -------------------------------------------------------------------------------- /web/assets/img/plupload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/plupload.png -------------------------------------------------------------------------------- /web/assets/img/rotate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/rotate.gif -------------------------------------------------------------------------------- /web/assets/img/wrong-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z4yx/bashu-onlinejudge/3a5301f6a3508640eba6a4e7575a41b90a968b8f/web/assets/img/wrong-icon.png -------------------------------------------------------------------------------- /web/assets/js/bootstrap-affix.js: -------------------------------------------------------------------------------- 1 | /* ========================================================== 2 | * bootstrap-affix.js v2.3.1 3 | * http://twitter.github.com/bootstrap/javascript.html#affix 4 | * ========================================================== 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================== */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* AFFIX CLASS DEFINITION 27 | * ====================== */ 28 | 29 | var Affix = function (element, options) { 30 | this.options = $.extend({}, $.fn.affix.defaults, options) 31 | this.$window = $(window) 32 | .on('scroll.affix.data-api', $.proxy(this.checkPosition, this)) 33 | .on('click.affix.data-api', $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this)) 34 | this.$element = $(element) 35 | this.checkPosition() 36 | } 37 | 38 | Affix.prototype.checkPosition = function () { 39 | if (!this.$element.is(':visible')) return 40 | 41 | var scrollHeight = $(document).height() 42 | , scrollTop = this.$window.scrollTop() 43 | , position = this.$element.offset() 44 | , offset = this.options.offset 45 | , offsetBottom = offset.bottom 46 | , offsetTop = offset.top 47 | , reset = 'affix affix-top affix-bottom' 48 | , affix 49 | 50 | if (typeof offset != 'object') offsetBottom = offsetTop = offset 51 | if (typeof offsetTop == 'function') offsetTop = offset.top() 52 | if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() 53 | 54 | affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? 55 | false : offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 56 | 'bottom' : offsetTop != null && scrollTop <= offsetTop ? 57 | 'top' : false 58 | 59 | if (this.affixed === affix) return 60 | 61 | this.affixed = affix 62 | this.unpin = affix == 'bottom' ? position.top - scrollTop : null 63 | 64 | this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : '')) 65 | } 66 | 67 | 68 | /* AFFIX PLUGIN DEFINITION 69 | * ======================= */ 70 | 71 | var old = $.fn.affix 72 | 73 | $.fn.affix = function (option) { 74 | return this.each(function () { 75 | var $this = $(this) 76 | , data = $this.data('affix') 77 | , options = typeof option == 'object' && option 78 | if (!data) $this.data('affix', (data = new Affix(this, options))) 79 | if (typeof option == 'string') data[option]() 80 | }) 81 | } 82 | 83 | $.fn.affix.Constructor = Affix 84 | 85 | $.fn.affix.defaults = { 86 | offset: 0 87 | } 88 | 89 | 90 | /* AFFIX NO CONFLICT 91 | * ================= */ 92 | 93 | $.fn.affix.noConflict = function () { 94 | $.fn.affix = old 95 | return this 96 | } 97 | 98 | 99 | /* AFFIX DATA-API 100 | * ============== */ 101 | 102 | $(window).on('load', function () { 103 | $('[data-spy="affix"]').each(function () { 104 | var $spy = $(this) 105 | , data = $spy.data() 106 | 107 | data.offset = data.offset || {} 108 | 109 | data.offsetBottom && (data.offset.bottom = data.offsetBottom) 110 | data.offsetTop && (data.offset.top = data.offsetTop) 111 | 112 | $spy.affix(data) 113 | }) 114 | }) 115 | 116 | 117 | }(window.jQuery); -------------------------------------------------------------------------------- /web/assets/js/bootstrap-alert.js: -------------------------------------------------------------------------------- 1 | /* ========================================================== 2 | * bootstrap-alert.js v2.3.1 3 | * http://twitter.github.com/bootstrap/javascript.html#alerts 4 | * ========================================================== 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================== */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* ALERT CLASS DEFINITION 27 | * ====================== */ 28 | 29 | var dismiss = '[data-dismiss="alert"]' 30 | , Alert = function (el) { 31 | $(el).on('click', dismiss, this.close) 32 | } 33 | 34 | Alert.prototype.close = function (e) { 35 | var $this = $(this) 36 | , selector = $this.attr('data-target') 37 | , $parent 38 | 39 | if (!selector) { 40 | selector = $this.attr('href') 41 | selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 42 | } 43 | 44 | $parent = $(selector) 45 | 46 | e && e.preventDefault() 47 | 48 | $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) 49 | 50 | $parent.trigger(e = $.Event('close')) 51 | 52 | if (e.isDefaultPrevented()) return 53 | 54 | $parent.removeClass('in') 55 | 56 | function removeElement() { 57 | $parent 58 | .trigger('closed') 59 | .remove() 60 | } 61 | 62 | $.support.transition && $parent.hasClass('fade') ? 63 | $parent.on($.support.transition.end, removeElement) : 64 | removeElement() 65 | } 66 | 67 | 68 | /* ALERT PLUGIN DEFINITION 69 | * ======================= */ 70 | 71 | var old = $.fn.alert 72 | 73 | $.fn.alert = function (option) { 74 | return this.each(function () { 75 | var $this = $(this) 76 | , data = $this.data('alert') 77 | if (!data) $this.data('alert', (data = new Alert(this))) 78 | if (typeof option == 'string') data[option].call($this) 79 | }) 80 | } 81 | 82 | $.fn.alert.Constructor = Alert 83 | 84 | 85 | /* ALERT NO CONFLICT 86 | * ================= */ 87 | 88 | $.fn.alert.noConflict = function () { 89 | $.fn.alert = old 90 | return this 91 | } 92 | 93 | 94 | /* ALERT DATA-API 95 | * ============== */ 96 | 97 | $(document).on('click.alert.data-api', dismiss, Alert.prototype.close) 98 | 99 | }(window.jQuery); -------------------------------------------------------------------------------- /web/assets/js/bootstrap-button.js: -------------------------------------------------------------------------------- 1 | /* ============================================================ 2 | * bootstrap-button.js v2.3.1 3 | * http://twitter.github.com/bootstrap/javascript.html#buttons 4 | * ============================================================ 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ============================================================ */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* BUTTON PUBLIC CLASS DEFINITION 27 | * ============================== */ 28 | 29 | var Button = function (element, options) { 30 | this.$element = $(element) 31 | this.options = $.extend({}, $.fn.button.defaults, options) 32 | } 33 | 34 | Button.prototype.setState = function (state) { 35 | var d = 'disabled' 36 | , $el = this.$element 37 | , data = $el.data() 38 | , val = $el.is('input') ? 'val' : 'html' 39 | 40 | state = state + 'Text' 41 | data.resetText || $el.data('resetText', $el[val]()) 42 | 43 | $el[val](data[state] || this.options[state]) 44 | 45 | // push to event loop to allow forms to submit 46 | setTimeout(function () { 47 | state == 'loadingText' ? 48 | $el.addClass(d).attr(d, d) : 49 | $el.removeClass(d).removeAttr(d) 50 | }, 0) 51 | } 52 | 53 | Button.prototype.toggle = function () { 54 | var $parent = this.$element.closest('[data-toggle="buttons-radio"]') 55 | 56 | $parent && $parent 57 | .find('.active') 58 | .removeClass('active') 59 | 60 | this.$element.toggleClass('active') 61 | } 62 | 63 | 64 | /* BUTTON PLUGIN DEFINITION 65 | * ======================== */ 66 | 67 | var old = $.fn.button 68 | 69 | $.fn.button = function (option) { 70 | return this.each(function () { 71 | var $this = $(this) 72 | , data = $this.data('button') 73 | , options = typeof option == 'object' && option 74 | if (!data) $this.data('button', (data = new Button(this, options))) 75 | if (option == 'toggle') data.toggle() 76 | else if (option) data.setState(option) 77 | }) 78 | } 79 | 80 | $.fn.button.defaults = { 81 | loadingText: 'loading...' 82 | } 83 | 84 | $.fn.button.Constructor = Button 85 | 86 | 87 | /* BUTTON NO CONFLICT 88 | * ================== */ 89 | 90 | $.fn.button.noConflict = function () { 91 | $.fn.button = old 92 | return this 93 | } 94 | 95 | 96 | /* BUTTON DATA-API 97 | * =============== */ 98 | 99 | $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) { 100 | var $btn = $(e.target) 101 | if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') 102 | $btn.button('toggle') 103 | }) 104 | 105 | }(window.jQuery); -------------------------------------------------------------------------------- /web/assets/js/bootstrap-popover.js: -------------------------------------------------------------------------------- 1 | /* =========================================================== 2 | * bootstrap-popover.js v2.3.1 3 | * http://twitter.github.com/bootstrap/javascript.html#popovers 4 | * =========================================================== 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * =========================================================== */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* POPOVER PUBLIC CLASS DEFINITION 27 | * =============================== */ 28 | 29 | var Popover = function (element, options) { 30 | this.init('popover', element, options) 31 | } 32 | 33 | 34 | /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js 35 | ========================================== */ 36 | 37 | Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, { 38 | 39 | constructor: Popover 40 | 41 | , setContent: function () { 42 | var $tip = this.tip() 43 | , title = this.getTitle() 44 | , content = this.getContent() 45 | 46 | $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) 47 | $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content) 48 | 49 | $tip.removeClass('fade top bottom left right in') 50 | } 51 | 52 | , hasContent: function () { 53 | return this.getTitle() || this.getContent() 54 | } 55 | 56 | , getContent: function () { 57 | var content 58 | , $e = this.$element 59 | , o = this.options 60 | 61 | content = (typeof o.content == 'function' ? o.content.call($e[0]) : o.content) 62 | || $e.attr('data-content') 63 | 64 | return content 65 | } 66 | 67 | , tip: function () { 68 | if (!this.$tip) { 69 | this.$tip = $(this.options.template) 70 | } 71 | return this.$tip 72 | } 73 | 74 | , destroy: function () { 75 | this.hide().$element.off('.' + this.type).removeData(this.type) 76 | } 77 | 78 | }) 79 | 80 | 81 | /* POPOVER PLUGIN DEFINITION 82 | * ======================= */ 83 | 84 | var old = $.fn.popover 85 | 86 | $.fn.popover = function (option) { 87 | return this.each(function () { 88 | var $this = $(this) 89 | , data = $this.data('popover') 90 | , options = typeof option == 'object' && option 91 | if (!data) $this.data('popover', (data = new Popover(this, options))) 92 | if (typeof option == 'string') data[option]() 93 | }) 94 | } 95 | 96 | $.fn.popover.Constructor = Popover 97 | 98 | $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, { 99 | placement: 'right' 100 | , trigger: 'click' 101 | , content: '' 102 | , template: '

' 103 | }) 104 | 105 | 106 | /* POPOVER NO CONFLICT 107 | * =================== */ 108 | 109 | $.fn.popover.noConflict = function () { 110 | $.fn.popover = old 111 | return this 112 | } 113 | 114 | }(window.jQuery); 115 | -------------------------------------------------------------------------------- /web/assets/js/bootstrap-transition.js: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * bootstrap-transition.js v2.3.1 3 | * http://twitter.github.com/bootstrap/javascript.html#transitions 4 | * =================================================== 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================== */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* CSS TRANSITION SUPPORT (http://www.modernizr.com/) 27 | * ======================================================= */ 28 | 29 | $(function () { 30 | 31 | $.support.transition = (function () { 32 | 33 | var transitionEnd = (function () { 34 | 35 | var el = document.createElement('bootstrap') 36 | , transEndEventNames = { 37 | 'WebkitTransition' : 'webkitTransitionEnd' 38 | , 'MozTransition' : 'transitionend' 39 | , 'OTransition' : 'oTransitionEnd otransitionend' 40 | , 'transition' : 'transitionend' 41 | } 42 | , name 43 | 44 | for (name in transEndEventNames){ 45 | if (el.style[name] !== undefined) { 46 | return transEndEventNames[name] 47 | } 48 | } 49 | 50 | }()) 51 | 52 | return transitionEnd && { 53 | end: transitionEnd 54 | } 55 | 56 | })() 57 | 58 | }) 59 | 60 | }(window.jQuery); -------------------------------------------------------------------------------- /web/assets/js/chat.js: -------------------------------------------------------------------------------- 1 | var socket; 2 | function ws_connect(){ 3 | socket = new WebSocket(ws_url); 4 | 5 | socket.onopen = function(){ 6 | $('#info_socket').html('Connected'); 7 | $('#chat_content').removeAttr('disabled').css('background-color','#fff');; 8 | $('#ipt_message').removeAttr('disabled'); 9 | $('#btn_send').removeAttr('disabled'); 10 | $('#btn_switch').removeAttr('disabled').html('Leave'); 11 | 12 | socket.send(userid); 13 | }; 14 | socket.onmessage = function(msgobj){ 15 | var ele = $('#chat_content').append(htmlEncode(msgobj.data.replace(/\n/g, '')) + "\n").get(0); 16 | ele.scrollTop = ele.scrollHeight; 17 | }; 18 | socket.onclose = function(){ 19 | $('#info_socket').html('Disconnected'); 20 | $('#chat_content').prop('disabled','disabled').css('background-color','#eee'); 21 | $('#ipt_message').prop('disabled','disabled'); 22 | $('#btn_send').prop('disabled','disabled'); 23 | $('#btn_switch').removeAttr('disabled').html('Enter'); 24 | }; 25 | } 26 | $(document).ready(function(){ 27 | $('#btn_switch').click(function(){ 28 | if(typeof(ws_url)==='undefined') 29 | return false; 30 | if(!("WebSocket" in window)){ 31 | alert('Sorry, you need a browser that supports HTML5 WebSockets.'); 32 | return false; 33 | } 34 | if(typeof(userid)==='undefined'){ 35 | alert("You have to log in before you can enter chat room."); 36 | return false; 37 | } 38 | var cmd = $(this).prop('disabled','disabled').html(); 39 | if(cmd == 'Enter') 40 | ws_connect(); 41 | else 42 | socket.close(); 43 | }); 44 | $('#btn_send').click(function(){ 45 | var ele=$('#ipt_message'); 46 | if(! $.trim(ele.val())) 47 | return false; 48 | socket.send(ele.val()); 49 | ele.val(''); 50 | }); 51 | $('#ipt_message').keypress(function(E){ 52 | if(E.keyCode == '13'){ 53 | $('#btn_send').click(); 54 | return false; 55 | } 56 | }); 57 | }); -------------------------------------------------------------------------------- /web/assets/js/google-code-prettify/prettify.css: -------------------------------------------------------------------------------- 1 | .com { color: #93a1a1; } 2 | .lit { color: #195f91; } 3 | .pun, .opn, .clo { color: #93a1a1; } 4 | .fun { color: #dc322f; } 5 | .str, .atv { color: #D14; } 6 | .kwd, .prettyprint .tag { color: #1e347b; } 7 | .typ, .atn, .dec, .var { color: teal; } 8 | .pln { color: #48484c; } 9 | 10 | .prettyprint { 11 | padding: 8px; 12 | background-color: #f7f7f9; 13 | border: 1px solid #e1e1e8; 14 | } 15 | .prettyprint.linenums { 16 | -webkit-box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0; 17 | -moz-box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0; 18 | box-shadow: inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0; 19 | } 20 | 21 | /* Specify class=linenums on a pre to get line numbering */ 22 | ol.linenums { 23 | margin: 0 0 0 33px; /* IE indents via margin-left */ 24 | } 25 | ol.linenums li { 26 | padding-left: 12px; 27 | color: #bebec5; 28 | line-height: 20px; 29 | text-shadow: 0 1px 0 #fff; 30 | } -------------------------------------------------------------------------------- /web/assets/js/html5.js: -------------------------------------------------------------------------------- 1 | /* 2 | HTML5 Shiv v3.6.2pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); 5 | a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; 6 | c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| 7 | "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",version:"3.6.2pre",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment(); 8 | for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;dYou are not administrator.'); 6 | 7 | require('inc/database.php'); 8 | if(isset($_POST['paswd'])){ 9 | 10 | require_once('inc/checkpwd.php'); 11 | if(password_right($_SESSION['user'], $_POST['paswd'])){ 12 | $_SESSION['admin_tfa']=1; 13 | if(isset($_SESSION['admin_retpage'])) 14 | $ret = $_SESSION['admin_retpage']; 15 | else 16 | $ret = "index.php"; 17 | header("Location: $ret"); 18 | exit(0); 19 | } 20 | } 21 | 22 | $Title="Admin Verification"; 23 | ?> 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 | 33 |
34 |
35 |
36 | 37 | 38 |
39 |
40 |
41 |
42 |
43 |

© 2012-2014 Bashu Middle School

44 |
45 | 46 |
47 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | -------------------------------------------------------------------------------- /web/code/ajax_deleteprob.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/code/ajax_mailfunc.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/code/ajax_opensource.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/code/ajax_preferences.php: -------------------------------------------------------------------------------- 1 | $name=$tmp; 19 | mysql_query("insert into preferences(user_id,property,value) values ('$user','$name','$tmp') ON DUPLICATE KEY UPDATE value='$tmp'"); 20 | 21 | } 22 | 23 | processOption('hidelogo'); 24 | processOption('sharecode'); 25 | processOption('hidehotkey'); 26 | 27 | $_SESSION['pref']=serialize($pref); 28 | 29 | 30 | -------------------------------------------------------------------------------- /web/code/ajax_profile.php: -------------------------------------------------------------------------------- 1 | 190) 5 | die('Nick is too long!'); 6 | if(strlen($_POST['school'])>60) 7 | die('School name is too long!'); 8 | if(strlen($_POST['email'])>60) 9 | die('E-mail is too long!'); 10 | if($_POST['type']=='profile'){ 11 | if(!isset($_POST['oldpwd'])) 12 | die('Invalid argument.'); 13 | session_start(); 14 | if(!isset($_SESSION['user'])) 15 | die('Not logged in.'); 16 | $user=$_SESSION['user']; 17 | require('inc/database.php'); 18 | require_once('inc/checkpwd.php'); 19 | if(!password_right($user, $_POST['oldpwd'])) 20 | die('Old password is not correct!'); 21 | 22 | $query='update users set email=\''.mysql_real_escape_string($_POST['email']).'\',school=\''.mysql_real_escape_string($_POST['school']).'\',nick=\''.mysql_real_escape_string($_POST['nick']).'\''; 23 | if(isset($_POST['newpwd']) && $_POST['newpwd']!=''){ 24 | $len=strlen($_POST['newpwd']); 25 | if($len<6||$len>20) 26 | die('Password is too long or too short!'); 27 | $query.=',password=\''.mysql_real_escape_string(my_rsa($_POST['newpwd'])).'\''; 28 | } 29 | $query.=" where user_id='$user'"; 30 | mysql_query($query); 31 | echo "User infomation updated successfully!"; 32 | }else if($_POST['type']=='reg'){ 33 | if(!isset($_POST['userid'],$_POST['newpwd'])) 34 | die('Invalid argument.'); 35 | require('inc/database.php'); 36 | $user=mysql_real_escape_string(trim($_POST['userid'])); 37 | $len=strlen($user); 38 | if($len==0) 39 | die('User name cannot be empty.'); 40 | if($len>20) 41 | die('User name is too long.'); 42 | if(preg_match('/\W/',$user)) 43 | die('User name can only contain number,letter and "_".'); 44 | 45 | $len=strlen($_POST['newpwd']); 46 | if($len<6||$len>20) 47 | die('Password is too long or too short!'); 48 | $pwd=mysql_real_escape_string($_POST['newpwd']); 49 | 50 | mysql_query("insert into users (user_id,email,password,reg_time,nick,school) values ('$user','".mysql_real_escape_string($_POST['email'])."','$pwd',NOW(),'".mysql_real_escape_string($_POST['nick'])."','".mysql_real_escape_string($_POST['school'])."')"); 51 | $code=mysql_errno(); 52 | if($code==0) 53 | echo 'User created successfully!'; 54 | else if($code==1062) 55 | echo "User '$user' exists."; 56 | else 57 | echo "Unknown error."; 58 | } 59 | ?> -------------------------------------------------------------------------------- /web/code/ajax_saveproblem.php: -------------------------------------------------------------------------------- 1 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 0"); 51 | $number=mysql_num_rows($failed); 52 | echo "'; 61 | $i=0; 62 | $solved=mysql_query("select problem_id from solution where result=0 and user_id='$user' group by problem_id"); 63 | $number=mysql_num_rows($solved); 64 | echo " 74 | 75 |
User:
Last Login:
IP:
School:
E-mail:
Reg Time:
AC/Submit:
Failed:
($number)
"; 53 | while($row=mysql_fetch_row($failed)){ 54 | echo '',$row[0],' '; 55 | if((++$i)==11){ 56 | echo '
'; 57 | $i=0; 58 | } 59 | } 60 | echo '
Solved:
($number)
"; 65 | while($row=mysql_fetch_row($solved)){ 66 | echo '',$row[0],' '; 67 | if((++$i)==11){ 68 | echo '
'; 69 | $i=0; 70 | } 71 | } 72 | ?> 73 |
76 | -------------------------------------------------------------------------------- /web/code/ajax_usernote.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/code/backupcode.php: -------------------------------------------------------------------------------- 1 | '; 7 | } 8 | session_start(); 9 | 10 | if(!isset($_SESSION['user'])){ 11 | show_alert('Not logged in.'); 12 | exit; 13 | } 14 | 15 | require('inc/database.php'); 16 | require('inc/preferences.php'); 17 | require('inc/lang_conf.php'); 18 | require('inc/tgz.lib.php'); 19 | 20 | $pref=unserialize($_SESSION['pref']); 21 | $now=time(); 22 | if($now - $pref->backuptime < 604800){ 23 | show_alert('You can only do this once a week!'); 24 | exit; 25 | } 26 | $archive="backup-$now"; 27 | header('Content-type: application/octet-stream'); 28 | header('Content-Disposition: attachment; filename="'.$archive.'.tar.gz"'); 29 | 30 | $fout = fopen('php://output','wb'); 31 | if($fout === FALSE) 32 | exit; 33 | 34 | $tar = new TGZfile($fout); 35 | 36 | $pref->backuptime=$now; 37 | $_SESSION['pref']=serialize($pref); 38 | 39 | $user=mysql_real_escape_string($_SESSION['user']); 40 | mysql_query("insert into preferences(user_id,property,value) values ('$user','backuptime','$now') ON DUPLICATE KEY UPDATE value='$now'"); 41 | 42 | $res=mysql_query("SELECT problem_id,language,source FROM source_code , (SELECT max_sol,problem_id,language FROM solution, (SELECT max(solution_id) AS max_sol FROM solution WHERE user_id='$user' AND result=0 GROUP BY problem_id) last WHERE solution_id=max_sol) tmp WHERE source_code.solution_id=max_sol"); 43 | 44 | while($row=mysql_fetch_row($res)){ 45 | $filename = $archive.'/'.$row[0].'.'.$LANG_EXT[$row[1]]; 46 | $tar->AddFile($filename, $row[2]); 47 | } 48 | 49 | $tar->Close(); 50 | 51 | -------------------------------------------------------------------------------- /web/code/control.php: -------------------------------------------------------------------------------- 1 | Not logged in.'; 6 | }else{ 7 | require('inc/database.php'); 8 | $user_id=$_SESSION['user']; 9 | } 10 | $Title="Control panel"; 11 | ?> 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 25 |
26 |

Preferences

27 |
28 | 31 | 34 | 37 | 38 |
39 | 40 |

Backup my code

41 |

42 | Download your last accepted submit of every problem.
You can do this for only once each week. 43 | backuptime)) 45 | echo "
Last Backup Time: ",date('Y-m-d H:i:s', $pref->backuptime),""; 46 | ?> 47 |

48 | 49 | 50 |

Open source

51 |

52 | Why Should I Open Source My Codes? 53 |

    54 |
  1. Open-source is an influential cultures which can date back to the early age of computer science's history; in addition, open-source softwares are the foundation of the web, the Internet, and our world.
  2. 55 |
  3. If one shares his code, everyone would have the chance to use, distribute, understand and improve the programs, and thus helps the author in return.
  4. 56 |
  5. Codes in OI are relatively short, nevertheless proned to be extremely obscure. Open-sourcing them can help other OIers struggling for solutions, whom we were once alike.
  6. 57 |
58 |

59 | 60 |
61 | 62 |
63 |
64 |
65 |

© 2012-2014 Bashu Middle School

66 |
67 |
68 | 69 | 70 | 71 | 72 | 73 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /web/code/download.php: -------------------------------------------------------------------------------- 1 | >20==0)die('invaild problem id.'); 48 | $datadir=get_testcase_dir(); 49 | if($op=='download'){ 50 | $dir=$datadir.$prob_id.'/'.$prob_id.'.zip'; 51 | if(!is_file($dir)) 52 | die('Can\'t open '.$prob_id.'.zip'); 53 | $file=fopen($dir,"r"); 54 | Header("Content-type: application/octet-stream" ); 55 | Header("Accept-Ranges: bytes" ); 56 | Header("Accept-Length: ".filesize($dir)); 57 | Header("Content-Disposition: attachment; filename=".$prob_id.".zip"); 58 | echo fread ($file,filesize($dir)); 59 | }else if($op=='update'){ 60 | if(!isset($_SESSION['administrator'])) 61 | die('Permission Denied'); 62 | if(!isset($_SESSION['admin_tfa']) || !$_SESSION['admin_tfa']){ 63 | $_SESSION['admin_retpage'] = "problempage.php?problem_id=$prob_id"; 64 | echo "admin_tfa"; 65 | exit; 66 | } 67 | $datadir=$datadir.$prob_id.'/'; 68 | if(!is_file($datadir."addition.zip"))$command="zip ".$datadir.$prob_id.".zip ".$datadir."*.in -j"; 69 | else $command="zip ".$datadir.$prob_id.".zip ".$datadir."*.in ".$datadir."/addition.zip -j"; 70 | //echo "system(".$command.")
"; 71 | exec($command,$ret,$callback); 72 | foreach($ret as $i){ 73 | echo mb_ereg_replace('\r?\n','
',$i)."
"; 74 | } 75 | if($callback!=0){ 76 | echo "
Something went wrong
Please Contact to Administrator
perhaps you haven't installed software \"zip\"
fail"; 77 | }else{ 78 | echo "
Success"; 79 | } 80 | }else if($op=='query'){ 81 | echo getcase($prob_id); 82 | }else die('Wrong operation.'); 83 | ?> -------------------------------------------------------------------------------- /web/code/head.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | <?php echo $Title?> 4 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /web/code/inc/checklogin.php: -------------------------------------------------------------------------------- 1 | 64) 7 | $value=substr($value,0,64); 8 | else 9 | $value=str_pad($value,64,"\x00"); 10 | 11 | $crypted=""; 12 | openssl_public_encrypt($value,$crypted,PUBLIC_KEY,OPENSSL_NO_PADDING); 13 | return "\x00".base64_encode($crypted); 14 | } 15 | 16 | function password_right($usr, $pwd_in){ 17 | $result=mysql_query("select password from users where user_id='$usr'"); 18 | if(!($row=mysql_fetch_row($result)) || !$row[0]) 19 | return false; 20 | 21 | $pwd_enc=my_rsa($pwd_in); 22 | $pwd_real=$row[0]; 23 | if(ord($pwd_real)!=0){ //password in database is not encrypted password 24 | $pwd_real=my_rsa($pwd_real); 25 | $pwd_escaped=mysql_escape_string($pwd_real); 26 | mysql_query("update users set password='$pwd_escaped' where user_id='$usr'"); 27 | } 28 | if(strcmp($pwd_enc, $pwd_real)!=0) 29 | return false; 30 | else 31 | return true; 32 | } 33 | -------------------------------------------------------------------------------- /web/code/inc/cookie.php: -------------------------------------------------------------------------------- 1 | 'bsoj'); 27 | $arr['user']=$_SESSION['user']; 28 | 29 | $data = encrypt(cookie_key, serialize($arr)); 30 | setcookie('SID', $data, time()+cookie_expire); 31 | } 32 | 33 | function encrypt($key, $plain_text) { 34 | $iv='7284565820000000'; 35 | $key=hash('sha256',$key,true); 36 | return openssl_encrypt($plain_text,'aes-256-cbc',$key,false,$iv); 37 | } 38 | function decrypt($key, $c_t) { 39 | $iv='7284565820000000'; 40 | $key=hash('sha256',$key,true); 41 | return openssl_decrypt($c_t,'aes-256-cbc',$key,false,$iv); 42 | } -------------------------------------------------------------------------------- /web/code/inc/database.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /web/code/inc/lang_conf.php: -------------------------------------------------------------------------------- 1 | 'G++', 4 | 1 => 'GCC', 5 | 2 => 'Pascal', 6 | 3 => 'G++(0x)', 7 | 4 => '/', 8 | ); 9 | 10 | static $LANG_EXT=array( 11 | 0 => 'cpp', 12 | 1 => 'c', 13 | 2 => 'pas', 14 | 3 => 'cpp', 15 | 4 => 'in', 16 | ); 17 | -------------------------------------------------------------------------------- /web/code/inc/mail_flags.php: -------------------------------------------------------------------------------- 1 | 2 | MathJax.Hub.Config({ 3 | extensions: ["tex2jax.js"], 4 | // jax: ["input/TeX", "output/HTML-CSS"], 5 | tex2jax: { 6 | inlineMath: [ ['[inline]','[/inline]'] ], 7 | displayMath: [ ["[tex]","[/tex]"] ] 8 | }, 9 | "HTML-CSS": { availableFonts: ["TeX"], webFont: "TeX", imageFont: null } 10 | }); 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /web/code/inc/mutex.php: -------------------------------------------------------------------------------- 1 | use_sysv=extension_loaded("sysvsem"); 7 | if($this->use_sysv){ 8 | $key=crc32($lock_file); 9 | $this->resource=sem_get($key, 1); 10 | if(!$this->resource || !sem_acquire($this->resource)) 11 | die('Could not get lock'); 12 | }else{ 13 | $i=0; 14 | while(!($this->resource=fopen($lock_file,'w+'))){ 15 | usleep(50000); 16 | $i++; 17 | if($i>10) 18 | die('Lock wait timeout exceeded'); 19 | } 20 | if(!flock($this->resource,LOCK_EX)){ 21 | fclose($this->resource); 22 | die('Could not get lock'); 23 | } 24 | } 25 | } 26 | 27 | public function release_mutex(){ 28 | if($this->use_sysv){ 29 | sem_release($this->resource); 30 | //sem_remove($this->resource); 31 | }else{ 32 | flock($this->resource, LOCK_UN); 33 | fclose($this->resource); 34 | } 35 | } 36 | 37 | public function __destruct(){ 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /web/code/inc/preferences.php: -------------------------------------------------------------------------------- 1 | hidelogo='on'; 11 | $this->hidehotkey='off'; 12 | $this->sharecode='off'; 13 | } 14 | } -------------------------------------------------------------------------------- /web/code/inc/problem_flags.php: -------------------------------------------------------------------------------- 1 | 'Accepted', 4 | 7 => 'Compile Error', 5 | 2 => 'Time Out', 6 | 3 => 'Memory Exceeded', 7 | 4 => 'Wrong Answer', 8 | 5 => 'Runtime Error', 9 | //6 => 'Wrong Answer',//'Output Limit Exceed', 10 | //1 => 'Wrong Answer',//'Presentation Error', 11 | //98 => 'Runtime Error',//'System Error', 12 | 99 => 'Validator Error' 13 | ); 14 | 15 | static $RESULT_STYLE=array( 16 | 0 => 'label-success', 17 | 7 => '', 18 | 2 => 'label-warning', 19 | 3 => 'label-warning', 20 | 4 => 'label-important', 21 | 5 => 'label-info', 22 | //6 => 'label-important',//'Output Limit Exceed', 23 | //1 => 'label-important',//'Presentation Error', 24 | //98 => 'label-info',//'System Error', 25 | 99 => 'label-inverse' 26 | ); 27 | ?> -------------------------------------------------------------------------------- /web/code/inc/tgz.lib.php: -------------------------------------------------------------------------------- 1 | tar_size = 0; 7 | $this->file = $_file; 8 | $this->create_time = time(); 9 | 10 | //gzip header 11 | fwrite($this->file, "\x1F\x8B\x08\x00".pack("V",$this->create_time)."\x00\x03"); 12 | 13 | $this->filter=stream_filter_append($this->file,'zlib.deflate',STREAM_FILTER_WRITE, -1); 14 | $this->hctx=hash_init('crc32b'); 15 | } 16 | private function calc_sum($tar_header) 17 | { 18 | $chksum=0; 19 | for($i=0;$i<512;$i++){ 20 | $chksum+=ord($tar_header{$i}); 21 | } 22 | 23 | return decoct($chksum); 24 | } 25 | private function str_modify(&$old, $pos, $new) 26 | { 27 | $len = strlen($new); 28 | 29 | for($i=0; $i<$len; $i++) 30 | $old[$pos++] = $new[$i]; 31 | } 32 | public function AddFile($name, $content) 33 | { 34 | if(strlen($name)>100) 35 | return FALSE; 36 | $length=strlen($content); 37 | 38 | $buf=str_pad($name,100,"\x00"); 39 | $buf.=str_pad('0000644',8,"\x00"); 40 | $buf.=str_pad('0001750',8,"\x00"); //uid 1000 41 | $buf.=str_pad('0001750',8,"\x00"); //gid 1000 42 | $buf.=str_pad(decoct($length),12,"\x00"); //size 43 | $buf.=str_pad(decoct($this->create_time), 12, "\x00"); //mtime 44 | $buf.="\x20\x20\x20\x20\x20\x20\x20\x20"; //chksum 45 | $buf.="\x30"; //flag 46 | $buf.=str_repeat("\0",100); //linkname 47 | $buf.='ustar '; //magic 48 | $buf.="\x20\x00"; //version GNU tar 49 | $buf.=str_pad('php',32,"\x00"); //uname 50 | $buf.=str_pad('php',32,"\x00"); //gname 51 | 52 | $buf.=str_repeat("\0",16); //dev 53 | $buf.=str_repeat("\0",155); //prefix 54 | $buf.=str_repeat("\0",12); //padding 55 | 56 | //write checksum 57 | $this->str_modify($buf, 148, $this->calc_sum($buf)); 58 | 59 | $align=($length+511)&(~511); // 512 bytes align 60 | $buf.=$content; 61 | $buf.=str_repeat("\0",$align-$length); 62 | 63 | fwrite($this->file, $buf); 64 | hash_update($this->hctx, $buf); 65 | 66 | $this->tar_size += strlen($buf); 67 | 68 | return TRUE; 69 | } 70 | // public function test_string($str) 71 | // { 72 | // fwrite($this->file, $str); 73 | // hash_update($this->hctx, $str); 74 | // $this->tar_size += strlen($str); 75 | // } 76 | public function Close() 77 | { 78 | $pad=str_repeat("\0",1024); 79 | fwrite($this->file, $pad); 80 | $this->tar_size += 1024; 81 | hash_update($this->hctx, $pad); 82 | 83 | stream_filter_remove($this->filter); 84 | $crc=hash_final($this->hctx, TRUE); 85 | fwrite($this->file, $crc[3].$crc[2].$crc[1].$crc[0], 4); 86 | fwrite($this->file, pack("V", $this->tar_size), 4); 87 | } 88 | } -------------------------------------------------------------------------------- /web/code/inc/userlogin.php: -------------------------------------------------------------------------------- 1 | $property=$r[1]; 33 | } 34 | $_SESSION['pref']=serialize($pref); 35 | 36 | $ip=mysql_escape_string($_SERVER["REMOTE_ADDR"]); 37 | mysql_query("update users set accesstime=NOW(),ip='$ip' where user_id='$user'"); 38 | 39 | return TRUE; 40 | } -------------------------------------------------------------------------------- /web/code/login.php: -------------------------------------------------------------------------------- 1 | 23 | 27 | -------------------------------------------------------------------------------- /web/code/logoff.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/code/marked.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | ',$info,'
'; 23 | }else{ 24 | ?> 25 |
26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
IDTitleLevelMarkedDelete
49 |
50 |
51 | 52 |
53 |
54 |

© 2012-2014 Bashu Middle School

55 |
56 | 57 | 58 | 59 | 60 | 61 | 62 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /web/code/postmessage.php: -------------------------------------------------------------------------------- 1 | 500) 32 | die('Message is too long'); 33 | 34 | $content=mysql_real_escape_string($_POST['detail']); 35 | 36 | $mutex=new php_mutex("/tmp/bsoj_postmessage.lock"); 37 | $new_msg_id=getNextMsgID(); 38 | 39 | if(isset($_POST['message_id']) 40 | && ($tmp=intval($_POST['message_id'])) 41 | && ($row=mysql_fetch_row(mysql_query('select orderNum,depth,thread_id,problem_id from message where message_id='.$tmp))) 42 | ){//Reply message 43 | 44 | $msg_id=$tmp; 45 | $order_num=$row[0]; 46 | $depth=$row[1]; 47 | $thread_id=$row[2]; 48 | $prob_id=$row[3]; 49 | 50 | $res=mysql_query("select depth,orderNum from message where thread_id=$thread_id and orderNum>$order_num order by orderNum"); 51 | while($row=mysql_fetch_row($res)){ 52 | if($row[0]<=$depth) 53 | break; 54 | $order_num=$row[1]; 55 | } 56 | mysql_query("update message set orderNum=orderNum+1 where thread_id=$thread_id and orderNum>$order_num"); 57 | mysql_query("update message set thread_id=$new_msg_id where thread_id=$thread_id"); 58 | $depth++; 59 | $order_num++; 60 | 61 | }else{//New message, check problem_id 62 | if(isset($_POST['problem_id'])){ 63 | $tmp=intval($_POST['problem_id']); 64 | if(mysql_num_rows(mysql_query('select problem_id from problem where problem_id='.$tmp))) 65 | $prob_id=$tmp; 66 | } 67 | } 68 | mysql_query("insert into message (thread_id,message_id,parent_id,orderNum,problem_id,depth,user_id,title,content,in_date) values($new_msg_id,$new_msg_id,$msg_id,$order_num,$prob_id,$depth,'$user_id','$title','$content',NOW())"); 69 | $mutex->release_mutex(); 70 | header('location: board.php'.($prob_id ? "?problem_id=$prob_id" : '')); 71 | //echo 'succeed'; 72 | 73 | ?> -------------------------------------------------------------------------------- /web/code/problemset_table.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Title'; 7 | else 8 | echo ''; 9 | ?> 10 | 11 | 12 | 13 | 14 | 15 | '; 18 | echo ''; 19 | if(isset($_SESSION['user'])){ 20 | echo ''; 21 | echo ''; 30 | } 31 | echo ''; 32 | echo ''; 34 | echo ''; 35 | echo ''; 36 | echo "\n"; 37 | } 38 | ?> 39 | 40 |
IDTitleAC/SubmitRatioLast Submit
',$row[0],'', ''; 22 | }else{ 23 | echo ''; 24 | } 25 | echo '',$row[1]; 26 | if($row[5]=='Y')echo 'Deleted'; 27 | echo ''; 28 | if(isset($_SESSION['user'])){ 29 | echo '',$row[2],'/'; 33 | echo '',$row[3],'',$row[3] ? intval($row[2]/$row[3]*100) : 0,'%',$row[4],'
-------------------------------------------------------------------------------- /web/code/proxy.php: -------------------------------------------------------------------------------- 1 | $prob, 59 | 'c'=>$row[0], 60 | 'd'=>$row[1], 61 | 'e'=>$row[2], 62 | 'h'=>"rejudge".$prob, 63 | 'j'=>$row[3], 64 | 'k'=>1 //TYPE_rejudge 65 | ); 66 | ignore_user_abort(TRUE); 67 | $result = posttodaemon($data); 68 | 69 | if(strstr($result,"OK")) 70 | echo "Rejudge $prob started."; 71 | else if(strstr($result,"another")) 72 | echo "Sorry, another rejudge thread is running."; 73 | else 74 | echo "Sorry, system error."; 75 | ?> -------------------------------------------------------------------------------- /web/code/solved.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 |
21 |
22 |
23 |
24 | 25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | '; 44 | echo ''; 45 | echo ''; 46 | echo ''; 47 | echo ''; 48 | echo "\n"; 49 | } 50 | ?> 51 | 52 |
SolutionNameProblemScoreDate
',$row[0],'',$row[1],'',$row[2],' -- ',$row[5],'',$row[3],'',$row[4],'
53 |
54 |
55 | 67 | 68 |
69 |
70 |

© 2012-2014 Bashu Middle School

71 |
72 | 73 |
74 | 75 | 76 | 77 | 78 | 95 | 96 | -------------------------------------------------------------------------------- /web/code/submit.php: -------------------------------------------------------------------------------- 1 | 29990) 57 | die('Code is too long.'); 58 | 59 | require('inc/database.php'); 60 | 61 | $res=mysql_query("select case_time_limit,memory_limit,case_score,compare_way,defunct,has_tex from problem where problem_id=$prob"); 62 | if(!($row=mysql_fetch_row($res))) 63 | die('No such problem'); 64 | 65 | require('inc/problem_flags.php'); 66 | $forbidden=false; 67 | if($row[4]=='Y' && !isset($_SESSION['administrator'])) 68 | $forbidden=true; 69 | else if($row[5]&PROB_IS_HIDE && !isset($_SESSION['insider'])) 70 | $forbidden=true; 71 | if($forbidden) 72 | die('You don\'t have permissions to access this problem'); 73 | if($LANG_NAME[$lang]!='/'){ 74 | $_SESSION['lang']=$lang; 75 | mysql_query("update users set language=$lang where user_id='".$_SESSION['user']."'"); 76 | } 77 | mysql_query("update problem set in_date=NOW() where problem_id=$prob"); 78 | 79 | $key=md5('key'.time().rand()); 80 | $share_code=(isset($_POST['public']) ? 1 : 0); 81 | 82 | $data=array( 83 | 'a'=>$prob, 84 | 'b'=>$lang, 85 | 'c'=>$row[0], 86 | 'd'=>$row[1], 87 | 'e'=>$row[2], 88 | 'f'=>$code, 89 | 'g'=>$_SESSION['user'], 90 | 'h'=>$key, 91 | 'i'=>$share_code, 92 | 'j'=>$row[3] 93 | ); 94 | ignore_user_abort(TRUE); 95 | $result = posttodaemon($data); 96 | //echo $result; 97 | if(strstr($result,"OK")) 98 | header("location: wait.php?key=$key"); 99 | else 100 | die($result); 101 | ?> 102 | -------------------------------------------------------------------------------- /web/code/upload.php: -------------------------------------------------------------------------------- 1 | 0) 11 | throw new Exception('Upload Error: '.$_FILES["file"]["error"]); 12 | 13 | $filename=isset($_POST['savename']) ? $_POST['savename'] : date('YmdHis_').mt_rand(10000,99999); 14 | if(!strlen($filename) || preg_match('/[^-)(\w]/',$filename)) 15 | throw new Exception("Invalid file name"); 16 | 17 | $filename.='.'.end(explode('.',$_FILES['file']['name'])); 18 | 19 | if(file_exists("../images/$filename")) 20 | throw new Exception("File '$filename' already exists,
try another file name."); 21 | if(!is_dir("../images")) 22 | if(!mkdir("../images",0770)) 23 | throw new Exception("Cannot create directory 'images'"); 24 | 25 | if(move_uploaded_file($_FILES["file"]["tmp_name"],"../images/$filename")){ 26 | $imgtag="<img src=\"../images/$filename\">"; 27 | }else 28 | throw new Exception("Upload failed"); 29 | }catch(Exception $e){ 30 | $info=$e->getMessage(); 31 | } 32 | }else{ 33 | $filename=date('YmdHis_').mt_rand(10000,99999); 34 | if(isset($_GET['id'])) 35 | $filename=intval($_GET['id']); 36 | } 37 | ?> 38 | 39 | 40 | 41 | Upload 42 | 55 | 65 | 66 | 67 |

Upload successfully.

68 |
HTML Tag:
69 |

Close

70 | 71 |

72 | «Go back 73 | 74 |
75 | 76 |
File name:
77 |
78 |
79 | 80 |
81 |
82 | 83 | 84 | --------------------------------------------------------------------------------