diff options
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | mbbsd/admin.c | 88 | ||||
-rw-r--r-- | mbbsd/announce.c | 2 | ||||
-rw-r--r-- | mbbsd/mail.c | 19 | ||||
-rw-r--r-- | mbbsd/merge.c | 123 | ||||
-rw-r--r-- | mbbsd/record.c | 24 | ||||
-rw-r--r-- | mbbsd/user.c | 1 | ||||
-rw-r--r-- | util/merge_dir.c | 2 |
8 files changed, 195 insertions, 66 deletions
diff --git a/include/proto.h b/include/proto.h index 2096eb29..039530ba 100644 --- a/include/proto.h +++ b/include/proto.h @@ -24,6 +24,7 @@ void setup_man(boardheader_t * board); void delete_symbolic_link(boardheader_t *bh, int bid); int make_symbolic_link(char *bname, int gid); int make_symbolic_link_interactively(int gid); +void merge_dir(char *dir1, char *dir2); /* announce */ int a_menu(char *maintitle, char *path, int lastlevel); @@ -341,6 +342,7 @@ int Name_Menu(void); #ifdef MERGEBBS /* merge */ int m_fpg(void); +void m_fpg_brd(char *bname,char *fromdir); #endif /* more */ diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 96b65ccd..4a04dfef 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -32,8 +32,7 @@ m_loginmsg() int m_user() { - userec_t muser; - int id; + userec_t muser; int id; char genbuf[200]; stand_title("使用者設定"); @@ -266,6 +265,57 @@ void delete_symbolic_link(boardheader_t *bh, int bid) log_usies("DelLink", bh->brdname); } +int dir_cmp(const void *a, const void *b) +{ + return (atoi( &((fileheader_t *)a)->filename[2] ) - + atoi( &((fileheader_t *)b)->filename[2] )); +} + +void merge_dir(char *dir1, char *dir2) +{ + int i, pn, sn; + fileheader_t *fh; + char *p1, *p2, bakdir[128], file1[128], file2[128]; + strcpy(file1,dir1); + strcpy(file2,dir2); + if((p1=strrchr(file1,'/'))) + p1 ++; + else + p1 = file1; + if((p2=strrchr(file2,'/'))) + p2 ++; + else + p2 = file2; + + pn=get_num_records(dir1, sizeof(fileheader_t)); + sn=get_num_records(dir2, sizeof(fileheader_t)); + if(!sn) return; + fh= (fileheader_t *)malloc( (pn+sn)*sizeof(fileheader_t)); + get_records(dir1, fh, sizeof(fileheader_t), 1, pn); + get_records(dir2, fh+pn, sizeof(fileheader_t), 1, sn); + qsort(fh, pn+sn, sizeof(fileheader_t), dir_cmp); + sprintf(bakdir,"%s.bak", dir1); + Rename(dir1, bakdir); + for(i=1; i<pn+sn; i++ ) + { + if(!fh[i].title[0] || !fh[i].filename[0]) continue; + if( strcmp(fh[i-1].filename, fh[i].filename)) + { + fh[i-1].recommend =0; + append_record(dir1, &fh[i-1], sizeof(fileheader_t)); + strcpy(p1, fh[i].filename); + if(!dashd(file1)) + { + strcpy(p2, fh[i].filename); + Copy(file2, file1); + } + } + else + fh[i].filemode |= fh[i-1].filemode; + } + free(fh); +} + int m_mod_board(char *bname) { @@ -286,9 +336,9 @@ m_mod_board(char *bname) /* Ptt 這邊斷行會檔到下面 */ move(9, 0); snprintf(genbuf, sizeof(genbuf), "(E)設定 (V)違法/解除%s%s [Q]取消?", - HAS_PERM(PERM_SYSOP) ? " (B)BVote (S)救回文章 (G)賭盤解卡" : "", + HAS_PERM(PERM_SYSOP) ? " (B)Vote (S)救回 (C)合併 (G)賭盤解卡" : "", HAS_PERM(PERM_SYSSUBOP) ? " (D)刪除" : ""); - getdata(10, 0, genbuf, ans, sizeof(ans), LCECHO); + getdata(10, 0, genbuf, ans, 3, LCECHO); switch (*ans) { case 'g': @@ -307,6 +357,35 @@ m_mod_board(char *bname) system(genbuf); } break; + case 'c': + if (HAS_PERM(PERM_SYSOP)) { + char frombname[20], fromdir[256]; +#ifdef MERGEBBS + if(getans("是否匯入小魚看板? (y/N)")=='y') + { + setbdir(genbuf, bname); + m_fpg_brd(bname, fromdir); + if(!fromdir[0]) break; + } + else{ +#endif + generalnamecomplete(MSG_SELECT_BOARD, frombname, sizeof(frombname), + SHM->Bnumber, + completeboard_compar, + completeboard_permission, + completeboard_getname); + if (frombname[0] == '\0' || !getbnum(frombname) || + !strcmp(frombname,bname)) + break; + setbdir(genbuf, bname); + setbdir(fromdir, frombname); +#ifdef MERGEBBS + } +#endif + merge_dir(genbuf, fromdir); + touchbtotal(bid); + } + break; case 'b': if (HAS_PERM(PERM_SYSOP)) { char bvotebuf[10]; @@ -711,7 +790,6 @@ m_newbrd(int recover) getbcache(class_bid)->childcount = 0; pressanykey(); setup_man(&newboard); - outs("\n新板成立"); post_newboard(newboard.title, newboard.brdname, newboard.BM); log_usies("NewBoard", newboard.title); diff --git a/mbbsd/announce.c b/mbbsd/announce.c index 3d1e3d9d..a1fc9d41 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -303,7 +303,7 @@ a_newitem(menu_t * pm, int mode) a_additem(pm, &item); } -static void +void a_pasteitem(menu_t * pm, int mode) { char newpath[PATHLEN]; diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 06f61e7b..c1e70606 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -156,10 +156,10 @@ chkmailbox() mailsumlimit += cuser.exmailbox * 10; mailmaxkeep = max_keepmail + cuser.exmailbox; m_init(); - if ((mailkeep = get_num_records(currmaildir, sizeof(fileheader_t))) > - mailmaxkeep || - (mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > - mailsumlimit) { + if(!mailkeep)mailkeep=get_num_records(currmaildir,sizeof(fileheader_t)); + if(!mailsum)mailsum=get_sum_records(currmaildir, sizeof(fileheader_t)); + if (mailkeep > mailmaxkeep || + mailsum > mailsumlimit) { bell(); bell(); vmsg("您保存信件數目或容量 %d 超出上限 %d, 請整理", @@ -737,6 +737,7 @@ read_new_mail(fileheader_t * fptr) if (genbuf[0] == 'y') { unlink(fname); delmsgs[delcnt++] = idc; // FIXME 一次刪太多信 out of array boundary + mailsum = mailkeep = 0; } } clear(); @@ -831,6 +832,7 @@ mail_del(int ent, fileheader_t * fhdr, char *direct) if (!delete_record(direct, sizeof(*fhdr), ent)) { setdirpath(genbuf, direct, fhdr->filename); unlink(genbuf); + mailsum = mailkeep = 0; return DIRCHANGED; } } @@ -1115,18 +1117,15 @@ int mail_man() { char buf[64], buf1[64]; - if (HAS_PERM(PERM_MAILLIMIT)) { - int mode0 = currutmp->mode; - int stat0 = currstat; + int mode0 = currutmp->mode; + int stat0 = currstat; sethomeman(buf, cuser.userid); snprintf(buf1, sizeof(buf1), "%s 的信件夾", cuser.userid); - a_menu(buf1, buf, 1); + a_menu(buf1, buf, HAS_PERM(PERM_MAILLIMIT)); currutmp->mode = mode0; currstat = stat0; return FULLUPDATE; - } - return DONOTHING; } static int diff --git a/mbbsd/merge.c b/mbbsd/merge.c index 5494e3df..daa60cc0 100644 --- a/mbbsd/merge.c +++ b/mbbsd/merge.c @@ -8,7 +8,7 @@ int m_fpg() { - char genbuf[256], buf[1024], userid[25], passbuf[24]; + char genbuf[256], buf[256], userid[25], passbuf[24]; int count=0, i; FILE *fp; ACCT man; @@ -18,19 +18,22 @@ m_fpg() move(1,0); outs( - "此功\能是專門給各位資深花園使用者,\n" - "把自己的變為資深Ptt使用者,讓花園的使用者享有平等安全的環境.\n" - "直接按[Enter]離開.\n\n" - "特別叮嚀: \n" - " 為了帳號安全,您只有連續三次密碼錯誤的機會,請小心輸入.\n" - " 連續三次錯誤您的變身功\能就會被開罰單並直接通知站長.\n" - " 請不要在變身過程中不正常斷線, 刻意斷線變半獸人站長不負責唷."); + " 小魚的紫色花園,\n" + " 讓花園的使用者轉移個人資產以及重要信用資料, 享有平等安全的環境.\n" + " 如果您不需要, 請直接按[Enter]離開.\n" + " -----------------------------------------------------------------\n" + " 特別叮嚀:\n" + " 為了帳號安全,您只有連續三次密碼錯誤的機會,請小心輸入.\n" + " 連續三次錯誤您的變身功\能就會被開罰單並直接通知站長.\n" + " 請不要在變身過程中不正常斷線, 刻意斷線變半獸人站長不救唷.\n" + ); + if(search_ulistn(usernum,2)) - {vmsg("請不要multi-login時使用, 以免變身失敗"); return 0;} + {vmsg("請登出其他視窗, 以免變身失敗"); return 0;} do { - if(!getdata(8,0, "請小心輸入小魚的ID [英文大小寫要完全正確]:", userid, 20, + if(!getdata(10,0, " 小魚的ID [英文大小寫要完全正確]:", userid, 20, DOECHO)) return 0; if(bad_user_id(userid)) continue; sprintf(genbuf, "/home/bbs/fpg/home/%c/%s.ACT",userid[0], userid); @@ -44,7 +47,7 @@ m_fpg() }while(!count); count = 0; do{ - getdata(9,0, "請小心輸入您在小魚的密碼:", passbuf, sizeof(passbuf), + getdata(11,0, " 小魚的密碼:", passbuf, sizeof(passbuf), NOECHO); if(++count>=3) { @@ -66,34 +69,36 @@ m_fpg() } sprintf(buf,"%s.done",genbuf); rename(genbuf,buf); - move(10,0); + move(12,0); + clrtobot(); reload_money(); prints("您的花園幣有 %d 換算成 Ptt 幣為 %d (匯率 155:1), 匯入後共有 %d\n", man.money, man.money/155, cuser.money + man.money/155); demoney(man.money/155); - cuser.exmailbox += man.mailk; - prints("您的花園信相有 %d , 匯入後共有 %d\n", - man.mailk, cuser.exmailbox ); + cuser.exmailbox += (man.mailk + man.keepmail); + prints("您的花園信箱有 %d : %d, 匯入後共有 %d\n", + man.mailk, man.keepmail, cuser.exmailbox ); - if(cuser.firstlogin>man.firstlogin) d = man.firstlogin; + if(cuser.firstlogin > man.firstlogin) d = man.firstlogin; else d = cuser.firstlogin; - prints("花園註冊日期 %s 與此帳號 %s 比 將取 %s", - Cdate(&man.firstlogin), Cdate(&cuser.firstlogin), - Cdate(&d) ); + prints("花園註冊日期 %s 此帳號註冊日期 %s 將取 %s \n", + Cdatedate(&(man.firstlogin)), + Cdatedate(&(cuser.firstlogin)), + Cdatedate(&d) ); cuser.firstlogin = d; if(cuser.numlogins < man.numlogins) i = man.numlogins; else i = cuser.numlogins; - prints("花園進站次數 %d 與此帳號 %d 比 將取 %d", man.numlogins, + prints("花園進站次數 %d 此帳號 %d 將取 %d \n", man.numlogins, cuser.numlogins, i); cuser.numlogins = i; if(cuser.numposts < man.numposts ) i = man.numposts; else i = cuser.numposts; - prints("花園文章次數 %d 與此帳號 %d 比 將取 %d", man.numposts,cuser.numposts, + prints("花園文章次數 %d 此帳號 %d 將取 %d\n", man.numposts,cuser.numposts, i); cuser.numposts = i; while(search_ulistn(usernum,2)) @@ -101,28 +106,72 @@ m_fpg() passwd_update(usernum, &cuser); sethomeman(genbuf, cuser.userid); mkdir(genbuf, 0600); - sprintf(buf, "cd home/bbs/fpg/tmp; tar zxvf ../home/%c/%s.tgz" - "cd home/bbs/home/%c; mv %s ../../../..;" - "cd ../../../../%s; ", - userid[0], userid, userid[0], userid, userid); - i = 0; - if (getans("是否匯入個人信箱以及信箱精華區? (Y/n)")!='n') + sprintf(buf, "tar zxvf home/%c/%s.tgz>/dev/null", + userid[0], userid); + chdir("fpg"); + system(buf); + chdir(BBSHOME); + + if (getans("是否匯入個人信箱? (Y/n)")!='n') + { + sethomedir(buf, cuser.userid); + sprintf(genbuf, "fpg/home/bbs/home/%c/%s/.DIR", + userid[0], userid); + merge_dir(buf, genbuf); + } + if(getans("是否匯入個人信箱精華區? (Y/n)")!='n') { - sprintf(genbuf, - "mv M.* /home/bbs/home/%c/%s;" - "mv man/* /home/bbs/home/%c/%s/man;", cuser.userid[0], cuser.userid, + sprintf(buf, + "mv fpg/home/bbs/home/%c/%s/man home/%c/%s/man", + userid[0], userid, cuser.userid[0], cuser.userid); - strcat(buf,genbuf); - i++; + system(buf); } - if (getans("是否匯入好友名單? (會覆蓋\現有設定, ID可能是不同人)? (y/N)")=='y') + if(getans("是否匯入好友名單? (會覆蓋\現有設定, ID可能是不同人)? (y/N)")=='y') { - sprintf(genbuf,"mv overrides /home/bbs/home/%c/%s; ", - cuser.userid[0], cuser.userid); + sethomefile(genbuf, cuser.userid, "overrides"); + sprintf(buf, "fpg/home/bbs/home/%c/%s/overrides",userid[0],userid); + Copy(buf, genbuf); strcat(buf, genbuf); - i++; + friend_load(FRIEND_OVERRIDE); } - if(i) system(buf); vmsg("恭喜您完成帳號變身.."); return 0; } + +void +m_fpg_brd(char *bname, char *fromdir) +{ + char fbname[25], buf[256]; + fileheader_t fh; + + fromdir[0]=0; + do{ + + if(!getdata(20,0, "小魚的板名 [英文大小寫要完全正確]:", fbname, 20, + DOECHO)) return; + } + while(invalid_brdname(fbname)); + + sprintf(buf, "fpg/boards/%s.inf", fbname); + if(!dashf(buf)) + { + vmsg("無此看板"); + return; + } + chdir("fpg"); + sprintf(buf, "tar zxf boards/%s.tgz >/dev/null",fbname); + system(buf); + sprintf(buf, "tar zxf boards/%s.man.tgz >/dev/null", fbname); + system(buf); + chdir(BBSHOME); + sprintf(buf, "mv fpg/home/bbs/man/boards/%s man/boards/%c/%s", fbname, + bname[0], bname); + system(buf); + sprintf(fh.title, "%s 精華區", fbname); + sprintf(fh.filename, fbname); + sprintf(fh.owner, cuser.userid); + sprintf(buf, "man/boards/%c/%s/.DIR", bname[0], bname); + append_record(buf, &fh, sizeof(fh)); + vmsg("匯入成功\ 精華區請link %s",fbname); +} diff --git a/mbbsd/record.c b/mbbsd/record.c index c8393f6f..2903ab2b 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -36,24 +36,25 @@ get_sum_records(char *fpath, int size) { struct stat st; long ans = 0; - FILE *fp; + int fp; fileheader_t fhdr; char buf[200], *p; - - if (!(fp = fopen(fpath, "r"))) + + // Ptt : should avoid big loop + if ((fp = open(fpath, O_RDONLY))) return -1; - + strlcpy(buf, fpath, sizeof(buf)); p = strrchr(buf, '/'); assert(p); p++; - while (fread(&fhdr, size, 1, fp) == 1) { + while (read(fp, &fhdr, size) == size) { strcpy(p, fhdr.filename); if (stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) ans += st.st_size; } - fclose(fp); + close(fp); return ans / 1024; } @@ -425,17 +426,16 @@ safe_article_delete_range(char *direct, int from, int to) int apply_record(char *fpath, int (*fptr) (), int size){ char abuf[BUFSIZE]; - FILE *fp; + int fp; - if (!(fp = fopen(fpath, "r"))) - return -1; + if((fp=open(fpath, O_RDONLY, 0))) return -1; - while (fread(abuf, 1, size, fp) == (size_t)size) + while (read(fp, abuf, size) == (size_t)size) if ((*fptr) (abuf) == QUIT) { - fclose(fp); + close(fp); return QUIT; } - fclose(fp); + close(fp); return 0; } diff --git a/mbbsd/user.c b/mbbsd/user.c index 12fe24e4..b9f459ae 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1589,3 +1589,4 @@ u_list() igetch(); return 0; } + diff --git a/util/merge_dir.c b/util/merge_dir.c index 304f0927..b2044050 100644 --- a/util/merge_dir.c +++ b/util/merge_dir.c @@ -12,7 +12,7 @@ fileheader_t *fh; int dir_cmp(const void *a, const void *b) { return (atoi( &((fileheader_t *)a)->filename[2] ) - - atoi( &((fileheader_t *)a)->filename[2] )); + atoi( &((fileheader_t *)b)->filename[2] )); } int main(int argc, char **argv) { |