aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--judge/Makefile17
-rw-r--r--judge/check.c128
-rw-r--r--judge/check_reactgrader.c571
-rw-r--r--judge/judge_app.c13
-rw-r--r--judge/judge_app.h3
-rw-r--r--judge/judge_def.h15
-rw-r--r--judge/judge_server.c292
-rw-r--r--judge/judge_server.h30
-rw-r--r--judge/judgm_mod.c62
-rw-r--r--judge/judgm_mod.h22
-rw-r--r--judge/judgm_security.c2298
-rw-r--r--judge/judgx.h27
-rw-r--r--judge/judgx_com.h19
-rw-r--r--judge/judgx_lib.c287
-rw-r--r--judge/judgx_lib.h13
-rw-r--r--judge/judgx_line.h20
-rw-r--r--judge/line.c197
-rw-r--r--judge/line.h27
-rw-r--r--judge/line_vscore.c189
-rw-r--r--judge/line_vscore.h28
-rwxr-xr-xtoj/center/pro/packpro.sh3
-rw-r--r--toj/center/src/Makefile25
-rw-r--r--toj/center/src/center.h53
-rw-r--r--toj/center/src/center_com.h70
-rw-r--r--toj/center/src/center_judge.cpp524
-rw-r--r--toj/center/src/center_judge.h106
-rw-r--r--toj/center/src/center_manage.cpp308
-rw-r--r--toj/center/src/center_manage.h23
-rw-r--r--toj/center/src/center_server.cpp192
-rw-r--r--toj/center/src/center_server.h45
-rw-r--r--toj/center/src/jmod_test.h15
-rw-r--r--toj/center/src/jmod_test_check.cpp104
-rw-r--r--toj/center/src/jmod_test_check.h4
-rw-r--r--toj/center/src/jmod_test_line.cpp189
-rw-r--r--toj/center/src/jmod_test_line.h11
-rw-r--r--toj/center/src/jmod_test_manage.cpp98
-rw-r--r--toj/center/src/jmod_test_manage.h35
-rwxr-xr-xtoj/center/src/judge_def.h20
-rw-r--r--toj/center/src/judge_server.cpp697
-rw-r--r--toj/center/src/judge_server.h107
-rwxr-xr-x[-rw-r--r--]toj/center/src/judgk.h (renamed from judge/judgm.h)12
-rw-r--r--toj/center/src/judgk_com.h25
-rw-r--r--toj/center/src/judgk_hyperio.c417
-rw-r--r--toj/center/src/judgk_hyperio.h53
-rwxr-xr-xtoj/center/src/judgk_mod.c75
-rwxr-xr-xtoj/center/src/judgk_mod.h31
-rwxr-xr-x[-rw-r--r--]toj/center/src/judgk_proc.c (renamed from judge/judgm_proc.c)111
-rwxr-xr-x[-rw-r--r--]toj/center/src/judgk_proc.h (renamed from judge/judgm_proc.h)13
-rwxr-xr-xtoj/center/src/judgk_security.c2698
-rwxr-xr-x[-rw-r--r--]toj/center/src/judgk_security.h (renamed from judge/judgm_security.h)55
-rwxr-xr-x[-rw-r--r--]toj/center/src/judgk_syscall.c (renamed from judge/judgm_syscall.c)32
-rwxr-xr-x[-rw-r--r--]toj/center/src/judgk_syscall.h (renamed from judge/judgm_syscall.h)12
-rwxr-xr-x[-rw-r--r--]toj/center/src/judgk_syscall_asm.S (renamed from judge/judgm_syscall_asm.S)6
-rw-r--r--toj/center/src/judgm_lib.h369
-rwxr-xr-xtoj/center/src/judgm_line.h19
-rw-r--r--toj/center/src/judgm_manage.h27
-rw-r--r--toj/center/src/netio.h192
-rw-r--r--toj/center/src/pack.cpp175
-rw-r--r--toj/center/src/pack.h20
-rw-r--r--toj/center/src/tpool.h169
-rw-r--r--toj/index.html303
-rw-r--r--toj/jcs/common.css19
-rw-r--r--toj/jcs/common.js336
-rw-r--r--toj/jcs/home.css (renamed from web/square_set.php)0
-rw-r--r--toj/jcs/home.js433
-rw-r--r--toj/jcs/index.css177
-rw-r--r--toj/jcs/index.js128
-rw-r--r--toj/jcs/notice.css58
-rw-r--r--toj/jcs/notice.js155
-rw-r--r--toj/jcs/pro.css28
-rw-r--r--toj/jcs/pro.js165
-rw-r--r--toj/jcs/sq.css0
-rw-r--r--toj/jcs/sq.js100
-rw-r--r--toj/jcs/stat.css56
-rw-r--r--toj/jcs/stat.js364
-rw-r--r--toj/jcs/user.css175
-rw-r--r--toj/jcs/user.js1025
-rw-r--r--toj/php/_json.php3
-rw-r--r--toj/php/_test.php20
-rw-r--r--toj/php/common.inc.php7
-rw-r--r--toj/php/connect.inc.php40
-rw-r--r--toj/php/event.inc.php71
-rw-r--r--toj/php/event.php24
-rw-r--r--toj/php/event_exec.cpp89
-rw-r--r--toj/php/event_exec.h12
-rw-r--r--toj/php/notice.inc.php244
-rw-r--r--toj/php/notice.php110
-rw-r--r--toj/php/problem.inc.php252
-rw-r--r--toj/php/problem.php140
-rw-r--r--toj/php/pzreadtest.php9
-rw-r--r--toj/php/sqlib.inc.php5
-rw-r--r--toj/php/sqlib_scoreboard.inc.php239
-rw-r--r--toj/php/square.inc.php229
-rw-r--r--toj/php/square.php350
-rw-r--r--toj/php/status.inc.php133
-rw-r--r--toj/php/status.php70
-rw-r--r--toj/php/step.inc.php17
-rw-r--r--toj/php/step.php64
-rw-r--r--toj/php/teamt.php28
-rw-r--r--toj/php/test.php32
-rw-r--r--toj/php/user.inc.php212
-rw-r--r--toj/php/user.php160
-rwxr-xr-xtoj/pmod/pmod_multisub/pmod_multisub.css52
-rwxr-xr-xtoj/pmod/pmod_multisub/pmod_multisub.html40
-rwxr-xr-xtoj/pmod/pmod_multisub/pmod_multisub.js98
-rwxr-xr-xtoj/pmod/pmod_multisub/pmod_multisub.php77
-rwxr-xr-xtoj/pmod/pmod_test/pmod_test.css53
-rwxr-xr-xtoj/pmod/pmod_test/pmod_test.html37
-rwxr-xr-xtoj/pmod/pmod_test/pmod_test.js74
-rwxr-xr-xtoj/pmod/pmod_test/pmod_test.php42
-rwxr-xr-xtoj/smod/smod_test/smod_test.css29
-rwxr-xr-xtoj/smod/smod_test/smod_test.html10
-rwxr-xr-xtoj/smod/smod_test/smod_test.js43
-rwxr-xr-xtoj/smod/smod_test/smod_test.php21
-rwxr-xr-xtoj/sqmod/sqmod_test/sqmod_test.css97
-rwxr-xr-xtoj/sqmod/sqmod_test/sqmod_test.html33
-rw-r--r--toj/sqmod/sqmod_test/sqmod_test.inc.php149
-rwxr-xr-xtoj/sqmod/sqmod_test/sqmod_test.js259
-rwxr-xr-xtoj/sqmod/sqmod_test/sqmod_test.php84
-rw-r--r--toj/sqmod/sqmod_test/team.inc.php37
-rw-r--r--web/common.php16
-rw-r--r--web/data.js39
-rw-r--r--web/data_update.php81
-rw-r--r--web/index.html810
-rw-r--r--web/nor.css112
-rw-r--r--web/nor.js111
-rw-r--r--web/page.css6
-rw-r--r--web/page.js91
-rw-r--r--web/page_problem.css164
-rw-r--r--web/page_problem.js525
-rw-r--r--web/page_square.css167
-rw-r--r--web/page_square.js840
-rw-r--r--web/page_status.css110
-rw-r--r--web/page_status.js497
-rw-r--r--web/page_user.css123
-rw-r--r--web/page_user.js305
-rw-r--r--web/problem_code_submit.php66
-rw-r--r--web/problem_view.php41
-rw-r--r--web/square_list.php81
-rw-r--r--web/square_problem_list.php63
-rw-r--r--web/square_rank_list.php115
-rw-r--r--web/square_scoreboard_list.php115
-rw-r--r--web/status_submit_list.php147
-rw-r--r--web/status_viewcode.php30
-rw-r--r--web/user_get.php65
-rw-r--r--web/user_login.php32
-rw-r--r--web/user_register.php41
-rw-r--r--web/user_set.php109
-rw-r--r--web/viewcode.html54
149 files changed, 14357 insertions, 9314 deletions
diff --git a/judge/Makefile b/judge/Makefile
deleted file mode 100644
index ea9ce41..0000000
--- a/judge/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-ifneq ($(KERNELRELEASE),)
- judgm-objs := judgm_mod.o judgm_proc.o judgm_syscall.o judgm_syscall_asm.o judgm_security.o
- obj-m := judgm.o
-else
- KERNEL_SOURCE := /usr/lib/modules/$(shell uname -r)/build
- PWD := $(shell pwd)
-default:
- ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
- gcc judge_app.c judge_server.c -lcap -ldl -pthread -lpq -o judge
- gcc -shared -fPIC judgx_lib.c -o libjudgx.so
- gcc -shared -fPIC -fvisibility=hidden -O2 line.c -Wl,-rpath,'$$ORIGIN' -L. -ljudgx -lrt -pthread -o line.so
- gcc -shared -fPIC -fvisibility=hidden -O2 check.c -Wl,-rpath,'$$ORIGIN' -L. -ljudgx -pthread -o check.so
- gcc -shared -fPIC -fvisibility=hidden -O2 line_vscore.c -Wl,-rpath,'$$ORIGIN' -L. -ljudgx -lrt -pthread -o line_vscore.so
- gcc -shared -fPIC -fvisibility=hidden -O2 check_reactgrader.c -Wl,-rpath,'$$ORIGIN' -L. -ljudgx -pthread -o check_reactgrader.so
-clean:
- ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
-endif
diff --git a/judge/check.c b/judge/check.c
deleted file mode 100644
index bfe4a14..0000000
--- a/judge/check.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<limits.h>
-#include<fcntl.h>
-#include<signal.h>
-#include<pthread.h>
-#include<semaphore.h>
-#include<termios.h>
-
-#include"judge_def.h"
-#include"judgx.h"
-
-struct check_thread_info{
- int status;
- sem_t *done_sem;
-};
-
-int mptd;
-char ptname[PATH_MAX + 1];
-int infd;
-int ansfd;
-
-DLL_PUBLIC int init(char *runpath,char *datapath){
- struct termios tes;
- char tpath[PATH_MAX + 1];
- char newpath[PATH_MAX + 1];
-
- printf("check1\n");
-
- mptd = posix_openpt(O_RDWR);
- grantpt(mptd);
- unlockpt(mptd);
- ptsname_r(mptd,ptname,sizeof(ptname));
- tcgetattr(mptd,&tes);
- cfmakeraw(&tes);
- tcsetattr(mptd,TCSANOW,&tes);
-
- snprintf(tpath,sizeof(tpath),"%s/in.txt",datapath);
- snprintf(newpath,sizeof(newpath),"%s/in.txt",runpath);
- if(link(tpath,newpath) == -1){
- unlink(newpath);
- link(tpath,newpath);
- }
- infd = open(tpath,O_RDONLY);
- snprintf(tpath,sizeof(tpath),"%s/ans.txt",datapath);
- ansfd = open(tpath,O_RDONLY);
- if(infd == -1 || ansfd == -1){
- goto error;
- }
-
- printf("check2\n");
-
- return 0;
-
-error:
-
- close(mptd);
- close(infd);
- close(ansfd);
-
- return -1;
-}
-
-static void thread_clean(void *arg){
- close(mptd);
- close(infd);
- close(ansfd);
- return;
-}
-DLL_PUBLIC void* thread(void *arg){
- int ret;
- struct check_thread_info *thread_info;
-
- int flag;
- char outbuf[4096];
- char ansbuf[4096];
-
- pthread_cleanup_push(thread_clean,NULL);
- thread_info = (struct check_thread_info*)arg;
-
- flag = 0;
- while(1){
- if((ret = read(mptd,outbuf,4096)) <= 0){
- if(read(ansfd,ansbuf,1) > 0){
- flag = 1;
- break;
- }else{
- break;
- }
- }
- if(read(ansfd,ansbuf,ret) != ret){
- flag = 1;
- break;
- }
- if(memcmp(ansbuf,outbuf,ret) != 0){
- flag = 1;
- break;
- }
- }
-
- if(flag == 0){
- thread_info->status = JUDGE_AC;
- }else{
- thread_info->status = JUDGE_WA;
- }
-
- pthread_cleanup_pop(thread_clean);
- sem_post(thread_info->done_sem);
- return NULL;
-}
-DLL_PUBLIC int stop(void){
- return 0;
-}
-
-DLL_PUBLIC int run(){
- int sptd;
- struct termios tes;
-
- sptd = open(ptname,O_RDWR);
- tcgetattr(sptd,&tes);
- cfmakeraw(&tes);
- tcsetattr(sptd,TCSANOW,&tes);
-
- dup2(infd,0);
- dup2(sptd,1);
- dup2(sptd,2);
- return 0;
-}
diff --git a/judge/check_reactgrader.c b/judge/check_reactgrader.c
deleted file mode 100644
index f283bc5..0000000
--- a/judge/check_reactgrader.c
+++ /dev/null
@@ -1,571 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<limits.h>
-#include<fcntl.h>
-#include<signal.h>
-#include<pthread.h>
-#include<semaphore.h>
-#include<termios.h>
-
-#include"judge_def.h"
-#include"judgx.h"
-
-struct check_thread_info{
- int status;
- int score;
- int maxscore;
- sem_t *done_sem;
-};
-
-int mptd;
-char ptname[PATH_MAX + 1];
-int infd;
-
-// Opponent program for Guess that Cow
-// Originally based on soln-opt by Hal Burch
-// Extensive changes by Matt Craighead
-#include <ctype.h>
-#include <string.h>
-
-/*
-guess.in: input case
-standard input/output: student running program
-stderr: grading output
- */
-
-
-// Shared solver code for Guess that Cow
-// Used by soln-mjc, opponent, and testgen
-// Originally based on soln-opt by Hal Burch
-// Extensive changes by Matt Craighead
-
-#define MAXPROP 8
-#define MAXVAL 3
-#define MAXITEM 50
-#define NAME "guess"
-
-#define HASHSIZE 904069
-
-// Mask of cows. Would use a 64-bit int, but this is more portable and lets me
-// optimize things the compiler would do a poor job at.
-typedef struct {
- unsigned int lo;
- unsigned int hi;
-} CowMask;
-
-typedef struct state {
- CowMask member;
- int score;
- struct state *next;
-} state_t;
-
-int item[MAXITEM][MAXPROP];
-int nitem, nprop;
-int maxSearchDepth = 100;
-int noHashTable;
-CowMask maskhistory[200];
-char query[200][100];
-int resp[200];
-int nhist;
-
-int nQuestionsUsed, nOptimalQuestions;
-
-state_t *hashTable[HASHSIZE];
-
-CowMask updateMasks[MAXPROP][1 << MAXVAL];
-
-void FindBestQuestion(CowMask poss, int depth, int *question, int *score);
-
-CowMask BuildCowMask(int i)
-{
- CowMask cm;
- if (i < 32) {
- cm.lo = 1 << i;
- cm.hi = 0;
- } else {
- cm.lo = 0;
- cm.hi = 1 << (i-32);
- }
- return cm;
-}
-
-state_t *HashFind(CowMask poss, int depth)
-{
- static state_t fakeHashEntry;
- int h, temp;
- state_t *lp;
-
- if (noHashTable) {
- h = 0;
- lp = &fakeHashEntry;
- } else {
- // Simple hash function
- h = (poss.lo + poss.hi*7) % HASHSIZE;
-
- // Check hash table to see if this node has already been searched
- for (lp = hashTable[h]; lp; lp = lp->next) {
- if ((poss.lo == lp->member.lo) && (poss.hi == lp->member.hi)) {
- return lp;
- }
- }
-
- // Alloc a hash entry and link it in
- lp = (state_t *)malloc(sizeof(state_t));
- }
-
- // Recursively search to find score for this node
- FindBestQuestion(poss, depth+1, &temp, &lp->score);
- lp->member = poss;
- if (!noHashTable) {
- lp->next = hashTable[h];
- hashTable[h] = lp;
- }
-
- return lp;
-}
-
-void CleanHashTable(void)
-{
- int i;
- state_t *p, *next;
- for (i = 0; i < HASHSIZE; i++) {
- p = hashTable[i];
- while (p) {
- next = p->next;
- free(p);
- p = next;
- }
- hashTable[i] = NULL;
- }
-}
-
-int CountBits(CowMask x)
-{
- static int table[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
- int bits;
- bits = 0;
- while (x.lo) {
- bits += table[x.lo & 0xF];
- x.lo >>= 4;
- }
- while (x.hi) {
- bits += table[x.hi & 0xF];
- x.hi >>= 4;
- }
- return bits;
-}
-
-void FindBestResponse(CowMask poss, int question, CowMask *newPoss, int *answer)
-{
- int attr = question % MAXPROP;
- int quest = question / MAXPROP;
- int fcnt, tcnt, fquestions, tquestions;
- CowMask fposs, tposs;
- state_t *s;
- int oldNoHashTable;
-
- oldNoHashTable = noHashTable;
- noHashTable = 0;
-
- // Must choose answer of true or false, so run the
- // solver on each case
- fposs.lo = poss.lo & ~updateMasks[attr][quest].lo;
- fposs.hi = poss.hi & ~updateMasks[attr][quest].hi;
- tposs.lo = poss.lo & updateMasks[attr][quest].lo;
- tposs.hi = poss.hi & updateMasks[attr][quest].hi;
- fcnt = CountBits(fposs);
- tcnt = CountBits(tposs);
- if (fcnt <= 3) {
- fquestions = fcnt-1;
- } else {
- s = HashFind(fposs, 0); fquestions = s->score;
- }
- if (tcnt <= 3) {
- tquestions = tcnt-1;
- } else {
- s = HashFind(tposs, 0); tquestions = s->score;
- }
-
- // First go by # of questions; if there's a tie, go by
- // # of cows
- if (fquestions > tquestions) {
- *answer = 0;
- } else if (fquestions < tquestions) {
- *answer = 1;
- } else if (fcnt > tcnt) {
- *answer = 0;
- } else if (fcnt < tcnt) {
- *answer = 1;
- } else {
- // arbitrary
- *answer = 0;
- if (nitem == 4 && nQuestionsUsed == 2) *answer = 1;
- }
-
- *newPoss = *answer ? tposs : fposs;
-
- noHashTable = oldNoHashTable;
-}
-
-void FindBestQuestion(CowMask poss, int depth, int *question, int *score)
-{
- CowMask fposs, tposs;
- int lq, lp;
- int bestScore, bestQuestion;
- int tcnt, fcnt;
- state_t *s;
-
- bestScore = 1000;
- bestQuestion = -1;
-
- // Consider all properties to ask about
- for (lp = 0; lp < nprop; lp++) {
- // Consider all useful sets of values to ask about
- // An empty list of values to ask about is useless
- // Omit the last property so as to not repeat questions, because
- // all questions can be phrased in two ways
- for (lq = 1; lq < (1 << (MAXVAL-1)); lq++) {
- // Get the sets of cows remaining after each answer
- fposs.lo = poss.lo & ~updateMasks[lp][lq].lo;
- fposs.hi = poss.hi & ~updateMasks[lp][lq].hi;
- tposs.lo = poss.lo & updateMasks[lp][lq].lo;
- tposs.hi = poss.hi & updateMasks[lp][lq].hi;
- fcnt = CountBits(fposs);
- tcnt = CountBits(tposs);
-
- // If one answer would leave no cows left, this question
- // doesn't really give us any information
- if ((fcnt == 0) || (tcnt == 0)) continue;
-
- // How many questions will be required after this one to
- // solve the puzzle if we get an answer of "yes"?
- if ((tcnt <= 3) || (depth >= maxSearchDepth)) {
- // Small cases are easy
- tcnt = tcnt - 1;
- } else {
- // Look in the hash table
- s = HashFind(tposs, depth);
- tcnt = s->score;
- }
-
- // Quit early if no better than the best so far
- if (tcnt >= bestScore) continue;
-
- // How many questions will be required after this one to
- // solve the puzzle if we get an answer of "no"?
- if ((fcnt <= 3) || (depth >= maxSearchDepth)) {
- // Small cases are easy
- fcnt = fcnt - 1;
- } else {
- // Look in the hash table
- s = HashFind(fposs, depth);
- fcnt = s->score;
- }
-
- // Pick the worse of the two
- if (tcnt < fcnt) tcnt = fcnt;
- if (tcnt + 1 < bestScore) {
- bestScore = tcnt + 1;
- bestQuestion = lp + lq*MAXPROP;
- }
- }
- }
-
- //assert(bestScore < 1000);
- //assert(bestQuestion != -1);
-
- *question = bestQuestion;
- *score = bestScore;
-}
-
-void ParseInputFile(FILE *f)
-{
- int lv, lv2;
- char str[3];
- fscanf(f, "%d %d", &nitem, &nprop);
-
- for (lv = 0; lv < nitem; lv++) {
- for (lv2 = 0; lv2 < nprop; lv2++) {
- fscanf(f, "%s", str);
- item[lv][lv2] = str[0] - 'X';
- }
- }
-
-}
-
-void BuildUpdateMasks(void)
-{
- int i, lp, lq;
-
- // Precompute sets of cows remaining after each possible question
- for (lp = 0; lp < nprop; lp++) {
- for (lq = 0; lq < (1 << MAXVAL); lq++) {
- updateMasks[lp][lq].lo = 0;
- updateMasks[lp][lq].hi = 0;
- for (i = 0; i < nitem; i++) {
- if (lq & (1 << item[i][lp])) {
- CowMask cm = BuildCowMask(i);
- updateMasks[lp][lq].lo |= cm.lo;
- updateMasks[lp][lq].hi |= cm.hi;
- }
- }
- }
- }
-}
-
-int judge(struct check_thread_info *thread_info){
- FILE *ioin;
- FILE *ioout;
- FILE *fin;
- char line[256];
- int score, answer, quest, i;
- CowMask poss;
-
- ioin = fdopen(mptd,"r");
- ioout = fdopen(mptd,"w");
- fin = fdopen(infd,"r");
-
- CleanHashTable();
- ParseInputFile(fin);
- BuildUpdateMasks();
-
- // At first, all cows are possible
- poss.lo = 0;
- poss.hi = 0;
- for (i = 0; i < nitem; i++) {
- CowMask cm = BuildCowMask(i);
- poss.lo |= cm.lo;
- poss.hi |= cm.hi;
- }
-
- nOptimalQuestions = 100;
-
- // Solve the problem to get the best possible score
- FindBestQuestion(poss, 0, &quest, &nOptimalQuestions);
-
- nQuestionsUsed = 0;
- maskhistory[nQuestionsUsed] = poss;
- for (;;) {
- if(fgets(line, sizeof(line), ioin) == NULL){
- return 1;
- }
-
- if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = 0;
- if (line[0] == 'Q') {
- int parsed, i, attr, val[3];
-
- nQuestionsUsed++;
- if(nQuestionsUsed > 100){
- fprintf(ioout, "ABORT\n");
- fprintf(stderr, "WRONG\nYour program asked more than 100 questions.\n");
- return 0;
- }
- if (!isdigit(line[2])) {
- fprintf(stderr, "Wrong: unexpected input format: %s\n", line);
- return 1;
- }
- attr = line[2] - '0';
- parsed = 0; i = 3;
- while (line[i] != 0) {
- if ((line[i] != ' ') || line[i+1] < 'X' || line[i+1] > 'Z') {
- fprintf(stderr, "Wrong: unexpected input format: %s\n", line);
- return 1;
- }
- val[parsed] = line[i+1]-'X'+1;
- parsed++;
- i += 2;
- }
- if (parsed < 1) {
- fprintf(stderr, "Wrong: unexpected input format: %s\n", line);
- return 1;
- }
- attr--;
- quest = 0;
- for (i = 0; i < parsed; i++) {
- if ((val[i] < 1) || (val[i] > MAXVAL)) {
- fprintf(stderr, "Incorrect: invalid attribute value in question\n");
- return 1;
- }
- quest |= 1 << (val[i]-1);
- }
-
- FindBestResponse(poss, attr + quest*MAXPROP, &poss, &answer);
- strcpy(query[nQuestionsUsed-1], line);
- maskhistory[nQuestionsUsed-1] = poss;
- resp[nQuestionsUsed-1] = answer;
-
- fprintf(ioout,"%d\n", answer);
- fflush(ioout);
- } else if (line[0] == 'C') {
- // Done, check the answer
- break;
- } else {
- fprintf(stderr, "Wrong: unexpected input format: %s\n", line);
- return 1;
- }
- }
-
- if ((line[1] != ' ') || !isdigit(line[2])) {
- fprintf(stderr, "Wrong: unexpected input format: %s", line);
- return 1;
- }
- if (line[3] != 0) {
- if (!isdigit(line[3]) || (line[4] != 0)) {
- fprintf(stderr, "Wrong: unexpected input format: %s", line);
- return 1;
- }
- }
- sscanf(line, "C %d", &answer);
- answer--;
-
- // To be correct, this cow must be the only remaining possible cow
- if (CountBits(poss) != 1) {
- fprintf(ioout, "ABORT\n");
- fprintf(stderr, "WRONG\n");
- fprintf(stderr, "The following cows are still consistent with the answers given:\n");
- fprintf(stderr, " ");
- for(i=0; i<32; i++){
- if(poss.lo&(1<<i)){
- fprintf(stderr, " %d", i+1);
- }
- }
- for(i=0;i<32; i++){
- if(poss.hi&(1<<i)){
- fprintf(stderr, " %d", i+32+1);
- }
- }
- fprintf(stderr, "\n");
- return 0;
- } else {
- CowMask cm = BuildCowMask(answer);
- if ((poss.lo != cm.lo) || (poss.hi != cm.hi)) {
- for(i=0; i<nQuestionsUsed; i++){
- if(!(maskhistory[i].lo&cm.lo)&&!(maskhistory[i].hi&cm.hi))
- break;
- }
- fprintf(ioout, "ABORT\n");
- fprintf(stderr, "WRONG\nYour program claims the solution is cow %d,\n", answer+1);
- fprintf(stderr, "but cow %d was eliminated by query #%d (%s) with response %d.\n", answer+1, i+1, query[i], resp[i]);
- return 0;
- } else {
- if (nQuestionsUsed <= nOptimalQuestions) {
- score = 10;
- } else if (nQuestionsUsed == nOptimalQuestions+1) {
- score = 8;
- } else if (nQuestionsUsed == nOptimalQuestions+2) {
- score = 5;
- } else if (nQuestionsUsed <= nOptimalQuestions+5) {
- score = 4;
- } else {
- score = 3;
- }
- if (score < 10) {
- fprintf(stderr, "OK %d\n", score);
- } else {
- fprintf(stderr, "OK\n");
- }
- if(nQuestionsUsed < nOptimalQuestions){
- fprintf(stderr, "Student is better than us.\n");
- }
-
- thread_info->score = score;
- if(nQuestionsUsed < nOptimalQuestions){
- thread_info->score += (nOptimalQuestions - nQuestionsUsed);
- }
- }
- }
-
- fprintf(ioout, "DONE\n");
-
- if(thread_info->score > 10){
- thread_info->maxscore = thread_info->score;
- }else{
- thread_info->maxscore = 10;
- }
-
- if(thread_info->score == thread_info->maxscore){
- thread_info->status = JUDGE_AC;
- }else{
- thread_info->status = JUDGE_WA;
- }
-
- return 0;
-}
-
-DLL_PUBLIC int init(char *runpath,char *datapath){
- struct termios tes;
- char tpath[PATH_MAX + 1];
- char newpath[PATH_MAX + 1];
-
- mptd = posix_openpt(O_RDWR);
- grantpt(mptd);
- unlockpt(mptd);
- ptsname_r(mptd,ptname,sizeof(ptname));
- tcgetattr(mptd,&tes);
- cfmakeraw(&tes);
- tcsetattr(mptd,TCSANOW,&tes);
-
- printf("check1\n");
-
- snprintf(tpath,sizeof(tpath),"%s/in.txt",datapath);
- snprintf(newpath,sizeof(newpath),"%s/guess.in",runpath);
- if(link(tpath,newpath) == -1){
- unlink(newpath);
- link(tpath,newpath);
- }
- infd = open(tpath,O_RDONLY);
- if(infd == -1){
- goto error;
- }
-
- printf("check2\n");
-
- return 0;
-
-error:
-
- close(mptd);
- close(infd);
-
- return -1;
-}
-
-static void thread_clean(void *arg){
- close(mptd);
- close(infd);
- return;
-}
-DLL_PUBLIC void* thread(void *arg){
- struct check_thread_info *thread_info;
-
- pthread_cleanup_push(thread_clean,NULL);
- thread_info = (struct check_thread_info*)arg;
-
- thread_info->status = JUDGE_WA;
- thread_info->score = 0;
- thread_info->maxscore = 10;
-
- judge(thread_info);
-
- pthread_cleanup_pop(thread_clean);
- sem_post(thread_info->done_sem);
- return NULL;
-}
-DLL_PUBLIC int stop(void){
- return 0;
-}
-
-DLL_PUBLIC int run(){
- int sptd;
- struct termios tes;
-
- sptd = open(ptname,O_RDWR);
- tcgetattr(sptd,&tes);
- cfmakeraw(&tes);
- tcsetattr(sptd,TCSANOW,&tes);
-
- dup2(sptd,0);
- dup2(sptd,1);
- dup2(sptd,2);
- return 0;
-}
diff --git a/judge/judge_app.c b/judge/judge_app.c
deleted file mode 100644
index f891602..0000000
--- a/judge/judge_app.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<signal.h>
-
-#include"judge_app.h"
-
-int main(int argc,char *argv[]){
-
- signal(SIGPIPE,SIG_IGN);
- judge_server();
-
- return 0;
-}
diff --git a/judge/judge_app.h b/judge/judge_app.h
deleted file mode 100644
index fdb8812..0000000
--- a/judge/judge_app.h
+++ /dev/null
@@ -1,3 +0,0 @@
-int judge_modfd;
-
-extern int judge_server();
diff --git a/judge/judge_def.h b/judge/judge_def.h
deleted file mode 100644
index b55c8d4..0000000
--- a/judge/judge_def.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#define JUDGE_AC 0
-#define JUDGE_WA 1
-#define JUDGE_TLE 2
-#define JUDGE_MLE 3
-#define JUDGE_RF 4
-#define JUDGE_RE 5
-#define JUDGE_CE 6
-#define JUDGE_ERR 7
-#define JUDGE_WAIT 100
-
-#define JUDGE_DB_STATUSMAX 1024
-#define JUDGE_DB_SCOREMAX 1024
-#define JUDGE_DB_MAXSCOREMAX 1024
-#define JUDGE_DB_RUNTIMEMAX 1024
-#define JUDGE_DB_PEAKMEMMAX 1024
diff --git a/judge/judge_server.c b/judge/judge_server.c
deleted file mode 100644
index f0e48cd..0000000
--- a/judge/judge_server.c
+++ /dev/null
@@ -1,292 +0,0 @@
-#define _XOPEN_SOURCE 600
-#define _GNU_SOURCE
-
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<limits.h>
-#include<pthread.h>
-#include<semaphore.h>
-#include<dlfcn.h>
-#include<sys/socket.h>
-#include<sys/mman.h>
-#include<netinet/in.h>
-#include<errno.h>
-#include<ftw.h>
-#include<libpq-fe.h>
-
-#include"judge_def.h"
-#include"judgx_line.h"
-#include"judge_server.h"
-
-#define JUDGE_DB_MAXSCOREMAX 1024
-
-static int server_cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftwbuf){
- if(ftwbuf->level == 0){
- return 0;
- }
-
- if(S_ISDIR(st->st_mode)){
- rmdir(path);
- }else{
- unlink(path);
- }
- return 0;
-}
-static int server_cleardir(char *path){
- nftw(path,server_cleardir_callback,64,FTW_DEPTH | FTW_PHYS);
- return 0;
-}
-static int server_updatedb(PGconn *sqlc,int submitid,int result_count,struct judgx_line_result *result){
- int i;
- int j;
-
- char sqlstatus[JUDGE_DB_STATUSMAX + 1];
- char sqlscore[JUDGE_DB_SCOREMAX + 1];
- char sqlmaxscore[JUDGE_DB_MAXSCOREMAX + 1];
- char sqlruntime[JUDGE_DB_RUNTIMEMAX + 1];
- char sqlpeakmem[JUDGE_DB_PEAKMEMMAX + 1];
- char sqlsubmitid[64];
-
- const char *sqlparam[6];
- PGresult *sqlr;
-
- printf("sql1 %d\n",getpid());
-
- sqlstatus[0] = '{';
- for(i = 0,j = 1;i < result_count;i++){
- snprintf(sqlstatus + j,sizeof(sqlstatus) - j,"%d,",result[i].status);
- while(sqlstatus[j] != '\0'){
- j++;
- }
- }
- sqlstatus[j - 1] = '}';
-
- sqlscore[0] = '{';
- for(i = 0,j = 1;i < result_count;i++){
- snprintf(sqlscore + j,sizeof(sqlscore) - j,"%d,",result[i].score);
- while(sqlscore[j] != '\0'){
- j++;
- }
- }
- sqlscore[j - 1] = '}';
-
- sqlmaxscore[0] = '{';
- for(i = 0,j = 1;i < result_count;i++){
- snprintf(sqlmaxscore + j,sizeof(sqlmaxscore) - j,"%d,",result[i].maxscore);
- while(sqlmaxscore[j] != '\0'){
- j++;
- }
- }
- sqlmaxscore[j - 1] = '}';
-
- sqlruntime[0] = '{';
- for(i = 0,j = 1;i < result_count;i++){
- snprintf(sqlruntime + j,sizeof(sqlruntime) - j,"%lu,",result[i].runtime);
- while(sqlruntime[j] != '\0'){
- j++;
- }
- }
- sqlruntime[j - 1] = '}';
-
- sqlpeakmem[0] = '{';
- for(i = 0,j = 1;i < result_count;i++){
- snprintf(sqlpeakmem + j,sizeof(sqlpeakmem) - j,"%lu,",result[i].peakmem);
- while(sqlpeakmem[j] != '\0'){
- j++;
- }
- }
- sqlpeakmem[j - 1] = '}';
-
- snprintf(sqlsubmitid,64,"%d",submitid);
-
- printf("sql2\n");
-
- sqlparam[0] = sqlstatus;
- sqlparam[1] = sqlscore;
- sqlparam[2] = sqlmaxscore;
- sqlparam[3] = sqlruntime;
- sqlparam[4] = sqlpeakmem;
- sqlparam[5] = sqlsubmitid;
-
- sqlr = PQexecParams(sqlc,
- "UPDATE \"submit\" SET \"status\"=$1,\"score\"=$2,\"maxscore\"=$3,\"runtime\"=$4,\"peakmem\"=$5 WHERE \"submitid\"=$6;",
- 6,
- NULL,
- sqlparam,
- NULL,
- NULL,
- 0);
- PQclear(sqlr);
-
- printf("sql3\n");
-
- return 0;
-}
-static void* server_thread(void *arg){
- int i;
-
- struct server_thread_info *thread_info;
- struct judge_submit_info *submit_info;
- struct judgx_line_info *line_info;
-
- PGconn *sqlc;
- char tname[NAME_MAX + 1];
- char tpath[PATH_MAX + 1];
- line_run_fn line_run;
- int runpid;
-
- thread_info = (struct server_thread_info*)arg;
-
- sqlc = PQconnectdb("host=localhost port=5432 dbname=expoj user=expoj password=xxxxx");
-
- while(1){
- printf("in\n");
-
- sem_wait(&server_queue_sem);
-
- pthread_mutex_lock(&server_queue_mutex);
-
- printf("in1\n");
-
- submit_info = server_queue_head.next;
- server_queue_head.next = submit_info->next;
- submit_info->next->prev = &server_queue_head;
-
- pthread_mutex_unlock(&server_queue_mutex);
-
- printf("in2\n");
-
- server_cleardir(thread_info->run_path);
-
- printf("in3\n");
-
- line_info = mmap(NULL,sizeof(struct judgx_line_info),PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS,-1,0);
- snprintf(line_info->pro_path,sizeof(line_info->pro_path),"pro/%d",submit_info->proid);
- snprintf(line_info->cpp_path,sizeof(line_info->cpp_path),"submit/%d_submit.cpp",submit_info->submitid);
- line_info->run_path[0] = '\0';
- strncat(line_info->run_path,thread_info->run_path,sizeof(line_info->run_path));
-
- printf("in4");
-
- snprintf(tpath,sizeof(tpath),"pro/%d/%d_setting.txt",submit_info->proid,submit_info->proid);
- line_info->set_file = fopen(tpath,"r");
-
- printf("in5\n");
-
- fgets(tname,sizeof(tname),line_info->set_file);
- tname[strlen(tname) - 1] = '\0';
- snprintf(tpath,sizeof(tpath),"judge/%s.so",tname);
-
- printf("in5-1\n");
-
- line_info->line_dll = dlopen(tpath,RTLD_LAZY | RTLD_NODELETE);
-
- printf("in5-2\n");
-
- fgets(tname,sizeof(tname),line_info->set_file);
- tname[strlen(tname) - 1] = '\0';
- snprintf(tpath,sizeof(tpath),"judge/%s.so",tname);
-
- printf("in5-3\n");
-
- line_info->check_dll = dlopen(tpath,RTLD_LAZY | RTLD_NODELETE);
-
- printf("in6\n");
-
- line_run = dlsym(line_info->line_dll,"run");
- if((runpid = fork()) == 0){
- line_run(line_info);
- exit(0);
- }
- waitpid(runpid,NULL,0);
-
- printf("in7\n");
-
- server_updatedb(sqlc,submit_info->submitid,line_info->result_count,line_info->result);
-
- printf("in8\n");
-
- fclose(line_info->set_file);
- dlclose(line_info->line_dll);
- dlclose(line_info->check_dll);
-
- munmap(line_info,sizeof(struct judgx_line_info));
- free(submit_info);
-
- printf("out\n");
- }
-
- PQfinish(sqlc);
-
- return NULL;
-}
-int judge_server(){
- int ret;
- int i;
-
- struct server_thread_info *thread_info;
-
- int ssd;
- struct sockaddr_in saddr;
- struct sockaddr_in caddr;
- int csd;
- char *buf;
- int submitid;
- int proid;
- struct judge_submit_info *submit_info;
-
- server_queue_head.next = &server_queue_head;
- server_queue_head.prev = &server_queue_head;
- sem_init(&server_queue_sem,0,0);
- pthread_mutex_init(&server_queue_mutex,NULL);
-
- thread_info = (struct server_thread_info*)malloc(sizeof(struct server_thread_info) * 4);
- for(i = 0;i < 2;i++){
- thread_info[i].threadid = i;
- snprintf(thread_info[i].run_path,sizeof(thread_info[i].run_path),"run/%d",i);
- mkdir(thread_info[i].run_path,0775);
- pthread_create(&thread_info[i].pt,NULL,server_thread,&thread_info[i]);
- }
-
- ssd = socket(AF_INET,SOCK_STREAM,0);
- saddr.sin_family = AF_INET;
- saddr.sin_port = htons(2501);
- saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- bind(ssd,(struct sockaddr*)&saddr,sizeof(saddr));
- listen(ssd,128);
-
- buf = malloc(65536);
- while((csd = accept(ssd,(struct sockaddr*)&saddr,&ret)) != -1){
- i = 0;
- if((ret = recv(csd,buf + i,65536,0)) != -1){
- i += ret;
- }
- sscanf(buf,"%d %d",&submitid,&proid);
-
- printf(" %d %d\n",submitid,proid);
-
- submit_info = malloc(sizeof(struct judge_submit_info));
- submit_info->submitid = submitid;
- submit_info->proid = proid;
-
- pthread_mutex_lock(&server_queue_mutex);
-
- submit_info->next = &server_queue_head;
- submit_info->prev = server_queue_head.prev;
- server_queue_head.prev->next = submit_info;
- server_queue_head.prev = submit_info;
-
- pthread_mutex_unlock(&server_queue_mutex);
-
- sem_post(&server_queue_sem);
-
- close(csd);
- }
- free(buf);
-
- free(thread_info);
-
- return 0;
-}
-
diff --git a/judge/judge_server.h b/judge/judge_server.h
deleted file mode 100644
index 9d7b753..0000000
--- a/judge/judge_server.h
+++ /dev/null
@@ -1,30 +0,0 @@
-typedef int (*line_run_fn)(struct judgx_line_info *line_info);
-
-struct server_thread_info{
- int threadid;
- pthread_t pt;
-
- char run_path[PATH_MAX + 1];
-};
-struct judge_submit_info{
- struct judge_submit_info *next;
- struct judge_submit_info *prev;
-
- int submitid;
- int proid;
-};
-
-static int server_cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftwbuf);
-static int server_cleardir(char *path);
-static int server_updatedb(PGconn *sqlc,int submitid,int result_count,struct judgx_line_result *result);
-static void* server_thread(void *arg);
-
-static struct judge_submit_info server_queue_head;
-static sem_t server_queue_sem;
-static pthread_mutex_t server_queue_mutex;
-
-int judge_server();
-
-extern struct judge_proc_info* judge_proc_create(char *abspath,char *path,char *sopath,unsigned long timelimit,unsigned long memlimit);
-extern int judge_proc_free(struct judge_proc_info *proc_info);
-extern int judge_proc_run(struct judge_proc_info *proc_info);
diff --git a/judge/judgm_mod.c b/judge/judgm_mod.c
deleted file mode 100644
index 092902a..0000000
--- a/judge/judgm_mod.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#include<linux/module.h>
-#include<linux/kernel.h>
-#include<linux/kdev_t.h>
-#include<linux/device.h>
-#include<linux/cdev.h>
-#include<linux/fs.h>
-
-#include"judgm_mod.h"
-#include"judgm.h"
-#include"judgx_com.h"
-
-static int __init mod_init(){
- alloc_chrdev_region(&mod_dev,0,1,"judgm");
- mod_class = class_create(THIS_MODULE,"chardev");
- device_create(mod_class,NULL,mod_dev,NULL,"judgm");
- cdev_init(&mod_cdev,&mod_fops);
- cdev_add(&mod_cdev,mod_dev,1);
-
- judgm_proc_init();
- judgm_security_hook();
- judgm_syscall_hook();
-
- pr_alert("judgm:Init\n");
- return 0;
-}
-static void __exit mod_exit(){
- cdev_del(&mod_cdev);
- device_destroy(mod_class,mod_dev);
- class_destroy(mod_class);
- unregister_chrdev_region(mod_dev,1);
-
- judgm_proc_exit();
- judgm_syscall_unhook();
- judgm_security_unhook();
-
- pr_alert("judgm:Exit\n");
-}
-module_init(mod_init);
-module_exit(mod_exit);
-MODULE_LICENSE("GPL");
-
-static long mod_ioctl(struct file *file,unsigned int cmd,unsigned long arg){
- int ret;
-
- ret = -1;
- switch(cmd){
- case IOCTL_PROC_ADD:
- ret = judgm_proc_add(arg);
- break;
- case IOCTL_PROC_GET:
- ret = judgm_proc_get(arg);
- break;
- case IOCTL_PROC_KILL:
- ret = judgm_proc_kill(arg);
- break;
- case IOCTL_PROC_DEL:
- ret = judgm_proc_del(arg);
- break;
- }
-
- return ret;
-}
diff --git a/judge/judgm_mod.h b/judge/judgm_mod.h
deleted file mode 100644
index 5d7f509..0000000
--- a/judge/judgm_mod.h
+++ /dev/null
@@ -1,22 +0,0 @@
-static int __init mod_init(void);
-static void __exit mod_exit(void);
-static long mod_ioctl(struct file *file,unsigned int cmd,unsigned long arg);
-
-static dev_t mod_dev;
-static struct cdev mod_cdev;
-static struct class *mod_class;
-static struct file_operations mod_fops = {
- .owner = THIS_MODULE,
- .unlocked_ioctl = mod_ioctl
-};
-
-extern int judgm_proc_init(void);
-extern int judgm_proc_exit(void);
-extern int judgm_proc_add(unsigned long arg);
-extern int judgm_proc_get(unsigned long arg);
-extern int judgm_proc_kill(unsigned long arg);
-extern int judgm_proc_del(unsigned long arg);
-extern int judgm_syscall_hook(void);
-extern int judgm_syscall_unhook(void);
-extern int judgm_security_hook(void);
-extern int judgm_security_unhook(void);
diff --git a/judge/judgm_security.c b/judge/judgm_security.c
deleted file mode 100644
index a8ed14e..0000000
--- a/judge/judgm_security.c
+++ /dev/null
@@ -1,2298 +0,0 @@
-#include<linux/fs.h>
-#include<linux/security.h>
-#include<linux/sched.h>
-#include<asm/uaccess.h>
-
-#include"judge_def.h"
-#include"judgm.h"
-#include"judgx_com.h"
-#include"judgm_security.h"
-
-int judgm_security_hook(){
-
- security_hook_addr = security_get_addr();
-
- ori_sops = (struct security_operations*)*security_hook_addr;
- memcpy(&hook_sops,ori_sops,sizeof(struct security_operations));
-
- hook_sops.ptrace_access_check = hook_ptrace_access_check;
- hook_sops.ptrace_traceme = hook_ptrace_traceme;
- hook_sops.capget = hook_capget;
- hook_sops.capset = hook_capset;
- //hook_sops.capable = hook_capable;
- hook_sops.quotactl = hook_quotactl;
- hook_sops.quota_on = hook_quota_on;
- hook_sops.syslog = hook_syslog;
- hook_sops.settime = hook_settime;
- hook_sops.vm_enough_memory = hook_vm_enough_memory;
- //hook_sops.bprm_set_creds = hook_bprm_set_creds;
- //hook_sops.bprm_check_security = hook_bprm_check_security;
- //hook_sops.bprm_secureexec = hook_bprm_secureexec;
- hook_sops.sb_alloc_security = hook_sb_alloc_security;
- hook_sops.sb_copy_data = hook_sb_copy_data;
- hook_sops.sb_remount = hook_sb_remount;
- hook_sops.sb_kern_mount = hook_sb_kern_mount;
- hook_sops.sb_show_options = hook_sb_show_options;
- hook_sops.sb_statfs = hook_sb_statfs;
- hook_sops.sb_mount = hook_sb_mount;
- hook_sops.sb_umount = hook_sb_umount;
- hook_sops.sb_pivotroot = hook_sb_pivotroot;
- hook_sops.sb_set_mnt_opts = hook_sb_set_mnt_opts;
- hook_sops.sb_parse_opts_str = hook_sb_parse_opts_str;
- hook_sops.path_unlink = hook_path_unlink;
- hook_sops.path_mkdir = hook_path_mkdir;
- hook_sops.path_rmdir = hook_path_rmdir;
- hook_sops.path_mknod = hook_path_mknod;
- hook_sops.path_truncate = hook_path_truncate;
- hook_sops.path_symlink = hook_path_symlink;
- hook_sops.path_link = hook_path_link;
- hook_sops.path_rename = hook_path_rename;
- hook_sops.path_chmod = hook_path_chmod;
- hook_sops.path_chown = hook_path_chown;
- hook_sops.path_chroot = hook_path_chroot;
- //hook_sops.inode_alloc_security = hook_inode_alloc_security;
- hook_sops.inode_init_security = hook_inode_init_security;
- hook_sops.inode_create = hook_inode_create;
- hook_sops.inode_link = hook_inode_link;
- hook_sops.inode_unlink = hook_inode_unlink;
- hook_sops.inode_symlink = hook_inode_symlink;
- hook_sops.inode_mkdir = hook_inode_mkdir;
- hook_sops.inode_rmdir = hook_inode_rmdir;
- hook_sops.inode_mknod = hook_inode_mknod;
- hook_sops.inode_rename = hook_inode_rename;
- hook_sops.inode_readlink = hook_inode_readlink;
- //hook_sops.inode_follow_link = hook_inode_follow_link;
- hook_sops.inode_permission = hook_inode_permission;
- hook_sops.inode_setattr = hook_inode_setattr;
- //hook_sops.inode_getattr = hook_inode_getattr;
- hook_sops.inode_setxattr = hook_inode_setxattr;
- hook_sops.inode_getxattr = hook_inode_getxattr;
- hook_sops.inode_listxattr = hook_inode_listxattr;
- hook_sops.inode_removexattr = hook_inode_removexattr;
- hook_sops.inode_need_killpriv = hook_inode_need_killpriv;
- hook_sops.inode_killpriv = hook_inode_killpriv;
- hook_sops.inode_getsecurity = hook_inode_getsecurity;
- hook_sops.inode_setsecurity = hook_inode_setsecurity;
- hook_sops.inode_listsecurity = hook_inode_listsecurity;
- hook_sops.file_permission = hook_file_permission;
- //hook_sops.file_alloc_security = hook_file_alloc_security;
- hook_sops.file_ioctl = hook_file_ioctl;
- //hook_sops.mmap_addr = hook_mmap_addr;
- //hook_sops.mmap_file = hook_mmap_file;
- //hook_sops.file_mprotect = hook_file_mprotect;
- hook_sops.file_lock = hook_file_lock;
- hook_sops.file_fcntl = hook_file_fcntl;
- hook_sops.file_set_fowner = hook_file_set_fowner;
- hook_sops.file_send_sigiotask = hook_file_send_sigiotask;
- hook_sops.file_receive = hook_file_receive;
- hook_sops.file_open = hook_file_open;
- hook_sops.task_create = hook_task_create;
- hook_sops.cred_alloc_blank = hook_cred_alloc_blank;
- //hook_sops.cred_prepare = hook_cred_prepare;
- hook_sops.kernel_act_as = hook_kernel_act_as;
- hook_sops.kernel_create_files_as = hook_kernel_create_files_as;
- hook_sops.kernel_module_request = hook_kernel_module_request;
- hook_sops.task_fix_setuid = hook_task_fix_setuid;
- hook_sops.task_setpgid = hook_task_setpgid;
- hook_sops.task_getpgid = hook_task_getpgid;
- hook_sops.task_getsid = hook_task_getsid;
- hook_sops.task_setnice = hook_task_setnice;
- hook_sops.task_setioprio = hook_task_setioprio;
- hook_sops.task_getioprio = hook_task_getioprio;
- hook_sops.task_setrlimit = hook_task_setrlimit;
- hook_sops.task_setscheduler = hook_task_setscheduler;
- hook_sops.task_getscheduler = hook_task_getscheduler;
- hook_sops.task_movememory = hook_task_movememory;
- hook_sops.task_kill = hook_task_kill;
- hook_sops.task_wait = hook_task_wait;
- hook_sops.task_prctl = hook_task_prctl;
- hook_sops.ipc_permission = hook_ipc_permission;
- hook_sops.msg_msg_alloc_security = hook_msg_msg_alloc_security;
- hook_sops.msg_queue_alloc_security = hook_msg_queue_alloc_security;
- hook_sops.msg_queue_associate = hook_msg_queue_associate;
- hook_sops.msg_queue_msgctl = hook_msg_queue_msgctl;
- hook_sops.msg_queue_msgsnd = hook_msg_queue_msgsnd;
- hook_sops.msg_queue_msgrcv = hook_msg_queue_msgrcv;
- hook_sops.shm_alloc_security = hook_shm_alloc_security;
- hook_sops.shm_associate = hook_shm_associate;
- hook_sops.shm_shmctl = hook_shm_shmctl;
- hook_sops.shm_shmat = hook_shm_shmat;
- hook_sops.sem_alloc_security = hook_sem_alloc_security;
- hook_sops.sem_associate = hook_sem_associate;
- hook_sops.sem_semctl = hook_sem_semctl;
- hook_sops.sem_semop = hook_sem_semop;
- hook_sops.netlink_send = hook_netlink_send;
- hook_sops.getprocattr = hook_getprocattr;
- hook_sops.setprocattr = hook_setprocattr;
- hook_sops.secid_to_secctx = hook_secid_to_secctx;
- hook_sops.secctx_to_secid = hook_secctx_to_secid;
- hook_sops.inode_notifysecctx = hook_inode_notifysecctx;
- hook_sops.inode_setsecctx = hook_inode_setsecctx;
- hook_sops.inode_getsecctx = hook_inode_getsecctx;
- hook_sops.unix_stream_connect = hook_unix_stream_connect;
- hook_sops.unix_may_send = hook_unix_may_send;
- hook_sops.socket_create = hook_socket_create;
- hook_sops.socket_post_create = hook_socket_post_create;
- hook_sops.socket_bind = hook_socket_bind;
- hook_sops.socket_connect = hook_socket_connect;
- hook_sops.socket_listen = hook_socket_listen;
- hook_sops.socket_accept = hook_socket_accept;
- hook_sops.socket_sendmsg = hook_socket_sendmsg;
- hook_sops.socket_recvmsg = hook_socket_recvmsg;
- hook_sops.socket_getsockname = hook_socket_getsockname;
- hook_sops.socket_getpeername = hook_socket_getpeername;
- hook_sops.socket_getsockopt = hook_socket_getsockopt;
- hook_sops.socket_setsockopt = hook_socket_setsockopt;
- hook_sops.socket_shutdown = hook_socket_shutdown;
- //hook_sops.socket_sock_rcv_skb = hook_socket_sock_rcv_skb;
- hook_sops.socket_getpeersec_stream = hook_socket_getpeersec_stream;
- hook_sops.socket_getpeersec_dgram = hook_socket_getpeersec_dgram;
- //hook_sops.sk_alloc_security = hook_sk_alloc_security;
- //hook_sops.inet_conn_request = hook_inet_conn_request;
- hook_sops.secmark_relabel_packet = hook_secmark_relabel_packet;
- hook_sops.tun_dev_create = hook_tun_dev_create;
- hook_sops.tun_dev_attach = hook_tun_dev_attach;
- hook_sops.key_alloc = hook_key_alloc;
- hook_sops.key_permission = hook_key_permission;
- hook_sops.key_getsecurity = hook_key_getsecurity;
- hook_sops.audit_rule_init = hook_audit_rule_init;
- hook_sops.audit_rule_known = hook_audit_rule_known;
- hook_sops.audit_rule_match = hook_audit_rule_match;
-
- *security_hook_addr = (unsigned long)&hook_sops;
-
- return 0;
-}
-int judgm_security_unhook(){
- *security_hook_addr = (unsigned long)ori_sops;
- return 0;
-}
-
-static unsigned long* security_get_addr(){
- ssize_t ret;
- int i;
- int j;
-
- struct file *f;
- char line[128];
- unsigned char code[3] = {0x48,0xc7,0x05};
- unsigned long addr;
-
- f = filp_open("/proc/kallsyms",O_RDONLY,0);
- set_fs(KERNEL_DS);
-
- i = 0;
- addr = 0;
- while(true){
- ret = f->f_op->read(f,&line[i],1,&f->f_pos);
-
- if(line[i] == '\n' || ret <= 0){
- line[i] = '\0';
-
- addr = 0;
- for(j = 0;j < i;j++){
- if(line[j] == ' '){
- j++;
- break;
- }
-
- addr *= 16UL;
- if(line[j] >= '0' && line[j] <= '9'){
- addr += (unsigned long)(line[j] - '0');
- }else{
- addr += (unsigned long)(line[j] - 'a' + 10);
- }
- }
- for(;j < i;j++){
- if(line[j] == ' '){
- j++;
- break;
- }
- }
- if(j < i){
- if(strcmp("reset_security_ops",line + j) == 0){
- break;
- }
- }
-
- i = 0;
- }else{
- i++;
- }
-
- if(ret <= 0){
- break;
- }
- }
-
- set_fs(USER_DS);
- filp_close(f,NULL);
-
- i = 0;
- while(i < 3){
- if(*(unsigned char*)addr != code[i]){
- i = 0;
- }else{
- i++;
- }
- addr++;
- }
-
- return (unsigned long*)(addr + (unsigned long)*(u32*)addr + 8UL);
-}
-
-static int hook_inode_permission(struct inode *inode,int mask){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_permission(inode,mask);
- }
-
- pr_alert("judgm:PID %d inode_permission %08x\n",current->tgid,mask);
-
- if((mask & ~(MAY_EXEC | MAY_READ | MAY_OPEN | MAY_CHDIR | MAY_NOT_BLOCK)) != 0){
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }
- return ori_sops->inode_permission(inode,mask);
-}
-static int hook_file_open(struct file *file, const struct cred *cred){
- int ret;
- int i;
-
- struct judgm_proc_info *info;
- char *buf_path,*path;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_open(file,cred);
- }
-
- ret = 0;
-
- buf_path = kmalloc(sizeof(char) * (PATH_MAX + 1),GFP_KERNEL);
- path = d_path(&file->f_path,buf_path,PATH_MAX + 1);
-
- pr_alert("judgm:PID %d file_open %s %08x\n",current->tgid,path,file->f_mode);
-
- if((file->f_mode & !(FMODE_READ | FMODE_LSEEK | FMODE_PREAD | FMODE_EXEC)) != 0){
- ret = -EACCES;
- }else if(strcmp(path,"/proc/meminfo") != 0){
- i = 0;
- while(info->run_path[i] != '\0'){
- if(path[i] != info->run_path[i]){
- ret = -EACCES;
- break;
- }
- i++;
- }
- if(path[i] == info->run_path[i]){
- ret = -EACCES;
- }
- }
-
- kfree(buf_path);
-
- if(ret != 0){
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return ret;
- }
- return ori_sops->file_open(file,cred);
-}
-static int hook_file_permission(struct file *file,int mask){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_permission(file,mask);
- }
-
- /*buf_path = kmalloc(sizeof(char) * (PATH_MAX + 1),GFP_KERNEL);
- path = d_path(&file->f_path,buf_path,PATH_MAX + 1);
-
- pr_alert("judgm:PID %d file_permission %s %08x\n",current->tgid,path,mask);
-
- kfree(buf_path);*/
-
- if((mask & ~(MAY_READ | MAY_WRITE)) != 0){
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }else if((mask & MAY_WRITE) != 0 && file != info->pout){
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }
- return ori_sops->file_permission(file,mask);
-}
-static int hook_vm_enough_memory(struct mm_struct *mm,long pages){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->vm_enough_memory(mm,pages);
- }
-
- info->peakmem = (mm->total_vm + pages) << PAGE_SHIFT;
- pr_alert("judgm:PID %d vm_enough_memory %lu\n",current->tgid,info->peakmem);
-
- if(info->peakmem > info->memlimit){
- info->status = JUDGE_MLE;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }
- return ori_sops->vm_enough_memory(mm,pages);
-}
-
-
-
-
-static int hook_ptrace_access_check(struct task_struct *child,unsigned int mode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->ptrace_access_check(child,mode);
- }
-
- pr_alert("judgm:PID %d ptrace_access_check\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_ptrace_traceme(struct task_struct *parent){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->ptrace_traceme(parent);
- }
-
- pr_alert("judgm:PID %d ptrace_traceme\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_capget(struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->capget(target,effective,inheritable,permitted);
- }
-
- pr_alert("judgm:PID %d capget\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_capset(struct cred *new,const struct cred *old,const kernel_cap_t *effective,const kernel_cap_t *inheritable,const kernel_cap_t *permitted){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->capset(new,old,effective,inheritable,permitted);
- }
-
- pr_alert("judgm:PID %d capset\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_capable(const struct cred *cred,struct user_namespace *ns,int cap,int audit){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->capable(cred,ns,cap,audit);
- }
-
- pr_alert("judgm:PID %d capable\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_quotactl(int cmds,int type,int id,struct super_block *sb){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->quotactl(cmds,type,id,sb);
- }
-
- pr_alert("judgm:PID %d quotactl\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_quota_on(struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->quota_on(dentry);
- }
-
- pr_alert("judgm:PID %d quota_on\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_syslog(int type){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->syslog(type);
- }
-
- pr_alert("judgm:PID %d syslog\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_settime(const struct timespec *ts,const struct timezone *tz){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->settime(ts,tz);
- }
-
- pr_alert("judgm:PID %d settime\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_bprm_set_creds(struct linux_binprm *bprm){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->bprm_set_creds(bprm);
- }
-
- pr_alert("judgm:PID %d bprm_set_creds\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-/*static int hook_bprm_check_security(struct linux_binprm *bprm){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->bprm_check_security(bprm);
- }
-
- pr_alert("judgm:PID %d bprm_check_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-/*static int hook_bprm_secureexec(struct linux_binprm *bprm){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->bprm_secureexec(bprm);
- }
-
- pr_alert("judgm:PID %d bprm_secureexec\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_sb_alloc_security(struct super_block *sb){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_alloc_security(sb);
- }
-
- pr_alert("judgm:PID %d sb_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_copy_data(char *orig,char *copy){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_copy_data(orig,copy);
- }
-
- pr_alert("judgm:PID %d sb_copy_data\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_remount(struct super_block *sb,void *data){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_remount(sb,data);
- }
-
- pr_alert("judgm:PID %d sb_remount\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_kern_mount(struct super_block *sb,int flags,void *data){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_kern_mount(sb,flags,data);
- }
-
- pr_alert("judgm:PID %d sb_kern_mount\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_show_options(struct seq_file *m,struct super_block *sb){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_show_options(m,sb);
- }
-
- pr_alert("judgm:PID %d sb_show_options\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_statfs(struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_statfs(dentry);
- }
-
- pr_alert("judgm:PID %d sb_statfs\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_mount(char *dev_name,struct path *path,char *type,unsigned long flags,void *data){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_mount(dev_name,path,type,flags,data);
- }
-
- pr_alert("judgm:PID %d sb_mount\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_umount(struct vfsmount *mnt,int flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_umount(mnt,flags);
- }
-
- pr_alert("judgm:PID %d sb_umount\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_pivotroot(struct path *old_path,struct path *new_path){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_pivotroot(old_path,new_path);
- }
-
- pr_alert("judgm:PID %d sb_pivotroot\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_set_mnt_opts(struct super_block *sb,struct security_mnt_opts *opts){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_set_mnt_opts(sb,opts);
- }
-
- pr_alert("judgm:PID %d sb_set_mnt_opts\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sb_parse_opts_str(char *options,struct security_mnt_opts *opts){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sb_parse_opts_str(options,opts);
- }
-
- pr_alert("judgm:PID %d sb_parse_opts_str\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_unlink(struct path *dir,struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_unlink(dir,dentry);
- }
-
- pr_alert("judgm:PID %d path_unlink\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_mkdir(struct path *dir,struct dentry *dentry,umode_t mode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_mkdir(dir,dentry,mode);
- }
-
- pr_alert("judgm:PID %d path_mkdir\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_rmdir(struct path *dir,struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_rmdir(dir,dentry);
- }
-
- pr_alert("judgm:PID %d path_rmdir\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_mknod(struct path *dir,struct dentry *dentry,umode_t mode,unsigned int dev){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_mknod(dir,dentry,mode,dev);
- }
-
- pr_alert("judgm:PID %d path_mknod\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_truncate(struct path *path){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_truncate(path);
- }
-
- pr_alert("judgm:PID %d path_truncate\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_symlink(struct path *dir,struct dentry *dentry,const char *old_name){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_symlink(dir,dentry,old_name);
- }
-
- pr_alert("judgm:PID %d path_symlink\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_link(struct dentry *old_dentry,struct path *new_dir,struct dentry *new_dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_link(old_dentry,new_dir,new_dentry);
- }
-
- pr_alert("judgm:PID %d path_link\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_rename(struct path *old_dir,struct dentry *old_dentry,struct path *new_dir,struct dentry *new_dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_rename(old_dir,old_dentry,new_dir,new_dentry);
- }
-
- pr_alert("judgm:PID %d path_rename\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_chmod(struct path *path,umode_t mode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_chmod(path,mode);
- }
-
- pr_alert("judgm:PID %d path_chmod\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_chown(struct path *path,uid_t uid,gid_t gid){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_chown(path,uid,gid);
- }
-
- pr_alert("judgm:PID %d path_chown\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_path_chroot(struct path *path){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->path_chroot(path);
- }
-
- pr_alert("judgm:PID %d path_chroot\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_inode_alloc_security(struct inode *inode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_alloc_security(inode);
- }
-
- pr_alert("judgm:PID %d inode_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_inode_init_security(struct inode *inode,struct inode *dir,const struct qstr *qstr,char **name,void **value,size_t *len){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_init_security(inode,dir,qstr,name,value,len);
- }
-
- pr_alert("judgm:PID %d inode_init_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_create(struct inode *dir,struct dentry *dentry,umode_t mode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_create(dir,dentry,mode);
- }
-
- pr_alert("judgm:PID %d inode_create\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_link(struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_link(old_dentry,dir,new_dentry);
- }
-
- pr_alert("judgm:PID %d inode_link\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_unlink(struct inode *dir,struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_unlink(dir,dentry);
- }
-
- pr_alert("judgm:PID %d inode_unlink\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_symlink(struct inode *dir,struct dentry *dentry,const char *old_name){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_symlink(dir,dentry,old_name);
- }
-
- pr_alert("judgm:PID %d inode_symlink\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_mkdir(struct inode *dir,struct dentry *dentry,umode_t mode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_mkdir(dir,dentry,mode);
- }
-
- pr_alert("judgm:PID %d inode_mkdir\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_rmdir(struct inode *dir,struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_rmdir(dir,dentry);
- }
-
- pr_alert("judgm:PID %d inode_rmdir\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_mknod(struct inode *dir,struct dentry *dentry,umode_t mode,dev_t dev){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_mknod(dir,dentry,mode,dev);
- }
-
- pr_alert("judgm:PID %d inode_mknod\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_rename(struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_rename(old_dir,old_dentry,new_dir,new_dentry);
- }
-
- pr_alert("judgm:PID %d inode_rename\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_readlink(struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_readlink(dentry);
- }
-
- pr_alert("judgm:PID %d inode_readlink\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_inode_follow_link(struct dentry *dentry,struct nameidata *nd){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_follow_link(dentry,nd);
- }
-
- pr_alert("judgm:PID %d inode_follow_link\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_inode_setattr(struct dentry *dentry,struct iattr *attr){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_setattr(dentry,attr);
- }
-
- pr_alert("judgm:PID %d inode_setattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_inode_getattr(struct vfsmount *mnt,struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_getattr(mnt,dentry);
- }
-
- pr_alert("judgm:PID %d inode_getattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_inode_setxattr(struct dentry *dentry,const char *name,const void *value,size_t size,int flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_setxattr(dentry,name,value,size,flags);
- }
-
- pr_alert("judgm:PID %d inode_setxattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_getxattr(struct dentry *dentry,const char *name){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_getxattr(dentry,name);
- }
-
- pr_alert("judgm:PID %d inode_getxattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_listxattr(struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_listxattr(dentry);
- }
-
- pr_alert("judgm:PID %d inode_listxattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_removexattr(struct dentry *dentry,const char *name){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_removexattr(dentry,name);
- }
-
- pr_alert("judgm:PID %d inode_removexattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_need_killpriv(struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_need_killpriv(dentry);
- }
-
- pr_alert("judgm:PID %d inode_need_killpriv\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_killpriv(struct dentry *dentry){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_killpriv(dentry);
- }
-
- pr_alert("judgm:PID %d inode_killpriv\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_getsecurity(const struct inode *inode,const char *name,void **buffer,bool alloc){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_getsecurity(inode,name,buffer,alloc);
- }
-
- pr_alert("judgm:PID %d inode_getsecurity\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_setsecurity(struct inode *inode,const char *name,const void *value,size_t size,int flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_setsecurity(inode,name,value,size,flags);
- }
-
- pr_alert("judgm:PID %d inode_setsecurity\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_listsecurity(struct inode *inode,char *buffer,size_t buffer_size){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_listsecurity(inode,buffer,buffer_size);
- }
-
- pr_alert("judgm:PID %d inode_listsecurity\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_file_alloc_security(struct file *file){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_alloc_security(file);
- }
-
- pr_alert("judgm:PID %d file_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_file_ioctl(struct file *file,unsigned int cmd,unsigned long arg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_ioctl(file,cmd,arg);
- }
-
- pr_alert("judgm:PID %d file_ioctl\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_mmap_addr(unsigned long addr){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->mmap_addr(addr);
- }
-
- pr_alert("judgm:PID %d mmap_addr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-/*static int hook_mmap_file(struct file *file,unsigned long reqprot,unsigned long prot,unsigned long flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->mmap_file(file,reqprot,prot,flags);
- }
-
- pr_alert("judgm:PID %d mmap_file\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-/*static int hook_file_mprotect(struct vm_area_struct *vma,unsigned long reqprot,unsigned long prot){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_mprotect(vma,reqprot,prot);
- }
-
- pr_alert("judgm:PID %d file_mprotect\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_file_lock(struct file *file,unsigned int cmd){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_lock(file,cmd);
- }
-
- pr_alert("judgm:PID %d file_lock\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_file_fcntl(struct file *file,unsigned int cmd,unsigned long arg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_fcntl(file,cmd,arg);
- }
-
- pr_alert("judgm:PID %d file_fcntl\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_file_set_fowner(struct file *file){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_set_fowner(file);
- }
-
- pr_alert("judgm:PID %d file_set_fowner\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_file_send_sigiotask(struct task_struct *tsk,struct fown_struct *fown,int sig){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_send_sigiotask(tsk,fown,sig);
- }
-
- pr_alert("judgm:PID %d file_send_sigiotask\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_file_receive(struct file *file){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->file_receive(file);
- }
-
- pr_alert("judgm:PID %d file_receive\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_create(unsigned long clone_flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_create(clone_flags);
- }
-
- pr_alert("judgm:PID %d task_create\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_cred_alloc_blank(struct cred *cred,gfp_t gfp){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->cred_alloc_blank(cred,gfp);
- }
-
- pr_alert("judgm:PID %d cred_alloc_blank\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-/*static int hook_cred_prepare(struct cred *new,const struct cred *old,gfp_t gfp){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->cred_prepare(new,old,gfp);
- }
-
- pr_alert("judgm:PID %d cred_prepare\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
- }*/
-static int hook_kernel_act_as(struct cred *new,u32 secid){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->kernel_act_as(new,secid);
- }
-
- pr_alert("judgm:PID %d kernel_act_as\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_kernel_create_files_as(struct cred *new,struct inode *inode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->kernel_create_files_as(new,inode);
- }
-
- pr_alert("judgm:PID %d kernel_create_files_as\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_kernel_module_request(char *kmod_name){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->kernel_module_request(kmod_name);
- }
-
- pr_alert("judgm:PID %d kernel_module_request\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_fix_setuid(struct cred *new,const struct cred *old,int flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_fix_setuid(new,old,flags);
- }
-
- pr_alert("judgm:PID %d task_fix_setuid\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_setpgid(struct task_struct *p,pid_t pgid){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_setpgid(p,pgid);
- }
-
- pr_alert("judgm:PID %d task_setpgid\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_getpgid(struct task_struct *p){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_getpgid(p);
- }
-
- pr_alert("judgm:PID %d task_getpgid\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_getsid(struct task_struct *p){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_getsid(p);
- }
-
- pr_alert("judgm:PID %d task_getsid\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_setnice(struct task_struct *p,int nice){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_setnice(p,nice);
- }
-
- pr_alert("judgm:PID %d task_setnice\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_setioprio(struct task_struct *p,int ioprio){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_setioprio(p,ioprio);
- }
-
- pr_alert("judgm:PID %d task_setioprio\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_getioprio(struct task_struct *p){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_getioprio(p);
- }
-
- pr_alert("judgm:PID %d task_getioprio\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_setrlimit(struct task_struct *p,unsigned int resource,struct rlimit *new_rlim){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_setrlimit(p,resource,new_rlim);
- }
-
- pr_alert("judgm:PID %d task_setrlimit\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_setscheduler(struct task_struct *p){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_setscheduler(p);
- }
-
- pr_alert("judgm:PID %d task_setscheduler\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_getscheduler(struct task_struct *p){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_getscheduler(p);
- }
-
- pr_alert("judgm:PID %d task_getscheduler\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_movememory(struct task_struct *p){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_movememory(p);
- }
-
- pr_alert("judgm:PID %d task_movememory\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_kill(struct task_struct *p,struct siginfo *siginfo,int sig,u32 secid){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_kill(p,siginfo,sig,secid);
- }
-
- pr_alert("judgm:PID %d task_kill\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_wait(struct task_struct *p){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_wait(p);
- }
-
- pr_alert("judgm:PID %d task_wait\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_task_prctl(int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->task_prctl(option,arg2,arg3,arg4,arg5);
- }
-
- pr_alert("judgm:PID %d task_prctl\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_ipc_permission(struct kern_ipc_perm *ipcp,short flag){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->ipc_permission(ipcp,flag);
- }
-
- pr_alert("judgm:PID %d ipc_permission\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_msg_msg_alloc_security(struct msg_msg *msg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->msg_msg_alloc_security(msg);
- }
-
- pr_alert("judgm:PID %d msg_msg_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_msg_queue_alloc_security(struct msg_queue *msq){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->msg_queue_alloc_security(msq);
- }
-
- pr_alert("judgm:PID %d msg_queue_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_msg_queue_associate(struct msg_queue *msq,int msqflg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->msg_queue_associate(msq,msqflg);
- }
-
- pr_alert("judgm:PID %d msg_queue_associate\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_msg_queue_msgctl(struct msg_queue *msq,int cmd){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->msg_queue_msgctl(msq,cmd);
- }
-
- pr_alert("judgm:PID %d msg_queue_msgctl\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_msg_queue_msgsnd(struct msg_queue *msq,struct msg_msg *msg,int msqflg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->msg_queue_msgsnd(msq,msg,msqflg);
- }
-
- pr_alert("judgm:PID %d msg_queue_msgsnd\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_msg_queue_msgrcv(struct msg_queue *msq,struct msg_msg *msg,struct task_struct *target,long type,int mode){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->msg_queue_msgrcv(msq,msg,target,type,mode);
- }
-
- pr_alert("judgm:PID %d msg_queue_msgrcv\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_shm_alloc_security(struct shmid_kernel *shp){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->shm_alloc_security(shp);
- }
-
- pr_alert("judgm:PID %d shm_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_shm_associate(struct shmid_kernel *shp,int shmflg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->shm_associate(shp,shmflg);
- }
-
- pr_alert("judgm:PID %d shm_associate\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_shm_shmctl(struct shmid_kernel *shp,int cmd){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->shm_shmctl(shp,cmd);
- }
-
- pr_alert("judgm:PID %d shm_shmctl\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_shm_shmat(struct shmid_kernel *shp,char __user *shmaddr,int shmflg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->shm_shmat(shp,shmaddr,shmflg);
- }
-
- pr_alert("judgm:PID %d shm_shmat\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sem_alloc_security(struct sem_array *sma){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sem_alloc_security(sma);
- }
-
- pr_alert("judgm:PID %d sem_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sem_associate(struct sem_array *sma,int semflg){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sem_associate(sma,semflg);
- }
-
- pr_alert("judgm:PID %d sem_associate\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sem_semctl(struct sem_array *sma,int cmd){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sem_semctl(sma,cmd);
- }
-
- pr_alert("judgm:PID %d sem_semctl\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sem_semop(struct sem_array *sma,struct sembuf *sops,unsigned nsops,int alter){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sem_semop(sma,sops,nsops,alter);
- }
-
- pr_alert("judgm:PID %d sem_semop\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_netlink_send(struct sock *sk,struct sk_buff *skb){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->netlink_send(sk,skb);
- }
-
- pr_alert("judgm:PID %d netlink_send\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_getprocattr(struct task_struct *p,char *name,char **value){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->getprocattr(p,name,value);
- }
-
- pr_alert("judgm:PID %d getprocattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_setprocattr(struct task_struct *p,char *name,void *value,size_t size){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->setprocattr(p,name,value,size);
- }
-
- pr_alert("judgm:PID %d setprocattr\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_secid_to_secctx(u32 secid,char **secdata,u32 *seclen){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->secid_to_secctx(secid,secdata,seclen);
- }
-
- pr_alert("judgm:PID %d secid_to_secctx\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_secctx_to_secid(const char *secdata,u32 seclen,u32 *secid){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->secctx_to_secid(secdata,seclen,secid);
- }
-
- pr_alert("judgm:PID %d secctx_to_secid\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_notifysecctx(struct inode *inode,void *ctx,u32 ctxlen){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_notifysecctx(inode,ctx,ctxlen);
- }
-
- pr_alert("judgm:PID %d inode_notifysecctx\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_setsecctx(struct dentry *dentry,void *ctx,u32 ctxlen){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_setsecctx(dentry,ctx,ctxlen);
- }
-
- pr_alert("judgm:PID %d inode_setsecctx\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inode_getsecctx(struct inode *inode,void **ctx,u32 *ctxlen){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inode_getsecctx(inode,ctx,ctxlen);
- }
-
- pr_alert("judgm:PID %d inode_getsecctx\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_unix_stream_connect(struct sock *sock,struct sock *other,struct sock *newsk){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->unix_stream_connect(sock,other,newsk);
- }
-
- pr_alert("judgm:PID %d unix_stream_connect\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_unix_may_send(struct socket *sock,struct socket *other){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->unix_may_send(sock,other);
- }
-
- pr_alert("judgm:PID %d unix_may_send\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_create(int family,int type,int protocol,int kern){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_create(family,type,protocol,kern);
- }
-
- pr_alert("judgm:PID %d socket_create\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_post_create(struct socket *sock,int family,int type,int protocol,int kern){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_post_create(sock,family,type,protocol,kern);
- }
-
- pr_alert("judgm:PID %d socket_post_create\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_bind(struct socket *sock,struct sockaddr *address,int addrlen){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_bind(sock,address,addrlen);
- }
-
- pr_alert("judgm:PID %d socket_bind\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_connect(struct socket *sock,struct sockaddr *address,int addrlen){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_connect(sock,address,addrlen);
- }
-
- pr_alert("judgm:PID %d socket_connect\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_listen(struct socket *sock,int backlog){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_listen(sock,backlog);
- }
-
- pr_alert("judgm:PID %d socket_listen\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_accept(struct socket *sock,struct socket *newsock){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_accept(sock,newsock);
- }
-
- pr_alert("judgm:PID %d socket_accept\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_sendmsg(struct socket *sock,struct msghdr *msg,int size){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_sendmsg(sock,msg,size);
- }
-
- pr_alert("judgm:PID %d socket_sendmsg\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_recvmsg(struct socket *sock,struct msghdr *msg,int size,int flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_recvmsg(sock,msg,size,flags);
- }
-
- pr_alert("judgm:PID %d socket_recvmsg\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_getsockname(struct socket *sock){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_getsockname(sock);
- }
-
- pr_alert("judgm:PID %d socket_getsockname\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_getpeername(struct socket *sock){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_getpeername(sock);
- }
-
- pr_alert("judgm:PID %d socket_getpeername\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_getsockopt(struct socket *sock,int level,int optname){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_getsockopt(sock,level,optname);
- }
-
- pr_alert("judgm:PID %d socket_getsockopt\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_setsockopt(struct socket *sock,int level,int optname){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_setsockopt(sock,level,optname);
- }
-
- pr_alert("judgm:PID %d socket_setsockopt\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_shutdown(struct socket *sock,int how){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_shutdown(sock,how);
- }
-
- pr_alert("judgm:PID %d socket_shutdown\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_sock_rcv_skb(struct sock *sk,struct sk_buff *skb){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_sock_rcv_skb(sk,skb);
- }
-
- pr_alert("judgm:PID %d socket_sock_rcv_skb\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_getpeersec_stream(struct socket *sock,char __user *optval,int __user *optlen,unsigned len){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_getpeersec_stream(sock,optval,optlen,len);
- }
-
- pr_alert("judgm:PID %d socket_getpeersec_stream\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_socket_getpeersec_dgram(struct socket *sock,struct sk_buff *skb,u32 *secid){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->socket_getpeersec_dgram(sock,skb,secid);
- }
-
- pr_alert("judgm:PID %d socket_getpeersec_dgram\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_sk_alloc_security(struct sock *sk,int family,gfp_t priority){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->sk_alloc_security(sk,family,priority);
- }
-
- pr_alert("judgm:PID %d sk_alloc_security\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_inet_conn_request(struct sock *sk,struct sk_buff *skb,struct request_sock *req){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->inet_conn_request(sk,skb,req);
- }
-
- pr_alert("judgm:PID %d inet_conn_request\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_secmark_relabel_packet(u32 secid){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->secmark_relabel_packet(secid);
- }
-
- pr_alert("judgm:PID %d secmark_relabel_packet\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_tun_dev_create(void){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->tun_dev_create();
- }
-
- pr_alert("judgm:PID %d tun_dev_create\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_tun_dev_attach(struct sock *sk){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->tun_dev_attach(sk);
- }
-
- pr_alert("judgm:PID %d tun_dev_attach\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_key_alloc(struct key *key,const struct cred *cred,unsigned long flags){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->key_alloc(key,cred,flags);
- }
-
- pr_alert("judgm:PID %d key_alloc\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_key_permission(key_ref_t key_ref,const struct cred *cred,key_perm_t perm){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->key_permission(key_ref,cred,perm);
- }
-
- pr_alert("judgm:PID %d key_permission\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_key_getsecurity(struct key *key,char **_buffer){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->key_getsecurity(key,_buffer);
- }
-
- pr_alert("judgm:PID %d key_getsecurity\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_audit_rule_init(u32 field,u32 op,char *rulestr,void **lsmrule){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->audit_rule_init(field,op,rulestr,lsmrule);
- }
-
- pr_alert("judgm:PID %d audit_rule_init\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_audit_rule_known(struct audit_krule *krule){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->audit_rule_known(krule);
- }
-
- pr_alert("judgm:PID %d audit_rule_known\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
-static int hook_audit_rule_match(u32 secid,u32 field,u32 op,void *lsmrule,struct audit_context *actx){
- struct judgm_proc_info *info;
-
- info = judgm_proc_task_lookup(current);
- if(info == NULL){
- return ori_sops->audit_rule_match(secid,field,op,lsmrule,actx);
- }
-
- pr_alert("judgm:PID %d audit_rule_match\n",current->tgid);
-
- info->status = JUDGE_RF;
- send_sig(SIGKILL,current,0);
- return -EACCES;
-}
diff --git a/judge/judgx.h b/judge/judgx.h
deleted file mode 100644
index b1df863..0000000
--- a/judge/judgx.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#define DLL_PUBLIC __attribute__ ((visibility ("default")))
-
-struct judgx_proc_info{
- int status;
- unsigned long runtime;
- unsigned long peakmem;
-
- char run_path[PATH_MAX + 1];
- char exe_path[PATH_MAX + 1];
- char exe_name[NAME_MAX + 1];
- unsigned long pid;
- unsigned long task;
-
- unsigned long timelimit;
- unsigned long hardtimelimit;
- unsigned long memlimit;
-};
-
-typedef void (*judgx_ini_handler)(void *data,char *section,char *key,char *value);
-typedef void (*judgx_check_run_fn)(void);
-
-extern int judgx_ini_load(FILE *f,judgx_ini_handler handler,void *data);
-extern int judgx_compile(char *cpppath,char *exepath,char *arg);
-extern struct judgx_proc_info* judgx_proc_create(char *runpath,char *exepath,unsigned long timelimit,unsigned long hardtimelimit,unsigned long memlimit);
-extern int judgx_proc_run(struct judgx_proc_info *proc_info,judgx_check_run_fn check_run);
-extern int judgx_proc_kill(struct judgx_proc_info *proc_info);
-extern int judgx_proc_free(struct judgx_proc_info *proc_info);
diff --git a/judge/judgx_com.h b/judge/judgx_com.h
deleted file mode 100644
index 80efc12..0000000
--- a/judge/judgx_com.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#define IOCTL_PROC_ADD _IOWR('x',0x0,int)
-#define IOCTL_PROC_GET _IOWR('x',0x1,int)
-#define IOCTL_PROC_KILL _IOR('x',0x2,int)
-#define IOCTL_PROC_DEL _IOR('x',0x3,int)
-
-struct judgx_com_proc_add{
- char run_path[PATH_MAX + 1];
- unsigned long pid;
- unsigned long task;
- unsigned long timelimit;
- unsigned long hardtimelimit;
- unsigned long memlimit;
-};
-struct judgx_com_proc_get{
- unsigned long task;
- int status;
- unsigned long runtime;
- unsigned long peakmem;
-};
diff --git a/judge/judgx_lib.c b/judge/judgx_lib.c
deleted file mode 100644
index 32f5d04..0000000
--- a/judge/judgx_lib.c
+++ /dev/null
@@ -1,287 +0,0 @@
-#define _XOPEN_SOURCE 500
-
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<fcntl.h>
-#include<dlfcn.h>
-#include<limits.h>
-#include<signal.h>
-#include<ftw.h>
-#include<sys/ioctl.h>
-#include<sys/capability.h>
-#include<sys/resource.h>
-#include<sys/stat.h>
-
-#include"judge_def.h"
-#include"judgx.h"
-#include"judgx_com.h"
-#include"judgx_lib.h"
-
-static __attribute__((constructor)) void judgx_init(){
- judgx_modfd = open("/dev/judgm",O_RDWR);
- return;
-}
-static __attribute__((destructor)) void judgx_exit(){
- close(judgx_modfd);
- return;
-}
-
-DLL_PUBLIC int judgx_ini_load(FILE *f,judgx_ini_handler handler,void *data){
- int i;
- int j;
-
- char *buf;
- int l;
- char *section;
- char *key;
- char *value;
-
- buf = malloc(1024);
- section = malloc(1024);
- key = malloc(1024);
- value = malloc(1024);
-
- while(fgets(buf,1024,f) != NULL){
- l = strlen(buf);
- if(buf[l - 1] == '\n'){
- buf[l - 1] = '\0';
- }
- if(buf[0] == '\0'){
- continue;
- }
- if(buf[0] == '['){
- for(i = 1,j = 0;i < l && buf[i] != ']';i++,j++){
- section[j] = buf[i];
- }
- section[j] = '\0';
- }else{
- for(i = 0,j = 0;i < l && buf[i] != '=';i++,j++){
- key[j] = buf[i];
- }
- key[j] = '\0';
- for(i += 1,j = 0;i < l;i++,j++){
- value[j] = buf[i];
- }
- value[j] = '\0';
- handler(data,section,key,value);
- }
- }
-
- free(buf);
- free(section);
- free(key);
- free(value);
-
- return 0;
-}
-
-DLL_PUBLIC int judgx_compile(char *cpppath,char *exepath,char *arg){
- int pid;
- int waitstatus;
-
- if((pid = fork()) == 0){
- char *argv[] = {"g++","-static","-O2",cpppath,"-lrt","-o",exepath,NULL};
-
- freopen("/dev/null","w",stdout);
- freopen("/dev/null","w",stderr);
-
- execvp("g++",argv);
- }
- waitpid(pid,&waitstatus,0);
- if(waitstatus != 0){
- return JUDGE_CE;
- }
- return 0;
-}
-
-DLL_PUBLIC struct judgx_proc_info* judgx_proc_create(char *runpath,char *exepath,unsigned long timelimit,unsigned long hardtimelimit,unsigned long memlimit){
- int ret;
- int i,j;
-
- struct stat st;
- struct judgx_proc_info *proc_info;
-
- if(stat(exepath,&st)){
- return NULL;
- }
- if(!S_ISREG(st.st_mode)){
- return NULL;
- }
-
- proc_info = malloc(sizeof(struct judgx_proc_info));
- if(proc_info == NULL){
- goto error;
- }
-
- proc_info->run_path[0] = '\0';
- strncat(proc_info->run_path,runpath,sizeof(proc_info->run_path));
- proc_info->exe_path[0] = '\0';
- strncat(proc_info->exe_path,exepath,sizeof(proc_info->exe_path));
-
- proc_info->exe_name[NAME_MAX] = '\0';
- for(i = 0,j = 0;proc_info->exe_path[i] != '\0' && j < NAME_MAX;i++){
- if(proc_info->exe_path[i] == '/'){
- j = 0;
- }else{
- proc_info->exe_name[j] = proc_info->exe_path[i];
- j++;
- }
- }
- proc_info->status = JUDGE_ERR;
- proc_info->exe_name[j] = '\0';
- proc_info->pid = -1;
- proc_info->task = -1;
- proc_info->timelimit = timelimit;
- proc_info->hardtimelimit = hardtimelimit;
- proc_info->memlimit = memlimit;
- proc_info->runtime = 0L;
- proc_info->peakmem = 0L;
-
- return proc_info;
-
-error:
-
- if(proc_info != NULL){
- free(proc_info);
- }
-
- return NULL;
-}
-static int proc_protect(struct judgx_proc_info *proc_info){
- cap_t caps;
- struct rlimit limit;
- struct judgx_com_proc_add com_proc_add;
-
- /*caps = cap_init();
- if(cap_set_file(proc_info->path,caps)){
- cap_free(caps);
- goto error;
- }
- cap_free(caps);*/
-
- limit.rlim_cur = 1;
- limit.rlim_max = limit.rlim_cur;
- prlimit(proc_info->pid,RLIMIT_NPROC,&limit,NULL);
-
- limit.rlim_cur = 8L;
- limit.rlim_max = limit.rlim_cur;
- prlimit(proc_info->pid,RLIMIT_NOFILE,&limit,NULL);
-
- /*limit.rlim_cur = (proc_info->timelimit) / 1000L * 2;
- limit.rlim_max = limit.rlim_cur;
- prlimit(proc_info->pid,RLIMIT_CPU,&limit,NULL);*/
-
- /*limit.rlim_cur = proc_info->memlimit * 1024L + 4096L * 128L;
- limit.rlim_max = limit.rlim_cur;
- prlimit(proc_info->pid,RLIMIT_AS,&limit,NULL);*/
-
- com_proc_add.run_path[0] = '\0';
- strncat(com_proc_add.run_path,proc_info->run_path,sizeof(com_proc_add.run_path));
- com_proc_add.pid = proc_info->pid;
- com_proc_add.timelimit = proc_info->timelimit * 1000L;
- com_proc_add.hardtimelimit = proc_info->hardtimelimit * 1000L;
- com_proc_add.memlimit = proc_info->memlimit * 1024L + 4096L * 128L;
- if(ioctl(judgx_modfd,IOCTL_PROC_ADD,&com_proc_add)){
- return -1;
- }
- proc_info->task = com_proc_add.task;
-
- return 0;
-}
-DLL_PUBLIC int judgx_proc_run(struct judgx_proc_info *proc_info,judgx_check_run_fn check_run){
- int ret;
-
- char abspath[PATH_MAX + 1];
- int waitstatus;
- struct judgx_com_proc_get com_proc_get;
-
- ret = 0;
-
- printf("proc1\n");
-
- realpath(proc_info->exe_path,abspath);
- if((proc_info->pid = fork()) == 0){
- char *argv[] = {NULL,NULL};
- char *envp[] = {NULL};
-
- chdir(proc_info->run_path);
- check_run();
-
- setgid(99);
- setuid(99);
- kill(getpid(),SIGSTOP);
-
- argv[0] = proc_info->exe_name;
- execve(abspath,argv,envp);
- }
-
- printf("proc2\n");
-
- if(proc_info->pid == -1){
- ret = -1;
- goto end;
- }
- waitpid(proc_info->pid,NULL,WUNTRACED);
-
- printf("proc3\n");
-
- if(proc_protect(proc_info)){
- kill(proc_info->pid,SIGKILL);
- ret = -1;
- goto end;
- }
-
- printf("proc4\n");
-
- kill(proc_info->pid,SIGCONT);
- if(waitpid(proc_info->pid,&waitstatus,0) == -1){
- ret = -1;
- goto end;
- }
-
- com_proc_get.task = proc_info->task;
- if(ioctl(judgx_modfd,IOCTL_PROC_GET,&com_proc_get)){
- ret = -1;
- goto end;
- }
-
- printf("proc5 %d\n",com_proc_get.status);
-
- proc_info->runtime = com_proc_get.runtime;
- proc_info->peakmem = com_proc_get.peakmem;
-
- if(com_proc_get.status != JUDGE_AC){
- proc_info->status = com_proc_get.status;
- }else if(proc_info->peakmem > (proc_info->memlimit * 1024L)){
- proc_info->status = JUDGE_MLE;
- }else if(proc_info->runtime > (proc_info->timelimit * 1000L)){
- proc_info->status = JUDGE_TLE;
- }else if(WIFEXITED(waitstatus) || (WIFSIGNALED(waitstatus) && WTERMSIG(waitstatus) == SIGKILL)){
- proc_info->status = JUDGE_AC;
- }else{
- proc_info->status = JUDGE_RE;
- }
-
-end:
-
- printf("proc6\n");
-
- return ret;
-}
-DLL_PUBLIC int judgx_proc_kill(struct judgx_proc_info *proc_info){
- if(ioctl(judgx_modfd,IOCTL_PROC_KILL,proc_info->task)){
- return -1;
- }
- return 0;
-}
-DLL_PUBLIC int judgx_proc_free(struct judgx_proc_info *proc_info){
- if(proc_info->task != -1){
- if(ioctl(judgx_modfd,IOCTL_PROC_DEL,proc_info->task)){
- return -1;
- }
- }
-
- free(proc_info);
- return 0;
-}
diff --git a/judge/judgx_lib.h b/judge/judgx_lib.h
deleted file mode 100644
index c5c7074..0000000
--- a/judge/judgx_lib.h
+++ /dev/null
@@ -1,13 +0,0 @@
-static __attribute__((constructor)) void judgx_init(void);
-static __attribute__((destructor)) void judgx_exit(void);
-static int rmdir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftwbuf);
-static int proc_protect(struct judgx_proc_info *proc_info);
-
-static int judgx_modfd;
-
-DLL_PUBLIC int judgx_ini_load(FILE *f,judgx_ini_handler handler,void *data);
-DLL_PUBLIC int judgx_compile(char *cpppath,char *exepath,char *arg);
-DLL_PUBLIC struct judgx_proc_info* judgx_proc_create(char *runpath,char *exepath,unsigned long timelimit,unsigned long hardtimelimit,unsigned long memlimit);
-DLL_PUBLIC int judgx_proc_run(struct judgx_proc_info *proc_info,judgx_check_run_fn check_run);
-DLL_PUBLIC int judgx_proc_kill(struct judgx_proc_info *proc_info);
-DLL_PUBLIC int judgx_proc_free(struct judgx_proc_info *proc_info);
diff --git a/judge/judgx_line.h b/judge/judgx_line.h
deleted file mode 100644
index 3823b62..0000000
--- a/judge/judgx_line.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#define JUDGX_LINE_RESULTMAX 64
-
-struct judgx_line_result{
- int status;
- int score;
- int maxscore;
- unsigned long runtime;
- unsigned long peakmem;
-};
-struct judgx_line_info{
- char pro_path[PATH_MAX + 1];
- char cpp_path[PATH_MAX + 1];
- char run_path[PATH_MAX + 1];
- FILE *set_file;
- void *line_dll;
- void *check_dll;
-
- int result_count;
- struct judgx_line_result result[JUDGX_LINE_RESULTMAX];
-};
diff --git a/judge/line.c b/judge/line.c
deleted file mode 100644
index 7468aa7..0000000
--- a/judge/line.c
+++ /dev/null
@@ -1,197 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<dlfcn.h>
-#include<limits.h>
-#include<semaphore.h>
-#include<signal.h>
-#include<time.h>
-
-#include"judge_def.h"
-#include"judgx.h"
-#include"judgx_line.h"
-#include"line.h"
-
-static void line_ini_handler(void *data,char *section,char *key,char *value){
- int i;
-
- struct line_setting_info *set_info;
- char *part;
- char *savpart;
-
- set_info = (struct line_setting_info*)data;
- if(strcmp(section,"JUDGE") == 0){
- if(strcmp(key,"timelimit") == 0){
- set_info->timelimit = atoi(value);
- }else if(strcmp(key,"hardtimelimit") == 0){
- set_info->hardtimelimit = atoi(value);
- }else if(strcmp(key,"memlimit") == 0){
- set_info->memlimit = atoi(value);
- }else if(strcmp(key,"count") == 0){
- set_info->count = atoi(value);
- }else if(strcmp(key,"score") == 0){
- part = strtok_r(value,",",&savpart);
- i = 0;
- while(part != NULL){
- set_info->score[i] = atoi(part);
- part = strtok_r(NULL,",",&savpart);
- i++;
- }
- }
- }
-}
-static void* line_procrun_thread(void *arg){
- struct line_procrun_info *procrun_info;
-
- procrun_info = (struct line_procrun_info*)arg;
- judgx_proc_run(procrun_info->proc_info,procrun_info->check_run);
-
- sem_post(procrun_info->done_sem);
- return NULL;
-}
-
-DLL_PUBLIC int run(struct judgx_line_info *line_info){
- int ret;
- int i;
-
- struct line_setting_info *set_info;
- char exepath[PATH_MAX + 1];
- char datapath[PATH_MAX + 1];
-
- check_init_fn check_init;
- check_thread_fn check_thread;
- check_stop_fn check_stop;
- judgx_check_run_fn check_run;
-
- struct judgx_proc_info *proc_info;
- int status;
- int score;
- unsigned long runtime;
- unsigned long peakmem;
-
- sem_t donesem;
- struct check_thread_info thread_info;
- struct line_procrun_info procrun_info;
- pthread_t check_pt;
- pthread_t procrun_pt;
- struct timespec waittime;
-
- printf("line1\n");
-
- set_info = malloc(sizeof(struct line_setting_info));
- set_info->hardtimelimit = -1;
- judgx_ini_load(line_info->set_file,line_ini_handler,set_info);
- if(set_info->hardtimelimit < 0){
- set_info->hardtimelimit = set_info->timelimit * 10L + 10000;
- }
-
- printf("line2\n");
-
- check_init = dlsym(line_info->check_dll,"init");
- check_thread = dlsym(line_info->check_dll,"thread");
- check_stop = dlsym(line_info->check_dll,"stop");
- check_run = dlsym(line_info->check_dll,"run");
-
- printf("line3\n");
-
- snprintf(exepath,sizeof(exepath),"%s/test",line_info->run_path);
- if(judgx_compile(line_info->cpp_path,exepath,NULL) == JUDGE_CE){
- for(i = 0;i < set_info->count;i++){
- line_info->result[i].status = JUDGE_CE;
- line_info->result[i].score = 0;
- line_info->result[i].maxscore = set_info->score[i];
- line_info->result[i].runtime = 0;
- line_info->result[i].peakmem = 0;
- }
- line_info->result_count = set_info->count;
-
- goto clean;
- }
-
- printf("line4\n");
-
- for(i = 0;i < set_info->count;i++){
- status = JUDGE_ERR;
- score = 0;
- runtime = 0;
- peakmem = 0;
-
- printf("line5\n");
-
- if(!(proc_info = judgx_proc_create(line_info->run_path,exepath,set_info->timelimit,set_info->hardtimelimit,set_info->memlimit))){
- goto proc_end;
- }
-
- printf("line7\n");
-
- snprintf(datapath,sizeof(datapath),"%s/%d",line_info->pro_path,(i + 1));
- if(check_init(line_info->run_path,datapath)){
- goto proc_clean;
- }
-
- sem_init(&donesem,0,0);
-
- thread_info.status = JUDGE_WA;
- thread_info.done_sem = &donesem;
-
- procrun_info.proc_info = proc_info;
- procrun_info.check_run = check_run;
- procrun_info.done_sem = &donesem;
-
- pthread_create(&check_pt,NULL,check_thread,&thread_info);
- pthread_create(&procrun_pt,NULL,line_procrun_thread,&procrun_info);
-
- sem_wait(&donesem);
-
- judgx_proc_kill(proc_info);
- pthread_join(procrun_pt,NULL);
-
- check_stop();
-
- if(proc_info->status == JUDGE_AC){
- clock_gettime(CLOCK_REALTIME,&waittime);
- waittime.tv_sec += CHECK_THREAD_WAITTIME;
- if(sem_timedwait(&donesem,&waittime)){
- status = JUDGE_WA;
- }else{
- status = thread_info.status;
- if(status == JUDGE_AC){
- score = set_info->score[i];
- }
- }
- }else{
- status = proc_info->status;
- }
-
- pthread_cancel(check_pt);
- sem_destroy(&donesem);
-
- runtime = proc_info->runtime;
- peakmem = proc_info->peakmem;
-
-proc_clean:
-
- judgx_proc_free(proc_info);
-
-proc_end:
-
- line_info->result[i].status = status;
- line_info->result[i].score = score;
- line_info->result[i].maxscore = set_info->score[i];
- line_info->result[i].runtime = runtime;
- line_info->result[i].peakmem = peakmem;
- }
-
- printf("line8\n");
-
- line_info->result_count = set_info->count;
-
-clean:
-
- free(set_info);
- close(line_info->set_file);
-
- printf("line10\n");
-
- return 0;
-}
diff --git a/judge/line.h b/judge/line.h
deleted file mode 100644
index 8864868..0000000
--- a/judge/line.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#define CHECK_THREAD_WAITTIME 5
-
-typedef int (*check_init_fn)(char *runpath,char *datapath);
-typedef void* (*check_thread_fn)(void *arg);
-typedef int (*check_stop_fn)(void);
-
-struct line_setting_info{
- unsigned long timelimit;
- unsigned long hardtimelimit;
- unsigned long memlimit;
- int count;
- int score[JUDGX_LINE_RESULTMAX];
-};
-struct line_procrun_info{
- struct judgx_proc_info *proc_info;
- judgx_check_run_fn check_run;
- sem_t *done_sem;
-};
-struct check_thread_info{
- int status;
- sem_t *done_sem;
-};
-
-static void line_ini_handler(void *data,char *section,char *key,char *value);
-static void* line_procrun_thread(void *arg);
-
-DLL_PUBLIC int run(struct judgx_line_info *line_info);
diff --git a/judge/line_vscore.c b/judge/line_vscore.c
deleted file mode 100644
index c241495..0000000
--- a/judge/line_vscore.c
+++ /dev/null
@@ -1,189 +0,0 @@
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<dlfcn.h>
-#include<limits.h>
-#include<semaphore.h>
-#include<signal.h>
-#include<time.h>
-
-#include"judge_def.h"
-#include"judgx.h"
-#include"judgx_line.h"
-#include"line_vscore.h"
-
-static void line_ini_handler(void *data,char *section,char *key,char *value){
- int i;
-
- struct line_setting_info *set_info;
- char *part;
- char *savpart;
-
- set_info = (struct line_setting_info*)data;
- if(strcmp(section,"JUDGE") == 0){
- if(strcmp(key,"timelimit") == 0){
- set_info->timelimit = atoi(value);
- }else if(strcmp(key,"hardtimelimit") == 0){
- set_info->hardtimelimit = atoi(value);
- }else if(strcmp(key,"memlimit") == 0){
- set_info->memlimit = atoi(value);
- }else if(strcmp(key,"count") == 0){
- set_info->count = atoi(value);
- }
- }
-}
-static void* line_procrun_thread(void *arg){
- struct line_procrun_info *procrun_info;
-
- procrun_info = (struct line_procrun_info*)arg;
- judgx_proc_run(procrun_info->proc_info,procrun_info->check_run);
-
- sem_post(procrun_info->done_sem);
- return NULL;
-}
-
-DLL_PUBLIC int run(struct judgx_line_info *line_info){
- int i;
-
- struct line_setting_info *set_info;
- char exepath[PATH_MAX + 1];
- char datapath[PATH_MAX + 1];
-
- check_init_fn check_init;
- check_thread_fn check_thread;
- check_stop_fn check_stop;
- judgx_check_run_fn check_run;
-
- struct judgx_proc_info *proc_info;
- int status;
- int score;
- int maxscore;
- unsigned long runtime;
- unsigned long peakmem;
-
- sem_t donesem;
- struct check_thread_info thread_info;
- struct line_procrun_info procrun_info;
- pthread_t check_pt;
- pthread_t procrun_pt;
- struct timespec waittime;
-
- printf("line1\n");
-
- set_info = malloc(sizeof(struct line_setting_info));
- set_info->hardtimelimit = -1;
- judgx_ini_load(line_info->set_file,line_ini_handler,set_info);
- if(set_info->hardtimelimit < 0){
- set_info->hardtimelimit = set_info->timelimit * 10L + 10000;
- }
-
- printf("line2\n");
-
- check_init = dlsym(line_info->check_dll,"init");
- check_thread = dlsym(line_info->check_dll,"thread");
- check_stop = dlsym(line_info->check_dll,"stop");
- check_run = dlsym(line_info->check_dll,"run");
-
- printf("line3\n");
-
- snprintf(exepath,sizeof(exepath),"%s/test",line_info->run_path);
- if(judgx_compile(line_info->cpp_path,exepath,NULL) == JUDGE_CE){
- for(i = 0;i < set_info->count;i++){
- line_info->result[i].status = JUDGE_CE;
- line_info->result[i].score = 0;
- line_info->result[i].maxscore = 1;
- line_info->result[i].runtime = 0;
- line_info->result[i].peakmem = 0;
- }
- line_info->result_count = set_info->count;
-
- goto clean;
- }
-
- printf("line4\n");
-
- for(i = 0;i < set_info->count;i++){
- status = JUDGE_ERR;
- score = 0;
- maxscore = 1;
- runtime = 0;
- peakmem = 0;
-
- printf("line5\n");
-
- if(!(proc_info = judgx_proc_create(line_info->run_path,exepath,set_info->timelimit,set_info->hardtimelimit,set_info->memlimit))){
- goto proc_end;
- }
-
- printf("line7\n");
-
- snprintf(datapath,sizeof(datapath),"%s/%d",line_info->pro_path,(i + 1));
- if(check_init(line_info->run_path,datapath)){
- goto proc_clean;
- }
-
- sem_init(&donesem,0,0);
-
- thread_info.status = JUDGE_WA;
- thread_info.done_sem = &donesem;
-
- procrun_info.proc_info = proc_info;
- procrun_info.check_run = check_run;
- procrun_info.done_sem = &donesem;
-
- pthread_create(&check_pt,NULL,check_thread,&thread_info);
- pthread_create(&procrun_pt,NULL,line_procrun_thread,&procrun_info);
-
- sem_wait(&donesem);
-
- judgx_proc_kill(proc_info);
- pthread_join(procrun_pt,NULL);
-
- check_stop();
-
- if(proc_info->status == JUDGE_AC){
- clock_gettime(CLOCK_REALTIME,&waittime);
- waittime.tv_sec += CHECK_THREAD_WAITTIME;
- if(sem_timedwait(&donesem,&waittime)){
- status = JUDGE_WA;
- }else{
- status = thread_info.status;
- score = thread_info.score;
- maxscore = thread_info.maxscore;
- }
- }else{
- status = proc_info->status;
- }
-
- pthread_cancel(check_pt);
- sem_destroy(&donesem);
-
- runtime = proc_info->runtime;
- peakmem = proc_info->peakmem;
-
-proc_clean:
-
- judgx_proc_free(proc_info);
-
-proc_end:
-
- line_info->result[i].status = status;
- line_info->result[i].score = score;
- line_info->result[i].maxscore = maxscore;
- line_info->result[i].runtime = runtime;
- line_info->result[i].peakmem = peakmem;
- }
-
- printf("line8\n");
-
- line_info->result_count = set_info->count;
-
-clean:
-
- free(set_info);
- close(line_info->set_file);
-
- printf("line10\n");
-
- return 0;
-}
diff --git a/judge/line_vscore.h b/judge/line_vscore.h
deleted file mode 100644
index 3609e88..0000000
--- a/judge/line_vscore.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#define CHECK_THREAD_WAITTIME 5
-
-typedef int (*check_init_fn)(char *runpath,char *datapath);
-typedef void* (*check_thread_fn)(void *arg);
-typedef int (*check_stop_fn)(void);
-
-struct line_setting_info{
- unsigned long timelimit;
- unsigned long hardtimelimit;
- unsigned long memlimit;
- int count;
-};
-struct line_procrun_info{
- struct judgx_proc_info *proc_info;
- judgx_check_run_fn check_run;
- sem_t *done_sem;
-};
-struct check_thread_info{
- int status;
- int score;
- int maxscore;
- sem_t *done_sem;
-};
-
-static void line_ini_handler(void *data,char *section,char *key,char *value);
-static void* line_procrun_thread(void *arg);
-
-DLL_PUBLIC int run(struct judgx_line_info *line_info);
diff --git a/toj/center/pro/packpro.sh b/toj/center/pro/packpro.sh
new file mode 100755
index 0000000..b53a707
--- /dev/null
+++ b/toj/center/pro/packpro.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+tar -jcvf ../tmp/propack/$1.tar.bz2 -C $1 .
diff --git a/toj/center/src/Makefile b/toj/center/src/Makefile
new file mode 100644
index 0000000..dcfab80
--- /dev/null
+++ b/toj/center/src/Makefile
@@ -0,0 +1,25 @@
+ifneq ($(KERNELRELEASE),)
+ judgk-objs := judgk_mod.o judgk_proc.o judgk_syscall.o judgk_syscall_asm.o judgk_security.o judgk_hyperio.o
+ obj-m := judgk.o
+else
+ KERNEL_SOURCE := /usr/lib/modules/$(shell uname -r)/build
+ PWD := $(shell pwd)
+default:
+ ${MAKE} -C ${KERNEL_SOURCE} M=${PWD} modules
+ mv judgk.ko ../judge/
+
+ g++ -rdynamic -fvisibility=hidden -O2 center_server.cpp center_manage.cpp center_judge.cpp pack.cpp /srv/http/toj/php/event_exec.cpp -ldl -lpq -ltar -lbz2 -ljson -lcurl -pthread -o center_server
+ g++ -O2 judge_server.cpp pack.cpp -ldl -lbz2 -ltar -pthread -o judge_server
+ mv center_server ../
+ mv judge_server ../judge/
+
+ g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_manage.cpp -ldl -ljson -pthread -o jmod_test_manage.so
+ g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_line.cpp -ljson -pthread -o jmod_test_line.so
+ g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_check.cpp -o jmod_test_check.so
+ mv jmod_test_manage.so ../jmod/jmod_test/
+ mv jmod_test_line.so ../jmod/jmod_test/
+ mv jmod_test_check.so ../jmod/jmod_test/
+ tar -jcvf ../tmp/jmodpack/jmod_test.tar.bz2 -C ../jmod/jmod_test .
+clean:
+ ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
+endif
diff --git a/toj/center/src/center.h b/toj/center/src/center.h
new file mode 100644
index 0000000..a143df0
--- /dev/null
+++ b/toj/center/src/center.h
@@ -0,0 +1,53 @@
+class center_jmod_info{
+public:
+ char name[NAME_MAX + 1];
+ int cacheid;
+ void *manage_dll;
+ void *manage_sub_fn;
+ void *manage_res_fn;
+
+ center_jmod_info(char *name,int cacheid){
+ this->name[0] = '\0';
+ strncat(this->name,name,sizeof(this->name));
+ this->cacheid = cacheid;
+ this->manage_dll = NULL;
+ this->manage_sub_fn = NULL;
+ this->manage_res_fn = NULL;
+ }
+};
+
+class center_pro_info{
+public:
+ int proid;
+ int cacheid;
+ center_jmod_info *jmod_info;
+ int lang_flag;
+
+ center_pro_info(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag){
+ this->proid = proid;
+ this->cacheid = cacheid;
+ this->jmod_info = jmod_info;
+ this->lang_flag = lang_flag;
+ }
+};
+
+class center_submit_info{
+public:
+ int subid;
+ int uid;
+ center_jmod_info *jmod_info;
+ center_pro_info *pro_info;
+ int lang;
+ char *param;
+ void *jmod_manage_data;
+
+ center_submit_info(int subid,int uid,center_jmod_info *jmod_info,center_pro_info *pro_info,int lang,char *param){
+ this->subid = subid;
+ this->uid = uid;
+ this->jmod_info = jmod_info;
+ this->pro_info = pro_info;
+ this->lang = lang;
+ this->param = param;
+ this->jmod_manage_data = NULL;
+ }
+};
diff --git a/toj/center/src/center_com.h b/toj/center/src/center_com.h
new file mode 100644
index 0000000..73f3ff3
--- /dev/null
+++ b/toj/center/src/center_com.h
@@ -0,0 +1,70 @@
+#define CENTER_COMCODE_SETID 1
+#define CENTER_COMCODE_SETINFO 2
+#define CENTER_COMCODE_SUBMIT 3
+#define CENTER_COMCODE_RESULT 4
+
+#define CENTER_COMCODE_SETPRO 10
+#define CENTER_COMCODE_REQPRO 11
+#define CENTER_COMCODE_SENDPRO 12
+#define CENTER_COMCODE_SETJMOD 13
+#define CENTER_COMCODE_REQJMOD 14
+#define CENTER_COMCODE_SENDJMOD 15
+
+#define CENTER_COMCODE_REQCODE 20
+#define CENTER_COMCODE_SENDCODE 21
+
+struct center_com_header{
+ int code;
+ int size;
+}__attribute__((packed));
+struct center_com_setid{
+ int id; //0:new judge
+}__attribute__((packed));
+struct center_com_setinfo{
+ int avail;
+}__attribute__((packed));
+struct center_com_submit{
+ int subid;
+ int proid;
+ int lang;
+ char set_data[JUDGE_SET_DATAMAX];
+}__attribute__((packed));
+struct center_com_result{ //just result header
+ int subid;
+}__attribute__((packed));
+
+struct center_com_setpro{
+ int proid;
+ int cacheid;
+ int type; //0:add problem 1:drop problem
+}__attribute__((packed));
+struct center_com_reqpro{
+ int proid;
+}__attribute__((packed));
+struct center_com_sendpro{
+ int proid;
+ int cacheid;
+ size_t filesize;
+}__attribute__((packed));
+
+struct center_com_setjmod{
+ char jmod_name[NAME_MAX + 1];
+ int cacheid;
+ int type; //0:add jmod 1:drop jmod
+}__attribute__((packed));
+struct center_com_reqjmod{
+ char jmod_name[NAME_MAX + 1];
+}__attribute__((packed));
+struct center_com_sendjmod{
+ char jmod_name[NAME_MAX + 1];
+ int cacheid;
+ size_t filesize;
+}__attribute__((packed));
+
+struct center_com_reqcode{
+ int subid;
+}__attribute__((packed));
+struct center_com_sendcode{
+ int subid;
+ size_t filesize;
+}__attribute__((packed));
diff --git a/toj/center/src/center_judge.cpp b/toj/center/src/center_judge.cpp
new file mode 100644
index 0000000..38837cc
--- /dev/null
+++ b/toj/center/src/center_judge.cpp
@@ -0,0 +1,524 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+#include<fcntl.h>
+#include<limits.h>
+#include<errno.h>
+#include<sys/stat.h>
+#include<sys/types.h>
+#include<sys/epoll.h>
+#include<sys/sendfile.h>
+#include<map>
+#include<list>
+#include<queue>
+#include<string>
+
+#include"netio.h"
+#include"judge_def.h"
+#include"center.h"
+#include"center_com.h"
+#include"center_judge.h"
+
+int judge_info::last_id = 0;
+judge_info::judge_info(){
+ last_id++;
+ this->id = last_id;
+ this->avail = 0;
+
+ judge_idmap.insert(std::pair<int,judge_info*>(id,this));
+ judge_runlist.push_back(this);
+ judge_it = judge_runlist.end();
+ judge_it--;
+}
+judge_info::~judge_info(){
+ judge_idmap.erase(id);
+ judge_runlist.erase(judge_it);
+}
+int judge_info::setavail(int avail){
+ int old;
+
+ old = this->avail;
+ this->avail = avail;
+ if(this->avail > 0 && old <= 0){
+ judge_runlist.erase(judge_it);
+ judge_runlist.push_front(this);
+ judge_it = judge_runlist.begin();
+ }else if(this->avail <= 0 && old > 0){
+ judge_runlist.erase(judge_it);
+ judge_runlist.push_back(this);
+ judge_it = judge_runlist.end();
+ judge_it--;
+ }
+
+ return 0;
+}
+int judge_info::setinfo(int avail){
+ setavail(avail);
+ return 0;
+}
+int judge_info::submit(judge_submit_info *sub_info){
+ setavail(avail - 1);
+ conn_main->send_submit(sub_info);
+ return 0;
+}
+int judge_info::result(int subid,char *res_data){
+ setavail(avail + 1);
+
+ printf("submitid:%d\n",subid);
+ center_manage_result(subid,res_data);
+
+ judge_submit_waitqueue();
+ return 0;
+}
+
+
+judge_conn::judge_conn(int fd):netio(fd){
+ this->info = NULL;
+ this->recv_dispatch_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_dispatch);
+ this->recv_setid_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setid);
+ this->recv_setinfo_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setinfo);
+ this->recv_result_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_result);
+ this->recv_setpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setpro);
+ this->recv_reqpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqpro);
+ this->recv_setjmod_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setjmod);
+ this->recv_reqjmod_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqjmod);
+ this->recv_reqcode_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqcode);
+}
+judge_conn::~judge_conn(){
+ info->conn_list.erase(conn_it);
+ if(info->conn_main == this){
+ info->conn_main = NULL;
+ }
+ if(info->conn_list.empty()){
+ delete info;
+ }
+
+ delete recv_dispatch_fn;
+ delete recv_setid_fn;
+ delete recv_setinfo_fn;
+ delete recv_result_fn;
+ delete recv_setpro_fn;
+ delete recv_reqpro_fn;
+ delete recv_setjmod_fn;
+ delete recv_reqjmod_fn;
+ delete recv_reqcode_fn;
+}
+char* judge_conn::create_combuf(int code,int size,int &len,void **data){
+ char *buf;
+ center_com_header *header;
+
+ buf = new char[sizeof(center_com_header) + size];
+ header = (center_com_header*)buf;
+ header->code = code;
+ header->size = size;
+ len = sizeof(center_com_header) + size;
+ *data = (void*)(buf + sizeof(center_com_header));
+
+ return buf;
+}
+int judge_conn::send_setid(int judgeid){
+ char *write_buf;
+ int write_len;
+ center_com_setid *setid;
+
+ write_buf = create_combuf(CENTER_COMCODE_SETID,sizeof(center_com_setid),write_len,(void**)&setid);
+ setid->id = judgeid;
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int judge_conn::send_submit(judge_submit_info *sub_info){
+ char *write_buf;
+ int write_len;
+ center_com_submit *sub;
+
+ printf(" send submit %d\n",sub_info->subid);
+
+ write_buf = create_combuf(CENTER_COMCODE_SUBMIT,sizeof(center_com_submit),write_len,(void**)&sub);
+ sub->subid = sub_info->subid;
+ sub->proid = sub_info->proid;
+ sub->lang = sub_info->lang;
+ memcpy(sub->set_data,sub_info->set_data,sub_info->set_len);
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ delete sub_info;
+ return 0;
+}
+int judge_conn::send_setpro(int *proid,int *cacheid,int type,int count){
+ int i;
+
+ char *write_buf;
+ int write_len;
+ center_com_setpro *setpro;
+
+ write_buf = create_combuf(CENTER_COMCODE_SETPRO,sizeof(center_com_setpro) * count,write_len,(void**)&setpro);
+ for(i = 0;i < count;i++){
+ setpro[i].proid = proid[i];
+ setpro[i].cacheid = cacheid[i];
+ setpro[i].type = type;
+ }
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int judge_conn::send_setjmod(char **jmod_name,int *cacheid,int type,int count){
+ int i;
+
+ char *write_buf;
+ int write_len;
+ center_com_setjmod *setjmod;
+
+ write_buf = create_combuf(CENTER_COMCODE_SETJMOD,sizeof(center_com_setjmod) * count,write_len,(void**)&setjmod);
+ for(i = 0;i < count;i++){
+ setjmod[i].jmod_name[0] = '\0';
+ strncat(setjmod[i].jmod_name,jmod_name[i],sizeof(setjmod[i].jmod_name));
+ setjmod[i].cacheid = cacheid[i];
+ setjmod[i].type = type;
+ }
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int judge_conn::readidle(){
+ readbytes(new center_com_header,sizeof(center_com_header),recv_dispatch_fn,NULL);
+ return 0;
+}
+void judge_conn::recv_dispatch(void *buf,size_t len,void *data){
+ center_com_header *header;
+ char *readbuf;
+
+ header = (center_com_header*)buf;
+ readbuf = new char[header->size];
+
+ printf("code:%d size:%d\n",header->code,header->size);
+ switch(header->code){
+ case CENTER_COMCODE_SETID:
+ readbytes(readbuf,header->size,recv_setid_fn,NULL);
+ break;
+ case CENTER_COMCODE_SETINFO:
+ readbytes(readbuf,header->size,recv_setinfo_fn,NULL);
+ break;
+ case CENTER_COMCODE_RESULT:
+ readbytes(readbuf,header->size,recv_result_fn,NULL);
+ break;
+ case CENTER_COMCODE_SETPRO:
+ readbytes(readbuf,header->size,recv_setpro_fn,NULL);
+ break;
+ case CENTER_COMCODE_REQPRO:
+ readbytes(readbuf,header->size,recv_reqpro_fn,NULL);
+ break;
+ case CENTER_COMCODE_SETJMOD:
+ readbytes(readbuf,header->size,recv_setjmod_fn,NULL);
+ break;
+ case CENTER_COMCODE_REQJMOD:
+ readbytes(readbuf,header->size,recv_reqjmod_fn,NULL);
+ break;
+ case CENTER_COMCODE_REQCODE:
+ readbytes(readbuf,header->size,recv_reqcode_fn,NULL);
+ break;
+ }
+
+ delete header;
+}
+void judge_conn::recv_setid(void *buf,size_t len,void *data){
+ center_com_setid *setid;
+ std::map<int,judge_info*>::iterator it;
+
+ setid = (center_com_setid*)buf;
+ if(setid->id == 0){
+ info = new judge_info();
+
+ info->conn_list.push_front(this);
+ conn_it = info->conn_list.begin();
+ info->conn_main = this;
+
+ this->send_setid(info->id);
+ }else{
+ if((it = judge_idmap.find(setid->id)) != judge_idmap.end()){
+ info = it->second;
+ info->conn_list.push_front(this);
+ conn_it = info->conn_list.begin();
+ }
+ }
+
+ delete setid;
+}
+void judge_conn::recv_setinfo(void *buf,size_t len,void *data){
+ int i;
+ int count;
+
+ center_com_setinfo *setinfo;
+ char **jmod_name;
+ std::map<std::string,center_jmod_info*>::iterator jmod_it;
+ int *proid;
+ int *cacheid;
+ std::map<int,center_pro_info*>::iterator pro_it;
+
+ setinfo = (center_com_setinfo*)buf;
+ info->setinfo(setinfo->avail);
+
+ count = center_manage_jmodmap.size();
+ jmod_name = new char*[count];
+ cacheid = new int[count];
+ jmod_it = center_manage_jmodmap.begin();
+ for(i = 0;i < count;i++,jmod_it++){
+ jmod_name[i] = jmod_it->second->name;
+ cacheid[i] = jmod_it->second->cacheid;
+ }
+ send_setjmod(jmod_name,cacheid,0,count);
+
+ delete jmod_name;
+ delete cacheid;
+
+ count = center_manage_promap.size();
+ proid = new int[count];
+ cacheid = new int[count];
+ pro_it = center_manage_promap.begin();
+ for(i = 0;i < count;i++,pro_it++){
+ proid[i] = pro_it->second->proid;
+ cacheid[i] = pro_it->second->cacheid;
+ }
+ send_setpro(proid,cacheid,0,count);
+
+ delete proid;
+ delete cacheid;
+
+ delete setinfo;
+}
+void judge_conn::recv_result(void *buf,size_t len,void *data){
+ int subid;
+ char *res_data;
+
+ subid = ((center_com_result*)buf)->subid;
+ res_data = (char*)((char*)buf + sizeof(center_com_result));
+
+ info->result(subid,res_data);
+
+ delete (char*)buf;
+}
+void judge_conn::recv_setpro(void *buf,size_t len,void *data){
+ int i;
+ int count;
+
+ center_com_setpro *setpro;
+ std::map<int,center_pro_info*>::iterator pro_it;
+
+ count = len / sizeof(center_com_setpro);
+ setpro = (center_com_setpro*)buf;
+ for(i = 0;i < count;i++){
+ if(setpro[i].type == 0){
+ if((pro_it = center_manage_promap.find(setpro[i].proid)) == center_manage_promap.end()){
+ continue;
+ }
+ if(pro_it->second->cacheid != setpro[i].cacheid){
+ continue;
+ }
+
+ info->pro_map.insert(std::pair<int,center_pro_info*>(pro_it->second->proid,pro_it->second));
+ }else if(setpro[i].type == 1){
+ info->pro_map.erase(setpro[i].proid);
+ }
+ }
+
+ judge_submit_waitqueue();
+ delete setpro;
+}
+void judge_conn::recv_reqpro(void *buf,size_t len,void *data){
+ center_com_reqpro *reqpro;
+ std::map<int,center_pro_info*>::iterator pro_it;
+ center_pro_info *pro_info;
+
+ char tpath[PATH_MAX + 1];
+ int fd;
+ struct stat st;
+
+ char *write_buf;
+ int write_len;
+ center_com_sendpro *sendpro;
+
+ reqpro = (center_com_reqpro*)buf;
+ if((pro_it = center_manage_promap.find(reqpro->proid)) == center_manage_promap.end()){
+ //fix
+ }else{
+ pro_info = pro_it->second;
+
+ snprintf(tpath,sizeof(tpath),"tmp/propack/%d.tar.bz2",pro_info->proid);
+ fd = open(tpath,O_RDONLY);
+ if(fstat(fd,&st)){
+ //fix
+ }else{
+ write_buf = create_combuf(CENTER_COMCODE_SENDPRO,sizeof(center_com_sendpro),write_len,(void**)&sendpro);
+ sendpro->proid = pro_info->proid;
+ sendpro->cacheid = pro_info->cacheid;
+ sendpro->filesize = st.st_size;
+ printf("sendpro:%lu\n",sendpro->filesize);
+
+ writebytes(write_buf,write_len,NULL,NULL);
+ writefile(fd,st.st_size,NULL,NULL);
+ }
+ }
+
+ delete reqpro;
+}
+void judge_conn::recv_setjmod(void *buf,size_t len,void *data){
+ int i;
+ int count;
+
+ center_com_setjmod *setjmod;
+ std::map<std::string,center_jmod_info*>::iterator jmod_it;
+
+ count = len / sizeof(center_com_setjmod);
+ setjmod = (center_com_setjmod*)buf;
+ for(i = 0;i < count;i++){
+ if(setjmod[i].type == 0){
+ if((jmod_it = center_manage_jmodmap.find(setjmod[i].jmod_name)) == center_manage_jmodmap.end()){
+ continue;
+ }
+ if(jmod_it->second->cacheid != setjmod[i].cacheid){
+ continue;
+ }
+
+ info->jmod_map.insert(std::pair<std::string,center_jmod_info*>(jmod_it->second->name,jmod_it->second));
+ }else if(setjmod[i].type == 1){
+ info->jmod_map.erase(setjmod[i].jmod_name);
+ }
+ }
+
+ judge_submit_waitqueue();
+ delete setjmod;
+}
+void judge_conn::recv_reqjmod(void *buf,size_t len,void *data){
+ center_com_reqjmod *reqjmod;
+ std::map<std::string,center_jmod_info*>::iterator jmod_it;
+ center_jmod_info *jmod_info;
+
+ char tpath[PATH_MAX + 1];
+ int fd;
+ struct stat st;
+
+ char *write_buf;
+ int write_len;
+ center_com_sendjmod *sendjmod;
+
+ reqjmod = (center_com_reqjmod*)buf;
+ if((jmod_it = center_manage_jmodmap.find(reqjmod->jmod_name)) == center_manage_jmodmap.end()){
+ //fix
+ }else{
+ jmod_info = jmod_it->second;
+
+ snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s.tar.bz2",jmod_info->name);
+ fd = open(tpath,O_RDONLY);
+ if(fstat(fd,&st)){
+ //fix
+ }else{
+ write_buf = create_combuf(CENTER_COMCODE_SENDJMOD,sizeof(center_com_sendjmod),write_len,(void**)&sendjmod);
+ sendjmod->jmod_name[0] = '\0';
+ strncat(sendjmod->jmod_name,jmod_info->name,sizeof(sendjmod->jmod_name));
+ sendjmod->cacheid = jmod_info->cacheid;
+ sendjmod->filesize = st.st_size;
+ printf("sendjmod:%lu\n",sendjmod->filesize);
+
+ writebytes(write_buf,write_len,NULL,NULL);
+ writefile(fd,st.st_size,NULL,NULL);
+ }
+ }
+
+ delete reqjmod;
+}
+void judge_conn::recv_reqcode(void *buf,size_t len,void *data){
+ center_com_reqcode *reqcode;
+ char tpath[PATH_MAX + 1];
+ int fd;
+ struct stat st;
+
+ char *write_buf;
+ int write_len;
+ center_com_header *header;
+ center_com_sendcode *sendcode;
+
+ reqcode = (center_com_reqcode*)buf;
+ snprintf(tpath,sizeof(tpath),"tmp/codepack/%d.tar.bz2",reqcode->subid);
+ fd = open(tpath,O_RDONLY);
+ if(fstat(fd,&st)){
+ //fix
+ }else{
+ write_buf = create_combuf(CENTER_COMCODE_SENDCODE,sizeof(center_com_sendcode),write_len,(void**)&sendcode);
+ sendcode->subid = reqcode->subid;
+ sendcode->filesize = st.st_size;
+ printf("sendcode:%lu\n",sendcode->filesize);
+
+ writebytes(write_buf,write_len,NULL,NULL);
+ writefile(fd,st.st_size,NULL,NULL);
+ }
+
+ delete reqcode;
+}
+
+
+static int judge_submit_waitqueue(){
+ int count;
+ judge_submit_info *sub_info;
+ bool wait_flag;
+ std::list<judge_info*>::iterator judge_it;
+ judge_info *info;
+ std::map<int,center_pro_info*>::iterator pro_it;
+ center_pro_info *pro_info;
+
+ count = judge_submitqueue.size();
+ for(;count > 0;count--){
+ sub_info = judge_submitqueue.front();
+ judge_submitqueue.pop();
+
+ if((pro_it = center_manage_promap.find(sub_info->proid)) == center_manage_promap.end()){
+ continue;
+ }
+ pro_info = pro_it->second;
+
+ wait_flag = true;
+ for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){
+ info = *judge_it;
+ if(info->avail <= 0){
+ break;
+ }
+ if(info->pro_map.find(pro_info->proid) != info->pro_map.end() && info->jmod_map.find(pro_info->jmod_info->name) != info->jmod_map.end()){
+ info->submit(sub_info);
+ wait_flag = false;
+ break;
+ }
+ }
+ if(wait_flag == true){
+ judge_submitqueue.push(sub_info);
+ }
+ }
+ return 0;
+}
+int center_judge_init(){
+ return 0;
+}
+void* center_judge_addconn(int fd){
+ return new judge_conn(fd);
+}
+int center_judge_dispatch(int evflag,void *data){
+ judge_conn *cinfo;
+
+ cinfo = (judge_conn*)data;
+ if(evflag & EPOLLRDHUP){
+ printf("close %d\n",cinfo->fd);
+ delete cinfo;
+ }else{
+ if(evflag & EPOLLIN){
+ cinfo->readio();
+ }
+ if(evflag & EPOLLOUT){
+ cinfo->writeio();
+ }
+ }
+
+ return 0;
+}
+int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len){
+ judge_submitqueue.push(new judge_submit_info(subid,proid,lang,set_data,set_len));
+ judge_submit_waitqueue();
+ return 0;
+}
diff --git a/toj/center/src/center_judge.h b/toj/center/src/center_judge.h
new file mode 100644
index 0000000..74b2daf
--- /dev/null
+++ b/toj/center/src/center_judge.h
@@ -0,0 +1,106 @@
+class judge_info;
+class judge_conn;
+class judge_submit_info;
+
+class judge_info{
+private:
+ static int last_id;
+
+public:
+ int id;
+ int avail;
+ judge_conn *conn_main;
+ std::list<judge_conn*> conn_list;
+ std::list<judge_info*>::iterator judge_it;
+ std::map<int,center_pro_info*> pro_map;
+ std::map<std::string,center_jmod_info*> jmod_map;
+
+ judge_info();
+ ~judge_info();
+ int setavail(int value);
+ int setinfo(int avail);
+ int submit(judge_submit_info *submit_info);
+ int result(int subid,char *res_data);
+};
+
+class judge_conn : public netio{
+private:
+ netio_iofn<judge_conn> *recv_dispatch_fn;
+ netio_iofn<judge_conn> *recv_setid_fn;
+ netio_iofn<judge_conn> *recv_setinfo_fn;
+ netio_iofn<judge_conn> *recv_result_fn;
+ netio_iofn<judge_conn> *recv_setpro_fn;
+ netio_iofn<judge_conn> *recv_reqpro_fn;
+ netio_iofn<judge_conn> *recv_setjmod_fn;
+ netio_iofn<judge_conn> *recv_reqjmod_fn;
+ netio_iofn<judge_conn> *recv_reqcode_fn;
+
+ char* create_combuf(int code,int size,int &len,void **data);
+ void recv_dispatch(void *buf,size_t len,void *data);
+ void recv_setid(void *buf,size_t len,void *data);
+ void recv_setinfo(void *buf,size_t len,void *data);
+ void recv_result(void *buf,size_t len,void *data);
+ void recv_setpro(void *buf,size_t len,void *data);
+ void recv_reqpro(void *buf,size_t len,void *data);
+ void recv_setjmod(void *buf,size_t len,void *data);
+ void recv_reqjmod(void *buf,size_t len,void *data);
+ void recv_reqcode(void *buf,size_t len,void *data);
+
+public:
+ judge_info *info;
+ std::list<judge_conn*>::iterator conn_it;
+
+ judge_conn(int fd);
+ ~judge_conn();
+ int send_setid(int judgeid);
+ int send_submit(judge_submit_info* submit_info);
+ int send_setpro(int *proid,int *cacheid,int type,int count);
+ int send_setjmod(char **jmod_name,int *cacheid,int type,int count);
+ virtual int readidle();
+};
+
+class judge_submit_info{
+public:
+ int subid;
+ int proid;
+ int lang;
+ char set_data[JUDGE_SET_DATAMAX];
+ size_t set_len;
+
+ judge_submit_info(int subid,int proid,int lang,char *setdata,size_t setlen){
+ this->subid = subid;
+ this->proid = proid;
+ this->lang = lang;
+ if(setlen > JUDGE_SET_DATAMAX){
+ memcpy(this->set_data,setdata,JUDGE_SET_DATAMAX);
+ }else{
+ memcpy(this->set_data,setdata,setlen);
+ }
+ this->set_len = setlen;
+ }
+};
+
+static int judge_submit_waitqueue();
+
+static std::map<int,judge_info*> judge_idmap;
+static std::list<judge_info*> judge_runlist;
+static std::queue<judge_submit_info*> judge_submitqueue;
+
+int center_judge_init();
+void* center_judge_addconn(int fd);
+int center_judge_dispatch(int evflag,void *data);
+int center_judge_submit(int subid,int proid,int lang,char *setdata,size_t setlen);
+
+extern int center_manage_result(int subid,char *res_data);
+
+extern std::map<std::string,center_jmod_info*> center_manage_jmodmap;
+extern std::map<int,center_pro_info*> center_manage_promap;
+
+
+
+/*#define JUDGE_DB_MAXSCOREMAX 1024
+static int tmp_init();
+static int tmp_update(int submitid,int count,void *data);
+static int server_updatedb(PGconn *sqlc,int submitid,int result_count,struct judgx_line_result *result);
+
+static PGconn *tmp_sqlc;*/
diff --git a/toj/center/src/center_manage.cpp b/toj/center/src/center_manage.cpp
new file mode 100644
index 0000000..887bdff
--- /dev/null
+++ b/toj/center/src/center_manage.cpp
@@ -0,0 +1,308 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<limits.h>
+#include<dlfcn.h>
+#include<unistd.h>
+#include<pthread.h>
+#include<semaphore.h>
+#include<libpq-fe.h>
+#include<sys/eventfd.h>
+#include<json/json.h>
+#include<vector>
+#include<queue>
+#include<map>
+#include<string>
+
+#include"tpool.h"
+#include"/srv/http/toj/php/event_exec.h"
+#include"center.h"
+#include"judge_def.h"
+#include"judgm_manage.h"
+#include"center_manage.h"
+
+int center_manage_init(tpool **tpinfo){
+ manage_packtp = new tpool(4);
+ manage_packtp->start();
+ *tpinfo = manage_packtp;
+
+ manage_packcode_thfn = new tpool_static_fn(manage_packcode_th);
+ manage_packcode_cbfn = new tpool_static_fn(manage_packcode_cb);
+
+ center_manage_updatedata();
+ return 0;
+}
+PGconn* center_manage_conndb(){
+ return PQconnectdb("host=localhost port=5432 dbname=xxxxx user=xxxxx password=xxxxx");
+}
+int center_manage_closedb(PGconn *conn){
+ PQfinish(conn);
+ return 0;
+}
+int center_manage_updatedata(){
+ int i;
+
+ PGconn *db_conn;
+ PGresult *db_res;
+ int db_count;
+ center_jmod_info *jmod_info;
+ int proid;
+ int lang_flag;
+ std::map<std::string,center_jmod_info*>::iterator jmod_it;
+ center_pro_info *pro_info;
+
+ if((db_conn = center_manage_conndb()) == NULL){
+ return -1;
+ }
+
+ db_res = PQexec(db_conn,"SELECT DISTINCT \"jmodname\" FROM \"mod\";");
+ if(PQresultStatus(db_res) != PGRES_TUPLES_OK){
+ center_manage_closedb(db_conn);
+ return -1;
+ }
+
+ db_count = PQntuples(db_res);
+ for(i = 0;i < db_count;i++){
+ jmod_info = new center_jmod_info(PQgetvalue(db_res,i,0),2);
+ center_manage_jmodmap.insert(std::pair<std::string,center_jmod_info*>(jmod_info->name,jmod_info));
+ }
+
+ PQclear(db_res);
+
+ db_res = PQexec(db_conn,"SELECT \"proid\",\"jmodname\",\"lang\" FROM \"problem\" INNER JOIN \"mod\" ON (\"problem\".\"modid\"=\"mod\".\"modid\");");
+ if(PQresultStatus(db_res) != PGRES_TUPLES_OK){
+ center_manage_closedb(db_conn);
+ return -1;
+ }
+
+ db_count = PQntuples(db_res);
+ for(i = 0;i < db_count;i++){
+ sscanf(PQgetvalue(db_res,i,0),"%d",&proid);
+ sscanf(PQgetvalue(db_res,i,2),"%d",&lang_flag);
+ if((jmod_it = center_manage_jmodmap.find(PQgetvalue(db_res,i,1))) == center_manage_jmodmap.end()){
+ continue;
+ }
+ pro_info = new center_pro_info(proid,1,jmod_it->second,lang_flag);
+ center_manage_promap.insert(std::pair<int,center_pro_info*>(pro_info->proid,pro_info));
+ }
+
+ PQclear(db_res);
+ center_manage_closedb(db_conn);
+ return 0;
+}
+int center_manage_submit(int subid,char *param){
+ PGconn *db_conn;
+ PGresult *db_res;
+ char *db_param[1];
+ char db_subid[64];
+
+ int uid;
+ int proid;
+ int lang;
+ std::map<int,center_pro_info*>::iterator pro_it;
+ center_pro_info *pro_info;
+ center_jmod_info *jmod_info;
+ center_submit_info *sub_info;
+
+ if((db_conn = center_manage_conndb()) == NULL){
+ return -1;
+ }
+
+ snprintf(db_subid,sizeof(db_subid),"%d",subid);
+ db_param[0] = db_subid;
+ db_res = PQexecParams(db_conn,
+ "SELECT \"uid\",\"proid\",\"lang\" FROM \"submit\" WHERE \"subid\"=$1;",
+ 1,
+ NULL,
+ db_param,
+ NULL,
+ NULL,
+ 0);
+ if(PQresultStatus(db_res) != PGRES_TUPLES_OK){
+ center_manage_closedb(db_conn);
+ return -1;
+ }
+
+ sscanf(PQgetvalue(db_res,0,0),"%d",&uid);
+ sscanf(PQgetvalue(db_res,0,1),"%d",&proid);
+ sscanf(PQgetvalue(db_res,0,2),"%d",&lang);
+ PQclear(db_res);
+ center_manage_closedb(db_conn);
+
+ if((pro_it = center_manage_promap.find(proid)) == center_manage_promap.end()){
+ return -1;
+ }
+ pro_info = pro_it->second;
+
+ if((lang & pro_info->lang_flag) == 0){
+ return -1;
+ }
+ jmod_info = pro_info->jmod_info;
+
+ sub_info = new center_submit_info(subid,uid,jmod_info,pro_info,lang,param);
+ center_manage_submap.insert(std::pair<int,center_submit_info*>(sub_info->subid,sub_info));
+ manage_packtp->add(manage_packcode_thfn,sub_info,manage_packcode_cbfn,sub_info);
+
+ return 0;
+}
+static void manage_packcode_th(void *data){
+ center_submit_info *sub_info;
+ int subid;
+ char dir_path[PATH_MAX + 1];
+ char pack_path[PATH_MAX + 1];
+
+ sub_info = (center_submit_info*)data;
+ subid = sub_info->subid;
+
+ snprintf(dir_path,sizeof(dir_path),"submit/%d/%d/data",(subid / 1000) * 1000,subid);
+ snprintf(pack_path,sizeof(pack_path),"tmp/codepack/%d.tar.bz2",subid);
+ pack_pack(pack_path,dir_path);
+}
+static void manage_packcode_cb(void *data){
+ center_submit_info *sub_info;
+ center_jmod_info *jmod_info;
+ center_pro_info *pro_info;
+
+ char cwd_path[PATH_MAX + 1];
+ char tpath[PATH_MAX + 1];
+ judgm_manage_submit_fn mod_sub_fn;
+ judgm_manage_submitinfo mod_sub_info;
+ FILE *set_file;
+ char lchr;
+ char tchr;
+
+ sub_info = (center_submit_info*)data;
+ jmod_info = sub_info->jmod_info;
+ pro_info = sub_info->pro_info;
+
+ if(jmod_info->manage_dll == NULL){
+ getcwd(cwd_path,sizeof(cwd_path));
+ snprintf(tpath,sizeof(tpath),"%s/jmod/%s/%s_manage.so",cwd_path,jmod_info->name,jmod_info->name);
+
+ jmod_info->manage_dll = dlopen(tpath,RTLD_NOW);
+ jmod_info->manage_sub_fn = dlsym(jmod_info->manage_dll,"submit");
+ jmod_info->manage_res_fn = dlsym(jmod_info->manage_dll,"result");
+ }
+ mod_sub_fn = (judgm_manage_submit_fn)jmod_info->manage_sub_fn;
+
+ mod_sub_info.uid = sub_info->uid;
+ mod_sub_info.subid = sub_info->subid;
+ mod_sub_info.proid = pro_info->proid;
+ mod_sub_info.lang = sub_info->lang;
+ mod_sub_info.param = sub_info->param;
+ snprintf(mod_sub_info.pro_path,sizeof(mod_sub_info.pro_path),"pro/%d",pro_info->proid);
+
+ snprintf(tpath,sizeof(tpath),"pro/%d/setting",pro_info->proid);
+ set_file = fopen(tpath,"r");
+ lchr = '\n';
+ while((tchr = fgetc(set_file)) != EOF){
+ if(lchr == '\n' && tchr == '='){
+ while(fgetc(set_file) != '\n');
+ break;
+ }
+ lchr = tchr;
+ }
+ mod_sub_info.set_file = set_file;
+
+ mod_sub_fn(&mod_sub_info,&sub_info->jmod_manage_data);
+
+ fclose(set_file);
+}
+static int manage_notice(int subid,int uid,int proid,int result,int runtime,int memory){
+ char msg[4096];
+ json_object *jso_msg;
+ json_object *jso_arg;
+
+ jso_msg = json_object_new_object();
+ json_object_object_add(jso_msg,"type",json_object_new_string("result"));
+ json_object_object_add(jso_msg,"subid",json_object_new_int(subid));
+ json_object_object_add(jso_msg,"proid",json_object_new_int(proid));
+ json_object_object_add(jso_msg,"result",json_object_new_int(result));
+ json_object_object_add(jso_msg,"runtime",json_object_new_int(runtime));
+ json_object_object_add(jso_msg,"memory",json_object_new_int(memory / 1024UL));
+
+ jso_arg = json_object_new_array();
+ json_object_array_add(jso_arg,json_object_new_int(uid));
+ json_object_array_add(jso_arg,jso_msg);
+
+ printf("%d %d %d\n",uid,proid,event_exec("pzreadtest.php","center_result_event",json_object_get_string(jso_arg)));
+ json_object_put(jso_arg);
+
+ return 0;
+}
+
+int center_manage_result(int subid,char *res_data){
+ int ret;
+
+ std::map<int,center_submit_info*>::iterator sub_it;
+ center_submit_info *sub_info;
+ center_jmod_info *jmod_info;
+
+ char res_path[PATH_MAX + 1];
+ judgm_manage_resultinfo res_info;
+ judgm_manage_result_fn res_fn;
+
+ PGconn *db_conn;
+ PGresult *db_res;
+ char db_result[32];
+ char db_score[32];
+ char db_runtime[32];
+ char db_memory[32];
+ char db_subid[32];
+ char *db_param[5];
+
+ if((sub_it = center_manage_submap.find(subid)) == center_manage_submap.end()){
+ return -1;
+ }
+ sub_info = sub_it->second;
+ jmod_info = sub_info->jmod_info;
+
+ res_info.uid = sub_info->uid;
+ res_info.subid = subid;
+ res_info.proid = sub_info->pro_info->proid;
+ snprintf(res_path,sizeof(res_path),"submit/%d/%d/result",(subid / 1000) * 1000,subid);
+ res_info.res_path = res_path;
+ res_info.res_data = res_data;
+ res_fn = (judgm_manage_result_fn)jmod_info->manage_res_fn;
+ ret = res_fn(&res_info,sub_info->jmod_manage_data);
+ if(ret == 1){
+ center_manage_submap.erase(sub_it);
+
+ if((db_conn = center_manage_conndb()) == NULL){
+ return -1;
+ }
+
+ snprintf(db_result,sizeof(db_result),"%d",res_info.result);
+ snprintf(db_score,sizeof(db_score),"%d",(int)res_info.score);
+ snprintf(db_runtime,sizeof(db_runtime),"%lu",res_info.runtime);
+ snprintf(db_memory,sizeof(db_memory),"%lu",res_info.memory / 1024UL);
+ snprintf(db_subid,sizeof(db_subid),"%d",subid);
+ db_param[0] = db_result;
+ db_param[1] = db_score;
+ db_param[2] = db_runtime;
+ db_param[3] = db_memory;
+ db_param[4] = db_subid;
+ db_res = PQexecParams(db_conn,
+ "UPDATE \"submit\" SET \"result\"=$1,\"score\"=$2,\"runtime\"=$3,\"memory\"=$4 WHERE \"subid\"=$5;",
+ 5,
+ NULL,
+ db_param,
+ NULL,
+ NULL,
+ 0);
+ PQclear(db_res);
+ center_manage_closedb(db_conn);
+
+ manage_notice(subid,sub_info->uid,sub_info->pro_info->proid,res_info.result,res_info.runtime,res_info.memory);
+
+ delete sub_info;
+ }else{
+ return -1;
+ }
+
+ return 0;
+}
+DLL_PUBLIC int center_manage_queuesubmit(int subid,int proid,int lang,char *set_data,size_t set_len){
+ center_judge_submit(subid,proid,lang,set_data,set_len);
+ return 0;
+}
diff --git a/toj/center/src/center_manage.h b/toj/center/src/center_manage.h
new file mode 100644
index 0000000..27e1bc9
--- /dev/null
+++ b/toj/center/src/center_manage.h
@@ -0,0 +1,23 @@
+static void manage_packcode_th(void *data);
+static void manage_packcode_cb(void *data);
+static int manage_notice(int subid,int uid,int proid,int result,int runtime,int memory);
+
+static tpool *manage_packtp;
+static tpool_static_fn *manage_packcode_thfn;
+static tpool_static_fn *manage_packcode_cbfn;
+
+int center_manage_init(tpool **tpinfo);
+PGconn* center_manage_conndb();
+int center_manage_closedb(PGconn *conn);
+int center_manage_updatedata();
+int center_manage_submit(int subid,char *param);
+int center_manage_result(int subid,char *res_data);
+DLL_PUBLIC int center_manage_queuesubmit(int subid,int proid,int lang,char *set_data,size_t set_len);
+
+std::map<std::string,center_jmod_info*> center_manage_jmodmap;
+std::map<int,center_pro_info*> center_manage_promap;
+std::map<int,center_submit_info*> center_manage_submap;
+
+extern int pack_pack(char *pack_path,char *dir_path);
+extern int pack_unpack(char *pack_path,char *dir_path);
+extern int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len);
diff --git a/toj/center/src/center_server.cpp b/toj/center/src/center_server.cpp
new file mode 100644
index 0000000..406e0fc
--- /dev/null
+++ b/toj/center/src/center_server.cpp
@@ -0,0 +1,192 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+#include<signal.h>
+#include<limits.h>
+#include<errno.h>
+#include<fcntl.h>
+#include<pthread.h>
+#include<semaphore.h>
+#include<libpq-fe.h>
+#include<sys/socket.h>
+#include<sys/epoll.h>
+#include<sys/eventfd.h>
+#include<netinet/in.h>
+#include<arpa/inet.h>
+#include<libpq-fe.h>
+#include<vector>
+#include<queue>
+
+#include"tpool.h"
+#include"center_server.h"
+
+server_epevdata::server_epevdata(int fd,int type,void *data){
+ this->fd = fd;
+ this->type = type;
+ this->data = data;
+}
+
+
+server_web_conn::server_web_conn(int fd){
+ this->fd = fd;
+ this->off = 0;
+ this->count = 0;
+}
+server_web_conn::~server_web_conn(){
+ epoll_ctl(server_epfd,EPOLL_CTL_DEL,fd,NULL);
+ close(fd);
+}
+int server_web_conn::readio(){
+ int ret;
+ char c;
+ int len;
+ int subid;
+ char *param;
+
+ while((ret = read(fd,&c,1)) > 0){
+ buf[off] = c;
+ off++;
+ if(c == '\0'){
+ count++;
+ if(count == 2){
+ break;
+ }
+ }
+ }
+
+ if(count == 2){
+ off = 0;
+ count = 0;
+
+ sscanf(buf,"%d",&subid);
+ param = buf + strlen(buf) + 1;
+ printf("%d %s\n",subid,param);
+
+ center_manage_submit(subid,param);
+
+ write(fd,"S",2);
+ }
+
+ return 0;
+}
+
+
+static int server_addepev(int fd,unsigned int flag,int type,void *data){
+ server_epevdata *epevdata;
+ epoll_event epev;
+
+ epevdata = new server_epevdata(fd,type,data);
+ epev.events = flag;
+ epev.data.ptr = epevdata;
+ epoll_ctl(server_epfd,EPOLL_CTL_ADD,fd,&epev);
+
+ return 0;
+}
+static int server_delepev(server_epevdata *epevdata){
+ epoll_ctl(server_epfd,EPOLL_CTL_DEL,epevdata->fd,NULL);
+ delete epevdata;
+ return 0;
+}
+int main(){
+ int ret;
+ int i;
+
+ int judge_sfd;
+ int web_sfd;
+ int cfd;
+ sockaddr_in saddr;
+ sockaddr_in caddr;
+ epoll_event epev;
+ epoll_event epevs[SERVER_EPOLL_MAXEVENT];
+ int nevs;
+
+ unsigned int ev_flag;
+ server_epevdata *epevdata;
+ server_web_conn *winfo;
+ tpool *tpinfo;
+
+ signal(SIGPIPE,SIG_IGN);
+ server_epfd = epoll_create1(0);
+ center_manage_init(&tpinfo);
+ server_addepev(tpinfo->fd,EPOLLIN | EPOLLET,SERVER_EPEV_TPOOL,tpinfo);
+ center_judge_init();
+
+
+ judge_sfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6);
+ saddr.sin_family = AF_INET;
+ saddr.sin_port = htons(SERVER_JUDGE_PORT);
+ //saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ //saddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ saddr.sin_addr.s_addr = inet_addr("10.8.0.2");
+ setsockopt(judge_sfd,SOL_SOCKET,SO_REUSEADDR,&saddr,sizeof(saddr));
+ bind(judge_sfd,(sockaddr*)&saddr,sizeof(saddr));
+
+ server_addepev(judge_sfd,EPOLLIN | EPOLLET,SERVER_EPEV_JUDGESERVER,NULL);
+ listen(judge_sfd,4096);
+
+ web_sfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6);
+ saddr.sin_family = AF_INET;
+ saddr.sin_port = htons(SERVER_WEB_PORT);
+ saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ //saddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ setsockopt(web_sfd,SOL_SOCKET,SO_REUSEADDR,&saddr,sizeof(saddr));
+ bind(web_sfd,(sockaddr*)&saddr,sizeof(saddr));
+
+ server_addepev(web_sfd,EPOLLIN | EPOLLET,SERVER_EPEV_WEBSERVER,NULL);
+ listen(web_sfd,4096);
+
+ while(true){
+ nevs = epoll_wait(server_epfd,epevs,SERVER_EPOLL_MAXEVENT,-1);
+ for(i = 0;i < nevs;i++){
+ ev_flag = epevs[i].events;
+ epevdata = (server_epevdata*)epevs[i].data.ptr;
+
+ if(epevdata->type == SERVER_EPEV_JUDGESERVER){
+ while(true){
+ ret = 0;
+ if((cfd = accept4(epevdata->fd,(sockaddr*)&caddr,(socklen_t*)&ret,SOCK_NONBLOCK)) == -1){
+ break;
+ }
+
+ server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_JUDGECLIENT,center_judge_addconn(cfd));
+ }
+ }else if(epevdata->type == SERVER_EPEV_JUDGECLIENT){
+ center_judge_dispatch(ev_flag,epevdata->data);
+ if(ev_flag & EPOLLRDHUP){
+ server_delepev(epevdata);
+ }
+ }else if(epevdata->type == SERVER_EPEV_WEBSERVER){
+ printf("test\n");
+ while(true){
+ ret = 0;
+ if((cfd = accept4(epevdata->fd,(sockaddr*)&caddr,(socklen_t*)&ret,SOCK_NONBLOCK)) == -1){
+ break;
+ }
+
+ server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_WEBCLIENT,new server_web_conn(cfd));
+ }
+ }else if(epevdata->type == SERVER_EPEV_WEBCLIENT){
+ winfo = (server_web_conn*)epevdata->data;
+ if(ev_flag & EPOLLIN){
+ winfo->readio();
+ }
+ if(ev_flag & EPOLLRDHUP){
+ delete winfo;
+ delete (server_epevdata*)epev.data.ptr;
+ }
+ }else if(epevdata->type == SERVER_EPEV_TPOOL){
+ tpinfo = (tpool*)epevdata->data;
+ if(ev_flag & EPOLLIN){
+ tpinfo->done();
+ }
+ }
+ }
+ }
+
+ close(judge_sfd);
+ close(server_epfd);
+ close(web_sfd);
+
+ return 0;
+}
diff --git a/toj/center/src/center_server.h b/toj/center/src/center_server.h
new file mode 100644
index 0000000..140a1d4
--- /dev/null
+++ b/toj/center/src/center_server.h
@@ -0,0 +1,45 @@
+#define SERVER_JUDGE_PORT 2573
+#define SERVER_WEB_PORT 2501
+#define SERVER_EPOLL_MAXEVENT 4096
+
+#define SERVER_EPEV_JUDGESERVER 0
+#define SERVER_EPEV_JUDGECLIENT 1
+#define SERVER_EPEV_WEBSERVER 2
+#define SERVER_EPEV_WEBCLIENT 3
+#define SERVER_EPEV_TPOOL 4
+class server_epevdata{
+public:
+ int fd;
+ int type;
+ void *data;
+
+ server_epevdata(int fd,int type,void *data);
+};
+
+class server_web_conn{
+private:
+ int fd;
+ char buf[65536];
+ int off;
+ int count;
+
+public:
+ server_web_conn(int fd);
+ ~server_web_conn();
+ int readio();
+};
+
+static int server_addepev(int fd,unsigned int flag,int type,void *data);
+static int server_delepev(server_epevdata *epevdata);
+static int server_epfd;
+
+extern int center_manage_init(tpool **tpinfo);
+extern int center_manage_submit(int subid,char *param);
+
+extern int center_judge_init();
+extern void* center_judge_addconn(int fd);
+extern int center_judge_dispatch(int ev_flag,void *data);
+extern int center_judge_submit(int subid,int proid);
+
+extern int pack_pack(char *pack_path,char *dir_path);
+extern int pack_unpack(char *pack_path,char *target_path);
diff --git a/toj/center/src/jmod_test.h b/toj/center/src/jmod_test.h
new file mode 100644
index 0000000..49381fc
--- /dev/null
+++ b/toj/center/src/jmod_test.h
@@ -0,0 +1,15 @@
+typedef int (*check_init_fn)(int judgk_modfd,char *datapath,char *runpath);
+typedef int (*check_run_fn)(int &status);
+typedef int (*check_stop_fn)();
+
+struct line_set_data{
+ int test_id;
+};
+struct line_result_data{
+ int test_id;
+ int status;
+ double score;
+ unsigned long runtime;
+ unsigned long memory;
+ char errmsg[4096];
+};
diff --git a/toj/center/src/jmod_test_check.cpp b/toj/center/src/jmod_test_check.cpp
new file mode 100644
index 0000000..df7368f
--- /dev/null
+++ b/toj/center/src/jmod_test_check.cpp
@@ -0,0 +1,104 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<limits.h>
+#include<unistd.h>
+#include<fcntl.h>
+#include<errno.h>
+
+#include"judge_def.h"
+#include"judgm_lib.h"
+#include"jmod_test.h"
+#include"jmod_test_check.h"
+
+static int ansfd;
+static judgm_hyperio *hyperio;
+static int tty_idx;
+
+int p[2];
+
+DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath){
+ char tpath[PATH_MAX + 1];
+ char dstpath[PATH_MAX + 1];
+
+ pipe(p);
+
+ snprintf(tpath,sizeof(tpath),"%s/in",datapath);
+ snprintf(dstpath,sizeof(dstpath),"%s/in",runpath);
+ if(link(tpath,dstpath)){
+ return -1;
+ }
+ snprintf(tpath,sizeof(tpath),"%s/ans",datapath);
+ if((ansfd = open(tpath,O_RDONLY)) == -1){
+ return -1;
+ }
+
+ //hyperio = new judgm_hyperio(judgk_modfd);
+ //tty_idx = hyperio->tty_idx;
+
+ return 0;
+}
+DLL_PUBLIC int run(int &status){
+ int ret;
+
+ char *inbuf;
+ char *ansbuf;
+
+ status = JUDGE_AC;
+ inbuf = new char[65536];
+ ansbuf = new char[65536];
+
+ /*while((ret = read(ansfd,ansbuf,65536)) > 0){
+ if(hyperio->compare(ansbuf,ret)){
+ status = JUDGE_WA;
+ break;
+ }
+ }
+ if(status == JUDGE_AC && hyperio->wait() > 0){
+ status = JUDGE_WA;
+ }
+
+ delete inbuf;
+ delete ansbuf;
+ close(ansfd);
+ delete hyperio;*/
+
+ close(p[1]);
+ while((ret = read(p[0],inbuf,65536)) > 0){
+ if(read(ansfd,ansbuf,ret) != ret){
+ status = JUDGE_WA;
+ break;
+ }
+ if(memcmp(ansbuf,inbuf,ret)){
+ status = JUDGE_WA;
+ break;
+ }
+ }
+ if(status == JUDGE_AC && read(ansfd,ansbuf,1) > 0){
+ status = JUDGE_WA;
+ }
+
+ return 0;
+}
+DLL_PUBLIC int proc(){
+ int infd;
+ int outfd;
+
+ if((infd = open("in",O_RDONLY)) == -1){
+ return -1;
+ }
+ /*if((outfd = judgm_hyperio::get_ttyfd(tty_idx)) == -1){
+ return -1;
+ }*/
+
+ close(p[0]);
+ outfd = p[1];
+ dup2(infd,0);
+ dup2(outfd,1);
+ dup2(outfd,2);
+
+ return 0;
+}
+DLL_PUBLIC int stop(){
+ return 0;
+}
diff --git a/toj/center/src/jmod_test_check.h b/toj/center/src/jmod_test_check.h
new file mode 100644
index 0000000..57bc2c6
--- /dev/null
+++ b/toj/center/src/jmod_test_check.h
@@ -0,0 +1,4 @@
+DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath);
+DLL_PUBLIC int run(int &status);
+DLL_PUBLIC int proc();
+DLL_PUBLIC int stop();
diff --git a/toj/center/src/jmod_test_line.cpp b/toj/center/src/jmod_test_line.cpp
new file mode 100644
index 0000000..85340ad
--- /dev/null
+++ b/toj/center/src/jmod_test_line.cpp
@@ -0,0 +1,189 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<limits.h>
+#include<dlfcn.h>
+#include<pthread.h>
+#include<json/json.h>
+
+#include"judge_def.h"
+#include"judgm_lib.h"
+#include"judgm_line.h"
+#include"jmod_test.h"
+#include"jmod_test_line.h"
+
+static int line_load_setfile(FILE *set_file,int test_id,int &timelimit,int &memlimit,double &score){
+ int ret;
+
+ json_object *jso;
+ char buf[JUDGE_SET_FILEMAX];
+
+ fread(buf,1,sizeof(buf),set_file);
+ jso = json_tokener_parse(buf);
+
+ timelimit = json_object_get_int(json_object_object_get(jso,"timelimit"));
+ memlimit = json_object_get_int(json_object_object_get(jso,"memlimit"));
+ score = json_object_get_double(json_object_array_get_idx(json_object_object_get(jso,"score"),test_id - 1));
+
+ json_object_put(jso);
+ return 0;
+}
+static void line_sigaction(int sig_num,siginfo_t *sig_info,void *context){
+ if(sig_info->si_pid == line_proc->pid && line_proc->status == JUDGE_RUN){
+ if(!line_proc->proc_wait(false)){
+ line_chk_stop_fn();
+ }
+ }
+}
+static int line_sig_set(){
+ struct sigaction sig;
+
+ sig.sa_sigaction = line_sigaction;
+ sigemptyset(&sig.sa_mask);
+ sig.sa_flags = SA_SIGINFO | SA_RESTART;
+ if(sigaction(SIGCHLD,&sig,NULL)){
+ return -1;
+ }
+
+ return 0;
+}
+static int line_sig_restore(){
+ struct sigaction sig;
+
+ sig.sa_handler = SIG_DFL;
+ sigemptyset(&sig.sa_mask);
+ sig.sa_flags = 0;
+ if(sigaction(SIGCHLD,&sig,NULL)){
+ return -1;
+ }
+
+ return 0;
+}
+static int line_sig_block(){
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask,SIGCHLD);
+ if(pthread_sigmask(SIG_BLOCK,&mask,NULL)){
+ return -1;
+ }
+
+ return 0;
+}
+static int line_sig_unblock(){
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask,SIGCHLD);
+ if(pthread_sigmask(SIG_UNBLOCK,&mask,NULL)){
+ return -1;
+ }
+
+ return 0;
+}
+static int line_sig_wait(){
+ sigset_t mask;
+ int num;
+
+ sigfillset(&mask);
+ sigdelset(&mask,SIGKILL);
+ sigdelset(&mask,SIGTERM);
+ sigdelset(&mask,SIGINT);
+ sigdelset(&mask,SIGCHLD);
+ sigsuspend(&mask);
+
+ return 0;
+}
+DLL_PUBLIC int run(judgm_line_info *info){
+ int i;
+
+ line_result_data *res_data;
+
+ int set_timelimit;
+ int set_memlimit;
+ double set_score;
+ line_set_data *set_data;
+
+ char main_path[PATH_MAX + 1];
+ char exe_path[PATH_MAX + 1];
+
+ check_init_fn chk_init_fn;
+ check_run_fn chk_run_fn;
+ judgm_proc_check_fn chk_proc_fn;
+
+ char data_path[PATH_MAX + 1];
+ int chk_status;
+
+ set_data = (line_set_data*)info->set_data;
+
+ res_data = (line_result_data*)info->res_data;
+ info->res_len = sizeof(line_result_data);
+
+ res_data->test_id = set_data->test_id;
+ res_data->status = JUDGE_ERR;
+ res_data->score = 0;
+ res_data->runtime = 0;
+ res_data->memory = 0;
+
+ if(line_load_setfile(info->set_file,set_data->test_id,set_timelimit,set_memlimit,set_score)){
+ return -1;
+ }
+
+ snprintf(main_path,sizeof(main_path),"%s/main.cpp",info->code_path);
+ snprintf(exe_path,sizeof(exe_path),"%s/test",info->run_path);
+ if(judgm_compile(info->subid,main_path,exe_path,info->lang,false,res_data->errmsg,sizeof(res_data->errmsg))){
+ res_data->status = JUDGE_CE;
+ return -1;
+ }
+
+ chk_init_fn = (check_init_fn)dlsym(info->check_dll,"init");
+ chk_run_fn = (check_run_fn)dlsym(info->check_dll,"run");
+ chk_proc_fn = (judgm_proc_check_fn)dlsym(info->check_dll,"proc");
+ line_chk_stop_fn = (check_stop_fn)dlsym(info->check_dll,"stop");
+ line_proc = new judgm_proc(info->judgk_modfd,info->run_path,exe_path,set_timelimit,(set_timelimit * 10 + 5000),set_memlimit,chk_proc_fn);
+
+ snprintf(data_path,sizeof(data_path),"%s/private/%d",info->pro_path,set_data->test_id);
+ if(chk_init_fn(info->judgk_modfd,data_path,info->run_path)){
+ delete line_proc;
+ return -1;
+ }
+ if(line_sig_set()){
+ delete line_proc;
+ return -1;
+ }
+
+ if(line_proc->proc_run()){
+ delete line_proc;
+ return -1;
+ }
+ chk_run_fn(chk_status);
+
+ line_sig_block();
+ if(line_proc->status == JUDGE_RUN){
+ line_proc->proc_kill();
+ line_sig_wait();
+ }
+ line_sig_unblock();
+
+ printf("check status %d proc status %d\n",chk_status,line_proc->status);
+
+ if(line_sig_restore()){
+ delete line_proc;
+ return -1;
+ }
+
+ if(line_proc->status != JUDGE_AC){
+ res_data->status = line_proc->status;
+ }else{
+ res_data->status = chk_status;
+ }
+ if(res_data->status == JUDGE_AC){
+ res_data->score = set_score;
+ }else{
+ res_data->score = 0;
+ }
+ res_data->runtime = line_proc->runtime;
+ res_data->memory = line_proc->memory;
+
+ delete line_proc;
+ return 0;
+}
diff --git a/toj/center/src/jmod_test_line.h b/toj/center/src/jmod_test_line.h
new file mode 100644
index 0000000..c09a503
--- /dev/null
+++ b/toj/center/src/jmod_test_line.h
@@ -0,0 +1,11 @@
+static int line_load_setfile(FILE *set_file,int test_id,int &timelimit,int &memlimit,double &score);
+static int line_sig_set();
+static int line_sig_restore();
+static int line_sig_block();
+static int line_sig_unblock();
+static int line_sig_wait();
+
+static judgm_proc *line_proc;
+static check_stop_fn line_chk_stop_fn;
+
+DLL_PUBLIC int run(judgm_line_info *info);
diff --git a/toj/center/src/jmod_test_manage.cpp b/toj/center/src/jmod_test_manage.cpp
new file mode 100644
index 0000000..e4738df
--- /dev/null
+++ b/toj/center/src/jmod_test_manage.cpp
@@ -0,0 +1,98 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<limits.h>
+#include<dlfcn.h>
+#include<json/json.h>
+
+#include"judge_def.h"
+#include"judgm_lib.h"
+#include"judgm_manage.h"
+#include"jmod_test.h"
+#include"jmod_test_manage.h"
+
+static void __attribute__ ((constructor)) manage_init(){
+ manage_queuesubmit_fn = (judgm_manage_queuesubmit_fn)dlsym(dlopen(NULL,RTLD_NOW),"center_manage_queuesubmit");
+}
+static int manage_load_setfile(FILE *set_file,int &count){
+ int ret;
+
+ json_object *jso;
+ char buf[JUDGE_SET_FILEMAX];
+
+ fread(buf,1,sizeof(buf),set_file);
+ jso = json_tokener_parse(buf);
+
+ count = json_object_get_int(json_object_object_get(jso,"count"));
+
+ json_object_put(jso);
+ return 0;
+}
+
+DLL_PUBLIC int submit(judgm_manage_submitinfo *info,void **manage_data){
+ int i;
+
+ int count;
+ manage_result_info *res_info;
+ line_set_data set_data;
+
+ manage_load_setfile(info->set_file,count);
+
+ res_info = new manage_result_info(count);
+ *manage_data = res_info;
+
+ for(i = 0;i < count;i++){
+ set_data.test_id = i + 1;
+ manage_queuesubmit_fn(info->subid,info->proid,info->lang,(char*)&set_data,sizeof(line_set_data));
+ }
+
+ return 0;
+}
+DLL_PUBLIC int result(judgm_manage_resultinfo *info,void *manage_data){
+ manage_result_info *res_info;
+ line_result_data *res_data;
+ json_object *jso_item;
+ char tpath[PATH_MAX + 1];
+
+ res_info = (manage_result_info*)manage_data;
+ res_info->test_count++;
+
+ res_data = (line_result_data*)info->res_data;
+ if(res_data->status > res_info->test_result){
+ res_info->test_result = res_data->status;
+ }
+ res_info->test_totalscore += res_data->score;
+ res_info->test_totalruntime += res_data->runtime;
+ if(res_data->memory > res_info->test_maxmemory){
+ res_info->test_maxmemory = res_data->memory;
+ }
+
+ jso_item = json_object_new_object();
+ json_object_object_add(jso_item,"status",json_object_new_int(res_data->status));
+ json_object_object_add(jso_item,"score",json_object_new_double(res_data->score));
+ json_object_object_add(jso_item,"runtime",json_object_new_int64(res_data->runtime));
+ json_object_object_add(jso_item,"memory",json_object_new_int64(res_data->memory / 1024UL));
+ if(res_data->status == JUDGE_CE){
+ json_object_object_add(jso_item,"errmsg",json_object_new_string(res_data->errmsg));
+ }
+ json_object_array_put_idx(res_info->jso_resarray,res_data->test_id - 1,jso_item);
+
+ printf("jmod count %d %d\n",res_info->test_count,res_info->test_allcount);
+ if(res_info->test_count == res_info->test_allcount){
+ snprintf(tpath,sizeof(tpath),"%s/result",info->res_path);
+ json_object_to_file_ext(tpath,res_info->jso_res,JSON_C_TO_STRING_PLAIN);
+
+ info->result = res_info->test_result;
+ info->score = res_info->test_totalscore;
+ info->runtime = res_info->test_totalruntime;
+ info->memory = res_info->test_maxmemory;
+
+ printf("finish result\n");
+
+ delete res_info;
+ return 1;
+ }
+ return 0;
+}
+
+
diff --git a/toj/center/src/jmod_test_manage.h b/toj/center/src/jmod_test_manage.h
new file mode 100644
index 0000000..811274a
--- /dev/null
+++ b/toj/center/src/jmod_test_manage.h
@@ -0,0 +1,35 @@
+class manage_result_info{
+public:
+ int test_allcount;
+ int test_count;
+ int test_result;
+ double test_totalscore;
+ unsigned long test_totalruntime;
+ unsigned long test_maxmemory;
+ json_object *jso_res;
+ json_object *jso_resarray;
+
+ manage_result_info(int allcount){
+ this->test_allcount = allcount;
+ this->test_count = 0;
+ this->test_result = JUDGE_AC;
+ this->test_totalscore = 0;
+ this->test_totalruntime = 0;
+ this->test_maxmemory = 0;
+
+ this->jso_res = json_object_new_object();
+ this->jso_resarray = json_object_new_array();
+ json_object_object_add(this->jso_res,"result",this->jso_resarray);
+ }
+ ~manage_result_info(){
+ json_object_put(jso_res);
+ }
+};
+
+DLL_PUBLIC int submit(judgm_manage_submitinfo *info,void **manage_data);
+DLL_PUBLIC int result(judgm_manage_resultinfo *info,void *manage_data);
+
+static void __attribute__ ((constructor)) manage_init();
+static int manage_load_setfile(FILE *setfile,int &count);
+
+static judgm_manage_queuesubmit_fn manage_queuesubmit_fn;
diff --git a/toj/center/src/judge_def.h b/toj/center/src/judge_def.h
new file mode 100755
index 0000000..fad8c4d
--- /dev/null
+++ b/toj/center/src/judge_def.h
@@ -0,0 +1,20 @@
+#define JUDGE_AC 0
+#define JUDGE_WA 1
+#define JUDGE_TLE 2
+#define JUDGE_MLE 3
+#define JUDGE_RF 4
+#define JUDGE_RE 5
+#define JUDGE_CE 6
+#define JUDGE_ERR 7
+#define JUDGE_WAIT 100
+#define JUDGE_RUN 101
+
+#define JUDGE_CPP 0x1
+#define JUDGE_JAVA 0x2
+#define JUDGE_PASCEL 0x4
+
+#define JUDGE_SET_FILEMAX 65536
+#define JUDGE_SET_DATAMAX 4096
+#define JUDGE_RES_DATAMAX 65536
+
+#define DLL_PUBLIC extern "C" __attribute__ ((visibility ("default")))
diff --git a/toj/center/src/judge_server.cpp b/toj/center/src/judge_server.cpp
new file mode 100644
index 0000000..2741459
--- /dev/null
+++ b/toj/center/src/judge_server.cpp
@@ -0,0 +1,697 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+#include<fcntl.h>
+#include<dlfcn.h>
+#include<signal.h>
+#include<limits.h>
+#include<ftw.h>
+#include<pthread.h>
+#include<semaphore.h>
+#include<errno.h>
+#include<sys/types.h>
+#include<sys/socket.h>
+#include<sys/epoll.h>
+#include<sys/eventfd.h>
+#include<sys/sendfile.h>
+#include<sys/mman.h>
+#include<netinet/in.h>
+#include<arpa/inet.h>
+#include<map>
+#include<queue>
+
+#include"judge_def.h"
+#include"netio.h"
+#include"tpool.h"
+#include"center_com.h"
+#include"judgm_line.h"
+#include"judgm_lib.h"
+#include"judge_server.h"
+
+server_epevdata::server_epevdata(int fd,int type,void *data){
+ this->fd = fd;
+ this->type = type;
+ this->data = data;
+}
+
+
+server_conn::server_conn(int fd):netio(fd){
+ this->recv_dispatch_fn = new netio_iofn<server_conn>(this,&server_conn::recv_dispatch);
+ this->recv_setid_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setid);
+ this->recv_submit_fn = new netio_iofn<server_conn>(this,&server_conn::recv_submit);
+ this->recv_setpro_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setpro);
+ this->recv_sendpro_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendpro);
+ this->done_sendpro_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendpro);
+ this->recv_setjmod_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setjmod);
+ this->recv_sendjmod_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendjmod);
+ this->done_sendjmod_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendjmod);
+ this->recv_sendcode_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendcode);
+ this->done_sendcode_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendcode);
+ this->tp_unpackpro_thfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackpro_th);
+ this->tp_unpackpro_cbfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackpro_cb);
+ this->tp_unpackjmod_thfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackjmod_th);
+ this->tp_unpackjmod_cbfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackjmod_cb);
+ this->tp_unpackcode_thfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackcode_th);
+ this->tp_unpackcode_cbfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackcode_cb);
+ this->tp_judge_thfn = new tpool_fn<server_conn>(this,&server_conn::tp_judge_th);
+ this->tp_judge_cbfn = new tpool_fn<server_conn>(this,&server_conn::tp_judge_cb);
+
+ send_setid();
+}
+char* server_conn::create_combuf(int code,int size,int &len,void **data){
+ char *buf;
+ center_com_header *header;
+
+ buf = new char[sizeof(center_com_header) + size];
+ header = (center_com_header*)buf;
+ header->code = code;
+ header->size = size;
+ len = sizeof(center_com_header) + size;
+ *data = (void*)(buf + sizeof(center_com_header));
+
+ return buf;
+}
+int server_conn::send_setid(){
+ char *write_buf;
+ int write_len;
+ center_com_setid *setid;
+
+ write_buf = create_combuf(CENTER_COMCODE_SETID,sizeof(center_com_setid),write_len,(void**)&setid);
+ setid->id = server_id;
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int server_conn::send_setinfo(){
+ char *write_buf;
+ int write_len;
+ center_com_setinfo *setinfo;
+
+ write_buf = create_combuf(CENTER_COMCODE_SETINFO,sizeof(center_com_setinfo),write_len,(void**)&setinfo);
+ setinfo->avail = server_avail;
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int server_conn::send_result(int subid,char *res_data,size_t res_len){
+ char *write_buf;
+ int write_len;
+ center_com_result *result;
+
+ if(res_len > JUDGE_RES_DATAMAX){
+ return -1;
+ }
+
+ write_buf = create_combuf(CENTER_COMCODE_RESULT,sizeof(center_com_result) + res_len,write_len,(void**)&result);
+ result->subid = subid;
+ memcpy((void*)(write_buf + sizeof(center_com_header) + sizeof(center_com_result)),res_data,res_len);
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int server_conn::send_setpro(int *proid,int *cacheid,int type,int count){
+ int i;
+ char *write_buf;
+ int write_len;
+ center_com_setpro *setpro;
+
+ write_buf = create_combuf(CENTER_COMCODE_SETPRO,sizeof(center_com_setpro) * count,write_len,(void**)&setpro);
+ for(i = 0;i < count;i++){
+ setpro[i].proid = proid[i];
+ setpro[i].cacheid = cacheid[i];
+ setpro[i].type = type;
+ }
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int server_conn::send_setjmod(char **jmod_name,int *cacheid,int type,int count){
+ int i;
+
+ char *write_buf;
+ int write_len;
+ center_com_setjmod *setjmod;
+
+ write_buf = create_combuf(CENTER_COMCODE_SETJMOD,sizeof(center_com_setjmod) * count,write_len,(void**)&setjmod);
+ for(i = 0;i < count;i++){
+ setjmod[i].jmod_name[0] = '\0';
+ strncat(setjmod[i].jmod_name,jmod_name[i],sizeof(setjmod[i].jmod_name));
+ setjmod[i].cacheid = cacheid[i];
+ setjmod[i].type = type;
+ }
+ writebytes(write_buf,write_len,NULL,NULL);
+
+ return 0;
+}
+int server_conn::readidle(){
+ readbytes(new center_com_header,sizeof(center_com_header),recv_dispatch_fn,NULL);
+ return 0;
+}
+void server_conn::recv_dispatch(void *buf,size_t len,void *data){
+ center_com_header *header;
+ char *readbuf;
+
+ header = (center_com_header*)buf;
+ readbuf = new char[header->size];
+ printf("code:%d size:%d\n",header->code,header->size);
+ switch(header->code){
+ case CENTER_COMCODE_SETID:
+ readbytes(readbuf,header->size,recv_setid_fn,NULL);
+ break;
+ case CENTER_COMCODE_SUBMIT:
+ readbytes(readbuf,header->size,recv_submit_fn,NULL);
+ break;
+ case CENTER_COMCODE_SETPRO:
+ readbytes(readbuf,header->size,recv_setpro_fn,NULL);
+ break;
+ case CENTER_COMCODE_SENDPRO:
+ readbytes(readbuf,header->size,recv_sendpro_fn,NULL);
+ break;
+ case CENTER_COMCODE_SETJMOD:
+ readbytes(readbuf,header->size,recv_setjmod_fn,NULL);
+ break;
+ case CENTER_COMCODE_SENDJMOD:
+ readbytes(readbuf,header->size,recv_sendjmod_fn,NULL);
+ break;
+ case CENTER_COMCODE_SENDCODE:
+ readbytes(readbuf,header->size,recv_sendcode_fn,NULL);
+ break;
+ }
+
+ delete header;
+}
+void server_conn::recv_setid(void *buf,size_t len,void *data){
+ center_com_setid *setid;
+
+ setid = (center_com_setid*)buf;
+ server_id = setid->id;
+ printf("server_id:%d\n",server_id);
+
+ //judge server init
+ send_setinfo();
+
+ delete setid;
+}
+void server_conn::recv_submit(void *buf,size_t len,void *data){
+ center_com_submit *sub;
+ char *write_buf;
+ int write_len;
+ center_com_reqcode *reqcode;
+ std::multimap<int,center_com_submit*>::iterator sub_it;
+ char tpath[PATH_MAX + 1];
+ struct stat st;
+
+ sub = (center_com_submit*)buf;
+ if(server_codeconn == NULL){
+ server_codeconn = server_connect();
+ }
+
+ if(server_submap.find(sub->subid) == server_submap.end()){
+ snprintf(tpath,sizeof(tpath),"tmp/code/%d",sub->subid);
+ if(!stat(tpath,&st)){
+ server_queuejudge(sub,tp_judge_thfn,tp_judge_cbfn);
+ }else{
+ write_buf = create_combuf(CENTER_COMCODE_REQCODE,sizeof(center_com_submit),write_len,(void**)&reqcode);
+ reqcode->subid = sub->subid;
+ writebytes(write_buf,write_len,NULL,NULL);
+ server_submap.insert(std::pair<int,center_com_submit*>(sub->subid,sub));
+ }
+ }else{
+ server_submap.insert(std::pair<int,center_com_submit*>(sub->subid,sub));
+ }
+}
+void server_conn::recv_setpro(void *buf,size_t len,void *data){
+ int i;
+ int count;
+ center_com_setpro *setpro;
+
+ char tpath[PATH_MAX + 1];
+ FILE *f;
+ int cacheid;
+ std::vector<int> sl_proid;
+ std::vector<int> sl_cacheid;
+
+ char *write_buf;
+ int write_len;
+ center_com_reqpro *reqpro;
+
+ count = len / sizeof(center_com_setpro);
+ setpro = (center_com_setpro*)buf;
+ for(i = 0;i < count;i++){
+ if(setpro[i].type == 0){
+ snprintf(tpath,sizeof(tpath),"tmp/pro/%d/cacheinfo",setpro[i].proid);
+ f = fopen(tpath,"r");
+ if(f != NULL){
+ fscanf(f,"%d",&cacheid);
+ fclose(f);
+
+ if(cacheid == setpro[i].cacheid){
+ sl_proid.push_back(setpro[i].proid);
+ sl_cacheid.push_back(setpro[i].cacheid);
+ continue;
+ }
+ }
+
+ if(server_fileconn == NULL){
+ server_fileconn = server_connect();
+ }
+
+ write_buf = create_combuf(CENTER_COMCODE_REQPRO,sizeof(center_com_reqpro),write_len,(void**)&reqpro);
+ reqpro->proid = setpro[i].proid;
+ server_fileconn->writebytes(write_buf,write_len,NULL,NULL);
+ }else if(setpro[i].type == 1){
+
+ }
+ }
+
+ if(!sl_proid.empty()){
+ this->send_setpro(&sl_proid[0],&sl_cacheid[0],0,sl_proid.size());
+ }
+
+ delete setpro;
+}
+void server_conn::recv_sendpro(void *buf,size_t len,void *data){
+ center_com_sendpro *sendpro;
+ char tpath[PATH_MAX + 1];
+ int fd;
+
+ sendpro = (center_com_sendpro*)buf;
+ snprintf(tpath,sizeof(tpath),"tmp/propack/%d.tar.bz2",sendpro->proid);
+ fd = open(tpath,O_WRONLY | O_CREAT,0644);
+ readfile(fd,sendpro->filesize,done_sendpro_fn,sendpro);
+}
+void server_conn::done_sendpro(void *buf,size_t len,void *data){
+ center_com_sendpro *sendpro;
+
+ close(*(int*)buf);
+
+ sendpro = (center_com_sendpro*)data;
+ server_packtp->add(tp_unpackpro_thfn,sendpro,tp_unpackpro_cbfn,sendpro);
+}
+void server_conn::recv_setjmod(void *buf,size_t len,void *data){
+ int i;
+ int count;
+ center_com_setjmod *setjmod;
+
+ char tpath[PATH_MAX + 1];
+ FILE *f;
+ int cacheid;
+ std::vector<char*> sl_jmod_name;
+ std::vector<int> sl_cacheid;
+
+ char *write_buf;
+ int write_len;
+ center_com_reqjmod *reqjmod;
+
+ count = len / sizeof(center_com_setjmod);
+ setjmod = (center_com_setjmod*)buf;
+ for(i = 0;i < count;i++){
+ if(setjmod[i].type == 0){
+ snprintf(tpath,sizeof(tpath),"tmp/jmod/%s/cacheinfo",setjmod[i].jmod_name);
+ f = fopen(tpath,"r");
+ if(f != NULL){
+ fscanf(f,"%d",&cacheid);
+ fclose(f);
+
+ if(cacheid == setjmod[i].cacheid){
+ sl_jmod_name.push_back(setjmod[i].jmod_name);
+ sl_cacheid.push_back(setjmod[i].cacheid);
+ continue;
+ }
+ }
+
+ if(server_fileconn == NULL){
+ server_fileconn = server_connect();
+ }
+
+ write_buf = create_combuf(CENTER_COMCODE_REQJMOD,sizeof(center_com_reqjmod),write_len,(void**)&reqjmod);
+ reqjmod->jmod_name[0] = '\0';
+ strncat(reqjmod->jmod_name,setjmod[i].jmod_name,sizeof(reqjmod->jmod_name));
+ server_fileconn->writebytes(write_buf,write_len,NULL,NULL);
+ }else if(setjmod[i].type == 1){
+
+ }
+ }
+
+ if(!sl_jmod_name.empty()){
+ this->send_setjmod(&sl_jmod_name[0],&sl_cacheid[0],0,sl_jmod_name.size());
+ }
+
+ delete setjmod;
+}
+void server_conn::recv_sendjmod(void *buf,size_t len,void *data){
+ center_com_sendjmod *sendjmod;
+ char tpath[PATH_MAX + 1];
+ int fd;
+
+ sendjmod = (center_com_sendjmod*)buf;
+ snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s.tar.bz2",sendjmod->jmod_name);
+ fd = open(tpath,O_WRONLY | O_CREAT,0644);
+ readfile(fd,sendjmod->filesize,done_sendjmod_fn,sendjmod);
+}
+void server_conn::done_sendjmod(void *buf,size_t len,void *data){
+ center_com_sendjmod *sendjmod;
+
+ close(*(int*)buf);
+
+ sendjmod = (center_com_sendjmod*)data;
+ server_packtp->add(tp_unpackjmod_thfn,sendjmod,tp_unpackjmod_cbfn,sendjmod);
+}
+void server_conn::recv_sendcode(void *buf,size_t len,void *data){
+ center_com_sendcode *sendcode;
+ char tpath[PATH_MAX + 1];
+ int fd;
+
+ sendcode = (center_com_sendcode*)buf;
+ snprintf(tpath,sizeof(tpath),"tmp/codepack/%d.tar.bz2",sendcode->subid);
+ fd = open(tpath,O_WRONLY | O_CREAT,0644);
+ readfile(fd,sendcode->filesize,done_sendcode_fn,sendcode);
+}
+void server_conn::done_sendcode(void *buf,size_t len,void *data){
+ center_com_sendcode *sendcode;
+
+ close(*(int*)buf);
+
+ sendcode = (center_com_sendcode*)data;
+ server_packtp->add(tp_unpackcode_thfn,sendcode,tp_unpackcode_cbfn,sendcode);
+}
+void server_conn::tp_unpackpro_th(void *data){
+ center_com_sendpro *sendpro;
+ char pack_path[PATH_MAX + 1];
+ char dir_path[PATH_MAX + 1];
+ char tpath[PATH_MAX + 1];
+ FILE *f;
+
+ sendpro = (center_com_sendpro*)data;
+
+ snprintf(pack_path,sizeof(pack_path),"tmp/propack/%d.tar.bz2",sendpro->proid);
+ snprintf(dir_path,sizeof(dir_path),"tmp/pro/%d",sendpro->proid);
+
+ mkdir(dir_path,0755);
+ server_cleardir(dir_path);
+ pack_unpack(pack_path,dir_path);
+
+ snprintf(tpath,sizeof(tpath),"tmp/pro/%d/cacheinfo",sendpro->proid);
+ f = fopen(tpath,"w");
+ fprintf(f,"%d",sendpro->cacheid);
+ fclose(f);
+}
+void server_conn::tp_unpackpro_cb(void *data){
+ center_com_sendpro *sendpro;
+
+ sendpro = (center_com_sendpro*)data;
+ send_setpro(&sendpro->proid,&sendpro->cacheid,0,1);
+
+ delete sendpro;
+}
+void server_conn::tp_unpackjmod_th(void *data){
+ center_com_sendjmod *sendjmod;
+ char pack_path[PATH_MAX + 1];
+ char dir_path[PATH_MAX + 1];
+ char tpath[PATH_MAX + 1];
+ FILE *f;
+
+ sendjmod = (center_com_sendjmod*)data;
+
+ snprintf(pack_path,sizeof(pack_path),"tmp/jmodpack/%s.tar.bz2",sendjmod->jmod_name);
+ snprintf(dir_path,sizeof(dir_path),"tmp/jmod/%s",sendjmod->jmod_name);
+ mkdir(dir_path,0755);
+ server_cleardir(dir_path);
+ pack_unpack(pack_path,dir_path);
+
+ snprintf(tpath,sizeof(tpath),"tmp/jmod/%s/cacheinfo",sendjmod->jmod_name);
+ f = fopen(tpath,"w");
+ fprintf(f,"%d",sendjmod->cacheid);
+ fclose(f);
+}
+void server_conn::tp_unpackjmod_cb(void *data){
+ center_com_sendjmod *sendjmod;
+ char *jmod_name;
+
+ sendjmod = (center_com_sendjmod*)data;
+ jmod_name = sendjmod->jmod_name;
+ send_setjmod(&jmod_name,&sendjmod->cacheid,0,1);
+
+ delete sendjmod;
+}
+void server_conn::tp_unpackcode_th(void *data){
+ center_com_sendcode *sendcode;
+ char pack_path[PATH_MAX + 1];
+ char dir_path[PATH_MAX + 1];
+ char tpath[PATH_MAX + 1];
+ FILE *f;
+
+ sendcode = (center_com_sendcode*)data;
+
+ snprintf(pack_path,sizeof(pack_path),"tmp/codepack/%d.tar.bz2",sendcode->subid);
+ snprintf(dir_path,sizeof(dir_path),"tmp/code/%d",sendcode->subid);
+ mkdir(dir_path,0755);
+ server_cleardir(dir_path);
+ pack_unpack(pack_path,dir_path);
+}
+void server_conn::tp_unpackcode_cb(void *data){
+ center_com_sendcode *sendcode;
+ int subid;
+ std::multimap<int,center_com_submit*>::iterator sub_it;
+ center_com_submit *sub;
+
+ sendcode = (center_com_sendcode*)data;
+ subid = sendcode->subid;
+
+ while((sub_it = server_submap.find(subid)) != server_submap.end()){
+ sub = sub_it->second;
+ server_queuejudge(sub,tp_judge_thfn,tp_judge_cbfn);
+ server_submap.erase(sub_it);
+ }
+
+ delete sendcode;
+}
+void server_conn::tp_judge_th(void *data){
+ server_judgeth_info *th_info;
+ center_com_submit *sub;
+ char pro_path[PATH_MAX + 1];
+ char code_path[PATH_MAX + 1];
+
+ th_info = (server_judgeth_info*)data;
+ sub = th_info->sub;
+
+ snprintf(pro_path,sizeof(pro_path),"tmp/pro/%d",sub->proid);
+ snprintf(code_path,sizeof(code_path),"tmp/code/%d",sub->subid);
+ server_judge(sub->subid,pro_path,code_path,th_info->run_path,sub->lang,sub->set_data,th_info->res_data,th_info->res_len);
+}
+void server_conn::tp_judge_cb(void *data){
+ server_judgeth_info *th_info;
+ center_com_submit *sub;
+
+ th_info = (server_judgeth_info*)data;
+ sub = th_info->sub;
+
+ send_result(sub->subid,th_info->res_data,th_info->res_len);
+
+ th_info->use_flag = false;
+ th_info->sub = NULL;
+ delete sub;
+}
+
+
+static int server_queuejudge(center_com_submit *sub,tpool_protofn *th_fn,tpool_protofn *cb_fn){
+ int i;
+
+ printf("get submit %d %d\n",sub->subid,sub->proid);
+ for(i = 0;i < 8;i++){
+ if(server_judgepool[i]->use_flag == false){
+ server_judgepool[i]->use_flag = true;
+ server_judgepool[i]->sub = sub;
+ server_judgetp->add(th_fn,server_judgepool[i],cb_fn,server_judgepool[i]);
+ break;
+ }
+ }
+
+ return 0;
+}
+static int server_judge(int subid,char *pro_path,char *code_path,char *run_path,int lang,char *set_data,char *res_data,size_t &res_len){
+ judgm_line_info *line_info;
+ int pid;
+
+ char tpath[PATH_MAX + 1];
+ FILE *set_file;
+ char cwd_path[PATH_MAX + 1];
+ char jmod_name[NAME_MAX + 1];
+ char line_path[PATH_MAX + 1];
+ char check_name[NAME_MAX + 1];
+ char check_path[PATH_MAX + 1];
+ char lchr;
+ char tchr;
+
+ int judgk_modfd;
+ void *line_dll;
+ void *check_dll;
+ judgm_line_run_fn run_fn;
+
+ snprintf(tpath,sizeof(tpath),"%s/setting",pro_path);
+ set_file = fopen(tpath,"r");
+
+ getcwd(cwd_path,sizeof(cwd_path));
+ fscanf(set_file,"%s",jmod_name);
+ snprintf(line_path,sizeof(line_path),"%s/tmp/jmod/%s/%s_line.so",cwd_path,jmod_name,jmod_name);
+ fscanf(set_file,"%s",check_name);
+ snprintf(check_path,sizeof(check_path),"%s/tmp/jmod/%s/%s.so",cwd_path,jmod_name,check_name);
+
+ lchr = '\n';
+ while((tchr = fgetc(set_file)) != EOF){
+ if(lchr == '\n' && tchr == '='){
+ while(fgetc(set_file) != '\n');
+ break;
+ }
+ lchr = tchr;
+ }
+
+ judgk_modfd = open("/dev/judgk",O_RDWR);
+ line_dll = dlopen(line_path,RTLD_NOW);
+ check_dll = dlopen(check_path,RTLD_NOW);
+
+ line_info = (judgm_line_info*)mmap(NULL,sizeof(struct judgm_line_info),PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS,-1,0);
+
+ line_info->subid = subid;
+
+ line_info->pro_path = pro_path;
+ line_info->code_path = code_path;
+ line_info->run_path = run_path;
+
+ line_info->judgk_modfd = judgk_modfd;
+ line_info->line_dll = line_dll;
+ line_info->check_dll = check_dll;
+
+ line_info->lang = lang;
+ line_info->set_file = set_file;
+ line_info->set_data = set_data;
+
+ server_cleardir(line_info->run_path);
+
+ run_fn = (judgm_line_run_fn)dlsym(line_dll,"run");
+ if((pid = fork()) == 0){
+ run_fn(line_info);
+ exit(0);
+ }
+ waitpid(pid,NULL,0);
+
+ memcpy(res_data,line_info->res_data,line_info->res_len);
+ res_len = line_info->res_len;
+
+ munmap(line_info,sizeof(judgm_line_info));
+ fclose(set_file);
+ close(judgk_modfd);
+ return 0;
+}
+static int server_cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftw_buf){
+ if(ftw_buf->level == 0){
+ return 0;
+ }
+
+ if(S_ISDIR(st->st_mode)){
+ rmdir(path);
+ }else{
+ unlink(path);
+ }
+ return 0;
+}
+static int server_cleardir(char *path){
+ nftw(path,server_cleardir_callback,64,FTW_DEPTH | FTW_PHYS);
+ return 0;
+}
+static int server_addepev(int fd,unsigned int flag,int type,void *data){
+ server_epevdata *epevdata;
+ epoll_event epev;
+
+ epevdata = new server_epevdata(fd,type,data);
+ epev.events = flag;
+ epev.data.ptr = epevdata;
+ epoll_ctl(server_epfd,EPOLL_CTL_ADD,fd,&epev);
+
+ return 0;
+}
+static int server_delepev(server_epevdata *epevdata){
+ epoll_ctl(server_epfd,EPOLL_CTL_DEL,epevdata->fd,NULL);
+ delete epevdata;
+ return 0;
+}
+static server_conn* server_connect(){
+ int cfd;
+ sockaddr_in caddr;
+ epoll_event epev;
+ server_conn *cinfo;
+
+ cfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6);
+ caddr.sin_family = AF_INET;
+ caddr.sin_port = htons(SERVER_JUDGE_PORT);
+ //caddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ caddr.sin_addr.s_addr = inet_addr("10.8.0.2");
+
+ cinfo = new server_conn(cfd);
+ server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_JUDGECLIENT,cinfo);
+ connect(cfd,(sockaddr*)&caddr,sizeof(caddr));
+
+ return cinfo;
+}
+int main(){
+ int i;
+
+ epoll_event epev;
+ epoll_event epevs[SERVER_EPOLL_MAXEVENT];
+ int nevs;
+
+ int ev_flag;
+ server_epevdata *epevdata;
+ server_conn *cinfo;
+ tpool *tpinfo;
+
+ signal(SIGPIPE,SIG_IGN);
+ server_epfd = epoll_create1(0);
+
+ server_id = 0;
+ server_avail = 2;
+ server_mainconn = server_connect();
+ server_fileconn = NULL;
+ server_codeconn = NULL;
+
+ server_packtp = new tpool(4);
+ server_packtp->start();
+ server_addepev(server_packtp->fd,EPOLLIN | EPOLLET,SERVER_EPEV_TPOOL,server_packtp);
+
+ for(i = 0;i < 8;i++){
+ server_judgepool[i] = new server_judgeth_info(i);
+ }
+ server_judgetp = new tpool(8);
+ server_judgetp->start();
+ server_addepev(server_judgetp->fd,EPOLLIN | EPOLLET,SERVER_EPEV_TPOOL,server_judgetp);
+
+ while(true){
+ nevs = epoll_wait(server_epfd,epevs,SERVER_EPOLL_MAXEVENT,-1);
+ for(i = 0;i < nevs;i++){
+ ev_flag = epevs[i].events;
+ epevdata = (server_epevdata*)epevs[i].data.ptr;
+
+ if(epevdata->type == SERVER_EPEV_JUDGECLIENT){
+ cinfo = (server_conn*)epevdata->data;
+ if(ev_flag & EPOLLIN){
+ cinfo->readio();
+ }
+ if(ev_flag & EPOLLOUT){
+ cinfo->writeio();
+ }
+
+ server_packtp->done();
+ }else if(epevdata->type = SERVER_EPEV_TPOOL){
+ tpinfo = (tpool*)epevdata->data;
+ if(ev_flag & EPOLLIN){
+ tpinfo->done();
+ }
+ }
+ }
+ }
+
+ close(server_epfd);
+
+ return 0;
+}
diff --git a/toj/center/src/judge_server.h b/toj/center/src/judge_server.h
new file mode 100644
index 0000000..d904d9d
--- /dev/null
+++ b/toj/center/src/judge_server.h
@@ -0,0 +1,107 @@
+#define SERVER_JUDGE_PORT 2573
+#define SERVER_EPOLL_MAXEVENT 4096
+
+#define SERVER_EPEV_JUDGECLIENT 0
+#define SERVER_EPEV_TPOOL 1
+class server_epevdata{
+public:
+ int fd;
+ int type;
+ void *data;
+
+ server_epevdata(int fd,int type,void *data);
+};
+
+class server_conn : public netio{
+private:
+ netio_iofn<server_conn> *recv_dispatch_fn;
+ netio_iofn<server_conn> *recv_setid_fn;
+ netio_iofn<server_conn> *recv_submit_fn;
+ netio_iofn<server_conn> *recv_setpro_fn;
+ netio_iofn<server_conn> *recv_sendpro_fn;
+ netio_iofn<server_conn> *done_sendpro_fn;
+ netio_iofn<server_conn> *recv_setjmod_fn;
+ netio_iofn<server_conn> *recv_sendjmod_fn;
+ netio_iofn<server_conn> *done_sendjmod_fn;
+ netio_iofn<server_conn> *recv_sendcode_fn;
+ netio_iofn<server_conn> *done_sendcode_fn;
+ tpool_fn<server_conn> *tp_unpackpro_thfn;
+ tpool_fn<server_conn> *tp_unpackpro_cbfn;
+ tpool_fn<server_conn> *tp_unpackjmod_thfn;
+ tpool_fn<server_conn> *tp_unpackjmod_cbfn;
+ tpool_fn<server_conn> *tp_unpackcode_thfn;
+ tpool_fn<server_conn> *tp_unpackcode_cbfn;
+ tpool_fn<server_conn> *tp_judge_thfn;
+ tpool_fn<server_conn> *tp_judge_cbfn;
+
+ char* create_combuf(int code,int size,int &len,void **data);
+ void recv_dispatch(void *buf,size_t len,void *data);
+ void recv_setid(void *buf,size_t len,void *data);
+ void recv_submit(void *buf,size_t len,void *data);
+ void recv_setpro(void *buf,size_t len,void *data);
+ void recv_sendpro(void *buf,size_t len,void *data);
+ void done_sendpro(void *buf,size_t len,void *data);
+ void recv_setjmod(void *buf,size_t len,void *data);
+ void recv_sendjmod(void *buf,size_t len,void *data);
+ void done_sendjmod(void *buf,size_t len,void *data);
+ void recv_sendcode(void *buf,size_t len,void *data);
+ void done_sendcode(void *buf,size_t len,void *data);
+ void tp_unpackpro_th(void *data);
+ void tp_unpackpro_cb(void *data);
+ void tp_unpackjmod_th(void *data);
+ void tp_unpackjmod_cb(void *data);
+ void tp_unpackcode_th(void *data);
+ void tp_unpackcode_cb(void *data);
+ void tp_judge_th(void *data);
+ void tp_judge_cb(void *data);
+
+public:
+ server_conn(int fd);
+ int send_setid();
+ int send_setinfo();
+ int send_result(int subid,char *res_data,size_t res_len);
+ int send_setpro(int *proid,int *cacheid,int type,int count);
+ int send_setjmod(char **jmod_name,int *cacheid,int type,int count);
+ virtual int readidle();
+};
+
+class server_judgeth_info{
+public:
+ bool use_flag;
+ int thid;
+ char run_path[PATH_MAX + 1];
+ center_com_submit *sub;
+ char res_data[JUDGE_RES_DATAMAX];
+ size_t res_len;
+
+ server_judgeth_info(int thid){
+ this->use_flag = false;
+ this->thid = thid;
+ snprintf(this->run_path,sizeof(this->run_path),"tmp/run/%d",thid);
+ mkdir(this->run_path,0775);
+ this->sub = NULL;
+ this->res_len = 0;
+ }
+};
+
+static int server_queuejudge(center_com_submit *sub,tpool_protofn *th_fn,tpool_protofn *cb_fn);
+static int server_judge(int subid,char *pro_path,char *code_path,char *run_path,int lang,char *set_data,char *res_data,size_t &res_len);
+static int server_cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftw_buf);
+static int server_cleardir(char *path);
+static int server_addepev(int fd,unsigned int flag,int type,void *data);
+static int server_delepev(server_epevdata *epevdata);
+static server_conn* server_connect();
+
+static int server_id;
+static int server_avail;
+static std::multimap<int,center_com_submit*> server_submap;
+static int server_epfd;
+static server_conn *server_mainconn;
+static server_conn *server_fileconn;
+static server_conn *server_codeconn;
+static tpool *server_packtp;
+static server_judgeth_info *server_judgepool[8];
+static tpool *server_judgetp;
+
+extern int pack_pack(char *pack_path,char *dir_path);
+extern int pack_unpack(char *pack_path,char *dir_path);
diff --git a/judge/judgm.h b/toj/center/src/judgk.h
index f2c0841..18f9a6c 100644..100755
--- a/judge/judgm.h
+++ b/toj/center/src/judgk.h
@@ -1,16 +1,16 @@
-struct judgm_proc_info{
+struct judgk_proc_info{
struct hlist_node node;
struct list_head list;
struct task_struct *task;
- struct file *pin;
- struct file *pout;
+ struct file *std_in;
+ struct file *std_out;
char run_path[PATH_MAX + 1];
int status;
unsigned long timelimit;
- unsigned long jiffiesstart;
- unsigned long jiffiesend;
+ unsigned long jiff_start;
+ unsigned long jiff_end;
unsigned long memlimit;
unsigned long runtime;
- unsigned long peakmem;
+ unsigned long memory;
};
diff --git a/toj/center/src/judgk_com.h b/toj/center/src/judgk_com.h
new file mode 100644
index 0000000..842c69c
--- /dev/null
+++ b/toj/center/src/judgk_com.h
@@ -0,0 +1,25 @@
+#define IOCTL_PROC_ADD _IOWR('x',0x0,int)
+#define IOCTL_PROC_GET _IOWR('x',0x1,int)
+#define IOCTL_PROC_DEL _IOR('x',0x3,int)
+
+#define IOCTL_HYPERIO_ADD _IOWR('x',0x10,int)
+#define IOCTL_HYPERIO_READ _IOWR('x',0x11,int)
+#define IOCTL_HYPERIO_WRITE _IOWR('x',0x12,int)
+#define IOCTL_HYPERIO_DEL _IOWR('x',0x13,int)
+
+#define JUDGK_COM_HYPERIO_BUFSIZE 4194304
+
+struct judgk_com_proc_add{
+ char run_path[PATH_MAX + 1];
+ pid_t pid;
+ unsigned long kern_task;
+ unsigned long timelimit;
+ unsigned long hardtimelimit;
+ unsigned long memlimit;
+};
+struct judgk_com_proc_get{
+ unsigned long kern_task;
+ int status;
+ unsigned long runtime;
+ unsigned long memory;
+};
diff --git a/toj/center/src/judgk_hyperio.c b/toj/center/src/judgk_hyperio.c
new file mode 100644
index 0000000..67b0ef6
--- /dev/null
+++ b/toj/center/src/judgk_hyperio.c
@@ -0,0 +1,417 @@
+#include<linux/fs.h>
+#include<linux/tty.h>
+#include<linux/slab.h>
+#include<linux/mm.h>
+#include<linux/wait.h>
+#include<linux/sched.h>
+#include<asm/atomic.h>
+#include<asm/mman.h>
+
+#include"judgk.h"
+#include"judgk_com.h"
+#include"judgk_hyperio.h"
+
+int judgk_hyperio_init(){
+ int i;
+ struct hyperio_info *info;
+
+ hyperio_filp_ht = (struct hlist_head*)kmalloc(sizeof(struct hlist_head) * HYPERIO_FILP_HTSIZE,GFP_KERNEL);
+ for(i = 0;i < HYPERIO_FILP_HTSIZE;i++){
+ INIT_HLIST_HEAD(&hyperio_filp_ht[i]);
+ }
+
+ hyperio_table = (struct hyperio_info*)kmalloc(sizeof(struct hyperio_info) * HYPERIO_MAXNUM,GFP_KERNEL);
+ for(i = 0;i < HYPERIO_MAXNUM;i++){
+ info = &hyperio_table[i];
+
+ atomic_set(&info->ref_count,0);
+ info->filp = NULL;
+ info->create_flag = false;
+ info->end_flag = false;
+ info->hook_fops = NULL;
+ info->old_fops = NULL;
+
+ atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->read_off = 0;
+ info->read_buf = NULL;
+ init_completion(&info->read_rwait);
+ init_completion(&info->read_wwait);
+
+ atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->write_off = 0;
+ info->write_buf = NULL;
+ init_completion(&info->write_rwait);
+ init_completion(&info->write_wwait);
+ }
+
+ hyperio_tty_drv = tty_alloc_driver(HYPERIO_MAXNUM,TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
+ hyperio_tty_drv->owner = THIS_MODULE;
+ hyperio_tty_drv->driver_name = "judgk_tty";
+ hyperio_tty_drv->name = "jtty";
+ hyperio_tty_drv->type = TTY_DRIVER_TYPE_SYSTEM;
+ hyperio_tty_drv->subtype = SYSTEM_TYPE_TTY;
+ hyperio_tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+ hyperio_tty_drv->init_termios = tty_std_termios;
+ hyperio_tty_drv->init_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+ hyperio_tty_drv->init_termios.c_oflag &= ~OPOST;
+ hyperio_tty_drv->init_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+ hyperio_tty_drv->init_termios.c_cflag &= ~(CSIZE | PARENB);
+ hyperio_tty_drv->init_termios.c_cflag |= CS8;
+ tty_set_operations(hyperio_tty_drv,&hyperio_tops);
+
+ tty_register_driver(hyperio_tty_drv);
+
+ return 0;
+}
+int judgk_hyperio_exit(){
+ int i;
+
+ for(i = 0;i < HYPERIO_MAXNUM;i++){
+ if(hyperio_table[i].create_flag == true){
+ tty_unregister_device(hyperio_tty_drv,i);
+ hyperio_table[i].create_flag = false;
+ }
+ }
+ tty_unregister_driver(hyperio_tty_drv);
+
+ return 0;
+}
+int judgk_hyperio_add(struct file *filp){
+ int idx;
+ struct hyperio_info *info;
+
+ info = NULL;
+ for(idx = 0;idx < HYPERIO_MAXNUM;idx++){
+ if(atomic_cmpxchg(&hyperio_table[idx].ref_count,0,1) == 0){
+ info = &hyperio_table[idx];
+ break;
+ }
+ }
+ if(info == NULL){
+ return -1;
+ }
+
+ filp->private_data = info;
+
+ info->filp = NULL;
+ if(info->create_flag == false){
+ tty_port_init(&info->port);
+ tty_port_register_device(&info->port,hyperio_tty_drv,idx,NULL);
+ info->create_flag = true;
+ }
+ info->end_flag = false;
+ if(info->hook_fops == NULL){
+ info->hook_fops = (struct file_operations*)kmalloc(sizeof(struct file_operations),GFP_KERNEL);
+ }
+
+ atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->read_off = 0;
+ if(info->read_buf == NULL){
+ info->read_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL);
+ }
+ memset(info->read_buf,0,JUDGK_COM_HYPERIO_BUFSIZE);
+ init_completion(&info->read_rwait);
+ init_completion(&info->read_wwait);
+
+ atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->write_off = 0;
+ if(info->write_buf == NULL){
+ info->write_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL);
+ }
+ memset(info->write_buf,0,JUDGK_COM_HYPERIO_BUFSIZE);
+ init_completion(&info->write_rwait);
+ init_completion(&info->write_wwait);
+
+ return idx;
+}
+int judgk_hyperio_read(struct file *filp,size_t len){
+ struct hyperio_info *info;
+ bool wait_flag;
+ size_t remain;
+
+ if((long)len >= 0){
+ wait_flag = true;
+ }else{
+ wait_flag = false;
+ len = -(long)len;
+ }
+
+ info = (struct hyperio_info*)filp->private_data;
+
+ remain = atomic64_read(&info->write_remain);
+ if(unlikely(len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){
+ return -EINVAL;
+ }
+
+ if(unlikely(len > 0 && (remain = atomic64_add_return(len,&info->write_remain)) == len)){
+ complete(&info->write_wwait);
+ }
+ if(wait_flag == true){
+ while(unlikely(remain == JUDGK_COM_HYPERIO_BUFSIZE)){
+ if(info->end_flag == true){
+ remain = atomic64_read(&info->write_remain);
+ break;
+ }
+ wait_for_completion_interruptible(&info->write_rwait);
+ remain = atomic64_read(&info->write_remain);
+ }
+ }
+
+ return JUDGK_COM_HYPERIO_BUFSIZE - remain;
+}
+int judgk_hyperio_write(struct file *filp,size_t len){
+ struct hyperio_info *info;
+ bool wait_flag;
+ size_t remain;
+
+ if((long)len >= 0){
+ wait_flag = true;
+ }else{
+ wait_flag = false;
+ len = -(long)len;
+ }
+
+ info = (struct hyperio_info*)filp->private_data;
+
+ remain = atomic64_read(&info->read_remain);
+ if(unlikely(len > remain)){
+ return -EINVAL;
+ }
+
+ if(unlikely(len > 0 && (remain = atomic64_sub_return(len,&info->read_remain)) == (JUDGK_COM_HYPERIO_BUFSIZE - len))){
+ complete(&info->read_rwait);
+ }
+ if(wait_flag == true){
+ while(unlikely(remain == 0)){
+ if(info->end_flag == true){
+ remain = atomic64_read(&info->read_remain);
+ break;
+ }
+ wait_for_completion_interruptible(&info->read_wwait);
+ remain = atomic64_read(&info->read_remain);
+ }
+ }
+
+ return remain;
+}
+int judgk_hyperio_del(struct file *filp){
+ struct hyperio_info *info;
+
+ info = (struct hyperio_info*)filp->private_data;
+ info->end_flag = true;
+ complete(&info->read_rwait);
+ complete(&info->read_wwait);
+ complete(&info->write_rwait);
+ complete(&info->write_wwait);
+
+ atomic_dec(&info->ref_count);
+ return 0;
+}
+int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma){
+ unsigned long size;
+ unsigned long off;
+ void *buf;
+
+ size = vma->vm_end - vma->vm_start;
+ off = vma->vm_pgoff << PAGE_SHIFT;
+ if((size + off) > JUDGK_COM_HYPERIO_BUFSIZE){
+ return -EINVAL;
+ }
+ if((vma->vm_flags & VM_READ) != 0 && (vma->vm_flags & VM_WRITE) != 0){
+ return -EINVAL;
+ }
+ if((vma->vm_flags & VM_READ) == 0 && (vma->vm_flags & VM_WRITE) == 0){
+ return -EINVAL;
+ }
+
+ if((vma->vm_flags & VM_READ) != 0){
+ buf = ((struct hyperio_info*)filp->private_data)->write_buf;
+ }else{
+ buf = ((struct hyperio_info*)filp->private_data)->read_buf;
+ }
+ remap_pfn_range(vma,
+ vma->vm_start,
+ virt_to_phys(buf + off) >> PAGE_SHIFT,
+ size,
+ vma->vm_page_prot);
+
+ return 0;
+}
+
+static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp){
+ struct hlist_node *node;
+ struct hyperio_info *info;
+
+ rcu_read_lock();
+
+ info = NULL;
+ hlist_for_each_entry_rcu(info,node,&hyperio_filp_ht[(unsigned long)filp % HYPERIO_FILP_HTSIZE],node){
+ if((unsigned long)info->filp == (unsigned long)filp){
+ break;
+ }
+ info = NULL;
+ }
+
+ rcu_read_unlock();
+
+ return info;
+}
+static int hyperio_tty_open(struct tty_struct *tty, struct file *filp){
+ struct hyperio_info *info;
+ struct file_operations *hook_fops;
+
+ tty->low_latency = 1;
+
+ info = &hyperio_table[tty->index];
+ atomic_inc(&info->ref_count);
+ info->filp = filp;
+
+ hook_fops = info->hook_fops;
+ info->old_fops = filp->f_op;
+ memcpy(hook_fops,filp->f_op,sizeof(struct file_operations));
+
+ hook_fops->read = hyperio_tty_filpread;
+ hook_fops->write = hyperio_tty_filpwrite;
+
+ filp->f_op = hook_fops;
+
+ spin_lock(&hyperio_filp_htlock);
+
+ hlist_add_head_rcu(&info->node,&hyperio_filp_ht[(unsigned long)info->filp % HYPERIO_FILP_HTSIZE]);
+
+ spin_unlock(&hyperio_filp_htlock);
+
+ return 0;
+}
+static void hyperio_tty_close(struct tty_struct *tty, struct file *filp){
+ struct hyperio_info *info;
+
+ info = &hyperio_table[tty->index];
+
+ spin_lock(&hyperio_filp_htlock);
+
+ hlist_del_rcu(&info->node);
+
+ spin_unlock(&hyperio_filp_htlock);
+
+ filp->f_op = info->old_fops;
+
+ info->end_flag = true;
+ complete(&info->read_rwait);
+ complete(&info->read_wwait);
+ complete(&info->write_rwait);
+ complete(&info->write_wwait);
+
+ atomic_dec(&info->ref_count);
+}
+static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count){
+ return count;
+}
+static int hyperio_tty_write_room(struct tty_struct *tty){
+ return JUDGK_COM_HYPERIO_BUFSIZE;
+}
+static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off){
+ struct hyperio_info *info;
+ size_t buf_len;
+ off_t buf_off;
+ size_t remain;
+ size_t read_len;
+ off_t read_off;
+
+ if(unlikely(count < 0)){
+ return -EINVAL;
+ }
+
+ info = hyperio_filp_lookup(filp);
+ if(unlikely(info == NULL)){
+ return -EIO;
+ }
+
+ buf_len = count;
+ buf_off = 0;
+ while(likely(buf_len > 0)){
+ while(unlikely((remain = atomic64_read(&info->read_remain)) == JUDGK_COM_HYPERIO_BUFSIZE)){
+ if(unlikely(info->end_flag == true)){
+ return -EIO;
+ }
+ if(likely(buf_off > 0)){
+ return buf_off;
+ }
+ wait_for_completion_interruptible(&info->read_rwait);
+ }
+ if(unlikely(buf_len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){
+ read_len = JUDGK_COM_HYPERIO_BUFSIZE - remain;
+ }else{
+ read_len = buf_len;
+ }
+
+ read_off = info->read_off;
+ if(likely((read_len + read_off) < JUDGK_COM_HYPERIO_BUFSIZE)){
+ copy_to_user(buf + buf_off,info->read_buf + read_off,read_len);
+ info->read_off = read_len + read_off;
+ }else{
+ copy_to_user(buf + buf_off,info->read_buf + read_off,JUDGK_COM_HYPERIO_BUFSIZE - read_off);
+ copy_to_user(buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - read_off),info->read_buf,(read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE);
+ info->read_off = (read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE;
+ }
+
+ if(unlikely(atomic64_add_return(read_len,&info->read_remain) == read_len)){
+ complete(&info->read_wwait);
+ }
+ buf_len -= read_len;
+ buf_off += read_len;
+ }
+
+ return count;
+}
+static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off){
+ struct hyperio_info *info;
+ size_t buf_len;
+ off_t buf_off;
+ size_t remain;
+ size_t write_len;
+ off_t write_off;
+
+ if(unlikely(count < 0)){
+ return -EINVAL;
+ }
+
+ info = hyperio_filp_lookup(filp);
+ if(unlikely(info == NULL)){
+ return -EIO;
+ }
+
+ buf_len = count;
+ buf_off = 0;
+ while(likely(buf_len > 0)){
+ while(unlikely((remain = atomic64_read(&info->write_remain)) == 0)){
+ if(unlikely(info->end_flag == true)){
+ return -EIO;
+ }
+ wait_for_completion_interruptible(&info->write_wwait);
+ }
+ if(unlikely(buf_len > remain)){
+ write_len = remain;
+ }else{
+ write_len = buf_len;
+ }
+
+ write_off = info->write_off;
+ if(unlikely((write_len + write_off) >= JUDGK_COM_HYPERIO_BUFSIZE)){
+ copy_from_user(info->write_buf + write_off,buf + buf_off,JUDGK_COM_HYPERIO_BUFSIZE - write_off);
+ copy_from_user(info->write_buf,buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - write_off),(write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE);
+ info->write_off = (write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE;
+ }else{
+ copy_from_user(info->write_buf + write_off,buf + buf_off,write_len);
+ info->write_off = write_len + write_off;
+ }
+
+ if(unlikely(atomic64_sub_return(write_len,&info->write_remain) == (JUDGK_COM_HYPERIO_BUFSIZE - write_len))){
+ complete(&info->write_rwait);
+ }
+ buf_len -= write_len;
+ buf_off += write_len;
+ }
+
+ return count;
+}
diff --git a/toj/center/src/judgk_hyperio.h b/toj/center/src/judgk_hyperio.h
new file mode 100644
index 0000000..ccc1449
--- /dev/null
+++ b/toj/center/src/judgk_hyperio.h
@@ -0,0 +1,53 @@
+#define HYPERIO_MAXNUM 256
+#define HYPERIO_FILP_HTSIZE 1009
+
+struct hyperio_info{
+ atomic_t ref_count;
+ struct hlist_node node;
+ struct file *filp;
+ struct tty_port port;
+
+ bool create_flag;
+ bool end_flag;
+ struct file_operations *hook_fops;
+ const struct file_operations *old_fops;
+
+ atomic64_t read_remain;
+ off_t read_off;
+ char *read_buf;
+ struct completion read_rwait;
+ struct completion read_wwait;
+
+ atomic64_t write_remain;
+ off_t write_off;
+ char *write_buf;
+ struct completion write_rwait;
+ struct completion write_wwait;
+};
+
+static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp);
+static int hyperio_tty_open(struct tty_struct * tty, struct file * filp);
+static void hyperio_tty_close(struct tty_struct * tty, struct file * filp);
+static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count);
+static int hyperio_tty_write_room(struct tty_struct *tty);
+static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off);
+static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off);
+
+static struct tty_driver *hyperio_tty_drv;
+static struct tty_operations hyperio_tops = {
+ .open = hyperio_tty_open,
+ .close = hyperio_tty_close,
+ .write = hyperio_tty_write,
+ .write_room = hyperio_tty_write_room
+};
+static struct hyperio_info *hyperio_table;
+static struct hlist_head *hyperio_filp_ht;
+static DEFINE_SPINLOCK(hyperio_filp_htlock);
+
+int judgk_hyperio_init(void);
+int judgk_hyperio_exit(void);
+int judgk_hyperio_add(struct file *filp);
+int judgk_hyperio_read(struct file *filp,size_t len);
+int judgk_hyperio_write(struct file *filp,size_t len);
+int judgk_hyperio_del(struct file *filp);
+int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma);
diff --git a/toj/center/src/judgk_mod.c b/toj/center/src/judgk_mod.c
new file mode 100755
index 0000000..3f56d90
--- /dev/null
+++ b/toj/center/src/judgk_mod.c
@@ -0,0 +1,75 @@
+#include<linux/module.h>
+#include<linux/kernel.h>
+#include<linux/kdev_t.h>
+#include<linux/device.h>
+#include<linux/cdev.h>
+#include<linux/fs.h>
+#include<linux/sched.h>
+
+#include"judgk.h"
+#include"judgk_com.h"
+#include"judgk_mod.h"
+
+static int __init mod_init(){
+ alloc_chrdev_region(&mod_dev,0,1,"judgk");
+ mod_class = class_create(THIS_MODULE,"chardev");
+ device_create(mod_class,NULL,mod_dev,NULL,"judgk");
+ cdev_init(&mod_cdev,&mod_fops);
+ cdev_add(&mod_cdev,mod_dev,1);
+
+ judgk_proc_init();
+ judgk_security_hook();
+ judgk_syscall_hook();
+ judgk_hyperio_init();
+
+ pr_alert("judgk:Init\n");
+ return 0;
+}
+static void __exit mod_exit(){
+ cdev_del(&mod_cdev);
+ device_destroy(mod_class,mod_dev);
+ class_destroy(mod_class);
+ unregister_chrdev_region(mod_dev,1);
+
+ judgk_proc_exit();
+ judgk_syscall_unhook();
+ judgk_security_unhook();
+ judgk_hyperio_exit();
+
+ schedule_timeout_interruptible(3 * HZ);
+ pr_alert("judgk:Exit\n");
+}
+module_init(mod_init);
+module_exit(mod_exit);
+MODULE_LICENSE("GPL");
+
+static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg){
+ int ret;
+
+ ret = -1;
+ switch(cmd){
+ case IOCTL_PROC_ADD:
+ ret = judgk_proc_add(arg);
+ break;
+ case IOCTL_PROC_GET:
+ ret = judgk_proc_get(arg);
+ break;
+ case IOCTL_PROC_DEL:
+ ret = judgk_proc_del(arg);
+ break;
+ case IOCTL_HYPERIO_ADD:
+ ret = judgk_hyperio_add(filp);
+ break;
+ case IOCTL_HYPERIO_READ:
+ ret = judgk_hyperio_read(filp,arg);
+ break;
+ case IOCTL_HYPERIO_WRITE:
+ ret = judgk_hyperio_write(filp,arg);
+ break;
+ case IOCTL_HYPERIO_DEL:
+ ret = judgk_hyperio_del(filp);
+ break;
+ }
+
+ return ret;
+}
diff --git a/toj/center/src/judgk_mod.h b/toj/center/src/judgk_mod.h
new file mode 100755
index 0000000..58bc76b
--- /dev/null
+++ b/toj/center/src/judgk_mod.h
@@ -0,0 +1,31 @@
+static int __init mod_init(void);
+static void __exit mod_exit(void);
+static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg);
+
+static dev_t mod_dev;
+static struct cdev mod_cdev;
+static struct class *mod_class;
+
+extern int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma);
+static struct file_operations mod_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = mod_ioctl,
+ .mmap = judgk_hyperio_mmap
+};
+
+extern int judgk_proc_init(void);
+extern int judgk_proc_exit(void);
+extern int judgk_proc_add(unsigned long arg);
+extern int judgk_proc_get(unsigned long arg);
+extern int judgk_proc_del(unsigned long arg);
+extern int judgk_syscall_hook(void);
+extern int judgk_syscall_unhook(void);
+extern int judgk_security_hook(void);
+extern int judgk_security_unhook(void);
+
+extern int judgk_hyperio_init(void);
+extern int judgk_hyperio_exit(void);
+extern int judgk_hyperio_add(struct file *filp);
+extern int judgk_hyperio_read(struct file *filp,size_t len);
+extern int judgk_hyperio_write(struct file *filp,size_t len);
+extern int judgk_hyperio_del(struct file *filp);
diff --git a/judge/judgm_proc.c b/toj/center/src/judgk_proc.c
index 2933512..17a0375 100644..100755
--- a/judge/judgm_proc.c
+++ b/toj/center/src/judgk_proc.c
@@ -5,42 +5,45 @@
#include<linux/kthread.h>
#include<asm/uaccess.h>
-#include"judgm.h"
#include"judge_def.h"
-#include"judgx_com.h"
-#include"judgm_proc.h"
+#include"judgk.h"
+#include"judgk_com.h"
+#include"judgk_proc.h"
-int judgm_proc_init(){
+int judgk_proc_init(){
int i;
proc_task_ht = kmalloc(sizeof(struct hlist_head) * PROC_TASK_HTSIZE,GFP_KERNEL);
for(i = 0;i < PROC_TASK_HTSIZE;i++){
INIT_HLIST_HEAD(&proc_task_ht[i]);
}
- proc_info_cachep = kmem_cache_create("proc_info_cachep",sizeof(struct judgm_proc_info),0,0,NULL);
+ proc_info_cachep = kmem_cache_create("proc_info_cachep",sizeof(struct judgk_proc_info),0,0,NULL);
- proc_watcher_task = kthread_run(proc_watcher,NULL,"judgm_proc");
+ proc_watcher_task = kthread_run(proc_watcher,NULL,"judgk_proc");
return 0;
}
+int judgk_proc_exit(){
+ kthread_stop(proc_watcher_task);
+ return 0;
+}
-int judgm_proc_add(unsigned long arg){
+int judgk_proc_add(unsigned long arg){
int ret;
struct task_struct *task;
- struct judgm_proc_info *info;
- struct judgx_com_proc_add *com_proc_add;
+ struct judgk_proc_info *info;
+ struct judgk_com_proc_add *com_proc_add;
ret = 0;
-
- com_proc_add = kmalloc(sizeof(struct judgx_com_proc_add),GFP_KERNEL);
- copy_from_user(com_proc_add,(void* __user)arg,sizeof(struct judgx_com_proc_add));
+ com_proc_add = kmalloc(sizeof(struct judgk_com_proc_add),GFP_KERNEL);
+ copy_from_user(com_proc_add,(void* __user)arg,sizeof(struct judgk_com_proc_add));
if((task = get_pid_task(find_vpid(com_proc_add->pid),PIDTYPE_PID)) == NULL){
ret = -1;
goto end;
}
- if(judgm_proc_task_lookup(task) != NULL){
+ if(judgk_proc_task_lookup(task) != NULL){
put_task_struct(task);
ret = -1;
goto end;
@@ -48,15 +51,15 @@ int judgm_proc_add(unsigned long arg){
info = kmem_cache_alloc(proc_info_cachep,GFP_KERNEL);
info->task = task;
- info->pin = fcheck_files(task->files,0);
- info->pout = fcheck_files(task->files,1);
+ info->std_in = fcheck_files(task->files,0);
+ info->std_out = fcheck_files(task->files,1);
info->status = JUDGE_AC;
info->timelimit = com_proc_add->timelimit;
- info->jiffiesstart = jiffies;
- info->jiffiesend = info->jiffiesstart + usecs_to_jiffies(com_proc_add->hardtimelimit);
+ info->jiff_start = jiffies;
+ info->jiff_end = info->jiff_start + usecs_to_jiffies(com_proc_add->hardtimelimit);
info->memlimit = com_proc_add->memlimit;
info->runtime = 0L;
- info->peakmem = 0L;
+ info->memory = 0L;
if(proc_get_path(com_proc_add->run_path,info->run_path)){
put_task_struct(task);
@@ -74,8 +77,8 @@ int judgm_proc_add(unsigned long arg){
spin_unlock(&proc_task_htlock);
- com_proc_add->task = (unsigned long)task;
- copy_to_user((void* __user)arg,com_proc_add,sizeof(struct judgx_com_proc_add));
+ com_proc_add->kern_task = (unsigned long)task;
+ copy_to_user((void* __user)arg,com_proc_add,sizeof(struct judgk_com_proc_add));
end:
@@ -83,15 +86,15 @@ end:
return ret;
}
-int judgm_proc_get(unsigned long arg){
+int judgk_proc_get(unsigned long arg){
struct task_struct *task;
- struct judgm_proc_info *info;
- struct judgx_com_proc_get *com_proc_get;
+ struct judgk_proc_info *info;
+ struct judgk_com_proc_get *com_proc_get;
- com_proc_get = kmalloc(sizeof(struct judgx_com_proc_get),GFP_KERNEL);
- copy_from_user(com_proc_get,(void* __user)arg,sizeof(struct judgx_com_proc_get));
- task = (struct task_struct*)com_proc_get->task;
- if((info = judgm_proc_task_lookup(task)) == NULL){
+ com_proc_get = kmalloc(sizeof(struct judgk_com_proc_get),GFP_KERNEL);
+ copy_from_user(com_proc_get,(void* __user)arg,sizeof(struct judgk_com_proc_get));
+ task = (struct task_struct*)com_proc_get->kern_task;
+ if((info = judgk_proc_task_lookup(task)) == NULL){
kfree(com_proc_get);
return -1;
}
@@ -103,33 +106,31 @@ int judgm_proc_get(unsigned long arg){
com_proc_get->runtime = cputime_to_usecs(task->utime);
info->runtime = com_proc_get->runtime;
}
- com_proc_get->peakmem = info->peakmem;
+ com_proc_get->memory = info->memory;
- copy_to_user((void* __user)arg,com_proc_get,sizeof(struct judgx_com_proc_get));
+ copy_to_user((void* __user)arg,com_proc_get,sizeof(struct judgk_com_proc_get));
kfree(com_proc_get);
- return 0;
-}
-int judgm_proc_kill(unsigned long arg){
- struct task_struct *task;
- struct judgm_proc_info *info;
+ spin_lock(&proc_task_htlock);
- task = (struct task_struct*)arg;
- if((info = judgm_proc_task_lookup(task)) == NULL){
- return -1;
- }
+ list_del_rcu(&info->list);
+ hlist_del_rcu(&info->node);
+
+ spin_unlock(&proc_task_htlock);
+
+ synchronize_rcu();
+
+ put_task_struct(info->task);
+ kmem_cache_free(proc_info_cachep,info);
- if(send_sig(SIGKILL,task,0)){
- return -1;
- }
return 0;
}
-int judgm_proc_del(unsigned long arg){
+int judgk_proc_del(unsigned long arg){
struct task_struct *task;
- struct judgm_proc_info *info;
+ struct judgk_proc_info *info;
task = (struct task_struct*)arg;
- if((info = judgm_proc_task_lookup(task)) == NULL){
+ if((info = judgk_proc_task_lookup(task)) == NULL){
return -1;
}
@@ -147,8 +148,8 @@ int judgm_proc_del(unsigned long arg){
return 0;
}
-struct judgm_proc_info* judgm_proc_task_lookup(struct task_struct *task){
- struct judgm_proc_info *info;
+struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task){
+ struct judgk_proc_info *info;
struct hlist_node *node;
rcu_read_lock();
@@ -165,12 +166,9 @@ struct judgm_proc_info* judgm_proc_task_lookup(struct task_struct *task){
return info;
}
-int judgm_proc_exit(){
- kthread_stop(proc_watcher_task);
- return 0;
-}
+
static int proc_watcher(void *data){
- struct judgm_proc_info *info;
+ struct judgk_proc_info *info;
while(!kthread_should_stop()){
@@ -178,10 +176,11 @@ static int proc_watcher(void *data){
list_for_each_entry_rcu(info,&proc_task_list,list){
if(cputime_to_usecs(info->task->utime) > info->timelimit){
+ pr_alert("judgk:TLE");
info->status = JUDGE_TLE;
send_sig(SIGKILL,info->task,0);
- }else if(time_after(jiffies,info->jiffiesend)){
- info->runtime = jiffies_to_usecs((unsigned long)(-((long)info->jiffiesstart - (long)jiffies)));
+ }else if(time_after(jiffies,info->jiff_end)){
+ info->runtime = jiffies_to_usecs((unsigned long)(-((long)info->jiff_start - (long)jiffies)));
info->status = JUDGE_TLE;
send_sig(SIGKILL,info->task,0);
}
@@ -210,6 +209,7 @@ static int proc_get_path(char *in_path,char *real_path){
return 0;
}
+//Watch out kernel update
static int proc_close_fd(struct task_struct *task){
struct file *f;
struct files_struct *files;
@@ -221,7 +221,6 @@ static int proc_close_fd(struct task_struct *task){
spin_lock(&files->file_lock);
fdt = files_fdtable(files);
- fd = 3;
for(fd = 3;fd < fdt->max_fds;fd++){
if((fd = find_next_bit(fdt->open_fds,fdt->max_fds,fd)) >= fdt->max_fds){
break;
@@ -232,8 +231,8 @@ static int proc_close_fd(struct task_struct *task){
}
rcu_assign_pointer(fdt->fd[fd],NULL);
- __clear_close_on_exec(fd,fdt);
- __clear_open_fd(fd,fdt);
+ __clear_bit(fd,fdt->close_on_exec);
+ __clear_bit(fd,fdt->open_fds);
if(fd < files->next_fd){
files->next_fd = fd;
}
diff --git a/judge/judgm_proc.h b/toj/center/src/judgk_proc.h
index 9ccc032..fd60d30 100644..100755
--- a/judge/judgm_proc.h
+++ b/toj/center/src/judgk_proc.h
@@ -10,10 +10,9 @@ static struct hlist_head *proc_task_ht;
static DEFINE_SPINLOCK(proc_task_htlock);
static struct kmem_cache *proc_info_cachep;
-int judgm_proc_init(void);
-int judgm_proc_exit(void);
-int judgm_proc_add(unsigned long arg);
-int judgm_proc_get(unsigned long arg);
-int judgm_proc_kill(unsigned long arg);
-int judgm_proc_del(unsigned long arg);
-struct judgm_proc_info* judgm_proc_task_lookup(struct task_struct *task);
+int judgk_proc_init(void);
+int judgk_proc_exit(void);
+int judgk_proc_add(unsigned long arg);
+int judgk_proc_get(unsigned long arg);
+int judgk_proc_del(unsigned long arg);
+struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task);
diff --git a/toj/center/src/judgk_security.c b/toj/center/src/judgk_security.c
new file mode 100755
index 0000000..876bb1b
--- /dev/null
+++ b/toj/center/src/judgk_security.c
@@ -0,0 +1,2698 @@
+#include<linux/fs.h>
+#include<linux/security.h>
+#include<linux/sched.h>
+#include<linux/hardirq.h>
+#include<asm/uaccess.h>
+
+#include"judge_def.h"
+#include"judgk.h"
+#include"judgk_security.h"
+
+int judgk_security_hook(){
+
+ security_hook_addr = security_get_addr();
+
+ ori_sops = (struct security_operations*)*security_hook_addr;
+ memcpy(&hook_sops,ori_sops,sizeof(struct security_operations));
+
+ hook_sops.ptrace_access_check = hook_ptrace_access_check;
+ hook_sops.ptrace_traceme = hook_ptrace_traceme;
+ hook_sops.capget = hook_capget;
+ hook_sops.capset = hook_capset;
+ //hook_sops.capable = hook_capable;
+ hook_sops.quotactl = hook_quotactl;
+ hook_sops.quota_on = hook_quota_on;
+ hook_sops.syslog = hook_syslog;
+ hook_sops.settime = hook_settime;
+ hook_sops.vm_enough_memory = hook_vm_enough_memory;
+ //hook_sops.bprm_set_creds = hook_bprm_set_creds;
+ //hook_sops.bprm_check_security = hook_bprm_check_security;
+ //hook_sops.bprm_secureexec = hook_bprm_secureexec;
+ //hook_sops.bprm_committing_creds = hook_bprm_committing_creds;
+ //hook_sops.bprm_committed_creds = hook_bprm_committed_creds;
+ hook_sops.sb_alloc_security = hook_sb_alloc_security;
+ hook_sops.sb_free_security = hook_sb_free_security;
+ hook_sops.sb_copy_data = hook_sb_copy_data;
+ hook_sops.sb_remount = hook_sb_remount;
+ hook_sops.sb_kern_mount = hook_sb_kern_mount;
+ hook_sops.sb_show_options = hook_sb_show_options;
+ hook_sops.sb_statfs = hook_sb_statfs;
+ hook_sops.sb_mount = hook_sb_mount;
+ hook_sops.sb_umount = hook_sb_umount;
+ hook_sops.sb_pivotroot = hook_sb_pivotroot;
+ hook_sops.sb_set_mnt_opts = hook_sb_set_mnt_opts;
+ hook_sops.sb_clone_mnt_opts = hook_sb_clone_mnt_opts;
+ hook_sops.sb_parse_opts_str = hook_sb_parse_opts_str;
+ hook_sops.path_unlink = hook_path_unlink;
+ hook_sops.path_mkdir = hook_path_mkdir;
+ hook_sops.path_rmdir = hook_path_rmdir;
+ hook_sops.path_mknod = hook_path_mknod;
+ hook_sops.path_truncate = hook_path_truncate;
+ hook_sops.path_symlink = hook_path_symlink;
+ hook_sops.path_link = hook_path_link;
+ hook_sops.path_rename = hook_path_rename;
+ hook_sops.path_chmod = hook_path_chmod;
+ hook_sops.path_chown = hook_path_chown;
+ hook_sops.path_chroot = hook_path_chroot;
+ //hook_sops.inode_alloc_security = hook_inode_alloc_security;
+ //hook_sops.inode_free_security = hook_inode_free_security;
+ hook_sops.inode_init_security = hook_inode_init_security;
+ hook_sops.inode_create = hook_inode_create;
+ hook_sops.inode_link = hook_inode_link;
+ hook_sops.inode_unlink = hook_inode_unlink;
+ hook_sops.inode_symlink = hook_inode_symlink;
+ hook_sops.inode_mkdir = hook_inode_mkdir;
+ hook_sops.inode_rmdir = hook_inode_rmdir;
+ hook_sops.inode_mknod = hook_inode_mknod;
+ hook_sops.inode_rename = hook_inode_rename;
+ hook_sops.inode_readlink = hook_inode_readlink;
+ //hook_sops.inode_follow_link = hook_inode_follow_link;
+ hook_sops.inode_permission = hook_inode_permission;
+ hook_sops.inode_setattr = hook_inode_setattr;
+ //hook_sops.inode_getattr = hook_inode_getattr;
+ hook_sops.inode_setxattr = hook_inode_setxattr;
+ hook_sops.inode_post_setxattr = hook_inode_post_setxattr;
+ hook_sops.inode_getxattr = hook_inode_getxattr;
+ hook_sops.inode_listxattr = hook_inode_listxattr;
+ hook_sops.inode_removexattr = hook_inode_removexattr;
+ hook_sops.inode_need_killpriv = hook_inode_need_killpriv;
+ hook_sops.inode_killpriv = hook_inode_killpriv;
+ hook_sops.inode_getsecurity = hook_inode_getsecurity;
+ hook_sops.inode_setsecurity = hook_inode_setsecurity;
+ hook_sops.inode_listsecurity = hook_inode_listsecurity;
+ hook_sops.inode_getsecid = hook_inode_getsecid;
+ hook_sops.file_permission = hook_file_permission;
+ //hook_sops.file_alloc_security = hook_file_alloc_security;
+ //hook_sops.file_free_security = hook_file_free_security;
+ hook_sops.file_ioctl = hook_file_ioctl;
+ //hook_sops.mmap_addr = hook_mmap_addr;
+ //hook_sops.mmap_file = hook_mmap_file;
+ //hook_sops.file_mprotect = hook_file_mprotect;
+ hook_sops.file_lock = hook_file_lock;
+ hook_sops.file_fcntl = hook_file_fcntl;
+ hook_sops.file_set_fowner = hook_file_set_fowner;
+ hook_sops.file_send_sigiotask = hook_file_send_sigiotask;
+ hook_sops.file_receive = hook_file_receive;
+ hook_sops.file_open = hook_file_open;
+ hook_sops.task_create = hook_task_create;
+ //hook_sops.task_free = hook_task_free;
+ hook_sops.cred_alloc_blank = hook_cred_alloc_blank;
+ //hook_sops.cred_free = hook_cred_free;
+ //hook_sops.cred_prepare = hook_cred_prepare;
+ hook_sops.cred_transfer = hook_cred_transfer;
+ hook_sops.kernel_act_as = hook_kernel_act_as;
+ hook_sops.kernel_create_files_as = hook_kernel_create_files_as;
+ hook_sops.kernel_module_request = hook_kernel_module_request;
+ hook_sops.task_fix_setuid = hook_task_fix_setuid;
+ hook_sops.task_setpgid = hook_task_setpgid;
+ hook_sops.task_getpgid = hook_task_getpgid;
+ hook_sops.task_getsid = hook_task_getsid;
+ hook_sops.task_getsecid = hook_task_getsecid;
+ hook_sops.task_setnice = hook_task_setnice;
+ hook_sops.task_setioprio = hook_task_setioprio;
+ hook_sops.task_getioprio = hook_task_getioprio;
+ hook_sops.task_setrlimit = hook_task_setrlimit;
+ hook_sops.task_setscheduler = hook_task_setscheduler;
+ hook_sops.task_getscheduler = hook_task_getscheduler;
+ hook_sops.task_movememory = hook_task_movememory;
+ hook_sops.task_kill = hook_task_kill;
+ hook_sops.task_wait = hook_task_wait;
+ hook_sops.task_prctl = hook_task_prctl;
+ hook_sops.task_to_inode = hook_task_to_inode;
+ hook_sops.ipc_permission = hook_ipc_permission;
+ hook_sops.ipc_getsecid = hook_ipc_getsecid;
+ hook_sops.msg_msg_alloc_security = hook_msg_msg_alloc_security;
+ hook_sops.msg_msg_free_security = hook_msg_msg_free_security;
+ hook_sops.msg_queue_alloc_security = hook_msg_queue_alloc_security;
+ hook_sops.msg_queue_free_security = hook_msg_queue_free_security;
+ hook_sops.msg_queue_associate = hook_msg_queue_associate;
+ hook_sops.msg_queue_msgctl = hook_msg_queue_msgctl;
+ hook_sops.msg_queue_msgsnd = hook_msg_queue_msgsnd;
+ hook_sops.msg_queue_msgrcv = hook_msg_queue_msgrcv;
+ hook_sops.shm_alloc_security = hook_shm_alloc_security;
+ hook_sops.shm_free_security = hook_shm_free_security;
+ hook_sops.shm_associate = hook_shm_associate;
+ hook_sops.shm_shmctl = hook_shm_shmctl;
+ hook_sops.shm_shmat = hook_shm_shmat;
+ hook_sops.sem_alloc_security = hook_sem_alloc_security;
+ hook_sops.sem_free_security = hook_sem_free_security;
+ hook_sops.sem_associate = hook_sem_associate;
+ hook_sops.sem_semctl = hook_sem_semctl;
+ hook_sops.sem_semop = hook_sem_semop;
+ hook_sops.netlink_send = hook_netlink_send;
+ hook_sops.d_instantiate = hook_d_instantiate;
+ hook_sops.getprocattr = hook_getprocattr;
+ hook_sops.setprocattr = hook_setprocattr;
+ hook_sops.secid_to_secctx = hook_secid_to_secctx;
+ hook_sops.secctx_to_secid = hook_secctx_to_secid;
+ hook_sops.release_secctx = hook_release_secctx;
+ hook_sops.inode_notifysecctx = hook_inode_notifysecctx;
+ hook_sops.inode_setsecctx = hook_inode_setsecctx;
+ hook_sops.inode_getsecctx = hook_inode_getsecctx;
+ hook_sops.unix_stream_connect = hook_unix_stream_connect;
+ hook_sops.unix_may_send = hook_unix_may_send;
+ hook_sops.socket_create = hook_socket_create;
+ hook_sops.socket_post_create = hook_socket_post_create;
+ hook_sops.socket_bind = hook_socket_bind;
+ hook_sops.socket_connect = hook_socket_connect;
+ hook_sops.socket_listen = hook_socket_listen;
+ hook_sops.socket_accept = hook_socket_accept;
+ hook_sops.socket_sendmsg = hook_socket_sendmsg;
+ hook_sops.socket_recvmsg = hook_socket_recvmsg;
+ hook_sops.socket_getsockname = hook_socket_getsockname;
+ hook_sops.socket_getpeername = hook_socket_getpeername;
+ hook_sops.socket_getsockopt = hook_socket_getsockopt;
+ hook_sops.socket_setsockopt = hook_socket_setsockopt;
+ hook_sops.socket_shutdown = hook_socket_shutdown;
+ hook_sops.socket_sock_rcv_skb = hook_socket_sock_rcv_skb;
+ hook_sops.socket_getpeersec_stream = hook_socket_getpeersec_stream;
+ hook_sops.socket_getpeersec_dgram = hook_socket_getpeersec_dgram;
+ hook_sops.sk_alloc_security = hook_sk_alloc_security;
+ hook_sops.sk_free_security = hook_sk_free_security;
+ hook_sops.sk_clone_security = hook_sk_clone_security;
+ hook_sops.sk_getsecid = hook_sk_getsecid;
+ hook_sops.sock_graft = hook_sock_graft;
+ hook_sops.inet_conn_request = hook_inet_conn_request;
+ hook_sops.inet_csk_clone = hook_inet_csk_clone;
+ hook_sops.inet_conn_established = hook_inet_conn_established;
+ hook_sops.secmark_relabel_packet = hook_secmark_relabel_packet;
+ hook_sops.secmark_refcount_inc = hook_secmark_refcount_inc;
+ hook_sops.secmark_refcount_dec = hook_secmark_refcount_dec;
+ hook_sops.req_classify_flow = hook_req_classify_flow;
+ hook_sops.tun_dev_create = hook_tun_dev_create;
+ hook_sops.tun_dev_post_create = hook_tun_dev_post_create;
+ hook_sops.tun_dev_attach = hook_tun_dev_attach;
+ hook_sops.key_alloc = hook_key_alloc;
+ hook_sops.key_free = hook_key_free;
+ hook_sops.key_permission = hook_key_permission;
+ hook_sops.key_getsecurity = hook_key_getsecurity;
+ hook_sops.audit_rule_init = hook_audit_rule_init;
+ hook_sops.audit_rule_known = hook_audit_rule_known;
+ hook_sops.audit_rule_match = hook_audit_rule_match;
+ hook_sops.audit_rule_free = hook_audit_rule_free;
+
+ *security_hook_addr = (unsigned long)&hook_sops;
+
+ return 0;
+}
+int judgk_security_unhook(){
+ *security_hook_addr = (unsigned long)ori_sops;
+ return 0;
+}
+
+static unsigned long* security_get_addr(){
+ ssize_t ret;
+ int i;
+ int j;
+
+ struct file *f;
+ char line[128];
+ unsigned char code[3] = {0x48,0xc7,0x05};
+ unsigned long addr;
+
+ f = filp_open("/proc/kallsyms",O_RDONLY,0);
+ set_fs(KERNEL_DS);
+
+ i = 0;
+ addr = 0;
+ while(true){
+ ret = f->f_op->read(f,&line[i],1,&f->f_pos);
+
+ if(line[i] == '\n' || ret <= 0){
+ line[i] = '\0';
+
+ addr = 0;
+ for(j = 0;j < i;j++){
+ if(line[j] == ' '){
+ j++;
+ break;
+ }
+
+ addr *= 16UL;
+ if(line[j] >= '0' && line[j] <= '9'){
+ addr += (unsigned long)(line[j] - '0');
+ }else{
+ addr += (unsigned long)(line[j] - 'a' + 10);
+ }
+ }
+ for(;j < i;j++){
+ if(line[j] == ' '){
+ j++;
+ break;
+ }
+ }
+ if(j < i){
+ if(strcmp("reset_security_ops",line + j) == 0){
+ break;
+ }
+ }
+
+ i = 0;
+ }else{
+ i++;
+ }
+
+ if(ret <= 0){
+ break;
+ }
+ }
+
+ set_fs(USER_DS);
+ filp_close(f,NULL);
+
+ i = 0;
+ while(i < 3){
+ if(*(unsigned char*)addr != code[i]){
+ i = 0;
+ }else{
+ i++;
+ }
+ addr++;
+ }
+
+ return (unsigned long*)(addr + (unsigned long)*(unsigned int*)addr + 8UL);
+}
+static inline void security_hook_rf(struct judgk_proc_info *info){
+ info->status = JUDGE_RF;
+ send_sig(SIGKILL,current,0);
+}
+
+static int hook_inode_permission(struct inode *inode,int mask){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_permission(inode,mask);
+ }
+
+ if((mask & ~(MAY_EXEC | MAY_READ | MAY_OPEN | MAY_CHDIR | MAY_NOT_BLOCK)) != 0){
+ pr_alert("judgk:PID %d RF inode_permission %08x\n",current->tgid,mask);
+
+ security_hook_rf(info);
+ return -EACCES;
+ }
+ return ori_sops->inode_permission(inode,mask);
+}
+static int hook_file_permission(struct file *file,int mask){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_permission(file,mask);
+ }
+
+ if((mask & ~(MAY_READ | MAY_WRITE)) != 0){
+ security_hook_rf(info);
+ return -EACCES;
+ }else if((mask & MAY_WRITE) != 0 && file != info->std_out){
+ security_hook_rf(info);
+ return -EACCES;
+ }
+ return ori_sops->file_permission(file,mask);
+}
+static int hook_file_open(struct file *file, const struct cred *cred){
+ int ret;
+ int i;
+
+ struct judgk_proc_info *info;
+ char *buf_path,*path;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_open(file,cred);
+ }
+
+ ret = 0;
+ buf_path = kmalloc(sizeof(char) * (PATH_MAX + 1),GFP_KERNEL);
+ path = d_path(&file->f_path,buf_path,PATH_MAX + 1);
+
+ if((file->f_mode & !(FMODE_READ | FMODE_LSEEK | FMODE_PREAD | FMODE_EXEC)) != 0){
+ ret = -EACCES;
+ }else if(strcmp(path,"/proc/meminfo") != 0){
+ i = 0;
+ while(info->run_path[i] != '\0'){
+ if(path[i] != info->run_path[i]){
+ ret = -EACCES;
+ break;
+ }
+ i++;
+ }
+ if(path[i] == info->run_path[i]){
+ ret = -EACCES;
+ }
+ }
+
+ kfree(buf_path);
+
+ if(ret != 0){
+ pr_alert("judgk:PID %d RF file_open %s %08x\n",current->tgid,path,file->f_mode);
+
+ security_hook_rf(info);
+ return ret;
+ }
+ return ori_sops->file_open(file,cred);
+}
+static int hook_file_ioctl(struct file *file,unsigned int cmd,unsigned long arg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_ioctl(file,cmd,arg);
+ }
+
+ if(file != info->std_in && file != info->std_out){
+ pr_alert("judgk:PID %d file_ioctl\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+ }
+ return ori_sops->file_ioctl(file,cmd,arg);
+}
+static int hook_vm_enough_memory(struct mm_struct *mm,long pages){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL)){
+ return ori_sops->vm_enough_memory(mm,pages);
+ }
+
+ info->memory = (mm->total_vm + pages) << PAGE_SHIFT;
+ //pr_alert("judgk:PID %d vm_enough_memory %lu\n",current->tgid,info->memory);
+
+ if(info->memory > info->memlimit){
+ info->status = JUDGE_MLE;
+ send_sig(SIGKILL,current,0);
+ return -EACCES;
+ }
+ return ori_sops->vm_enough_memory(mm,pages);
+}
+
+
+
+
+static int hook_ptrace_access_check(struct task_struct *child,unsigned int mode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->ptrace_access_check(child,mode);
+ }
+
+ pr_alert("judgk:PID %d ptrace_access_check\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_ptrace_traceme(struct task_struct *parent){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->ptrace_traceme(parent);
+ }
+
+ pr_alert("judgk:PID %d ptrace_traceme\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_capget(struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->capget(target,effective,inheritable,permitted);
+ }
+
+ pr_alert("judgk:PID %d capget\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_capset(struct cred *new,const struct cred *old,const kernel_cap_t *effective,const kernel_cap_t *inheritable,const kernel_cap_t *permitted){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->capset(new,old,effective,inheritable,permitted);
+ }
+
+ pr_alert("judgk:PID %d capset\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static int hook_capable(const struct cred *cred,struct user_namespace *ns,int cap,int audit){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->capable(cred,ns,cap,audit);
+ }
+
+ pr_alert("judgk:PID %d capable\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}*/
+static int hook_quotactl(int cmds,int type,int id,struct super_block *sb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->quotactl(cmds,type,id,sb);
+ }
+
+ pr_alert("judgk:PID %d quotactl\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_quota_on(struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->quota_on(dentry);
+ }
+
+ pr_alert("judgk:PID %d quota_on\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_syslog(int type){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->syslog(type);
+ }
+
+ pr_alert("judgk:PID %d syslog\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_settime(const struct timespec *ts,const struct timezone *tz){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->settime(ts,tz);
+ }
+
+ pr_alert("judgk:PID %d settime\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static int hook_bprm_set_creds(struct linux_binprm *bprm){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->bprm_set_creds(bprm);
+ }
+
+ pr_alert("judgk:PID %d bprm_set_creds\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_bprm_check_security(struct linux_binprm *bprm){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->bprm_check_security(bprm);
+ }
+
+ pr_alert("judgk:PID %d bprm_check_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_bprm_secureexec(struct linux_binprm *bprm){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->bprm_secureexec(bprm);
+ }
+
+ pr_alert("judgk:PID %d bprm_secureexec\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_bprm_committing_creds(struct linux_binprm *bprm){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->bprm_committing_creds(bprm);
+ }
+
+ pr_alert("judgk:PID %d bprm_committing_creds\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static void hook_bprm_committed_creds(struct linux_binprm *bprm){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->bprm_committed_creds(bprm);
+ }
+
+ pr_alert("judgk:PID %d bprm_committed_creds\n",current->tgid);
+
+ security_hook_rf(info);
+}*/
+static int hook_sb_alloc_security(struct super_block *sb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_alloc_security(sb);
+ }
+
+ pr_alert("judgk:PID %d sb_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_sb_free_security(struct super_block *sb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_free_security(sb);
+ }
+
+ pr_alert("judgk:PID %d sb_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_sb_copy_data(char *orig,char *copy){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_copy_data(orig,copy);
+ }
+
+ pr_alert("judgk:PID %d sb_copy_data\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_remount(struct super_block *sb,void *data){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_remount(sb,data);
+ }
+
+ pr_alert("judgk:PID %d sb_remount\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_kern_mount(struct super_block *sb,int flags,void *data){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_kern_mount(sb,flags,data);
+ }
+
+ pr_alert("judgk:PID %d sb_kern_mount\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_show_options(struct seq_file *m,struct super_block *sb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_show_options(m,sb);
+ }
+
+ pr_alert("judgk:PID %d sb_show_options\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_statfs(struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_statfs(dentry);
+ }
+
+ pr_alert("judgk:PID %d sb_statfs\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_mount(const char *dev_name,struct path *path,const char *type,unsigned long flags,void *data){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_mount(dev_name,path,type,flags,data);
+ }
+
+ pr_alert("judgk:PID %d sb_mount\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_umount(struct vfsmount *mnt,int flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_umount(mnt,flags);
+ }
+
+ pr_alert("judgk:PID %d sb_umount\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_pivotroot(struct path *old_path,struct path *new_path){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_pivotroot(old_path,new_path);
+ }
+
+ pr_alert("judgk:PID %d sb_pivotroot\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sb_set_mnt_opts(struct super_block *sb,struct security_mnt_opts *opts){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_set_mnt_opts(sb,opts);
+ }
+
+ pr_alert("judgk:PID %d sb_set_mnt_opts\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_sb_clone_mnt_opts(const struct super_block *oldsb,struct super_block *newsb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_clone_mnt_opts(oldsb,newsb);
+ }
+
+ pr_alert("judgk:PID %d sb_clone_mnt_opts\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_sb_parse_opts_str(char *options,struct security_mnt_opts *opts){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sb_parse_opts_str(options,opts);
+ }
+
+ pr_alert("judgk:PID %d sb_parse_opts_str\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_unlink(struct path *dir,struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_unlink(dir,dentry);
+ }
+
+ pr_alert("judgk:PID %d path_unlink\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_mkdir(struct path *dir,struct dentry *dentry,umode_t mode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_mkdir(dir,dentry,mode);
+ }
+
+ pr_alert("judgk:PID %d path_mkdir\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_rmdir(struct path *dir,struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_rmdir(dir,dentry);
+ }
+
+ pr_alert("judgk:PID %d path_rmdir\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_mknod(struct path *dir,struct dentry *dentry,umode_t mode,unsigned int dev){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_mknod(dir,dentry,mode,dev);
+ }
+
+ pr_alert("judgk:PID %d path_mknod\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_truncate(struct path *path){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_truncate(path);
+ }
+
+ pr_alert("judgk:PID %d path_truncate\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_symlink(struct path *dir,struct dentry *dentry,const char *old_name){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_symlink(dir,dentry,old_name);
+ }
+
+ pr_alert("judgk:PID %d path_symlink\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_link(struct dentry *old_dentry,struct path *new_dir,struct dentry *new_dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_link(old_dentry,new_dir,new_dentry);
+ }
+
+ pr_alert("judgk:PID %d path_link\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_rename(struct path *old_dir,struct dentry *old_dentry,struct path *new_dir,struct dentry *new_dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_rename(old_dir,old_dentry,new_dir,new_dentry);
+ }
+
+ pr_alert("judgk:PID %d path_rename\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_chmod(struct path *path,umode_t mode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_chmod(path,mode);
+ }
+
+ pr_alert("judgk:PID %d path_chmod\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_chown(struct path *path,kuid_t uid,kgid_t gid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_chown(path,uid,gid);
+ }
+
+ pr_alert("judgk:PID %d path_chown\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_path_chroot(struct path *path){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->path_chroot(path);
+ }
+
+ pr_alert("judgk:PID %d path_chroot\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static int hook_inode_alloc_security(struct inode *inode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_alloc_security(inode);
+ }
+
+ pr_alert("judgk:PID %d inode_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_inode_free_security(struct inode *inode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_free_security(inode);
+ }
+
+ pr_alert("judgk:PID %d inode_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}*/
+static int hook_inode_init_security(struct inode *inode,struct inode *dir,const struct qstr *qstr,char **name,void **value,size_t *len){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_init_security(inode,dir,qstr,name,value,len);
+ }
+
+ pr_alert("judgk:PID %d inode_init_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_create(struct inode *dir,struct dentry *dentry,umode_t mode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_create(dir,dentry,mode);
+ }
+
+ pr_alert("judgk:PID %d inode_create\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_link(struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_link(old_dentry,dir,new_dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_link\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_unlink(struct inode *dir,struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_unlink(dir,dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_unlink\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_symlink(struct inode *dir,struct dentry *dentry,const char *old_name){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_symlink(dir,dentry,old_name);
+ }
+
+ pr_alert("judgk:PID %d inode_symlink\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_mkdir(struct inode *dir,struct dentry *dentry,umode_t mode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_mkdir(dir,dentry,mode);
+ }
+
+ pr_alert("judgk:PID %d inode_mkdir\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_rmdir(struct inode *dir,struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_rmdir(dir,dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_rmdir\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_mknod(struct inode *dir,struct dentry *dentry,umode_t mode,dev_t dev){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_mknod(dir,dentry,mode,dev);
+ }
+
+ pr_alert("judgk:PID %d inode_mknod\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_rename(struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_rename(old_dir,old_dentry,new_dir,new_dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_rename\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_readlink(struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_readlink(dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_readlink\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static int hook_inode_follow_link(struct dentry *dentry,struct nameidata *nd){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_follow_link(dentry,nd);
+ }
+
+ pr_alert("judgk:PID %d inode_follow_link\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}*/
+static int hook_inode_setattr(struct dentry *dentry,struct iattr *attr){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_setattr(dentry,attr);
+ }
+
+ pr_alert("judgk:PID %d inode_setattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static int hook_inode_getattr(struct vfsmount *mnt,struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_getattr(mnt,dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_getattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}*/
+static int hook_inode_setxattr(struct dentry *dentry,const char *name,const void *value,size_t size,int flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_setxattr(dentry,name,value,size,flags);
+ }
+
+ pr_alert("judgk:PID %d inode_setxattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_inode_post_setxattr(struct dentry *dentry,const char *name,const void *value,size_t size,int flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_post_setxattr(dentry,name,value,size,flags);
+ }
+
+ pr_alert("judgk:PID %d inode_post_setxattr\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_inode_getxattr(struct dentry *dentry,const char *name){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_getxattr(dentry,name);
+ }
+
+ pr_alert("judgk:PID %d inode_getxattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_listxattr(struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_listxattr(dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_listxattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_removexattr(struct dentry *dentry,const char *name){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_removexattr(dentry,name);
+ }
+
+ pr_alert("judgk:PID %d inode_removexattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_need_killpriv(struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_need_killpriv(dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_need_killpriv\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_killpriv(struct dentry *dentry){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_killpriv(dentry);
+ }
+
+ pr_alert("judgk:PID %d inode_killpriv\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_getsecurity(const struct inode *inode,const char *name,void **buffer,bool alloc){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_getsecurity(inode,name,buffer,alloc);
+ }
+
+ pr_alert("judgk:PID %d inode_getsecurity\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_setsecurity(struct inode *inode,const char *name,const void *value,size_t size,int flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_setsecurity(inode,name,value,size,flags);
+ }
+
+ pr_alert("judgk:PID %d inode_setsecurity\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_listsecurity(struct inode *inode,char *buffer,size_t buffer_size){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_listsecurity(inode,buffer,buffer_size);
+ }
+
+ pr_alert("judgk:PID %d inode_listsecurity\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_inode_getsecid(const struct inode *inode,u32 *secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_getsecid(inode,secid);
+ }
+
+ pr_alert("judgk:PID %d inode_getsecid\n",current->tgid);
+
+ security_hook_rf(info);
+}
+/*static int hook_file_alloc_security(struct file *file){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_alloc_security(file);
+ }
+
+ pr_alert("judgk:PID %d file_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_file_free_security(struct file *file){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_free_security(file);
+ }
+
+ pr_alert("judgk:PID %d file_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_mmap_addr(unsigned long addr){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->mmap_addr(addr);
+ }
+
+ pr_alert("judgk:PID %d mmap_addr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_mmap_file(struct file *file,unsigned long reqprot,unsigned long prot,unsigned long flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->mmap_file(file,reqprot,prot,flags);
+ }
+
+ pr_alert("judgk:PID %d mmap_file\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_file_mprotect(struct vm_area_struct *vma,unsigned long reqprot,unsigned long prot){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_mprotect(vma,reqprot,prot);
+ }
+
+ pr_alert("judgk:PID %d file_mprotect\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}*/
+static int hook_file_lock(struct file *file,unsigned int cmd){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_lock(file,cmd);
+ }
+
+ pr_alert("judgk:PID %d file_lock\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_file_fcntl(struct file *file,unsigned int cmd,unsigned long arg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_fcntl(file,cmd,arg);
+ }
+
+ pr_alert("judgk:PID %d file_fcntl\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_file_set_fowner(struct file *file){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_set_fowner(file);
+ }
+
+ pr_alert("judgk:PID %d file_set_fowner\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_file_send_sigiotask(struct task_struct *tsk,struct fown_struct *fown,int sig){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_send_sigiotask(tsk,fown,sig);
+ }
+
+ pr_alert("judgk:PID %d file_send_sigiotask\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_file_receive(struct file *file){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->file_receive(file);
+ }
+
+ pr_alert("judgk:PID %d file_receive\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_create(unsigned long clone_flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_create(clone_flags);
+ }
+
+ pr_alert("judgk:PID %d task_create\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static void hook_task_free(struct task_struct *task){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_free(task);
+ }
+
+ pr_alert("judgk:PID %d task_free\n",current->tgid);
+
+ security_hook_rf(info);
+}*/
+static int hook_cred_alloc_blank(struct cred *cred,gfp_t gfp){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->cred_alloc_blank(cred,gfp);
+ }
+
+ pr_alert("judgk:PID %d cred_alloc_blank\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static void hook_cred_free(struct cred *cred){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->cred_free(cred);
+ }
+
+ pr_alert("judgk:PID %d cred_free\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_cred_prepare(struct cred *new,const struct cred *old,gfp_t gfp){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->cred_prepare(new,old,gfp);
+ }
+
+ pr_alert("judgk:PID %d cred_prepare\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}*/
+static void hook_cred_transfer(struct cred *new,const struct cred *old){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->cred_transfer(new,old);
+ }
+
+ pr_alert("judgk:PID %d cred_transfer\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_kernel_act_as(struct cred *new,u32 secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->kernel_act_as(new,secid);
+ }
+
+ pr_alert("judgk:PID %d kernel_act_as\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_kernel_create_files_as(struct cred *new,struct inode *inode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->kernel_create_files_as(new,inode);
+ }
+
+ pr_alert("judgk:PID %d kernel_create_files_as\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_kernel_module_request(char *kmod_name){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->kernel_module_request(kmod_name);
+ }
+
+ pr_alert("judgk:PID %d kernel_module_request\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_fix_setuid(struct cred *new,const struct cred *old,int flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_fix_setuid(new,old,flags);
+ }
+
+ pr_alert("judgk:PID %d task_fix_setuid\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_setpgid(struct task_struct *p,pid_t pgid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_setpgid(p,pgid);
+ }
+
+ pr_alert("judgk:PID %d task_setpgid\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_getpgid(struct task_struct *p){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_getpgid(p);
+ }
+
+ pr_alert("judgk:PID %d task_getpgid\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_getsid(struct task_struct *p){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_getsid(p);
+ }
+
+ pr_alert("judgk:PID %d task_getsid\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_task_getsecid(struct task_struct *p,u32 *secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_getsecid(p,secid);
+ }
+
+ pr_alert("judgk:PID %d task_getsecid\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_task_setnice(struct task_struct *p,int nice){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_setnice(p,nice);
+ }
+
+ pr_alert("judgk:PID %d task_setnice\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_setioprio(struct task_struct *p,int ioprio){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_setioprio(p,ioprio);
+ }
+
+ pr_alert("judgk:PID %d task_setioprio\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_getioprio(struct task_struct *p){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_getioprio(p);
+ }
+
+ pr_alert("judgk:PID %d task_getioprio\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_setrlimit(struct task_struct *p,unsigned int resource,struct rlimit *new_rlim){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_setrlimit(p,resource,new_rlim);
+ }
+
+ pr_alert("judgk:PID %d task_setrlimit\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_setscheduler(struct task_struct *p){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_setscheduler(p);
+ }
+
+ pr_alert("judgk:PID %d task_setscheduler\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_getscheduler(struct task_struct *p){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_getscheduler(p);
+ }
+
+ pr_alert("judgk:PID %d task_getscheduler\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_movememory(struct task_struct *p){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_movememory(p);
+ }
+
+ pr_alert("judgk:PID %d task_movememory\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_kill(struct task_struct *p,struct siginfo *siginfo,int sig,u32 secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_kill(p,siginfo,sig,secid);
+ }
+
+ pr_alert("judgk:PID %d task_kill\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_wait(struct task_struct *p){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_wait(p);
+ }
+
+ pr_alert("judgk:PID %d task_wait\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_task_prctl(int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_prctl(option,arg2,arg3,arg4,arg5);
+ }
+
+ pr_alert("judgk:PID %d task_prctl\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_task_to_inode(struct task_struct *p,struct inode *inode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->task_to_inode(p,inode);
+ }
+
+ pr_alert("judgk:PID %d task_to_inode\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_ipc_permission(struct kern_ipc_perm *ipcp,short flag){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->ipc_permission(ipcp,flag);
+ }
+
+ pr_alert("judgk:PID %d ipc_permission\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_ipc_getsecid(struct kern_ipc_perm *ipcp,u32 *secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->ipc_getsecid(ipcp,secid);
+ }
+
+ pr_alert("judgk:PID %d ipc_getsecid\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_msg_msg_alloc_security(struct msg_msg *msg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_msg_alloc_security(msg);
+ }
+
+ pr_alert("judgk:PID %d msg_msg_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_msg_msg_free_security(struct msg_msg *msg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_msg_free_security(msg);
+ }
+
+ pr_alert("judgk:PID %d msg_msg_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_msg_queue_alloc_security(struct msg_queue *msq){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_queue_alloc_security(msq);
+ }
+
+ pr_alert("judgk:PID %d msg_queue_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_msg_queue_free_security(struct msg_queue *msq){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_queue_free_security(msq);
+ }
+
+ pr_alert("judgk:PID %d msg_queue_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_msg_queue_associate(struct msg_queue *msq,int msqflg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_queue_associate(msq,msqflg);
+ }
+
+ pr_alert("judgk:PID %d msg_queue_associate\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_msg_queue_msgctl(struct msg_queue *msq,int cmd){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_queue_msgctl(msq,cmd);
+ }
+
+ pr_alert("judgk:PID %d msg_queue_msgctl\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_msg_queue_msgsnd(struct msg_queue *msq,struct msg_msg *msg,int msqflg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_queue_msgsnd(msq,msg,msqflg);
+ }
+
+ pr_alert("judgk:PID %d msg_queue_msgsnd\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_msg_queue_msgrcv(struct msg_queue *msq,struct msg_msg *msg,struct task_struct *target,long type,int mode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->msg_queue_msgrcv(msq,msg,target,type,mode);
+ }
+
+ pr_alert("judgk:PID %d msg_queue_msgrcv\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_shm_alloc_security(struct shmid_kernel *shp){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->shm_alloc_security(shp);
+ }
+
+ pr_alert("judgk:PID %d shm_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_shm_free_security(struct shmid_kernel *shp){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->shm_free_security(shp);
+ }
+
+ pr_alert("judgk:PID %d shm_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_shm_associate(struct shmid_kernel *shp,int shmflg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->shm_associate(shp,shmflg);
+ }
+
+ pr_alert("judgk:PID %d shm_associate\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_shm_shmctl(struct shmid_kernel *shp,int cmd){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->shm_shmctl(shp,cmd);
+ }
+
+ pr_alert("judgk:PID %d shm_shmctl\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_shm_shmat(struct shmid_kernel *shp,char __user *shmaddr,int shmflg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->shm_shmat(shp,shmaddr,shmflg);
+ }
+
+ pr_alert("judgk:PID %d shm_shmat\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sem_alloc_security(struct sem_array *sma){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sem_alloc_security(sma);
+ }
+
+ pr_alert("judgk:PID %d sem_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_sem_free_security(struct sem_array *sma){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sem_free_security(sma);
+ }
+
+ pr_alert("judgk:PID %d sem_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_sem_associate(struct sem_array *sma,int semflg){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sem_associate(sma,semflg);
+ }
+
+ pr_alert("judgk:PID %d sem_associate\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sem_semctl(struct sem_array *sma,int cmd){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sem_semctl(sma,cmd);
+ }
+
+ pr_alert("judgk:PID %d sem_semctl\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sem_semop(struct sem_array *sma,struct sembuf *sops,unsigned nsops,int alter){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sem_semop(sma,sops,nsops,alter);
+ }
+
+ pr_alert("judgk:PID %d sem_semop\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_netlink_send(struct sock *sk,struct sk_buff *skb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->netlink_send(sk,skb);
+ }
+
+ pr_alert("judgk:PID %d netlink_send\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_d_instantiate(struct dentry *dentry,struct inode *inode){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->d_instantiate(dentry,inode);
+ }
+
+ pr_alert("judgk:PID %d d_instantiate\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_getprocattr(struct task_struct *p,char *name,char **value){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->getprocattr(p,name,value);
+ }
+
+ pr_alert("judgk:PID %d getprocattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_setprocattr(struct task_struct *p,char *name,void *value,size_t size){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->setprocattr(p,name,value,size);
+ }
+
+ pr_alert("judgk:PID %d setprocattr\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_secid_to_secctx(u32 secid,char **secdata,u32 *seclen){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->secid_to_secctx(secid,secdata,seclen);
+ }
+
+ pr_alert("judgk:PID %d secid_to_secctx\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_secctx_to_secid(const char *secdata,u32 seclen,u32 *secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->secctx_to_secid(secdata,seclen,secid);
+ }
+
+ pr_alert("judgk:PID %d secctx_to_secid\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_release_secctx(char *secdata,u32 seclen){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->release_secctx(secdata,seclen);
+ }
+
+ pr_alert("judgk:PID %d release_secctx\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_inode_notifysecctx(struct inode *inode,void *ctx,u32 ctxlen){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_notifysecctx(inode,ctx,ctxlen);
+ }
+
+ pr_alert("judgk:PID %d inode_notifysecctx\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_setsecctx(struct dentry *dentry,void *ctx,u32 ctxlen){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_setsecctx(dentry,ctx,ctxlen);
+ }
+
+ pr_alert("judgk:PID %d inode_setsecctx\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_inode_getsecctx(struct inode *inode,void **ctx,u32 *ctxlen){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inode_getsecctx(inode,ctx,ctxlen);
+ }
+
+ pr_alert("judgk:PID %d inode_getsecctx\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_unix_stream_connect(struct sock *sock,struct sock *other,struct sock *newsk){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->unix_stream_connect(sock,other,newsk);
+ }
+
+ pr_alert("judgk:PID %d unix_stream_connect\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_unix_may_send(struct socket *sock,struct socket *other){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->unix_may_send(sock,other);
+ }
+
+ pr_alert("judgk:PID %d unix_may_send\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_create(int family,int type,int protocol,int kern){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_create(family,type,protocol,kern);
+ }
+
+ pr_alert("judgk:PID %d socket_create\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_post_create(struct socket *sock,int family,int type,int protocol,int kern){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_post_create(sock,family,type,protocol,kern);
+ }
+
+ pr_alert("judgk:PID %d socket_post_create\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_bind(struct socket *sock,struct sockaddr *address,int addrlen){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_bind(sock,address,addrlen);
+ }
+
+ pr_alert("judgk:PID %d socket_bind\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_connect(struct socket *sock,struct sockaddr *address,int addrlen){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_connect(sock,address,addrlen);
+ }
+
+ pr_alert("judgk:PID %d socket_connect\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_listen(struct socket *sock,int backlog){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_listen(sock,backlog);
+ }
+
+ pr_alert("judgk:PID %d socket_listen\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_accept(struct socket *sock,struct socket *newsock){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_accept(sock,newsock);
+ }
+
+ pr_alert("judgk:PID %d socket_accept\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_sendmsg(struct socket *sock,struct msghdr *msg,int size){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_sendmsg(sock,msg,size);
+ }
+
+ pr_alert("judgk:PID %d socket_sendmsg\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_recvmsg(struct socket *sock,struct msghdr *msg,int size,int flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_recvmsg(sock,msg,size,flags);
+ }
+
+ pr_alert("judgk:PID %d socket_recvmsg\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_getsockname(struct socket *sock){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_getsockname(sock);
+ }
+
+ pr_alert("judgk:PID %d socket_getsockname\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_getpeername(struct socket *sock){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_getpeername(sock);
+ }
+
+ pr_alert("judgk:PID %d socket_getpeername\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_getsockopt(struct socket *sock,int level,int optname){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_getsockopt(sock,level,optname);
+ }
+
+ pr_alert("judgk:PID %d socket_getsockopt\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_setsockopt(struct socket *sock,int level,int optname){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_setsockopt(sock,level,optname);
+ }
+
+ pr_alert("judgk:PID %d socket_setsockopt\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_shutdown(struct socket *sock,int how){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_shutdown(sock,how);
+ }
+
+ pr_alert("judgk:PID %d socket_shutdown\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_sock_rcv_skb(struct sock *sk,struct sk_buff *skb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_sock_rcv_skb(sk,skb);
+ }
+
+ pr_alert("judgk:PID %d socket_sock_rcv_skb\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_getpeersec_stream(struct socket *sock,char __user *optval,int __user *optlen,unsigned len){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_getpeersec_stream(sock,optval,optlen,len);
+ }
+
+ pr_alert("judgk:PID %d socket_getpeersec_stream\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_socket_getpeersec_dgram(struct socket *sock,struct sk_buff *skb,u32 *secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->socket_getpeersec_dgram(sock,skb,secid);
+ }
+
+ pr_alert("judgk:PID %d socket_getpeersec_dgram\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_sk_alloc_security(struct sock *sk,int family,gfp_t priority){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sk_alloc_security(sk,family,priority);
+ }
+
+ pr_alert("judgk:PID %d sk_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_sk_free_security(struct sock *sk){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sk_free_security(sk);
+ }
+
+ pr_alert("judgk:PID %d sk_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static void hook_sk_clone_security(const struct sock *sk,struct sock *newsk){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sk_clone_security(sk,newsk);
+ }
+
+ pr_alert("judgk:PID %d sk_clone_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static void hook_sk_getsecid(struct sock *sk,u32 *secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sk_getsecid(sk,secid);
+ }
+
+ pr_alert("judgk:PID %d sk_getsecid\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static void hook_sock_graft(struct sock *sk,struct socket *parent){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->sock_graft(sk,parent);
+ }
+
+ pr_alert("judgk:PID %d sock_graft\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_inet_conn_request(struct sock *sk,struct sk_buff *skb,struct request_sock *req){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inet_conn_request(sk,skb,req);
+ }
+
+ pr_alert("judgk:PID %d inet_conn_request\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_inet_csk_clone(struct sock *newsk,const struct request_sock *req){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inet_csk_clone(newsk,req);
+ }
+
+ pr_alert("judgk:PID %d inet_csk_clone\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static void hook_inet_conn_established(struct sock *sk,struct sk_buff *skb){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->inet_conn_established(sk,skb);
+ }
+
+ pr_alert("judgk:PID %d inet_conn_established\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_secmark_relabel_packet(u32 secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->secmark_relabel_packet(secid);
+ }
+
+ pr_alert("judgk:PID %d secmark_relabel_packet\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_secmark_refcount_inc(){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->secmark_refcount_inc();
+ }
+
+ pr_alert("judgk:PID %d secmark_refcount_inc\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static void hook_secmark_refcount_dec(){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->secmark_refcount_dec();
+ }
+
+ pr_alert("judgk:PID %d secmark_refcount_dec\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static void hook_req_classify_flow(const struct request_sock *req,struct flowi *fl){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->req_classify_flow(req,fl);
+ }
+
+ pr_alert("judgk:PID %d req_classify_flow\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_tun_dev_create(){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->tun_dev_create();
+ }
+
+ pr_alert("judgk:PID %d tun_dev_create\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_tun_dev_post_create(struct sock *sk){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->tun_dev_post_create(sk);
+ }
+
+ pr_alert("judgk:PID %d tun_dev_post_create\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_tun_dev_attach(struct sock *sk){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->tun_dev_attach(sk);
+ }
+
+ pr_alert("judgk:PID %d tun_dev_attach\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+/*static int hook_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp,struct xfrm_user_sec_ctx *sec_ctx){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_policy_alloc_security(ctxp,sec_ctx);
+ }
+
+ pr_alert("judgk:PID %d xfrm_policy_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_xfrm_policy_clone_security(struct xfrm_sec_ctx *old_ctx,struct xfrm_sec_ctx **new_ctx){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_policy_clone_security(old_ctx,new_ctx);
+ }
+
+ pr_alert("judgk:PID %d xfrm_policy_clone_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_xfrm_policy_free_security(struct xfrm_sec_ctx *ctx){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_policy_free_security(ctx);
+ }
+
+ pr_alert("judgk:PID %d xfrm_policy_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_xfrm_policy_delete_security(struct xfrm_sec_ctx *ctx){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_policy_delete_security(ctx);
+ }
+
+ pr_alert("judgk:PID %d xfrm_policy_delete_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_xfrm_state_alloc_security(struct xfrm_state *x,struct xfrm_user_sec_ctx *sec_ctx,u32 secid){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_state_alloc_security(x,sec_ctx,secid);
+ }
+
+ pr_alert("judgk:PID %d xfrm_state_alloc_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_xfrm_state_free_security(struct xfrm_state *x){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_state_free_security(x);
+ }
+
+ pr_alert("judgk:PID %d xfrm_state_free_security\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_xfrm_state_delete_security(struct xfrm_state *x){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_state_delete_security(x);
+ }
+
+ pr_alert("judgk:PID %d xfrm_state_delete_security\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx,u32 fl_secid,u8 dir){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_policy_lookup(ctx,fl_secid,dir);
+ }
+
+ pr_alert("judgk:PID %d xfrm_policy_lookup\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_xfrm_state_pol_flow_match(struct xfrm_state *x,struct xfrm_policy *xp,const struct flowi *fl){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_state_pol_flow_match(x,xp,fl);
+ }
+
+ pr_alert("judgk:PID %d xfrm_state_pol_flow_match\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_xfrm_decode_session(struct sk_buff *skb,u32 *secid,int ckall){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->xfrm_decode_session(skb,secid,ckall);
+ }
+
+ pr_alert("judgk:PID %d xfrm_decode_session\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}*/
+static int hook_key_alloc(struct key *key,const struct cred *cred,unsigned long flags){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->key_alloc(key,cred,flags);
+ }
+
+ pr_alert("judgk:PID %d key_alloc\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_key_free(struct key *key){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->key_free(key);
+ }
+
+ pr_alert("judgk:PID %d key_free\n",current->tgid);
+
+ security_hook_rf(info);
+}
+static int hook_key_permission(key_ref_t key_ref,const struct cred *cred,key_perm_t perm){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->key_permission(key_ref,cred,perm);
+ }
+
+ pr_alert("judgk:PID %d key_permission\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_key_getsecurity(struct key *key,char **_buffer){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->key_getsecurity(key,_buffer);
+ }
+
+ pr_alert("judgk:PID %d key_getsecurity\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_audit_rule_init(u32 field,u32 op,char *rulestr,void **lsmrule){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->audit_rule_init(field,op,rulestr,lsmrule);
+ }
+
+ pr_alert("judgk:PID %d audit_rule_init\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_audit_rule_known(struct audit_krule *krule){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->audit_rule_known(krule);
+ }
+
+ pr_alert("judgk:PID %d audit_rule_known\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static int hook_audit_rule_match(u32 secid,u32 field,u32 op,void *lsmrule,struct audit_context *actx){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->audit_rule_match(secid,field,op,lsmrule,actx);
+ }
+
+ pr_alert("judgk:PID %d audit_rule_match\n",current->tgid);
+
+ security_hook_rf(info);
+ return -EACCES;
+}
+static void hook_audit_rule_free(void *lsmrule){
+ struct judgk_proc_info *info;
+
+ info = judgk_proc_task_lookup(current);
+ if(likely(info == NULL || in_interrupt())){
+ return ori_sops->audit_rule_free(lsmrule);
+ }
+
+ pr_alert("judgk:PID %d audit_rule_free\n",current->tgid);
+
+ security_hook_rf(info);
+}
diff --git a/judge/judgm_security.h b/toj/center/src/judgk_security.h
index f723331..5080dd0 100644..100755
--- a/judge/judgm_security.h
+++ b/toj/center/src/judgk_security.h
@@ -1,13 +1,14 @@
static unsigned long* security_get_addr(void);
+static inline void security_hook_rf(struct judgk_proc_info *info);
static unsigned long* security_hook_addr;
static struct security_operations *ori_sops;
static struct security_operations hook_sops;
-int judgm_security_hook(void);
-int judgm_security_unhook(void);
+int judgk_security_hook(void);
+int judgk_security_unhook(void);
-extern struct judgm_proc_info* judgm_proc_task_lookup(struct task_struct *task);
+extern struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task);
static int hook_ptrace_access_check(struct task_struct *child,unsigned int mode);
static int hook_ptrace_traceme(struct task_struct *parent);
@@ -22,16 +23,20 @@ static int hook_vm_enough_memory(struct mm_struct *mm,long pages);
//static int hook_bprm_set_creds(struct linux_binprm *bprm);
//static int hook_bprm_check_security(struct linux_binprm *bprm);
//static int hook_bprm_secureexec(struct linux_binprm *bprm);
+//static void hook_bprm_committing_creds(struct linux_binprm *bprm);
+//static void hook_bprm_committed_creds(struct linux_binprm *bprm);
static int hook_sb_alloc_security(struct super_block *sb);
+static void hook_sb_free_security(struct super_block *sb);
static int hook_sb_copy_data(char *orig,char *copy);
static int hook_sb_remount(struct super_block *sb,void *data);
static int hook_sb_kern_mount(struct super_block *sb,int flags,void *data);
static int hook_sb_show_options(struct seq_file *m,struct super_block *sb);
static int hook_sb_statfs(struct dentry *dentry);
-static int hook_sb_mount(char *dev_name,struct path *path,char *type,unsigned long flags,void *data);
+static int hook_sb_mount(const char *dev_name,struct path *path,const char *type,unsigned long flags,void *data);
static int hook_sb_umount(struct vfsmount *mnt,int flags);
static int hook_sb_pivotroot(struct path *old_path,struct path *new_path);
static int hook_sb_set_mnt_opts(struct super_block *sb,struct security_mnt_opts *opts);
+static void hook_sb_clone_mnt_opts(const struct super_block *oldsb,struct super_block *newsb);
static int hook_sb_parse_opts_str(char *options,struct security_mnt_opts *opts);
static int hook_path_unlink(struct path *dir,struct dentry *dentry);
static int hook_path_mkdir(struct path *dir,struct dentry *dentry,umode_t mode);
@@ -42,9 +47,10 @@ static int hook_path_symlink(struct path *dir,struct dentry *dentry,const char *
static int hook_path_link(struct dentry *old_dentry,struct path *new_dir,struct dentry *new_dentry);
static int hook_path_rename(struct path *old_dir,struct dentry *old_dentry,struct path *new_dir,struct dentry *new_dentry);
static int hook_path_chmod(struct path *path,umode_t mode);
-static int hook_path_chown(struct path *path,uid_t uid,gid_t gid);
+static int hook_path_chown(struct path *path,kuid_t uid,kgid_t gid);
static int hook_path_chroot(struct path *path);
//static int hook_inode_alloc_security(struct inode *inode);
+//static void hook_inode_free_security(struct inode *inode);
static int hook_inode_init_security(struct inode *inode,struct inode *dir,const struct qstr *qstr,char **name,void **value,size_t *len);
static int hook_inode_create(struct inode *dir,struct dentry *dentry,umode_t mode);
static int hook_inode_link(struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry);
@@ -60,6 +66,7 @@ static int hook_inode_permission(struct inode *inode,int mask);
static int hook_inode_setattr(struct dentry *dentry,struct iattr *attr);
//static int hook_inode_getattr(struct vfsmount *mnt,struct dentry *dentry);
static int hook_inode_setxattr(struct dentry *dentry,const char *name,const void *value,size_t size,int flags);
+static void hook_inode_post_setxattr(struct dentry *dentry,const char *name,const void *value,size_t size,int flags);
static int hook_inode_getxattr(struct dentry *dentry,const char *name);
static int hook_inode_listxattr(struct dentry *dentry);
static int hook_inode_removexattr(struct dentry *dentry,const char *name);
@@ -68,8 +75,10 @@ static int hook_inode_killpriv(struct dentry *dentry);
static int hook_inode_getsecurity(const struct inode *inode,const char *name,void **buffer,bool alloc);
static int hook_inode_setsecurity(struct inode *inode,const char *name,const void *value,size_t size,int flags);
static int hook_inode_listsecurity(struct inode *inode,char *buffer,size_t buffer_size);
+static void hook_inode_getsecid(const struct inode *inode,u32 *secid);
static int hook_file_permission(struct file *file,int mask);
//static int hook_file_alloc_security(struct file *file);
+//static void hook_file_free_security(struct file *file);
static int hook_file_ioctl(struct file *file,unsigned int cmd,unsigned long arg);
//static int hook_mmap_addr(unsigned long addr);
//static int hook_mmap_file(struct file *file,unsigned long reqprot,unsigned long prot,unsigned long flags);
@@ -81,8 +90,11 @@ static int hook_file_send_sigiotask(struct task_struct *tsk,struct fown_struct *
static int hook_file_receive(struct file *file);
static int hook_file_open(struct file *file,const struct cred *cred);
static int hook_task_create(unsigned long clone_flags);
+//static void hook_task_free(struct task_struct *task);
static int hook_cred_alloc_blank(struct cred *cred,gfp_t gfp);
+//static void hook_cred_free(struct cred *cred);
//static int hook_cred_prepare(struct cred *new,const struct cred *old,gfp_t gfp);
+static void hook_cred_transfer(struct cred *new,const struct cred *old);
static int hook_kernel_act_as(struct cred *new,u32 secid);
static int hook_kernel_create_files_as(struct cred *new,struct inode *inode);
static int hook_kernel_module_request(char *kmod_name);
@@ -90,6 +102,7 @@ static int hook_task_fix_setuid(struct cred *new,const struct cred *old,int flag
static int hook_task_setpgid(struct task_struct *p,pid_t pgid);
static int hook_task_getpgid(struct task_struct *p);
static int hook_task_getsid(struct task_struct *p);
+static void hook_task_getsecid(struct task_struct *p,u32 *secid);
static int hook_task_setnice(struct task_struct *p,int nice);
static int hook_task_setioprio(struct task_struct *p,int ioprio);
static int hook_task_getioprio(struct task_struct *p);
@@ -97,29 +110,37 @@ static int hook_task_setrlimit(struct task_struct *p,unsigned int resource,struc
static int hook_task_setscheduler(struct task_struct *p);
static int hook_task_getscheduler(struct task_struct *p);
static int hook_task_movememory(struct task_struct *p);
-static int hook_task_kill(struct task_struct *p,struct siginfo *info,int sig,u32 secid);
+static int hook_task_kill(struct task_struct *p,struct siginfo *siginfo,int sig,u32 secid);
static int hook_task_wait(struct task_struct *p);
static int hook_task_prctl(int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5);
+static void hook_task_to_inode(struct task_struct *p,struct inode *inode);
static int hook_ipc_permission(struct kern_ipc_perm *ipcp,short flag);
+static void hook_ipc_getsecid(struct kern_ipc_perm *ipcp,u32 *secid);
static int hook_msg_msg_alloc_security(struct msg_msg *msg);
+static void hook_msg_msg_free_security(struct msg_msg *msg);
static int hook_msg_queue_alloc_security(struct msg_queue *msq);
+static void hook_msg_queue_free_security(struct msg_queue *msq);
static int hook_msg_queue_associate(struct msg_queue *msq,int msqflg);
static int hook_msg_queue_msgctl(struct msg_queue *msq,int cmd);
static int hook_msg_queue_msgsnd(struct msg_queue *msq,struct msg_msg *msg,int msqflg);
static int hook_msg_queue_msgrcv(struct msg_queue *msq,struct msg_msg *msg,struct task_struct *target,long type,int mode);
static int hook_shm_alloc_security(struct shmid_kernel *shp);
+static void hook_shm_free_security(struct shmid_kernel *shp);
static int hook_shm_associate(struct shmid_kernel *shp,int shmflg);
static int hook_shm_shmctl(struct shmid_kernel *shp,int cmd);
static int hook_shm_shmat(struct shmid_kernel *shp,char __user *shmaddr,int shmflg);
static int hook_sem_alloc_security(struct sem_array *sma);
+static void hook_sem_free_security(struct sem_array *sma);
static int hook_sem_associate(struct sem_array *sma,int semflg);
static int hook_sem_semctl(struct sem_array *sma,int cmd);
static int hook_sem_semop(struct sem_array *sma,struct sembuf *sops,unsigned nsops,int alter);
static int hook_netlink_send(struct sock *sk,struct sk_buff *skb);
+static void hook_d_instantiate(struct dentry *dentry,struct inode *inode);
static int hook_getprocattr(struct task_struct *p,char *name,char **value);
static int hook_setprocattr(struct task_struct *p,char *name,void *value,size_t size);
static int hook_secid_to_secctx(u32 secid,char **secdata,u32 *seclen);
static int hook_secctx_to_secid(const char *secdata,u32 seclen,u32 *secid);
+static void hook_release_secctx(char *secdata,u32 seclen);
static int hook_inode_notifysecctx(struct inode *inode,void *ctx,u32 ctxlen);
static int hook_inode_setsecctx(struct dentry *dentry,void *ctx,u32 ctxlen);
static int hook_inode_getsecctx(struct inode *inode,void **ctx,u32 *ctxlen);
@@ -142,13 +163,35 @@ static int hook_socket_sock_rcv_skb(struct sock *sk,struct sk_buff *skb);
static int hook_socket_getpeersec_stream(struct socket *sock,char __user *optval,int __user *optlen,unsigned len);
static int hook_socket_getpeersec_dgram(struct socket *sock,struct sk_buff *skb,u32 *secid);
static int hook_sk_alloc_security(struct sock *sk,int family,gfp_t priority);
+static void hook_sk_free_security(struct sock *sk);
+static void hook_sk_clone_security(const struct sock *sk,struct sock *newsk);
+static void hook_sk_getsecid(struct sock *sk,u32 *secid);
+static void hook_sock_graft(struct sock *sk,struct socket *parent);
static int hook_inet_conn_request(struct sock *sk,struct sk_buff *skb,struct request_sock *req);
+static void hook_inet_csk_clone(struct sock *newsk,const struct request_sock *req);
+static void hook_inet_conn_established(struct sock *sk,struct sk_buff *skb);
static int hook_secmark_relabel_packet(u32 secid);
+static void hook_secmark_refcount_inc(void);
+static void hook_secmark_refcount_dec(void);
+static void hook_req_classify_flow(const struct request_sock *req,struct flowi *fl);
static int hook_tun_dev_create(void);
+static void hook_tun_dev_post_create(struct sock *sk);
static int hook_tun_dev_attach(struct sock *sk);
+/*static int hook_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp,struct xfrm_user_sec_ctx *sec_ctx);
+static int hook_xfrm_policy_clone_security(struct xfrm_sec_ctx *old_ctx,struct xfrm_sec_ctx **new_ctx);
+static void hook_xfrm_policy_free_security(struct xfrm_sec_ctx *ctx);
+static int hook_xfrm_policy_delete_security(struct xfrm_sec_ctx *ctx);
+static int hook_xfrm_state_alloc_security(struct xfrm_state *x,struct xfrm_user_sec_ctx *sec_ctx,u32 secid);
+static void hook_xfrm_state_free_security(struct xfrm_state *x);
+static int hook_xfrm_state_delete_security(struct xfrm_state *x);
+static int hook_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx,u32 fl_secid,u8 dir);
+static int hook_xfrm_state_pol_flow_match(struct xfrm_state *x,struct xfrm_policy *xp,const struct flowi *fl);
+static int hook_xfrm_decode_session(struct sk_buff *skb,u32 *secid,int ckall);*/
static int hook_key_alloc(struct key *key,const struct cred *cred,unsigned long flags);
+static void hook_key_free(struct key *key);
static int hook_key_permission(key_ref_t key_ref,const struct cred *cred,key_perm_t perm);
static int hook_key_getsecurity(struct key *key,char **_buffer);
static int hook_audit_rule_init(u32 field,u32 op,char *rulestr,void **lsmrule);
static int hook_audit_rule_known(struct audit_krule *krule);
static int hook_audit_rule_match(u32 secid,u32 field,u32 op,void *lsmrule,struct audit_context *actx);
+static void hook_audit_rule_free(void *lsmrule);
diff --git a/judge/judgm_syscall.c b/toj/center/src/judgk_syscall.c
index 155e13e..370a3fe 100644..100755
--- a/judge/judgm_syscall.c
+++ b/toj/center/src/judgk_syscall.c
@@ -1,17 +1,17 @@
#include<linux/fs.h>
-#include<linux/sched.h>
#include<linux/slab.h>
+#include<linux/sched.h>
#include<linux/sort.h>
#include<asm/msr.h>
#include<asm/unistd.h>
#include<asm/uaccess.h>
#include"judge_def.h"
-#include"judgm.h"
-#include"judgx_com.h"
-#include"judgm_syscall.h"
+#include"judgk.h"
+#include"judgk_com.h"
+#include"judgk_syscall.h"
-int judgm_syscall_hook(){
+int judgk_syscall_hook(){
int i;
int j;
@@ -38,7 +38,7 @@ int judgm_syscall_hook(){
return 0;
}
-int judgm_syscall_unhook(){
+int judgk_syscall_unhook(){
int i;
unsigned int size;
@@ -52,11 +52,11 @@ int judgm_syscall_unhook(){
}
size -= sizeof(unsigned long);
- syscall_table[i] = (unsigned long)judgm_syscall_ori_table[i];
+ syscall_table[i] = (unsigned long)judgk_syscall_ori_table[i];
}
syscall_addr_restore((unsigned long)(&syscall_table[i - 1]),restore);
- schedule_timeout_interruptible(3 * HZ);
+ kfree(judgk_syscall_ori_table);
return 0;
}
static int syscall_init_hook(){
@@ -143,8 +143,8 @@ static int syscall_init_hook(){
}
syscall_max = *(unsigned int*)addr;
- judgm_syscall_ori_table = kmalloc(sizeof(unsigned long) * (syscall_max + 1),GFP_KERNEL);
- memcpy(judgm_syscall_ori_table,syscall_table,sizeof(unsigned long) * syscall_max);
+ judgk_syscall_ori_table = kmalloc(sizeof(unsigned long) * (syscall_max + 1),GFP_KERNEL);
+ memcpy(judgk_syscall_ori_table,syscall_table,sizeof(unsigned long) * syscall_max);
sort(syscall_whitelist,SYSCALL_WHITELIST_SIZE,sizeof(unsigned int),syscall_whitelist_cmp,NULL);
@@ -176,7 +176,7 @@ static int syscall_addr_write(unsigned long addr,unsigned int *size,int *restore
*size = 4096;
break;
case PG_LEVEL_2M:
- *size = 2097152 ;
+ *size = 2097152;
break;
case PG_LEVEL_1G:
*size = 1073741824;
@@ -198,16 +198,16 @@ static int syscall_addr_restore(unsigned long addr,int restore){
return 0;
}
-int judgm_syscall_check(){
- if(judgm_proc_task_lookup(current)){
+int judgk_syscall_check(){
+ if(judgk_proc_task_lookup(current)){
return 1;
}
return 0;
}
-int judgm_syscall_block(){
- struct judgm_proc_info *info;
+int judgk_syscall_block(){
+ struct judgk_proc_info *info;
- if((info = judgm_proc_task_lookup(current)) == NULL){
+ if((info = judgk_proc_task_lookup(current)) == NULL){
return 0;
}
diff --git a/judge/judgm_syscall.h b/toj/center/src/judgk_syscall.h
index b586b0c..2ee6afb 100644..100755
--- a/judge/judgm_syscall.h
+++ b/toj/center/src/judgk_syscall.h
@@ -55,14 +55,14 @@ static unsigned int syscall_whitelist[SYSCALL_WHITELIST_SIZE] = {
__NR_dup3
};
-int judgm_syscall_hook(void);
-int judgm_syscall_unhook(void);
-int judgm_syscall_check(void);
-int judgm_syscall_block(void);
+int judgk_syscall_hook(void);
+int judgk_syscall_unhook(void);
+int judgk_syscall_check(void);
+int judgk_syscall_block(void);
-unsigned long *judgm_syscall_ori_table;
+unsigned long *judgk_syscall_ori_table;
-extern struct judgm_proc_info* judgm_proc_task_lookup(struct task_struct *task);
+extern struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task);
extern long hook_sys_block(void);
//typedef asmlinkage long (*func_sys_nanosleep)(struct timespec __user *rqtp,struct timespec __user *rmtp);
diff --git a/judge/judgm_syscall_asm.S b/toj/center/src/judgk_syscall_asm.S
index df4a1f3..dfc5bc6 100644..100755
--- a/judge/judgm_syscall_asm.S
+++ b/toj/center/src/judgk_syscall_asm.S
@@ -21,7 +21,7 @@ hook_sys_block:
push %r14
push %r15
- call judgm_syscall_check
+ call judgk_syscall_check
test %eax,%eax
pop %r15
@@ -46,9 +46,9 @@ hook_sys_block:
mov $8,%rdx
mul %rdx
pop %rdx
- add judgm_syscall_ori_table,%rax
+ add judgk_syscall_ori_table,%rax
jmp *(%rax)
block:
- call judgm_syscall_block
+ call judgk_syscall_block
mov $-1,%rax
ret
diff --git a/toj/center/src/judgm_lib.h b/toj/center/src/judgm_lib.h
new file mode 100644
index 0000000..324147e
--- /dev/null
+++ b/toj/center/src/judgm_lib.h
@@ -0,0 +1,369 @@
+#include<string.h>
+#include<limits.h>
+#include<unistd.h>
+#include<signal.h>
+#include<limits.h>
+#include<errno.h>
+#include<pthread.h>
+#include<semaphore.h>
+#include<fcntl.h>
+#include<sys/ioctl.h>
+#include<sys/resource.h>
+#include<sys/stat.h>
+#include<sys/types.h>
+#include<sys/wait.h>
+#include<sys/mman.h>
+#include<map>
+#include<utility>
+
+#include"judgk_com.h"
+
+typedef int (*judgm_proc_check_fn)();
+
+class judgm_proc{
+private:
+ int init(){
+ int i;
+ int j;
+ struct stat st;
+
+ if(stat(exe_path,&st)){
+ return -1;
+ }
+ if(!S_ISREG(st.st_mode)){
+ return -1;
+ }
+
+ exe_name[NAME_MAX] = '\0';
+ for(i = 0,j = 0;exe_path[i] != '\0' && j < NAME_MAX;i++){
+ if(exe_path[i] == '/'){
+ j = 0;
+ }else{
+ exe_name[j] = exe_path[i];
+ j++;
+ }
+ }
+ exe_name[j] = '\0';
+
+ pid = 0;
+ kern_task = 0;
+ status = JUDGE_WAIT;
+ runtime = 0;
+ memory = 0;
+
+ return 0;
+ }
+ int protect(){
+ rlimit limit;
+ judgk_com_proc_add com_proc_add;
+
+ limit.rlim_cur = 1;
+ limit.rlim_max = limit.rlim_cur;
+ prlimit(pid,RLIMIT_NPROC,&limit,NULL);
+
+ limit.rlim_cur = 8L;
+ limit.rlim_max = limit.rlim_cur;
+ prlimit(pid,RLIMIT_NOFILE,&limit,NULL);
+
+ com_proc_add.run_path[0] = '\0';
+ strncat(com_proc_add.run_path,run_path,sizeof(com_proc_add.run_path));
+ com_proc_add.pid = pid;
+ com_proc_add.timelimit = timelimit * 1000L;
+ com_proc_add.hardtimelimit = hardtimelimit * 1000L;
+ com_proc_add.memlimit = memlimit * 1024L + 4096L * 128L;
+ if(ioctl(judgk_modfd,IOCTL_PROC_ADD,&com_proc_add)){
+ return -1;
+ }
+ kern_task = com_proc_add.kern_task;
+
+ return 0;
+ }
+
+public:
+ int judgk_modfd;
+ char run_path[PATH_MAX + 1];
+ char exe_path[PATH_MAX + 1];
+ char exe_name[NAME_MAX + 1];
+ unsigned long timelimit;
+ unsigned long hardtimelimit;
+ unsigned long memlimit;
+ judgm_proc_check_fn check_fn;
+
+ pid_t pid;
+ unsigned long kern_task;
+ int status;
+ unsigned long runtime;
+ unsigned long memory;
+
+ judgm_proc(int judgk_modfd,char *runpath,char *exe_path,unsigned long timelimit,unsigned long hardtimelimit,unsigned long memlimit,judgm_proc_check_fn check_fn){
+ this->judgk_modfd = judgk_modfd;
+ this->run_path[0] = '\0';
+ strncat(this->run_path,runpath,sizeof(this->run_path));
+ this->exe_path[0] = '\0';
+ strncat(this->exe_path,exe_path,sizeof(this->exe_path));
+
+ this->timelimit = timelimit;
+ this->hardtimelimit = hardtimelimit;
+ this->memlimit = memlimit;
+ this->check_fn = check_fn;
+ }
+
+ int proc_run(){
+ char abspath[PATH_MAX + 1];
+
+ if(init()){
+ return -1;
+ }
+
+ realpath(exe_path,abspath);
+ if((pid = fork()) == 0){
+ char *argv[] = {NULL,NULL};
+ char *envp[] = {NULL};
+
+ chdir(run_path);
+ check_fn();
+
+ setgid(99);
+ setuid(99);
+ kill(getpid(),SIGSTOP);
+
+ argv[0] = exe_name;
+ execve(abspath,argv,envp);
+ exit(0);
+ }
+
+ if(pid == -1){
+ return -1;
+ }
+ waitpid(pid,NULL,WUNTRACED);
+
+ if(protect()){
+ kill(pid,SIGKILL);
+ return -1;
+ }
+ status = JUDGE_RUN;
+ kill(pid,SIGCONT);
+
+ return 0;
+ }
+ int proc_wait(bool blockflag){
+ int wstatus;
+ struct judgk_com_proc_get com_proc_get;
+
+ if(blockflag == true){
+ if(waitpid(pid,&wstatus,WUNTRACED) == -1){
+ return -1;
+ }
+ }else{
+ if(waitpid(pid,&wstatus,WUNTRACED | WNOHANG) <= 0){
+ return -1;
+ }
+ }
+
+ com_proc_get.kern_task = kern_task;
+ if(ioctl(judgk_modfd,IOCTL_PROC_GET,&com_proc_get)){
+ return -1;
+ }
+
+ runtime = com_proc_get.runtime / 1000L;
+ memory = com_proc_get.memory;
+
+ printf("runtime:%lu memory:%lu\n",runtime,memory);
+
+ if(com_proc_get.status != JUDGE_AC){
+ status = com_proc_get.status;
+ }else if(memory > (memlimit * 1024L)){
+ status = JUDGE_MLE;
+ }else if(runtime > timelimit){
+ status = JUDGE_TLE;
+ }else if(WIFEXITED(wstatus) || (WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGKILL)){
+ status = JUDGE_AC;
+ }else{
+ status = JUDGE_RE;
+ }
+
+ return 0;
+ }
+ int proc_kill(){
+ if(kill(pid,SIGKILL)){
+ return -1;
+ }
+ return 0;
+ }
+};
+
+class judgm_hyperio{
+private:
+ int judgk_modfd;
+ char *read_buf;
+ off_t read_off;
+
+public:
+ int tty_idx;
+
+ judgm_hyperio(int judgk_modfd){
+ this->judgk_modfd = judgk_modfd;
+ this->tty_idx = ioctl(this->judgk_modfd,IOCTL_HYPERIO_ADD,0);
+ this->read_buf = (char*)mmap(NULL,JUDGK_COM_HYPERIO_BUFSIZE,PROT_READ,MAP_SHARED,judgk_modfd,0);
+ this->read_off = 0;
+ }
+ ~judgm_hyperio(){
+ munmap(read_buf,JUDGK_COM_HYPERIO_BUFSIZE);
+ ioctl(judgk_modfd,IOCTL_HYPERIO_DEL,0);
+ }
+
+ static int get_ttyfd(int idx){
+ char tpath[PATH_MAX + 1];
+
+ snprintf(tpath,sizeof(tpath),"/dev/jtty%d",idx);
+ return open(tpath,O_RDWR);
+ }
+ size_t wait(){
+ return ioctl(judgk_modfd,IOCTL_HYPERIO_READ,0);
+ }
+ int compare(char *buf,size_t len){
+ int flag;
+ size_t remain;
+ off_t off;
+ size_t data_len;
+ size_t cmp_len;
+
+ flag = 0;
+ remain = len;
+ off = 0;
+ data_len = 0;
+ cmp_len = 0;
+ while(remain > 0 && flag == 0){
+ if(data_len == 0){
+ if((data_len = ioctl(judgk_modfd,IOCTL_HYPERIO_READ,cmp_len)) <= 0){
+ return -1;
+ }
+ }
+ if(remain < data_len){
+ cmp_len = remain;
+ }else{
+ cmp_len = data_len;
+ }
+
+ if((cmp_len + read_off) < JUDGK_COM_HYPERIO_BUFSIZE){
+ flag |= memcmp(read_buf + read_off,buf + off,cmp_len);
+ read_off += cmp_len;
+ }else{
+ flag |= memcmp(read_buf + read_off,buf + off,JUDGK_COM_HYPERIO_BUFSIZE - read_off);
+ flag |= memcmp(read_buf,buf + off + (JUDGK_COM_HYPERIO_BUFSIZE - read_off),(cmp_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE);
+ read_off = (cmp_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE;
+ }
+ remain -= cmp_len;
+ off += cmp_len;
+ data_len -= cmp_len;
+ }
+ if(cmp_len > 0){
+ ioctl(judgk_modfd,IOCTL_HYPERIO_READ,-(long)cmp_len);
+ }
+
+ if(flag == 0){
+ return 0;
+ }else{
+ return -1;
+ }
+ }
+};
+
+static int judgm_compile(int subid,char *code_path,char *exe_path,int lang,bool force_flag,char *errmsg,size_t errsize){
+ int ret;
+ int i;
+
+ char main_path[PATH_MAX + 1];
+ char sem_path[PATH_MAX + 1];
+ struct stat st;
+ sem_t *wait_sem;
+ bool ce_flag;
+ char dir_path[PATH_MAX + 1];
+ char *out_path;
+ int io[2];
+ int pid;
+ int wstatus;
+ off_t off;
+
+ if(force_flag == false){
+ snprintf(main_path,sizeof(main_path),"tmp/exe/%d/main",subid);
+ snprintf(sem_path,sizeof(sem_path),"/judgm_compile_wait_%d",subid);
+ if((wait_sem = sem_open(sem_path,0)) == SEM_FAILED){
+ if(stat(main_path,&st)){
+ if((wait_sem = sem_open(sem_path,O_CREAT | O_EXCL,0644,0)) != SEM_FAILED){
+ out_path = main_path;
+ goto compile;
+ }else if((wait_sem = sem_open(sem_path,0)) != SEM_FAILED){
+
+ sem_wait(wait_sem);
+
+ sem_close(wait_sem);
+ }
+ }
+ }else{
+
+ sem_wait(wait_sem);
+
+ sem_close(wait_sem);
+ }
+
+ if(!link(main_path,exe_path)){
+ return 0;
+ }
+ }
+
+ force_flag = true;
+ out_path = exe_path;
+
+compile:
+
+ if(force_flag == false){
+ snprintf(dir_path,sizeof(dir_path),"tmp/exe/%d",subid);
+ mkdir(dir_path,0755);
+ }
+ ce_flag = false;
+
+ if(lang == JUDGE_CPP){
+ pipe(io);
+
+ if((pid = fork()) == 0){
+ char *argv[] = {"g++","-static","-O2",code_path,"-std=c++0x","-o",out_path,NULL};
+
+ dup2(io[1],1);
+ dup2(io[1],2);
+ execvp("g++",argv);
+ }
+
+ close(io[1]);
+ off = 0;
+ while((ret = read(io[0],errmsg + off,errsize - off - 1)) > 0){
+ off += ret;
+ }
+ errmsg[off] = '\0';
+ close(io[0]);
+
+ waitpid(pid,&wstatus,0);
+ if(wstatus != 0){
+ ce_flag = true;
+ }
+ }
+
+ if(force_flag == false){
+ if(ce_flag == true){
+ rmdir(dir_path);
+ }
+
+ for(i = 0;i < 8;i++){
+ sem_post(wait_sem);
+ }
+ sem_close(wait_sem);
+ sem_unlink(sem_path);
+ }
+ if(ce_flag == true){
+ return -1;
+ }
+
+ link(main_path,exe_path);
+
+ return 0;
+}
diff --git a/toj/center/src/judgm_line.h b/toj/center/src/judgm_line.h
new file mode 100755
index 0000000..1b36c74
--- /dev/null
+++ b/toj/center/src/judgm_line.h
@@ -0,0 +1,19 @@
+struct judgm_line_info{
+ int subid;
+
+ char *pro_path;
+ char *code_path;
+ char *run_path;
+
+ int judgk_modfd;
+ void *line_dll;
+ void *check_dll;
+
+ int lang;
+ FILE *set_file;
+ char *set_data;
+
+ char res_data[JUDGE_RES_DATAMAX];
+ size_t res_len;
+};
+typedef int (*judgm_line_run_fn)(judgm_line_info *info);
diff --git a/toj/center/src/judgm_manage.h b/toj/center/src/judgm_manage.h
new file mode 100644
index 0000000..85385e7
--- /dev/null
+++ b/toj/center/src/judgm_manage.h
@@ -0,0 +1,27 @@
+typedef int (*judgm_manage_queuesubmit_fn)(int subid,int proid,int lang,char *set_data,size_t set_len);
+
+struct judgm_manage_submitinfo{
+ int subid;
+ int uid;
+ int proid;
+ int lang;
+ char *param;
+
+ char pro_path[PATH_MAX + 1];
+ FILE *set_file;
+};
+typedef int (*judgm_manage_submit_fn)(judgm_manage_submitinfo *info,void **manage_data);
+
+struct judgm_manage_resultinfo{
+ int subid;
+ int uid;
+ int proid;
+ char *res_path;
+ char *res_data;
+
+ int result;
+ double score;
+ unsigned long runtime;
+ unsigned long memory;
+};
+typedef int (*judgm_manage_result_fn)(judgm_manage_resultinfo *info,void *manage_data);
diff --git a/toj/center/src/netio.h b/toj/center/src/netio.h
new file mode 100644
index 0000000..db54b23
--- /dev/null
+++ b/toj/center/src/netio.h
@@ -0,0 +1,192 @@
+class netio_protoiofn{
+public:
+ virtual void operator()(void *buf,size_t len,void *data) = 0;
+};
+
+template<typename C>
+class netio_iofn : public netio_protoiofn{
+private:
+ typedef void (C::*netio_iofn_type)(void *buf,size_t len,void *data);
+ C *obj;
+ netio_iofn_type fn;
+
+public:
+ netio_iofn(C *obj,netio_iofn_type fn){
+ this->obj = obj;
+ this->fn = fn;
+ }
+ void operator()(void *buf,size_t len,void *data){
+ (obj->*fn)(buf,len,data);
+ }
+};
+
+#define NETIO_IOTYPE_PLAIN 0
+#define NETIO_IOTYPE_FILE 1
+class netio_iocb{
+public:
+ int type;
+
+ void *buf;
+ int fd;
+ off_t off;
+ size_t len;
+ netio_protoiofn *cb_fn;
+ void *cb_data;
+
+ netio_iocb(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){
+ this->type = NETIO_IOTYPE_PLAIN;
+ this->buf = buf;
+ this->off = 0;
+ this->len = len;
+ this->cb_fn = cb_fn;
+ this->cb_data = cb_data;
+ }
+ netio_iocb(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){
+ this->type = NETIO_IOTYPE_FILE;
+ this->buf = &this->fd;
+ this->fd = fd;
+ this->off = 0;
+ this->len = len;
+ this->cb_fn = cb_fn;
+ this->cb_data = cb_data;
+ }
+};
+
+#define NETIO_IOSIZE 65536
+class netio{
+private:
+ netio_iocb *read_iocb;
+ std::queue<netio_iocb*> write_queue;
+ bool readio_reen;
+ char readio_buf[NETIO_IOSIZE];
+
+public:
+ int fd;
+ virtual int readidle() = 0;
+
+ netio(int fd){
+ this->fd = fd;
+ this->read_iocb = NULL;
+ this->readio_reen = false;
+ }
+ ~netio(){
+ close(this->fd);
+ }
+ int readio(){
+ int ret;
+ size_t len;
+ netio_iocb *iocb;
+
+ if(readio_reen == true){
+ return -1;
+ }
+ readio_reen = true;
+
+ while(true){
+ if(read_iocb == NULL){
+ readidle();
+ }
+
+ iocb = read_iocb;
+ if(iocb->type == NETIO_IOTYPE_PLAIN){
+ while((ret = read(fd,(char*)iocb->buf + iocb->off,iocb->len - iocb->off)) > 0){
+ iocb->off += ret;
+ }
+ }else if(iocb->type == NETIO_IOTYPE_FILE){
+ while(true){
+ len = iocb->len - iocb->off;
+ if(len >= NETIO_IOSIZE){
+ len = NETIO_IOSIZE;
+ }
+ if((ret = read(fd,readio_buf,len)) <= 0){
+ break;
+ }
+
+ write(iocb->fd,readio_buf,ret);
+ iocb->off += ret;
+ }
+ }
+ if(iocb->off == iocb->len){
+ read_iocb = NULL;
+
+ if(iocb->cb_fn != NULL){
+ (*iocb->cb_fn)(iocb->buf,iocb->len,iocb->cb_data);
+ }else{
+ if(iocb->type == NETIO_IOTYPE_PLAIN){
+ delete (char*)iocb->buf;
+ }else if(iocb->type == NETIO_IOTYPE_FILE){
+ close(iocb->fd);
+ }
+ }
+
+ delete iocb;
+ }else{
+ break;
+ }
+ }
+
+ readio_reen = false;
+ return 0;
+ }
+ int readbytes(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){
+ read_iocb = new netio_iocb(buf,len,cb_fn,cb_data);
+ readio();
+ return 0;
+ }
+ int readfile(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){
+ read_iocb = new netio_iocb(fd,len,cb_fn,cb_data);
+ readio();
+ return 0;
+ }
+ int writeio(){
+ int ret;
+ size_t len;
+ netio_iocb *iocb;
+
+ while(!write_queue.empty()){
+ iocb = write_queue.front();
+ if(iocb->type == NETIO_IOTYPE_PLAIN){
+ while((ret = write(fd,(char*)iocb->buf + iocb->off,iocb->len - iocb->off)) > 0){
+ iocb->off += ret;
+ }
+ }else if(iocb->type == NETIO_IOTYPE_FILE){
+ len = iocb->len - iocb->off;
+ if(len >= NETIO_IOSIZE){
+ len = NETIO_IOSIZE;
+ }
+ while((ret = sendfile(fd,iocb->fd,NULL,len)) > 0){
+ iocb->off += ret;
+ }
+ }
+ if(iocb->off == iocb->len){
+ write_queue.pop();
+
+ if(iocb->cb_fn != NULL){
+ (*iocb->cb_fn)(iocb->buf,iocb->len,iocb->cb_data);
+ }else{
+ if(iocb->type == NETIO_IOTYPE_PLAIN){
+ delete (char*)iocb->buf;
+ }else if(iocb->type == NETIO_IOTYPE_FILE){
+ close(iocb->fd);
+ }
+ }
+
+ delete iocb;
+ }else{
+ break;
+ }
+ }
+
+ return 0;
+ }
+ int writebytes(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){
+ write_queue.push(new netio_iocb(buf,len,cb_fn,cb_data));
+ writeio();
+ return 0;
+ }
+ int writefile(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){
+ write_queue.push(new netio_iocb(fd,len,cb_fn,cb_data));
+ writeio();
+ return 0;
+ }
+};
diff --git a/toj/center/src/pack.cpp b/toj/center/src/pack.cpp
new file mode 100644
index 0000000..c2206b1
--- /dev/null
+++ b/toj/center/src/pack.cpp
@@ -0,0 +1,175 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+#include<fcntl.h>
+#include<libtar.h>
+#include<bzlib.h>
+#include<map>
+
+#include"pack.h"
+
+static int pack_copenfn(const char *pathname,int flags,...){
+ int fd;
+ pack_bzinfo *bzinfo;
+
+ if((fd = open(pathname,flags,0644)) == -1){
+ return -1;
+ }
+
+ bzinfo = new pack_bzinfo;
+ bzinfo->len = 0;
+ bzinfo->off = 0;
+ bzinfo->endflag = false;
+ bzinfo->bzs.bzalloc = NULL;
+ bzinfo->bzs.bzfree = NULL;
+ bzinfo->bzs.opaque = NULL;
+ BZ2_bzCompressInit(&bzinfo->bzs,9,0,0);
+
+ pack_fdmap.insert(std::pair<int,pack_bzinfo*>(fd,bzinfo));
+
+ return fd;
+}
+static int pack_cclosefn(long fd){
+ int ret;
+ pack_bzinfo *bzinfo;
+
+ bzinfo = pack_fdmap.find(fd)->second;
+ pack_fdmap.erase(fd);
+
+ bzinfo->bzs.next_in = NULL;
+ bzinfo->bzs.avail_in = 0;
+ while(true){
+ bzinfo->bzs.next_out = bzinfo->buf;
+ bzinfo->bzs.avail_out = PACK_BUFSIZE;
+ ret = BZ2_bzCompress(&bzinfo->bzs,BZ_FINISH);
+
+ if(bzinfo->bzs.avail_out != PACK_BUFSIZE){
+ write(fd,bzinfo->buf,PACK_BUFSIZE - bzinfo->bzs.avail_out);
+ }
+ if(ret == BZ_STREAM_END){
+ break;
+ }
+ }
+
+ BZ2_bzCompressEnd(&bzinfo->bzs);
+ delete bzinfo;
+ return close(fd);
+}
+static ssize_t pack_cwritefn(long fd,const void *buf,size_t count){
+ pack_bzinfo *bzinfo;
+
+ bzinfo = pack_fdmap.find(fd)->second;
+
+ bzinfo->bzs.next_in = (char*)buf;
+ bzinfo->bzs.avail_in = count;
+ while(bzinfo->bzs.avail_in > 0){
+ bzinfo->bzs.next_out = bzinfo->buf;
+ bzinfo->bzs.avail_out = PACK_BUFSIZE;
+ BZ2_bzCompress(&bzinfo->bzs,BZ_RUN);
+ if(bzinfo->bzs.avail_out != PACK_BUFSIZE){
+ write(fd,bzinfo->buf,PACK_BUFSIZE - bzinfo->bzs.avail_out);
+ }
+ }
+
+ return count;
+}
+static int pack_xopenfn(const char *pathname,int flags,...){
+ int fd;
+ pack_bzinfo *bzinfo;
+
+ if((fd = open(pathname,flags)) == -1){
+ return -1;
+ }
+
+ bzinfo = new pack_bzinfo;
+ bzinfo->len = 0;
+ bzinfo->off = 0;
+ bzinfo->endflag = false;
+ bzinfo->bzs.bzalloc = NULL;
+ bzinfo->bzs.bzfree = NULL;
+ bzinfo->bzs.opaque = NULL;
+ BZ2_bzDecompressInit(&bzinfo->bzs,0,0);
+
+ pack_fdmap.insert(std::pair<int,pack_bzinfo*>(fd,bzinfo));
+
+ return fd;
+}
+static int pack_xclosefn(long fd){
+ int ret;
+ pack_bzinfo *bzinfo;
+
+ bzinfo = pack_fdmap.find(fd)->second;
+ pack_fdmap.erase(fd);
+ BZ2_bzDecompressEnd(&bzinfo->bzs);
+ delete bzinfo;
+
+ return close(fd);
+}
+static ssize_t pack_xreadfn(long fd,void *buf,size_t count){
+ int ret;
+ pack_bzinfo *bzinfo;
+
+ bzinfo = pack_fdmap.find(fd)->second;
+
+ bzinfo->bzs.next_out = (char*)buf;
+ bzinfo->bzs.avail_out = count;
+ while(bzinfo->endflag == false){
+ if(bzinfo->len == 0){
+ ret = read(fd,bzinfo->buf,PACK_BUFSIZE);
+ bzinfo->len = ret;
+ bzinfo->off = 0;
+ }
+ if(bzinfo->len == 0){
+ break;
+ }
+
+ bzinfo->bzs.next_in = bzinfo->buf + bzinfo->off;
+ bzinfo->bzs.avail_in = bzinfo->len;
+ while(bzinfo->bzs.avail_in > 0 && bzinfo->bzs.avail_out > 0){
+ if(BZ2_bzDecompress(&bzinfo->bzs) != BZ_OK){
+ bzinfo->endflag = true;
+ break;
+ }
+ }
+ bzinfo->off += bzinfo->len - bzinfo->bzs.avail_in;
+ bzinfo->len = bzinfo->bzs.avail_in;
+
+ if(bzinfo->bzs.avail_out == 0){
+ break;
+ }
+ }
+
+ return count - bzinfo->bzs.avail_out;
+}
+
+int pack_pack(char *packpath,char *dirpath){
+ tartype_t tartype;
+ TAR *tarp;
+
+ tartype.openfunc = pack_copenfn;
+ tartype.closefunc = pack_cclosefn;
+ tartype.readfunc = (readfunc_t)read;
+ tartype.writefunc = pack_cwritefn;
+ tar_open(&tarp,packpath,&tartype,O_WRONLY | O_CREAT,0644,TAR_GNU);
+
+ tar_append_tree(tarp,dirpath,".");
+ tar_close(tarp);
+
+ return 0;
+}
+int pack_unpack(char *packpath,char *dirpath){
+ tartype_t tartype;
+ TAR *tarp;
+
+ tartype.openfunc = pack_xopenfn;
+ tartype.closefunc = pack_xclosefn;
+ tartype.readfunc = pack_xreadfn;
+ tartype.writefunc = (writefunc_t)write;
+ tar_open(&tarp,packpath,&tartype,O_RDONLY,0644,TAR_GNU);
+
+ tar_extract_all(tarp,dirpath);
+ tar_close(tarp);
+
+ return 0;
+}
diff --git a/toj/center/src/pack.h b/toj/center/src/pack.h
new file mode 100644
index 0000000..8f8ac88
--- /dev/null
+++ b/toj/center/src/pack.h
@@ -0,0 +1,20 @@
+#define PACK_BUFSIZE 65536
+struct pack_bzinfo{
+ bz_stream bzs;
+ char buf[PACK_BUFSIZE];
+ int len;
+ int off;
+ bool endflag;
+};
+
+static int pack_copenfn(const char *pathname,int flags,...);
+static int pack_cclosefn(long fd);
+static ssize_t cpack_writefn(long fd,const void *buf,size_t count);
+static int pack_xopenfn(const char *pathname,int flags,...);
+static int pack_xclosefn(long fd);
+static ssize_t xpack_readfn(long fd,void *buf,size_t count);
+
+static std::map<int,pack_bzinfo*> pack_fdmap;
+
+int pack_pack(char *packpath,char *dirpath);
+int pack_unpack(char *packpath,char *dirpath);
diff --git a/toj/center/src/tpool.h b/toj/center/src/tpool.h
new file mode 100644
index 0000000..08aedbc
--- /dev/null
+++ b/toj/center/src/tpool.h
@@ -0,0 +1,169 @@
+class tpool_protofn{
+public:
+ virtual void operator()(void *data) = 0;
+};
+
+template<typename C>
+class tpool_fn : public tpool_protofn{
+private:
+ typedef void (C::*tpool_fn_type)(void *data);
+ C *obj;
+ tpool_fn_type fn;
+
+public:
+ tpool_fn(C *obj,tpool_fn_type fn){
+ this->obj = obj;
+ this->fn = fn;
+ }
+ void operator()(void *data){
+ (obj->*fn)(data);
+ }
+};
+class tpool_static_fn : public tpool_protofn{
+private:
+ typedef void (*tpool_static_fn_type)(void *data);
+ tpool_static_fn_type fn;
+
+public:
+ tpool_static_fn(tpool_static_fn_type fn){
+ this->fn = fn;
+ }
+ void operator()(void *data){
+ fn(data);
+ }
+};
+
+class tpool_thcb{
+public:
+ tpool_protofn *th_fn;
+ void *th_data;
+ tpool_protofn *cb_fn;
+ void *cb_data;
+
+ tpool_thcb(tpool_protofn *th_fn,void *th_data,tpool_protofn *cb_fn,void *cb_data){
+ this->th_fn = th_fn;
+ this->th_data = th_data;
+ this->cb_fn = cb_fn;
+ this->cb_data = cb_data;
+ }
+ int run(){
+ (*th_fn)(th_data);
+ return 0;
+ }
+ int done(){
+ if(cb_fn != NULL){
+ (*cb_fn)(cb_data);
+ }
+ return 0;
+ }
+};
+
+#define TPOOL_THREAD_MAXNUM 64
+class tpool{
+private:
+ std::queue<tpool_thcb*> wait_queue;
+ std::vector<tpool_thcb*> done_list;
+ pthread_t pt[TPOOL_THREAD_MAXNUM];
+ int pt_num;
+ sem_t pt_sem;
+ pthread_mutex_t pt_mutex;
+
+ static void* pt_runfn(void *arg){
+ tpool *that;
+ tpool_thcb *thcb;
+ long long int sig;
+
+ that = (tpool*)arg;
+
+ while(true){
+
+ sem_wait(&that->pt_sem);
+
+ pthread_mutex_lock(&that->pt_mutex);
+
+ if(!that->wait_queue.empty()){
+ thcb = that->wait_queue.front();
+ that->wait_queue.pop();
+ }else{
+ thcb = NULL;
+ }
+
+ pthread_mutex_unlock(&that->pt_mutex);
+
+ if(thcb == NULL){
+ continue;
+ }
+
+ thcb->run();
+
+ pthread_mutex_lock(&that->pt_mutex);
+
+ that->done_list.push_back(thcb);
+
+ pthread_mutex_unlock(&that->pt_mutex);
+
+ sig = 1;
+ write(that->fd,&sig,sizeof(sig)),that->done_list.size();
+ }
+ return NULL;
+ }
+
+public:
+ int fd;
+
+ tpool(int pt_num){
+ if((this->pt_num = pt_num) > TPOOL_THREAD_MAXNUM){
+ this->pt_num = TPOOL_THREAD_MAXNUM;
+ }
+ fd = eventfd(0,EFD_NONBLOCK);
+ sem_init(&pt_sem,0,0);
+ pthread_mutex_init(&pt_mutex,NULL);
+ }
+ ~tpool(){
+ close(fd);
+ sem_destroy(&pt_sem);
+ pthread_mutex_destroy(&pt_mutex);
+ }
+ int start(){
+ int i;
+
+ for(i = 0;i < pt_num;i++){
+ pthread_create(&pt[pt_num],NULL,pt_runfn,this);
+ }
+
+ return 0;
+ }
+ int done(){
+ int i;
+ std::vector<tpool_thcb*> l;
+ long long int sig;
+
+ pthread_mutex_lock(&pt_mutex);
+
+ l.swap(done_list);
+
+ pthread_mutex_unlock(&pt_mutex);
+
+ for(i = l.size() - 1;i >= 0;i--){
+ l[i]->done();
+ delete l[i];
+ }
+
+ read(fd,&sig,sizeof(sig));
+ }
+ int add(tpool_protofn *th_fn,void *th_data,tpool_protofn *cb_fn,void *cb_data){
+ tpool_thcb *thcb;
+
+ thcb = new tpool_thcb(th_fn,th_data,cb_fn,cb_data);
+
+ pthread_mutex_lock(&pt_mutex);
+
+ wait_queue.push(thcb);
+
+ pthread_mutex_unlock(&pt_mutex);
+
+ sem_post(&pt_sem);
+
+ return 0;
+ }
+};
diff --git a/toj/index.html b/toj/index.html
new file mode 100644
index 0000000..5126216
--- /dev/null
+++ b/toj/index.html
@@ -0,0 +1,303 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Taiwan Online Judge</title>
+
+<link href='http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'>
+
+<link rel="stylesheet" href="/codemirror.css">
+<link rel="stylesheet" href="/lesser-dark.css">
+
+<link rel="stylesheet" type="text/css" href="/toj/jcs/common.css">
+<link rel="stylesheet" type="text/css" href="/toj/jcs/index.css">
+<link rel="stylesheet" type="text/css" href="/toj/jcs/notice.css">
+<link rel="stylesheet" type="text/css" href="/toj/jcs/home.css">
+<link rel="stylesheet" type="text/css" href="/toj/jcs/stat.css">
+<link rel="stylesheet" type="text/css" href="/toj/jcs/user.css">
+<link rel="stylesheet" type="text/css" href="/toj/jcs/sq.css">
+<link rel="stylesheet" type="text/css" href="/toj/jcs/pro.css">
+
+<script src="/jquery-1.9.1.min.js"></script>
+<script src="/jquery.easing.1.3.js"></script>
+<script type="text/javascript" src="/codemirror.js"></script>
+<script type="text/javascript" src="/clike.js"></script>
+
+<script src="/toj/jcs/common.js"></script>
+<script src="/toj/jcs/index.js"></script>
+<script src="/toj/jcs/notice.js"></script>
+<script src="/toj/jcs/home.js"></script>
+<script src="/toj/jcs/stat.js"></script>
+<script src="/toj/jcs/user.js"></script>
+<script src="/toj/jcs/sq.js"></script>
+<script src="/toj/jcs/pro.js"></script>
+
+<style type="text/css">
+body{
+ color:#E9E9E9;
+ background-color:#373C38;
+ font-family:\5FAE\8EDF\6B63\9ED1\9AD4,\65B0\7D30\660E\9AD4;
+ overflow-y:hidden;
+}
+button{
+ height:32px;
+ margin:0px 0px;
+ padding:0px 16px 0px 16px;
+ font-size:16px;
+ font-family:\5FAE\8EDF\6B63\9ED1\9AD4,\65B0\7D30\660E\9AD4;
+ color:#E9E9E9;
+ background-color:#00896C;
+ border:none;
+ cursor:pointer;
+}
+button:hover{
+ background-color:#24936E;
+}
+</style>
+<script type="text/javascript">
+ $(document).ready(function(){
+ common.init();
+ user.init();
+ index.init();
+ notice.init();
+ home.init();
+ stat.init();
+ sq.init();
+ pro.init();
+
+ common.exheight();
+ $(window).resize(function(e){common.exheight();});
+ $(window).on('popstate',function(e){
+ if(location.href != common.url_curr){
+ common.url_prev = common.url_curr;
+ common.url_curr = location.href;
+ common.page_urlchange();
+ }
+ });
+
+ common.page_urlchange();
+ });
+</script>
+</head>
+<body>
+
+<div id="index_head" class="index_head">
+ <div class="title">Taiwan Online Judge</div>
+ <div class="tab_box"></div>
+ <div class="content_box"></div>
+ <div id="index_head_panel" class="panel">開始</div>
+ <div id="index_head_notice" class="notice" style="display:none">[0]</div>
+ <div id="index_head_nickname" class="nickname"><a class="nickname"></a></div>
+</div>
+
+<div id="index_panel_box" exheight=true class="index_panel_box"><ul id="index_panel" class="index_panel">
+ <li page="home" class="button"><a href="/toj/home/" class="button">首頁</a></li>
+ <li page="stat" class="button"><a href="/toj/stat/" class="button">狀態</a></li>
+ <li page="user" class="button" style="display:none;"><a class="button">個人</a></li>
+ <li page="square" class="button"><a class="button">方塊</a></li>
+ <ul class="square_box"></ul>
+
+ <li page="login" class="button" style="margin:64px 0px 0px 0px; display:none;"><a href="/toj/login/" class="button">登入</a></li>
+ <li page="register" class="button" style="display:none;"><a href="/toj/register/" class="button">註冊</a></li>
+ <li page="logout" class="button" style="margin:64px 0px 0px 0px; display:none;"><a href="/toj/logout/" class="button">登出</a></li>
+</ul></div>
+
+<div id="notice_list_box" exheight=true class="notice_list_box"><ul id="notice_list" class="notice_list"></ul></div>
+
+<div id="index_page" exheight=true class="index_page">
+
+ <div page="home" class="common_page home_page">
+ <audio id="tmpload_audio" src="/tmpload.ogg" preload></audio>
+ <audio id="tmp_audio" src="/tmp.ogg" preload></audio>
+ <div id="tmpani" style="width:100%; height:100%; background-color:#0C0C0C;">
+ <canvas id="tmpcanv" width=1280 height=720 style="margin:0px auto 0px auto; display:block;"></canvas>
+ </div>
+ </div>
+
+ <div page="none" class="common_page none_page">
+ <div style="margin:192px 0px 0px 256px;">
+ <h1>Oops! 此頁不存在</h1>
+ <a href="/toj/home/" style="margin-left:6px; color:#E9E9E9;">回首頁</a>
+ </div>
+ </div>
+
+ <div page="stat" class="common_page stat_page">
+ <div tab="allsub" class="common_tab sub_tab">
+ <table class="sublist">
+ <tr class="head">
+ <th class="subid">SubID</th>
+ <th class="proid" >ProID</th>
+ <th class="nickname">暱稱</th>
+ <th class="runtime">執行時間</th>
+ <th class="memory">記憶體</th>
+ <th class="result">結果</th>
+ <th class="score">分數</th>
+ <th class="time">時間</th>
+ <th class="lang">語言</th>
+ </tr>
+ </table>
+ </div>
+ </div>
+
+ <div page="user" class="common_page user_page">
+ <div tab="main" class="common_tab main_tab">
+ <div class="info_box">
+ <img class="avatar"></img>
+ <div class="aboutme"></div>
+ </div>
+ </div>
+ <div tab="edit" class="common_tab edit_tab">
+ <div class="edit_box">
+ <h1>個人資料</h1>
+ <label>暱稱</label>
+ <input name="nickname" type="textbox">
+ <label>照片</label>
+ <input name="avatar" type="textbox" placeholder="http://example.png">
+ <img class="avatar"></img>
+ <label>關於我</label>
+ <input name="aboutme" type="textbox">
+ <label>電子郵件</label>
+ <input name="email" type="textbox"><br>
+
+ <h1>重設密碼</h1>
+ <label>舊使用者密碼</label>
+ <input name="password_old" type="password">
+ <label>新使用者密碼</label>
+ <input name="password_new" type="password">
+ <label>重復新密碼</label>
+ <input name="password_repeat" type="password"><br>
+
+ <div class="error"></div>
+ <button class="submit">確定</button>
+ <button class="cancel">取消</button>
+ </div>
+ </div>
+ <div tab="mgsq" class="common_tab mgsq_tab">
+ <div class="in_box">
+ <h1>已加入方塊</h1>
+ <h2>等待中</h2>
+ <div class="wait"></div><br>
+ <h2>進行中</h2>
+ <div class="run"></div><br>
+ <h2>已結束</h2>
+ <div class="past"></div>
+ </div>
+ <div class="out_box">
+ <h1>未加入方塊</h1>
+ <h2>等待中</h2>
+ <div class="wait"></div><br>
+ <h2>進行中</h2>
+ <div class="run"></div><br>
+ <h2>已結束</h2>
+ <div class="past"></div>
+ </div>
+ </div>
+ <div tab="mg" class="common_tab mg_tab">
+ <div class="left_box">
+ <h1>方塊</h1>
+ <button class="newsq">建立方塊</button>
+ </div>
+ </div>
+ </div>
+
+ <div page="sq" class="common_page sq_page"></div>
+ <div page="pro" class="common_page pro_page"></div>
+
+ <div page="login" class="common_page login_page">
+ <div class="info_box">
+ <h1>登入TOJ, 開始你的解題</h1>
+ <strong>沒有帳號?</strong><a href="/toj/register/" style="margin-left:6px; color:#E9E9E9;">註冊</a>
+ </div>
+ <div class="login_box">
+ <h1>登入</h1>
+ <div class="error"></div>
+ <input name="username" type="textbox" placeholder="使用者名稱">
+ <input name="password" type="password" placeholder="使用者密碼">
+ <button>登入</button>
+ </div>
+ </div>
+
+ <div page="register" class="common_page register_page">
+ <div class="info_box">
+ <h1>註冊TOJ, 開始你的解題</h1>
+ <strong>有帳號?</strong><a href="/toj/login/" style="margin-left:6px; color:#E9E9E9;">登入</a>
+ </div>
+ <div class="register_box">
+ <h1>註冊</h1>
+ <div class="error"></div>
+ <input name="username" type="textbox" placeholder="使用者名稱">
+ <input name="password" type="password" placeholder="使用者密碼">
+ <input name="password_repeat" type="password" placeholder="重復密碼">
+ <input name="nickname" type="textbox" placeholder="暱稱">
+ <input name="email" type="textbox" placeholder="電子郵件">
+ <button>註冊</button>
+ </div>
+ </div>
+
+</div>
+
+<div id="index_mask" class="index_mask">
+ <div class="user_mask">
+ <div class="common_mask_box editsq_mbox">
+ <div class="edit_box">
+ <h1>基本資料</h1>
+ <label>方塊名稱</label>
+ <input name="sqname" type="textbox" size="16" placeholder="foo">
+ <label>模組名稱</label>
+ <input name="sqmodname" type="textbox" size="16" placeholder="sqmod_foo">
+ <label>隱私</label>
+ <select name="publicity">
+ <option value=3>公開</option>
+ <option value=2>可申請</option>
+ <option value=1>秘密</option>
+ </select>
+ <label>時間限制</label>
+ <select name="infinite">
+ <option value=1>無時限</option>
+ <option value=2>有時限</option>
+ </select>
+ <div class="time" style="display:none;">
+ <label>開始時間</label><br>
+ <input name="s_year" type="textbox" size="1" placeholder="2501" style="display:inline-block">
+ <input name="s_month" type="textbox" size="1" placeholder="1" style="display:inline-block">
+ <input name="s_day" type="textbox" size="1" placeholder="1" style="display:inline-block">
+ <input name="s_hr" type="textbox" size="1" placeholder="18" style="margin:0px 0px 0px 6px; display:inline-block">
+ <input name="s_min" type="textbox" size="1" placeholder="30" style="display:inline-block"><br>
+ <label>結束時間</label><br>
+ <input name="e_year" type="textbox" size="1" placeholder="2501" style="display:inline-block">
+ <input name="e_month" type="textbox" size="1" placeholder="1" style="display:inline-block">
+ <input name="e_day" type="textbox" size="1" placeholder="1" style="display:inline-block">
+ <input name="e_hr" type="textbox" size="1" placeholder="18" style="margin:0px 0px 0px 6px; display:inline-block">
+ <input name="e_min" type="textbox" size="1" placeholder="30" style="display:inline-block">
+ </div><br>
+ <button class="delete" style="display:none;">刪除</button><br><br>
+
+ <div class="error"></div>
+ <button class="submit">確定</button>
+ <button class="cancel">取消</button>
+ </div>
+ </div>
+ </div>
+ <div class="pro_mask">
+ <div exheight=true extop=32 exbottom=32 class="common_mask_box sub_mbox">
+ <div class="head">
+ <div class="title"></div>
+ <div class="error"></div>
+ <div class="oper">
+ <select name="lang">
+ <option value="1">C++</option>
+ </select>
+ <button class="submit">確定</button>
+ <button class="cancel">取消</button>
+ </div>
+ </div>
+ <div exheight=true extop=76 exbottom=38 class="codebox"></div>
+ </div>
+ </div>
+ <div class="stat_mask">
+ <div class="common_mask_box subinfo_mbox"></div>
+ </div>
+</div>
+
+</body>
+</html>
diff --git a/toj/jcs/common.css b/toj/jcs/common.css
new file mode 100644
index 0000000..f693f3d
--- /dev/null
+++ b/toj/jcs/common.css
@@ -0,0 +1,19 @@
+div.common_page{
+ height:100%;
+ position:relative;
+ overflow:auto;
+ display:none;
+}
+div.common_tab{
+ height:100%;
+ position:relative;
+ overflow:auto;
+ display:none;
+}
+div.common_mask_box{
+ margin:32px auto;
+ padding:0px 32px 0px 32px;
+ background-color:#373C38;
+ position:relative;
+ display:none;
+}
diff --git a/toj/jcs/common.js b/toj/jcs/common.js
new file mode 100644
index 0000000..84468e3
--- /dev/null
+++ b/toj/jcs/common.js
@@ -0,0 +1,336 @@
+var RESULTMAP = {0:'AC',1:'WA',2:'TLE',3:'MLE',4:'RF',5:'RE',6:'CE',7:'ERR',100:'WAIT'};
+
+var USER_PER_USER = 0x00000001;
+var USER_PER_PROCREATOR = 0x00000002;
+var USER_PER_PROADMIN = 0x00000004;
+
+var USER_LEVEL_USER = 0x00000001;
+var USER_LEVEL_PROCREATOR = 0x00000003;
+var USER_LEVEL_PROADMIN = 0x00000007;
+var USER_LEVEL_ADMIN = 0x0000ffff;
+var USER_LEVEL_SUPERADMIN = -1;
+
+var __extend = function(child,parent){
+ child.prototype.__super = parent;
+};
+
+var common = {
+ page_list:new Array(),
+ url_prev:null,
+ url_curr:null,
+ mbox_curr:null,
+ mbox_defer:null,
+
+ init:function(){
+ var i;
+ var url;
+ var urlpart;
+
+ urlpart = location.href.split('?');
+ if(urlpart[0].search(/\/$/) == -1){
+ url = urlpart[0] + '/';
+ if(urlpart.length > 1){
+ url = url + '?';
+ for(i = 1;i < urlpart.length;i++){
+ url = url + urlpart[i];
+ }
+ }
+ window.history.replaceState(null,document.title,url);
+ }
+
+ common.url_curr = location.href;
+
+ $(document).on('click','a',function(e){
+ common.pushurl($(this).attr('href'));
+ return false;
+ });
+ $(document).on('keyup',function(e){
+ if(e.which == 27){
+ common.hidembox(false);
+ }
+ });
+ },
+
+ exheight:function(){
+ var i;
+ var es;
+ var extop;
+ var exbottom;
+ var j_e;
+ var j_parent;
+
+ es = $('[exheight=true]');
+ for(i = 0;i < es.length;i++){
+ j_e = $(es[i]);
+ if((extop = j_e.attr('extop')) == undefined){
+ extop = j_e.css('top').match(/(.+)px/)[1];
+ }
+ if((exbottom = j_e.attr('exbottom')) == undefined){
+ exbottom = 0;
+ }
+ extop = parseInt(extop);
+ exbottom = parseInt(exbottom);
+
+ j_e.css('height',($(window).height() - (extop + exbottom) + 'px'));
+ }
+ },
+ getcookie:function(){
+ var ret;
+ var i;
+ var part;
+ var subpart;
+
+ ret = new Array();
+ part = document.cookie.split(';');
+ for(i = 0;i < part.length;i++){
+ part[i] = part[i].replace(/\+/g,' ');
+ subpart = part[i].split('=');
+ ret[decodeURIComponent(subpart[0])] = decodeURIComponent(subpart[1]);
+ }
+
+ return ret;
+ },
+ getdate:function(str){
+ var part;
+ part = str.match(/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/);
+ return new Date(part[1],parseInt(part[2]) - 1,part[3],part[4],part[5],part[6],0);
+ },
+ getdatestring:function(date,secflag){
+ var month;
+ var day;
+ var hr;
+ var min;
+ var sec;
+
+ month = date.getMonth() + 1;
+ if(month < 10){
+ month = '0' + month;
+ }
+ day = date.getDate();
+ if(day < 10){
+ day = '0' + day;
+ }
+ hr = date.getHours();
+ if(hr < 10){
+ hr = '0' + hr;
+ }
+ min = date.getMinutes();
+ if(min < 10){
+ min = '0' + min;
+ }
+ if(secflag == true){
+ sec = date.getSeconds();
+ if(sec < 10){
+ sec = '0' + sec;
+ }
+
+ return date.getFullYear() + '-' + month + '-' + day + ' ' + hr + ':' + min + ':' + sec;
+ }else{
+ return date.getFullYear() + '-' + month + '-' + day + ' ' + hr + ':' + min;
+ }
+ },
+ getlang:function(value){
+ var i;
+ var ret;
+ var langlist = ['C++','JAVA','Pascal'];
+
+ ret = new Array;
+ i = 0;
+ while(value > 0){
+ if((value & 1) == 1){
+ ret.push(langlist[i]);
+ }
+ value = value >> 1;
+ }
+
+ return ret;
+ },
+
+ geturlpart:function(url){
+ if(url == undefined){
+ return location.href.match(/toj\/(.*)/)[1].split('/');
+ }else{
+ return url.match(/toj\/(.*)/)[1].split('/');
+ }
+ },
+ pushurl:function(url){
+ common.url_prev = location.href;
+ window.history.pushState(null,document.title,url);
+ common.url_curr = location.href;
+ common.page_urlchange();
+ },
+ replaceurl:function(url){
+ window.history.replaceState(null,document.title,url);
+ common.url_curr = location.href;
+ },
+ prevurl:function(notpagename){
+ if(common.url_prev == null || common.geturlpart(common.url_prev)[0] == notpagename){
+ common.pushurl('/toj/home/');
+ }else{
+ common.pushurl(common.url_prev);
+ }
+ },
+ page_urlchange:function(){
+ var urlpart;
+ var pagename;
+ var pagename_prev;
+
+ if(arguments.callee.reentrant == true){
+ arguments.callee.hasnext = true;
+ return;
+ }else{
+ arguments.callee.reentrant = true;
+ arguments.callee.hasnext = true;
+ }
+
+ while(arguments.callee.hasnext){
+ arguments.callee.hasnext = false;
+
+ if(common.mbox_curr != null){
+ common.hidembox(false);
+ }
+
+ urlpart = common.geturlpart();
+ pagename = urlpart[0];
+ if(pagename == ''){
+ common.replaceurl('/toj/home/');
+ common.page_urlchange();
+ continue;
+ }else if(!(pagename in common.page_list)){
+ common.replaceurl('/toj/none/');
+ common.page_urlchange();
+ continue;
+ }
+
+ if(common.url_prev != null){
+ pagename_prev = common.geturlpart(common.url_prev)[0];
+ if(pagename == pagename_prev){
+ common.page_list[pagename].urlchange('same');
+ }else{
+ if(pagename_prev in common.page_list){
+ common.page_list[pagename_prev].urlchange('out');
+ }
+ common.page_list[pagename].urlchange('in');
+ }
+ }else{
+ common.page_list[pagename].urlchange('in');
+ }
+ }
+ arguments.callee.reentrant = false;
+ },
+ addpage:function(pagename,pageobj){
+ common.page_list[pagename] = pageobj;
+ },
+ removepage:function(pagename){
+ delete common.page_list[pagename];
+ },
+
+ showmbox:function(mboxobj){
+ common.mbox_curr = mboxobj;
+ mboxobj.switchchange('in');
+ common.mbox_defer = $.Deferred();
+ return common.mbox_defer.promise();
+ },
+ hidembox:function(done){
+ if(common.mbox_curr != null){
+ common.mbox_curr.switchchange('out');
+ common.mbox_curr = null;
+ if(done == true){
+ common.mbox_defer.resolve();
+ }else{
+ common.mbox_defer.reject();
+ }
+ }
+ }
+};
+
+var class_common_page = function(){
+ var that = this;
+ that.tab_list = Array();
+ that.tabname_curr = null;
+
+ that.urlchange = function(direct){};
+ that.fadein = function(j_e){
+ j_e.stop().fadeIn('fast');
+ };
+ that.fadeout = function(j_e){
+ j_e.stop().hide();
+ };
+
+ that.tab_urlchange = function(tabname){
+ if(arguments.callee.reentrant == true){
+ arguments.callee.hasnext = true;
+ return;
+ }else{
+ arguments.callee.reentrant = true;
+ arguments.callee.hasnext = true;
+ }
+
+ while(arguments.callee.hasnext){
+ arguments.callee.hasnext = false;
+
+ if(tabname == null){
+ if(that.tabname_curr in that.tab_list){
+ index.lltab(that.tabname_curr);
+ that.tab_list[that.tabname_curr].urlchange('out');
+ }
+ that.tab_list = new Array();
+ that.tabname_curr = null;
+ continue;
+ }
+
+ if(!(tabname in that.tab_list)){
+ common.replaceurl('/toj/none/');
+ common.page_urlchange();
+ return;
+ }
+
+ if(tabname == that.tabname_curr){
+ that.tab_list[tabname].urlchange('same');
+ }else{
+ if(that.tabname_curr in that.tab_list){
+ index.lltab(that.tabname_curr);
+ that.tab_list[that.tabname_curr].urlchange('out');
+ }
+ that.tabname_curr = tabname;
+ index.hltab(tabname);
+ that.tab_list[tabname].urlchange('in');
+ }
+ }
+ arguments.callee.reentrant = false;
+ };
+ that.addtab = function(tabname,tabobj){
+ that.tab_list[tabname] = tabobj;
+ };
+ that.removetab = function(tabname){
+ delete that.tab_list[tabname];
+ };
+};
+
+var class_common_tab = function(paobj){
+ var that = this;
+ that.paobj = paobj;
+
+ that.urlchange = function(direct){};
+ that.fadein = function(j_e){
+ j_e.stop().fadeIn('fast');
+ };
+ that.fadeout = function(j_e){
+ j_e.stop().hide();
+ };
+};
+
+var class_common_mbox = function(paobj){
+ var that = this;
+ that.paobj = paobj;
+
+ that.switchchange = function(direct){};
+ that.fadein = function(j_e){
+ j_e.stop().show();
+ index.showmask();
+ };
+ that.fadeout = function(j_e){
+ index.hidemask();
+ j_e.stop().hide();
+ };
+}
diff --git a/web/square_set.php b/toj/jcs/home.css
index e69de29..e69de29 100644
--- a/web/square_set.php
+++ b/toj/jcs/home.css
diff --git a/toj/jcs/home.js b/toj/jcs/home.js
new file mode 100644
index 0000000..bdc509d
--- /dev/null
+++ b/toj/jcs/home.js
@@ -0,0 +1,433 @@
+var home = {
+ init:function(){
+ home.home_page = new class_home_page;
+ home.none_page = new class_none_page;
+ }
+};
+
+var class_home_page = function(){
+ var that = this;
+ var j_page = $($('#index_page > [page="home"]')[0]);
+
+ that.__super();
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_page);
+ index.settitle('Taiwan Online Judge');
+ tmp();
+ }else if(direct == 'out'){
+ that.fadeout(j_page);
+ tmp_stop = true;
+ }
+ }
+ common.addpage('home',that);
+
+
+ var tmp_stop = true;
+ var tmp_first = true;
+
+ var load;
+ var prog = 0;
+ var bd = Math.PI / 180;
+
+ var co_table = [
+ '255,255,0',
+ '255,0,255',
+ '255,255,0',
+ '255,255,255',
+ '17,50,133',
+ '203,27,69',
+ '233,139,42',
+ '186,145,50',
+ '123,162,63',
+ '27,129,62',
+ '0,170,144',
+ '0,137,167',
+ '0,92,175',
+ '203,64,66',
+ '233,205,76',
+ '232,48,21',
+ '255,196,8'
+ ];
+
+ var st;
+ var et;
+ var pa_off = 0;
+ var pa_c = 6;
+ var pa_co = 0;
+ var pb_off = 0;
+ var pb_c = 6;
+ var pb_co = 0;
+
+ function tmp(){
+ var e_ani;
+ var e_canvas;
+ var ctx;
+ var e_audio;
+
+ function drawTextAlongArc(context,str,centerX,centerY,radius,angle,offangle) {
+ var len = str.length, s;
+ context.save();
+ context.translate(centerX,centerY);
+ context.rotate(-1 * offangle);
+ context.rotate(-1 * angle / 2);
+ context.rotate(-1 * (angle / len) / 2);
+ for(var n = 0; n < len; n++) {
+ context.rotate(angle / len);
+ context.save();
+ context.translate(0, -1 * radius);
+ s = str[n];
+ context.fillText(s,0,0);
+ context.restore();
+ }
+ context.restore();
+ }
+ function drawRect(ctx,x,y,w,h){
+ ctx.beginPath();
+ ctx.rect(x,y,w,h);
+ ctx.fill();
+ }
+ function drawCircle(ctx,x,y,r,a,off){
+ ctx.beginPath();
+ ctx.arc(x,y,r,off,a + off,false);
+ ctx.stroke();
+ }
+ function drawLine(ctx,ax,ay,bx,by){
+ ctx.beginPath();
+ ctx.moveTo(ax,ay);
+ ctx.lineTo(bx,by);
+ ctx.stroke();
+ }
+ function drawPoly(ctx,x,y,r,c,offangle){
+ var i;
+
+ ctx.save();
+ ctx.beginPath();
+ ctx.translate(x,y);
+ ctx.rotate(-1 * offangle);
+ ctx.moveTo(0,-r);
+ for(i = 1;i <= c;i++){
+ ctx.rotate(bd * 360 / c);
+ ctx.lineTo(0,-r);
+ }
+ ctx.stroke();
+ ctx.restore();
+ }
+
+ var ani = function(){
+ var i;
+ var u,v;
+
+ if(tmp_stop == true){
+ return;
+ }
+
+ et = new Date().getTime();
+ if((et - st) < 20){
+ window.requestAnimationFrame(ani);
+ return;
+ }
+ ctx.clearRect(0,0,1920,1080);
+
+ ctx.fillStyle = 'rgba(128,128,128,1)';
+ ctx.shadowBlur = 0;
+
+ ctx.strokeStyle = 'rgba(30,30,30,1)';
+ ctx.lineWidth = 2;
+ u = 3000 - (prog % 240) / 240 * 3000;
+ for(i = 0;i < 12;i++){
+ v = (u + i * 250) % 3000;
+ drawLine(ctx,v - 540,-5,v - 1040,1085);
+ }
+ ctx.strokeStyle = 'rgba(30,30,30,1)';
+ ctx.lineWidth = 2;
+ u = 2500 - (prog % 240) / 240 * 2500;
+ for(i = 0;i < 10;i++){
+ v = (u + i * 250) % 2500;
+ drawLine(ctx,-5,v - 1250,1925,v - 540);
+ }
+
+ ctx.strokeStyle = 'rgba(128,128,128,1)';
+
+ ctx.lineWidth = 12;
+ drawCircle(ctx,700,500,550,bd * 30,-bd * (prog % 360));
+ drawCircle(ctx,700,500,550,bd * 30,-bd * (prog % 360 + 120));
+ drawCircle(ctx,700,500,550,bd * 30,-bd * (prog % 360 + 240));
+
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,450,bd * 360,0);
+
+ ctx.lineWidth = 16;
+ drawCircle(ctx,700,500,440,bd * 60,-bd * ((prog * 2) % 360));
+ drawCircle(ctx,700,500,440,bd * 60,-bd * ((prog * 2) % 360 + 120));
+ drawCircle(ctx,700,500,440,bd * 60,-bd * ((prog * 2) % 360 + 240));
+
+ ctx.lineWidth = 10;
+ drawCircle(ctx,700,500,390,bd * 60,bd * ((prog * 7) % 360 + 160));
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,370,bd * 30,-bd * ((prog * 8) % 360 + 290));
+
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,350,bd * 60,bd * ((prog * 3) % 360));
+ ctx.lineWidth = 38;
+ drawCircle(ctx,700,500,335,bd * 20,bd * ((prog * 3) % 360 + 59));
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,320,bd * 80,bd * ((prog * 3) % 360 + 60));
+
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,350,bd * 50,bd * ((prog * 3) % 360 + 200));
+ ctx.lineWidth = 28;
+ drawCircle(ctx,700,500,340,bd * 40,bd * ((prog * 3) % 360 + 249));
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,330,bd * 60,bd * ((prog * 3) % 360 + 260));
+
+ ctx.lineWidth = 4;
+ drawCircle(ctx,700,500,300,bd * 360,0);
+ ctx.lineWidth = 16;
+ drawCircle(ctx,700,500,295,bd * 80,-bd * ((prog * 4) % 360 + 90));
+
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,260,bd * 90,bd * ((prog * 4) % 360));
+ drawCircle(ctx,700,500,230,bd * 120,-bd * ((prog * 5) % 360 + 120));
+ drawCircle(ctx,700,500,210,bd * 160,bd * ((prog * 3) % 360 + 270));
+
+ ctx.strokeStyle = 'rgba(128,128,128,' + (1 - (prog % 24)/24) + ')';
+ ctx.lineWidth = 8;
+ drawCircle(ctx,700,500,80 + (prog % 24) * 4,bd * 360,0);
+ ctx.lineWidth = 4;
+ drawCircle(ctx,700,500,70 + (prog % 24) * 4,bd * 360,0);
+
+ ctx.font = 'bold 16px tahoma';
+ drawTextAlongArc(ctx,"Hello TOJ [FORCORO]",700,500,460,bd * 60,bd * (prog % 360 + 115) * 2);
+ drawTextAlongArc(ctx,"Are You Happy?",700,500,460,bd * 50,bd * (prog % 360 + 30) * 2);
+
+ if(prog < 456 || prog > 912){
+ ctx.strokeStyle = 'rgba(255,255,255,1)';
+ ctx.lineWidth = 6;
+ drawCircle(ctx,700,500,60,bd * 60,bd * ((prog * 4) % 360));
+ drawCircle(ctx,700,500,60,bd * 60,bd * ((prog * 4) % 360 + 180));
+ }else{
+ u = prog % 48;
+ if(u == 0){
+ pa_off = bd * (prog % 373);
+ pa_c = prog % 5 + 3;
+ pa_co = Math.round(Math.random() * co_table.length);
+ }
+ ctx.strokeStyle = 'rgba(' + co_table[pa_co] + ',' + (1 - u / 48) + ')';
+ drawPoly(ctx,700,500,u * 20,pa_c,pa_off);
+ u = (prog + 24) % 48;
+ if(u == 0){
+ pb_off = bd * (prog % 173);
+ pb_c = prog % 5 + 3;
+ pb_co = Math.round(Math.random() * co_table.length);
+ }
+ ctx.strokeStyle = 'rgba(' + co_table[pb_co] + ',' + (1 - u / 48) + ')';
+ drawPoly(ctx,700,500,u * 20,pb_c,pb_off);
+
+ ctx.strokeStyle = 'rgba(255,255,255,1)';
+ ctx.lineWidth = 6;
+ drawCircle(ctx,700,500,60,bd * 60,-bd * ((prog * 15) % 360));
+ drawCircle(ctx,700,500,60,bd * 60,-bd * ((prog * 15) % 360 + 180));
+ }
+
+ v = prog % 96;
+ if((v >= 24 && v < 26)|| (v >= 28 && v < 30)){
+ ctx.shadowBlur = 5;
+ }else{
+ ctx.shadowBlur = 0;
+ }
+
+ ctx.font = 'bold 64px tahoma';
+ u = 0;
+ ctx.fillStyle = 'rgba(255,255,0,1)';
+ ctx.shadowColor = 'rgba(255,255,0,1)';
+ ctx.fillText('T',1000 + u,600);
+ ctx.fillStyle = 'rgba(255,255,255,1)';
+ ctx.shadowColor = 'rgba(255,255,255,1)';
+ u += ctx.measureText('T').width;
+ ctx.fillText('aiwan',1000 + u,600);
+ u += ctx.measureText('aiwan').width;
+
+ if((v >= 32 && v < 34)|| (v >= 36 && v < 38)){
+ ctx.shadowBlur = 5;
+ }else{
+ ctx.shadowBlur = 0;
+ }
+
+ ctx.fillStyle = 'rgba(255,0,255,1)';
+ ctx.shadowColor = 'rgba(255,0,255,1)';
+ ctx.fillText(' O',1000 + u,600);
+ ctx.fillStyle = 'rgba(255,255,255,1)';
+ ctx.shadowColor = 'rgba(255,255,255,1)';
+ u += ctx.measureText(' O').width;
+ ctx.fillText('nline',1000 + u,600);
+ u += ctx.measureText('nline').width;
+
+ if((v >= 40 && v < 42)|| (v >= 44 && v < 46)){
+ ctx.shadowBlur = 5;
+ }else{
+ ctx.shadowBlur = 0;
+ }
+
+ ctx.fillStyle = 'rgba(0,255,255,1)';
+ ctx.shadowColor = 'rgba(0,255,255,1)';
+ ctx.fillText(' J',1000 + u,600);
+ ctx.fillStyle = 'rgba(255,255,255,1)';
+ ctx.shadowColor = 'rgba(255,255,255,1)';
+ u += ctx.measureText(' J').width;
+ ctx.fillText('udge',1000 + u,600);
+
+ ctx.shadowBlur = 0;
+
+ ctx.fillStyle = 'rgba(255,196,8,0.9)';
+ drawRect(ctx,0,930,1920,70);
+
+ ctx.font = 'bold 50px 微軟正黑體';
+ ctx.fillStyle = 'rgba(255,255,255,1)';
+ ctx.fillText('Taiwan Online Judge へようこそ システムテスト',1920 - (prog % 360) / 360 * 3000,980);
+ ctx.fillText('Taiwan Online Judge へようこそ システムテスト',1920 - ((prog + 180) % 360) / 360 * 3000,980);
+
+ ctx.font = 'bold 36px 微軟正黑體';
+ u = ctx.measureText('Parallel Judge 使用可能').width + 64;
+ ctx.fillText('Parallel Judge 使用可能',1920 - u,64);
+
+ if(prog % 24 < 12){
+ ctx.font = 'bold 36px 微軟正黑體';
+ u = ctx.measureText('INSERT COIN[S]').width + 64;
+ ctx.fillText('INSERT COIN[S]',1920 - u,1045);
+ }
+
+ if(prog <= 45){
+ ctx.fillStyle = 'rgba(8,8,8,1)';
+ drawRect(ctx,0,0,1920,1080);
+ }else if(prog < 50){
+ ctx.fillStyle = 'rgba(8,8,8,' + (1 - (prog / 50)) + ')';
+ drawRect(ctx,0,0,1920,1080);
+ }
+
+ if(prog > 25){
+ if(prog <= 45){
+ ctx.fillStyle = 'rgba(255,255,0,1)';
+ drawRect(ctx,1000 * ((prog - 25) / 20) * 4 - 3000,500,200,128);
+ ctx.fillStyle = 'rgba(255,0,255,1)';
+ drawRect(ctx,1200 * ((prog - 25) / 20) * 4 - 3600,500,200,128);
+ ctx.fillStyle = 'rgba(0,255,255,1)';
+ drawRect(ctx,1400 * ((prog - 25) / 20) * 4 - 4200,500,200,128);
+ }else if(prog < 50){
+ ctx.fillStyle = 'rgba(255,255,0,' + (1 - (prog / 50)) + ')';
+ drawRect(ctx,1000,500,200,128);
+ ctx.fillStyle = 'rgba(255,0,255,' + (1 - (prog / 50)) + ')';
+ drawRect(ctx,1200,500,200,128);
+ ctx.fillStyle = 'rgba(0,255,255,' + (1 - (prog / 50)) + ')';
+ drawRect(ctx,1400,500,200,128);
+ }
+ }
+
+ st = et;
+ prog++;
+ if(prog == 1080){
+ prog = 360;
+ }
+ window.requestAnimationFrame(ani);
+ };
+
+ var loadani = function(){
+ var u;
+ var v;
+
+ ctx.clearRect(0,0,1920,1080);
+
+ if(tmp_stop == true){
+ return;
+ }
+
+ if(prog < 50){
+ u = 0;
+ }else if(prog < 100){
+ u = (prog - 50) / 50;
+ }else if(prog < 250){
+ u = 1;
+ }else if(prog < 300){
+ u = (300 - prog) / 50;
+ }else{
+ u = 0;
+ }
+
+ ctx.fillStyle = 'rgba(8,8,8,1)';
+ drawRect(ctx,0,0,1920,1080);
+
+ v = ctx.measureText('TF∪CK ').width;
+ ctx.fillStyle = 'rgba(128,0,0,' + u + ')';
+ ctx.fillRect(960 - v / 2 - 10,380,v + 20,200);
+
+ ctx.fillStyle = 'rgba(255,255,255,' + u + ')';
+ ctx.font = 'bold 192px tahoma';
+ ctx.fillText('TF∪CK ',960 - v / 2,550);
+
+ prog++;
+ if(prog == 400){
+ prog = 0;
+ st = 0;
+ document.getElementById('tmp_audio').play();
+ ani();
+ }else{
+ setTimeout(loadani,10);
+ }
+ }
+
+ e_ani = document.getElementById('tmpani');
+ e_canvas = document.getElementById('tmpcanv');
+
+ if(e_ani.clientWidth * 9 > e_ani.clientHeight * 16){
+ e_canvas.width = e_ani.clientHeight / 9 * 16;
+ e_canvas.height = e_ani.clientHeight;
+ }else{
+ e_canvas.width = e_ani.clientWidth;
+ e_canvas.height = e_ani.clientWidth / 16 * 9;
+ }
+
+ var waitaudio = function(){
+ if(document.getElementById('tmpload_audio').readyState != 4 || document.getElementById('tmp_audio').readyState != 4){
+ setTimeout(waitaudio,100);
+ }else{
+ e_audio = document.getElementById('tmpload_audio');
+ e_audio.play();
+ loadani();
+ }
+ }
+
+ ctx = e_canvas.getContext('2d');
+ ctx.scale(e_canvas.width / 1920,e_canvas.height / 1080);
+
+ tmp_stop = false;
+ if(tmp_first == true){
+ load = true;
+ waitaudio();
+ }else{
+ load = false;
+ ani();
+ }
+
+ tmp_first = false;
+ }
+}; __extend(class_home_page,class_common_page);
+
+var class_none_page = function(){
+ var that = this;
+ var j_page = $($('#index_page > [page="none"]')[0]);
+
+ that.__super();
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_page);
+ index.settitle('Taiwan Online Judge');
+ }else if(direct == 'out'){
+ that.fadeout(j_page);
+ }
+ }
+ common.addpage('none',that);
+}; __extend(class_none_page,class_common_page);
+
+
diff --git a/toj/jcs/index.css b/toj/jcs/index.css
new file mode 100644
index 0000000..d5d8dd2
--- /dev/null
+++ b/toj/jcs/index.css
@@ -0,0 +1,177 @@
+div.index_head{
+ width:100%;
+ height:32px;
+ font-size:20px;
+ line-height:32px;
+ background-color:#1C1C1C;
+ position:absolute;
+ left:0px;
+ top:0px;
+ z-index:1;
+}
+div.index_head > div.title{
+ width:250px;
+ height:100%;
+ margin:0px 0px 0px 6px;
+ float:left;
+}
+div.index_head > div.tab_box{
+ width:auto;
+ height:100%;
+ float:left;
+}
+div.index_head > div.tab_box > div.button{
+ height:100%;
+ margin:0px 0px;
+ float:left;
+}
+div.index_head > div.tab_box > div.button_s{
+ background-color:#3A8FB7;
+}
+div.index_head > div.tab_box > div.button > a.button{
+ height:100%;
+ padding:0px 16px 0px 16px;
+ color:#E9E9E9;
+ text-decoration:none;
+ display:block;
+}
+div.index_head > div.tab_box > div.button > a:hover.button{
+ color:#FFFFFF;
+}
+div.index_head > div.content_box{
+ width:auto;
+ height:100%;
+ float:left;
+}
+div.index_head > div.panel{
+ width:96px;
+ height:100%;
+ text-align:center;
+ cursor:pointer;
+ float:right;
+}
+div.index_head > div.panel_m{
+ color:#FFFFFF;
+}
+div.index_head > div.notice{
+ width:96px;
+ height:100%;
+ text-align:center;
+ font-family:monospace;
+ cursor:pointer;
+ float:right;
+}
+div.index_head > div:hover.notice{
+ color:#FFFFFF;
+}
+div.index_head > div.notice_s{
+ color:#FFFFFF;
+}
+div.index_head > div.notice_h{
+ background-color:#E83015;
+ color:#FFFFFF;
+}
+div.index_head > div.nickname{
+ height:100%;
+ padding:0px 16px 0px 16px;
+ float:right;
+}
+div.index_head > div.nickname > a.nickname{
+ height:100%;
+ color:#E9E9E9;
+ text-align:center;
+ text-decoration:none;
+}
+div.index_head > div.nickname > a:hover.nickname{
+ color:#FFFFFF;
+}
+
+div.index_panel_box{
+ width:0px;
+ position:absolute;
+ left:auto;
+ right:0px;
+ top:32px;
+ overflow:hidden;
+ z-index:110;
+}
+ul.index_panel{
+ width:256px;
+ height:100%;
+ margin:0px 0px;
+ padding:0px 0px;
+ background-color:#1C1C1C;
+ opacity:0;
+ position:absolute;
+ left:auto;
+ right:-256px;
+ top:0px;
+ z-index:2;
+ overflow-x:hidden;
+ overflow-y:auto;
+ list-style:none;
+}
+ul.index_panel > li.button{
+ width:auto;
+ height:64px;
+ padding:0px 0px 0px 32px;
+ font-size:20px;
+ line-height:64px;
+}
+ul.index_panel > li:hover.button{
+ color:#FFFFFF;
+ background-color:rgba(255,255,255,0.2);
+}
+ul.index_panel > ul.square_box{
+ width:100%;
+ margin:0px 0px;
+ padding:0px 0px;
+ list-style:none;
+ overflow:hidden;
+ display:none;
+}
+ul.index_panel > ul.square_box > li.button{
+ width:auto;
+ height:32px;
+ padding:0px 0px 0px 32px;
+ font-size:16px;
+ line-height:32px;
+}
+ul.index_panel > ul.square_box > li:hover.button{
+ color:#FFFFFF;
+ background-color:rgba(255,255,255,0.2);
+}
+ul.index_panel a.button{
+ width:100%;
+ height:100%;
+ color:#E9E9E9;
+ text-decoration:none;
+ position:relative;
+ top:0px;
+ left:50%;
+ cursor:pointer;
+ display:block;
+}
+ul.index_panel a.button_m{
+ color:#FFFFFF;
+}
+
+div.index_page{
+ width:100%;
+ position:absolute;
+ left:0px;
+ top:32px;
+ z-index:0;
+}
+
+div.index_mask{
+ width:100%;
+ height:100%;
+ background-color:rgba(0,0,0,0.9);
+ position:absolute;
+ top:0px;
+ left:0px;
+ z-index:3;
+ display:none;
+ overflow:auto;
+}
diff --git a/toj/jcs/index.js b/toj/jcs/index.js
new file mode 100644
index 0000000..e97242a
--- /dev/null
+++ b/toj/jcs/index.js
@@ -0,0 +1,128 @@
+var index = {
+ init:function(){
+ $('body').on('mouseover',function(e){
+ var j_panel;
+
+ if(e.target == null || e.target.id == 'index_panel' || $(e.target).parents('#index_panel').length > 0){
+ return;
+ }
+
+ j_panel = $('#index_head_panel');
+ if(e.target.id == 'index_head_panel'){
+ $('#index_head_notice').removeClass('notice_s');
+ $('#notice_list').stop().animate({opacity:0},'fast','easeOutQuad',
+ function(){
+ $('#notice_list_box').css('width','0px');
+ $('#notice_list').css('right','-256px');
+ $('#notice_list a.item').css('left','50%');
+ }
+ );
+
+ j_panel.addClass('panel_m');
+ $('#index_panel_box').stop().animate({width:256},'slow','easeOutExpo');
+ $('#index_panel').css('opacity','1').stop().animate({right:0},'slow','easeOutExpo');
+ $('#index_panel a.button').stop().animate({left:0},'slow','easeOutQuart');
+ }else{
+ $('#index_head_panel').removeClass('panel_m');
+ $('#index_panel').stop().animate({opacity:0},'fast','easeOutQuad',
+ function(){
+ $('#index_panel_box').css('width','0px');
+ $('#index_panel').css('right','-256px');
+ $('#index_panel a.button').css('left','50%');
+ }
+ );
+ }
+ });
+ $('#index_head_panel').on('mousedown',function(e){
+ return false;
+ });
+
+ $('#index_panel > li').on('mousedown',function(e){
+ return false;
+ });
+
+ $('#index_panel > [page="square"] > a.button').off('click').on('click',function(e){
+ var j_ul;
+
+ j_ul = $('#index_panel > ul.square_box');
+ if(j_ul.is(':visible')){
+ j_ul.stop().slideUp('slow','easeOutExpo');
+ }else{
+ j_ul.stop().slideDown('slow','easeOutExpo');
+ }
+
+ return false;
+ });
+
+ $('#index_mask').on('click',function(e){
+ if((e.target == this || $(e.target).parents('div.common_mask_box').length == 0) && !$(e.target).hasClass('common_mask_box') && common.mbox_curr != null){
+ common.hidembox(false);
+ }
+ });
+ },
+
+ showpanel:function(pagename){
+ $('#index_panel > [page="' + pagename + '"]').show();
+ },
+ hidepanel:function(pagename){
+ $('#index_panel > [page="' + pagename + '"]').hide();
+ },
+ setpanel:function(pagename,panellink,paneltext){
+ var j_a;
+
+ j_a = $('#index_panel > [page="' + pagename + '"] > a.button');
+ j_a.attr('href',panellink);
+ j_a.text(paneltext);
+ },
+
+ settitle:function(titletext){
+ $('#index_head > div.title').text(titletext);
+ },
+
+ addtab:function(tabname,tablink,tabtext){
+ var j_div;
+ var j_a;
+
+ j_div = $('<div class="button"></div>');
+ j_div.attr('tab',tabname);
+
+ j_a = $('<a class="button"></a>');
+ j_a.attr('href',tablink);
+ j_a.text(tabtext);
+
+ j_div.append(j_a);
+ $('#index_head > div.tab_box').append(j_div);
+
+ return j_div;
+ },
+ settab:function(tabname,tablink,tabtext){
+ var j_a;
+
+ j_a = $('#index_head > div.tab_box [tab="' + tabname + '"] > a.button');
+ j_a.attr('href',tablink);
+ j_a.text(tabtext);
+ },
+ emptytab:function(){
+ $('#index_head > div.tab_box').empty();
+ },
+ hltab:function(tabname){
+ $('#index_head > div.tab_box > [tab="' + tabname + '"]').addClass('button_s');
+ },
+ lltab:function(tabname){
+ $('#index_head > div.tab_box > [tab="' + tabname + '"]').removeClass('button_s');
+ },
+
+ setcontent:function(j_content){
+ $('#index_head > div.content_box').append(j_content);
+ },
+ emptycontent:function(){
+ $('#index_head > div.content_box').empty();
+ },
+
+ showmask:function(){
+ $('#index_mask').stop().fadeIn('fast');
+ },
+ hidemask:function(){
+ $('#index_mask').stop().hide();
+ }
+};
diff --git a/toj/jcs/notice.css b/toj/jcs/notice.css
new file mode 100644
index 0000000..44c790e
--- /dev/null
+++ b/toj/jcs/notice.css
@@ -0,0 +1,58 @@
+div.notice_list_box{
+ width:0px;
+ position:absolute;
+ left:auto;
+ right:0px;
+ top:32px;
+ overflow:hidden;
+ z-index:100;
+}
+ul.notice_list{
+ width:256px;
+ height:100%;
+ margin:0px 0px;
+ padding:0px 0px;
+ background-color:#1C1C1C;
+ opacity:0;
+ position:absolute;
+ left:auto;
+ right:-256px;
+ top:0px;
+ z-index:2;
+ overflow-x:hidden;
+ overflow-y:auto;
+ list-style:none;
+}
+ul.notice_list > li.item{
+ width:auto;
+ height:96px;
+ padding:0px 0px 0px 6px;
+}
+ul.notice_list > li:hover.item{
+ color:#FFFFFF;
+ background-color:rgba(255,255,255,0.2);
+}
+ul.notice_list > li.item div.head{
+ padding:16px 0px 6px 0px;
+ font-weight:bold;
+ font-size:20px;
+}
+ul.notice_list > li.item div.content{
+ font-size:16px;
+ word-break:break-all;
+ overflow:hidden;
+}
+ul.notice_list a.item{
+ width:100%;
+ height:100%;
+ color:#91989F;
+ text-decoration:none;
+ position:relative;
+ top:0px;
+ left:50%;
+ cursor:pointer;
+ display:block;
+}
+ul.notice_list a.item_h{
+ color:#E9E9E9;
+}
diff --git a/toj/jcs/notice.js b/toj/jcs/notice.js
new file mode 100644
index 0000000..64e93ef
--- /dev/null
+++ b/toj/jcs/notice.js
@@ -0,0 +1,155 @@
+var notice = {
+ j_ajax:null,
+ enid:null,
+
+ init:function(){
+ $('body').on('click',function(e){
+ var j_notice;
+
+ if(e.target == null || ($(e.target).parents('a.item').length == 0 && $(e.target).parents('#notice_list').length > 0)){
+ return;
+ }
+
+ j_notice = $('#index_head_notice');
+ if(e.target.id == 'index_head_notice' && !j_notice.hasClass('notice_s')){
+ j_notice.addClass('notice_s');
+ $('#notice_list_box').stop().animate({width:256},'slow','easeOutExpo');
+ $('#notice_list').css('opacity','1').stop().animate({right:0},'slow','easeOutExpo');
+ $('#notice_list a.item').stop().animate({left:0},'slow','easeOutQuart');
+ }else{
+ j_notice.removeClass('notice_s');
+ $('#notice_list').stop().animate({opacity:0},'fast','easeOutQuad',
+ function(){
+ $('#notice_list_box').css('width','0px');
+ $('#notice_list').css('right','-256px');
+ $('#notice_list a.item').css('left','50%');
+ }
+ );
+ }
+ });
+ $('#index_head_notice').on('click',function(e){
+ var j_list;
+
+ j_list = $('#notice_list');
+ if(j_list.css('opacity') == 0){
+ j_list.empty();
+ notice.enid = null;
+ notice.updatenew();
+ }
+ }).on('mousedown',function(e){
+ return false;
+ });
+
+ notice.refresh();
+ },
+ listnew:function(noticeo){
+ j_item = $('<li class="item"><a class="item"><div class="head"></div><div class="content"></div></a></li>')
+ j_a = j_item.find('a.item');
+ j_head = j_item.find('div.head');
+ j_content = j_item.find('div.content');
+
+ switch(noticeo.type){
+ case 'result':
+ j_a.attr('href','/toj/stat/allsub/' + noticeo.subid + '/');
+ j_head.text('Submit ' + noticeo.subid);
+ j_content.html('ProID ' + noticeo.proid + ' 結果: ' + RESULTMAP[noticeo.result] + '<br>' + noticeo.runtime+ 'ms / ' + noticeo.memory + 'KB');
+ break;
+ }
+
+ return j_item;
+ },
+ updatenew:function(){
+ var j_list;
+
+ if(notice.j_ajax != null){
+ notice.j_ajax.abort();
+ }
+
+ j_list = $('#notice_list');
+ notice.j_ajax = $.post('/toj/php/notice.php',{'action':'get','data':JSON.stringify({'nid':0,'count':10})},
+ function(res){
+ var i;
+
+ var reto;
+ var noticeo;
+ var j_item;
+ var j_a;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ for(i = 0;i < reto.length;i++){
+ noticeo = JSON.parse(reto[i].txt);
+ j_item = notice.listnew(noticeo);
+ j_list.prepend(j_item);
+ j_a = j_item.find('a.item');
+ j_a.addClass('item_h');
+ j_a.stop().animate({left:0},'slow','easeOutQuart');
+ }
+
+ if(notice.enid == null){
+ if(reto.length == 0){
+ notice.enid = 2147483647;
+ }else{
+ notice.enid = reto[0].nid;
+ }
+ notice.updateprev();
+ }
+ }
+
+ notice.j_ajax = null;
+ }
+ );
+ },
+ updateprev:function(){
+ var j_list;
+
+ j_list = $('#notice_list');
+ $.post('/toj/php/notice.php',{'action':'get','data':JSON.stringify({'nid':notice.enid,'count':10})},
+ function(res){
+ var i;
+
+ var reto;
+ var noticeo;
+ var j_item;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ for(i = reto.length - 1;i >= 0;i--){
+ noticeo = JSON.parse(reto[i].txt);
+ j_item = notice.listnew(noticeo);
+ j_list.append(j_item);
+ j_item.find('a.item').stop().animate({left:0},'slow','easeOutQuart');
+ }
+
+ notice.enid = 0;
+ }
+ }
+ );
+ },
+ refresh:function(){
+ $.post('/toj/php/notice.php',{'action':'count','data':JSON.stringify({})},
+ function(res){
+ var count;
+ var j_notice;
+
+ if(res[0] != 'E'){
+ count = JSON.parse(res);
+ j_notice = $('#index_head_notice');
+ if(count == 0){
+ j_notice.removeClass('notice_h');
+ j_notice.text('[' + count + ']');
+ }else{
+ if($('#notice_list').css('opacity') == 1){
+ notice.updatenew();
+ }else{
+ j_notice.addClass('notice_h');
+ j_notice.text('[' + count + ']');
+ }
+ }
+
+ setTimeout(notice.refresh,1000);
+ }
+ }
+ );
+ }
+};
diff --git a/toj/jcs/pro.css b/toj/jcs/pro.css
new file mode 100644
index 0000000..0629ee1
--- /dev/null
+++ b/toj/jcs/pro.css
@@ -0,0 +1,28 @@
+div.pro_mask > div.sub_mbox{
+ width:62%;
+}
+div.pro_mask > div.sub_mbox > div.head{
+ width:100%;
+ height:32px;
+ padding:6px 0px 6px 0px;
+}
+div.pro_mask > div.sub_mbox > div.head > div.title{
+ font-size:20px;
+ line-height:32px;
+ float:left;
+}
+div.pro_mask > div.sub_mbox > div.head > div.error{
+ margin:0px 0px 0px 16px;
+ color:#FFA0A0;
+ font-size:16px;
+ line-height:32px;
+ float:left;
+}
+div.pro_mask > div.sub_mbox > div.head > div.oper{
+ float:right;
+}
+div.pro_mask > div.sub_mbox > div.head > div.oper > select{
+ height:32px;
+ border-width:0px;
+ font-size:16px;
+}
diff --git a/toj/jcs/pro.js b/toj/jcs/pro.js
new file mode 100644
index 0000000..5e4db35
--- /dev/null
+++ b/toj/jcs/pro.js
@@ -0,0 +1,165 @@
+var pro = {
+ init:function(){
+ pro.pro_page = new class_pro_page;
+ }
+};
+
+var class_pro_page = function(){
+ var that = this;
+ var ori_prop = new Object;
+ var j_page = $('#index_page > [page="pro"]');
+ var sub_mbox = new class_pro_sub_mbox(that);
+
+ that.proid = null;
+ that.proname = null;
+ that.pmodname = null;
+
+ that.__super();
+
+ that.urlchange = function(direct){
+ var proid;
+
+ var _check = function(){
+ proid = common.geturlpart()[1];
+ if(proid == ''){
+ return false;
+ }
+ proid = parseInt(proid);
+ return true;
+ };
+ var _in = function(){
+ index.settitle('TOJ-題目');
+
+ $.post('/toj/php/problem.php',{'action':'get_pro','data':JSON.stringify({'proid':proid})},function(res){
+ var css;
+ var reto;
+
+ if(res[0] != 'E'){
+ that.proid = proid;
+ reto = JSON.parse(res);
+ that.proname = reto.proname;
+ that.pmodname = reto.pmodname;
+ j_page.addClass(that.pmodname);
+
+ css = $('<link rel="stylesheet" type="text/css" href="/toj/pmod/' + that.pmodname + '/' + that.pmodname + '.css">');
+ $('head').append(css);
+ css.ready(function(){
+ $.get('/toj/pmod/' + that.pmodname + '/' + that.pmodname + '.html',{},function(res){
+ j_page.html(res);
+ $.getScript('/toj/pmod/' + that.pmodname + '/' + that.pmodname + '.js',function(script,stat,res){
+ eval(that.pmodname + '.init(that,j_page)');
+ that.export_urlchange('in');
+ });
+ });
+ });
+ }
+ });
+ };
+ var _out = function(){
+ that.export_urlchange('out');
+
+ for(key in that){
+ if(!(key in ori_prop)){
+ delete that[key];
+ }else{
+ that[key] = ori_prop[key];
+ }
+ }
+
+ j_page.empty();
+ j_page.removeClass(that.pmodname);
+ index.emptycontent();
+ index.emptytab();
+ that.proid = null;
+ that.proname = null;
+ that.pmodname = null;
+ };
+
+ if(direct == 'in'){
+ if(_check()){
+ _in();
+ }
+ }else if(direct == 'out'){
+ _out();
+ }else if(direct == 'same'){
+ if(_check()){
+ if(proid != that.proid){
+ _out();
+ _in();
+ }else{
+ that.export_urlchange('same');
+ }
+ }
+ }
+ };
+ that.submit = function(proid){
+ if(proid == undefined){
+ proid = that.proid
+ }
+ sub_mbox.init(proid);
+ common.showmbox(sub_mbox);
+ };
+
+ for(key in that){
+ ori_prop[key] = that[key];
+ }
+
+ common.addpage('pro',that);
+}; __extend(class_pro_page,class_common_page);
+
+var class_pro_sub_mbox = function(paobj){
+ var that = this;
+ var j_mbox = $('#index_mask > div.pro_mask > div.sub_mbox');
+ var j_error = j_mbox.find('div.head > div.error');
+ var codebox = CodeMirror(j_mbox.find('div.codebox')[0],{
+ mode:'text/x-c++src',
+ theme:'lesser-dark',
+ lineNumbers:true,
+ matchBrackets:true,
+ indentUnit:4
+ });
+
+ that.__super(paobj);
+
+ that.init = function(proid){
+ that.proid = proid;
+ j_mbox.find('div.head > div.title').text('上傳ProID:' + that.proid);
+ j_error.text('');
+ $(j_mbox.find('[name="lang"] > option')[0]).attr('selected',true);
+ codebox.setValue('');
+ };
+ that.switchchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_mbox);
+ codebox.refresh();
+ }else if(direct == 'out'){
+ that.fadeout(j_mbox);
+ }
+ };
+
+ j_mbox.find('div.head > div.oper > button.submit').on('click',function(e){
+ $.post('/toj/php/problem.php',{'action':'submit_code','data':JSON.stringify({'proid':that.proid,'lang':1,'code':codebox.getValue()})},function(res){
+ if(res[0] == 'E'){
+ if(res == 'Enot_login'){
+ j_error.text('未登入');
+ }else if(res == 'Ewrong_language'){
+ j_error.text('語言錯誤');
+ }else if(res == 'Ecode_too_long'){
+ j_error.text('程式碼過長');
+ }else{
+ j_error.text('其他錯誤');
+ }
+ }else{
+ common.hidembox(j_mbox);
+ }
+ });
+ });
+ j_mbox.find('div.head > div.oper > button.cancel').on('click',function(e){
+ common.hidembox(j_mbox);
+ });
+
+ codebox.getWrapperElement().style.width = '100%';
+ codebox.getWrapperElement().style.height = '100%';
+ codebox.getScrollerElement().style.width = '100%';
+ codebox.getScrollerElement().style.height = '100%';
+}; __extend(class_pro_sub_mbox,class_common_mbox);
diff --git a/toj/jcs/sq.css b/toj/jcs/sq.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/toj/jcs/sq.css
diff --git a/toj/jcs/sq.js b/toj/jcs/sq.js
new file mode 100644
index 0000000..e3026b2
--- /dev/null
+++ b/toj/jcs/sq.js
@@ -0,0 +1,100 @@
+var sq = {
+ init:function(){
+ sq.sq_page = new class_sq_page;
+ }
+};
+
+var class_sq_page = function(){
+ var that = this;
+ var ori_prop = new Object;
+ var j_page = $('#index_page > [page="sq"]');
+
+ that.sqid = null;
+ that.sqname = null;
+ that.sqmodname = null;
+
+ that.__super();
+
+ that.urlchange = function(direct){
+ var sqid;
+
+ var _check = function(){
+ sqid = common.geturlpart()[1];
+ if(sqid == ''){
+ return false;
+ }
+ sqid = parseInt(sqid);
+ return true;
+ };
+ var _in = function(){
+ $.post('/toj/php/square.php',{'action':'get_sq','data':JSON.stringify({'sqid':sqid})},function(res){
+ var css;
+ var reto;
+
+ if(res[0] != 'E'){
+ that.sqid = sqid;
+ reto = JSON.parse(res);
+ that.sqname = reto.sqname;
+ that.sqmodname = reto.sqmodname;
+ j_page.addClass(that.sqmodname);
+ index.settitle('TOJ-' + that.sqname);
+
+ css = $('<link rel="stylesheet" type="text/css" href="/toj/sqmod/' + that.sqmodname + '/' + that.sqmodname + '.css">');
+ $('head').append(css);
+ css.ready(function(){
+ $.get('/toj/sqmod/' + that.sqmodname + '/' + that.sqmodname + '.html',{},function(res){
+ j_page.html(res);
+ $.getScript('/toj/sqmod/' + that.sqmodname + '/' + that.sqmodname + '.js',function(script,stat,res){
+ eval(that.sqmodname + '.init(that,j_page)');
+ that.export_urlchange('in');
+ });
+ });
+ });
+ }
+ });
+ };
+ var _out = function(){
+ that.export_urlchange('out');
+
+ for(key in that){
+ if(!(key in ori_prop)){
+ delete that[key];
+ }else{
+ that[key] = ori_prop[key];
+ }
+ }
+
+ j_page.empty();
+ j_page.removeClass(that.sqmodname);
+ index.emptycontent();
+ index.emptytab();
+ that.sqid = null;
+ that.sqname = null;
+ that.sqmodname = null;
+ };
+
+ if(direct == 'in'){
+ if(_check()){
+ _in();
+ }
+ }else if(direct == 'out'){
+ _out();
+ }else if(direct == 'same'){
+ if(_check()){
+ if(sqid != that.sqid){
+ _out();
+ _in();
+ }else{
+ that.export_urlchange('same');
+ }
+ }
+ }
+ }
+
+ for(key in that){
+ ori_prop[key] = that[key];
+ }
+
+ common.addpage('sq',that);
+}; __extend(class_sq_page,class_common_page);
+
diff --git a/toj/jcs/stat.css b/toj/jcs/stat.css
new file mode 100644
index 0000000..e0885e2
--- /dev/null
+++ b/toj/jcs/stat.css
@@ -0,0 +1,56 @@
+div.stat_page > div.sub_tab > table.sublist{
+ width:85%;
+ margin:0px auto 6px auto;
+ border-collapse:collapse;
+ text-align:left;
+}
+div.stat_page > div.sub_tab > table.sublist tr.head{
+ height:64px;
+ font-size:20px;
+}
+div.stat_page > div.sub_tab > table.sublist tr.item{
+ height:32px;
+ display:none;
+}
+div.stat_page > div.sub_tab > table.sublist tr:hover.item{
+ background-color:rgba(255,255,255,0.2);
+}
+div.stat_page > div.sub_tab > table.sublist th.subid,div.stat_page > div.sub_tab > table.sublist td.subid{
+ width:96px;
+}
+div.stat_page > div.sub_tab > table.sublist th.proid,div.stat_page > div.sub_tab > table.sublist td.proid{
+ width:96px;
+}
+div.stat_page > div.sub_tab > table.sublist th.nickname,div.stat_page > div.sub_tab > table.sublist td.nickname{
+ width:auto;
+}
+div.stat_page > div.sub_tab > table.sublist th.runtime,div.stat_page > div.sub_tab > table.sublist td.runtime{
+ width:96px;
+}
+div.stat_page > div.sub_tab > table.sublist th.memory,div.stat_page > div.sub_tab > table.sublist td.memory{
+ width:96px;
+}
+div.stat_page > div.sub_tab > table.sublist th.result,div.stat_page > div.sub_tab > table.sublist td.result{
+ width:64px;
+}
+div.stat_page > div.sub_tab > table.sublist th.score,div.stat_page > div.sub_tab > table.sublist td.score{
+ width:96px;
+}
+div.stat_page > div.sub_tab > table.sublist th.time,div.stat_page > div.sub_tab > table.sublist td.time{
+ width:256px;
+}
+div.stat_page > div.sub_tab > table.sublist th.lang,div.stat_page > div.sub_tab > table.sublist td.lang{
+ width:64px;
+}
+div.stat_page > div.sub_tab > table.sublist a.link{
+ color:#E9E9E9;
+ text-decoration:none;
+}
+div.stat_page > div.sub_tab > table.sublist a:hover.link{
+ color:#E9E9E9;
+ text-decoration:underline;
+}
+
+div.stat_mask > div.subinfo_mbox{
+ width:85%;
+}
diff --git a/toj/jcs/stat.js b/toj/jcs/stat.js
new file mode 100644
index 0000000..e0c7d55
--- /dev/null
+++ b/toj/jcs/stat.js
@@ -0,0 +1,364 @@
+var stat = {
+ init:function(){
+ stat.stat_page = new class_stat_page;
+ }
+};
+
+class_stat_page = function(){
+ var that = this;
+ var j_page = $('#index_page > [page="stat"]');
+ var j_blank = $('#index_page > [page="stat"] > div.blank');
+ var allsub_tab = new class_stat_allsub_tab(that);
+
+ that.subinfo_mbox = new class_stat_subinfo_mbox(that);
+
+ that.__super();
+
+ that.urlchange = function(direct){
+ var _in = function(){
+ that.fadein(j_page);
+
+ index.settitle('TOJ-狀態');
+
+ that.addtab('allsub',allsub_tab);
+ index.addtab('allsub','/toj/stat/allsub/','全部動態');
+
+ _change();
+ };
+ var _out = function(){
+ that.fadeout(j_page);
+ index.emptytab();
+ that.tab_urlchange(null);
+ };
+ var _change = function(){
+ var tabname;
+
+ tabname = common.geturlpart()[1];
+ if(!(tabname in that.tab_list)){
+ tabname = 'allsub';
+ common.replaceurl('/toj/stat/allsub/');
+ }
+ that.tab_urlchange(tabname);
+ }
+
+ if(direct == 'in'){
+ _in();
+ }else if(direct == 'out'){
+ _out();
+ }else if(direct == 'same'){
+ _change();
+ }
+ };
+
+ common.addpage('stat',that);
+}; __extend(class_stat_page,class_common_page);
+
+var class_stat_allsub_tab = function(paobj){
+ var that = this;
+ var j_tab = $('#index_page > [page="stat"] > [tab="allsub"]');
+ var j_table = j_tab.find('table.sublist');
+
+ var refresh_flag = false;
+ var j_ajax = null;
+ var ssubid = 0;
+ var esubid = 2147483647;
+ var lastupdate = null;
+ var topflag = true;
+ var topqueue = new Array;
+ var downblock = false;
+ var subid_curr = null;
+
+ var subinfo_switch = function(subid){
+ if(subid == undefined){
+ subid = common.geturlpart()[2];
+ }
+ if(subid != '' && subid != subid_curr){
+ subid_curr = parseInt(subid);
+ common.replaceurl('/toj/stat/allsub/' + subid_curr + '/');
+ that.paobj.subinfo_mbox.init(subid_curr);
+ common.showmbox(that.paobj.subinfo_mbox).always(function(){
+ subid_curr = null;
+ //common.prevurl();
+ });
+ }
+ };
+ var sub_listset = function(j_item,subo){
+ var j_a;
+
+ j_item.attr('subid',subo.subid);
+
+ j_item.find('td.subid').text(subo.subid);
+
+ j_a = j_item.find('td.proid > a.link');
+ j_a.attr('href','/toj/pro/' + subo.proid+ '/');
+ j_a.text(subo.proid);
+
+ j_a = j_item.find('td.nickname > a.link');
+ j_a.attr('href','/toj/user/' + subo.uid+ '/');
+ j_a.text(subo.nickname);
+
+ j_item.find('td.runtime').text(subo.runtime);
+ j_item.find('td.memory').text(subo.memory);
+ j_item.find('td.result').text(RESULTMAP[subo.result]);
+ j_item.find('td.score').text(subo.score);
+ j_item.find('td.time').text(common.getdatestring(subo.submit_time,true));
+ j_item.find('td.lang').text(common.getlang(subo.lang)[0]);
+
+ j_item.off('click').on('click',function(e){
+ if(e.target.tagName != 'A'){
+ subinfo_switch(subo.subid);
+ }
+ });
+ };
+ var sub_listnew = function(subo){
+ var j_item;
+
+ j_item = $('<tr class="item"><td class="subid"></td><td class="proid"><a class="link"></a></td><td class="nickname"><a class="link"></a></td><td class="runtime"></td><td class="memory"></td><td class="result"></td><td class="score"></td><td class="time"></td><td class="lang"></td></tr>');
+ sub_listset(j_item,subo);
+
+ return j_item;
+ };
+ var sub_refresh = function(){
+ if(refresh_flag == false){
+ return;
+ }
+ if(j_ajax != null){
+ j_ajax.abort();
+ }
+ j_ajax = $.post('/toj/php/status.php',{'action':'get_submit',
+ 'data':JSON.stringify({
+ 'filter':{'uid':null,'result':null,'proid':null,'lang':null},
+ 'sort':{'score':null,'runtime':null,'memory':null,'subid':[1,0]},
+ 'wait':10,
+ 'count':100,
+ 'last_update':lastupdate
+ })}
+ ,function(res){
+ var i;
+ var reto;
+ var j_item;
+ var maxsubid;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+
+ maxsubid = ssubid;
+ for(i = 0;i < reto.length;i++){
+ reto[i].submit_time = common.getdate(reto[i].submit_time);
+
+ j_item = j_table.find('[subid="' + reto[i].subid + '"]')
+ if(j_item.length > 0){
+ sub_listset(j_item,reto[i]);
+ }else if(reto[i].subid > ssubid){
+ if(topflag == true){
+ j_item = sub_listnew(reto[i]);
+ j_item.insertAfter(j_table.find('tr.head'));
+ j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
+ }else{
+ j_item = sub_listnew(reto[i]);
+ j_item.insertAfter(j_table.find('tr.head'));
+ topqueue.push(reto[i].subid);
+ }
+ }
+
+ if(reto[i].subid > maxsubid){
+ maxsubid = reto[i].subid;
+ }
+ if(reto[i].last_update > lastupdate){
+ lastupdate = reto[i].last_update;
+ }
+ }
+ ssubid = maxsubid;
+ }
+
+ j_ajax = null;
+ sub_refresh();
+ }
+ );
+ };
+ var sub_update = function(type){
+ if(type == 0){
+ while(topqueue.length > 0){
+ j_table.find('[subid="' + topqueue.pop() + '"]').css('opacity',0).slideDown('fast').fadeTo(100,1);
+ }
+ }else if(type == 1 && downblock == false){
+ downblock = true;
+ $.post('/toj/php/status.php',{'action':'get_submit',
+ 'data':JSON.stringify({
+ 'filter':{'uid':null,'result':null,'proid':null,'lang':null},
+ 'sort':{'score':null,'runtime':null,'memory':null,'subid':[0,esubid]},
+ 'wait':0,
+ 'count':50,
+ 'last_update':null
+ })}
+ ,function(res){
+ var i;
+ var reto;
+
+ if(res[0] == 'E'){
+ if(res != 'Eno_result'){
+ downblock = false;
+ }
+ }else{
+ reto = JSON.parse(res);
+ for(i = 0;i < reto.length;i++){
+ reto[i].submit_time = common.getdate(reto[i].submit_time);
+
+ j_item = sub_listnew(reto[i]);
+ j_table.append(j_item);
+ j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
+ }
+
+ if(lastupdate == null){
+ for(i = 0;i < reto.length;i++){
+ if(ssubid < reto[i].subid){
+ ssubid = reto[i].subid;
+ }
+ }
+
+ lastupdate = reto[0].last_update;
+ for(i = 1;i < reto.length;i++){
+ if(lastupdate < reto[i].last_update){
+ lastupdate = reto[i].last_update;
+ }
+ }
+
+ sub_refresh();
+
+ j_tab.on('scroll',function(e){
+ if(Math.floor(j_tab.scrollTop() / 32) < 10){
+ if(topflag == false){
+ topflag = true;
+ sub_update(0);
+ }
+ }else{
+ topflag = false;
+ }
+
+ if(Math.floor((j_table.height() - j_tab.scrollTop()) / 32) < 50){
+ sub_update(1);
+ }
+ });
+ }
+
+ esubid = reto[reto.length - 1].subid;
+ downblock = false;
+ }
+ }
+ );
+ }
+ };
+
+ that.__super(paobj);
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_tab);
+ refresh_flag = true;
+
+ sub_update(1);
+ subinfo_switch();
+ }else if(direct == 'out'){
+ that.fadeout(j_tab);
+ j_tab.off('scorll');
+ j_table.find('tr.item').remove();
+
+ if(j_ajax != null){
+ j_ajax.abort();
+ j_ajax = null;
+ }
+
+ refresh_flag = false;
+ j_ajax = null;
+ esubid = 2147483647;
+ lastupdate = null;
+ topflag = true;
+ topqueue = new Array;
+ downblock = false;
+ subid_curr = null;
+ }else if(direct == 'same'){
+ subinfo_switch();
+ }
+ };
+
+ j_table.on('mousedown',function(e){
+ return false;
+ });
+}; __extend(class_stat_allsub_tab,class_common_tab);
+
+var class_stat_subinfo_mbox = function(paobj){
+ var that = this;
+ var ori_prop = new Object;
+ var j_mbox = $('#index_mask > div.stat_mask > div.subinfo_mbox');
+ var subid = null;
+
+ that.subid = null;
+ that.smodname = null;
+ that.subo = null;
+
+ that.__super(paobj);
+
+ that.init = function(id){
+ subid = id;
+ };
+ that.switchchange = function(direct){
+ if(direct == 'in'){
+ $.post('/toj/php/status.php',{'action':'get_by_subid','data':JSON.stringify({'subid':subid})},function(res){
+ var reto;
+
+ if(res[0] != 'E'){
+ that.subid = subid;
+ reto = JSON.parse(res);
+ that.smodname = reto.smodname;
+ that.subo = reto;
+ delete that.subo.smodname;
+
+ j_mbox.addClass(that.smodname);
+
+ css = $('<link rel="stylesheet" type="text/css" href="/toj/smod/' + that.smodname + '/' + that.smodname + '.css">');
+ $('head').append(css);
+ css.ready(function(){
+ $.get('/toj/smod/' + that.smodname + '/' + that.smodname + '.html',{},function(res){
+ var j_h;
+ var j_button;
+
+ j_mbox.html(res);
+
+ j_h = $('<h2 style="padding:6px 0px 0px 0px;"></h2>');
+ j_h.text('SubID:' + that.subo.subid);
+ j_button = $('<button style="margin:6px 0px 0px 0px; float:right;">關閉</button>');
+ j_button.on('click',function(e){
+ common.hidembox('false');
+ });
+ j_mbox.prepend(j_h);
+ j_mbox.prepend(j_button);
+
+ $.getScript('/toj/smod/' + that.smodname + '/' + that.smodname + '.js',function(script,stat,res){
+ eval(that.smodname + '.init(that,j_mbox)');
+ that.export_switchchange('in');
+ });
+ });
+ });
+ }
+ });
+ }else if(direct == 'out'){
+ that.export_switchchange('out');
+
+ for(key in that){
+ if(!(key in ori_prop)){
+ delete that[key];
+ }
+ }
+
+ j_mbox.empty();
+ j_mbox.removeClass(that.smodname);
+ that.subid = null;
+ that.smodname = null;
+ that.subo = null;
+ }
+ };
+
+ for(key in that){
+ ori_prop[key] = true;
+ }
+}; __extend(class_stat_subinfo_mbox,class_common_mbox);
diff --git a/toj/jcs/user.css b/toj/jcs/user.css
new file mode 100644
index 0000000..171efaf
--- /dev/null
+++ b/toj/jcs/user.css
@@ -0,0 +1,175 @@
+div.user_page > div.main_tab > div.info_box{
+ width:256px;
+ height:100%;
+ background-color:#1C1C1C;
+ font-size:20px;
+ float:left;
+}
+div.user_page > div.main_tab > div.info_box > div.aboutme{
+ margin:6px 6px;
+ word-break:break-all;
+}
+div.user_page > div.main_tab > div.info_box > img.avatar{
+ width:100%;
+ display:block;
+}
+div.user_page > div.edit_tab > div.edit_box{
+ padding:64px 0px 64px 256px;
+}
+div.user_page > div.edit_tab > div.edit_box > img.avatar{
+ width:268px;
+ margin:0px 0px 16px 0px;
+ display:block;
+}
+div.user_page > div.edit_tab > div.edit_box > div.error{
+ margin:0px 0px 16px 0px;
+ font-size:16px;
+ color:#FFA0A0;
+}
+div.user_page > div.edit_tab > div.edit_box label{
+ font-size:16px;
+}
+div.user_page > div.edit_tab > div.edit_box input{
+ width:256px;
+ height:32px;
+ margin:0px 0px 16px 0px;
+ padding:0px 6px 0px 6px;
+ border-width:0px;
+ font-size:16px;
+ display:block;
+}
+div.user_page > div.mgsq_tab > div.in_box{
+ width:480px;
+ padding:0px 0px 64px 0px;
+ position:absolute;
+ top:64px;
+ left:256px;
+}
+div.user_page > div.mgsq_tab > div.out_box{
+ width:480px;
+ padding:0px 6px 64px 0px;
+ position:absolute;
+ top:64px;
+ left:752px;
+}
+div.user_page > div.mgsq_tab div.item{
+ margin:6px 0px 6px 0px;
+ padding:6px 6px;
+ font-size:16px;
+ cursor:pointer;
+}
+div.user_page > div.mgsq_tab div.item_s{
+ background-color:rgba(255,255,255,0.2);
+}
+div.user_page > div.mgsq_tab div:hover.item{
+ background-color:rgba(255,255,255,0.2);
+}
+div.user_page > div.mgsq_tab div.item > div.info{
+ width:100%;
+ height:32px;
+ line-height:32px;
+}
+div.user_page > div.mgsq_tab div.item > div.info > span.time{
+ height:32px;
+ font-size:14px;
+ line-height:32px;
+ text-align:right;
+ float:right;
+}
+div.user_page > div.mgsq_tab div.item > div.data{
+ width:100%;
+ height:32px;
+ margin:6px 0px 0px 0px;
+ display:none;
+}
+div.user_page > div.mgsq_tab div.item a{
+ height:100%;
+ text-decoration:none;
+ color:#E9E9E9;
+}
+div.user_page > div.mgsq_tab div.item a:hover{
+ text-decoration:underline;
+}
+div.user_page > div.mg_tab > div.left_box{
+ padding:64px 0px 0px 256px;
+ float:left;
+}
+div.user_mask > div.editsq_mbox{
+ width:31%;
+}
+div.user_mask > div.editsq_mbox > div.edit_box{
+ padding:64px 0px 64px 0px;
+}
+div.user_mask > div.editsq_mbox > div.edit_box > div.error{
+ margin:0px 0px 16px 0px;
+ font-size:16px;
+ color:#FFA0A0;
+}
+div.user_mask > div.editsq_mbox > div.edit_box label{
+ font-size:16px;
+}
+div.user_mask > div.editsq_mbox > div.edit_box input{
+ height:32px;
+ margin:0px 0px 16px 0px;
+ padding:0px 6px 0px 6px;
+ border-width:0px;
+ font-size:16px;
+ display:block;
+}
+div.user_mask > div.editsq_mbox > div.edit_box select{
+ height:32px;
+ margin:0px 0px 16px 0px;
+ border-width:0px;
+ font-size:16px;
+ display:block;
+}
+
+div.login_page > div.info_box{
+ width:31%;
+ margin:192px 0px 0px 19%;
+ float:left;
+}
+div.login_page > div.login_box{
+ width:31%;
+ margin:192px auto 0px auto;
+ float:left;
+}
+div.login_page > div.login_box > div.error{
+ margin:0px 0px 16px 0px;
+ font-size:16px;
+ color:#FFA0A0;
+}
+div.login_page > div.login_box > input{
+ width:256px;
+ height:32px;
+ margin:0px 0px 16px 0px;
+ padding:0px 6px 0px 6px;
+ border-width:0px;
+ font-size:16px;
+ display:block;
+}
+
+div.register_page > div.info_box{
+ width:31%;
+ margin:192px 0px 0px 19%;
+ float:left;
+}
+div.register_page > div.register_box{
+ width:31%;
+ margin:192px auto 0px auto;
+ float:left;
+}
+div.register_page > div.register_box > div.error{
+ margin:0px 0px 16px 0px;
+ font-size:16px;
+ color:#FFA0A0;
+}
+div.register_page > div.register_box > input{
+ width:256px;
+ height:32px;
+ margin:0px 0px 16px 0px;
+ padding:0px 6px 0px 6px;
+ border-width:0px;
+ font-size:16px;
+ display:block;
+}
diff --git a/toj/jcs/user.js b/toj/jcs/user.js
new file mode 100644
index 0000000..b8ffd3e
--- /dev/null
+++ b/toj/jcs/user.js
@@ -0,0 +1,1025 @@
+/*
+square state
+0 => wait
+1 => run
+2 => past
+*/
+
+var user = {
+ uid:null,
+ level:null,
+ username:null,
+ nickname:null,
+ avatar:null,
+ aboutme:null,
+ email:null,
+ sq_inlist:null,
+ loginchange:$.Callbacks(),
+ datachange:$.Callbacks(),
+
+ init:function(){
+ user.user_page = new class_user_page;
+ user.login_page = new class_login_page;
+ user.register_page = new class_register_page;
+
+ $('#index_panel > [page="logout"] > a.button').off('click').on('click',function(e){
+ var cookie;
+ var key;
+
+ cookie = common.getcookie();
+ for(key in cookie){
+ document.cookie = key + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/toj/';
+ }
+
+ location.href = '/toj/home/';
+ return false;
+ });
+ user.loginchange.add(function(login){
+ var j_notice;
+ var j_nickname;
+
+ j_notice = $('#index_head_notice');
+ j_nickname = $('#index_head_nickname > a.nickname')
+
+ if(login){
+ j_notice.show();
+ j_nickname.attr('href','/toj/user/' + user.uid + '/');
+ j_nickname.text(user.nickname);
+
+ index.showpanel('logout');
+ index.setpanel('user','/toj/user/' + user.uid + '/','個人');
+ index.showpanel('user');
+ }else{
+ j_notice.hide();
+ j_nickname.attr('href','');
+ j_nickname.text('');
+
+ index.hidepanel('logout');
+ index.hidepanel('user');
+ index.setpanel('user',null,'個人');
+ }
+ });
+ user.datachange.add(function(){
+ var i;
+ var j_ul;
+ var j_li;
+ var sqo;
+ var panelsq_listadd = function(j_ul,idx,sqid,sqname){
+ var j_li;
+ var j_a;
+
+ j_li = $(j_ul.find('li.button')[idx]);
+ if(j_li.length == 0){
+ j_li = $('<li class="button"><a class="button"></a></li>');
+ j_li.hide();
+ j_ul.append(j_li);
+ }
+
+ j_a = j_li.find('a.button');
+ j_a.attr('href','/toj/sq/' + sqid + '/pro/');
+ j_a.text(sqname);
+
+ j_li.show();
+ };
+
+ j_ul = $('#index_panel > ul.square_box');
+ j_ul.find('li.button').hide();
+ for(i = 0;i < user.sq_inlist.length;i++){
+ sqo = user.sq_inlist[i];
+ if(sqo.relationship != 1){
+ panelsq_listadd(j_ul,i,sqo.sqid,sqo.sqname);
+ }
+ }
+ });
+
+ user.updatedata(true);
+ },
+
+ updatedata:function(sync){
+ $.ajax({'url':'/toj/php/user.php',
+ 'type':'POST',
+ 'data':{'action':'view','data':JSON.stringify({'uid':null})},
+ 'async':!sync,
+ 'success':function(res){
+ var reto;
+ var old_uid;
+
+ old_uid = user.uid;
+ if(res[0] == 'E'){
+ user.uid = null;
+ user.level = null;
+ user.username = null;
+ user.nickname = null;
+ user.avatar = null;
+ user.aboutme = null;
+ user.email = null;
+ user.sq_inlist = null;
+
+ user.loginchange.fire(false);
+ }else{
+ reto = JSON.parse(res);
+ user.uid = reto.uid;
+ user.level = reto.level;
+ user.username = reto.username;
+ user.nickname = reto.nickname;
+ user.avatar = reto.avatar;
+ user.aboutme = reto.aboutme;
+ user.email = reto.email;
+
+ if(old_uid != user.uid){
+ user.loginchange.fire(true);
+ }
+
+ $.post('/toj/php/square.php',{'action':'get_entered_sq','data':JSON.stringify({'uid':user.uid})},function(res){
+ var i;
+ var reto;
+ var ts;
+ var sqlist;
+ var sqo;
+
+ if(res[0] == 'E'){
+ return;
+ }
+
+ reto = JSON.parse(res);
+ ts = common.getdate(reto.timestamp);
+ sqlist = reto.list;
+ for(i = 0;i < sqlist.length;i++){
+ sqo = sqlist[i];
+ sqo.state = 1;
+ if(sqo.start_time != null){
+ sqo.start_time = common.getdate(sqo.start_time);
+ if(ts < sqo.start_time){
+ sqo.state = 0;
+ }
+ }
+ if(sqo.end_time != null){
+ sqo.end_time = common.getdate(sqo.end_time);
+ if(sqo.end_time < ts){
+ sqo.state = 2;
+ }
+ }
+ }
+ user.sq_inlist = sqlist;
+
+ user.datachange.fire(true);
+ });
+ }
+ }
+ });
+ }
+};
+
+var class_user_page = function(){
+ var that = this;
+ var j_page = $('#index_page > [page="user"]');
+ var main_tab = new class_user_main_tab(that);
+ var edit_tab = new class_user_edit_tab(that);
+ var mgsq_tab = new class_user_mgsq_tab(that);
+ var mg_tab = new class_user_mg_tab(that);
+
+ that.__super();
+
+ that.editsq_mbox = new class_user_editsq_mbox(that);
+
+ that.uid = null;
+ that.nickname = null;
+ that.avatar = null;
+ that.aboutme = null;
+
+ that.urlchange = function(direct){
+ var uid;
+ var _check = function(){
+ uid = common.geturlpart()[1];
+ if(uid == ''){
+ if(user.uid == null){
+ common.pushurl('/toj/none/');
+ return false;
+ }
+ uid = user.uid;
+ common.replaceurl('/toj/user/' + uid + '/main/');
+ }
+ return true;
+ };
+ var _in = function(){
+ $.post('/toj/php/user.php',{'action':'view','data':JSON.stringify({'uid':uid})},function(res){
+ var reto;
+
+ if(res[0] == 'E'){
+ common.pushurl('/toj/none/');
+ }else{
+ reto = JSON.parse(res);
+ that.uid = reto.uid;
+ that.nickname = reto.nickname;
+ that.avatar = reto.avatar;
+ that.aboutme = reto.aboutme;
+
+ that.fadein(j_page);
+
+ index.settitle('TOJ-使用者');
+
+ that.addtab('main',main_tab);
+ index.addtab('main','/toj/user/' + that.uid + '/main/',that.nickname);
+
+ if(uid == user.uid){
+ that.addtab('mgsq',mgsq_tab);
+ index.addtab('mgsq','/toj/user/' + that.uid + '/mgsq/','你的方塊');
+ that.addtab('edit',edit_tab);
+ index.addtab('edit','/toj/user/' + that.uid + '/edit/','更改資料');
+
+ if((user.level & USER_LEVEL_SUPERADMIN) == USER_LEVEL_SUPERADMIN){
+ that.addtab('mg',mg_tab);
+ index.addtab('mg','/toj/user/' + that.uid + '/mg/','管理');
+ }
+ }
+
+ _change();
+ }
+ });
+ };
+ var _out = function(){
+ index.emptytab();
+ that.fadeout(j_page);
+ that.tab_urlchange(null);
+ that.uid = null;
+ };
+ var _change = function(){
+ var tabname;
+
+ tabname = common.geturlpart()[2];
+ if(!(tabname in that.tab_list)){
+ tabname = 'main';
+ common.replaceurl('/toj/user/' + that.uid + '/main/');
+ }
+ that.tab_urlchange(tabname);
+ };
+
+ if(direct == 'in'){
+ if(_check()){
+ _in();
+ }
+ }else if(direct == 'out'){
+ _out();
+ }else if(direct = 'same'){
+ if(_check()){
+ if(uid != that.uid || that.forceupdate){
+ that.forceupdate = false;
+ _out();
+ _in();
+ }else{
+ _change();
+ }
+ }
+ }
+ };
+
+ common.addpage('user',that);
+}; __extend(class_user_page,class_common_page);
+
+var class_user_main_tab = function(paobj){
+ var that = this;
+ var j_tab = $('#index_page > [page="user"] > [tab="main"]');
+
+ that.__super(paobj);
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_tab);
+
+ if(user.user_page.avatar == ''){
+ j_tab.find('div.info_box > img.avatar').attr('src','http://i.imgur.com/ykkQD.png');
+ }else{
+ j_tab.find('div.info_box > img.avatar').attr('src',that.paobj.avatar);
+ }
+ j_tab.find('div.info_box > div.aboutme').text(that.paobj.aboutme);
+ }else if(direct == 'out'){
+ that.fadeout(j_tab);
+ }
+ };
+}; __extend(class_user_main_tab,class_common_tab);
+
+var class_user_edit_tab = function(paobj){
+ var that = this;
+ var j_tab = $('#index_page > [page="user"] > [tab="edit"]');
+
+ that.__super(paobj);
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_tab);
+
+ j_tab.find('div.edit_box > [name="nickname"]').val(user.nickname);
+ j_tab.find('div.edit_box > [name="avatar"]').val(user.avatar);
+ if(user.avatar == ''){
+ j_tab.find('div.edit_box > img.avatar').attr('src','http://i.imgur.com/ykkQD.png');
+ }else{
+ j_tab.find('div.edit_box > img.avatar').attr('src',user.avatar);
+ }
+ j_tab.find('div.edit_box > [name="aboutme"]').val(user.aboutme);
+ j_tab.find('div.edit_box > [name="email"]').val(user.email);
+ }else if(direct == 'out'){
+ that.fadeout(j_tab);
+ j_tab.find('div.edit_box > input').val('');
+ j_tab.find('div.edit_box > img.avatar').attr('src',null);
+ j_tab.find('div.edit_box > div.error').text('');
+ }
+ };
+
+ j_tab.find('div.edit_box > [name="avatar"]').change(function(e){
+ var avatar;
+
+ avatar = $(this).val();
+ if(avatar == ''){
+ j_tab.find('div.edit_box > img.avatar').attr('src','http://i.imgur.com/ykkQD.png');
+ }else{
+ j_tab.find('div.edit_box > img.avatar').attr('src',avatar);
+ }('test')
+ });
+ j_tab.find('div.edit_box > button.submit').click(function(e){
+ var j_error;
+ var nickname;
+ var avatar;
+ var aboutme;
+ var email;
+ var password_old;
+ var password_new;
+ var password_repeat;
+ var data;
+
+ j_error = j_tab.find('div.edit_box > div.error');
+ nickname = j_tab.find('div.edit_box > [name="nickname"]').val();
+ avatar = j_tab.find('div.edit_box > [name="avatar"]').val();
+ aboutme = j_tab.find('div.edit_box > [name="aboutme"]').val();
+ email = j_tab.find('div.edit_box > [name="email"]').val();
+ password_old = j_tab.find('div.edit_box > [name="password_old"]').val();
+ password_new = j_tab.find('div.edit_box > [name="password_new"]').val();
+ password_repeat = j_tab.find('div.edit_box > [name="password_repeat"]').val();
+
+ data = {'nickname':nickname,'avatar':avatar,'aboutme':aboutme,'email':email};
+ if(password_old != '' || password_new != '' || password_repeat != ''){
+ if(password_new != password_repeat){
+ j_error.text('使用者密碼不相同');
+ return;
+ }
+ data.oldpw = password_old;
+ data.password = password_new;
+ }
+
+ $.post('/toj/php/user.php',{'action':'update','data':JSON.stringify(data)},function(res){
+ if(res[0] == 'E'){
+ switch(res){
+ case 'Epassword_too_short':
+ j_error.text('使用者密碼太短');
+ break;
+ case 'Epassword_too_long':
+ j_error.text('使用者密碼太長');
+ break;
+ case 'Enickname_too_short':
+ j_error.text('暱稱太短');
+ break;
+ case 'Enickname_too_long':
+ j_error.text('暱稱太長');
+ break;
+ case 'Eold_password_not_match':
+ j_error.text('舊使用者密碼錯誤');
+ break;
+ case 'Eempty_email':
+ j_error.text('電子郵件不能爲空');
+ break;
+ case 'Eemail_too_long':
+ j_error.text('電子郵件太長');
+ break;
+ default:
+ j_error.text('更新錯誤');
+ break;
+ }
+ }else{
+ user.updatedata(true);
+
+ that.paobj.forceupdate = true;
+ common.pushurl('/toj/user/' + user.uid + '/main/');
+ }
+ });
+ });
+ j_tab.find('div.edit_box > button.cancel').click(function(e){
+ common.pushurl('/toj/user/' + user.uid + '/main/');
+ });
+}; __extend(class_user_edit_tab,class_common_tab);
+
+var class_user_mgsq_tab = function(paobj){
+ var that = this;
+ var j_tab = $('#index_page > [page="user"] > [tab="mgsq"]');
+
+ var sq_join = function(sqid){
+ $.post('/toj/php/square.php',{'action':'add_user','data':JSON.stringify({'uid':user.uid,'sqid':sqid})},function(res){
+ if(res[0] != 'E'){
+ sq_update();
+ }
+ });
+ };
+ var sq_quit = function(sqid){
+ $.post('/toj/php/square.php',{'action':'delete_user','data':JSON.stringify({'uid':user.uid,'sqid':sqid})},function(res){
+ if(res[0] != 'E'){
+ sq_update();
+ }
+ });
+ };
+ var sq_listset = function(j_item,sqo){
+ var j_info;
+ var j_data;
+ var j_a;
+ var j_button;
+
+ j_info = j_item.find('div.info');
+ j_data = j_item.find('div.data');
+ j_data.empty();
+
+ j_item.attr('sqid',sqo.sqid);
+
+ j_a = j_info.find('span.name > a');
+ j_a.attr('href','/toj/sq/' + sqo.sqid + '/pro/');
+ j_a.text(sqo.sqname);
+
+ if(sqo.end_time == null){
+ j_info.find('span.time').text('');
+ }else{
+ j_info.find('span.time').text(common.getdatestring(sqo.start_time,false) + ' > ' + common.getdatestring(sqo.end_time,false));
+ }
+
+ if(sqo.relationship == 3 || (user.level & USER_LEVEL_SUPERADMIN) == USER_LEVEL_SUPERADMIN){
+ j_button = $('<button style="margin:0px 6px 0px 0px;">管理</button>');
+ j_button.on('click',function(e){
+ that.paobj.editsq_mbox.init('edit',sqo);
+ common.showmbox(that.paobj.editsq_mbox).done(sq_update);
+ return false;
+ });
+ j_data.append(j_button);
+ }
+
+ j_button = $('<button></button>');
+ if(sqo.relationship == 0){
+ if(sqo.publicity == 2 && (user.level & USER_LEVEL_SUPERADMIN) != USER_LEVEL_SUPERADMIN){
+ j_button.text('申請');
+ }else{
+ j_button.text('加入');
+ }
+ j_button.off('click').on('click',function(e){
+ sq_join(sqo.sqid);
+ return false;
+ });
+ }else{
+ if(sqo.relationship == 1 && (user.level & USER_LEVEL_SUPERADMIN) != USER_LEVEL_SUPERADMIN){
+ j_button.text('取消申請');
+ }else{
+ j_button.text('退出');
+ }
+ j_button.on('click',function(e){
+ sq_quit(sqo.sqid);
+ return false;
+ });
+ }
+ j_data.append(j_button);
+
+ j_item.off('click').on('click',function(e){
+ if(j_data.is(':visible')){
+ j_item.removeClass('item_s');
+ j_data.stop().fadeTo(100,0).slideUp('fast');
+ }else{
+ j_item.addClass('item_s');
+ j_data.stop().css('opacity',1).slideDown('fast');
+ }
+ });
+ };
+ var sq_listnew = function(sqo){
+ var j_item;
+ var j_info;
+ var j_data;
+
+ j_item = $('<div class="item"></div>');
+ j_info = $('<div class="info"><span class="name"><a></a></span><span class="time"></span></div>');
+ j_item.append(j_info);
+ j_data = $('<div class="data"></div>');
+ j_item.append(j_data);
+
+ sq_listset(j_item,sqo);
+
+ return j_item;
+ };
+ var sq_update = function(){
+ var _updatelist = function(j_list,sqlist){
+ var i;
+ var j;
+
+ var j_divs;
+ var j_last;
+ var j_item;
+ var oldhash;
+
+ j_divs = j_list.children('div.item');
+ oldhash = new Array();
+ for(i = 0;i < j_divs.length;i++){
+ oldhash[$(j_divs[i]).attr('sqid')] = i;
+ }
+
+ j = 0;
+ j_last = null;
+ for(i = 0;i < sqlist.length;i++){
+ sqo = sqlist[i];
+ if(sqo.sqid in oldhash){
+ for(;j < oldhash[sqo.sqid];j++){
+ j_item = $(j_divs[j]);
+ j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove();});
+ }
+ j_item = $(j_divs[j]);
+ j++;
+
+ sq_listset(j_item,sqo);
+ j_last = j_item;
+ }else{
+ j_item = sq_listnew(sqo);
+ j_item.hide();
+ if(j_last == null){
+ j_list.prepend(j_item);
+ j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
+ }else{
+ j_item.insertAfter(j_last);
+ j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
+ }
+ j_last = j_item;
+ }
+ }
+ for(;j < j_divs.length;j++){
+ j_item = $(j_divs[j]);
+ j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove();});
+ }
+ };
+
+ user.datachange.add(function(){
+ var i;
+ var sqo;
+ var sqwait;
+ var sqrun;
+ var sqpast;
+
+ var j_wait;
+ var j_run;
+ var j_past;
+
+ user.datachange.remove(arguments.callee);
+
+ sqwait = new Array();
+ sqrun = new Array();
+ sqpast = new Array();
+ for(i = 0;i < user.sq_inlist.length;i++){
+ sqo = user.sq_inlist[i];
+ switch(sqo.state){
+ case 0:
+ sqwait.push(sqo);
+ break;
+ case 1:
+ sqrun.push(sqo);
+ break;
+ case 2:
+ sqpast.push(sqo);
+ break;
+ };
+ }
+
+ j_wait = j_tab.find('div.in_box > div.wait');
+ j_run = j_tab.find('div.in_box > div.run');
+ j_past = j_tab.find('div.in_box > div.past');
+
+ _updatelist(j_wait,sqwait);
+ _updatelist(j_run,sqrun);
+ _updatelist(j_past,sqpast);
+ });
+ user.updatedata(false);
+
+ $.post('/toj/php/square.php',{'action':'get_available_sq','data':null},function(res){
+ var i;
+ var reto;
+ var ts;
+ var sqlist;
+ var sqo;
+ var sqwait;
+ var sqrun;
+ var sqpast;
+
+ var j_wait;
+ var j_run;
+ var j_past;
+
+ if(res[0] == 'E'){
+ return;
+ }
+
+ reto = JSON.parse(res);
+ ts = common.getdate(reto.timestamp);
+ sqlist = reto.list;
+ sqwait = new Array();
+ sqrun = new Array();
+ sqpast = new Array();
+ for(i = 0;i < sqlist.length;i++){
+ sqo = sqlist[i];
+ sqo.relationship = 0;
+ sqo.state = 1;
+ if(sqo.start_time != null){
+ sqo.start_time = common.getdate(sqo.start_time);
+ if(ts < sqo.start_time){
+ sqo.state = 0;
+ }
+ }
+ if(sqo.end_time != null){
+ sqo.end_time = common.getdate(sqo.end_time);
+ if(sqo.end_time < ts){
+ sqo.state = 2;
+ }
+ }
+
+ switch(sqo.state){
+ case 0:
+ sqwait.push(sqo);
+ break;
+ case 1:
+ sqrun.push(sqo);
+ break;
+ case 2:
+ sqpast.push(sqo);
+ break;
+ }
+ }
+
+ j_wait = j_tab.find('div.out_box > div.wait');
+ j_run = j_tab.find('div.out_box > div.run');
+ j_past = j_tab.find('div.out_box > div.past');
+
+ _updatelist(j_wait,sqwait);
+ _updatelist(j_run,sqrun);
+ _updatelist(j_past,sqpast);
+ });
+ }
+
+ that.__super(paobj);
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_tab);
+ sq_update();
+ }else if(direct == 'out'){
+ that.fadeout(j_tab);
+ j_tab.find('div.in_box > div > div').remove();
+ j_tab.find('div.out_box > div > div').remove();
+ }
+ };
+}; __extend(class_user_mgsq_tab,class_common_tab);
+
+var class_user_mg_tab = function(paobj){
+ var that = this;
+ var j_tab = $('#index_page > [page="user"] > [tab="mg"]');
+
+ that.__super(paobj);
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_tab);
+ }else if(direct == 'out'){
+ that.fadeout(j_tab);
+ }
+ };
+
+ j_tab.find('button.newsq').on('click',function(e){
+ that.paobj.editsq_mbox.init('new');
+ common.showmbox(that.paobj.editsq_mbox);
+ });
+}; __extend(class_user_mg_tab,class_common_tab);
+
+var class_user_editsq_mbox = function(paobj){
+ var that = this;
+ var j_mbox = $('#index_mask > div.user_mask > div.editsq_mbox');
+ var action = null;
+ var sqid;
+
+ that.__super(paobj);
+
+ that.init = function(act,sqo){
+ action = act;
+ if(action == 'edit'){
+ sqid = sqo.sqid;
+
+ console.log(sqo);
+ j_mbox.find('[name="sqname"]').val(sqo.sqname);
+ j_mbox.find('[name="sqmodname"]').val(sqo.sqmodname);
+ j_mbox.find('[name="publicity"]').val(sqo.publicity);
+ if(sqo.end_time == null){
+ j_mbox.find('[name="infinite"]').val(1);
+ }else{
+ j_mbox.find('[name="infinite"]').val(2);
+ j_mbox.find('div.time').show();
+ j_mbox.find('[name="s_year"]').val(sqo.start_time.getFullYear());
+ j_mbox.find('[name="s_month"]').val(sqo.start_time.getMonth() + 1);
+ j_mbox.find('[name="s_day"]').val(sqo.start_time.getDate());
+ j_mbox.find('[name="s_hr"]').val(sqo.start_time.getHours());
+ j_mbox.find('[name="s_min"]').val(sqo.start_time.getMinutes());
+ j_mbox.find('[name="e_year"]').val(sqo.end_time.getFullYear());
+ j_mbox.find('[name="e_month"]').val(sqo.end_time.getMonth() + 1);
+ j_mbox.find('[name="e_day"]').val(sqo.end_time.getDate());
+ j_mbox.find('[name="e_hr"]').val(sqo.end_time.getHours());
+ j_mbox.find('[name="e_min"]').val(sqo.end_time.getMinutes());
+ }
+ j_mbox.find('button.delete').show();
+ }
+ };
+ that.switchchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_mbox);
+ }else if(direct == 'out'){
+ that.fadeout(j_mbox);
+ j_mbox.find('input').val('');
+ j_mbox.find('[name="publicity"]').val(3);
+ j_mbox.find('[name="infinite"]').val(1);
+ j_mbox.find('div.time').hide();
+ j_mbox.find('button.delete').hide();
+ j_mbox.find('div.error').text('');
+ }
+ };
+
+ j_mbox.find('[name="infinite"]').on('change',function(e){
+ if($(this).val() == 1){
+ j_mbox.find('div.time').hide();
+ }else{
+ j_mbox.find('div.time').show();
+ }
+ });
+ j_mbox.find('button.delete').on('click',function(e){
+ if(confirm('確定刪除方塊?')){
+ $.post('/toj/php/square.php',{'action':'delete_sq','data':JSON.stringify({'sqid':sqid})},function(res){
+ var j_error;
+
+ if(res[0] == 'E'){
+ j_error = j_mbox.find('div.error');
+ switch(res){
+ case 'Eno_login':
+ j_error.text('未登入');
+ case 'Epermission_denied':
+ j_error.text('權限不足');
+ break;
+ default:
+ j_error.text('其他錯誤');
+ break;
+ }
+ }else{
+ common.hidembox(true);
+ }
+ });
+ }
+ });
+ j_mbox.find('button.submit').on('click',function(e){
+ var sqname;
+ var sqmodname;
+ var publicity;
+ var start_time;
+ var end_time;
+ var j_error;
+
+ sqname = j_mbox.find('[name="sqname"]').val();
+ sqmodname = j_mbox.find('[name="sqmodname"]').val();
+ publicity = parseInt(j_mbox.find('[name="publicity"]').val());
+ if(j_mbox.find('[name="infinite"]').val() == 1){
+ start_time = null;
+ end_time = null;
+ }else{
+ start_time = j_mbox.find('[name="s_year"]').val() + '-' +
+ j_mbox.find('[name="s_month"]').val() + '-' +
+ j_mbox.find('[name="s_day"]').val() + ' ' +
+ j_mbox.find('[name="s_hr"]').val() + ':' +
+ j_mbox.find('[name="s_min"]').val();
+ end_time = j_mbox.find('[name="e_year"]').val() + '-' +
+ j_mbox.find('[name="e_month"]').val() + '-' +
+ j_mbox.find('[name="e_day"]').val() + ' ' +
+ j_mbox.find('[name="e_hr"]').val() + ':' +
+ j_mbox.find('[name="e_min"]').val();
+ }
+
+ j_error = j_mbox.find('div.error');
+ if(action == 'new'){
+ $.post('/toj/php/square.php',{'action':'add_sq','data':JSON.stringify({'sqname':sqname,'sqmodname':sqmodname,'publicity':publicity,'start_time':start_time,'end_time':end_time})},function(res){
+ if(res[0] == 'E'){
+ switch(res){
+ case 'Eno_login':
+ j_error.text('未登入');
+ case 'Epermission_denied':
+ j_error.text('權限不足');
+ break;
+ case 'Esqname_too_short':
+ j_error.text('方塊名稱太短');
+ break;
+ case 'Esqname_too_long':
+ j_error.text('方塊名稱太長');
+ break;
+ case 'Esqmodname_empty':
+ j_error.text('模組名稱不能爲空');
+ break;
+ default:
+ j_error.text('其他錯誤');
+ break;
+ }
+ }else{
+ common.hidembox(true);
+ }
+ });
+ }else if(action == 'edit'){
+ $.post('/toj/php/square.php',{'action':'edit_sq','data':JSON.stringify({'sqid':sqid,'sqname':sqname,'sqmodname':sqmodname,'publicity':publicity,'start_time':start_time,'end_time':end_time})},function(res){
+ if(res[0] == 'E'){
+ switch(res){
+ case 'Eno_login':
+ j_error.text('未登入');
+ case 'Epermission_denied':
+ j_error.text('權限不足');
+ break;
+ case 'Esqname_too_short':
+ j_error.text('方塊名稱太短');
+ break;
+ case 'Esqname_too_long':
+ j_error.text('方塊名稱太長');
+ break;
+ default:
+ j_error.text('其他錯誤');
+ break;
+ }
+ }else{
+ user.updatedata(false);
+ common.hidembox(true);
+ }
+ });
+ }
+ });
+ j_mbox.find('button.cancel').on('click',function(e){
+ common.hidembox(false);
+ });
+}; __extend(class_user_editsq_mbox,class_common_mbox);
+
+var class_login_page = function(){
+ var that = this;
+ var j_page = $('#index_page > [page="login"]');
+
+ that.__super();
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_page);
+ index.settitle('TOJ-登入');
+ j_page.find('div.login_box [name="username"]').focus();
+ }else if(direct == 'out'){
+ that.fadeout(j_page);
+ j_page.find('div.login_box > div.error').text('');
+ j_page.find('div.login_box > input').val('');
+ }
+ };
+
+ j_page.find('div.login_box > input').keypress(function(e){
+ if(e.which == 13){
+ j_page.find('div.login_box > button').click();
+ }
+ });
+
+ j_page.find('div.login_box > button').click(function(e){
+ var j_error;
+ var username;
+ var password;
+ var data;
+
+ j_error = j_page.find('div.login_box > div.error');
+ username = j_page.find('div.login_box [name="username"]').val();
+ password = j_page.find('div.login_box [name="password"]').val();
+
+ if(username == '' || password == ''){
+ j_error.text('欄位不可為空');
+ return;
+ }
+
+ data = {'username':username,'password':password};
+ $.post('/toj/php/user.php',{'action':'login','data':JSON.stringify(data)},function(res){
+ if(res[0] == 'E'){
+ j_error.text('登入錯誤');
+ }else{
+ user.updatedata(true);
+ common.prevurl('register');
+ }
+ });
+ });
+
+ user.loginchange.add(function(login){
+ if(login){
+ that.urlchange('out');
+ common.removepage('login');
+ index.hidepanel('login');
+ }else{
+ common.addpage('login',that);
+ index.showpanel('login');
+ }
+ });
+}; __extend(class_login_page,class_common_page);
+
+var class_register_page = function(){
+ var that = this;
+ var j_page = $('#index_page > [page="register"]');
+
+ that.__super();
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_page);
+ index.settitle('TOJ-註冊');
+ j_page.find('div.register_box [name="username"]').focus();
+ }else if(direct == 'out'){
+ that.fadeout(j_page);
+ j_page.find('div.register_box > div.error').text('');
+ j_page.find('div.register_box > div.register_box > input').val('');
+ j_page.find('div.register_box > div.register_box > div.cover').show();
+ }
+ };
+
+ j_page.find('div.register_box > input').keypress(function(e){
+ if(e.which == 13){
+ j_page.find('div.register_box > button').click();
+ }
+ });
+
+ j_page.find('div.register_box > button').click(function(e){
+ var j_error;
+ var username;
+ var password;
+ var password_repeat;
+ var nickname;
+ var email;
+ var data;
+
+ j_error = j_page.find('div.register_box > div.error');
+ username = j_page.find('div.register_box [name="username"]').val();
+ password = j_page.find('div.register_box [name="password"]').val();
+ password_repeat = j_page.find('div.register_box [name="password_repeat"]').val();
+ nickname = j_page.find('div.register_box [name="nickname"]').val();
+ email = j_page.find('div.register_box [name="email"]').val();
+
+ if(username == '' || password == '' || password_repeat == '' || nickname == '' || email == ''){
+ j_error.text('欄位不可為空');
+ return;
+ }
+ if(password != password_repeat){
+ j_error.text('使用者密碼不相同');
+ return;
+ }
+
+ data = {'username':username,'password':password,'nickname':nickname,'email':email};
+ $.post('/toj/php/user.php',{'action':'register','data':JSON.stringify(data)},function(res){
+ if(res[0] == 'E'){
+ switch(res){
+ case 'Eusername_too_short':
+ j_error.text('使用者名稱太短');
+ break;
+ case 'Eusername_too_long':
+ j_error.text('使用者名稱太長');
+ break;
+ case 'Epassword_too_short':
+ j_error.text('使用者密碼太短');
+ break;
+ case 'Epassword_too_long':
+ j_error.text('使用者密碼太長');
+ break;
+ case 'Enickname_too_short':
+ j_error.text('暱稱太短');
+ break;
+ case 'Enickname_too_long':
+ j_error.text('暱稱太長');
+ break;
+ case 'Eusername_exists':
+ j_error.text('使用者名稱已存在');
+ break;
+ case 'Eempty_email':
+ j_error.text('電子郵件不能爲空');
+ break;
+ case 'Eemail_too_long':
+ j_error.text('電子郵件太長');
+ break;
+ default:
+ j_error.text('註冊錯誤');
+ break;
+ }
+ }else{
+ user.updatedata(true);
+ common.prevurl('login');
+ }
+ });
+ });
+
+ user.loginchange.add(function(login){
+ if(login){
+ that.urlchange('out');
+ common.removepage('register');
+ index.hidepanel('register');
+ }else{
+ common.addpage('register',that);
+ index.showpanel('register');
+ }
+ });
+}; __extend(class_register_page,class_common_page);
diff --git a/toj/php/_json.php b/toj/php/_json.php
new file mode 100644
index 0000000..b3c443e
--- /dev/null
+++ b/toj/php/_json.php
@@ -0,0 +1,3 @@
+<?php
+echo json_encode("#include <stdio.h>\nint main(){while(scanf(\"%d%d\", &a, &b)==2)printf(\"%d\n\", a+b); return 0;}\n");
+?>
diff --git a/toj/php/_test.php b/toj/php/_test.php
new file mode 100644
index 0000000..5ce8271
--- /dev/null
+++ b/toj/php/_test.php
@@ -0,0 +1,20 @@
+<form action="notice.php" method=post>
+ <input type='hidden' value='{"uid":111}' name='data'>
+ <input type='hidden' value='count' name='action'>
+ <input type='submit' value='ti jiao count'>
+</form>
+<form action="notice.php" method=post>
+ <input type='text' value='{"uid":111}' name='data'>
+ <input type='hidden' value='get' name='action'>
+ <input type='submit' value='ti jiao get'>
+</form>
+<form action="notice.php" method=post>
+ <input type='hidden' value='{"uid":111}' name='data'>
+ <input type='hidden' value='clear' name='action'>
+ <input type='submit' value='ti jiao clear'>
+</form>
+<form action="notice.php" method=post>
+ <input type='text' value='{"uid":111,"type":1,"value":111,"context":"aaaaaa"}' name='data'>
+ <input type='hidden' value='add' name='action'>
+ <input type='submit' value='ti jiao add'>
+</form>
diff --git a/toj/php/common.inc.php b/toj/php/common.inc.php
new file mode 100644
index 0000000..d31a596
--- /dev/null
+++ b/toj/php/common.inc.php
@@ -0,0 +1,7 @@
+<?php
+
+date_default_timezone_set('Asia/Taipei');
+
+require('connect.inc.php');
+
+?>
diff --git a/toj/php/connect.inc.php b/toj/php/connect.inc.php
new file mode 100644
index 0000000..3eebe89
--- /dev/null
+++ b/toj/php/connect.inc.php
@@ -0,0 +1,40 @@
+<?php
+
+define('DB_NAME','xxxxx');
+define('DB_USER','xxxxx');
+define('DB_PASSWORD','xxxxx');
+define('SEC_SALT','xxxxx');
+
+define('SMTP_HOST','xxxxx');
+define('SMTP_USER','xxxxx');
+define('SMTP_PASS','xxxxx');
+
+const CENTER_SOCKET_PORT = 2501;
+
+function sec_is_login()
+{
+ if(!isset($_COOKIE['uid']) || !isset($_COOKIE['usec'])){
+ return false;
+ }
+
+ $userid = $_COOKIE['uid'];
+ $usersec = $_COOKIE['usec'];
+
+ if($userid == '' || $usersec == '' || strval(intval($userid)) != $userid || hash('sha512',$userid.SEC_SALT) != $usersec){
+ return false;
+ }
+
+ return true;
+}
+
+function db_connect($dbn = DB_NAME)
+{
+ return pg_connect('host=localhost port=5432 dbname='.$dbn.' user='.DB_USER.' password='.DB_PASSWORD);
+}
+
+function db_close($sqlcx)
+{
+ pg_close($sqlcx);
+}
+
+?>
diff --git a/toj/php/event.inc.php b/toj/php/event.inc.php
new file mode 100644
index 0000000..9d2a23c
--- /dev/null
+++ b/toj/php/event.inc.php
@@ -0,0 +1,71 @@
+<?php
+class event
+{
+ private static $white_list;
+
+ private static function init()
+ {
+ event::$white_list = array('10.8.0.2');
+ }
+
+ // execute function $name in file $fname
+ // if want to call a function of a class, have 2 choice:
+ // 1. pass an array as $name, put every level of class in it, like:
+ // A::B::C() should be passed like array("A", "B", "C").
+ // 2. pass a string with :: directly, it will be automatically
+ // translated.
+ // return value will be FALSE on failure, return value of target
+ // function otherwise. NULL when no return value.
+ public static function exec_func($fname, $name, $arg)
+ {
+ if(!file_exists($fname))
+ {
+ return false;
+ }
+ require_once($fname);
+ if(is_string($name) && strpos($name, ":") !== FALSE)
+ {
+ $name = preg_split("/::/", $name);
+ }
+ if(is_string($name) && !is_callable($name))
+ {
+ return false;
+ }
+ if(is_array($name) && !is_callable(join($name, "::")))
+ {
+ return false;
+ }
+ if($arg == NULL)
+ {
+ $res = call_user_func($name);
+ }
+ else
+ {
+ $res = call_user_func_array($name, $arg);
+ }
+ if($res === false)
+ {
+ return false;
+ }
+ return $res;
+ }
+
+ public static function validate_ip()
+ {
+ event::init();
+ if (!empty($_SERVER['HTTP_CLIENT_IP']))
+ {
+ $ip=$_SERVER['HTTP_CLIENT_IP'];
+ }
+ else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
+ {
+ $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
+ }
+ else
+ {
+ $ip=$_SERVER['REMOTE_ADDR'];
+ }
+ return in_array($ip, event::$white_list);
+ }
+}
+?>
diff --git a/toj/php/event.php b/toj/php/event.php
new file mode 100644
index 0000000..e121287
--- /dev/null
+++ b/toj/php/event.php
@@ -0,0 +1,24 @@
+<?php
+ require_once('event.inc.php');
+ if (!empty($_SERVER['HTTP_CLIENT_IP']))
+ $ip=$_SERVER['HTTP_CLIENT_IP'];
+ else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
+ $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
+ else
+ $ip=$_SERVER['REMOTE_ADDR'];
+ if(!event::validate_ip())
+ {
+ exit;
+ }
+ $fname = $_POST['fname'];
+ $name = $_POST['name'];
+ $arg = json_decode($_POST['arg']);
+ if(event::exec_func($fname, $name, $arg) === false)
+ {
+ echo "false";
+ }
+ else
+ {
+ echo "true";
+ }
+?>
diff --git a/toj/php/event_exec.cpp b/toj/php/event_exec.cpp
new file mode 100644
index 0000000..25d7944
--- /dev/null
+++ b/toj/php/event_exec.cpp
@@ -0,0 +1,89 @@
+#include "event_exec.h"
+
+#define EVENT_BUFLEN 1005
+#define EVENT_URL "http://10.8.0.2/toj/php/event.php"
+
+struct event_handle
+{
+ int init, plen, blen;
+ char *post, *buf;
+ pthread_mutex_t mutex;
+ CURL *handle;
+};
+
+static struct event_handle conn;
+
+size_t event_write_cb(void *in, size_t siz, size_t nb, void *buf)
+{
+ int len;
+ len = siz*nb+1;
+ if(len > conn.blen)
+ {
+ len = conn.blen-1;
+ }
+ memcpy(buf, in, len);
+ ((char*)buf)[len] = 0;
+ return siz*nb;
+}
+
+int event_init()
+{
+ if(conn.init)
+ {
+ return 0;
+ }
+ conn.plen = conn.blen = EVENT_BUFLEN;
+ conn.post = (char*)malloc(EVENT_BUFLEN);
+ conn.buf = (char*)malloc(EVENT_BUFLEN);
+ curl_global_init(CURL_GLOBAL_ALL);
+ conn.handle = curl_easy_init();
+ curl_easy_setopt(conn.handle, CURLOPT_URL, EVENT_URL);
+ curl_easy_setopt(conn.handle, CURLOPT_WRITEFUNCTION, event_write_cb);
+ curl_easy_setopt(conn.handle, CURLOPT_WRITEDATA, conn.buf);
+ pthread_mutex_init(&conn.mutex, NULL);
+ conn.init = 1;
+ return 1;
+}
+
+int event_exec(const char *fname, const char *name, const char *arg)
+{
+ int res, len;
+ char *t;
+ event_init();
+ if(pthread_mutex_lock(&conn.mutex) == 0)
+ {
+ len = 0;
+ len += strlen(fname)+6;
+ len += strlen(name)+6;
+ len += strlen(arg)+6;
+ if(len > conn.plen)
+ {
+ t = (char*)malloc(len);
+ if(!t)
+ {
+ pthread_mutex_unlock(&conn.mutex);
+ return 0;
+ }
+ free(conn.post);
+ conn.post = t;
+ conn.plen = len;
+ }
+ sprintf(conn.post, "fname=%s&name=%s&arg=%s", fname, name, arg);
+ curl_easy_setopt(conn.handle, CURLOPT_POSTFIELDS, conn.post);
+ res = curl_easy_perform(conn.handle);
+ if(res)
+ {
+ pthread_mutex_unlock(&conn.mutex);
+ return 0;
+ }
+ fprintf(stderr, "%s\n", conn.buf);
+ if(!strcmp(conn.buf, "true"))
+ {
+ pthread_mutex_unlock(&conn.mutex);
+ return 1;
+ }
+
+ pthread_mutex_unlock(&conn.mutex);
+ }
+ return 0;
+}
diff --git a/toj/php/event_exec.h b/toj/php/event_exec.h
new file mode 100644
index 0000000..aec1acb
--- /dev/null
+++ b/toj/php/event_exec.h
@@ -0,0 +1,12 @@
+#ifndef EVENT_EXEC
+#define EVENT_EXEC
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <curl/curl.h>
+#include <pthread.h>
+
+int event_exec(const char *fname, const char *name, const char *arg);
+
+#endif
diff --git a/toj/php/notice.inc.php b/toj/php/notice.inc.php
new file mode 100644
index 0000000..dbf47cc
--- /dev/null
+++ b/toj/php/notice.inc.php
@@ -0,0 +1,244 @@
+<?php
+require_once('common.inc.php');
+require_once('user.inc.php');
+
+const NOTICE_DEF_LIM = 5;
+const NOTICE_MAX_LIM = 30;
+
+const NOTICE_ACT_CNT = 1;
+const NOTICE_ACT_NEW = 2;
+const NOTICE_ACT_OLD = 4;
+
+const NOTICE_TYP_USR = 1;
+const NOTICE_TYP_PRO = 2;
+const NOTICE_TYP_SQR = 3;
+const NOTICE_TYP_ALL = 255;
+
+class notice
+{
+ private static function ins_uid($sqlc, $uid)
+ {
+ $sqlstr = 'INSERT INTO "notice_cache" ("uid", "tim", "cnt", "tmp", "rsv") VALUES ($1, $2, $3, $4, $5) RETURNING *;';
+ $sqlarr = array($uid, date("Y-m-d H:i:s"), 0, "0", "0");
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr);
+ pg_free_result($sqlr);
+ return $ret;
+ }
+
+ public static function is_match($sqlc, $uid, &$not)
+ {
+ if($not->typ == NOTICE_TYP_ALL)
+ {
+ return true;
+ }
+ if($not->typ == NOTICE_TYP_USR)
+ {
+ return $uid == intval($not->val);
+ }
+ require_once('event.inc.php');
+ if($not->typ == NOTICE_TYP_PRO)
+ {
+ if(!event::exec_func('problem.inc.php', 'problem::is_available', array($sqlc, $not->val, $uid)))
+ {
+ return false;
+ }
+ return true;
+ }
+ else if($not->typ == NOTICE_TYP_SQR)
+ {
+ $ret = event::exec_func('square.inc.php', 'square::get_user_relationship', array($sqlc, $uid, $not->val));
+ if($ret >= SQUARE_USER_ACTIVE)
+ {
+ return true;
+ }
+ return false;
+ }
+ return false;
+ }
+
+ private static function update($sqlc, $uid, &$tar, &$arr)
+ {
+ if(count($arr) <= 0)
+ {
+ return false;
+ }
+ $sqlstr = 'UPDATE "notice_cache" SET "tmp"=$1, "cnt"=$2, "tim"=$4 WHERE "uid"=$3 RETURNING *;';
+ $sqlarr = array($arr[0], intval($tar->cnt)+count($arr), $uid, date('Y-m-d H:i:s'));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr);
+ pg_free_result($sqlr);
+ foreach($arr as $it)
+ {
+ $sqlstr = 'INSERT INTO "user_notice" ("uid", "nid") VALUES ($1, $2);';
+ $sqlarr = array(intval($uid), intval($it));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ pg_free_result($sqlr);
+ }
+ return $ret;
+ }
+
+ private static function check_new($sqlc, $uid)
+ {
+ $sqlstr = 'SELECT * FROM "notice_cache" WHERE "uid"=$1;';
+ $sqlarr = array($uid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr);
+ if($ret === false)
+ {
+ $ret = notice::ins_uid($sqlc, $uid);
+ }
+ pg_free_result($sqlr);
+ $sqlstr = 'SELECT * FROM "notice" WHERE "nid" > $1 ORDER BY "tim";';
+ $sqlarr = array(intval($ret->tmp));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $buf = array();
+ while($row = pg_fetch_object($sqlr))
+ {
+ if(self::is_match($sqlc, $uid, $row))
+ {
+ array_unshift($buf, $row->nid);
+ }
+ }
+ pg_free_result($sqlr);
+ if(count($buf) > 0)
+ {
+ return self::update($sqlc, $uid, $ret, $buf);
+ }
+ return $ret;
+ }
+
+ // **warning**: this function will clear notice count of uid!!
+ public static function get($sqlc, $uid, $typ, $arg1, $arg2)
+ {
+ $uid = intval($uid);
+ if(!$uid || !$sqlc)
+ {
+ return false;
+ }
+ $ret = self::check_new($sqlc, $uid);
+ if($typ == NOTICE_ACT_CNT)
+ {
+ return intval($ret->cnt);
+ }
+ else if($typ == NOTICE_ACT_NEW)
+ {
+ if($ret->cnt == 0)
+ {
+ return array();
+ }
+ $sqlstr = 'SELECT "nid" FROM "user_notice" WHERE "uid"=$1 AND "nid">$2 ORDER BY "nid" DESC';
+ $sqlarr = array($uid, intval($ret->rsv));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $nids = array();
+ while($it=pg_fetch_array($sqlr))
+ {
+ $nids[] = $it[0];
+ }
+ $sqlstr = 'SELECT * FROM "notice" WHERE "nid" IN ('.join($nids, ",").') ORDER BY "tim";';
+ $sqlr = pg_query($sqlc, $sqlstr);
+ $buf = array();
+ while($it = pg_fetch_object($sqlr))
+ {
+ $it->nid = intval($it->nid);
+ $it->typ = intval($it->typ);
+ $buf[] = $it;
+ }
+ pg_free_result($sqlr);
+ $sqlstr = 'UPDATE "notice_cache" SET "cnt"=0, "rsv"=$2 WHERE "uid"=$1;';
+ $sqlarr = array($uid, $nids[0]);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ return $buf;
+ }
+ else if($typ == NOTICE_ACT_OLD)
+ {
+ if($arg2 <= 0)
+ {
+ $arg2 = 1;
+ }
+ if($arg2 > NOTICE_MAX_LIM)
+ {
+ $arg2 = NOTICE_MAX_LIM;
+ }
+ $sqlstr = 'SELECT "nid" FROM "user_notice" WHERE "uid"=$1 AND "nid"<$2 ORDER BY "nid" DESC LIMIT $3';
+ $sqlarr = array($uid, $arg1, $arg2);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $nids = array();
+ while($it=pg_fetch_array($sqlr))
+ {
+ $nids[] = $it[0];
+ }
+ $sqlstr = 'SELECT * FROM "notice" WHERE "nid" IN ('.join($nids, ",").') ORDER BY "tim";';
+ $sqlr = pg_query($sqlc, $sqlstr);
+ $buf = array();
+ while($it = pg_fetch_object($sqlr))
+ {
+ $it->nid = intval($it->nid);
+ $it->typ = intval($it->typ);
+ $buf[] = $it;
+ }
+ pg_free_result($sqlr);
+ return $buf;
+ }
+ return false;
+ }
+
+ public static function clr($sqlc, $uid, $lim=NOTICE_DEF_LIM)
+ {
+ return false;
+ if($lim < 0)
+ {
+ $lim = 0;
+ }
+ $ret = self::check_new($sqlc, $uid);
+ $buf = preg_split("/[,]/", $ret->tmp);
+ $buf = array_slice($buf, 0, $ret->cnt+$lim);
+ $sqlstr = 'UPDATE "notice_cache" SET "tmp"=$1 WHERE "uid"=$2;';
+ $sqlarr = array(join($buf, ","), $uid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ if($sqlr)
+ {
+ return count($buf);
+ }
+ return false;
+ }
+
+ // you can add notice by calling it.
+ public static function add($sqlc, $typ, $val, $txt)
+ {
+ if(!is_string($val))
+ {
+ $val = json_encode($val);
+ }
+ $sqlstr = 'INSERT INTO "notice" ("typ", "val", "txt", "tim") VALUES ($1, $2, $3, $4) RETURNING *;';
+ $sqlarr = array($typ, $val, $txt, date('Y-m-d H:i:s'));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr);
+ if($ret === false)
+ {
+ return false;
+ }
+ return json_encode($ret);
+ }
+
+ public static function del($sqlc, $cond)
+ {
+ $sqlstr = 'DELETE FROM "notice" WHERE 0';
+ if(isset($cond['nid']))
+ {
+ $sqlstr .= ' OR "nid"=$1';
+ }
+ if(isset($cond['tim']))
+ {
+ $sqlstr .= ' OR "tim" >= $2';
+ }
+ $sqlarr = array($cond['nid'], $cond['tim']);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ if(!$sqlr)
+ {
+ return false;
+ }
+ return true;
+ }
+}
+?>
diff --git a/toj/php/notice.php b/toj/php/notice.php
new file mode 100644
index 0000000..a0f984a
--- /dev/null
+++ b/toj/php/notice.php
@@ -0,0 +1,110 @@
+<?php
+//ini_set("display_errors", "On");
+//error_reporting(E_ALL & ~E_NOTICE);
+
+require_once('notice.inc.php');
+
+/* usage:
+ * action count(uid): update notice count of uid, return value: integer
+ * action get(uid): update notice of uid, return notice data limited to notice count,
+ * and clear notice count. format: object array, see table "notice"
+ * action clear(uid, [limit]): clear cache number to notice_count+limit,
+ * does not affect notice, only user cache. return remain number as int.
+ * action add(type, value, context): add a notice, need admin permission now.
+ * **attention**: this is only for web, use notice::add with your own code,
+ * that function does not require any user permission.
+ * type is an integer, see "notice.inc.php" NOTICE_TYP_*.
+ * value are paired with type, like proid, sqid, uid, .., meaning nothing
+ * with NOTICE_TYP_ALL, but cannot be NULL.
+ * context is what you want. treat as string data so its format
+ * depends on your own.
+ * return 'S' when success.
+ */
+
+$sqlc = db_connect();
+$action = $_POST['action'];
+$data = json_decode($_POST['data']);
+
+if(strlen($action) == 0)
+{
+ die('Eno_action');
+}
+if(!sec_is_login())
+{
+ die('Eno_login');
+}
+$uid = intval($_COOKIE['uid']);
+$usr = user::get_from_uid($sqlc, $uid);
+if(!$usr)
+{
+ die('Eno_such_user');
+}
+
+if($action == 'count')
+{
+ $cnt = notice::get($sqlc, $uid, NOTICE_ACT_CNT);
+ echo $cnt;
+}
+else if($action == 'get')
+{
+ $nid = intval($data->nid);
+ if($nid > 0)
+ {
+ $cnt = intval($data->count);
+ $res = notice::get($sqlc, $uid, NOTICE_ACT_OLD, $nid, $cnt);
+ if($res === false)
+ {
+ die('Eno_such_nid');
+ }
+ echo json_encode($res);
+ }
+ else
+ {
+ $res = notice::get($sqlc, $uid, NOTICE_ACT_NEW);
+ echo json_encode($res);
+ }
+}
+else if($action == 'clear')
+{
+ $lim = NOTICE_DEF_LIM;
+ if(isset($data->limit))
+ {
+ $lim = intval($data->limit);
+ }
+ if($lim > NOTICE_MAX_LIM)
+ {
+ $lim = NOTICE_MAX_LIM;
+ }
+ $ret = notice::clr($sqlc, $uid, $lim);
+ echo $ret;
+}
+else if($action == 'add')
+{
+ if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) && $uid != 111)
+ //if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN))
+ {
+ die('Epermission_denied');
+ }
+ if(!isset($data->type))
+ {
+ die('Etype_is_empty');
+ }
+ if(!isset($data->value))
+ {
+ die('Evalue_is_empty');
+ }
+ if(!isset($data->context))
+ {
+ die('Econtext_is_empty');
+ }
+ $res = notice::add($sqlc, $data->type, $data->value, $data->context);
+ if(!$res)
+ {
+ die('Efail');
+ }
+ echo 'S';
+}
+
+db_close($sqlc);
+
+?>
diff --git a/toj/php/problem.inc.php b/toj/php/problem.inc.php
new file mode 100644
index 0000000..e41e633
--- /dev/null
+++ b/toj/php/problem.inc.php
@@ -0,0 +1,252 @@
+<?php
+require_once('common.inc.php');
+require_once('user.inc.php');
+require_once('square.inc.php');
+
+const PRONAME_LEN_MAX = 100;
+
+const CODE_LEN_MIN = 1;
+const CODE_LEN_MAX = 102400;
+
+const SUBMIT_MIN_INTERVAL = 10;
+
+$LANGUAGE = array(0x1=>'C/C++', 0x2=>'JAVA', 0x4=>'Pascal');
+$EXTENSION = array(0x1=>'cpp', 0x2=>'java', 0x4=>'pas');
+
+class problem
+{
+ public $proid;
+ public $modid;
+ public $proname;
+ public $hidden;
+
+ public static function getmod($sqlc, $modid)
+ {
+ //return pmodname, smodname, jmodname for specified $modid.
+ //False if not found.
+ $result = pg_query_params($sqlc, 'SELECT * FROM "mod" WHERE "modid"=$1 LIMIT 1;', array($modid));
+ $mret = pg_fetch_object($result);
+ pg_free_result($result);
+ if(!$mret)
+ return false;
+ return $mret;
+ }
+ public static function get($sqlc, $proid)
+ {
+ //return problem data: proid, modid, proname, pmodname, smodname, jmodname
+ //False if not found.
+ $result = pg_query_params($sqlc, 'SELECT * FROM "problem" WHERE "proid"=$1 LIMIT 1;', array(intval($proid))) or die ("Eerror_get_problem");
+ $ret = pg_fetch_object($result, null, 'problem');
+ pg_free_result($result);
+ if(!$ret)
+ return false;
+
+ $ret->proid = intval($ret->proid);
+ $ret->modid = intval($ret->modid);
+ $ret->admin_uid = intval($ret->admin_uid);
+
+ $mret = problem::getmod($sqlc, $ret->modid);
+ if(!$mret)
+ return false;
+
+ $ret->pmodname = $mret->pmodname;
+ $ret->smodname = $mret->smodname;
+ $ret->jmodname = $mret->jmodname;
+
+ return $ret;
+ }
+
+ public static function is_available($sqlc, $proid, $uid = null)
+ {
+ //return whether the problem is available for user $_COOKIE['uid'] or not.
+ //USER_PER_PROADMIN always OK
+ //admin of problem always OK
+ //if HIDDEN , then NOT OK except admins
+ //in sqid=1 always OK , even if not login
+ //otherwise must exist at least one common square with relationship >= SQUARE_USER_ACTIVE
+ $uidnull = false;
+ if($uid == null)
+ {
+ $uid = intval($_COOKIE['uid']);
+ $uidnull = true;
+ }
+ $sqlr = pg_query_params('SELECT "hidden", "admin_uid" FROM "problem" WHERE "proid"=$1;', array($proid));
+ $obj = pg_fetch_object($sqlr);
+ $hdn = $obj->hidden;
+ if($hdn == null)
+ return false; // no such problem
+
+ if(sec_check_level($sqlc, USER_PER_PROADMIN, $uidnull?null:$uid))
+ return true;
+
+ if((!$uidnull || sec_is_login()) && $uid == intval($obj->admin_uid))
+ return true;
+
+ if($hdn == "t")
+ return false;
+
+ $sqlstr = 'SELECT COUNT(*) FROM "pro_sq" WHERE "proid"=$1 AND "sqid"=$2;';
+ $sqlarr = array($proid, 1);
+ $sqlr = pg_query_params($sqlstr, $sqlarr);
+ $ret = intval(pg_fetch_result($sqlr, 0));
+ if($ret > 0)
+ return true;
+
+ if($uidnull && !sec_is_login())
+ return false;
+
+ $sqlstr = 'SELECT COUNT("pro_sq"."sqid") FROM "pro_sq" INNER JOIN "us_sq" ON "pro_sq"."sqid"="us_sq"."sqid" WHERE "pro_sq"."proid"=$1 AND "us_sq"."uid"=$2 AND "us_sq"."relationship">=$3;';
+ $sqlarr = array($proid, $uid, SQUARE_USER_ACTIVE);
+ $sqlr = pg_query_params($sqlstr, $sqlarr);
+ $ret = intval(pg_fetch_result($sqlr, 0));
+ if($ret > 0)
+ return true;
+
+ return false;
+ }
+
+ public static function submit($sqlc, $proid, $uid, $lang, $code)
+ {
+ //Submit code(or data) : $proid, $uid, $lang, $code
+ //Return subid. False if failed.
+
+ ////$submit_time = date('Y-m-d H:i:s');
+ ////$last_update = $submit_time;
+ $sqlstr = 'INSERT INTO "submit" ("proid", "uid", "lang") VALUES ($1, $2, $3) RETURNING subid;';
+ $sqlarr = array($proid, $uid, $lang);
+ $sqlr = pg_query_params($sqlstr, $sqlarr);
+ $subid = intval(pg_fetch_result($sqlr, 0));
+ if(!$subid)
+ return false;
+
+ global $EXTENSION;
+ $ext = $EXTENSION[intval($lang)];
+ if($ext == null)
+ die('Ewrong_extension');
+
+ $parnum = $subid - ($subid%1000);
+ $pardir = '../center/submit/'.$parnum.'/';
+ if(!is_dir($pardir))
+ mkdir($pardir, 0755) or die('Ecannot_mkdir');
+ mkdir($pardir.$subid, 0755) or die('Ecannot_mkdir');
+ mkdir($pardir.$subid.'/data', 0755) or die('Ecannot_mkdir');
+ mkdir($pardir.$subid.'/result', 0755) or die('Ecannot_mkdir');
+
+ //$file = fopen($pardir.$subid.'/data/'.$subid.'.'.$ext,'w');
+ //20130205 tmp change
+ $file = fopen($pardir.$subid.'/data/main.'.$ext,'w');
+ if(!$file)
+ die('Ewrite_file_failed');
+ fwrite($file, $code);
+ fclose($file);
+
+ return $subid;
+ }
+
+ public static function add($sqlc, $pro)
+ {
+ //Add a new problem $pro into problem table.
+ //Return the inserted object. False if failed.
+
+ $sqlstr = 'INSERT INTO "problem" ("modid", "proname", "hidden", "admin_uid") VALUES ($1, $2, $3, $4) RETURNING *;';
+ $sqlarr = array($pro->modid, $pro->proname, $pro->hidden, $pro->admin_uid);
+ $sqlr = pg_query_params($sqlstr, $sqlarr);
+ if(!$sqlr)
+ return false;
+ $obj = pg_fetch_object($sqlr, null, 'problem');
+ pg_free_result($sqlr);
+ if(!$obj)
+ return false;
+
+ $obj->proid = intval($obj->proid);
+ $obj->modid = intval($obj->modid);
+ $obj->admin_uid = intval($obj->admin_uid);
+
+ return $obj;
+ }
+
+ public static function mod_get_lang($sqlc, $modid)
+ {
+ //get available language code (OR) format
+ //return language code
+
+ $sqlstr = 'SELECT "lang" FROM "mod" WHERE "modid"=$1;';
+ $sqlarr = array($modid);
+ $sqlr = pg_query_params($sqlstr, $sqlarr);
+ $ret = pg_fetch_result($sqlr, 0);
+ pg_free_result($sqlr);
+ if(!$ret)
+ return false;
+ return intval($ret);
+ }
+
+ public static function recent_submit($sqlc, $uid, $time)
+ {
+ //return submission number in recent $time seconds.
+ $lasttime = date('Y-m-d H:i:s', time()-$time);
+ $sqlstr = 'SELECT COUNT(*) FROM "submit" WHERE "uid"=$1 AND "submit_time" >= $2;';
+ $sqlarr = array($uid, $lasttime);
+ $sqlr = pg_query_params($sqlstr, $sqlarr);
+ $ret = pg_fetch_result($sqlr, 0);
+ if(!$ret)
+ return false;
+ return intval($ret);
+ }
+
+ public static function send_socket($subid, $proid)
+ {
+ ///send socket to center.
+ //Return true if success, false if failed.
+
+ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+ $sconn = socket_connect($socket, '127.0.0.1', CENTER_SOCKET_PORT);
+
+ if(!$sconn)
+ return false;
+
+ $wret = socket_write($socket, $subid.chr(0).'{}'.chr(0));
+ if($wret === false)
+ return false;
+
+
+ $cret = socket_read($socket, 1024);
+ if($cret === false)
+ return false;
+ if($cret[0] != 'S')
+ return false;
+ return true;
+ }
+
+ public static function get_pro_stat($sqlc, $proid, $uid)
+ {
+ //get $uid 's score and is_ac of problem $proid.
+
+ $ret = new stdClass();
+
+ $sqlstr = 'SELECT COUNT(*) FROM "submit" WHERE "proid"=$1 AND "uid"=$2 AND "result"=0;';
+ $sqlarr = array($proid, $uid);
+ $res = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $acct = pg_fetch_result($res, 0);
+ $ret->is_ac = ($acct > 0);
+
+ $sqlstr = 'SELECT "score" FROM "submit" WHERE "proid"=$1 AND "uid"=$2 ORDER BY "score" DESC LIMIT 1;';
+ $sqlarr = array($proid, $uid);
+ $res = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $score = pg_fetch_result($res, 0);
+ if($score === false)
+ {
+ $ret->tried = false;
+ $ret->score = 0;
+ }
+ else
+ {
+ $ret->tried = true;
+ $ret->score = $score;
+ }
+
+ return $ret;
+ }
+}
+
+
+?>
diff --git a/toj/php/problem.php b/toj/php/problem.php
new file mode 100644
index 0000000..be79ecb
--- /dev/null
+++ b/toj/php/problem.php
@@ -0,0 +1,140 @@
+<?php
+ini_set("display_errors", "On");
+error_reporting(E_ALL & ~E_NOTICE);
+
+require_once('problem.inc.php');
+require_once('user.inc.php');
+
+$sqlc = db_connect();
+
+$action = $_POST['action'];
+$data = $_POST['data'];
+
+if(strlen($action)==0)
+ die('Eno_action');
+if($action == 'get_pro')
+{
+ //get problem data: proid, modid, name, pmodname, smodname, jmodname
+ //only USER_LEVEL_SUPERADMIN or is_available
+ //data : proid
+
+ $dt = json_decode($data);
+
+ $proid = intval($dt->proid);
+
+ $ret = problem::get($sqlc, $proid);
+ if(!$ret)
+ die('Eget_problem');
+
+ if(!problem::is_available($sqlc, $proid))
+ die('Epermission_denied');
+
+ unset($ret->proid);
+ //unset($ret->hidden);
+
+ echo(json_encode($ret));
+}
+if($action == 'add_pro')
+{
+ //Add problem
+ //need SUPERADMIN
+ //data: modid, proname, [hidden]
+ if(!sec_is_login())
+ die('Enot_login');
+ if(!sec_check_level($sqlc, USER_PER_PROCREATOR))
+ die('Epermission_denied');
+
+ $dt = json_decode($data);
+
+ if(strlen($dt->proname) == 0)
+ die('Eproname_too_short');
+ if(strlen($dt->proname) > PRONAME_LEN_MAX)
+ die('Eproname_too_long');
+
+ if(!problem::getmod($sqlc, $dt->modid))
+ die('Ewrong_modid');
+
+ if($dt->hidden != 't' && $dt->hidden != 'f')
+ die('Ewrong_hidden_value');
+
+ /*CHECK OTHER DATA, TESTDATA ETC*/
+
+ $dt->admin_uid = intval($_COOKIE['uid']);
+
+ $pro = problem::add($sqlc, $dt);
+ if(!$pro)
+ die('Eadd_problem');
+
+ echo(json_encode($pro));
+}
+if($action == 'submit_code')
+{
+ //Submit code
+ //Need problem available
+ //data: proid, lang, code
+ if(!sec_is_login())
+ die('Enot_login');
+
+ $uid = intval($_COOKIE['uid']);
+ $dt = json_decode($data);
+
+ $proid = intval($dt->proid);
+
+ if(!problem::is_available($sqlc, $proid)){
+ die('Epermission_denied');
+ }
+
+ $obj = problem::get($sqlc, $proid);
+ $lang = intval($dt->lang);
+ $oklang = problem::mod_get_lang($sqlc, $obj->modid);
+ if($LANGUAGE[$lang] == null || (($lang & $oklang) == 0))
+ die('Ewrong_language');
+
+ if(strlen($dt->code) < CODE_LEN_MIN)
+ die('Ecode_too_short');
+ if(strlen($dt->code) > CODE_LEN_MAX)
+ die('Ecode_too_long');
+
+ //if(problem::recent_submit($sqlc, $uid, SUBMIT_MIN_INTERVAL) > 0)
+ // die('Esubmit_too_frequently');
+
+ $subid = problem::submit($sqlc, $proid, $uid, $lang, $dt->code);
+ if(!$subid)
+ die('Esubmit_code_failed');
+
+ /*ASSOCIATED SQUARE : CALL SQUARE MODULE TO GET EXTRA JUDGE OPTION*/
+
+ if(!problem::send_socket($subid, $proid))
+ die('Esend_socket_failed');
+
+ echo(json_encode($subid));
+}
+if($action == 'get_pro_stat')
+{
+ //Get score and is_ac for specified proid.
+ //Need login and problem available.
+ //data : proid
+
+ if(!sec_is_login())
+ die('Enot_login');
+
+ $uid = intval($_COOKIE['uid']);
+ $dt = json_decode($data);
+
+ $proid = intval($dt->proid);
+
+ if(!problem::is_available($sqlc, $proid)){
+ die('Epermission_denied');
+ }
+
+ $ret = problem::get_pro_stat($sqlc, $proid, $uid);
+ if(!$ret)
+ die('Eerror_get_pro_stat');
+
+ echo(json_encode($ret));
+}
+
+db_close($sqlc);
+
+
+?>
diff --git a/toj/php/pzreadtest.php b/toj/php/pzreadtest.php
new file mode 100644
index 0000000..b67ae9e
--- /dev/null
+++ b/toj/php/pzreadtest.php
@@ -0,0 +1,9 @@
+<?php
+ require_once('notice.inc.php');
+
+ function center_result_event($uid,$msg){
+ $db = db_connect();
+ notice::add($db,NOTICE_TYP_USR,$uid,json_encode($msg));
+ db_close($db);
+ }
+?>
diff --git a/toj/php/sqlib.inc.php b/toj/php/sqlib.inc.php
new file mode 100644
index 0000000..154bcbd
--- /dev/null
+++ b/toj/php/sqlib.inc.php
@@ -0,0 +1,5 @@
+<?php
+
+ require_once('sqlib_scoreboard.inc.php');
+
+?>
diff --git a/toj/php/sqlib_scoreboard.inc.php b/toj/php/sqlib_scoreboard.inc.php
new file mode 100644
index 0000000..84a71ef
--- /dev/null
+++ b/toj/php/sqlib_scoreboard.inc.php
@@ -0,0 +1,239 @@
+<?php
+
+ /*
+ Square mod library : Scoreboard
+ 2013/02/10 By TOJTeam
+
+ Get scoreboard by rank :
+ sqlib_scoreboard::get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $start_rank, $number)
+
+ Get scoreboard of specific user :
+ sqlib_scoreboard::get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $uid)
+
+ $sqlc : sql connection to database 'toj'
+ $msqlc : sql connection to database 'toj_mod'
+ $sqid : square id number
+ $sboard_id : scoreboard id number (of square)
+ $score_func : function to determine rank_score
+ $start_time : start timestamp
+ $end_time : end timestamp
+ $start_rank : display from which rank
+ $number : number to display
+ $uid : user id number
+
+ Parameter format of $score_func:
+ func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $tries);
+
+ */
+
+ require_once('common.inc.php');
+
+ class sqlib_scoreboard
+ {
+ public static function def_func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $tries)
+ {
+ return $best_score;
+ }
+
+ public static function get_last_update($msqlc, $sqid, $sboard_id)
+ {
+ $sqlstr = 'SELECT "last_update" FROM "sqlib_scoreboard_last_update" WHERE "sqid"=$1 AND "sboard_id"=$2;';
+ $sqlarr = array($sqid, $sboard_id);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_result($res, 0);
+ return $ret;
+ }
+
+ public static function set_last_update($msqlc, $sqid, $sboard_id, $new)
+ {
+ $now = date('Y-m-d H:i:s+08');
+ $sqlstr = 'UPDATE "sqlib_scoreboard_last_update" SET "last_update"=$3 WHERE "sqid"=$1 AND "sboard_id"=$2;';
+ if($new)
+ {
+ $sqlstr = 'INSERT INTO "sqlib_scoreboard_last_update" ("sqid", "sboard_id", "last_update") VALUES ($1, $2, $3);';
+ }
+ $sqlarr = array($sqid, $sboard_id, $now);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ }
+
+ public static function get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time = null, $end_time = null, $start_offset, $number, $uid = null)
+ {
+ if(!$start_time)$start_time = '1900-01-01 01:01:01+08';
+ if(!$end_time)$end_time = '2222-01-01- 01:01:01+08';
+ sqlib_scoreboard::update($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time);
+
+ //display
+ $sqlstr = 'SELECT "a1"."uid", "a1"."rank_score", COUNT(*) AS "rank" FROM "sqlib_scoreboard_main" "a1", "sqlib_scoreboard_main" "a2" WHERE "a1"."sqid"=$1 AND "a1"."sboard_id"=$2 AND "a2"."sqid"=$1 AND "a2"."sboard_id"=$2 AND ("a2"."rank_score">"a1"."rank_score" OR "a2"."uid"="a1"."uid") GROUP BY "a1"."uid", "a1"."rank_score" ORDER BY "a1"."rank_score" DESC, "a1"."uid" LIMIT $4 OFFSET $3;';
+ $sqlarr = array($sqid, $sboard_id, $start_offset-1, $number);
+ if($uid)
+ {
+ $sqlstr = 'SELECT "a1"."uid", "a1"."rank_score", COUNT(*) AS "rank" FROM "sqlib_scoreboard_main" "a1", "sqlib_scoreboard_main" "a2" WHERE "a1"."sqid"=$1 AND "a1"."sboard_id"=$2 AND "a1"."uid"=$3 AND "a2"."sqid"=$1 AND "a2"."sboard_id"=$2 AND ("a2"."rank_score">"a1"."rank_score" OR "a2"."uid"="a1"."uid") GROUP BY "a1"."uid", "a1"."rank_score";';
+ $sqlarr = array($sqid, $sboard_id, $uid);
+ }
+
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ $arr = pg_fetch_all($res);
+
+ $ret_obj = array();
+ foreach($arr as $item)
+ {
+ $obj = new stdClass();
+ $obj->uid = intval($item['uid']);
+ $obj->rank_score = doubleval($item['rank_score']);
+ $obj->rank = intval($item['rank']);
+ $obj->problem = array();
+
+ $sqlstr = 'SELECT "proid", "best_score", "best_time", "is_ac", "ac_time", "tries_before_ac", "last_score", "last_status", "last_time", "tries", "rank_score" FROM "sqlib_scoreboard_pro" WHERE "sqid"=$1 AND "sboard_id"=$2 AND "uid"=$3;';
+ $sqlarr = array($sqid, $sboard_id, $obj->uid);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ $data = pg_fetch_all($res);
+ foreach($data as $pro)
+ {
+ $pobj = new stdClass();
+ $pobj->proid = intval($pro['proid']); ///
+ $pobj->best_score = doubleval($pro['best_score']);
+ $pobj->best_time = $pro['best_time'];
+ $pobj->is_ac = ($pro['is_ac']=='t');
+ $pobj->ac_time = $pro['ac_time'];
+ $pobj->tries_before_ac = intval($pro['tries_before_ac']);
+ $pobj->last_score = doubleval($pro['last_score']);
+ $pobj->last_status = intval($pro['last_status']);
+ $pobj->last_time = $pro['last_time'];
+ $pobj->tries = intval($pro['tries']);
+ $pobj->rank_score = doubleval($pro['rank_score']);
+
+ $proid = intval($pro['proid']);
+ $obj->problem[$proid] = $pobj;
+ }
+ array_push($ret_obj, $obj);
+ }
+ return $ret_obj;
+ }
+
+ public static function get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time = null, $end_time = null, $uid)
+ {
+ return sqlib_scoreboard::get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, null, null, $uid);
+ }
+
+ public static function update($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time)
+ {
+ $last_update = sqlib_scoreboard::get_last_update($msqlc, $sqid, $sboard_id);
+ $last_update_time = strtotime($last_update);
+ if(!$last_update)$last_update_time = 0;
+ if($last_update_time <= time()-2)
+ {
+ sqlib_scoreboard::set_last_update($msqlc, $sqid, $sboard_id, !$last_update);
+ }
+ else return;
+ $last_update = date('Y-m-d H:i:s+08', $last_update_time);
+
+ //echo ('update!!'.$last_update.'<br>');
+ $sqlstr = 'SELECT DISTINCT "uid" FROM "submit" WHERE "last_update">=$4 AND "proid" IN (SELECT "proid" FROM "pro_sq" WHERE "sqid"=$1) AND "submit_time">=$2 AND "submit_time"<=$3;';
+ $sqlarr = array($sqid, $start_time, $end_time, $last_update);
+ $res = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $uid_list = pg_fetch_all_columns($res);
+ foreach($uid_list as $item)
+ {
+ //echo($item.', ');
+ $uid = intval($item);
+ sqlib_scoreboard::update_user($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $uid);
+ }
+ }
+
+ public static function update_user($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $uid)
+ {
+ $sqlstr = 'SELECT "proid" FROM "pro_sq" WHERE "sqid"=$1;';
+ $sqlarr = array($sqid);
+ $res = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $proid_list = pg_fetch_all_columns($res, 0);
+
+ $total_rank_score = 0.0;
+ foreach($proid_list as $item)
+ {
+ $proid = intval($item);
+ $sqlstr = 'SELECT "result", "score", "submit_time" FROM "submit" WHERE "uid"=$1 AND "proid"=$2 AND "submit_time">=$3 AND "submit_time"<=$4 ORDER BY "submit_time";';
+ $sqlarr = array($uid, $proid, $start_time, $end_time);
+ $res = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $sub_list = pg_fetch_all($res);
+
+ $best_score = -1.0;
+ $best_time = '1900-01-01 01:01:01+08';
+
+ $is_ac = false;
+ $ac_time = null;
+ $tries_before_ac = 0;
+
+ $tries = count($sub_list);
+ $last_score = null;
+ $last_status = null;
+ $last_time = null;
+ if($sub_list)
+ {
+ $last_score = doubleval($sub_list[$tries-1]['score']);
+ $last_status = intval($sub_list[$tries-1]['result']);
+ $last_time = $sub_list[$tries-1]['submit_time'];
+
+ foreach($sub_list as $obj)
+ {
+ $score = doubleval($obj['score']);
+ $status = intval($obj['result']);
+ $stime = $obj['submit_time'];
+ if($score > $best_score)
+ {
+ $best_score = $score;
+ $best_time = $stime;
+ }
+ if(!$is_ac)
+ {
+ if($status == 0) // JUDGE_AC
+ {
+ $is_ac = true;
+ $ac_time = $stime;
+ }
+ else
+ {
+ $tries_before_ac += 1;
+ }
+ }
+ }
+ }
+ else
+ {
+ $tries = 0;
+ $best_score = null;
+ $best_time = null;
+ }
+
+ if($score_func == null)$score_func = array('sqlib_scoreboard', 'def_func');
+ $rank_score = $score_func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $last_time, $tries);
+ $sqlstr = 'SELECT COUNT(*) FROM "sqlib_scoreboard_pro" WHERE "sqid"=$1 AND "sboard_id"=$3 AND "proid"=$2 AND "uid"=$4;';
+ $sqlarr = array($sqid, $proid, $sboard_id, $uid);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ $cnt = intval(pg_fetch_result($res, 0));
+
+ $sqlstr = 'UPDATE "sqlib_scoreboard_pro" SET "best_score"=$5, "best_time"=$6, "is_ac"=$7, "ac_time"=$8, "tries_before_ac"=$9, "last_score"=$10, "last_status"=$11, "last_time"=$12, "tries"=$13, "rank_score"=$14 WHERE "sqid"=$1 AND "sboard_id"=$2 AND "proid"=$3 AND "uid"=$4;';
+ if($cnt==0)
+ {
+ $sqlstr = 'INSERT INTO "sqlib_scoreboard_pro" ("sqid", "sboard_id", "proid", "uid", "best_score", "best_time", "is_ac", "ac_time", "tries_before_ac", "last_score", "last_status", "last_time", "tries", "rank_score") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);';
+ }
+ $sqlarr = array($sqid, $sboard_id, $proid, $uid, $best_score, $best_time, $is_ac?'t':'f', $ac_time, $tries_before_ac, $last_score, $last_status, $last_time, $tries, $rank_score);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ //var_dump($sqlarr);
+ $total_rank_score += $rank_score;
+ }
+
+ $sqlstr = 'SELECT COUNT(*) FROM "sqlib_scoreboard_main" WHERE "sqid"=$1 AND "sboard_id"=$2 AND "uid"=$3;';
+ $sqlarr = array($sqid, $sboard_id, $uid);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ $cnt = intval(pg_fetch_result($res, 0));
+
+ $sqlstr = 'UPDATE "sqlib_scoreboard_main" SET "rank_score"=$4 WHERE "sqid"=$1 AND "sboard_id"=$2 AND "uid"=$3;';
+ if($cnt == 0)
+ {
+ $sqlstr = 'INSERT INTO "sqlib_scoreboard_main" ("sqid", "sboard_id", "uid", "rank_score") VALUES ($1, $2, $3, $4);';
+ }
+ $sqlarr = array($sqid, $sboard_id, $uid, $total_rank_score);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ }
+ }
+?>
diff --git a/toj/php/square.inc.php b/toj/php/square.inc.php
new file mode 100644
index 0000000..784490d
--- /dev/null
+++ b/toj/php/square.inc.php
@@ -0,0 +1,229 @@
+<?php
+
+require_once('common.inc.php');
+require_once('user.inc.php');
+require_once('problem.inc.php');
+
+const SQUARE_USER_PENDING = 1;
+const SQUARE_USER_ACTIVE = 2;
+const SQUARE_USER_ADMIN = 3;
+
+const SQUARE_PUBLIC = 3;
+const SQUARE_AUTH = 2;
+const SQUARE_PRIVATE = 1;
+
+const SQUARE_NAME_LEN_MAX = 100;
+
+class square
+{
+ public $sqid;
+ public $publicity;
+ public $start_time;
+ public $end_time;
+ public $sqname;
+ public $sqmodname;
+
+ public static function get($sqlc, $sqid)
+ {
+ //get square object from sqid
+ //return the object found. False if no such record
+ $sqlr = pg_query_params($sqlc, 'SELECT * FROM "square" WHERE "sqid"=$1 LIMIT 1;', array($sqid));
+ $ret = pg_fetch_object($sqlr, null, 'square');
+ pg_free_result($sqlr);
+ if($ret)$ret->sqid = intval($ret->sqid);
+ return $ret;
+ }
+
+ public static function add($sqlc, $sq)
+ {
+ //add a square object
+ //required member of sq : publicity, start_time, end_time, sqname, sqmodname
+ //publicity : SQUARE_PUBLIC, SQUARE_AUTH, SQUARE_PRIVATE
+ //return the object . False if failed.
+ $sqlstr = 'INSERT INTO "square" ("publicity", "start_time", "end_time", "sqname", "sqmodname") VALUES ($1, $2, $3, $4, $5) RETURNING *;';
+ $sqlarr = array($sq->publicity, $sq->start_time, $sq->end_time, $sq->sqname, $sq->sqmodname);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr, null, 'square');
+ pg_free_result($sqlr);
+ if($ret)$ret->sqid = intval($ret->sqid);
+ return $ret;
+ }
+
+ public static function edit($sqlc, $sqid, $sq)
+ {
+ //edit exist square data
+ //required member of sq : publicity, start_time, end_time, sqname, sqmodname
+ //publicity : SQUARE_PUBLIC, SQUARE_AUTH, SQUARE_PRIVATE
+ //return edited object . False if failed.
+ //
+ //if puhlicity change SQUARE_AUTH => SQUARE_PUBLIC,
+ //set all SQUARE_USER_PENDING users to SQUARE_USER_ACTIVE.
+ $oldsq = square::get($sqlc, $sqid);
+ if($oldsq->publicity==SQUARE_AUTH && $sq->publicity==SQUARE_PUBLIC)
+ {
+ $sqlstr = 'UPDATE "us_sq" SET "relationship"=$1 WHERE "sqid"=$2 AND "relationship"=$3;';
+ $sqlarr = array(SQUARE_USER_ACTIVE, $sqid, SQUARE_USER_PENDING);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ }
+ $sqlstr = 'UPDATE "square" SET "publicity"=$1, "start_time"=$2, "end_time"=$3, "sqname"=$4, "sqmodname"=$5 WHERE "sqid"=$6 RETURNING *;';
+ $sqlarr = array($sq->publicity, $sq->start_time, $sq->end_time, $sq->sqname, $sq->sqmodname, $sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr, null, 'square');
+ pg_free_result($sqlr);
+ if($ret)$ret->sqid = intval($ret->sqid);
+ return $ret;
+ }
+
+ public static function del($sqlc, $sqid)
+ {
+ //Delete the square $sqid. Also delete the user-square relation involves this square.
+ //return false if failed.
+ $sqlstr = 'DELETE FROM "square" WHERE "sqid"=$1;';
+ $sqlstr2 = 'DELETE FROM "us_sq" WHERE "sqid"=$1;';
+ $sqlr = pg_query_params($sqlc, $sqlstr, array($sqid));
+ if(!$sqlr)return false;
+ $sqlr = pg_query_params($sqlc, $sqlstr2, array($sqid));
+ if(!$sqlr)return false;
+ else return true;
+ }
+
+ public static function add_user($sqlc, $uid, $sqid, $relationship)
+ {
+ //add user into user-square relation.
+ //return false if failed.
+ $sqlstr = 'INSERT INTO "us_sq" ("uid", "sqid", "relationship") VALUES ($1, $2, $3) RETURNING *;';
+ $sqlarr = array($uid, $sqid, $relationship);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr);
+ pg_free_result($sqlr);
+ if(!$ret)return false;
+ else return true;
+ }
+
+ public static function del_user($sqlc, $uid, $sqid)
+ {
+ //delete user from user-square relation.
+ //return false if failed.
+ $sqlstr = 'DELETE FROM "us_sq" WHERE "uid"=$1 AND "sqid"=$2;';
+ $sqlarr = array($uid, $sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ if(!$sqlr)return false;
+ else return true;
+ }
+
+ public static function set_user_relationship($sqlc, $uid, $sqid, $relationship)
+ {
+ //update user relationship.
+ //relationship: SQUARE_USER_PENDING, SQUARE_USER_ACTIVE, SQUARE_USER_ADMIN
+ //return false if failed.
+ $sqlr = pg_query_params($sqlc, 'UPDATE "us_sq" SET "relationship"=$3 WHERE "uid"=$1 AND "sqid"=$2;', array($uid, $sqid, $relationship));
+ if(!$sqlr)return false;
+ else return true;
+ }
+
+ public static function get_user_relationship($sqlc, $uid, $sqid)
+ {
+ //get the relationship of uid,sqid from user-square relation.
+ //Return the relationship. SQUARE_USER_PENDING, SQUARE_USER_ACTIVE, SQUARE_USER_ADMIN
+ //return false if no record in the table;
+ $sqlr = pg_query_params($sqlc, 'SELECT "relationship" FROM "us_sq" WHERE "uid"=$1 AND "sqid"=$2;', array($uid, $sqid));
+ $ret = pg_fetch_result($sqlr, 0);
+ if(!$ret)return false;
+ else return intval($ret);
+ }
+
+ public static function get_available_sq($sqlc, $uid, $minpub)
+ {
+ //get all available square for given uid and publicity at least minpub. (not includes entered ones)
+ //Return array of object, which contains each sqid, start_time, end_time, publicity, sqname, sqmodname
+ //return empty array if no record in the table;
+ $sqlstr = 'SELECT "sqid", "start_time", "end_time", "publicity", "sqname", "sqmodname" FROM "square" WHERE "sqid" NOT IN (SELECT "sqid" FROM "us_sq" WHERE "uid"=$1) AND "publicity" >= $2 ORDER BY (CASE WHEN "square"."end_time" IS NULL THEN "square"."sqid" ELSE 0 END), "square"."start_time", "square"."sqid";';
+ $sqlarr = array($uid, $minpub);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = array();
+ while($row = pg_fetch_object($sqlr))
+ {
+ array_push($ret, $row);
+ }
+ return $ret;
+ }
+
+ public static function get_entered_sq($sqlc, $uid)
+ {
+ //gel all entered square for given uid.
+ //Return array of object, which contains each sqid, start_time, end_time, publicity, sqname, sqmodname, relationship
+ //return empty array if no record in the table;
+ $sqlstr = 'SELECT "square"."sqid", "square"."start_time", "square"."end_time", "square"."publicity", "square"."sqname", "square"."sqmodname", "us_sq"."relationship" FROM "us_sq" INNER JOIN "square" ON "us_sq"."sqid"="square"."sqid" WHERE "us_sq"."uid"=$1 ORDER BY (CASE WHEN "square"."end_time" IS NULL THEN "square"."sqid" ELSE 0 END), "square"."start_time", "square"."sqid";';
+ $sqlarr = array($uid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = array();
+ while($row = pg_fetch_object($sqlr))
+ {
+ array_push($ret, $row);
+ }
+ return $ret;
+ }
+
+ public static function del_pro($sqlc, $proid, $sqid)
+ {
+ //Delete $proid from square $sqid.
+ //Return true if success, false if failed.
+ $sqlstr = 'DELETE FROM "pro_sq" WHERE "proid"=$1 AND "sqid"=$2;';
+ $sqlarr = array($proid, $sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ if(!$sqlr)
+ return false;
+ return true;
+ }
+
+ public static function add_pro($sqlc, $proid, $sqid)
+ {
+ //Add problem $proid into square $sqid.
+ //Return true if success, false if failed.
+ $sqlstr = 'INSERT INTO "pro_sq" ("proid", "sqid") VALUES ($1, $2) RETURNING *;';
+ $sqlarr = array($proid, $sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_result($sqlr, 0);
+ if(!$ret)
+ return false;
+ return true;
+ }
+
+ public static function is_pro_in_sq($sqlc, $proid, $sqid)
+ {
+ //Return whether problem $proid is in square $sqid or not.
+ $sqlstr = 'SELECT COUNT(*) FROM "pro_sq" WHERE "proid"=$1 AND "sqid"=$2;';
+ $sqlarr = array($proid, $sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = intval(pg_fetch_result($sqlr, 0));
+ return $ret > 0;
+ }
+
+ public static function get_sqmod($sqlc, $sqid)
+ {
+ //Return the sqmodname of square $sqid.
+ $sqlstr = 'SELECT "sqmodname" FROM "square" WHERE "sqid"=$1;';
+ $sqlarr = array($sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_result($sqlr, 0);
+ return $ret;
+ }
+
+ public static function get_pro_list($sqlc, $sqid)
+ {
+ //get problem list of square $sqid.
+ $sqlstr = 'SELECT "problem"."proid", "problem"."proname", "problem"."hidden" FROM "problem" INNER JOIN "pro_sq" ON "problem"."proid"="pro_sq"."proid" WHERE "pro_sq"."sqid"=$1 ORDER BY "problem"."proid";';
+ $sqlarr = array($sqid);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = array();
+ while($obj = pg_fetch_object($sqlr))
+ {
+ $obj->proid = intval($obj->proid);
+ $obj->hidden = ($obj->hidden=='t');
+ array_push($ret, $obj);
+ }
+ return $ret;
+ }
+}
+
+?>
diff --git a/toj/php/square.php b/toj/php/square.php
new file mode 100644
index 0000000..4880ab3
--- /dev/null
+++ b/toj/php/square.php
@@ -0,0 +1,350 @@
+<?php
+//ini_set("display_errors", "On");
+
+require_once('square.inc.php');
+
+$sqlc = db_connect();
+
+$action = $_POST['action'];
+$data = $_POST['data'];
+
+if(strlen($action)==0)
+ die('Eno_action');
+if($action == 'add_sq')
+{
+ //Add new square. level USER_LEVEL_SUPERADMIN or above required.
+ //data: sqname, publicity, [start_time, end_time], sqmodname
+
+ $sq = json_decode($data);
+
+ if(!sec_is_login())
+ die('Eno_login');
+ if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN))
+ die('Epermission_denied');
+
+ if($sq->publicity != SQUARE_PUBLIC && $sq->publicity != SQUARE_AUTH && $sq->publicity != SQUARE_PRIVATE)
+ die('Ewrong_publicity');
+
+ if(!($sq->start_time))
+ $sq->start_time = date('Y-m-d H:i:s');
+ if(!($sq->end_time))
+ $sq->start_time = null;
+ if(strlen($sq->sqname)==0)
+ die('Esqname_too_short');
+ if(strlen($sq->sqname)>SQUARE_NAME_LEN_MAX)
+ die('Esqname_too_long');
+ if(strlen($sq->sqmodname)==0)
+ die('Esqmodname_empty');
+
+ $res = square::add($sqlc, $sq);
+ if(!$res)
+ die('Eadd_sq_failed');
+
+ $res2 = square::add_user($sqlc, $_COOKIE['uid'], $res->sqid, SQUARE_USER_ADMIN);
+ if(!$res2)
+ die('Eadd_admin_failed');
+
+ echo('S');
+}
+if($action == 'delete_sq')
+{
+ //Delete exist square. level USER_LEVEL_SUPERADMIN or above required.
+ //data : sqid
+
+ $sq = json_decode($data);
+
+ if(!sec_is_login())
+ die('Eno_login');
+ if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN))
+ die('Epermission_denied');
+
+ $sqid = intval($sq->sqid);
+ if(!square::get($sqlc, $sqid))
+ die('Eno_such_sq');
+
+ $res = square::del($sqlc, $sqid);
+ if(!$res)
+ die('Edelete_failed');
+
+ echo('S');
+}
+if($action == 'edit_sq')
+{
+ //edit exist square. level USER_LEVEL_SUPERADMIN / SQUARE_USER_ADMIN or above required.
+ //data: sqid, sqname, publicity, [start_time, end_time], sqmodname
+
+ $sq = json_decode($data);
+
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $sqid = intval($sq->sqid);
+ if(!square::get($sqlc, $sqid))
+ die('Eno_such_sq');
+
+ if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) && !(square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN))
+ die('Epermission_denied');
+
+ if($sq->publicity != SQUARE_PUBLIC && $sq->publicity != SQUARE_AUTH && $sq->publicity != SQUARE_PRIVATE)
+ die('Ewrong_publicity');
+
+ if(!($sq->start_time) && $sq->end_time)
+ $sq->start_time = date('Y-m-d H:i:s');
+ if(strlen($sq->sqname)==0)
+ die('Esqname_too_short');
+ if(strlen($sq->sqname)>SQUARE_NAME_LEN_MAX)
+ die('Esqname_too_long');
+ if(strlen($sq->sqmodname)==0)
+ die('Esqmodname_empty');
+
+ $res = square::edit($sqlc, $sqid, $sq);
+ if(!$res)
+ die('Eedit_failed');
+
+ echo('S');
+}
+if($action == 'get_sq')
+{
+ //get exist square data
+ //data: sqid
+ $sq = json_decode($data);
+
+ $sqid = intval($sq->sqid);
+
+ $ret = square::get($sqlc, $sqid);
+ if(!$ret)
+ die('Eno_such_sq');
+
+ echo(json_encode($ret));
+}
+if($action == 'add_user')
+{
+ //add user to exist square
+ //data: uid, sqid
+ $dt = json_decode($data);
+
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $uid = intval($dt->uid);
+ $sqid = intval($dt->sqid);
+
+ $usr = user::get_from_uid($sqlc, $uid);
+ if(!$usr)
+ die('Eno_such_user');
+
+ $sq = square::get($sqlc, $sqid);
+ if(!$sq)
+ die('Eno_such_sq');
+
+ $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || (square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN);
+
+ if($uid != intval($_COOKIE['uid']) && !$adm)
+ die('Epermission_denied');
+
+ $rela = SQUARE_USER_ACTIVE;
+ if(!$adm)
+ {
+ if($sq->publicity == SQUARE_AUTH)
+ $rela = SQUARE_USER_PENDING;
+ if($sq->publicity == SQUARE_PRIVATE)
+ die('Eprivate_square');
+ }
+
+ if(square::get_user_relationship($sqlc, $uid, $sqid))
+ die('Ealready_entered');
+
+ $ret = square::add_user($sqlc, $uid, $sqid, $rela);
+ if(!$ret)
+ die('Eadd_user_failed');
+
+ echo('S');
+}
+if($action == 'delete_user')
+{
+ //delete user from user-square relation
+ //data : uid, sqid
+ $dt = json_decode($data);
+
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $uid = intval($dt->uid);
+ $sqid = intval($dt->sqid);
+
+ $usr = user::get_from_uid($sqlc, $uid);
+ if(!$usr)
+ die('Eno_such_user');
+
+ $sq = square::get($sqlc, $sqid);
+ if(!$sq)
+ die('Eno_such_sq');
+
+ $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || (square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN);
+
+ if($uid != intval($_COOKIE['uid']) && !$adm)
+ die('Epermission_denied');
+
+ if(!square::get_user_relationship($sqlc, $uid, $sqid))
+ die('Enot_entered');
+
+ $ret = square::del_user($sqlc, $uid, $sqid);
+ if(!$ret)
+ die('Edelete_user_failed');
+
+ echo('S');
+}
+if($action == 'edit_user_relationship')
+{
+ //edit user relationship.
+ //data: uid, sqid, relationship
+ $dt = json_decode($data);
+
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $uid = intval($dt->uid);
+ $sqid = intval($dt->sqid);
+ $rel = intval($dt->relationship);
+
+ $usr = user::get_from_uid($sqlc, $uid);
+ if(!$usr)
+ die('Eno_such_user');
+
+ $sq = square::get($sqlc, $sqid);
+ if(!$sq)
+ die('Eno_such_sq');
+
+ $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || (square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN);
+
+ if(!$adm)
+ die('Epermission_denied');
+
+ if(!square::get_user_relationship($sqlc, $uid, $sqid))
+ die('Enot_entered');
+
+ if($rel!=SQUARE_USER_PENDING && $rel!=SQUARE_USER_ACTIVE && $rel!=SQUARE_USER_ADMIN)
+die('Ewrong_relationship');
+
+ $ret = square::set_user_relationship($sqlc, $uid, $sqid, $rel);
+ if(!$ret)
+ die('Eedit_user_relationship_failed');
+
+ echo('S');
+}
+if($action == 'get_available_sq')
+{
+ //get all available square data: sqid, start_time, end_time, publicity, sqname for given uid.
+ //only USER_LEVEL_SUPERADMIN can see SQUARE_PRIVATE squares.
+ //data: (no)
+
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $uid = intval($_COOKIE['uid']);
+
+ $usr = user::get_from_uid($sqlc, $uid);
+ if(!$usr)
+ die('Eno_such_user');
+
+ $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN);
+
+ $pub = 2;
+ if($adm)
+ $pub = 1;
+
+ $list = square::get_available_sq($sqlc, $uid, $pub);
+
+ $ret->list = $list;
+ $ret->timestamp = date('Y-m-d H:i:s');
+
+ echo(json_encode($ret));
+}
+if($action == 'get_entered_sq')
+{
+
+ //get all entered square data: sqid, start_time, end_time, publicity, sqname, relationship for given uid.
+ //data: (no)
+
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $uid = intval($_COOKIE['uid']);
+
+ $usr = user::get_from_uid($sqlc, $uid);
+ if(!$usr)
+ die('Eno_such_user');
+
+ $list = square::get_entered_sq($sqlc, $uid);
+
+ $ret->list = $list;
+ $ret->timestamp = date('Y-m-d H:i:s');
+
+ echo(json_encode($ret));
+}
+if($action == 'add_pro_into_sq')
+{
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $uid = intval($_COOKIE['uid']);
+
+ $usr = user::get_from_uid($sqlc, $uid);
+ if(!$usr)
+ die('Eno_such_user');
+
+ $dt = json_decode($data);
+ if(!problem::is_available($sqlc, $dt->proid))
+ die('Ewrong_proid');
+
+ if(!square::get($sqlc, $dt->sqid))
+ die('Ewrong_sqid');
+
+ $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || square::get_user_relationship($sqlc, $uid, $dt->sqid) >= SQUARE_USER_ADMIN;
+
+ if(!$adm)
+ die('Enot_square_admin');
+
+ if(square::is_pro_in_sq($sqlc, $dt->proid, $dt->sqid))
+ die('Ealready_in_square');
+
+ $ret = square::add_pro($sqlc, $dt->proid, $dt->sqid);
+ if(!$ret)
+ die('Eadd_problem_into_square_failed');
+
+ echo('S');
+}
+if($action == 'delete_pro_from_sq')
+{
+ if(!sec_is_login())
+ die('Eno_login');
+
+ $uid = intval($_COOKIE['uid']);
+
+ $usr = user::get_from_uid($sqlc, $uid);
+ if(!$usr)
+ die('Eno_such_user');
+
+ $dt = json_decode($data);
+
+ if(!square::get($sqlc, $dt->sqid))
+ die('Ewrong_sqid');
+
+ $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || square::get_user_relationship($sqlc, $uid, $dt->sqid) >= SQUARE_USER_ADMIN;
+
+ if(!$adm)
+ die('Enot_square_admin');
+
+ if(!square::is_pro_in_sq($sqlc, $dt->proid, $dt->sqid))
+ die('Enot_in_square');
+
+ $ret = square::del_pro($sqlc, $dt->proid, $dt->sqid);
+ if(!$ret)
+ die('Edelete_problem_from_square_failed');
+
+ echo('S');
+}
+
+db_close($sqlc);
+
+?>
diff --git a/toj/php/status.inc.php b/toj/php/status.inc.php
new file mode 100644
index 0000000..d9f4f7d
--- /dev/null
+++ b/toj/php/status.inc.php
@@ -0,0 +1,133 @@
+<?php
+require_once('common.inc.php');
+require_once('user.inc.php');
+require_once('problem.inc.php');
+
+const SUBMIT_COUNT_MAX = 100;
+const SUBMIT_SLEEP_TIME = 2;
+const SUBMIT_WAIT_MAX = 10;
+
+class status
+{
+ public static function get_submit($sqlc, $filter, $sort, $count, $last_update, $admin)
+ {
+ //get submit from submit table.
+ //return an array with every entry an object of submission.
+ $condstr = '';
+ $ordstr = '';
+
+ if($admin != true)
+ {
+ $uid = $_COOKIE['uid'];
+ if(!sec_is_login())
+ $uid = 0;
+ $condstr = $condstr.'("problem"."admin_uid"='.intval($uid).' OR "problem"."hidden"=\'f\') AND ';
+ }
+
+ if($last_update != null)
+ {
+ $condstr = $condstr.'"last_update">\''.pg_escape_string($last_update).'\' AND ';
+ }
+
+ if($filter->userid != null)
+ {
+ $condstr = $condstr.'"uid"='.pg_escape_string($filter->userid).' AND ';
+ }
+ if($filter->result != null)
+ {
+ $condstr = $condstr.'"result"='.pg_escape_string($filter->result).' AND ';
+ }
+ if($filter->proid != null)
+ {
+ $condstr = $condstr.'"proid"='.pg_escape_string($filter->proid).' AND ';
+ }
+ if($filter->lang != null)
+ {
+ $condstr = $condstr.'"lang"='.pg_escape_string($filter->lang).' AND ';
+ }
+ if($sort->score != null)
+ {
+ $relstr = $sort->score[0]==0 ? '<=' : '>=';
+ $condstr = $condstr.'"score"'.$relstr.pg_escape_string($sort->score[1]).' AND ';
+ $ordstr = $ordstr.'"score" '.($sort->score[0]==0 ? 'DESC' : 'ASC').' ,';
+ }
+ if($sort->runtime != null)
+ {
+ $relstr = $sort->runtime[0]==0 ? '<=' : '>=';
+ $condstr = $condstr.'"runtime"'.$relstr.pg_escape_string($sort->runtime[1]).' AND ';
+ $ordstr = $ordstr.'"runtime" '.($sort->runtime[0]==0 ? 'DESC' : 'ASC').' ,';
+ }
+ if($sort->maxmem != null)
+ {
+ $relstr = $sort->maxmem[0]==0 ? '<=' : '>=';
+ $condstr = $condstr.'"memory"'.$relstr.pg_escape_string($sort->maxmem[1]).' AND ';
+ $ordstr = $ordstr.'"memory" '.($sort->maxmem[0]==0 ? 'DESC' : 'ASC').' ,';
+ }
+ if($sort->subid != null)
+ {
+ $relstr = $sort->subid[0]==0 ? '<' : '>';
+ $condstr = $condstr.'"subid"'.$relstr.pg_escape_string($sort->subid[1]);
+ $ordstr = $ordstr.'"subid" '.($sort->subid[0]==0 ? 'DESC' : 'ASC');
+ }
+
+
+ $sqlstr = 'SELECT "submit".*, "user"."nickname" FROM ("submit" INNER JOIN "user" ON "submit"."uid"="user"."uid") INNER JOIN "problem" ON "submit"."proid"="problem"."proid" WHERE '.$condstr.' ORDER BY '.$ordstr.' LIMIT '.pg_escape_string($count).';';
+
+ //echo($sqlstr.'<br>');
+ $sqlr = pg_query($sqlc, $sqlstr);
+ //return pg_fetch_object($sqlr);
+ $ret = array();
+ while($obj = pg_fetch_object($sqlr))
+ {
+ $obj->subid = intval($obj->subid);
+ $obj->uid = intval($obj->uid);
+ $obj->proid = intval($obj->proid);
+ $obj->result = intval($obj->result);
+ $obj->runtime = intval($obj->runtime);
+ $obj->memory = intval($obj->memory);
+ $obj->score = intval($obj->score);
+ $obj->lang = intval($obj->lang);
+
+ array_push($ret, $obj);
+ }
+
+ return $ret;
+ }
+
+ public static function get_by_subid($sqlc, $subid)
+ {
+ //get submit information by subid.
+ //return submit information.
+
+ $sqlstr = 'SELECT "submit".*, "mod"."smodname" FROM ("submit" INNER JOIN "problem" ON "submit"."proid"="problem"."proid") INNER JOIN "mod" ON "problem"."modid"="mod"."modid" WHERE "subid"=$1;';
+ $sqlarr = array($subid);
+ $sqlr = pg_query_params($sqlstr, $sqlarr);
+ $ret = pg_fetch_object($sqlr);
+ if(!$ret)
+ die('Eno_such_subid');
+ $ret->subid = intval($ret->subid);
+ $ret->proid = intval($ret->proid);
+ $ret->uid = intval($ret->uid);
+ $ret->result = intval($ret->result);
+ $ret->memory = intval($ret->memory);
+ $ret->score = intval($ret->score);
+ $ret->lang = intval($ret->lang);
+
+ return $ret;
+ }
+
+ public static function subid_is_available($sqlc, $subid)
+ {
+ //decide whether subid is visible or not.
+ //Return true if OK, false if permission denied or failed.
+ $sub = status::get_by_subid($sqlc, $subid);
+ if(!$sub)
+ return false;
+ $ret = problem::is_available($sqlc, $sub->proid);
+ if(!$ret)
+ return false;
+ return true;
+ }
+}
+
+?>
diff --git a/toj/php/status.php b/toj/php/status.php
new file mode 100644
index 0000000..5c00580
--- /dev/null
+++ b/toj/php/status.php
@@ -0,0 +1,70 @@
+<?php
+ini_set("display_errors", "On");
+error_reporting(E_ALL & ~E_NOTICE);
+
+require_once('status.inc.php');
+
+$sqlc = db_connect();
+
+$action = $_POST['action'];
+$data = $_POST['data'];
+
+if(strlen($action)==0)
+ die('Eno_action');
+if($action == 'get_submit')
+{
+ //get submit from submit table
+ //data: sort, sort->subid, count, [wait, filter, last_update]
+ $dt = json_decode($data);
+ if($dt->sort->subid == null)
+ die('Eno_sort_subid');
+ if($dt->count == null)
+ die('Eno_count');
+ $cnt = intval($dt->count);
+ if($cnt <= 0)
+ die('Etoo_few_count');
+ if($cnt > SUBMIT_COUNT_MAX)
+ die('Etoo_many_count');
+
+ $wait = intval($dt->wait);
+ if($wait > SUBMIT_WAIT_MAX)
+ die('Etoo_many_wait');
+
+ $nowwait = $wait;
+ $isadm = sec_check_level($sqlc, USER_PER_PROADMIN);
+
+ while(1)
+ {
+ $ret = status::get_submit($sqlc, $dt->filter, $dt->sort, $cnt, $dt->last_update, $isadm);
+ if($ret != null)
+ {
+ /* OUTPUT */
+ echo(json_encode($ret));
+ exit(0);
+ }
+ //die('Efail');
+ $nowwait--;
+ if($nowwait<0)break;
+ sleep(SUBMIT_SLEEP_TIME);
+ }
+ die('Eno_result');
+}
+if($action == 'get_by_subid')
+{
+ //get submission data and smodname by subid.
+ //problem must be available for the user.
+ //data: subid
+ $dt = json_decode($data);
+ $subid = intval($dt->subid);
+ if(!$subid)
+ die('Eno_subid');
+ $obj = status::get_by_subid($sqlc, $subid);
+
+ if(!problem::is_available($sqlc, $obj->proid))
+ die('Epermission_denied');
+
+ echo(json_encode($obj));
+}
+
+db_close($sqlc);
+?>
diff --git a/toj/php/step.inc.php b/toj/php/step.inc.php
new file mode 100644
index 0000000..a116a64
--- /dev/null
+++ b/toj/php/step.inc.php
@@ -0,0 +1,17 @@
+<?php
+
+require_once('common.inc.php');
+require_once('square.inc.php');
+require_once('sqlib_scoreboard.inc.php');
+
+function get_prob_stat_uid($sqlc, $msqlc, $sqid, $sboard_id, $uid)
+{
+ $sq = square::get($sqlc, $sqid);
+ if(!$sq)die('Eno_such_sq');
+
+ $data = sqlib_scoreboard::get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, null, $sq->start_time, $sq->end_time, $uid);
+
+ return $data[0];
+}
+
+?>
diff --git a/toj/php/step.php b/toj/php/step.php
new file mode 100644
index 0000000..6425ae1
--- /dev/null
+++ b/toj/php/step.php
@@ -0,0 +1,64 @@
+<?php
+//ini_set("display_errors", "On");
+
+require_once('common.inc.php');
+require_once('step.inc.php');
+require_once('teamt.php');
+
+$sqlc = db_connect();
+$msqlc = db_connect('toj_mod');
+
+if(strlen($action)==0)
+ die('Eno_action');
+if($action == '')
+{
+}
+
+$uid = $_GET['uid'];
+$dat = get_prob_stat_uid($sqlc, $msqlc, 1, 2, $uid);
+
+//var_dump($dat);
+echo('uid : '.$dat->uid.'<br>');
+foreach($dat->problem as $prob)
+{
+ echo('problem '.$prob->proid.' : ');
+ if(!$prob->tries)
+ {
+ echo('--<br>');
+ continue;
+ }
+ echo($prob->best_score.' ');
+ if($prob->is_ac)echo('AC');
+ echo('<br>');
+}
+
+$term = 1;
+$teamid = get_teamid($msqlc, $term, $uid);
+echo('<br>Team : '.$teamid.'<br>Members : <br>');
+$members = get_team_member($msqlc, $term, $teamid);
+foreach($members as $mem)
+{
+ echo('<br>Uid : '.$mem->uid.' ( Level '.$mem->level.' )<br>');
+ $uid = intval($mem->uid);
+ if($uid == intval($_GET['uid']))continue;
+ $dat = get_prob_stat_uid($sqlc, $msqlc, 1, 2, $uid);
+
+ foreach($dat->problem as $prob)
+ {
+ echo('problem '.$prob->proid.' : ');
+ if(!$prob->tries)
+ {
+ echo('--<br>');
+ continue;
+ }
+ echo($prob->best_score.' ');
+ if($prob->is_ac)echo('AC');
+ echo('<br>');
+ }
+}
+
+
+db_close($sqlc);
+db_close($msqlc);
+
+?>
diff --git a/toj/php/teamt.php b/toj/php/teamt.php
new file mode 100644
index 0000000..ca1cd4b
--- /dev/null
+++ b/toj/php/teamt.php
@@ -0,0 +1,28 @@
+<?php
+
+require_once('common.inc.php');
+
+function get_teamid($msqlc, $term, $uid)
+{
+ $sqlstr = 'SELECT "teamid" FROM "sqmod_sprout_team" WHERE "term"=$1 AND "uid"=$2;';
+ $sqlarr = array($term, $uid);
+ $res = pg_query_params($sqlstr, $sqlarr);
+ $teamid = pg_fetch_result($res, 0);
+ return $teamid;
+}
+
+function get_team_member($msqlc, $term, $teamid)
+{
+ $sqlstr = 'SELECT "uid", "level" FROM "sqmod_sprout_team" WHERE "term"=$1 AND "teamid"=$2 ORDER BY "level" DESC, "uid";';
+ $sqlarr = array($term, $teamid);
+ $res = pg_query_params($sqlstr, $sqlarr);
+ $ret = array();
+ while($obj = pg_fetch_object($res))
+ {
+ array_push($ret, $obj);
+ }
+ return $ret;
+}
+
+
+?>
diff --git a/toj/php/test.php b/toj/php/test.php
new file mode 100644
index 0000000..a38a8a8
--- /dev/null
+++ b/toj/php/test.php
@@ -0,0 +1,32 @@
+<?php
+ini_set("display_errors", "On");
+error_reporting(E_ALL & ~E_NOTICE);
+
+require_once('common.inc.php');
+require_once('sqlib.inc.php');
+require_once('user.inc.php');
+
+$msqlc = db_connect('toj_mod');
+$sqlc = db_connect();
+
+function func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $last_time, $tries)
+{
+ return $best_score;
+}
+
+//$a = intval($_GET['a']);
+//sqlib_scoreboard::set_last_update($msqlc, 1, 4, false);
+//$scb = sqlib_scoreboard::get_scoreboard($sqlc, $msqlc, 1, $a, func, null, null, 1, 20);
+//var_dump($scb);
+//echo(json_encode($scb));
+//$test = sqlib_scoreboard::get_last_update($msqlc, 1, $a);
+//echo($test.'<br>');
+//echo(strtotime($test).'<br>');
+//echo(time());
+
+$res = user::reset_password($sqlc, 130);
+var_dump($res);
+
+db_close($sqlc);
+db_close($msqlc);
+?>
diff --git a/toj/php/user.inc.php b/toj/php/user.inc.php
new file mode 100644
index 0000000..1a3eaef
--- /dev/null
+++ b/toj/php/user.inc.php
@@ -0,0 +1,212 @@
+<?php
+
+require_once('common.inc.php');
+require_once('/srv/http/phpmailer/class.phpmailer.php');
+
+const USERNAME_LEN_MIN = 5;
+const USERNAME_LEN_MAX = 20;
+const PASSWORD_LEN_MIN = 5;
+const PASSWORD_LEN_MAX = 32;
+const NICKNAME_LEN_MIN = 1;
+const NICKNAME_LEN_MAX = 32;
+const EMAIL_LEN_MAX = 100;
+
+const USER_PER_USER = 0x00000001;
+const USER_PER_PROCREATOR = 0x00000002;
+const USER_PER_PROADMIN = 0x00000004;
+
+const USER_LEVEL_USER = 0x00000001;
+const USER_LEVEL_PROCREATOR = 0x00000003;
+const USER_LEVEL_PROADMIN = 0x00000007;
+const USER_LEVEL_ADMIN = 0x0000ffff;
+const USER_LEVEL_SUPERADMIN = 0xffffffff;
+
+class user
+{
+ public $uid;
+ public $username;
+ public $password;
+ public $nickname;
+ public $aboutme;
+ public $avatar;
+ public $level;
+ public $email;
+
+ public static function get_from_uid($sqlc, $uid)
+ {
+ //return user object of specified uid. False if user doesn't exists.
+
+ $result = pg_query_params($sqlc, 'SELECT * FROM "user" WHERE "uid"=$1 LIMIT 1;', array(intval($uid))) or die ("Eerror_get_user");
+ $ret = pg_fetch_object($result, null, 'user');
+ pg_free_result($result);
+ if(!$ret)
+ return false;
+ $ret->uid = intval($ret->uid);
+ $ret->level = intval($ret->level);
+ return $ret;
+ }
+
+ public static function get_from_username($sqlc, $username)
+ {
+ //return user object of specified username. False if user doesn't exists.
+
+ $result = pg_query_params($sqlc, 'SELECT * FROM "user" WHERE "username"=$1 LIMIT 1;', array($username));
+ $ret = pg_fetch_object($result, null, 'user');
+ pg_free_result($result);
+ if(!$ret)
+ return false;
+ $ret->uid = intval($ret->uid);
+ $ret->level = intval($ret->level);
+
+ return $ret;
+ }
+
+ public static function add($sqlc, $user)
+ {
+ //add user to database , with $user the user data object
+ //return inserted user object. False if failed.
+ //Assume the insertion is valid!!
+ //requires member: string username, string nickname, string password, stirng aboutme, string avatar, string email
+
+ $sqlstr = 'INSERT INTO "user" ("username", "nickname", "password", "aboutme", "avatar", "email") VALUES ($1, $2, $3, $4, $5, $6) RETURNING *;';
+ $sqlarr = array($user->username, $user->nickname, $user->password, '', '', $user->email);
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ if(!$sqlr)return false;
+ //$sqlr = pg_query($sqlc, 'SELECT SCOPE_IDENTITY();');
+ $obj = pg_fetch_object($sqlr, null, 'user');
+ pg_free_result($sqlr);
+ if($obj)$obj->uid = intval($obj->uid);
+ return $obj;
+ }
+
+ public static function update($sqlc, $user)
+ {
+ //update user data into database, with $user the user data object
+ //return updated object. False if failed.
+ //Assume the update is valid!!
+ //requires member: string nickname, string password, string aboutme, string avatar, string email, int uid
+
+ $sqlstr = 'UPDATE "user" SET "nickname"=$1, "password"=$2, "aboutme"=$3, "avatar"=$4, "email"=$5 WHERE "uid"=$6 RETURNING *;';
+ $sqlarr = array($user->nickname, $user->password, $user->aboutme, $user->avatar, $user->email, intval($user->uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ if(!$sqlr)return false;
+ $obj = pg_fetch_object($sqlr, null, 'user');
+ pg_free_result($sqlr);
+ if($obj)$obj->uid = intval($obj->uid);
+ return $obj;
+ }
+
+ /*public static function update_property($sqlc, $user)
+ {
+ //update property of given user.
+ //return updated object. False if failed.
+ //Assume the update is valid!!
+ //requires member: int[] property, int uid;
+
+ $sqlstr = 'UPDATE "user" SET "property"=$1 WHERE "uid"=$2 RETURNING *;';
+ $sqlarr = array($user->property, intval($user->uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ if(!$sqlr)return false;
+ $obj = pg_fetch_object($sqlr, null, 'user');
+ pg_free_result($sqlr);
+ if($obj)$obj->uid = intval($obj->uid);
+ return $obj;
+ }*/
+
+ public static function get_username($sqlc, $uid)
+ {
+ //return username of given uid. False if not found.
+
+ $sqlstr = 'SELECT "username" FROM "user" WHERE "uid"=$1 LIMIT 1;';
+ $sqlarr = array(intval($uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_result($sqlr, 0);
+ pg_free_result($sqlr);
+ return $ret;
+ }
+
+ public static function get_nickname($sqlc, $uid)
+ {
+ //return nickname of given uid. False if not found.
+
+ $sqlstr = 'SELECT "nickname" FROM "user" WHERE "uid"=$1 LIMIT 1;';
+ $sqlarr = array(intval($uid));
+ $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr);
+ $ret = pg_fetch_result($sqlr, 0);
+ pg_free_result($sqlr);
+ return $ret;
+ }
+
+ public static function reset_password($sqlc, $uid)
+ {
+ //reset password for given uid. False if not found.
+
+ $user = user::get_from_uid($sqlc, $uid);
+ if(!$user)return false;
+ $email = $user->email;
+ if(!$email)return false;
+
+ $passlen = 8;
+ $newpass = '';
+ for($i = 0; $i < $passlen; $i++)
+ {
+ $v = rand()%62;
+ $c = null;
+ if($v<10)$c = chr(48 + $v);
+ else if($v<36)$c = chr(65 + $v - 10);
+ else $c = chr(97 + $v - 36);
+ $newpass = $newpass.$c;
+ }
+ echo($newpass.'<br>');
+
+ //email
+
+ $cmail = new PHPMailer();
+ $cmail->IsSMTP();
+
+ $cmail->SMTPAuth = true;
+ $cmail->SMTPSecure = 'SSL';
+ $cmail->Host = 'ssl://'.SMTP_HOST;
+ $cmail->Port = 465;
+ $cmail->Username = SMTP_USER;
+ $cmail->Password = SMTP_PASS;
+ $cmail->From = 'sprout@csie.ntu.edu.tw';
+ $cmail->FromName = 'Taiwan Online Judge';
+
+ $cmail->AddAddress($email, $user->nickname);
+ $cmail->WordWrap = 70;
+ $cmail->Subject = 'TOJ Password Reset Notice';
+ $cmail->IsHTML = true;
+ $cmail->Body = 'Hi '.$user->nickname.' ('.$user->username.') , your new password is '.$newpass.' .';
+ if(!$cmail->Send())
+ {
+ echo($cmail->ErrorInfo.'<br>');
+ return false;
+ }
+
+
+ return true;
+
+ $user->password = hash('sha512', $newpass);
+ $nuser = user::update($sqlc, $user);
+ if(!$nuser)return false;
+
+ return true;
+ }
+}
+
+function sec_check_level($sqlc, $lv, $uid = null)
+{
+ $uidnull = false;
+ if($uid == null)
+ {
+ $uid = intval($_COOKIE['uid']);
+ $uidnull = true;
+ }
+ if($uidnull && !sec_is_login())
+ return false;
+ $user = user::get_from_uid($sqlc, $uid);
+ return (($user->level & $lv) == $lv);
+}
+
+?>
diff --git a/toj/php/user.php b/toj/php/user.php
new file mode 100644
index 0000000..4570700
--- /dev/null
+++ b/toj/php/user.php
@@ -0,0 +1,160 @@
+<?php
+//ini_set("display_errors", "On");
+//error_reporting(E_ALL & ~E_NOTICE);
+
+require_once('user.inc.php');
+
+$sqlc = db_connect();
+
+$action = $_POST['action'];
+$data = $_POST['data'];
+
+if(strlen($action)==0)
+ die('Eno_action');
+if($action == 'register')
+{
+ //Add new user.
+ //Data: username, password, nickname, email, [aboutme, avatar]
+
+ $user = json_decode($data);
+
+ if(strlen($user->username)<USERNAME_LEN_MIN)
+ die('Eusername_too_short');
+ if(strlen($user->username)>USERNAME_LEN_MAX)
+ die('Eusername_too_long');
+ if(strlen($user->password)<PASSWORD_LEN_MIN)
+ die('Epassword_too_short');
+ if(strlen($user->password)>PASSWORD_LEN_MAX)
+ die('Epassword_too_long');
+ if(strlen($user->nickname)<NICKNAME_LEN_MIN)
+ die('Enickname_too_short');
+ if(strlen($user->nickname)>NICKNAME_LEN_MAX)
+ die('Enickname_too_long');
+ if(strlen($user->email)==0)
+ die('Eempty_email');
+ if(strlen($user->email)>EMAIL_LEN_MAX)
+ die('Eemail_too_long');
+ //if($user->password != $user->passconf)
+ // die('Epassword_not_match');
+
+ if(user::get_from_username($sqlc, $user->username) != false)
+ die('Eusername_exists');
+
+ $user->password = hash('sha512', $user->password);
+
+ $res = user::add($sqlc, $user);
+
+ if(!$res)
+ die('Einsert_failed');
+
+ setcookie('uid', $res->uid, time() + 31536000, '/toj/');
+ setcookie('usec', hash('sha512', $res->uid.SEC_SALT), time() + 31536000, '/toj/');
+
+ echo('S');
+}
+if($action == 'update')
+{
+ //Update exist user
+ //data: nickname, [aboutme, avatar], [oldpw, password]
+
+ $user = json_decode($data);
+
+ if(!sec_is_login())
+ die('Enot_login');
+
+ $user->uid = $_COOKIE['uid'];
+
+ $olduser = user::get_from_uid($sqlc, $user->uid);
+ if(!$olduser)
+ die('Eget_user_failed');
+
+ if(strlen($user->oldpw)>0)
+ {
+ if(strlen($user->password)<PASSWORD_LEN_MIN)
+ die('Epassword_too_short');
+ if(strlen($user->password)>PASSWORD_LEN_MAX)
+ die('Epassword_too_long');
+ //if($user->password != $user->passconf)
+ // die('Epassword_not_match');
+
+ $oldhash = hash('sha512', $user->oldpw);
+
+ if($olduser->password != $oldhash)
+ die('Eold_password_not_match');
+
+ $user->password = hash('sha512', $user->password);
+ }
+ else
+ {
+ $user->password = $olduser->password;
+ }
+
+ if(strlen($user->nickname)<NICKNAME_LEN_MIN)
+ die('Enickname_too_short');
+ if(strlen($user->nickname)>NICKNAME_LEN_MAX)
+ die('Enickname_too_long');
+ if(strlen($user->email)==0)
+ die('Eempty_email');
+ if(strlen($user->email)>EMAIL_LEN_MAX)
+ die('Eemail_too_long');
+
+ $res = user::update($sqlc, $user);
+ if(!$res)
+ die('Eupdate_failed');
+
+ echo('S');
+}
+if($action == 'view')
+{
+ //View user data
+ //data: uid
+
+ $cls = json_decode($data);
+
+ if($cls->uid == null)
+ {
+ if(!sec_is_login())
+ die('Enot_login_or_please_set_uid');
+ $cls->uid = intval($_COOKIE['uid']);
+ }
+ $user = user::get_from_uid($sqlc, $cls->uid);
+ if(!$user)
+ die('Eget_user_failed');
+
+ unset($user->password);
+ if(intval($_COOKIE['uid']) != $user->uid)
+ unset($user->email);
+
+ echo(json_encode($user));
+}
+if($action == 'login')
+{
+ //Login.
+ //data: username, password
+ $login = json_decode($data);
+
+ if(strlen($login->username)==0)
+ die('Eno_username');
+ if(strlen($login->username)>USERNAME_LEN_MAX)
+ die('Eusername_too_long');
+ if(strlen($login->password)==0)
+ die('Eno_password');
+ if(strlen($login->password)>PASSWORD_LEN_MAX)
+ die('Epassword_too_long');
+
+ $user = user::get_from_username($sqlc, $login->username);
+ if(!$user)
+ die('Euser_not_exist');
+
+ if(hash('sha512', $login->password) != $user->password)
+ die('Ewrong_password');
+
+ setcookie('uid', $user->uid, time() + 31536000, '/toj/');
+ setcookie('usec', hash('sha512', $user->uid.SEC_SALT), time() + 31536000, '/toj/');
+
+ echo('S');
+}
+
+db_close($sqlc);
+
+?>
diff --git a/toj/pmod/pmod_multisub/pmod_multisub.css b/toj/pmod/pmod_multisub/pmod_multisub.css
new file mode 100755
index 0000000..308cc94
--- /dev/null
+++ b/toj/pmod/pmod_multisub/pmod_multisub.css
@@ -0,0 +1,52 @@
+div.pmod_multisub > div.main_content{
+ margin:32px 0px 32px 256px;
+}
+div.pmod_multisub > table.probox{
+ width:100%;
+ margin:0px 0px 32px 0px;
+ border-collapse:collapse;
+}
+div.pmod_multisub > table.probox td.info{
+ width:250px;
+ padding:0px 0px 0px 6px;
+ vertical-align:top;
+}
+div.pmod_multisub > table.probox td.info > table.statlist{
+ width:100%;
+ text-align:left;
+ border-collapse:collapse;
+}
+div.pmod_multisub > table.probox td.info > table.statlist td.name{
+ width:96px;
+}
+div.pmod_multisub > table.probox td.info > table.statlist td.value{
+ width:auto;
+}
+div.pmod_multisub > table.probox td.info > table.limitlist{
+ width:100%;
+ text-align:left;
+ border-collapse:collapse;
+}
+div.pmod_multisub > table.probox td.info > table.limitlist td.name{
+ width:96px
+}
+div.pmod_multisub > table.probox td.info > table.limitlist td.value{
+ width:auto;
+}
+div.pmod_multisub > table.probox td.info > table.scorelist{
+ width:100%;
+ text-align:left;
+ border-collapse:collapse;
+}
+div.pmod_multisub > table.probox td.info > table.scorelist tr.item{
+ font-size:16;
+}
+div.pmod_multisub > table.probox td.info > table.scorelist th.no,div.pmod_multisub > td.info > table.scorelist td.no{
+ width:64px;
+}
+div.pmod_multisub > table.probox td.info > table.scorelist th.score,div.pmod_multisub > td.info > table.scorelist td.score{
+ width:auto;
+}
+div.pmod_multisub > table.probox td.content{
+ vertical-align:top;
+}
diff --git a/toj/pmod/pmod_multisub/pmod_multisub.html b/toj/pmod/pmod_multisub/pmod_multisub.html
new file mode 100755
index 0000000..07b19a9
--- /dev/null
+++ b/toj/pmod/pmod_multisub/pmod_multisub.html
@@ -0,0 +1,40 @@
+<div class="main_content"></div>
+<table class="probox ori_probox" style="display:none;"><tr>
+ <td class="info">
+ <h2 class="partname"></h2>
+ <button class="submit">上傳</button>
+
+ <h3>狀態</h3>
+ <table class="statlist">
+ <tr>
+ <td class="name">最佳分數</td>
+ <td class="value bscore"></td>
+ </tr>
+ <tr>
+ <td class="name">解題狀態</td>
+ <td class="value stat"></td>
+ </tr>
+ </table>
+
+ <h3>限制</h3>
+ <table class="limitlist">
+ <tr>
+ <td class="name">時間限制</td>
+ <td class="value timelimit"></td>
+ </tr>
+ <tr>
+ <td class="name">記憶體限制</td>
+ <td class="value memlimit"></td>
+ </tr>
+ </table>
+
+ <h3>配分</h3>
+ <table class="scorelist">
+ <tr class="head">
+ <th class="no">#</th>
+ <th class="score">Score</th>
+ </tr>
+ </table>
+ </td>
+ <td class="content"></td>
+</tr></table>
diff --git a/toj/pmod/pmod_multisub/pmod_multisub.js b/toj/pmod/pmod_multisub/pmod_multisub.js
new file mode 100755
index 0000000..9cbd7a3
--- /dev/null
+++ b/toj/pmod/pmod_multisub/pmod_multisub.js
@@ -0,0 +1,98 @@
+var pmod_multisub = {
+ that:null,
+ j_page:null,
+
+ init:function(that,j_page){
+ pmod_multisub.that = that;
+ pmod_multisub.j_page = j_page;
+
+ that.export_urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_page);
+
+ $.post('/toj/pmod/pmod_multisub/pmod_multisub.php',{'proid':JSON.stringify(that.proid)},function(res){
+ var i;
+ var reto;
+
+ reto = JSON.parse(res);
+ if(reto.redirect != undefined){
+ common.pushurl('/toj/pro/' + reto.redirect + '/');
+ }else{
+ j_page.find('div.main_content').text(reto.main_content);
+ index.setcontent($('<span>' + reto.proname + '</span>'));
+
+ for(i = 0;i < reto.pro.length;i++){
+ pmod_multisub.probox_add(reto.pro[i]);
+ }
+ }
+ });
+ }else if(direct == 'out'){
+ that.fadeout(j_page);
+ }else if(direct == 'same'){
+
+ }
+ };
+ },
+ probox_add:function(proo){
+ var i;
+
+ var j_probox;
+ var j_table;
+ var j_item;
+
+ j_probox = pmod_multisub.j_page.find('table.ori_probox').clone();
+ j_probox.removeClass('ori_probox');
+
+ j_probox.find('td.info > h2.partname').text(proo.partname + ' (' + proo.score + '%)');
+ j_probox.find('td.content').html(proo.content);
+
+ $.post('/toj/php/problem.php',{'action':'get_pro_stat','data':JSON.stringify({'proid':proo.proid})},function(res){
+ var reto
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ j_probox.find('td.info > table.statlist td.bscore').text(reto.score);
+ if(reto.tried == false){
+ j_probox.find('td.info > table.statlist td.bscore').css('color','#1C1C1C');
+ j_probox.find('td.info > table.statlist td.stat').text('未嘗試');
+ }else{
+ if(reto.score < 60){
+ j_probox.find('td.info > table.statlist td.bscore').css('color','#FF0000');
+ }else if(reto.score < 80){
+ j_probox.find('td.info > table.statlist td.bscore').css('color','#00FF00');
+ }else if(reto.score < 100){
+ j_probox.find('td.info > table.statlist td.bscore').css('color','#FFFF00');
+ }else{
+
+ j_probox.find('td.info > table.statlist td.bscore').css('color','#FFFFFF');
+ }
+
+ if(reto.is_ac == true){
+ j_probox.find('td.info > table.statlist td.stat').text('已通過');
+ }else{
+ j_probox.find('td.info > table.statlist td.stat').text('已嘗試');
+ }
+ }
+ }
+ });
+
+ j_probox.find('td.info > table.limitlist td.timelimit').text(proo.timelimit + ' ms');
+ j_probox.find('td.info > table.limitlist td.memlimit').text(proo.memlimit + ' KB');
+
+ j_table = j_probox.find('table.scorelist');
+ j_table.find('tr.item').remove();
+ for(i = 0;i < proo.partition.count;i++){
+ j_item = $('<tr class="item"><td class="no"></td><td class="score"></td></tr>');
+ j_item.find('td.no').text(i + 1);
+ j_item.find('td.score').text(proo.partition.score[i]);
+ j_table.append(j_item);
+ }
+
+ j_probox.find('td.info > button.submit').on('click',function(e){
+ pmod_multisub.that.submit(proo.proid);
+ });
+
+ j_probox.show();
+ pmod_multisub.j_page.append(j_probox);
+ }
+};
diff --git a/toj/pmod/pmod_multisub/pmod_multisub.php b/toj/pmod/pmod_multisub/pmod_multisub.php
new file mode 100755
index 0000000..342ff41
--- /dev/null
+++ b/toj/pmod/pmod_multisub/pmod_multisub.php
@@ -0,0 +1,77 @@
+<?php
+require_once('../../php/problem.inc.php');
+
+const PMODNAME = 'pmod_multisub';
+
+function get_set($prodir)
+{
+ $fd = fopen($prodir.'setting','r');
+ while($line = fgets($fd))
+ {
+ if($line[0] == '=')break;
+ }
+ $set = '';
+ while(($line = fgets($fd)))
+ {
+ $set = $set.$line;
+ }
+ fclose($fd);
+ return json_decode($set);
+}
+
+$sqlc = db_connect();
+
+$proid = json_decode($_POST['proid']);
+if(gettype($proid) != 'integer' || $proid < 1){
+ exit('Eproid');
+}
+
+if(!problem::is_available($sqlc, $proid)){
+ exit('Epermission');
+}
+
+$pro = problem::get($sqlc, $proid);
+if($pro->pmodname != PMODNAME)
+ exit('Ewrong_pmod');
+
+$prodir = '/srv/http/toj/center/pro/';
+
+$redir = file_get_contents($prodir.$proid.'/redirect');
+if($redir)
+{
+ $ret = new stdClass();
+ $ret->redirect = intval($redir);
+ exit(json_encode($ret));
+}
+
+$ret = new stdClass();
+
+$mfile = file_get_contents($prodir.$proid.'/multiset');
+$multiset = json_decode($mfile);
+
+$main_cont = file_get_contents($prodir.$proid.'/public/main_content');
+$ret->main_content = $main_cont;
+$ret->pro = array();
+$ret->proname = $multiset->proname;
+
+foreach($multiset->prolist as $spro)
+{
+ $apro = new stdClass();
+ $apro->proid = $spro->proid;
+ $apro->score = $spro->score;
+ $apro->partname = $spro->partname;
+
+ $apro->content = file_get_contents($prodir.$apro->proid.'/public/content');
+ $setting = get_set($prodir.$apro->proid.'/');
+ $apro->timelimit = $setting->timelimit;
+ $apro->memlimit = $setting->memlimit;
+ $apro->partition = new stdClass();
+ $apro->partition->count = $setting->count;
+ $apro->partition->score = $setting->score;
+
+ array_push($ret->pro, $apro);
+}
+
+echo(json_encode($ret));
+db_close($sqlc);
+?>
diff --git a/toj/pmod/pmod_test/pmod_test.css b/toj/pmod/pmod_test/pmod_test.css
new file mode 100755
index 0000000..2cd5bfb
--- /dev/null
+++ b/toj/pmod/pmod_test/pmod_test.css
@@ -0,0 +1,53 @@
+div.pmod_test > div.info{
+ width:250px;
+ height:100%;
+ padding:0px 0px 0px 6px;
+ position:absolute;
+ top:0px;
+ left:0px;
+ overflow:auto;
+}
+div.pmod_test > div.info > table.statlist{
+ width:100%;
+ text-align:left;
+ border-collapse:collapse;
+}
+div.pmod_test > div.info > table.statlist td.name{
+ width:96px;
+}
+div.pmod_test > div.info > table.statlist td.value{
+ width:auto;
+}
+div.pmod_test > div.info > table.limitlist{
+ width:100%;
+ text-align:left;
+ border-collapse:collapse;
+}
+div.pmod_test > div.info > table.limitlist td.name{
+ width:96px
+}
+div.pmod_test > div.info > table.limitlist td.value{
+ width:auto;
+}
+div.pmod_test > div.info > table.scorelist{
+ width:100%;
+ text-align:left;
+ border-collapse:collapse;
+}
+div.pmod_test > div.info > table.scorelist tr.item{
+ font-size:16;
+}
+div.pmod_test > div.info > table.scorelist th.no,div.pmod_test > div.info > table.scorelist td.no{
+ width:64px;
+}
+div.pmod_test > div.info > table.scorelist th.score,div.pmod_test > div.info > table.scorelist td.score{
+ width:auto;
+}
+div.pmod_test > div.content{
+ height:100%;
+ padding:0px 6px 0px 0px;
+ position:absolute;
+ top:0px;
+ left:256px;
+ overflow:auto;
+}
diff --git a/toj/pmod/pmod_test/pmod_test.html b/toj/pmod/pmod_test/pmod_test.html
new file mode 100755
index 0000000..10b297b
--- /dev/null
+++ b/toj/pmod/pmod_test/pmod_test.html
@@ -0,0 +1,37 @@
+<div class="info">
+ <h2 class="proid">ProID:</h2>
+ <button class="submit">上傳</button>
+
+ <h3>狀態</h3>
+ <table class="statlist">
+ <tr>
+ <td class="name">最佳分數</td>
+ <td class="value bscore"></td>
+ </tr>
+ <tr>
+ <td class="name">解題狀態</td>
+ <td class="value stat"></td>
+ </tr>
+ </table>
+
+ <h3>限制</h3>
+ <table class="limitlist">
+ <tr>
+ <td class="name">時間限制</td>
+ <td class="value timelimit"></td>
+ </tr>
+ <tr>
+ <td class="name">記憶體限制</td>
+ <td class="value memlimit"></td>
+ </tr>
+ </table>
+
+ <h3>配分</h3>
+ <table class="scorelist">
+ <tr class="head">
+ <th class="no">#</th>
+ <th class="score">Score</th>
+ </tr>
+ </table>
+</div>
+<div class="content"></div>
diff --git a/toj/pmod/pmod_test/pmod_test.js b/toj/pmod/pmod_test/pmod_test.js
new file mode 100755
index 0000000..c691c8a
--- /dev/null
+++ b/toj/pmod/pmod_test/pmod_test.js
@@ -0,0 +1,74 @@
+var pmod_test = {
+ init:function(that,j_page){
+ that.export_urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_page);
+ j_page.find('div.info > h2.proid').text('ProID:' + that.proid);
+ $.post('/toj/pmod/pmod_test/pmod_test.php',{'proid':JSON.stringify(that.proid)},function(res){
+ var i;
+ var reto;
+ var seto;
+ var j_table;
+ var j_item;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ seto = reto.set;
+ index.setcontent($('<span>' + that.proname + '</span>'));
+ j_page.find('div.content').html(reto.content);
+
+ $.post('/toj/php/problem.php',{'action':'get_pro_stat','data':JSON.stringify({'proid':that.proid})},function(res){
+ var reto
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ j_page.find('div.info > table.statlist td.bscore').text(reto.score);
+ if(reto.tried == false){
+ j_page.find('div.info > table.statlist td.bscore').css('color','#1C1C1C');
+ j_page.find('div.info > table.statlist td.stat').text('未嘗試');
+ }else{
+ if(reto.score < 60){
+ j_page.find('div.info > table.statlist td.bscore').css('color','#FF0000');
+ }else if(reto.score < 80){
+ j_page.find('div.info > table.statlist td.bscore').css('color','#00FF00');
+ }else if(reto.score < 100){
+ j_page.find('div.info > table.statlist td.bscore').css('color','#FFFF00');
+ }else{
+
+ j_page.find('div.info > table.statlist td.bscore').css('color','#FFFFFF');
+ }
+
+ if(reto.is_ac == true){
+ j_page.find('div.info > table.statlist td.stat').text('已通過');
+ }else{
+ j_page.find('div.info > table.statlist td.stat').text('已嘗試');
+ }
+ }
+ }
+ });
+
+ j_page.find('div.info > table.limitlist td.timelimit').text(seto.timelimit + ' ms');
+ j_page.find('div.info > table.limitlist td.memlimit').text(seto.memlimit + ' KB');
+
+ j_table = j_page.find('table.scorelist');
+ j_table.find('tr.item').remove();
+ for(i = 0;i < seto.count;i++){
+ j_item = $('<tr class="item"><td class="no"></td><td class="score"></td></tr>');
+ j_item.find('td.no').text(i + 1);
+ j_item.find('td.score').text(seto.score[i]);
+ j_table.append(j_item);
+ }
+ }
+ });
+ }else if(direct == 'out'){
+ that.fadeout(j_page);
+ }else if(direct == 'same'){
+
+ }
+ };
+
+ j_page.find('div.info > button.submit').on('click',function(e){
+ that.submit();
+ });
+ }
+};
diff --git a/toj/pmod/pmod_test/pmod_test.php b/toj/pmod/pmod_test/pmod_test.php
new file mode 100755
index 0000000..27eecf2
--- /dev/null
+++ b/toj/pmod/pmod_test/pmod_test.php
@@ -0,0 +1,42 @@
+<?php
+require_once('../../php/problem.inc.php');
+
+const PMODNAME = 'pmod_test';
+
+$proid = json_decode($_POST['proid']);
+if(gettype($proid) != 'integer' || $proid < 1){
+ exit('Eproid');
+}
+
+$sqlc = db_connect();
+if(!problem::is_available($sqlc,$proid)){
+ exit('Epermission');
+}
+
+$pro = problem::get($sqlc, $proid);
+if($pro->pmodname != PMODNAME)
+ exit('Ewrong_pmod');
+
+db_close($sqlc);
+
+$prodir = '/srv/http/toj/center/pro/'.$proid.'/';
+
+$fd = fopen($prodir.'setting','r');
+while($line = fgets($fd)){
+ if($line[0] == '='){
+ break;
+ }
+}
+$set = '';
+while(($line = fgets($fd))){
+ $set = $set.$line;
+}
+fclose($fd);
+
+$content = file_get_contents($prodir.'public/content');
+
+echo(json_encode(array(
+ 'set' => json_decode($set),
+ 'content' => $content
+)));
+?>
diff --git a/toj/smod/smod_test/smod_test.css b/toj/smod/smod_test/smod_test.css
new file mode 100755
index 0000000..be7aac2
--- /dev/null
+++ b/toj/smod/smod_test/smod_test.css
@@ -0,0 +1,29 @@
+div.smod_test > h1.msg{
+ padding:0px 0px 6px 0px;
+}
+div.smod_test > table.subinfolist{
+ padding:0px 0px 6px 0px;
+ text-align:left;
+}
+div.smod_test > table.subinfolist tr.head{
+ height:32px;
+ font-size:20px;
+}
+div.smod_test > table.subinfolist tr.item{
+ height:32px;
+}
+div.smod_test > table.subinfolist th.runtime,div.smod_test > table.subinfolist td.runtime{
+ width:96px;
+}
+div.smod_test > table.subinfolist th.memory,div.smod_test > table.subinfolist td.memory{
+ width:96px;
+}
+div.smod_test > table.subinfolist th.status,div.smod_test > table.subinfolist td.status{
+ width:96px;
+}
+div.smod_test > table.subinfolist th.score,div.smod_test > table.subinfolist td.score{
+ width:96px;
+}
+div.smod_test > table.subinfolist th.score,div.smod_test > table.subinfolist td.errmsg{
+ width:auto;
+}
diff --git a/toj/smod/smod_test/smod_test.html b/toj/smod/smod_test/smod_test.html
new file mode 100755
index 0000000..0e70522
--- /dev/null
+++ b/toj/smod/smod_test/smod_test.html
@@ -0,0 +1,10 @@
+<h1 class="msg" style="display:none;">Waiting</h1>
+<table class="subinfolist" style="display:none;">
+ <tr class="head">
+ <th class="runtime">執行時間</th>
+ <th class="memory">記憶體</th>
+ <th class="status">狀態</th>
+ <th class="score">分數</th>
+ <th class="errmsg"></th>
+ </tr>
+</table>
diff --git a/toj/smod/smod_test/smod_test.js b/toj/smod/smod_test/smod_test.js
new file mode 100755
index 0000000..0ef3674
--- /dev/null
+++ b/toj/smod/smod_test/smod_test.js
@@ -0,0 +1,43 @@
+var smod_test = {
+ init:function(that,j_mbox){
+ that.export_switchchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_mbox);
+ $.post('/toj/smod/smod_test/smod_test.php',{'subid':JSON.stringify(that.subid)},function(res){
+ var i;
+ var result;
+ var reso;
+ var j_table;
+ var j_item;
+
+
+ if(res[0] == 'E'){
+ if(res == 'Enull'){
+ j_mbox.find('h1.msg').show();
+ }
+ }else{
+ result = JSON.parse(res).result;
+
+ j_table = j_mbox.find('table.subinfolist');
+ for(i = 0;i < result.length;i++){
+ reso = result[i];
+ j_item = $('<tr class="item"><td class="runtime"></td><td class="memory"></td><td class="status"></td><td class="score"></td><td class="errmsg"></td></tr>')
+ j_item.find('td.runtime').text(reso.runtime);
+ j_item.find('td.memory').text(reso.memory);
+ j_item.find('td.status').text(RESULTMAP[reso.status]);
+ j_item.find('td.score').text(reso.score);
+ if(reso.errmsg != undefined){
+ j_item.find('td.errmsg').text(reso.errmsg);
+ }
+
+ j_table.append(j_item);
+ }
+ j_table.show();
+ }
+ });
+ }else if(direct == 'out'){
+ that.fadeout(j_mbox);
+ }
+ };
+ }
+};
diff --git a/toj/smod/smod_test/smod_test.php b/toj/smod/smod_test/smod_test.php
new file mode 100755
index 0000000..39d2cb3
--- /dev/null
+++ b/toj/smod/smod_test/smod_test.php
@@ -0,0 +1,21 @@
+<?php
+require_once('../../php/status.inc.php');
+
+$subid = json_decode($_POST['subid']);
+if(gettype($subid) != 'integer' || $subid < 1){
+ exit('Esubid');
+}
+
+$sqlc = db_connect();
+if(!status::subid_is_available($sqlc,$subid)){
+ exit('Epermission');
+}
+db_close($sqlc);
+
+$subdir = '/srv/http/toj/center/submit/'.($subid - ($subid % 1000)).'/'.$subid.'/result/';
+if(($result = file_get_contents($subdir.'result')) == ''){
+ exit('Enull');
+}
+
+echo($result);
+?>
diff --git a/toj/sqmod/sqmod_test/sqmod_test.css b/toj/sqmod/sqmod_test/sqmod_test.css
new file mode 100755
index 0000000..52009d2
--- /dev/null
+++ b/toj/sqmod/sqmod_test/sqmod_test.css
@@ -0,0 +1,97 @@
+div.sqmod_test > div.pro_tab > table.prolist{
+ width:62%;
+ margin:0px 0px 6px 257px;
+ border-collapse:collapse;
+ text-align:left;
+}
+div.sqmod_test > div.pro_tab > table.prolist tr.head{
+ height:64px;
+ font-size:20px;
+}
+div.sqmod_test > div.pro_tab > table.prolist tr.item{
+ height:32px;
+ border-left:2px solid;
+ border-color:#1C1C1C;
+}
+div.sqmod_test > div.pro_tab > table.prolist tr:hover.item{
+ background-color:rgba(255,255,255,0.2);
+}
+div.sqmod_test > div.pro_tab > table.prolist th.no,div.sqmod_test > div.pro_tab > table.prolist td.no{
+ width:96px;
+ padding:0px 0px 0px 6px;
+}
+div.sqmod_test > div.pro_tab > table.prolist th.name,div.sqmod_test > div.pro_tab > table.prolist td.name{
+ width:auto;
+}
+div.sqmod_test > div.pro_tab > table.prolist th.bscore,div.sqmod_test > div.pro_tab > table.prolist td.bscore{
+ width:128px;
+}
+div.sqmod_test > div.pro_tab > table.prolist th.team,div.sqmod_test > div.pro_tab > table.prolist td.team{
+ width:64px;
+ display:none;
+}
+div.sqmod_test > div.pro_tab > table.prolist a.link{
+ color:#E9E9E9;
+ text-decoration:none;
+}
+div.sqmod_test > div.pro_tab > table.prolist a:hover.link{
+ color:#E0E0E0;
+ text-decoration:underline;
+}
+
+div.sqmod_test > div.pro_tab > table.stat{
+ margin:32px 0px 6px 256px;
+ border-collapse:collapse;
+ text-align:left;
+}
+div.sqmod_test > div.pro_tab > table.stat tr{
+ height:32px;
+}
+div.sqmod_test > div.pro_tab div.prog_box{
+ width:512px;
+ height:16px;
+ background-color:rgba(255,255,255,0.2);
+ color:#1C1C1C;
+ font-size:12px;
+ font-family:monospace;
+ line-height:16px;
+ text-align:right;
+ position:relative;
+}
+div.sqmod_test > div.pro_tab div.prog_box > div.pass{
+ width:0%;
+ height:16px;
+ border-right:rgba(0,255,0,0.8) 2px solid;
+ position:absolute;
+ top:0px;
+ left:0%;
+ overflow:hidden;
+}
+div.sqmod_test > div.pro_tab div.prog_box > div.good{
+ width:0%;
+ height:16px;
+ border-right:rgba(255,255,0,0.8) 2px solid;
+ position:absolute;
+ top:0px;
+ left:0%;
+ overflow:hidden;
+}
+div.sqmod_test > div.pro_tab div.prog_box > div.total{
+ width:0%;
+ height:16px;
+ border-right:rgba(255,255,255,0.8) 2px solid;
+ position:absolute;
+ top:0px;
+ left:0%;
+ overflow:hidden;
+}
+div.sqmod_test > div.pro_tab div.prog_box > div.prog{
+ width:0%;
+ height:16px;
+ background-color:rgba(0,0,0,0);
+ font-weight:bold;
+ position:absolute;
+ top:0px;
+ left:0px;
+ overflow:hidden;
+}
diff --git a/toj/sqmod/sqmod_test/sqmod_test.html b/toj/sqmod/sqmod_test/sqmod_test.html
new file mode 100755
index 0000000..9b93096
--- /dev/null
+++ b/toj/sqmod/sqmod_test/sqmod_test.html
@@ -0,0 +1,33 @@
+<div tab="pro" class="common_tab pro_tab">
+ <table class="prolist">
+ <tr class="head">
+ <th class="no">#</th>
+ <th class="name">題目名稱</th>
+ <th class="bscore">最佳分數</th>
+ <th class="team"><a class="link"></a></th>
+ <th class="team"><a class="link"></a></th>
+ <th class="team"><a class="link"></a></th>
+ <th class="team"><a class="link"></a></th>
+ </tr>
+ </table>
+ <table class="stat">
+ <tr class="user_prog">
+ <td style="width:105px;">個人進度</td>
+ <td><div class="prog_box user_prog">
+ <div class="pass"></div>
+ <div class="good"></div>
+ <div class="total"></div>
+ <div class="prog"></div>
+ </div></td>
+ </tr>
+ <tr class="team_prog" style="display:none;">
+ <td>小組進度</td>
+ <td><div class="prog_box team_prog">
+ <div class="pass"></div>
+ <div class="good"></div>
+ <div class="total"></div>
+ <div class="prog"></div>
+ </div></td>
+ </tr>
+ </table>
+</div>
diff --git a/toj/sqmod/sqmod_test/sqmod_test.inc.php b/toj/sqmod/sqmod_test/sqmod_test.inc.php
new file mode 100644
index 0000000..3e472e7
--- /dev/null
+++ b/toj/sqmod/sqmod_test/sqmod_test.inc.php
@@ -0,0 +1,149 @@
+<?php
+
+require_once('../../php/common.inc.php');
+require_once('../../php/square.inc.php');
+require_once('../../php/sqlib_scoreboard.inc.php');
+
+const SQMODNAME = 'sqmod_test';
+
+const SCOREBOARD_ID_PROBSTAT = 1;
+
+
+function get_pro_stat_uid($sqlc, $msqlc, $sqid, $sboard_id, $uid)
+{
+ //get user $uid solving status of square $sqid. $sboard_id can be set as a fixed value.
+ $sq = square::get($sqlc, $sqid);
+ if(!$sq)die('Eno_such_sq');
+
+ $data = sqlib_scoreboard::get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, null, $sq->start_time, $sq->end_time, $uid);
+
+ return $data[0];
+}
+
+function process_pro_stat($obj)
+{
+ $ret = array();
+ foreach($obj->problem as $pro)
+ {
+ $ps = new stdClass();
+ $ps->proid = $pro->proid;
+ $ps->is_ac = $pro->is_ac;
+ $ps->best_score = $pro->best_score;
+ //$ps->rank_score = $pro->rank_score;
+ $ps->tried = ($pro->tries > 0);
+ //array_push($ret, $ps);
+ $ret[$pro->proid] = $ps;
+ }
+ return $ret;
+}
+
+function get_setting($sqid)
+{
+ $sqdir = '/srv/http/toj/center/sq/'.$sqid.'/';
+ $cont = file_get_contents($sqdir.'setting');
+ $data = json_decode($cont);
+ return $data;
+}
+
+function get_term($data, $sqid)
+{
+ return $data->term;
+}
+
+function calc_score($stat, $data, $sqid)
+{
+ $prolist = $data->pro;
+ $ret = array();
+ foreach($prolist as $pro)
+ {
+ $proid = $pro->proid;
+ $np = new stdClass();
+ if($stat)$np = clone $stat[$proid];
+ //else continue;
+ if(!$stat)
+ {
+ $np->proid = $proid;
+ $np->best_score = 0;
+ $np->tried = false;
+ $np->is_ac = false;
+ array_push($ret, $np);
+ continue;
+ }
+ $method = $pro->method;
+ //$np->full_score = $pro->score;
+ if($method == 'normal')
+ {
+ $np->best_score = $stat[$proid]->best_score / 100 * $pro->score;
+ }
+ if($method == 'max')
+ {
+ $score = 0;
+ $tis_ac = false;
+ foreach($pro->config as $conf)
+ {
+ //$np->best_score = json_encode($conf);
+ $nowscore = 0;
+ $is_ac = true;
+ foreach($conf as $unit)
+ {
+ $nowscore += $stat[$unit[0]]->best_score / 100 * $unit[1];
+ $np->tried = $np->tried || $stat[$unit[0]]->tried;
+ if(!$stat[$unit[0]]->is_ac)$is_ac = false;
+ }
+ $score = max($score, $nowscore);
+ if($is_ac)$tis_ac = true;
+ }
+ $np->is_ac = $tis_ac;
+ $np->best_score = $score;// / 100 * $pro->score;
+ }
+ //$np->best_score = json_encode($np);
+ array_push($ret, $np);
+ }
+ //$stat[0]->best_score = json_encode($ret[0]);
+ return $ret;
+}
+
+function process_pro_list($list, $data, $sqid)
+{
+ $prol = $data->pro;
+ $ret = array();
+ foreach($prol as $pro)
+ {
+ $proid = $pro->proid;
+ $np = null;
+ foreach($list as $op)
+ {
+ if($op->proid == $proid)
+ {
+ $np = clone $op;
+ break;
+ }
+ }
+ $np->prono = $pro->prono;
+ $np->full_score = $pro->score;
+ if($pro->proname)$np->proname = $pro->proname;
+ array_push($ret, $np);
+ }
+ return $ret;
+}
+
+function get_base_line($data, $sqid, $isteam)
+{
+ $ret = new stdClass();
+ if($isteam)
+ {
+ $ret->total_score = $data->total_score;
+ $ret->pass_score = $data->pass_score_team;
+ $ret->good_score = $data->good_score_team;
+ }
+ else
+ {
+ $ret->total_score = $data->total_score;
+ $ret->pass_score = $data->pass_score;
+ $ret->good_score = $data->good_score;
+ }
+
+ return $ret;
+}
+
+?>
diff --git a/toj/sqmod/sqmod_test/sqmod_test.js b/toj/sqmod/sqmod_test/sqmod_test.js
new file mode 100755
index 0000000..6d01881
--- /dev/null
+++ b/toj/sqmod/sqmod_test/sqmod_test.js
@@ -0,0 +1,259 @@
+var sqmod_test = {
+ init:function(that,j_page){
+ var pro_tab = new class_sqmod_test_pro_tab(that);
+
+ that.export_urlchange = function(direct){
+ var _in = function(){
+ that.fadein(j_page);
+
+ that.addtab('pro',pro_tab);
+ index.addtab('pro','/toj/sq/' + that.sqid + '/','題目');
+
+ _change();
+ };
+ var _out = function(){
+ that.fadeout(j_page);
+ index.emptytab();
+ that.tab_urlchange(null);
+ };
+ var _change = function(){
+ var tabname;
+
+ tabname = common.geturlpart()[2];
+ if(!(tabname in that.tab_list)){
+ tabname = 'pro';
+ common.replaceurl('/toj/sq/' + that.sqid + '/pro/');
+ }
+ that.tab_urlchange(tabname);
+ }
+
+ if(direct == 'in'){
+ _in();
+ }else if(direct == 'out'){
+ _out();
+ }else if(direct == 'same'){
+ _change();
+ }
+ }
+ }
+};
+
+var class_sqmod_test_pro_tab = function(paobj){
+ var that = this;
+ var j_tab = $('#index_page > [page="sq"] > [tab="pro"]');
+ var promap = null;
+
+ var pro_listset = function(j_item,proo){
+ var i;
+
+ var bscore;
+ var fscore;
+ var ratio;
+ var j_a;
+ var j_team;
+
+ if(proo != null){
+ j_item.attr('proid',proo.proid);
+
+ j_item.find('td.no').text(proo.prono);
+ j_a = j_item.find('td.name > a.link');
+ j_a.attr('href','/toj/pro/' + proo.proid + '/');
+ j_a.text(proo.proname);
+
+ bscore = proo.bscore;
+ fscore = proo.full_score;
+ j_item.find('td.bscore').text(bscore + ' / ' + fscore);
+
+ if(proo.tried == false){
+ j_item.css('border-color','#1C1C1C');
+ }else{
+ ratio = bscore / fscore;
+
+ if(ratio < 0.6){
+ j_item.css('border-color','#FF0000');
+ }else if(ratio < 0.8){
+ j_item.css('border-color','#00FF00');
+ }else if(ratio < 1){
+ j_item.css('border-color','#FFFF00');
+ }else{
+ j_item.css('border-color','#FFFFFF');
+ }
+ }
+
+ j_team = j_item.find('td.team');
+ j_team.hide();
+ for(i = 0;i < proo.tscore.length;i++){
+ $(j_team[i]).text(proo.tscore[i]);
+ $(j_team[i]).show();
+ }
+ }
+ };
+ var pro_listnew = function(proo){
+ var j_item;
+
+ j_item = $('<tr class="item"><td class="no"></td><td class="name"><a class="link"></a></td><td class="bscore"></td><td class="team"></td><td class="team"></td><td class="team"></td><td class="team"></td></tr>');
+ pro_listset(j_item,proo);
+
+ return j_item;
+ };
+ var prog_set = function(j_progbox,baseline,totalscore){
+ var off;
+ var ratio;
+ var j_prog;
+
+ off = 0;
+ ratio = baseline.pass_score * 100 / baseline.total_score;
+ j_prog = j_progbox.find('div.pass');
+ j_prog.css('width',ratio + '%');
+ j_prog.html(baseline.pass_score + '&nbsp');
+ off += ratio;
+ ratio = (baseline.good_score - baseline.pass_score) * 100 / baseline.total_score;
+ j_prog = j_progbox.find('div.good');
+ j_prog.css('left',off + '%');
+ j_prog.css('width',ratio + '%');
+ j_prog.html(baseline.good_score + '&nbsp');
+ off += ratio;
+ ratio = 100 - off;
+ j_prog = j_progbox.find('div.total');
+ j_prog.css('left',off + '%');
+ j_prog.css('width',ratio + '%');
+ j_prog.html(baseline.total_score + '&nbsp');
+
+ ratio = totalscore * 100 / baseline.total_score;
+ j_prog = j_progbox.find('div.prog');
+ j_prog.css('width',ratio + '%');
+ j_prog.html(totalscore + '&nbsp');
+ if(totalscore < baseline.pass_score){
+ ratio = totalscore / baseline.pass_score;
+ j_prog.css('background-color','rgba(255,' + Math.round(64 * ratio) + ',0,0.8)');
+ }else if(totalscore < baseline.good_score){
+ ratio = (totalscore - baseline.pass_score) / (baseline.good_score - baseline.pass_score);
+ j_prog.css('background-color','rgba(' + Math.round(128 * ratio) + ',255,0,0.8)');
+ }else if(totalscore < baseline.total_score){
+ ratio = (totalscore - baseline.good_score) / (baseline.total_score - baseline.good_score);
+ j_prog.css('background-color','rgba(255,255,' + Math.round(128 * ratio) + ',0.8)');
+ }else{
+ j_prog.css('background-color','rgba(255,255,255,0.8)');
+ }
+ }
+ var prostat_refresh = function(){
+ if(refresh_flag == false){
+ return;
+ }
+
+ $.post('/toj/sqmod/sqmod_test/sqmod_test.php',{'action':'get_user_stat','data':JSON.stringify({'sqid':paobj.sqid,'display_team':true})},function(res){
+ var i;
+ var j;
+
+ var reto;
+ var team;
+ var teamo;
+ var prostat;
+ var prostato;
+ var proo;
+ var user_total;
+ var team_total;
+ var maxscore;
+ var j_list;
+ var j_team;
+ var j_a;
+ var j_item;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ team = reto.team;
+ prostat = reto.prostat;
+
+ j_list = j_tab.find('table.prolist');
+ if(team != undefined){
+ j_team = j_list.find('th.team');
+ for(i = 0;i < team.length;i++){
+ teamo = team[i];
+
+ j_a = j_team.find('a.link');
+ $(j_a[i]).attr('href','/toj/user/' + teamo.uid + '/')
+ $(j_a[i]).text(teamo.name);
+
+ for(j = 0;j < teamo.prostat.length;j++){
+ if(teamo.prostat[j].tried == true){
+ promap[teamo.prostat[j].proid].tscore[i] = teamo.prostat[j].best_score;
+ }else{
+ promap[teamo.prostat[j].proid].tscore[i] = 0;
+ }
+ }
+
+ j_team.show();
+ }
+
+ j_tab.find('table.stat tr.team_prog').show();
+ }
+
+ user_total = 0;
+ team_total = 0;
+ for(i = 0;i < prostat.length;i++){
+ prostato = prostat[i];
+ proo = promap[prostato.proid];
+ proo.bscore = prostato.best_score;
+ proo.tried = prostato.tried;
+ user_total += prostato.best_score;
+ j_item = j_list.find('[proid = "' + prostato.proid + '"]');
+ if(j_item.length > 0){
+ pro_listset(j_item,proo);
+ }
+
+ maxscore = proo.bscore;
+ for(j = 0;j < proo.tscore.length;j++){
+ maxscore = Math.max(maxscore,proo.tscore[j]);
+ }
+ team_total += maxscore;
+ }
+
+ prog_set(j_tab.find('table.stat div.user_prog'),reto.base_line,user_total);
+ prog_set(j_tab.find('table.stat div.team_prog'),reto.team_base_line,team_total);
+
+ setTimeout(prostat_refresh,2000);
+ }
+ });
+ };
+
+ that.__super(paobj);
+
+ that.urlchange = function(direct){
+ if(direct == 'in'){
+ that.fadein(j_tab);
+ refresh_flag = true;
+
+ $.post('/toj/sqmod/sqmod_test/sqmod_test.php',{'action':'get_prolist','data':JSON.stringify({'sqid':paobj.sqid})},function(res){
+ var i;
+ var reto;
+ var proo;
+ var j_list;
+ var j_item;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+
+ promap = new Array;
+ j_list = j_tab.find('table.prolist');
+ for(i = 0;i < reto.length;i++){
+ proo = reto[i];
+ proo.bscore = 0;
+ proo.tscore = new Array;
+ proo.tried = false;
+ if(proo.hidden == false){
+ promap[proo.proid] = proo;
+ j_item = pro_listnew(proo);
+ j_list.append(j_item);
+ }
+ }
+
+ prostat_refresh();
+ }
+ });
+
+ }else if(direct == 'out'){
+ that.fadeout(j_tab);
+ refresh_flag = false;
+ }
+ };
+}; __extend(class_sqmod_test_pro_tab,class_common_tab);
diff --git a/toj/sqmod/sqmod_test/sqmod_test.php b/toj/sqmod/sqmod_test/sqmod_test.php
new file mode 100755
index 0000000..40093e2
--- /dev/null
+++ b/toj/sqmod/sqmod_test/sqmod_test.php
@@ -0,0 +1,84 @@
+<?php
+//ini_set("display_errors", "On");
+
+require_once('../../php/common.inc.php');
+require_once('../../php/user.inc.php');
+require_once('sqmod_test.inc.php');
+require_once('team.inc.php');
+require_once('../../php/sqlib_scoreboard.inc.php');
+
+$sqlc = db_connect();
+$msqlc = db_connect('toj_mod');
+
+$action = $_POST['action'];
+$data = $_POST['data'];
+
+if(strlen($action)==0)
+ die('Eno_action');
+if($action == 'get_prolist')
+{
+ $dt = json_decode($data);
+ $sqid = intval($dt->sqid);
+ if(square::get_sqmod($sqlc, $sqid) != SQMODNAME)
+ die('Eerror_sqid_this_mod');
+ if(!sec_is_login())
+ die('Enot_login');
+ $uid = intval($_COOKIE['uid']);
+ if(square::get_user_relationship($sqlc, $uid, $sqid) != SQUARE_USER_ACTIVE)
+ die('Ecannot_view_sq');
+
+ $list = square::get_pro_list($sqlc, $sqid);
+ if(!$list)
+ die('Eno_problem');
+ $data = get_setting($sqid);
+ $nlist = process_pro_list($list, $data, $sqid);
+ echo(json_encode($nlist));
+}
+if($action == 'get_user_stat')
+{
+ $dt = json_decode($data);
+ $sqid = intval($dt->sqid);
+ $display_team = $dt->display_team;
+ if(square::get_sqmod($sqlc, $sqid) != SQMODNAME)
+ die('Eerror_sqid_this_mod');
+ if(!sec_is_login())
+ die('Enot_login');
+ $uid = intval($_COOKIE['uid']);
+ if(square::get_user_relationship($sqlc, $uid, $sqid) != SQUARE_USER_ACTIVE)
+ die('Ecannot_view_sq');
+
+ $data = get_setting($sqid);
+
+ $ret = new stdClass();
+ $prostat = get_pro_stat_uid($sqlc, $msqlc, $sqid, SCOREBOARD_ID_PROBSTAT, $uid);
+ $tmpstat = process_pro_stat($prostat);
+ $ret->prostat = calc_score($tmpstat, $data, $sqid);
+ $ret->base_line = get_base_line($data, $sqid, false);
+
+ if($display_team)
+ {
+ $term = get_term($data, $sqid);
+ $teamid = intval(get_teamid($msqlc, $term, $uid));
+ if($teamid)
+ {
+ $ret->team_base_line = get_base_line($data, $sqid, true);
+ $members = get_team_member($msqlc, $term, $teamid);
+ $arr = array();
+ foreach($members as $mem)
+ {
+ if($mem->uid == $uid)continue;
+ $tmpstat = process_pro_stat(get_pro_stat_uid($sqlc, $msqlc, $sqid, SCOREBOARD_ID_PROBSTAT, $mem->uid));
+ $mem->prostat = calc_score($tmpstat, $data, $sqid);
+ array_push($arr, $mem);
+ }
+ $ret->team = $arr;
+ $ret->teamid = $teamid;
+ }
+ }
+ echo(json_encode($ret));
+}
+
+db_close($sqlc);
+db_close($msqlc);
+
+?>
diff --git a/toj/sqmod/sqmod_test/team.inc.php b/toj/sqmod/sqmod_test/team.inc.php
new file mode 100644
index 0000000..3effc0e
--- /dev/null
+++ b/toj/sqmod/sqmod_test/team.inc.php
@@ -0,0 +1,37 @@
+<?php
+
+require_once('../../php/common.inc.php');
+
+const TEAM_TYPE_BOY = 1;
+const TEAM_TYPE_GIRL = 2;
+const TEAM_TYPE_COL = 3;
+const TEAM_TYPE_TEA = 4;
+
+function get_teamid($msqlc, $term, $uid)
+{
+ //Return the teamid of $uid. False if not exists.
+ $sqlstr = 'SELECT "teamid" FROM "sqmod_sprout_team" WHERE "term"=$1 AND "uid"=$2;';
+ $sqlarr = array($term, $uid);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ $teamid = pg_fetch_result($res, 0);
+ return $teamid;
+}
+
+function get_team_member($msqlc, $term, $teamid)
+{
+ //Return all team member uid, level of team $teamid. False if not exists.
+ $sqlstr = 'SELECT "sqmod_sprout_team"."uid", "sqmod_sprout_team"."level", "sqmod_sprout_student"."name" FROM "sqmod_sprout_team" INNER JOIN "sqmod_sprout_student" ON "sqmod_sprout_team"."uid"="sqmod_sprout_student"."uid" WHERE "sqmod_sprout_team"."term"=$1 AND "sqmod_sprout_team"."teamid"=$2 ORDER BY "sqmod_sprout_team"."level" DESC, "sqmod_sprout_team"."uid";';
+ $sqlarr = array($term, $teamid);
+ $res = pg_query_params($msqlc, $sqlstr, $sqlarr);
+ $ret = array();
+ while($obj = pg_fetch_object($res))
+ {
+ $obj->uid = intval($obj->uid);
+ $obj->level = intval($obj->level);
+ array_push($ret, $obj);
+ }
+ return $ret;
+}
+
+
+?>
diff --git a/web/common.php b/web/common.php
deleted file mode 100644
index 9fd34f8..0000000
--- a/web/common.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-define('DB_NAME','expoj');
-define('DB_USER','expoj');
-define('DB_PASSWORD','');
-define('SEC_SALT','xxxxx');
-
-function sec_checkuser($userid,$usersec){
- if($userid == '' || $usersec == '' || strval(intval($userid)) != $userid || hash('sha512',$userid.SEC_SALT) != $usersec){
- return false;
- }
-
- return true;
-}
-
-?>
diff --git a/web/data.js b/web/data.js
deleted file mode 100644
index 874ce80..0000000
--- a/web/data.js
+++ /dev/null
@@ -1,39 +0,0 @@
-var data_callback;
-var data_paramo;
-var data_ajaxupdate;
-
-function data_init(){
- data_callback = $.Callbacks();
-
- data_paramo = new Object();
- data_paramo.laststamp = '_';
-
- data_ajaxupdate = null;
-}
-function data_update(force){
- if(data_ajaxupdate != null){
- data_ajaxupdate.abort();
- }
- if(force){
- data_paramo.laststamp = '_';
- }
-
- data_ajaxupdate = $.post('data_update.php',
- {'param':JSON.stringify(data_paramo)},
- function(res){
- var reto;
-
- if(res == 'Esame'){
- data_update();
- }else if(res[0] != 'E'){
- reto = JSON.parse(res);
- data_paramo.laststamp = reto.laststamp;
-
- data_callback.fire(reto);
-
- data_ajaxupdate = null;
- data_update(false);
- }
- }
- );
-}
diff --git a/web/data_update.php b/web/data_update.php
deleted file mode 100644
index b7bf9d2..0000000
--- a/web/data_update.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-require_once('common.php');
-require_once('status_submit_list.php');
-require_once('square_list.php');
-require_once('square_rank_list.php');
-require_once('square_problem_list.php');
-require_once('square_scoreboard_list.php');
-require_once('problem_view.php');
-
-set_time_limit(0);
-
-$paramo = json_decode($_POST['param']);
-if($paramo == null){
- exit('Eerror');
-}
-$laststamp = $paramo->laststamp;
-if($laststamp == null){
- return 'Eerror';
-}
-
-$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
-$retry = 8;
-while(true){
- $sqlr = pg_query($sqlc,'SELECT "timestamp",array_to_string("status",\',\') AS status FROM "submit" ORDER BY "timestamp" DESC LIMIT 1;');
- $sqlo = pg_fetch_object($sqlr);
-
- $nowstamp = $sqlo->timestamp.'_'.$sqlo->status;
- pg_free_result($sqlr);
-
- if($nowstamp != $laststamp){
- break;
- }
-
- if(($retry--) > 0){
- sleep(1);
- }else{
- pg_close($sqlc);
- exit('Esame');
- }
-}
-
-$ret = array(
- 'laststamp' => $nowstamp
-);
-if($paramo->status_submit_list != null){
- $ret['status_submit_list'] = status_submit_list($sqlc,$paramo->status_submit_list,false);
-}
-if($paramo->status_submit_userlist != null){
- $ret['status_submit_userlist'] = status_submit_list($sqlc,$paramo->status_submit_userlist,true);
-}
-
-if($paramo->problem_log_submit_acceptlist != null){
- $ret['problem_log_submit_acceptlist'] = status_submit_list($sqlc,$paramo->problem_log_submit_acceptlist,false);
-}
-if($paramo->problem_log_submit_alllist != null){
- $ret['problem_log_submit_alllist'] = status_submit_list($sqlc,$paramo->problem_log_submit_alllist,false);
-}
-
-if($paramo->square_list != null){
- $ret['square_list'] = square_list($sqlc,$paramo->square_list);
-}
-
-if($paramo->square_rank_list != null){
- $ret['square_rank_list'] = square_rank_list($sqlc,$paramo->square_rank_list);
-}
-if($paramo->square_problem_list != null){
- $ret['square_problem_list'] = square_problem_list($sqlc,$paramo->square_problem_list);
-}
-if($paramo->square_scoreboard_list != null){
- $ret['square_scoreboard_list'] = square_scoreboard_list($sqlc,$paramo->square_scoreboard_list);
-}
-
-if($paramo->problem_view != null){
- $ret['problem_view'] = problem_view($sqlc,$paramo->problem_view);
-}
-
-pg_close($sqlc);
-
-echo json_encode($ret);
-?>
diff --git a/web/index.html b/web/index.html
deleted file mode 100644
index 50f87cb..0000000
--- a/web/index.html
+++ /dev/null
@@ -1,810 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<title>ExpOJ</title>
-<style type="text/css">
-body{
- width:100%;
- height:100%;
- margin:0px 0px;
- background-color:#151515;
- color:#E9E9E9;
- font-family:Tahoma,Geneva;
- overflow:hidden;
-}
-div.index_head{
- width:100%;
- height:32px;
- background-color:#050505;
- z-index:0;
-}
-div.index_head div.title{
- margin:0px 0px 0px 6px;
- font-weight:bold;
- font-size:18px;
- line-height:32px;
- float:left;
-}
-div.index_head div.tab{
- position:absolute;
- top:0px;
- left:31%;
-}
-div.index_head div.content{
- width:auto;
- padding:0px 0px 0px 6px;
- font-weight:bold;
- font-size:18px;
- line-height:32px;
- position:absolute;
- top:0px;
- left:19%;
-}
-div.index_head div.panel{
- width:97px;
- height:100%;
- font-weight:bold;
- font-size:18px;
- line-height:32px;
- text-align:center;
- float:right;
- cursor:pointer;
-}
-div.index_head div.panel_m{
- color:#FFFFFF;
-}
-div.index_head div.msg{
- height:100%;
- padding:0px 6px 0px 6px;
- font-weight:bold;
- font-size:18px;
- line-height:32px;
- text-align:center;
- float:right;
- cursor:pointer;
-
- //background-color:#FF2400;
-}
-div.index_head div.msg_m{
- color:#FFFFFF;
-}
-
-div.index_panel_box{
- width:256px;
- position:absolute;
- top:32px;
- left:auto;
- right:0px;
- z-index:100;
- overflow:hidden;
-}
-div.index_panel{
- width:256px;
- height:100%;
- background-color:#001E4E;
- position:absolute;
- top:0px;
- left:auto;
- right:-256px;
- overflow-x:hidden;
- overflow-y:auto;
-}
-div.index_panel div.button{
- height:48px;
- padding:0px 0px 0px 32px;
- font-weight:normal;
- font-size:20px;
- line-height:48px;
- color:#E9E9E9;
- position:relative;
- top:0px;
- left:50%;
- cursor:pointer;
-}
-div.index_panel div.button_m{
- background-color:rgba(255,255,255,0.1);
-}
-div.index_panel a.button{
- height:100%;
- font-weight:normal;
- font-size:20px;
- line-height:48px;
- color:#E9E9E9;
- text-decoration:none;
- display:block;
-}
-
-div.index_panel div.square_list{
- margin:0px 0px 32px 0px;
-}
-div.index_panel div.square_list div.button{
- height:32px;
- padding:0px 0px 0px 32px;
- position:relative;
- top:0px;
- left:50%;
- cursor:pointer;
-}
-div.index_panel div.square_list a.button{
- height:100%;
- font-weight:normal;
- font-size:16px;
- line-height:32px;
- color:#E9E9E9;
- text-decoration:none;
- display:block;
-}
-
-div.index_page{
- width:100%;
- position:absolute;
- top:32px;
- left:0px;
- z-index:0;
- overflow:auto;
-}
-
-div.index_mask{
- width:100%;
- height:100%;
- position:fixed;
- top:0px;
- left:0px;
- background-color:rgba(0,0,0,0.9);
- z-index:1000;
-}
-</style>
-
-<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
-<script src="http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js"></script>
-<script type="text/javascript" src="http://codemirror.net/lib/codemirror.js"></script>
-<link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css">
-<link rel="stylesheet" href="http://codemirror.net/theme/lesser-dark.css">
-<script type="text/javascript" src="http://codemirror.net/mode/clike/clike.js"></script>
-
-<link rel="stylesheet" href="nor.css">
-<script type="text/javascript" src="nor.js"></script>
-<script type="text/javascript" src="data.js"></script>
-<link rel="stylesheet" href="page.css">
-<script type="text/javascript" src="page.js"></script>
-<link rel="stylesheet" href="page_status.css">
-<script type="text/javascript" src="page_status.js"></script>
-<link rel="stylesheet" href="page_user.css">
-<script type="text/javascript" src="page_user.js"></script>
-<link rel="stylesheet" href="page_square.css">
-<script type="text/javascript" src="page_square.js"></script>
-<link rel="stylesheet" href="page_problem.css">
-<script type="text/javascript" src="page_problem.js"></script>
-
-<script type="text/javascript">
-var initurl;
-
-$(document).ready(function(){
- $('body').on('mouseover',function(e){
- if(e.target == null ||
- e.target.id == 'index_panel' ||
- e.target.id == 'index_head_panel' ||
- $(e.target).parents('#index_panel').length > 0){
- return;
- }
-
- $('#index_head_panel').removeClass('panel_m');
- $('#index_panel').stop().animate({opacity:0},'fast','easeOutQuad',
- function(){
- $('#index_panel').css('right','-256px');
- $('#index_panel div.button').css('left','50%');
- }
- );
- });
-
- $('#index_head_panel').on('mouseover',function(e){
- $(this).addClass('panel_m');
- $('#index_panel').css('opacity','1').stop().animate({right:0},'slow','easeOutExpo');
-
- $('#index_panel div.button').stop().animate({left:0},'slow','easeOutQuart');
- });
-
- $('#index_panel div.button').hover(
- function(e){
- $(this).addClass('button_m');
- },
- function(e){
- $(this).removeClass('button_m');
- }
- );
- $('#index_panel a.button').on('click',function(e){
- page_switch($(this.parentNode).attr('page'));
- return false;
- });
-
- $('#index_panel_squarebutton').off('click').on('click',function(e){
- var j_div;
-
- j_div = $('#index_panel_squarelist');
- if(j_div.is(':visible')){
- j_div.stop().slideUp('slow','easeOutExpo');
- }else{
- j_div.stop().slideDown('slow','easeOutExpo');
- }
- });
-
- $('#index_head_msg').hover(
- function(e){
- $(this).addClass('msg_m');
- },
- function(e){
- $(this).removeClass('msg_m');
- }
- );
-
- nor_init();
- data_init();
- user_init();
- page_init();
- status_init();
- square_init();
- problem_init();
-
- nor_expendheight();
- user_loginchange();
- $(window).resize(function(e){nor_expendheight();});
- $(window).on('popstate',function(e){
- if(location.href == initurl){
- return;
- }
- initurl = null;
-
- page_switch(null);
- });
-
- initurl = location.href;
- page_switch(null);
-});
-</script>
-</head>
-<body>
-<div class="index_head">
- <div id="index_head_title" class="title"></div>
- <div id="index_head_tab" class="tab">
- <div id="index_headtab_status" class="nor_tab" style="display:none;">
- <div tab="allsubmit" class="button">
- <a class="button" href="/expoj/index.html?page=status&tab=allsubmit">All Submit</a>
- </div>
- <div tab="usersubmit" class="button" style="display:none;">
- <a class="button" href="/expoj/index.html?page=status&tab=usersubmit">User Submit</a>
- </div>
- </div>
- <div id="index_headtab_square" class="nor_tab" style="display:none;">
- <div tab="rank" class="button">
- <a class="button">Rank</a>
- </div>
- <div tab="problem" class="button">
- <a class="button">Problem</a>
- </div>
- <div tab="scoreboard" class="button" style="display:none;">
- <a class="button">Scoreboard</a>
- </div>
- </div>
- </div>
- <div id="index_head_content" class="content"></div>
- <div id="index_head_panel" class="panel">Panel</div>
- <div id="index_head_msg" class="msg">[0]</div>
-</div>
-
-<div expendheight=true class="index_panel_box">
-<div id="index_panel" class="index_panel">
- <div page="home" class="button" style="margin:32px 0px 0px 0px;">
- <a class="button" href="/expoj/index.html?page=home">Home</a>
- </div>
- <div page="status" class="button">
- <a class="button" href="/expoj/index.html?page=status">Status</a>
- </div>
- <div page="user" class="button" style="display:none;">
- <a class="button">User</a>
- </div>
- <div id="index_panel_squarebutton" class="button">Square</div>
- <div id="index_panel_squarelist" class="square_list" style="display:none;">
- <div page="squaremg" id="index_panel_squaremg" class="button">
- <a class="button" style="font-weight:bold;">Manage Square</a>
- </div>
- <div class="button ori" style="display:none;">
- <a class="button"></a>
- </div>
- </div>
-
- <div page="login" class="button" style="margin:64px 0px 0px 0px;">
- <a class="button" href="/expoj/index.html?page=login">Login</a>
- </div>
- <div page="register" class="button">
- <a class="button" href="/expoj/index.html?page=register">Register</a>
- </div>
- <div page="logout" class="button" style="margin:64px 0px 0px 0px; display:none;">Logout</div>
-</div>
-</div>
-
-<div expendheight=true class="index_page">
- <div id="page_home" class="page_box"></div>
-
- <div id="page_status" class="page_box">
- <div id="status_allsubmit" class="status_submit" style="display:none;">
- <div class="submitinfo">
- <div class="head">
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.status_submit').data('tabo').submitid);">View Code</div>
- </div>
-
- <table class="info">
- <colgroup>
- <col width="80px">
- <col width="auto">
- <col width="64px">
- <col width="64px">
- </colgroup>
- <tr>
- <td>SubmitID</td>
- <td></td>
- <td>ProID</td>
- <td><a class="link"></a></td>
- </tr>
- <tr>
- <td>Name</td>
- <td><a class="link"></a></td>
- <td>Score</td>
- <td></td>
- </tr>
- </table>
- <table class="list">
- <tr>
- <th>No</th>
- <th>Result</th>
- <th>Score</th>
- <th>Time(ms)</th>
- <th>Mem(KB)</th>
- </tr>
- </table>
- </div>
-
- <div class="submitlist">
- <table class="list">
- <tr class="head">
- <th class="id">ID</th>
- <th class="proid">ProID</th>
- <th class="nickname">Name</th>
- <th class="time">Time</th>
- <th class="result">Result</th>
- <th class="runtime">Runtime</th>
- <th class="score">Score</th>
- </tr>
- <tr class="item ori" style="display:none;">
- <td class="id"></td>
- <td class="proid"><a class="link"></a></td>
- <td class="nickname"><a class="link"></a></td>
- <td class="time"></td>
- <td class="result"></td>
- <td class="runtime"></td>
- <td class="score"></td>
- </tr>
- </table>
- <div class="nor_chpg"></div>
- </div>
- </div>
-
- <div id="status_usersubmit" class="status_submit" style="display:none;">
- <div class="submitinfo">
- <div class="head">
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.status_submit').data('tabo').submitid);">View Code</div>
- </div>
-
- <table class="info">
- <colgroup>
- <col width="80px">
- <col width="auto">
- <col width="64px">
- <col width="64px">
- </colgroup>
- <tr>
- <td>SubmitID</td>
- <td></td>
- <td>ProID</td>
- <td><a class="link"></a></td>
- </tr>
- <tr>
- <td>Name</td>
- <td><a class="link"></a></td>
- <td>Score</td>
- <td></td>
- </tr>
- </table>
- <table class="list">
- <tr>
- <th>No</th>
- <th>Result</th>
- <th>Score</th>
- <th>Time(ms)</th>
- <th>Mem(KB)</th>
- </tr>
- </table>
- </div>
-
- <div class="submitlist">
- <table class="list">
- <tr class="head">
- <th class="id">ID</th>
- <th class="proid">ProID</th>
- <th class="nickname">Name</th>
- <th class="time">Time</th>
- <th class="result">Result</th>
- <th class="runtime">Runtime</th>
- <th class="score">Score</th>
- </tr>
- <tr class="item ori" style="display:none;">
- <td class="id"></td>
- <td class="proid"><a class="link"></a></td>
- <td class="nickname"><a class="link"></a></td>
- <td class="time"></td>
- <td class="result"></td>
- <td class="runtime"></td>
- <td class="score"></td>
- </tr>
- </table>
- <div class="nor_chpg"></div>
- </div>
- </div>
- </div>
-
- <div id="page_user" class="page_box">
- <div id="user_info" class="user_info">
- <div class="head">
- <div class="setting" style="display:none;">
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right;" onclick="user_infoedit(true);">Edit</div>
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="user_infoedit(false);">Cancel</div>
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="user_infosubmit();">Apply</div>
- </div>
- <input type="textbox" readonly=readonly class="name">
- <input type="textbox" readonly=readonly class="aboutme">
- <input type="textbox" class="headimg" style="display:none;">
- <img class="headimg"></img>
- </div>
- <table class="info">
- <tr>
- <td class="info">Accepted</td>
- <td class="info"></td>
- </tr>
- <tr>
- <td class="info">Submited</td>
- <td class="info"></td>
- </tr>
- <tr>
- <td class="info">Tried</td>
- <td class="info"></td>
- </tr>
- </table>
- </div>
- <div id="user_data" class="user_data">
- <div class="prolist"></div>
- </div>
- </div>
-
- <div id="page_squaremg" class="page_box">
- <div id="squaremg_inside" class="squaremg_square" style="margin:0px 0px 0px 19%;">
- <div class="head">Inside square</div>
- <div class="squarelist upcoming">
- <div class="head">Upcoming</div>
- <table class="list">
- <tr class="item ori" style="display:none;">
- <td class="name"></td>
- <td class="time"></td>
- <td class="button"><div class="nor_button" style="display:none;">Remove</div></td>
- </tr>
- </table>
- </div>
- <div class="squarelist active">
- <div class="head">Active</div>
- <table class="list">
- <tr class="item ori" style="display:none;">
- <td class="name"></td>
- <td class="time"></td>
- <td class="button"><div class="nor_button" style="display:none;">Remove</div></td>
- </tr>
- </table>
- </div>
- <div class="squarelist inactive">
- <div class="head">Inactive</div>
- <table class="list">
- <tr class="item ori" style="display:none;">
- <td class="name"></td>
- <td class="time"></td>
- <td class="button"><div class="nor_button" style="display:none;">Remove</div></td>
- </tr>
- </table>
- </div>
- </div>
- <div id="squaremg_outside" class="squaremg_square" style="margin:0px 0px 0px 16px;">
- <div class="head">Outside square</div>
- <div class="squarelist upcoming">
- <div class="head">Upcoming</div>
- <table class="list">
- <tr class="item ori" style="display:none;">
- <td class="name"></td>
- <td class="button"><div class="nor_button" style="display:none;">Add</div></td>
- </tr>
- </table>
- </div>
- <div class="squarelist active">
- <div class="head">Active</div>
- <table class="list">
- <tr class="item ori" style="display:none;">
- <td class="name"></td>
- <td class="button"><div class="nor_button" style="display:none;">Add</div></td>
- </tr>
- </table>
- </div>
- <div class="squarelist inactive">
- <div class="head">Inactive</div>
- <table class="list">
- <tr class="item ori" style="display:none;">
- <td class="name"></td>
- <td class="button"><div class="nor_button" style="display:none;">Add</div></td>
- </tr>
- </table>
- </div>
- </div>
- </div>
-
- <div id="page_square" class="page_box">
- <div class="square_rank" style="display:none;">
- <table class="list">
- <tr class="head">
- <th class="rank">#</th>
- <th class="name">Name</th>
- <th class="rate">AC/SU</th>
- <th class="score">Score</th>
- </tr>
- <tr class="item ori" style="display:none;">
- <td class="rank"></td>
- <td class="name"><a class="link"></a></td>
- <td class="rate"></td>
- <td class="score"></td>
- </tr>
- </table>
- <div class="nor_chpg"></div>
- </div>
-
- <div class="square_problem" style="display:none;">
- <table class="list">
- <tr class="head">
- <th class="blank"></th>
- <th class="id">ID</th>
- <th class="name">Problem Name</th>
- <th class="rate">AC/SU</th>
- </tr>
- <tr class="item ori" style="display:none;">
- <td class="blank"></td>
- <td class="id"></td>
- <td class="name"><a class="link"></a></td>
- <td class="rate"></td>
- </tr>
- </table>
- <div class="nor_chpg"></div>
- </div>
-
- <div class="square_scoreboard" style="display:none;">
- <table class="list">
- <tr class="head"></tr>
- </table>
- </div>
- </div>
-
- <div id="page_problem" class="page_box">
- <div class="problem_info">
- <div class="head">
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right;" onclick="problem_codeswitch(true);">Submit</div>
- </div>
- <table class="info">
- <tr>
- <td class="info">ProID</td>
- <td class="info"></td>
- </tr>
- <tr>
- <td class="info">AC/SU</td>
- <td class="info"><a class="info" onclick="problem_logswitch(true);"></a></td>
- </tr>
- <tr>
- <td class="info">Time(ms)</td>
- <td class="info"></td>
- </tr>
- <tr>
- <td class="info">Mem(KB)</td>
- <td class="info"></td>
- </tr>
- </table>
- </div>
- <div class="problem_view">
- <div class="content"></div>
- </div>
- </div>
-
- <div id="page_login" class="page_box">
- <table class="login">
- <tr><td><div id="login_error" class="error"></div></td></tr>
- <tr><td>
- <div class="head">Username</div>
- <input id="login_username" type="textbox" class="input">
- </td></tr>
- <tr><td>
- <div class="head">Password</div>
- <input id="login_password" type="password" class="input">
- </td></tr>
- <tr><td>
- <div class="nor_button" style="width:auto; float:right;" onclick="user_login_reset();">Cancel</div>
- <div class="nor_button" style="width:auto; margin:0px 6px 0px 0px; float:right;" onclick="user_login_submit();">Login</div>
- </td></tr>
- </table>
- </div>
- <div id="page_register" class="page_box">
- <table class="register">
- <tr><td><div id="register_error" class="error"></div></td></tr>
- <tr><td>
- <div class="head">Username</div>
- <input id="register_username" type="textbox" class="input">
- </td></tr>
- <tr><td>
- <div class="head">Password</div>
- <input id="register_password" type="password" class="input">
- </td></tr>
- <tr><td>
- <div class="head">Nickname</div>
- <input id="register_nickname" type="textbox" class="input">
- </td></tr>
- <tr><td>
- <div class="nor_button" style="width:auto; float:right;" onclick="user_register_reset();">Cancel</div>
- <div class="nor_button" style="width:auto; margin:0px 6px 0px 0px; float:right;" onclick="user_register_submit();">Register</div>
- </td></tr>
- </table>
- </div>
-
- <div id="index_mask" class="index_mask" style="display:none;">
- <div id="mask_problem_log" class="mask_problem_log" style="display:none;">
- <div class="nor_mask_head">
- <div class="title"></div>
- <div class="nor_tab" style="position:absolute; top:0px; left:31%;">
- <div tab="allsubmit" class="button">All Submit</div>
- <div tab="acceptsubmit" class="button button_s">AC Submit</div>
- </div>
- <div class="button" style="float:right;" onclick="problem_logswitch(false);">Close</div>
- </div>
- <div expendheight=true class="nor_mask_box">
- <div id="problem_log_acceptsubmit" class="problem_log_submit">
- <div class="submitinfo">
- <div class="head">
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.problem_log_submit').data('tabo').submitid);">View Code</div>
- </div>
-
- <table class="info">
- <colgroup>
- <col width="80px">
- <col width="auto">
- <col width="64px">
- <col width="64px">
- </colgroup>
- <tr>
- <td>SubmitID</td>
- <td></td>
- <td>ProID</td>
- <td></td>
- </tr>
- <tr>
- <td>Name</td>
- <td><a class="link"></a></td>
- <td>Score</td>
- <td></td>
- </tr>
- </table>
- <table class="list">
- <tr>
- <th>No</th>
- <th>Result</th>
- <th>Score</th>
- <th>Time(ms)</th>
- <th>Mem(KB)</th>
- </tr>
- </table>
- </div>
-
- <div class="submitlist">
- <table class="list">
- <tr class="head">
- <th class="id">ID</th>
- <th class="nickname">Name</th>
- <th class="time">Time</th>
- <th class="runtime">Runtime</th>
- <th class="score">Score</th>
- </tr>
- <tr class="item ori" style="display:none;">
- <td class="id"></td>
- <td class="nickname"><a class="link"></a></td>
- <td class="time"></td>
- <td class="runtime"></td>
- <td class="score"></td>
- </tr>
- </table>
- <div class="nor_chpg"></div>
- </div>
- </div>
-
- <div id="problem_log_allsubmit" class="problem_log_submit" style="display:none;">
- <div class="submitinfo">
- <div class="head">
- <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.problem_log_submit').data('tabo').submitid);">View Code</div>
- </div>
-
- <table class="info">
- <colgroup>
- <col width="80px">
- <col width="auto">
- <col width="64px">
- <col width="64px">
- </colgroup>
- <tr>
- <td>SubmitID</td>
- <td></td>
- <td>ProID</td>
- <td><a class="link"></a></td>
- </tr>
- <tr>
- <td>Name</td>
- <td><a class="link"></a></td>
- <td>Score</td>
- <td></td>
- </tr>
- </table>
- <table class="list">
- <tr>
- <th>No</th>
- <th>Result</th>
- <th>Score</th>
- <th>Time(ms)</th>
- <th>Mem(KB)</th>
- </tr>
- </table>
- </div>
-
- <div class="submitlist">
- <table class="list">
- <tr class="head">
- <th class="id">ID</th>
- <th class="nickname">Name</th>
- <th class="time">Time</th>
- <th class="runtime">Runtime</th>
- <th class="score">Score</th>
- </tr>
- <tr class="item ori" style="display:none;">
- <td class="id"></td>
- <td class="nickname"><a class="link"></a></td>
- <td class="time"></td>
- <td class="runtime"></td>
- <td class="score"></td>
- </tr>
- </table>
- <div class="nor_chpg"></div>
- </div>
- </div>
- </div>
- </div>
-
- <div id="mask_problem_code" class="mask_problem_code" style="display:none;">
- <div class="nor_mask_head">
- <div class="title"></div>
- <div class="content error"></div>
- <div class="button" style="float:right;" onclick="problem_codeswitch(false);">Close</div>
- <div class="button" style="margin:0px 6px 0px 0px; float:right;" onclick="problem_code_submit();">Submit</div>
- </div>
- <div expendheight=true class="nor_mask_box">
- <div class="code"></div>
- </div>
- </div>
- </div>
-</div>
-</body>
-</html>
-
diff --git a/web/nor.css b/web/nor.css
deleted file mode 100644
index e0d2039..0000000
--- a/web/nor.css
+++ /dev/null
@@ -1,112 +0,0 @@
-div.nor_button{
- height:32px;
- padding:0px 6px;
- background-color:#393939;
- font-size:16px;
- font-weight:bold;
- text-align:center;
- line-height:32px;
- color:#E9E9E9;
- cursor:pointer;
-}
-div.nor_button_m{
- background-color:#36454F;
-}
-
-div.nor_tab{
- width:auto;
- height:32px;
-}
-div.nor_tab div.button{
- width:auto;
- height:100%;
- padding:0px 8px 0px 8px;
- font-weight:normal;
- font-size:18px;
- line-height:32px;
- color:#E9E9E9;
- float:left;
- cursor:pointer;
-}
-div.nor_tab div.button_m{
- color:#FFFFFF;
-}
-div.nor_tab div.button_s{
- background-color:#2E8B57;
-}
-div.nor_tab a.button{
- width:100%;
- height:100%;
- font-weight:normal;
- font-size:18px;
- line-height:32px;
- color:#E9E9E9;
- text-decoration:none;
- display:block;
-}
-div.nor_tab a:hover.button{
- color:#FFFFFF;
-}
-
-div.nor_mask_head{
- width:100%;
- height:32px;
- background-color:#050505;
- position:relative;
-}
-div.nor_mask_head div.title{
- margin:0px 0px 0px 6px;
- font-weight:bold;
- font-size:18px;
- line-height:32px;
- float:left;
-}
-div.nor_mask_head div.content{
- width:auto;
- padding:0px 0px 0px 6px;
- font-weight:bold;
- font-size:18px;
- line-height:32px;
- float:left;
-}
-div.nor_mask_head div.button{
- height:100%;
- padding:0px 6px 0px 6px;
- font-weight:bold;
- font-size:18px;
- line-height:32px;
- text-align:center;
- float:right;
- cursor:pointer;
-}
-div.nor_mask_head div.button_m{
- color:#FFFFFF;
-}
-div.nor_mask_box{
- width:100%;
- position:absolute;
- left:0px;
- top:32px;
- overflow:hidden;
-}
-
-div.nor_chpg{
- margin:0px auto auto;
- padding:16px 0px 16px 0px;
- font-size:20px;
- text-align:center;
-}
-a.nor_chpg{
- height:100%;
- padding:0px 3px 0px 3px;
- color:#E9E9E9;
- text-decoration:none;
- cursor:pointer;
- display:inline-block;
-}
-a.nor_chpg_s{
- background-color:#36454F;
-}
-a:hover.nor_chpg{
- background-color:#36454F;
-}
diff --git a/web/nor.js b/web/nor.js
deleted file mode 100644
index 8021bf5..0000000
--- a/web/nor.js
+++ /dev/null
@@ -1,111 +0,0 @@
-var nor_userid;
-var nor_usersec;
-
-function nor_init(){
- $('div.nor_button').hover(
- function(e){
- $(this).addClass('nor_button_m');
- },
- function(e){
- $(this).removeClass('nor_button_m');
- }
- );
- $('div.nor_tab > div.button').hover(
- function(e){
- $(this).addClass('button_m');
- },
- function(e){
- $(this).removeClass('button_m');
- }
- );
- $('div.nor_mask_head > div.button').hover(
- function(e){
- $(this).addClass('button_m');
- },
- function(e){
- $(this).removeClass('button_m');
- }
- );
-}
-function nor_scoretolight(sumscore,summaxscore){
- var i;
- var part;
- var light;
-
- if(sumscore == null){
- return 0;
- }
-
- if(summaxscore == 0){
- light = 1;
- }else{
- ratio = Math.floor(sumscore / summaxscore * 100);
- if(ratio == 100){
- light = 4;
- }else if(ratio >= 80){
- light = 3;
- }else if(ratio >= 60){
- light = 2;
- }else{
- light = 1;
- }
- }
-
- return light;
-}
-function nor_expendheight(){
- var i;
- var es;
- var j_e;
-
- es = $('[expendheight=true]');
- for(i = 0;i < es.length;i++){
- j_e = $(es[i]);
- j_e.css('height',(window.innerHeight - parseInt(j_e.css('top').match(/(.+)px/)[1])) + 'px');
- }
-}
-function nor_new_chpgbutton(text,click){
- var j_a;
-
- j_a = $('<a></a>')
- j_a.addClass('nor_chpg');
- j_a.on('click',click);
- j_a.text(text)
-
- return j_a;
-}
-
-function nor_getparam(){
- var ret;
- var i;
-
- var part;
- var subpart;
-
- ret = new Object();
- part = location.href.match(/([^?&]+)/g);
- for(i = 1;i < part.length;i++){
- part[i] = part[i].replace(/\+/g,' ');
- subpart = part[i].split('=');
- ret[decodeURIComponent(subpart[0]).replace(/^\s+|\s$/,' ')] = decodeURIComponent(subpart[1]);
- }
-
- return ret;
-}
-function nor_getcookie(){
- var ret;
- var i;
-
- var part;
- var subpart;
-
- ret = new Object();
- part = document.cookie.split(';');
- for(i = 0;i < part.length;i++){
- part[i] = part[i].replace(/\+/g,' ');
- subpart = part[i].split('=');
- ret[decodeURIComponent(subpart[0])] = decodeURIComponent(subpart[1]);
- }
-
- return ret;
-}
diff --git a/web/page.css b/web/page.css
deleted file mode 100644
index 1424623..0000000
--- a/web/page.css
+++ /dev/null
@@ -1,6 +0,0 @@
-div.page_box{
- width:auto;
- height:100%;
- overflow:auto;
- display:none;
-}
diff --git a/web/page.js b/web/page.js
deleted file mode 100644
index 43e0a2a..0000000
--- a/web/page.js
+++ /dev/null
@@ -1,91 +0,0 @@
-var page_name_select;
-var page_name_previous;
-
-function page_init(){
- page_name_select = 'home';
- page_name_previous = 'home';
-}
-function page_switch(page_name){
- var j_bar_button;
- var show = function(){
- page_name_previous = page_name_select;
- page_name_select = page_name;
-
- document.title = page_name + '-ExpOJ';
-
- if(page_name_previous == 'status'){
- status_pageswitch(false);
- }else if(page_name_previous.match(/^square_.+/) != null){
- square_pageswitch(page_name_previous,false);
- }else if(page_name_previous.match(/^problem_.+/) != null){
- problem_pageswitch(page_name_previous,false);
- }else if(page_name.match(/^user_.+/) != null){
- user_pageswitch(page_name,false);
- }
-
- if(page_name == 'home'){
- $('#index_head_title').text('Experiment OnlineJudge');
- $('#page_home').fadeIn('fast');
- }else if(page_name == 'status'){
- status_pageswitch(true);
- }else if(page_name == 'squaremg'){
- squaremg_pageswitch(true);
- }else if(page_name.match(/^square_.+/) != null){
- square_pageswitch(page_name,true);
- }else if(page_name.match(/^problem_.+/) != null){
- problem_pageswitch(page_name,true);
- }else if(page_name.match(/^user_.+/) != null){
- user_pageswitch(page_name,true);
- }else if(page_name == 'login'){
- user_login_pageswitch();
- }else if(page_name == 'register'){
- user_register_pageswitch();
- }else{
- page_name = 'home';
- page_name_select = page_name_previous;
- window.history.replaceState(page_name,document.title,'/expoj/index.html?page=home');
-
- show();
- }
- }
-
- if(page_name == null){
- page_name = nor_getparam().page;
- if(page_name == undefined){
- page_name = 'home';
- window.history.replaceState(page_name,document.title,'/expoj/index.html?page=home');
- }
- }else{
- if(page_name == page_name_select){
- return -1;
- }
- window.history.pushState(page_name,document.title,'/expoj/index.html?page=' + page_name);
- }
-
- $('#index_head_tab').find('div.nor_tab').hide();
- $('#index_head_content').empty();
-
- if(page_name_select != null){
- $('#page_' + page_name_select).fadeOut('fast',show);
- }else{
- show();
- }
-
- return 0;
-}
-function page_maskswitch(j_div,on){
- var i;
-
- var j_mask;
-
- j_mask = $('#index_mask');
- j_mask.children('div').hide();
-
- if(on == true){
- j_div.show();
- j_mask.fadeIn('fast');
- }else{
- j_div.hide();
- j_mask.fadeOut('fast');
- }
-}
diff --git a/web/page_problem.css b/web/page_problem.css
deleted file mode 100644
index afe1a7f..0000000
--- a/web/page_problem.css
+++ /dev/null
@@ -1,164 +0,0 @@
-div.problem_info{
- width:19%;
- height:100%;
- background-color:#222222;
- font-size:18px;
- overflow:auto;
- float:left;
-}
-div.problem_info > div.head{
- width:100%;
- height:32px;
- margin:6px 0px 0px 0px;
-}
-div.problem_info > table.info{
- margin:16px auto;
-}
-div.problem_info td.info{
- padding:2px 3px 2px 3px;
-}
-div.problem_info a.info{
- cursor:pointer;
- text-decoration:underline;
-}
-div.problem_info a:hover.info{
- color:#FFFFFF;
-}
-div.problem_view{
- width:81%;
- height:100%;
- overflow:auto;
- float:left;
-}
-div.problem_view > div.content{
- padding:6px 6px 32px 6px;
- font-size:18px;
- font-family:Courier New,monospace;
-}
-
-div.mask_problem_log{
- width:86%;
- height:100%;
- margin:0px auto;
- background-color:#151515;
-}
-div.problem_log_submit{
- width:86%;
- height:100%;
- margin:0px auto;
- overflow:hidden;
-}
-div.problem_log_submit > div.submitlist{
- width:69%;
- height:100%;
- margin:0px auto;
- float:left;
- overflow:auto;
-}
-div.problem_log_submit > div.submitlist > table.list{
- width:95%;
- margin:6px auto 0px auto;
- font-size:20px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.problem_log_submit > div.submitlist tr.head{
- height:32px;
-}
-div.problem_log_submit > div.submitlist tr.item{
- height:32px;
- cursor:pointer;
-}
-div.problem_log_submit > div.submitlist tr:hover.item{
- background-color:#36454F;
-}
-div.problem_log_submit > div.submitlist th.id,div.problem_log_submit > div.submitlist td.id{
- width:64px;
-}
-div.problem_log_submit > div.submitlist th.nickname,div.problem_log_submit > div.submitlist td.nickname{
- width:auto;
-}
-div.problem_log_submit > div.submitlist th.time{
- width:224px;
-}
-div.problem_log_submit > div.submitlist td.time{
- width:192px;
- font-weight:normal;
- font-size:16px;
-}
-div.problem_log_submit > div.submitlist th.runtime{
- width:104px;
-}
-div.problem_log_submit > div.submitlist td.runtime{
- width:104px;
- font-weight:normal;
- font-size:16px;
-}
-div.problem_log_submit > div.submitlist th.score,div.problem_log_submit > div.submitlist td.score{
- width:64px;
-}
-div.problem_log_submit > div.submitlist a.link{
- height:100%;
- color:#E9E9E9;
- text-decoration:none;
- cursor:pointer;
-}
-div.problem_log_submit > div.submitlist a:hover.link{
- text-decoration:underline;
-}
-
-div.problem_log_submit > div.submitinfo{
- width:31%;
- height:100%;
- background-color:#222222;
- overflow:auto;
- float:left;
-}
-div.problem_log_submit > div.submitinfo > div.head{
- width:100%;
- height:32px;
- margin:6px 0px 0px 0px;
-}
-div.problem_log_submit > div.submitinfo > table.info{
- width:95%;
- margin:26px 0px 0px auto;
- font-size:16px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.problem_log_submit > div.submitinfo > table.list{
- width:95%;
- margin:32px 0px 0px auto;
- font-size:16px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.problem_log_submit > div.submitinfo a.link{
- width:100%;
- height:100%;
- color:#E9E9E9;
- text-decoration:none;
- display:block;
- cursor:pointer;
-}
-div.problem_log_submit div.submitinfo a:hover.link{
- text-decoration:underline;
-}
-
-div.mask_problem_code{
- width:62%;
- height:100%;
- margin:0px auto;
- background-color:#151515;
-}
-div.mask_problem_code > div.nor_mask_head > div.error{
- color:#FFA0A0;
-}
-div.mask_problem_code div.code{
- width:62%;
- height:100%;
- margin:0px auto;
-}
diff --git a/web/page_problem.js b/web/page_problem.js
deleted file mode 100644
index e805ec8..0000000
--- a/web/page_problem.js
+++ /dev/null
@@ -1,525 +0,0 @@
-var problem_page;
-var problem_pageo;
-var problem_log_tab;
-var problem_submitcode;
-
-function problem_init(){
- var j_tab;
- var j_div;
-
- problem_page = $('#page_problem');
- problem_pageo = {
- 'proid':null
- };
- problem_log_tab = 'acceptsubmit';
-
- problem_submitcode = CodeMirror($('#mask_problem_code > div.nor_mask_box > div.code')[0],{
- mode:'text/x-c++src',
- theme:'lesser-dark',
- lineNumbers:true,
- matchBrackets:true,
- indentUnit:4
- });
- problem_submitcode.getWrapperElement().style.width = '100%';
- problem_submitcode.getWrapperElement().style.height = '100%';
- problem_submitcode.getScrollerElement().style.width = '100%';
- problem_submitcode.getScrollerElement().style.height = '100%';
-
- j_tab = $('#problem_log_acceptsubmit')
- j_tab.data('tabo',{
- 'result':0,
- 'submitid':2147483647,
- 'submitoff':0,
- 'submitcount':0,
- 'callback':$.Callbacks()
- });
- data_callback.add(function(j_tab){return function(res){
- problem_log_submit_callback(j_tab,res);
- }}(j_tab));
-
- j_tab = $('#problem_log_allsubmit')
- j_tab.data('tabo',{
- 'result':-100,
- 'submitid':2147483647,
- 'submitoff':0,
- 'submitcount':0,
- 'callback':$.Callbacks()
- });
- data_callback.add(function(j_tab){return function(res){
- problem_log_submit_callback(j_tab,res);
- }}(j_tab));
-
- $('#mask_problem_log > div.nor_mask_head > div.nor_tab > div.button').on('click',function(e){
- problem_log_tabswitch($(this).attr('tab'));
- });
-
-
- data_callback.add(function(res){
- var proid;
- var proo;
- var tds;
- var j_name;
- var j_content;
-
- if((proo = res.problem_view) === undefined){
- return;
- }
-
- if((proid = problem_pageo.proid) == null){
- return;
- }
-
- tds = problem_page.find('div.problem_info > table.info td.info');
- j_name = $('#index_head_content');
- j_content = $(problem_page.find('div.problem_view > div.content')[0]);
-
- if(data_paramo.problem_view.infoonly == true){
- $($(tds[3]).find('a.info')[0]).text(proo.acceptcount + '/' + proo.submitcount);
- }else{
- if(proo == null){
- $(tds[1]).text(proid);
- j_name.html('<span style="color:#FFA0A0">Page not found</span>');
-
- delete data_paramo.problem_view;
- }else{
- $(tds[1]).text(proid);
- $($(tds[3]).find('a.info')[0]).text(proo.acceptcount + '/' + proo.submitcount);
- $(tds[5]).text(proo.timelimit);
- $(tds[7]).text(proo.memlimit);
- j_name.text(proo.proname);
- j_content.html(problem_textconvert(proo.protext));
- data_paramo.problem_view.infoonly = true;
- }
- $('#mask_problem_code > div.nor_mask_head > div.title').text('ProID:' + proid);
-
- problem_page.fadeIn('slow');
- window.history.replaceState('problem',document.title,'/expoj/index.html?page=problem_' + proid);
- }
- });
-}
-function problem_pageswitch(pagename,on){
- var proid;
-
- if(on){
- proid = pagename.match(/^problem_(.+)/)[1];
-
- $('#index_head_title').text('ExpOJ-ProID:' + proid);
-
- problem_page.attr('id','page_problem_' + proid);
- problem_pageo.proid = proid;
-
- data_paramo.problem_view = {
- 'infoonly':false,
- 'proid':parseInt(proid)
- };
- data_update(true);
- }else{
- delete data_paramo.problem_view;
- delete data_paramo.problem_log_submit_acceptlist;
- delete data_paramo.problem_log_submit_alllist;
-
- problem_pageo.proid = null;
- }
-}
-function problem_logswitch(on){
- var j_tab;
- var tabo;
-
- if(on){
- problem_log_tab = 'acceptsubmit';
- $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="acceptsubmit"]').addClass('button_s');
- $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="allsubmit"]').removeClass('button_s');
-
- $('#mask_problem_log > div.nor_mask_head > div.title').text('ProID:' + problem_pageo.proid);
-
- j_tab = $('#problem_log_allsubmit');
- j_tab.hide();
- problem_log_submit_update(j_tab);
-
- j_tab = $('#problem_log_acceptsubmit');
- j_tab.hide();
- tabo = j_tab.data('tabo');
-
- tabo.callback.add(function(){
- j_tab.show();
- tabo.callback.remove(arguments.callee);
- });
-
- problem_log_submit_update(j_tab);
-
- page_maskswitch($('#mask_problem_log'),true);
- }else{
- delete data_paramo.problem_log_submit_acceptlist;
- delete data_paramo.problem_log_submit_alllist;
-
- page_maskswitch($('#mask_problem_log'),false);
- }
-}
-function problem_textconvert(text){
- var ret;
- var i;
-
- ret = '';
- for(i = 0;i < text.length;i++){
- if(text[i] != '\r' && text[i] != '\n'){
- ret += text[i];
- }else if(text[i] == '\n'){
- ret += '<br/>';
- }
- }
-
- return ret;
-}
-
-function problem_log_tabswitch(tabname){
- var j_tab;
- var tabo;
- var show = function(){
- problem_log_tab = tabname;
-
- j_tab = $('#problem_log_' + problem_log_tab);
- switch(problem_log_tab){
- case 'acceptsubmit':
- tabo = j_tab.data('tabo');
- tabo.callback.add(function(){
- j_tab.fadeIn('fast');
- tabo.callback.remove(arguments.callee);
- });
-
- problem_log_submit_update(j_tab);
- break;
- case 'allsubmit':
- tabo = j_tab.data('tabo');
- tabo.callback.add(function(){
- j_tab.fadeIn('fast');
- tabo.callback.remove(arguments.callee);
- });
-
- problem_log_submit_update(j_tab);
- break;
- }
- }
-
- if(problem_log_tab == tabname){
- return -1;
- }
-
- $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="' + problem_log_tab + '"]').removeClass('button_s');
- $('#problem_log_' + problem_log_tab).fadeOut('fast',show);
-
- $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="' + tabname + '"]').addClass('button_s');
-}
-
-function problem_log_submit_listadd(e_table,idx,submitid,userid,nickname,time,runtime,score,light){
- var j_tr;
- var j_td;
- var j_a;
-
- if((e_table.rows.length - 2) <= idx){
- j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
- j_tr.removeClass('ori');
- $(e_table).append(j_tr);
- }else{
- j_tr = $(e_table.rows[idx + 2]);
- }
-
- $(j_tr.find('td.id')[0]).text(submitid);
- $(j_tr.find('td.time')[0]).text(time.match(/(.*)\./)[1]);
- $(j_tr.find('td.runtime')[0]).text(Math.round(parseInt(runtime) / 1000));
- j_td = $(j_tr.find('td.score')[0]);
- j_td.text(score);
- switch(light){
- case 1:
- j_td.css('color','#FF0000');
- break;
- case 2:
- j_td.css('color','#00FF00');
- break;
- case 3:
- j_td.css('color','#FFFF00');
- break;
- case 4:
- j_td.css('color','#FFFFFF');
- break;
- }
-
- j_a = $(j_tr.find('td.nickname > a.link')[0]);
- j_a.attr('href','/expoj/index.html?page=user_' + userid);
- j_a.text(nickname);
- j_a.off('click').on('click',function(e){
- problem_logswitch(false);
- page_switch('user_' + userid);
- return false;
- });
-
- j_tr.off('click').on('click',function(e){
- var j_tab;
- var tabo;
-
- if(e.target.tagName == 'A'){
- return;
- }
-
- j_tab = $(this).data('j_tab');
- tabo = j_tab.data('tabo');
- tabo.submitid = $(this).data('submitid');
- problem_log_submit_update(j_tab);
- });
-
- j_tr.show();
- return j_tr;
-}
-function problem_log_submit_listchpg(j_tab,submitoff){
- var tabo;
-
- tabo = j_tab.data('tabo');
- if(submitoff >= 0 && submitoff < tabo.submitcount){
- tabo.submitoff = submitoff;
- tabo.laststamp = '_';
- tabo.callback.add(function(){
- tabo.callback.remove(arguments.callee);
- });
- problem_log_submit_update(j_tab);
- }
-}
-function problem_log_submit_update(j_tab){
- var tabo;
- var paramo;
-
- tabo = j_tab.data('tabo');
- paramo = {
- 'proid':parseInt(problem_pageo.proid),
- 'result':parseInt(tabo.result),
- 'submitoff':parseInt(tabo.submitoff),
- 'submitid':parseInt(tabo.submitid)
- };
- if(tabo.result == 0){
- data_paramo.problem_log_submit_acceptlist = paramo;
- }else if(tabo.result == -100){
- data_paramo.problem_log_submit_alllist = paramo;
- }
-
- data_update(true);
-}
-function problem_log_submit_callback(j_tab,res){
- var reto;
- var tabo;
- var submitlist;
-
- tabo = j_tab.data('tabo');
- if(tabo.result == 0){
- reto = res.problem_log_submit_acceptlist;
- }else if(tabo.result == -100){
- reto = res.problem_log_submit_alllist;
- }
- if(reto != null){
- tabo.submitcount = reto.submitcount;
- submitlist = reto.submitlist;
-
- if(tabo.result == 0){
- $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="acceptsubmit"]').text('AC Submit [' + tabo.submitcount+ ']');
- }else if(tabo.result == -100){
- $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="allsubmit"]').text('All Submit [' + tabo.submitcount+ ']');
- }
-
- if(tabo.submitoff != null){
- var i;
- var j;
-
- var e_table;
- var j_tr;
- var j_div;
- var j_a;
- var submito;
- var offs;
- var offe;
-
- e_table = j_tab.find('div.submitlist > table.list')[0];
- for(i = e_table.rows.length - 1;i > 1;i--){
- $(e_table.rows[i]).hide();
- }
-
- for(i = 0;i < submitlist.length - 1;i++){
- submito = submitlist[i];
- j_tr = problem_log_submit_listadd(
- e_table,
- i,
- submito.submitid,
- submito.userid,
- submito.nickname,
- submito.timestamp,
- submito.sumruntime,
- submito.sumscore,
- nor_scoretolight(submito.sumscore,submito.summaxscore));
- j_tr.data('j_tab',j_tab);
- j_tr.data('submitid',submito.submitid);
- }
-
- j_div = $(j_tab.find('div.nor_chpg')[0]);
- j_div.empty();
-
- j_a = nor_new_chpgbutton('«',function(){
- problem_log_submit_listchpg(j_tab,0);
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('‹',function(){
- problem_log_submit_listchpg(j_tab,(tabo.submitoff - 20));
- });
- j_div.append(j_a);
-
- offs = Math.max(0,tabo.submitoff - 100);
- if((offe = Math.min(tabo.submitcount,offs + 200)) == tabo.submitcount){
- offs = Math.max(0,(offe - offe % 20) - 180);
- }
- for(i = offs;i < offe;i += 20){
- j_a = nor_new_chpgbutton((i / 20 + 1),function(){
- problem_log_submit_listchpg(j_tab,$(this).data('submitoff'));
- });
- j_a.data('submitoff',i);
-
- if(i == tabo.submitoff){
- j_a.addClass('nor_chpg_s');
- }
-
- j_div.append(j_a);
- }
-
- j_a = nor_new_chpgbutton('›',function(){
- problem_log_submit_listchpg(j_tab,(tabo.submitoff + 20));
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('»',function(){
- problem_log_submit_listchpg(j_tab,(tabo.submitcount - tabo.submitcount % 20));
- });
- j_div.append(j_a);
- }
- if(tabo.submitid != null){
- var i;
-
- var e_table;
- var j_tr;
- var j_td;
- var tds;
- var j_a;
- var submito;
- var partstatus;
- var partscore;
- var partruntime;
- var partpeakmem;
-
- if(submitlist.length == 0){
- e_table = j_tab.find('div.submitinfo > table.list')[0];
- for(i = e_table.rows.length - 1;i > 0;i--){
- e_table.deleteRow(i);
- }
-
- e_table = j_tab.find('div.submitinfo > table.info')[0];
- tds = $(e_table).find('td');
- $(tds[1]).text('');
- $(tds[3]).text('');
- $(tds[7]).text('');
- j_a = $($(e_table).find('a')[0]);
- j_a.attr('href',null);
- j_a.text('');
- j_a.off('click');
- }else{
- submito = submitlist[submitlist.length - 1];
- tabo.submitid = submito.submitid;
-
- partstatus = submito.status.split(',');
- partscore = submito.score.split(',');
- partruntime = submito.runtime.split(',');
- partpeakmem = submito.peakmem.split(',');
-
- e_table = j_tab.find('div.submitinfo > table.list')[0];
- for(i = e_table.rows.length - 1;i > 0;i--){
- e_table.deleteRow(i);
- }
-
- for(i = 0;i < partstatus.length;i++){
- j_tr = $('<tr></tr>');
-
- j_td = $('<td></td>');
- j_td.text(i + 1);
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(status_judgestat[parseInt(partstatus[i])]);
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(partscore[i]);
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(Math.round(parseInt(partruntime[i]) / 1000));
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(Math.round(parseInt(partpeakmem[i]) / 1024));
- j_tr.append(j_td);
-
- $(e_table).append(j_tr);
- }
-
- e_table = j_tab.find('div.submitinfo > table.info')[0];
- tds = $(e_table).find('td');
- $(tds[1]).text(submito.submitid);
- $(tds[3]).text(submito.proid);
- $(tds[7]).text(submito.sumscore);
-
- j_a = $($(e_table).find('a')[0]);
- j_a.attr('href','/expoj/index.html?page=user_' + submito.userid);
- j_a.text(submito.nickname);
- j_a.off('click').on('click',function(userid){return function(e){
- problem_logswitch(false);
- page_switch('user_' + userid);
- return false;
- }}(submito.userid));
-
- if(user_usero != null && submito.userid == user_usero.userid){
- $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).show();
- }else{
- $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).hide();
- }
- }
- }
-
- tabo.callback.fire();
- }
-}
-
-function problem_codeswitch(on){
- if(user_usero == null){
- page_switch('login');
- return;
- }
-
- if(on){
- $($('#mask_problem_code > div.nor_mask_head > div.error')[0]).empty();
-
- page_maskswitch($('#mask_problem_code'),true);
- problem_submitcode.setValue('');
- }else{
- problem_submitcode.setValue('');
- page_maskswitch($('#mask_problem_code'),false);
- }
-}
-function problem_code_submit(){
- $.post('problem_code_submit.php',
- {'proid':problem_pageo.proid,'code':problem_submitcode.getValue()},
- function(res){
- var j_div;
-
- j_div = $($('#mask_problem_code > div.nor_mask_head > div.error')[0]);
- if(res[0] != 'E'){
- problem_submitcode.setValue('');
- page_maskswitch($('#mask_problem_code'),false);
- }else if(res == 'Euser'){
- page_switch('login');
- }else if(res == 'Ecode'){
- j_div.text('Ccde長度超過64KB');
- }else if(res == 'Elimit'){
- j_div.text('Submit間隔必須大於10s');
- }
- }
- );
-}
diff --git a/web/page_square.css b/web/page_square.css
deleted file mode 100644
index 6699a35..0000000
--- a/web/page_square.css
+++ /dev/null
@@ -1,167 +0,0 @@
-div.square_rank{
- width:100%;
-}
-div.square_rank > table.list{
- width:62%;
- margin:6px auto 0px auto;
- font-size:20px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.square_rank tr.head{
- height:32px;
-}
-div.square_rank tr.item{
- height:32px;
-}
-div.square_rank th.rank,div.square_rank td.rank{
- width:64px;
-}
-div.square_rank th.name,div.square_rank td.name{
- width:auto;
-}
-div.square_rank th.rate,div.square_rank td.rate{
- width:128px;
-}
-div.square_rank th.score,div.square_rank td.score{
- width:64px;
-}
-div.square_rank a.link{
- width:100%;
- height:100%;
- text-decoration:none;
- color:#E9E9E9;
- display:block;
-}
-div.square_rank a.link:hover{
- text-decoration:underline;
-}
-
-div.square_problem{
- width:100%;
-}
-div.square_problem > table.list{
- width:62%;
- margin:6px auto 0px auto;
- font-size:20px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.square_problem tr.head{
- height:32px;
-}
-div.square_problem tr.item{
- height:32px;
- border-left:#333333 5px solid;
- cursor:pointer;
-}
-div.square_problem tr:hover.item{
- background-color:#36454F;
-}
-div.square_problem th.blank,div.square_problem td.blank{
- width:8px;
-}
-div.square_problem th.id,div.square_problem td.id{
- width:64px;
-}
-div.square_problem th.name,div.square_problem td.name{
- width:auto;
-}
-div.square_problem th.rate,div.square_problem td.rate{
- width:128px;
-}
-div.square_problem a.link{
- width:100%;
- height:100%;
- text-decoration:none;
- color:#E9E9E9;
- display:block;
-}
-div.square_problem a:hover.link{
- text-decoration:underline;
-}
-
-div.square_scoreboard{
- padding:6px 6px;
- overflow:auto;
-}
-div.square_scoreboard > table.list{
- width:100%;
- font-size:20px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.square_scoreboard tr.head{
- height:32px;
-}
-div.square_scoreboard tr.item{
- height:32px;
-}
-div.square_scoreboard th.rank,div.square_scoreboard td.rank{
- width:64px;
- border:#333333 1px solid;
-}
-div.square_scoreboard th.name,div.square_scoreboard td.name{
- width:192px;
- border:#333333 1px solid;
-}
-div.square_scoreboard th.problem,div.square_scoreboard td.problem{
- width:104px;
- font-size:16px;
- text-align:center;
- border:#333333 1px solid;
-}
-div.square_scoreboard a.link{
- width:100%;
- height:100%;
- text-decoration:none;
- color:#E9E9E9;
- display:block;
-}
-div.square_scoreboard a.link:hover{
- text-decoration:underline;
-}
-
-div.squaremg_square{
- width:31%;
- float:left;
-}
-div.squaremg_square > div.head{
- font-size:32px;
- padding:0px 0px 6px 0px;
-}
-div.squaremg_square > div.squarelist{
- margin:6px 0px 0px 0px;
-}
-div.squaremg_square > div.squarelist > div.head{
- font-size:24px;
- border-bottom:#2E8B57 3px solid;
-}
-div.squaremg_square > div.squarelist > table.list{
- width:100%;
- margin:6px 0px 0px 0px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.squaremg_square > div.squarelist tr.item{
- height:36px;
-}
-div.squaremg_square > div.squarelist tr:hover.item{
- color:#FFFFFF;
-}
-div.squaremg_square > div.squarelist td.name{
- width:auto;
- font-size:16px;
-}
-div.squaremg_square > div.squarelist td.time{
- width:256px;
- font-size:16px;
-}
-div.squaremg_square > div.squarelist td.button{
- width:96px;
-}
-
diff --git a/web/page_square.js b/web/page_square.js
deleted file mode 100644
index 6ce6403..0000000
--- a/web/page_square.js
+++ /dev/null
@@ -1,840 +0,0 @@
-var square_page;
-var square_pageo_list;
-var suqare_pageo;
-var square_update_callback;
-
-function square_init(){
- square_page = $('#page_square');
- square_pageo_list = new Array();
- square_pageo = null;
- square_update_callback = $.Callbacks();
-
- user_logincallback.add(square_update);
-
- $('#index_headtab_square a.button').on('click',function(e){
- square_tabswitch($(this.parentNode).attr('tab'));
- return false;
- });
-
- $('div.squaremg_square > div.squarelist > table.list tr.item').hover(
- function(e){
- $(this).find('div.nor_button').show();
- },
- function(e){
- $(this).find('div.nor_button').hide();
- }
- );
-
- $('#squaremg_inside > div.squarelist > table.list tr.item div.nor_button').on('click',function(e){
- $.post('user_set.php',
- {
- 'type':'squareremove',
- 'squareid':$(this).parents('tr.item').data('squareid')
- },
- function(res){
- square_update();
- }
- );
- });
- $('#squaremg_outside > div.squarelist > table.list tr.item div.nor_button').on('click',function(e){
- $.post('user_set.php',
- {
- 'type':'squareadd',
- 'squareid':$(this).parents('tr.item').data('squareid')
- },
- function(res){
- square_update();
- }
- );
- });
- data_callback.add(square_callback);
- data_callback.add(square_rank_callback);
- data_callback.add(square_problem_callback);
- data_callback.add(square_scoreboard_callback);
-
- square_update();
-}
-function square_update(){
- data_paramo.square_list = new Object();
- data_update(true);
-}
-function square_callback(res){
- var i;
-
- var reto;
- var inlist;
- var outlist;
- var squareo;
-
- var divs;
- var j_oributton;
- var j_button;
- var j_a;
-
- var e_u_table;
- var e_a_table;
- var e_i_table;
- var uidx;
- var aidx;
- var iidx;
-
- if(res.square_list === undefined){
- return;
- }
- if(res.square_list != null){
- reto = res.square_list;
- inlist = reto.inlist;
- outlist = reto.outlist;
-
- j_oributton = $('#index_panel_squarelist > div.ori');
- divs = $('#index_panel_squarelist').children('div.button');
- for(i = 1;i < divs.length;i++){
- $(divs[i]).hide();
- }
- for(i = 0;i < inlist.length;i++){
- squareo = inlist[i];
- if(squareo.status != 'active'){
- continue;
- }
-
- if((divs.length - 2) <= i){
- j_button = j_oributton.clone(true);
- j_button.removeClass('ori');
- j_oributton.before(j_button);
- }else{
- j_button = $(divs[i + 1]);
- }
-
- j_button.attr('page','square_' + squareo.squareid);
- j_a = $(j_button.find('a.button')[0]);
- j_a.attr('href','/expoj/index.html?page=square_' + squareo.squareid);
- j_a.text(squareo.squarename);
-
- j_button.show();
-
- if(squareo.squareid in square_pageo_list){
- square_pageo_list[squareo.squareid].squarename = squareo.squarename;
- }else{
- square_pageo_list[squareo.squareid] = {
- 'squareid':squareo.squareid,
- 'squarename':squareo.squarename,
- 'flag':squareo.flag,
- 'tab':'problem',
- 'tabo_rank':{
- 'rankcount':0,
- 'rankoff':0,
- 'callback':$.Callbacks()
- },
- 'tabo_problem':{
- 'procount':0,
- 'prooff':0,
- 'callback':$.Callbacks()
- },
- 'tabo_scoreboard':{
- 'callback':$.Callbacks()
- }
- }
- }
- }
-
- e_u_table = $('#squaremg_inside > div.upcoming > table.list')[0];
- e_a_table = $('#squaremg_inside > div.active > table.list')[0];
- e_i_table = $('#squaremg_inside > div.inactive > table.list')[0];
- for(i = e_u_table.rows.length - 1;i > 0;i--){
- $(e_u_table.rows[i]).hide();
- }
- for(i = e_a_table.rows.length - 1;i > 0;i--){
- $(e_a_table.rows[i]).hide();
- }
- for(i = e_i_table.rows.length - 1;i > 0;i--){
- $(e_i_table.rows[i]).hide();
- }
-
- uidx = 0;
- aidx = 0;
- iidx = 0;
- for(i = 0;i < inlist.length;i++){
- squareo = inlist[i];
-
- switch(squareo.status){
- case 'upcoming':
- squaremg_square_listadd(
- e_u_table,
- uidx,
- squareo.squareid,
- squareo.squarename,
- squareo.starttime,
- squareo.endtime);
-
- uidx++;
- break;
- case 'active':
- squaremg_square_listadd(
- e_a_table,
- aidx,
- squareo.squareid,
- squareo.squarename,
- squareo.starttime,
- squareo.endtime);
-
- aidx++;
- break;
- case 'inactive':
- squaremg_square_listadd(
- e_i_table,
- iidx,
- squareo.squareid,
- squareo.squarename,
- squareo.starttime,
- squareo.endtime);
-
- iidx++;
- break;
- }
- }
-
- e_u_table = $('#squaremg_outside > div.upcoming > table.list')[0];
- e_a_table = $('#squaremg_outside > div.active > table.list')[0];
- e_i_table = $('#squaremg_outside > div.inactive > table.list')[0];
- for(i = e_u_table.rows.length - 1;i > 0;i--){
- $(e_u_table.rows[i]).hide();
- }
- for(i = e_a_table.rows.length - 1;i > 0;i--){
- $(e_a_table.rows[i]).hide();
- }
- for(i = e_i_table.rows.length - 1;i > 0;i--){
- $(e_i_table.rows[i]).hide();
- }
-
- uidx = 0;
- aidx = 0;
- iidx = 0;
- for(i = 0;i < outlist.length;i++){
- squareo = outlist[i];
-
- switch(squareo.status){
- case 'upcoming':
- squaremg_square_listadd(
- e_u_table,
- uidx,
- squareo.squareid,
- squareo.squarename,
- squareo.starttime,
- squareo.endtime);
-
- uidx++;
- break;
- case 'active':
- squaremg_square_listadd(
- e_a_table,
- aidx,
- squareo.squareid,
- squareo.squarename,
- squareo.starttime,
- squareo.endtime);
-
- aidx++;
- break;
- case 'inactive':
- squaremg_square_listadd(
- e_i_table,
- iidx,
- squareo.squareid,
- squareo.squarename,
- squareo.starttime,
- squareo.endtime);
-
- iidx++;
- break;
- } }
-
- square_update_callback.fire();
- }
-}
-
-function square_pageswitch(pagename,on){
- var squareid;
- var param;
- var as;
- var tabo;
- var show = function(){
- squareid = pagename.match(/^square_(.+)/)[1];
- square_pageo = square_pageo_list[squareid];
-
- param = nor_getparam();
- if(param.tab != undefined){
- square_pageo.tab = param.tab;
- }
-
- if(square_pageo.tab != 'rank' && square_pageo.tab != 'problem' && square_pageo.tab != 'scoreboard'){
- square_pageo.tab = 'problem';
- }
- if(square_pageo.tab == 'scoreboard' && !('1' in square_pageo.flag)){
- square_pageo.tab = 'problem';
- }
-
- $('#index_head_title').text('ExpOJ-' + square_pageo.squarename);
-
- square_page.attr('id','page_square_' + square_pageo.squareid);
-
- as = $('#index_headtab_square > div.button > a.button');
- $(as[0]).attr('href','/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=problem');
- $(as[1]).attr('href','/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=rank');
- $(as[2]).attr('href','/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=scoreboard');
-
- if('1' in square_pageo.flag){
- $('#index_headtab_square > [tab="scoreboard"]').show();
- }else{
- $('#index_headtab_square > [tab="scoreboard"]').hide();
- }
-
- $('#index_headtab_square > div.button').removeClass('button_s');
- $('#index_headtab_square > [tab="' + square_pageo.tab + '"]').addClass('button_s');
- $('#index_headtab_square').show();
-
- $(square_page.find('div.square_rank')[0]).hide();
- $(square_page.find('div.square_problem')[0]).hide();
- $(square_page.find('div.square_scoreboard')[0]).hide();
-
- switch(square_pageo.tab){
- case 'rank':
- tabo = square_pageo.tabo_rank;
- if(param.rankoff != undefined){
- tabo.rankoff = param.rankoff;
- }
-
- tabo.callback.add(function(){
- $(square_page.find('div.square_rank')[0]).show();
- window.history.replaceState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- square_rank_update();
- break;
- case 'problem':
- tabo = square_pageo.tabo_problem;
- if(param.prooff != undefined){
- tabo.prooff = param.prooff;
- }
-
- tabo.callback.add(function(){
- $(square_page.find('div.square_problem')[0]).show();
- window.history.replaceState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- square_problem_update();
- break;
- case 'scoreboard':
- tabo = square_pageo.tabo_scoreboard;
- tabo.callback.add(function(){
- $(square_page.find('div.square_scoreboard')[0]).show();
- window.history.replaceState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- square_scoreboard_update();
- break;
- }
-
- square_page.fadeIn('slow');
- }
-
- if(on){
- square_update_callback.add(function(){
- show();
- square_update_callback.remove(arguments.callee);
- });
- square_update();
- }else{
- delete data_paramo.square_rank_list;
- delete data_paramo.square_problem_list;
- delete data_paramo.square_scoreboard_list;
- }
-}
-function square_tabswitch(tabname){
- var j_tab;
- var tabo;
- var j_div;
- var show = function(){
- square_pageo.tab = tabname;
-
- j_tab = $(square_page.find('div.square_' + square_pageo.tab)[0]);
- switch(square_pageo.tab){
- case 'rank':
- tabo = square_pageo.tabo_rank;
- tabo.callback.add(function(){
- j_tab.fadeIn('fast');
- window.history.pushState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- square_rank_update();
- break;
- case 'problem':
- tabo = square_pageo.tabo_problem;
- tabo.callback.add(function(){
- j_tab.fadeIn('fast');
- window.history.pushState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- square_problem_update();
- break;
- case 'scoreboard':
- tabo = square_pageo.tabo_scoreboard;
- tabo.callback.add(function(){
- j_tab.fadeIn('fast');
- window.history.pushState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- })
-
- square_scoreboard_update();
- break;
- }
- }
-
- if(square_pageo.tab == tabname){
- return -1;
- }
-
- delete data_paramo.square_rank_list;
- delete data_paramo.square_problem_list;
- delete data_paramo.square_scoreboard_list;
-
- $('#index_headtab_square > div.button').removeClass('button_s');
- $(square_page.find('div.square_' + square_pageo.tab)[0]).fadeOut('fast',show);
- $('#index_headtab_square > [tab="' + tabname + '"]').addClass('button_s');
-}
-function square_geturl(){
- var url;
- var pageo;
- var j_tab;
- var tabo;
-
- url = '/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=' + square_pageo.tab;
-
- switch(square_pageo.tab){
- case 'rank':
- url = url + '&rankoff=' + square_pageo.tabo_rank.rankoff;
- break;
- case 'problem':
- url = url + '&prooff=' + square_pageo.tabo_problem.prooff;
- break;
- case 'scoreboard':
- break;
- }
-
- return url;
-}
-
-function square_rank_listadd(e_table,rank,userid,nickname,acceptcount,submitcount,score){
- var j_tr;
- var j_a;
-
- j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
- j_tr.removeClass('ori');
- $(j_tr.find('td.rank')[0]).text(rank);
- j_a = $(j_tr.find('td.name > a.link')[0]);
- j_a.attr('href','/expoj/index.html?page=user_' + userid);
- j_a.text(nickname);
- j_a.off('click').on('click',function(userid){return function(e){
- page_switch('user_' + userid);
- return false;
- }}(userid));
- $(j_tr.find('td.rate')[0]).text(acceptcount + '/' + submitcount);
- $(j_tr.find('td.score')[0]).text(score);
-
- j_tr.show();
- $(e_table).append(j_tr);
-}
-function square_rank_chpg(rankoff){
- var tabo;
-
- tabo = square_pageo.tabo_rank;
- if(rankoff >=0 && rankoff < tabo.rankcount){
- tabo.rankoff = rankoff;
- tabo.callback.add(function(){
- window.history.pushState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- square_rank_update();
- }
-}
-function square_rank_update(){
- data_paramo.square_rank_list = {
- 'squareid':parseInt(square_pageo.squareid),
- 'rankoff':parseInt(square_pageo.tabo_rank.rankoff)
- }
-
- data_update(true);
-}
-function square_rank_callback(res){
- var i;
-
- var reto;
- var ranklist;
- var tabo;
- var e_table;
- var j_div;
- var j_a;
-
- if((reto = res.square_rank_list) === undefined){
- return;
- }
-
- if(reto == null){
- delete data_paramo.square_rank_list;
- }else{
- tabo = square_pageo.tabo_rank;
- tabo.rankcount = reto.rankcount;
- ranklist = reto.ranklist;
-
- j_tab = $(square_page.find('div.square_rank')[0]);
-
- e_table = j_tab.find('table.list')[0];
- for(i = e_table.rows.length - 1;i > 1;i--){
- e_table.deleteRow(i);
- }
-
- for(i = 0;i < ranklist.length;i++){
- square_rank_listadd(
- e_table,
- ranklist[i].rank,
- ranklist[i].userid,
- ranklist[i].nickname,
- ranklist[i].acceptcount,
- ranklist[i].submitcount,
- ranklist[i].score);
- }
-
- j_div = $(j_tab.find('div.nor_chpg')[0]);
- j_div.empty();
-
- j_a = nor_new_chpgbutton('«',function(){
- square_rank_chpg(0);
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('‹',function(){
- square_rank_chpg(tabo.rankoff - 20);
- });
- j_div.append(j_a);
-
- offs = Math.max(0,tabo.rankoff - 100);
- if((offe = Math.min(tabo.rankcount,offs + 200)) == tabo.rankcount){
- offs = Math.max(0,(offe - offe % 20) - 180);
- }
- for(i = offs;i < offe;i += 20){
- j_a = nor_new_chpgbutton((i / 20 + 1),function(rankoff){return function(){
- square_rank_chpg(rankoff);
- }}(i));
-
- if(i == tabo.rankoff){
- j_a.addClass('nor_chpg_s');
- }
-
- j_div.append(j_a);
- }
-
- j_a = nor_new_chpgbutton('›',function(){
- square_rank_chpg(tabo.rankoff + 20);
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('»',function(){
- square_rank_chpg(tabo.rankcount - tabo.rankcount % 20);
- });
- j_div.append(j_a);
-
- tabo.callback.fire();
- }
-}
-
-function square_problem_listadd(e_table,idx,proid,proname,acceptcount,submitcount,light){
- var j_tr;
- var j_a;
-
- if((e_table.rows.length - 2) <= idx){
- j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
- j_tr.removeClass('ori');
- $(e_table).append(j_tr);
- }else{
- j_tr = $(e_table.rows[idx + 2]);
- }
-
- switch(light){
- case 0:
- j_tr.css('border-left','#333333 5px solid');
- break;
- case 1:
- j_tr.css('border-left','#FF0000 5px solid');
- break;
- case 2:
- j_tr.css('border-left','#00FF00 5px solid');
- break;
- case 3:
- j_tr.css('border-left','#FFFF00 5px solid');
- break;
- case 4:
- j_tr.css('border-left','#FFFFFF 5px solid');
- break;
- }
-
- $(j_tr.find('td.id')[0]).text(proid);
- $(j_tr.find('td.rate')[0]).text(acceptcount + '/' + submitcount);
- j_a = $(j_tr.find('td.name > a.link')[0]);
- j_a.attr('href','/expoj/index.html?page=problem_' + proid);
- j_a.text(proname);
-
- j_tr.off('click').on('click',function(e){
- page_switch('problem_' + proid);
- return false;
- });
-
- j_tr.show();
- return j_tr;
-}
-function square_problem_chpg(prooff){
- var tabo;
-
- tabo = square_pageo.tabo_problem;
- if(prooff >=0 && prooff < tabo.procount){
- tabo.prooff = prooff;
- tabo.callback.add(function(){
- window.history.pushState('square',document.title,square_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- square_problem_update();
- }
-}
-function square_problem_update(){
- var tabo;
-
- tabo = square_pageo.tabo_problem;
- data_paramo.square_problem_list = {
- 'squareid':parseInt(square_pageo.squareid),
- 'prooff':parseInt(tabo.prooff)
- };
-
- data_update(true);
-}
-function square_problem_callback(res){
- var i;
- var j;
-
- var reto;
- var tabo;
- var prolist;
- var proo;
- var e_table;
- var j_tr;
- var j_div;
-
- if((reto = res.square_problem_list) === undefined){
- return;
- }
-
- if(reto == null){
- delete data_paramo.square_problem_list;
- }else{
- tabo = square_pageo.tabo_problem;
- tabo.procount = reto.procount;
- prolist = reto.prolist;
-
- j_tab = $(square_page.find('div.square_problem')[0]);
-
- e_table = j_tab.find('table.list')[0];
- for(i = e_table.rows.length - 1;i > 1;i--){
- $(e_table.rows[i]).hide();
- }
-
- for(i = 0;i < prolist.length;i++){
- proo = prolist[i];
- square_problem_listadd(
- e_table,
- i,
- proo.proid,
- proo.proname,
- proo.acceptcount,
- proo.submitcount,
- nor_scoretolight(proo.sumscore,proo.summaxscore));
- }
-
- j_div = $(j_tab.find('div.nor_chpg')[0]);
- j_div.empty();
-
- j_a = nor_new_chpgbutton('«',function(){
- square_problem_chpg(0);
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('‹',function(){
- square_problem_chpg(tabo.prooff - 20);
- });
- j_div.append(j_a);
-
- offs = Math.max(0,tabo.prooff - 100);
- if((offe = Math.min(tabo.procount,offs + 200)) == tabo.procount){
- offs = Math.max(0,(offe - offe % 20) - 180);
- }
- for(i = offs;i < offe;i += 20){
- j_a = nor_new_chpgbutton((i / 20 + 1),function(prooff){return function(){
- square_problem_chpg(prooff);
- }}(i));
-
- if(i == tabo.prooff){
- j_a.addClass('nor_chpg_s');
- }
-
- j_div.append(j_a);
- }
-
- j_a = nor_new_chpgbutton('›',function(){
- square_problem_chpg(tabo.prooff + 20);
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('»',function(){
- square_problem_chpg(tabo.procount - tabo.procount % 20);
- });
- j_div.append(j_a);
-
- tabo.callback.fire();
- }
-}
-
-function square_scoreboard_listadd(e_table,rank,userid,nickname,proidlist,prolist){
- var i;
-
- var proo;
- var j_tr;
- var j_td;
- var j_a;
-
- j_tr = $('<tr class="item"></tr>');
- j_td = $('<td class="rank"></td>');
- j_td.text(rank);
- j_tr.append(j_td);
- j_td = $('<td class="name"></td>');
- j_a = $('<a class="link"></a>');
- j_a.attr('href','/expoj/index.html?page=user_' + userid);
- j_a.text(nickname);
- j_a.off('click').on('click',function(userid){return function(e){
- page_switch('user_' + userid);
- return false;
- }}(userid));
- j_td.append(j_a);
- j_tr.append(j_td);
-
- for(i = 0;i < proidlist.length;i++){
- j_td = $('<td class="problem"></td>');
- if(proidlist[i] in prolist){
- proo = prolist[proidlist[i]];
- if(proo.accepttime == null){
- j_td.text('-/' + proo.submitcount);
- }else{
- j_td.text(Math.round(proo.accepttime / 14400) + '/' + proo.submitcount);
- j_td.css('background-color','#222222');
- }
- }
- j_tr.append(j_td);
- }
-
- $(e_table).append(j_tr);
-}
-function square_scoreboard_update(){
- data_paramo.square_scoreboard_list = {
- 'squareid':parseInt(square_pageo.squareid),
- }
-
- data_update(true);
-}
-function square_scoreboard_callback(res){
- var i;
-
- var reto;
- var tabo;
- var proidlist;
- var scoreboardlist;
- var scoreboardo;
- var e_table;
- var j_tr;
- var j_th;
- var j_a;
-
- if((reto = res.square_scoreboard_list) === undefined){
- return;
- }
-
- if(reto == null){
- delete data_paramo.square_scoreboard_list;
- }else{
- tabo = square_pageo.tabo_scoreboard;
- proidlist = reto.proidlist;
- scoreboardlist = reto.scoreboardlist;
-
- j_tab = $(square_page.find('div.square_scoreboard')[0]);
- j_tab.css('width',(192 + 64 + proidlist.length * 104) + 'px');
-
- e_table = j_tab.find('table.list')[0];
-
- j_tr = $(e_table.rows[0]);
- j_tr.empty();
- j_tr.append('<th class="rank">#</th>');
- j_tr.append('<th class="name">Name</th>');
- for(i = 0;i < proidlist.length;i++){
- j_th = $('<th class="problem"></th>');
- j_a = $('<a class="link"></a>');
- j_a.attr('href','/expoj/index.html?page=problem_' + proidlist[i]);
- j_a.text(proidlist[i]);
- j_a.off('click').on('click',function(proid){return function(e){
- page_switch('problem_' + proid);
- return false;
- }}(proidlist[i]));
- j_th.append(j_a);
- j_tr.append(j_th);
- }
-
- for(i = e_table.rows.length - 1;i > 0;i--){
- e_table.deleteRow(i);
- }
-
- for(i = 0;i < scoreboardlist.length;i++){
- scoreboardo = scoreboardlist[i];
- square_scoreboard_listadd(
- e_table,
- scoreboardo.rank,
- scoreboardo.userid,
- scoreboardo.nickname,
- proidlist,
- scoreboardo.prolist);
- }
-
- tabo.callback.fire();
- }
-}
-
-function squaremg_pageswitch(on){
- square_update();
- $('#page_squaremg').fadeIn('slow');
-}
-function squaremg_square_listadd(e_table,idx,squareid,squarename,starttime,endtime){
- var j_tr;
-
- if((e_table.rows.length - 1) <= idx){
- j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
- j_tr.removeClass('ori');
- $(e_table).append(j_tr);
- }else{
- j_tr = $(e_table.rows[idx + 1]);
- }
-
- $(j_tr.find('td.name')).text(squarename);
- $(j_tr.find('td.time')).html(starttime.match(/(.*)[\.,\+]/)[1] + '<br/>' + endtime.match(/(.*)[\.,\+]/)[1]);
- j_tr.data('squareid',squareid);
-
- j_tr.show();
-}
diff --git a/web/page_status.css b/web/page_status.css
deleted file mode 100644
index 95f9401..0000000
--- a/web/page_status.css
+++ /dev/null
@@ -1,110 +0,0 @@
-div.status_submit{
- width:100%;
- height:100%;
- overflow:hidden;
-}
-
-div.status_submit > div.submitlist{
- width:69%;
- height:100%;
- float:left;
- overflow:auto;
-}
-div.status_submit > div.submitlist > table.list{
- width:95%;
- margin:6px auto 0px auto;
- font-size:20px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.status_submit > div.submitlist tr.head{
- height:32px;
-}
-div.status_submit > div.submitlist tr.item{
- height:32px;
- cursor:pointer;
-}
-div.status_submit > div.submitlist tr:hover.item{
- background-color:#36454F;
-}
-div.status_submit > div.submitlist th.id,div.status_submit > div.submitlist td.id{
- width:64px;
-}
-div.status_submit > div.submitlist th.proid,div.status_submit > div.submitlist td.proid{
- width:96px;
-}
-div.status_submit > div.submitlist th.nickname,div.status_submit > div.submitlist td.nickname{
- width:auto;
-}
-div.status_submit > div.submitlist th.time{
- width:224px;
-}
-div.status_submit > div.submitlist td.time{
- width:224px;
- font-weight:normal;
- font-size:16px;
-}
-div.status_submit > div.submitlist th.result,div.status_submit > div.submitlist td.result{
- width:80px;
-}
-div.status_submit > div.submitlist th.runtime{
- width:104px;
-}
-div.status_submit > div.submitlist td.runtime{
- width:104px;
- font-weight:normal;
- font-size:16px;
-}
-div.status_submit > div.submitlist th.score,div.status_submit > div.submitlist td.score{
- width:64px;
-}
-div.status_submit > div.submitlist a.link{
- height:100%;
- color:#E9E9E9;
- text-decoration:none;
- cursor:pointer;
-}
-div.status_submit > div.submitlist a:hover.link{
- text-decoration:underline;
-}
-
-div.status_submit > div.submitinfo{
- width:31%;
- height:100%;
- background-color:#222222;
- overflow:auto;
- float:left;
-}
-div.status_submit > div.submitinfo div.head{
- width:100%;
- height:32px;
- margin:6px 0px 0px 0px;
-}
-div.status_submit > div.submitinfo table.info{
- width:95%;
- margin:26px 0px 0px auto;
- font-size:16px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.status_submit > div.submitinfo > table.list{
- width:95%;
- margin:32px 0px 0px auto;
- font-size:16px;
- text-align:left;
- border-spacing:0px;
- border-collapse:collapse;
-}
-div.status_submit > div.submitinfo a.link{
- width:100%;
- height:100%;
- color:#E9E9E9;
- text-decoration:none;
- display:block;
- cursor:pointer;
-}
-div.status_submit > div.submitinfo a:hover.link{
- text-decoration:underline;
-}
diff --git a/web/page_status.js b/web/page_status.js
deleted file mode 100644
index 415f3d2..0000000
--- a/web/page_status.js
+++ /dev/null
@@ -1,497 +0,0 @@
-var status_judgestat;
-var status_tab;
-
-function status_init(){
- var j_tab;
- var j_div;
- var as;
-
- status_judgestat = new Array();
- status_judgestat[0] = 'AC';
- status_judgestat[1] = 'WA';
- status_judgestat[2] = 'TLE';
- status_judgestat[3] = 'MLE';
- status_judgestat[4] = 'RF';
- status_judgestat[5] = 'RE';
- status_judgestat[6] = 'CE';
- status_judgestat[7] = 'ERR';
- status_judgestat[100] = 'WAIT';
-
- j_tab = $('#status_allsubmit');
- j_tab.data('tabo',{
- 'useronly':false,
- 'submitid':2147483647,
- 'submitoff':0,
- 'submitcount':0,
- 'callback':$.Callbacks()
- });
- data_callback.add(function(j_tab){return function(res){
- status_submit_callback(j_tab,res);
- }}(j_tab));
-
- j_tab = $('#status_usersubmit');
- j_tab.data('tabo',{
- 'useronly':true,
- 'submitid':2147483647,
- 'submitoff':0,
- 'submitcount':0,
- 'callback':$.Callbacks()
- });
- user_logincallback.add(function(){
- var j_tab;
-
- j_tab = $('#status_usersubmit');
- if(user_usero != null){
- $('#index_headtab_status > [tab="usersubmit"]').show();
- }
- });
- data_callback.add(function(j_tab){return function(res){
- status_submit_callback(j_tab,res);
- }}(j_tab));
- status_submit_update(j_tab);
-
- $('#index_headtab_status > div.button').on('click',function(e){
- status_tabswitch($(this).attr('tab'));
- return false;
- });
-}
-function status_pageswitch(on){
- var param;
- var j_tab;
- var tabo;
-
- if(on){
- param = nor_getparam();
- if(param.tab != undefined){
- status_tab = param.tab;
- }
- if(status_tab != 'usersubmit' && status_tab != 'allsubmit'){
- status_tab = 'allsubmit';
- }
-
- $('#index_head_title').text('ExpOJ-Status');
-
- $('#index_headtab_status > div.button').removeClass('button_s');
- $('#index_headtab_status > [tab="' + status_tab + '"]').addClass('button_s');
- $('#index_headtab_status').show();
-
- $('#status_allsubmit').hide();
- $('#status_usersubmit').hide();
-
- switch(status_tab){
- case 'allsubmit':
- j_tab = $('#status_allsubmit');
- tabo = j_tab.data('tabo');
-
- if(param.submitid != undefined){
- tabo.submitid = param.submitid;
- }
- if(param.submitoff != undefined){
- tabo.submitoff = param.submitoff;
- }
-
- tabo.callback.add(function(){
- j_tab.show();
- window.history.replaceState('status',document.title,status_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- status_submit_update(j_tab);
- break;
- case 'usersubmit':
- j_tab = $('#status_usersubmit');
- tabo = j_tab.data('tabo');
-
- if(param.submitid != undefined){
- tabo.submitid = param.submitid;
- }
- if(param.submitoff != undefined){
- tabo.submitoff = param.submitoff;
- }
-
- tabo.callback.add(function(){
- j_tab.show();
- window.history.replaceState('status',document.title,status_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- status_submit_update(j_tab);
- break;
- }
-
- $('#page_status').fadeIn('slow');
- }else{
- delete data_paramo.status_submit_userlist;
- delete data_paramo.status_submit_list;
- }
-}
-function status_tabswitch(tabname){
- var j_tab;
- var tabo;
- var show = function(){
- status_tab = tabname;
-
- j_tab = $('#status_' + status_tab);
- switch(status_tab){
- case 'allsubmit':
- tabo = j_tab.data('tabo')
- tabo.callback.add(function(){
- j_tab.fadeIn('fast');
- window.history.pushState('status',document.title,status_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- status_submit_update(j_tab);
- break;
- case 'usersubmit':
- tabo = j_tab.data('tabo')
- tabo.callback.add(function(){
- j_tab.fadeIn('fast');
- window.history.pushState('status',document.title,status_geturl());
- tabo.callback.remove(arguments.callee);
- });
-
- status_submit_update(j_tab);
- break;
- }
- }
-
- if(status_tab == tabname){
- return -1;
- }
-
- delete data_paramo.status_submit_userlist;
- delete data_paramo.status_submit_list;
-
- $('#index_headtab_status > [tab="' + status_tab + '"]').removeClass('button_s');
- $('#status_' + status_tab).fadeOut('fast',show);
-
- $('#index_headtab_status > [tab="' + tabname + '"]').addClass('button_s');
-}
-function status_geturl(){
- var url;
- var tabo;
-
- switch(status_tab){
- case 'allsubmit':
- tabo = $('#status_allsubmit').data('tabo');
- if(tabo.submitid == null){
- url = '/expoj/index.html?page=status&tab=allsubmit&submitoff=' + tabo.submitoff;
- }else{
- url = '/expoj/index.html?page=status&tab=allsubmit&submitoff=' + tabo.submitoff + '&submitid=' + tabo.submitid;
- }
- break;
- case 'usersubmit':
- tabo = $('#status_usersubmit').data('tabo');
- if(tabo.submitid == null){
- url = '/expoj/index.html?page=status&tab=usersubmit&submitoff=' + tabo.submitoff;
- }else{
- url = '/expoj/index.html?page=status&tab=usersubmit&submitoff=' + tabo.submitoff + '&submitid=' + tabo.submitid;
- }
- break;
- }
-
- return url;
-}
-
-function status_submit_listadd(e_table,idx,submitid,proid,userid,nickname,time,result,runtime,score,light){
- var j_tr;
- var j_td;
- var j_a;
-
- if((e_table.rows.length - 2) <= idx){
- j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
- j_tr.removeClass('ori');
- $(e_table).append(j_tr);
- }else{
- j_tr = $(e_table.rows[idx + 2]);
- }
-
- $(j_tr.find('td.id')[0]).text(submitid);
- $(j_tr.find('td.time')[0]).text(time.match(/(.*)\./)[1]);
- $(j_tr.find('td.result')[0]).text(result);
- $(j_tr.find('td.runtime')[0]).text(Math.round(parseInt(runtime) / 1000));
- j_td = $(j_tr.find('td.score')[0]);
- j_td.text(score);
- switch(light){
- case 1:
- j_td.css('color','#FF0000');
- break;
- case 2:
- j_td.css('color','#00FF00');
- break;
- case 3:
- j_td.css('color','#FFFF00');
- break;
- case 4:
- j_td.css('color','#FFFFFF');
- break;
- }
-
- j_a = $(j_tr.find('td.proid > a.link')[0]);
- j_a.attr('href','/expoj/index.html?page=problem_' + proid);
- j_a.text(proid);
- j_a.off('click').on('click',function(e){
- page_switch('problem_' + proid);
- return false;
- });
-
- j_a = $(j_tr.find('td.nickname > a.link')[0]);
- j_a.attr('href','/expoj/index.html?page=user_' + userid);
- j_a.text(nickname);
- j_a.off('click').on('click',function(e){
- page_switch('user_' + userid);
- return false;
- });
-
- j_tr.off('click').on('click',function(e){
- var j_tab;
- var tabo;
-
- if(e.target.tagName == 'A'){
- return;
- }
-
- j_tab = $(this).data('j_tab');
- tabo = j_tab.data('tabo');
- tabo.submitid = $(this).data('submitid');
-
- tabo.callback.add(function(){
- window.history.pushState('status',document.title,status_geturl());
- tabo.callback.remove(arguments.callee);
- });
- status_submit_update(j_tab);
- });
-
- j_tr.show();
- return j_tr;
-}
-function status_submit_listchpg(j_tab,submitoff){
- var tabo;
-
- tabo = j_tab.data('tabo');
- if(submitoff >= 0 && submitoff < tabo.submitcount){
- tabo.submitoff = submitoff;
- tabo.callback.add(function(){
- window.history.pushState('status',document.title,status_geturl());
- tabo.callback.remove(arguments.callee);
- });
- status_submit_update(j_tab);
- }
-}
-function status_submit_update(j_tab){
- var tabo;
- var paramo;
-
- tabo = j_tab.data('tabo');
- paramo = {
- 'submitoff':parseInt(tabo.submitoff),
- 'submitid':parseInt(tabo.submitid)
- };
- if(tabo.useronly){
- data_paramo.status_submit_userlist = paramo;
- }else{
- data_paramo.status_submit_list = paramo;
- }
-
- data_update(true);
-}
-function status_submit_callback(j_tab,res){
- var reto;
- var j_tab;
- var tabo;
- var submitlist;
-
- tabo = j_tab.data('tabo');
- if(tabo.useronly){
- reto = res.status_submit_userlist;
- }else{
- reto = res.status_submit_list;
- }
- if(reto === undefined){
- return;
- }
-
- if(reto == null){
- if(tabo.useronly){
- delete data_paramo.status_submit_userlist;
- }else{
- delete data_paramo.status_submit_list;
- }
- }else{
- tabo.submitcount = reto.submitcount;
- submitlist = reto.submitlist;
-
- if(tabo.submitoff != null){
- var i;
- var j;
-
- var e_table;
- var j_tr;
- var j_div;
- var j_a;
- var submito;
- var offs;
- var offe;
-
- e_table = j_tab.find('div.submitlist > table.list')[0];
- for(i = e_table.rows.length - 1;i > 1;i--){
- $(e_table.rows[i]).hide();
- }
-
- for(i = 0;i < submitlist.length - 1;i++){
- submito = submitlist[i];
- j_tr = status_submit_listadd(
- e_table,
- i,
- submito.submitid,
- submito.proid,
- submito.userid,
- submito.nickname,
- submito.timestamp,
- status_judgestat[submito.result],
- submito.sumruntime,
- submito.sumscore,
- nor_scoretolight(submito.sumscore,submito.summaxscore));
- j_tr.data('j_tab',j_tab);
- j_tr.data('submitid',submito.submitid);
- }
-
- j_div = $(j_tab.find('div.nor_chpg')[0]);
- j_div.empty();
-
- j_a = nor_new_chpgbutton('«',function(){
- status_submit_listchpg(j_tab,0);
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('‹',function(){
- status_submit_listchpg(j_tab,(tabo.submitoff - 20));
- });
- j_div.append(j_a);
-
- offs = Math.max(0,tabo.submitoff - 100);
- if((offe = Math.min(tabo.submitcount,offs + 200)) == tabo.submitcount){
- offs = Math.max(0,(offe - offe % 20) - 180);
- }
- for(i = offs;i < offe;i += 20){
- j_a = nor_new_chpgbutton((i / 20 + 1),function(){
- status_submit_listchpg(j_tab,$(this).data('submitoff'));
- });
- j_a.data('submitoff',i);
-
- if(i == tabo.submitoff){
- j_a.addClass('nor_chpg_s');
- }
-
- j_div.append(j_a);
- }
-
- j_a = nor_new_chpgbutton('›',function(){
- status_submit_listchpg(j_tab,(tabo.submitoff + 20));
- });
- j_div.append(j_a);
-
- j_a = nor_new_chpgbutton('»',function(){
- status_submit_listchpg(j_tab,(tabo.submitcount - tabo.submitcount % 20));
- });
- j_div.append(j_a);
- }
- if(tabo.submitid != null){
- var i;
-
- var e_table;
- var tds;
- var as;
- var j_tr;
- var j_td;
- var submito;
- var partstatus;
- var partscore;
- var partruntime;
- var partpeakmem;
-
- if(submitlist.length == 0){
- e_table = j_tab.find('div.submitinfo > table.info')[0];
-
- tds = $(e_table).find('td');
- $(tds[1]).text('');
- $(tds[7]).text('');
-
- as = $(e_table).find('a');
- $(as[0]).attr('href','');
- $(as[0]).text('');
- $(as[0]).off('click');
- $(as[1]).attr('href','');
- $(as[1]).text('');
- $(as[1]).off('click');
- }else{
- submito = submitlist[submitlist.length - 1];
- tabo.submitid = submito.submitid;
- partstatus = submito.status.split(',');
- partscore = submito.score.split(',');
- partruntime = submito.runtime.split(',');
- partpeakmem = submito.peakmem.split(',');
-
- e_table = j_tab.find('div.submitinfo > table.list')[0];
- for(i = e_table.rows.length - 1;i > 0;i--){
- e_table.deleteRow(i);
- }
-
- for(i = 0;i < partstatus.length;i++){
- j_tr = $('<tr></tr>');
-
- j_td = $('<td></td>');
- j_td.text(i + 1);
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(status_judgestat[parseInt(partstatus[i])]);
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(partscore[i]);
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(Math.round(parseInt(partruntime[i]) / 1000));
- j_tr.append(j_td);
- j_td = $('<td></td>');
- j_td.text(Math.round(parseInt(partpeakmem[i]) / 1024));
- j_tr.append(j_td);
-
- $(e_table).append(j_tr);
- }
-
- e_table = j_tab.find('div.submitinfo > table.info')[0];
-
- tds = $(e_table).find('td');
- $(tds[1]).text(submito.submitid);
- $(tds[7]).text(submito.sumscore);
-
- as = $(e_table).find('a');
- $(as[0]).attr('href','/expoj/index.html?page=problem_' + submito.proid);
- $(as[0]).text(submito.proid);
- $(as[0]).off('click').on('click',function(proid){return function(e){
- page_switch('problem_' + proid);
- return false;
- }}(submito.proid));
- $(as[1]).attr('href','/expoj/index.html?page=user_' + submito.userid);
- $(as[1]).text(submito.nickname);
- $(as[1]).off('click').on('click',function(userid){return function(e){
- page_switch('user_' + userid);
- return false;
- }}(submito.userid));
-
- if(user_usero != null && submito.userid == user_usero.userid){
- $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).show();
- }else{
- $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).hide();
- }
- }
- }
-
- tabo.callback.fire();
- }
-}
-
-function status_viewcode(submitid){
- window.open('/expoj/viewcode.html?submitid=' + submitid);
-}
diff --git a/web/page_user.css b/web/page_user.css
deleted file mode 100644
index 7b2d91c..0000000
--- a/web/page_user.css
+++ /dev/null
@@ -1,123 +0,0 @@
-div.user_info{
- width:31%;
- height:100%;
- background-color:#222222;
- font-size:18px;
- overflow:auto;
- float:left;
-}
-div.user_info div.head{
- margin:6px 0px 6px 0px;
-}
-div.user_info div.setting{
- float:right;
-}
-div.user_info div.head input.name{
- width:62%;
- height:32px;
- margin:0px 0px 6px 6px;
- background-color:#222222;
- color:#E9E9E9;
- font-weight:bold;
- font-size:24px;
- line-height:32px;
- border-width:0px;
-}
-div.user_info div.head input.aboutme,input.headimg{
- width:95%;
- height:24px;
- margin:0px 0px 6px 6px;
- background-color:#222222;
- color:#E9E9E9;
- font-weight:normal;
- font-size:16px;
- line-height:24px;
- border-width:0px;
-}
-div.user_info div.head img.headimg{
- width:100%;
- margin:0px 0px 0px 0px;
- display:block;
-}
-div.user_info table.info{
- width:95%;
- margin:0px auto 0px 6px;
-}
-div.user_info table.info td.info{
- font-weight:normal;
- font-size:16px;
-}
-
-div.user_data{
- width:69%;
- height:100%;
- overflow:auto;
- float:left;
-}
-div.user_data div.prolist{
- width:62%;
- margin:32px auto 0px auto;
-}
-div.user_data div.prolist span.item{
- width:64px;
- height:32px;
- line-height:32px;
- display:inline-block;
-}
-div.user_data div.prolist a.item{
- width:100%;
- height:100%;
- font-weight:bold;
- font-size:16px;
- text-align:center;
- text-decoration:none;
- display:block;
-}
-div.user_data div.prolist a:hover.item{
- text-decoration:underline;
-}
-
-table.login{
- width:256px;
- margin:192px auto;
- border-spacing:16px;
-}
-table.login div.error{
- width:100%;
- height:16px;
- font-size:16px;
- color:#FFA0A0;
-}
-table.login div.head{
- width:100%;
- font-size:16px;
-}
-table.login input.input{
- width:100%;
- padding:0px 0px 0px 0px;
- font-size:20px;
- background-color:#E9E9E9;
- border-width:0px;
-}
-table.register{
- width:256px;
- margin:192px auto;
- border-spacing:16px;
-}
-table.register div.error{
- width:100%;
- height:16px;
- font-size:16px;
- color:#FFA0A0;
-}
-table.register div.head{
- width:100%;
- font-size:16px;
-}
-table.register input.input{
- width:100%;
- padding:0px 0px 0px 0px;
- font-size:20px;
- background-color:#E9E9E9;
- border-width:0px;
-}
diff --git a/web/page_user.js b/web/page_user.js
deleted file mode 100644
index e016a51..0000000
--- a/web/page_user.js
+++ /dev/null
@@ -1,305 +0,0 @@
-var user_usero;
-var user_logincallback;
-
-function user_init(){
- user_logincallback = $.Callbacks();
-
- $('#login_username').on('keypress',function(e){
- if(e.which == 13){
- user_login_submit();
- }
- });
- $('#login_password').on('keypress',function(e){
- if(e.which == 13){
- user_login_submit();
- }
- });
-
- $('#register_username').on('keypress',function(e){
- if(e.which == 13){
- user_register_submit();
- }
- });
- $('#register_password').on('keypress',function(e){
- if(e.which == 13){
- user_register_submit();
- }
- });
- $('#register_nickname').on('keypress',function(e){
- if(e.which == 13){
- user_register_submit();
- }
- });
-
- $('#index_panel > [page="logout"]').off('click').on('click',user_logout);
-}
-function user_loginchange(){
- var cookie;
- var j_div;
-
- cookie = nor_getcookie();
- if(cookie['userid'] != undefined){
- user_update(cookie['userid'],true);
- }else{
- user_usero = null;
- user_panelswitch(false);
- user_logincallback.fire();
- }
-}
-function user_update(userid,login){
- $.ajax({
- url:'user_get.php',
- type:'POST',
- data:{'userid':parseInt(userid)},
- async:false,
- success:function(res){
- var i;
-
- var reto;
- var usero;
- var prolist;
- var tds;
-
- var j_div;
- var proo;
- var j_span;
- var j_a;
- var color;
-
- if(res[0] != 'E'){
- reto = JSON.parse(res);
- usero = reto.userinfo;
- prolist = reto.prolist;
-
- $('#user_info > div.head > input.name').val(usero.nickname);
- $('#user_info > div.head > input.aboutme').val(usero.aboutme);
- $('#user_info > div.head > input.headimg').val(usero.headimg);
- $('#user_info > div.head > img.headimg').attr('src',usero.headimg);
-
- tds = $('#user_info > table.info td.info');
- $(tds[1]).text(usero.acceptcount);
- $(tds[3]).text(usero.submitcount);
- $(tds[5]).text(usero.trycount);
-
- j_div = $($('#user_data > div.prolist')[0]);
- j_div.empty();
- for(i = 0;i < prolist.length;i++){
- proo = prolist[i];
-
- j_span = $('<span class="item"></span');
- j_span.on('click',function(proid){return function(e){
- page_switch('problem_' + proid);
- return false;
- }}(proo.proid));
-
- j_a = $('<a class="item"></a>');
- j_a.attr('href','/expoj/index.html?page=problem_' + proo.proid);
- j_a.text(proo.proid);
-
- switch(nor_scoretolight(parseInt(proo.rate),100)){
- case 0:
- color = '#333333';
- case 1:
- color = '#FF0000';
- break;
- case 2:
- color = '#00FF00';
- break;
- case 3:
- color = '#FFFF00';
- break;
- case 4:
- color = '#FFFFFF';
- break;
- }
- j_a.css('color',color);
-
- j_span.append(j_a);
- j_div.append(j_span);
- }
-
- if(login){
- user_usero = usero;
- user_panelswitch(true);
- user_logincallback.fire();
- }
- }else if(login){
- user_usero = null;
- user_panelswitch(false);
- user_logincallback.fire();
- }
- }
- });
-}
-
-function user_panelswitch(on){
- var j_div;
-
- if(on){
- j_div = $('#index_panel > [page="user"]');
- j_div.attr('page','user_' + user_usero.userid);
- $(j_div.find('a.button')[0]).attr('href','/expoj/index.html?page=user_' + user_usero.userid);
- j_div.show();
- $('#index_panel > [page="login"]').hide();
- $('#index_panel > [page="register"]').hide();
- $('#index_panel > [page="logout"]').show();
- }else{
- j_div = $('#index_panel > [page^="user"]');
- j_div.attr('page','user');
- $(j_div.find('a.button')[0]).attr('href',null);
- j_div.hide();
- $('#index_panel > [page="login"]').show();
- $('#index_panel > [page="register"]').show();
- $('#index_panel > [page="logout"]').hide();
- }
-}
-function user_pageswitch(pagename,on){
- var userid;
- var j_page;
-
- if(on){
- userid = pagename.match(/^user_(.+)/)[1];
-
- $('#index_head_title').text('ExpOJ-UID:' + userid);
-
- user_update(userid,false);
-
- if(user_usero != null && userid == user_usero.userid){
- $('#user_info > div.head > div.setting').show();
- }else{
- $('#user_info > div.head > div.setting').hide();
- }
-
- j_page = $('[id^="page_user"]');
- j_page.attr('id','page_user_' + userid);
- j_page.fadeIn('slow');
- }else{
- $('[id^="page_user"]').attr('id','page_user');
- }
-}
-function user_infoedit(on){
- var divs;
- var inputs;
-
- divs = $('#user_info > div.head > div.setting > div.nor_button');
- inputs = $('#user_info > div.head > input');
- if(on){
- $(divs[0]).hide();
- $(divs[1]).show();
- $(divs[2]).show();
- $('#user_info > div.head > input.headimg').show();
- inputs.attr('readonly',null);
- inputs.css('background-color','#333333');
- }else{
- $(divs[0]).show();
- $(divs[1]).hide();
- $(divs[2]).hide();
- $('#user_info > div.head > input.headimg').hide();
- inputs.attr('readonly','readonly');
- inputs.css('background-color','transparent');
-
- user_update(user_usero.userid,false);
- }
-}
-function user_infosubmit(){
- var inputs;
- inputs = $('#user_info > div.head > input');
- $.post('user_set.php',
- {
- 'type':'userinfo',
- 'nickname':$('#user_info > div.head > input.name').val(),
- 'aboutme':$('#user_info > div.head > input.aboutme').val(),
- 'headimg':$('#user_info > div.head > input.headimg').val()
- },
- function(res){
- user_infoedit(false);
- }
- );
-}
-
-function user_login_pageswitch(){
- $('#index_head_title').text('ExpOJ-Login');
-
- user_login_reset();
- $('#page_login').fadeIn('fast',function(){
- $('#login_username').focus();
- });
-}
-function user_login_reset(){
- $('#login_error').html('');
- $('#login_username').val('');
- $('#login_password').val('');
-}
-function user_login_submit(){
- $.post('user_login.php',
- {'username':$('#login_username').val(),'password':$('#login_password').val()},
- function(res){
- if(res[0] == 'S'){
- user_login_reset();
- user_loginchange();
- if(page_name_previous == 'login' || page_name_previous == 'register'){
- page_switch('home');
- }else{
- page_switch(page_name_previous);
- }
- }else if(res == 'Eerror'){
- $('#login_error').html('使用者名稱或密碼錯誤');
- }else{
- $('#login_error').html('Oops');
- }
- }
- );
-}
-
-function user_register_pageswitch(){
- $('#index_head_title').text('ExpOJ-Register');
-
- user_register_reset();
- $('#page_register').fadeIn('fast',function(){
- $('#register_username').focus();
- });
-}
-function user_register_reset(){
- $('#register_error').html('');
- $('#register_username').val('');
- $('#register_password').val('');
- $('#register_nickname').val('');
-}
-function user_register_submit(){
- $.post('user_register.php',
- {'username':$('#register_username').val(),'password':$('#register_password').val(),'nickname':$('#register_nickname').val()},
- function(res){
- if(res[0] == 'S'){
- user_register_reset();
- user_loginchange();
- if(page_name_previous == 'login' || page_name_previous == 'register'){
- page_switch('home');
- }else{
- page_switch(page_name_previous);
- }
- }else if(res == 'Eusername'){
- $('#register_error').html('使用者名稱不可為空或有非法字元<br/>最長16 Bytes');
- }else if(res == 'Epassword'){
- $('#register_error').html('<br/>密碼不可為空,最長128 Bytes');
- }else if(res == 'Enickname'){
- $('#register_error').html('暱稱不可為空或有非法字元<br/>最長16 Bytes');
- }else if(res == 'Eexist'){
- $('#register_error').html('使用者名稱已存在');
- }else{
- $('#register_error').html('Oops');
- }
- }
- );
-}
-
-function user_logout(){
- var cookie;
- var key;
-
- cookie = nor_getcookie();
- for(key in cookie){
- document.cookie = key + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
- }
-
- location.href = '/expoj/index.html?page=home';
-}
diff --git a/web/problem_code_submit.php b/web/problem_code_submit.php
deleted file mode 100644
index 2e7459a..0000000
--- a/web/problem_code_submit.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-require_once('common.php');
-
-$userid = $_COOKIE['userid'];
-$usersec = $_COOKIE['usersec'];
-$proid = $_POST['proid'];
-$code = $_POST['code'];
-
-if(!sec_checkuser($userid,$usersec)){
- exit('Euser');
-}
-if($proid == '' || strval(intval($proid)) != $proid){
- exit('Epro');
-}
-if(strlen($code) > (64 * 1024)){
- exit('Ecode');
-}
-
-$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
-$userid = pg_escape_string($userid);
-$sqlr = pg_query_params($sqlc,'SELECT * FROM "user" WHERE userid=$1 LIMIT 1;',
- array($userid));
-if(($usero = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- pg_close($sqlc);
- exit('Euser');
-}
-pg_free_result($sqlr);
-
-$mc = new Memcached();
-$mc->addServer('localhost',11211);
-if(!$mc->add('problem_code_submit_limit_'.$userid,true,10)){
- pg_close($sqlc);
- exit('Elimit');
-}
-
-$proid = pg_escape_string($proid);
-$sqlr = pg_query_params($sqlc,'SELECT * FROM "problem" WHERE proid=$1 LIMIT 1;',
- array($proid));
-if(($proo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- pg_close($sqlc);
- exit('Epro');
-}
-pg_free_result($sqlr);
-
-$sqlr = pg_query_params($sqlc,'INSERT INTO "submit" ("proid","userid","status","score","maxscore","runtime","peakmem") VALUES($1,$2,$3,$4,$5,$6,$7) RETURNING "submitid";',
- array($proid,$userid,'{100}','{0}','{0}','{0}','{0}'));
-$submitid = pg_fetch_row($sqlr)[0];
-pg_free_result($sqlr);
-
-file_put_contents('submit/'.$submitid.'_submit.cpp',$code);
-
-pg_close($sqlc);
-
-$sd = socket_create(AF_INET,SOCK_STREAM,0);
-socket_connect($sd,'127.0.0.1',2501);
-
-$data = $submitid.' '.$proid.chr(0);
-socket_write($sd,$data,strlen($data));
-
-socket_close($sd);
-
-echo 'S';
-?>
diff --git a/web/problem_view.php b/web/problem_view.php
deleted file mode 100644
index d53db88..0000000
--- a/web/problem_view.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-require_once('common.php');
-
-function problem_view($sqlc,$paramo){
- $proid = $paramo->proid;
- $infoonly = $paramo->infoonly;
-
- if(gettype($proid) != 'integer' || $proid < 1){
- return null;
- }
-
- $sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
- $proid = pg_escape_string($proid);
- $sqlr = pg_query_params($sqlc,'SELECT * FROM "problem" WHERE proid=$1 LIMIT 1;',
- array($proid));
- if(($proo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- return null;
- }
-
- if($infoonly){
- $proo = array(
- 'acceptcount' => $proo->acceptcount,
- 'submitcount' => $proo->submitcount);
- }else{
- $setting_info = parse_ini_file('pro/'.$proo->proid.'/'.$proo->proid.'_setting.txt',true);
- $proo = array(
- 'proid' => $proo->proid,
- 'proname' => $proo->proname,
- 'timelimit' => $setting_info['JUDGE']['timelimit'],
- 'memlimit' => $setting_info['JUDGE']['memlimit'],
- 'acceptcount' => $proo->acceptcount,
- 'submitcount' => $proo->submitcount,
- 'protext' => file_get_contents('pro/'.$proo->proid.'/'.$proo->proid.'_text.txt'));
- }
-
- pg_free_result($sqlr);
- return $proo;
-}
-?>
diff --git a/web/square_list.php b/web/square_list.php
deleted file mode 100644
index 7ac9188..0000000
--- a/web/square_list.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-require_once('common.php');
-
-function square_list($sqlc,$paramo){
- $userid = $_COOKIE['userid'];
- $usersec = $_COOKIE['usersec'];
- if(!sec_checkuser($userid,$usersec)){
- return null;
- }
-
- $userid = pg_escape_string($userid);
- $sqlr = pg_query_params($sqlc,'SELECT array_to_string("squarelist",\',\') AS "squarelist" FROM "user" WHERE "userid"=$1 LIMIT 1;',
- array($userid));
-
- if(($sqlo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- return null;
- }
- $squarelist = $sqlo->squarelist;
- pg_free_result($sqlr);
-
- $sqlr = pg_query($sqlc,'SELECT *,array_to_string("flag",\',\') AS "flag","starttime"<=now() AS "start","endtime"<=now() AS "end" FROM "square" WHERE "squareid" IN ('.$squarelist.') ORDER BY "squareid" ASC;');
- $inlist = array();
- while($squareo = pg_fetch_object($sqlr)){
- if($squareo->end == 't'){
- $status = 'inactive';
- }else if($squareo->start == 't'){
- $status = 'active';
- }else{
- $status = 'upcoming';
- }
- $flaglist = explode(',',$squareo->flag);
- $flag = array();
- for($idx = 0;$idx < count($flaglist);$idx++){
- $flag[$flaglist[$idx]] = true;
- }
-
- $inlist[] = array(
- 'squareid' => $squareo->squareid,
- 'squarename' => $squareo->squarename,
- 'starttime' => $squareo->starttime,
- 'endtime' => $squareo->endtime,
- 'status' => $status,
- 'flag' => $flag
- );
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query($sqlc,'SELECT *,array_to_string("flag",\',\') AS "flag","starttime"<=now() AS "start","endtime"<=now() AS "end" FROM "square" WHERE "squareid" NOT IN ('.$squarelist.') ORDER BY "squareid" ASC;');
- $outlist = array();
- while($squareo = pg_fetch_object($sqlr)){
- if($squareo->end == 't'){
- $status = 'inactive';
- }else if($squareo->start == 't'){
- $status = 'active';
- }else{
- $status = 'upcoming';
- }
- $flaglist = explode(',',$squareo->flag);
- $flag = array();
- for($idx = 0;$idx < count($flaglist);$idx++){
- $flag[$flaglist[$idx]] = true;
- }
-
- $outlist[] = array(
- 'squareid' => $squareo->squareid,
- 'squarename' => $squareo->squarename,
- 'starttime' => $squareo->starttime,
- 'endtime' => $squareo->endtime,
- 'status' => $status,
- 'flag' => $flag
- );
- }
- pg_free_result($sqlr);
-
- return array(
- 'inlist' => $inlist,
- 'outlist' => $outlist
- );
-}
-?>
diff --git a/web/square_problem_list.php b/web/square_problem_list.php
deleted file mode 100644
index 60d4268..0000000
--- a/web/square_problem_list.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-require_once('common.php');
-
-function square_problem_list($sqlc,$paramo){
- $userid = $_COOKIE['userid'];
- $usersec = $_COOKIE['usersec'];
- $squareid = $paramo->squareid;
- $prooff = $paramo->prooff;
-
- if(!sec_checkuser($userid,$usersec)){
- $userid = null;
- }
- if(gettype($squareid) != 'integer' || $squareid < 1){
- return null;
- }
- if(gettype($prooff) != 'integer' || $prooff < 0){
- return null;
- }
-
- $squaireid = pg_escape_string($squareid);
- $prooff = pg_escape_string($prooff);
- $sqlr = pg_query_params($sqlc,'SELECT * FROM "problem" WHERE $1 = ANY ("squarelist") ORDER BY "proid" LIMIT 20 OFFSET $2;',
- array($squareid,$prooff));
-
- $prolist = array();
- $proidlist = array();
- while($proo = pg_fetch_object($sqlr)){
- $prolist[] = array(
- 'proid' => $proo->proid,
- 'proname' => $proo->proname,
- 'acceptcount' => $proo->acceptcount,
- 'submitcount' => $proo->submitcount,
- 'sumscore' => null,
- 'summaxscore' => null);
- $proidlist[$proo->proid] = count($prolist) - 1;
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT COUNT(*) FROM "problem" WHERE $1 = ANY ("squarelist");',
- array($squareid));
- $procount = pg_fetch_row($sqlr)[0];
- pg_free_result($sqlr);
-
- if($userid){
- $userid = pg_escape_string($userid);
- $sqlr = pg_query_params($sqlc,'SELECT "proid","sumscore","summaxscore" FROM "submit" WHERE "userid"=$1 AND "proid" IN ('.implode(',',array_keys($proidlist)).') ORDER BY "sumscore" DESC;',
- array($userid));
-
- while($sqlo = pg_fetch_object($sqlr)){
- if($prolist[$proidlist[$sqlo->proid]]['sumscore'] == null){
- $prolist[$proidlist[$sqlo->proid]]['sumscore'] = $sqlo->sumscore;
- $prolist[$proidlist[$sqlo->proid]]['summaxscore'] = $sqlo->summaxscore;
- }
- }
- pg_free_result($sqlr);
- }
-
- return array(
- 'procount' => $procount,
- 'prolist' => $prolist
- );
-}
-?>
diff --git a/web/square_rank_list.php b/web/square_rank_list.php
deleted file mode 100644
index 01f3f45..0000000
--- a/web/square_rank_list.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-require_once('common.php');
-
-function ranklist_cmp($a,$b){
- if($a['acceptcount'] == $b['acceptcount']){
- if($a['submitcount'] == $b['submitcount']){
- return $a['userid'] - $b['userid'];
- }else{
- return $a['submitcount'] - $b['submitcount'];
- }
- }
- return $b['acceptcount'] - $a['acceptcount'];
-}
-
-function square_rank_list($sqlc,$paramo){
- $squareid = $paramo->squareid;
- $rankoff = $paramo->rankoff;
-
- if(gettype($squareid) != 'integer' || $squareid < 1){
- return null;
- }
- if(gettype($rankoff) != 'integer' || $rankoff < 0){
- return null;
- }
-
- $squareid = pg_escape_string($squareid);
- $sqlr = pg_query_params($sqlc,'SELECT * FROM "square" WHERE "squareid"=$1',
- array($squareid));
-
- if(($squareo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- return null;
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "proid" FROM "problem" WHERE $1=ANY("squarelist");',
- array($squareid));
-
- $proidlist = array();
- while($sqlo = pg_fetch_object($sqlr)){
- $proidlist[] = $sqlo->proid;
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "userid","nickname" FROM "user" WHERE $1=ANY("squarelist");',
- array($squareid));
-
- $useridlist = array();
- while($sqlo = pg_fetch_object($sqlr)){
- $useridlist[$sqlo->userid] = array(
- 'nickname' => $sqlo->nickname,
- 'acceptcount' => 0,
- 'submitcount' => 0,
- 'score' => 0);
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "userid" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') AND "result"=0 AND "timestamp">=$1 AND "timestamp"<$2 GROUP BY "proid","userid";',
- array($squareo->starttime,$squareo->endtime));
-
- while($sqlo = pg_fetch_object($sqlr)){
- if(array_key_exists($sqlo->userid,$useridlist)){
- $useridlist[$sqlo->userid]['acceptcount']++;
- }
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "userid",COUNT("userid") AS "submitcount" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') AND "timestamp">=$1 AND "timestamp"<$2 GROUP BY "userid";',
- array($squareo->starttime,$squareo->endtime));
-
- while($sqlo = pg_fetch_object($sqlr)){
- if(array_key_exists($sqlo->userid,$useridlist)){
- $useridlist[$sqlo->userid]['submitcount'] += $sqlo->submitcount;
- }
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "userid",MAX("sumscore") AS "score" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') AND "timestamp">=$1 AND "timestamp"<$2 GROUP BY "proid","userid";',
- array($squareo->starttime,$squareo->endtime));
-
- while($sqlo = pg_fetch_object($sqlr)){
- if(array_key_exists($sqlo->userid,$useridlist)){
- $useridlist[$sqlo->userid]['score'] += $sqlo->score;
- }
- }
- pg_free_result($sqlr);
-
- $ranklist = array();
- foreach($useridlist as $key => $value){
- $ranklist[] = array(
- 'userid' => $key,
- 'nickname' => $value['nickname'],
- 'acceptcount' => $value['acceptcount'],
- 'submitcount' => $value['submitcount'],
- 'score' => $value['score']);
- }
- usort($ranklist,'ranklist_cmp');
-
- $rank = 1;
- for($idx = 0;$idx < count($ranklist);$idx++){
- if($idx > 0){
- if($ranklist[$idx]['acceptcount'] != $ranklist[$idx - 1]['acceptcount'] ||
- $ranklist[$idx]['submitcount'] != $ranklist[$idx - 1]['submitcount']){
- $rank = $idx + 1;
- }
- }
- $ranklist[$idx]['rank'] = $rank;
- }
-
- return array(
- 'rankcount' => count($ranklist),
- 'ranklist' => array_slice($ranklist,$rankoff,20)
- );
-}
-?>
diff --git a/web/square_scoreboard_list.php b/web/square_scoreboard_list.php
deleted file mode 100644
index 6fdbf13..0000000
--- a/web/square_scoreboard_list.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-require_once('common.php');
-
-function scoreboardlist_cmp($a,$b){
- if($a['acceptcount'] == $b['acceptcount']){
- if($a['penalty'] == $b['penalty']){
- return $a['userid'] - $b['userid'];
- }else{
- return $a['penalty'] - $b['penalty'];
- }
- }
- return $b['acceptcount'] - $a['acceptcount'];
-}
-
-function square_scoreboard_list($sqlc,$paramo){
- $squareid = $paramo->squareid;
-
- if(gettype($squareid) != 'integer' || $squareid < 1){
- return null;
- }
-
- $squareid = pg_escape_string($squareid);
- $sqlr = pg_query_params($sqlc,'SELECT * FROM "square" WHERE "squareid"=$1',
- array($squareid));
-
- if(($squareo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- return null;
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "proid" FROM "problem" WHERE $1=ANY("squarelist") ORDER BY "proid";',
- array($squareid));
-
- $proidlist = array();
- while($sqlo = pg_fetch_object($sqlr)){
- $proidlist[] = $sqlo->proid;
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "userid","nickname" FROM "user" WHERE $1=ANY("squarelist");',
- array($squareid));
-
- $useridlist = array();
- while($sqlo = pg_fetch_object($sqlr)){
- $useridlist[$sqlo->userid] = array(
- 'nickname' => $sqlo->nickname,
- 'acceptcount' => 0,
- 'penalty' => 0,
- 'prolist' => array()
- );
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT "userid","proid",EXTRACT(EPOCH FROM age("timestamp",$1)) AS "time","result"=0 AS "accept" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') ORDER BY "timestamp";',
- array($squareo->starttime));
-
- while($sqlo = pg_fetch_object($sqlr)){
- if(!array_key_exists($sqlo->userid,$useridlist)){
- continue;
- }
-
- $userido = &$useridlist[$sqlo->userid];
- if(!array_key_exists($sqlo->proid,$userido['prolist'])){
- $userido['prolist'][$sqlo->proid] = array(
- 'accepttime' => null,
- 'submitcount' => 0,
- 'penalty' => 0
- );
- }
- $proo = &$userido['prolist'][$sqlo->proid];
-
- if($proo['accepttime'] == null){
- if($sqlo->accept == 't'){
- $proo['accepttime'] = intval($sqlo->time);
- $proo['submitcount']++;
- $proo['penalty'] = ($userido->submitcount - 1) * 1200 + $proo['accepttime'];
-
- $userido['acceptcount']++;
- $userido['penalty'] += $proo['penalty'];
- }else{
- $proo['submitcount']++;
- }
- }
- }
- pg_free_result($sqlr);
-
- $scoreboardlist = array();
- foreach($useridlist as $key => $value){
- $scoreboardlist[] = array(
- 'userid' => $key,
- 'nickname' => $value['nickname'],
- 'acceptcount' => $value['acceptcount'],
- 'penalty' => $value['penalty'],
- 'prolist' => $value['prolist']);
- }
- usort($scoreboardlist,'scoreboardlist_cmp');
-
- $rank = 1;
- for($idx = 0;$idx < count($scoreboardlist);$idx++){
- if($idx > 0){
- if($scoreboardlist[$idx]['acceptcount'] != $scoreboardlist[$idx - 1]['acceptcount'] ||
- $scoreboardlist[$idx]['penalty'] != $scoreboardlist[$idx - 1]['penalty']){
- $rank = $idx + 1;
- }
- }
- $scoreboardlist[$idx]['rank'] = $rank;
- }
-
- return array(
- 'proidlist' => $proidlist,
- 'scoreboardlist' => $scoreboardlist
- );
-}
-?>
diff --git a/web/status_submit_list.php b/web/status_submit_list.php
deleted file mode 100644
index 57bf003..0000000
--- a/web/status_submit_list.php
+++ /dev/null
@@ -1,147 +0,0 @@
-<?php
-require_once('common.php');
-
-function status_submit_list($sqlc,$paramo,$useronly){
- $submitoff = $paramo->submitoff;
- $submitid = $paramo->submitid;
- $proid = $paramo->proid;
- $result = $paramo->result;
-
- if($useronly == true){
- $userid = $_COOKIE['userid'];
- $usersec = $_COOKIE['usersec'];
- if(!sec_checkuser($userid,$usersec)){
- return null;
- }
- $userid = pg_escape_string($userid);
- }
- if(gettype($submitoff) != 'integer' || $submitoff < 0){
- $submitoff = -1;
- }
- if(gettype($submitid) != 'integer' || $submitid < 1){
- $submitid = -1;
- }
- if(gettype($proid) != 'integer' || $proid < 1){
- $proid = -1;
- }
- if(gettype($result) != 'integer'){
- $result = -100;
- }
- if($submitoff == -1 && $submitid == -1){
- return null;
- }
-
- $submitlist = array();
- $useridlist = array();
-
- if($submitoff != -1){
- $submitoff = pg_escape_string($submitoff);
- $sqlstr = 'SELECT "submitid","proid","userid","timestamp","result","sumscore","summaxscore","sumruntime" FROM "submit" ';
-
- if($useronly == true){
- $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "userid"=$1 ORDER BY "submitid" DESC LIMIT 20 OFFSET $2;',
- array($userid,$submitoff));
- }else if($proid != -1 && $result != -100){
- $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"=$2 ORDER BY "sumruntime" ASC LIMIT 20 OFFSET $3;',
- array($proid,$result,$submitoff));
- }else if($proid != -1 && $result == -100){
- $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"<>100 ORDER BY "submitid" DESC LIMIT 20 OFFSET $2;',
- array($proid,$submitoff));
- }else{
- $sqlr = pg_query_params($sqlc,$sqlstr.'ORDER BY "submitid" DESC LIMIT 20 OFFSET $1;',
- array($submitoff));
- }
-
- while($submito = pg_fetch_object($sqlr)){
- $submitlist[] = array(
- 'submitid' => $submito->submitid,
- 'proid' => $submito->proid,
- 'userid' => $submito->userid,
- 'timestamp' => $submito->timestamp,
- 'result' => $submito->result,
- 'sumscore' => $submito->sumscore,
- 'summaxscore' => $submito->summaxscore,
- 'sumruntime' => $submito->sumruntime);
- $useridlist[$submito->userid] = '';
- }
- pg_free_result($sqlr);
- }
-
- if($submitid != -1){
- $sqlstr = 'SELECT "submitid","proid","userid",array_to_string("status",\',\') AS "status",array_to_string("score",\',\') AS "score",array_to_string("maxscore",\',\') AS "maxscore",array_to_string("runtime",\',\') AS "runtime",array_to_string("peakmem",\',\') AS "peakmem","timestamp","result","sumscore","summaxscore","sumruntime" FROM "submit" ';
-
- if($submitid != 2147483647){
- $submitid = pg_escape_string($submitid);
- $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "submitid"=$1 LIMIT 1;',
- array($submitid));
- }else{
- if($useronly == true){
- $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "userid"=$1 ORDER BY "submitid" DESC LIMIT 1;',
- array($userid));
- }else if($proid != -1 && $result != -100){
- $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"=$2 ORDER BY "sumruntime" ASC LIMIT 1;',
- array($proid,$result));
- }else if($proid != -1 && $result == -100){
- $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"<>100 ORDER BY "submitid" DESC LIMIT 1;',
- array($proid));
- }else{
- $sqlr = pg_query($sqlc,$sqlstr.'ORDER BY "submitid" DESC LIMIT 1;');
- }
- }
-
- while($submito = pg_fetch_object($sqlr)){
- $submitlist[] = array(
- 'submitid' => $submito->submitid,
- 'proid' => $submito->proid,
- 'userid' => $submito->userid,
- 'status' => $submito->status,
- 'score' => $submito->score,
- 'maxscore' => $submito->maxscore,
- 'runtime' => $submito->runtime,
- 'peakmem' => $submito->peakmem,
- 'timestamp' => $submito->timestamp,
- 'result' => $submito->result,
- 'sumscore' => $submito->sumscore,
- 'summaxscore' => $submito->summaxscore,
- 'sumruntime' => $submito->sumruntime);
- $useridlist[$submito->userid] = '';
- }
- pg_free_result($sqlr);
- }else{
- $submitlist[] = null;
- }
-
- $sqlr = pg_query($sqlc,'SELECT "userid","nickname" FROM "user" WHERE "userid" IN ('.implode(',',array_keys($useridlist)).');');
-
- while($sqlo = pg_fetch_object($sqlr)){
- $useridlist[$sqlo->userid] = $sqlo->nickname;
- }
- pg_free_result($sqlr);
-
- for($idx = 0;$idx < count($submitlist);$idx++){
- if($submitlist[$idx] != null){
- $submitlist[$idx]['nickname'] = $useridlist[$submitlist[$idx]['userid']];
- }
- }
-
- if($useronly == true){
- $sqlr = pg_query_params('SELECT COUNT(*) FROM "submit" WHERE "userid"=$1;',
- array($userid));
- }else if($proid != -1 && $result != -100){
- $sqlr = pg_query_params('SELECT COUNT(*) FROM "submit" WHERE "proid"=$1 AND "result"=$2;',
- array($proid,$result));
- }else if($proid != -1 && $result == -100){
- $sqlr = pg_query_params('SELECT COUNT(*) FROM "submit" WHERE "proid"=$1 AND "result"<>100;',
- array($proid));
- }else{
- $sqlr = pg_query('SELECT COUNT(*) FROM "submit";');
- }
- $submitcount = pg_fetch_row($sqlr)[0];
- pg_free_result($sqlr);
-
- return array(
- 'submitcount' => $submitcount,
- 'submitlist' => $submitlist
- );
-}
-?>
diff --git a/web/status_viewcode.php b/web/status_viewcode.php
deleted file mode 100644
index 0bf1fb4..0000000
--- a/web/status_viewcode.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-require_once('common.php');
-
-$userid = $_COOKIE['userid'];
-$usersec = $_COOKIE['usersec'];
-$submitid = $_POST['submitid'];
-
-if(!sec_checkuser($userid,$usersec)){
- exit('Eerror');
-}
-if($submitid == '' || strval(intval($submitid)) != $submitid){
- exit('Eerror');
-}
-
-$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
-$userid = pg_escape_string($userid);
-$submitid = pg_escape_string($submitid);
-$sqlr = pg_query_params($sqlc,'SELECT "submitid" FROM "submit" WHERE "userid"=$1 AND "submitid"=$2 LIMIT 1',
- array($userid,$submitid));
-if(pg_num_rows($sqlr) == 0){
- pg_free_result($sqlr);
- pg_close($sqlc);
- exit('Eerror');
-}
-pg_free_result($sqlr);
-pg_close($sqlc);
-
-echo json_encode(['code' => file_get_contents('submit/'.$submitid.'_submit.cpp')]);
-?>
diff --git a/web/user_get.php b/web/user_get.php
deleted file mode 100644
index 85b0127..0000000
--- a/web/user_get.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-require_once('common.php');
-
-$userid = intval($_POST['userid']);
-
-if(gettype($userid) != 'integer' || $userid < 1){
- exit('Eerror');
-}
-
-$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
-$userid = pg_escape_string($userid);
-$sqlr = pg_query_params($sqlc,'SELECT * FROM "user" WHERE "userid"=$1 LIMIT 1;',
- array($userid));
-
-if(($usero = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- pg_close($sqlc);
- exit('Eerror');
-}
-pg_free_result($sqlr);
-
-$sqlr = pg_query_params($sqlc,'SELECT COUNT(DISTINCT "proid") FROM "submit" WHERE "userid"=$1 AND "result"=0;',
- array($userid));
-$acceptcount = pg_fetch_row($sqlr)[0];
-pg_free_result($sqlr);
-
-$sqlr = pg_query_params($sqlc,'SELECT COUNT(DISTINCT "proid") FROM "submit" WHERE "userid"=$1;',
- array($userid));
-$trycount = pg_fetch_row($sqlr)[0];
-pg_free_result($sqlr);
-
-$sqlr = pg_query_params($sqlc,'SELECT COUNT("proid") FROM "submit" WHERE "userid"=$1;',
- array($userid));
-$submitcount = pg_fetch_row($sqlr)[0];
-pg_free_result($sqlr);
-
-$userinfo = array(
- 'userid' => $usero->userid,
- 'username' => $usero->username,
- 'nickname' => $usero->nickname,
- 'headimg' => $usero->headimg,
- 'aboutme' => $usero->aboutme,
- 'acceptcount' => $acceptcount,
- 'submitcount' => $submitcount,
- 'trycount' => $trycount);
-
-$sqlr = pg_query_params($sqlc,'SELECT "proid",MAX("sumscore"/"summaxscore") AS "rate" FROM "submit" WHERE "userid"=$1 AND "result"<>100 GROUP BY "proid" ORDER BY "proid";',
- array($userid));
-
-$prolist = array();
-while($sqlo = pg_fetch_object($sqlr)){
- $prolist[] = array(
- 'proid' => $sqlo->proid,
- 'rate' => $sqlo->rate * 100);
-}
-pg_free_result($sqlr);
-
-pg_close($sqlc);
-
-echo json_encode(array(
- 'userinfo' => $userinfo,
- 'prolist' => $prolist
-));
-?>
diff --git a/web/user_login.php b/web/user_login.php
deleted file mode 100644
index 1f455c2..0000000
--- a/web/user_login.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-require_once('common.php');
-
-$username = $_POST['username'];
-$password = $_POST['password'];
-
-if($username == '' || strlen($username) > 16 || $username != pg_escape_string($username)){
- exit('Eerror');
-}
-if($password == '' || strlen($password) > 128){
- exit('Eerror');
-}
-
-$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
-$username = pg_escape_string($username);
-$password = hash('sha512',$password);
-$sqlr = pg_query_params($sqlc,'SELECT "userid" FROM "user" WHERE "username"=$1 AND "password"=$2 LIMIT 1;',
- array($username,$password));
-if(($sqlo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- pg_close($sqlc);
- exit('Eerror');
-}
-$userid = $sqlo->userid;
-pg_free_result($sqlr);
-pg_close($sqlc);
-
-setcookie('userid',$userid,time() + 31536000);
-setcookie('usersec',hash('sha512',$userid.SEC_SALT),time() + 31536000);
-echo 'S';
-?>
diff --git a/web/user_register.php b/web/user_register.php
deleted file mode 100644
index a728e64..0000000
--- a/web/user_register.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-require_once('common.php');
-
-$username = $_POST['username'];
-$password = $_POST['password'];
-$nickname = $_POST['nickname'];
-
-if($username == '' || strlen($username) > 16 || $username != pg_escape_string($username)){
- exit('Eusername');
-}
-if($password == '' || strlen($password) > 128){
- exit('Epassword');
-}
-if($nickname == '' || strlen($nickname) > 16 || $nickname != pg_escape_string($nickname)){
- exit('Enickname');
-}
-
-$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
-$username = pg_escape_string($username);
-$sqlr = pg_query_params($sqlc,'SELECT "username" FROM "user" WHERE "username"=$1 LIMIT 1;',
- array($username));
-if(pg_num_rows($sqlr) > 0){
- pg_free_result($sqlr);
- pg_close($sqlc);
- exit('Eexist');
-}
-pg_free_result($sqlr);
-
-$password = hash('sha512',$password);
-$sqlr = pg_query_params($sqlc,'INSERT INTO "user" ("username","password","nickname") VALUES($1,$2,$3) RETURNING "userid";',
- array($username,$password,$nickname));
-$userid = pg_fetch_row($sqlr)[0];
-pg_free_result($sqlr);
-
-pg_close($sqlc);
-
-setcookie('userid',$userid,time() + 31536000);
-setcookie('usersec',hash('sha512',$userid.SEC_SALT),time() + 31536000);
-echo 'S';
-?>
diff --git a/web/user_set.php b/web/user_set.php
deleted file mode 100644
index de5ea32..0000000
--- a/web/user_set.php
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-require_once('common.php');
-
-$userid = $_COOKIE['userid'];
-$usersec = $_COOKIE['usersec'];
-$type = $_POST['type'];
-
-if(!sec_checkuser($userid,$usersec)){
- exit('Euser');
-}
-$userid = pg_escape_string($userid);
-
-$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
-
-if($type == 'userinfo'){
- $nickname = $_POST['nickname'];
- $aboutme = $_POST['aboutme'];
- $headimg = $_POST['headimg'];
-
- if($nickname == '' || strlen($nickname) > 16 || $nickname != pg_escape_string($nickname)){
- exit('Enickname');
- }
- if(strlen($aboutme) > 4096){
- exit('Eaboutme');
- }
- if($headimg == '' || strlen($headimg) > 4096){
- exit('Eheadimg');
- }
-
- $sqlr = pg_query_params($sqlc,'UPDATE "user" SET "nickname"=$1,"aboutme"=$2,"headimg"=$3 WHERE "userid"=$4;',
- array($nickname,$aboutme,$headimg,$userid));
-
- pg_free_result($sqlr);
-}else if($type == 'squareadd'){
- $squareid = $_POST['squareid'];
-
- if($squareid == '' || strval(intval($squareid)) != $squareid){
- exit('Eerror');
- }
-
- $squareid = pg_escape_string($squareid);
- $sqlr = pg_query_params($sqlc,'SELECT "squareid" FROM "square" WHERE "squareid"=$1 LIMIT 1',
- array($squareid));
-
- if(pg_num_rows($sqlr) == 0){
- exit('Eerror');
- pg_free_result($sqlr);
- }
- pg_free_result($sqlr);
-
- $sqlr = pg_query_params($sqlc,'SELECT array_to_string("squarelist",\',\') AS "squarelist" FROM "user" WHERE "userid"=$1 LIMIT 1;',
- array($userid));
-
- if(($sqlo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- exit('Eerror');
- }
- $squarelist = explode(',',$sqlo->squarelist);
- pg_free_result($sqlr);
-
- for($idx = 0;$idx < count($squarelist);$idx++){
- if($squarelist[$idx] == $squareid){
- exit('Eerror');
- }
- }
- $squarelist[] = $squareid;
-
- $sqlr = pg_query_params($sqlc,'UPDATE "user" SET "squarelist"=\'{'.implode(',',$squarelist).'}\' WHERE "userid"=$1;',
- array($userid));
-
- pg_free_result($sqlr);
-}else if($type == 'squareremove'){
- $squareid = $_POST['squareid'];
-
- if($squareid == '' || strval(intval($squareid)) != $squareid){
- exit('Eerror');
- }
- if($squareid == '1'){
- exit('Ecant');
- }
-
- $sqlr = pg_query_params($sqlc,'SELECT array_to_string("squarelist",\',\') AS "squarelist" FROM "user" WHERE "userid"=$1 LIMIT 1;',
- array($userid));
-
- if(($sqlo = pg_fetch_object($sqlr)) == null){
- pg_free_result($sqlr);
- exit('Eerror');
- }
- $squarelist = explode(',',$sqlo->squarelist);
- pg_free_result($sqlr);
-
- for($idx = 0;$idx < count($squarelist);$idx++){
- if($squarelist[$idx] == $squareid){
- array_splice($squarelist,$idx,1);
- break;
- }
- }
-
- $sqlr = pg_query_params($sqlc,'UPDATE "user" SET "squarelist"=\'{'.implode(',',$squarelist).'}\' WHERE "userid"=$1;',
- array($userid));
-
- pg_free_result($sqlr);
-}else{
- exit('Eerror');
-}
-
-pg_close($sqlc);
-echo 'S';
-?>
diff --git a/web/viewcode.html b/web/viewcode.html
deleted file mode 100644
index bb39f9e..0000000
--- a/web/viewcode.html
+++ /dev/null
@@ -1,54 +0,0 @@
-<html>
-<head>
-<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
-
-<script type="text/javascript" src="http://codemirror.net/lib/codemirror.js"></script>
-<link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css">
-<link rel="stylesheet" href="http://codemirror.net/theme/lesser-dark.css">
-<script type="text/javascript" src="http://codemirror.net/mode/clike/clike.js"></script>
-
-<script type="text/javascript" src="nor.js"></script>
-<link rel=stylesheet type="text/css" href="nor.css">
-
-<script type="text/javascript">
-function init(){
- var submitid;
-
- submitid = nor_getparam().submitid;
-
- new Ajax.Request('status_viewcode.php',{
- method:'post',
- parameters:{'submitid':submitid},
- onSuccess:function(transport){
- var res;
- var code;
- var e_codemirror;
-
- res = transport.responseText;
- if(res[0] == 'E'){
- code = '錯誤';
- }else{
- code = JSON.parse(res).code;
- }
-
- e_codemirror = CodeMirror(document.body,{
- mode:'text/x-c++src',
- theme:'lesser-dark',
- lineNumbers:true,
- matchBrackets:true,
- indentUnit:4,
- value:code
- });
-
- e_codemirror.getWrapperElement().style.width = '100%';
- e_codemirror.getWrapperElement().style.height = '100%';
- e_codemirror.getScrollerElement().style.width = '100%';
- e_codemirror.getScrollerElement().style.height = '100%';
- }
- });
-}
-</script>
-</head>
-<body style="width:100%; height:100%; margin:0px 0px;" onload='init();'></body>
-</html>
-