void dumpclass(int gid) { boardheader_t *bptr; int bid; bptr = getbcache(gid); if (bptr->firstchild[0] == 0 || bptr->childcount <= 0) load_uidofgid(gid, 0); printf("$db{'class.%d'} = $serializer->serialize([", gid); for( bid = bptr->firstchild[0] ; bid > 0 ; bid = bptr->next[0] ) { bptr = getbcache(bid); if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && (bptr->level & ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) ) continue; printf("%5d,\t", bid); parent[bid] = gid; } printf("]);\n"); bptr = getbcache(gid); for( bid = bptr->firstchild[0] ; bid > 0 ; bid = bptr->next[0] ) { bptr = getbcache(bid); if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && (bptr->level & ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) ) continue; if( bptr->brdattr & BRD_GROUPBOARD ) dumpclass(bid); } }
void dumpclass(int gid) { boardheader_t *bptr; int bid; const int type = BRD_GROUP_LL_TYPE_NAME; bptr = getbcache(gid); if (bptr->firstchild[type] == 0 || bptr->childcount <= 0) resolve_board_group(gid, type); printf("$db{'class.%d'} = $serializer->serialize([", gid); for( bid = bptr->firstchild[type] ; bid > 0 ; bid = bptr->next[type] ) { bptr = getbcache(bid); if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && (bptr->level & ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) ) continue; printf("%5d,\t", bid); parent[bid] = gid; } printf("]);\n"); bptr = getbcache(gid); for( bid = bptr->firstchild[type] ; bid > 0 ; bid = bptr->next[type] ) { bptr = getbcache(bid); if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && (bptr->level & ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) ) continue; if( bptr->brdattr & BRD_GROUPBOARD ) dumpclass(bid); } }
static void load_GoodBrd() //´ÓÎļþÖлñÈ¡¶©ÔÄ°æÃ棬Ìî³äÊý¾Ý½á¹¹ GoodBrd { char buf[STRLEN]; FILE *fp; GoodBrd.num = 0; setuserfile(buf, ".goodbrd"); if ((fp = fopen(buf, "r"))) { for (GoodBrd.num = 0; GoodBrd.num < GOOD_BRC_NUM;) { if (!fgets(buf, sizeof (buf), fp)) break; strsncpy(GoodBrd.ID[GoodBrd.num], strtrim(buf), sizeof (GoodBrd.ID[GoodBrd.num])); if (canberead(GoodBrd.ID[GoodBrd.num])) GoodBrd.num++; } fclose(fp); } if (GoodBrd.num == 0) { GoodBrd.num++; if (getbcache(DEFAULTBOARD)) strcpy(GoodBrd.ID[0], DEFAULTBOARD); else strcpy(GoodBrd.ID[0], currboard); } }
int main(int argc, char ** argv) { int all = 0; struct boardheader *bp; struct userec* sysopuser; if (init_all()) { printf("init data fail\n"); return -1; } getuser("SYSOP", &sysopuser); setCurrentUser(sysopuser); if (argc == 1) all = 1; else if (argc > 2) { printf("Usage: %s [boardid]\n", argv[0]); return -1; } if (all == 1) { apply_boards(cnv_board_dir,NULL); } else { if ((bp = getbcache(argv[1])) != NULL) cnv_board_dir(bp,NULL); } return 0; }
void setaidfile(char *buf, const char *bn, aidu_t aidu) { // try to load by AID int bid = 0; int n = 0, fd = 0; char bfpath[PATHLEN]; boardheader_t *bh = NULL; fileheader_t fh; buf[0] = 0; bid = getbnum(bn); if (bid <= 0) return; assert(0<=bid-1 && bid-1<MAX_BOARD); bh = getbcache(bid); if (!HasBoardPerm(bh)) return; setbfile(bfpath, bh->brdname, FN_DIR); n = search_aidu(bfpath, aidu); if (n < 0) return; fd = open(bfpath, O_RDONLY); if (fd < 0) return; lseek(fd, n*sizeof(fileheader_t), SEEK_SET); memset(&fh, 0, sizeof(fh)); if (read(fd, &fh, sizeof(fh)) > 0) { setbfile(buf, bh->brdname, fh.filename); if (!dashf(buf)) buf[0] = 0; } close(fd); }
void gen_board_rank_xml() { int i; FILE *fp; char xmlfile[STRLEN]; char xml_buf[256]; char url_buf[256]; const struct boardheader *bp; int sec_id; snprintf(xmlfile, sizeof(xmlfile), BBSHOME "/xml/board.xml"); if ((fp = fopen(xmlfile, "w")) == NULL) return; fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n"); fprintf(fp, "<BoardList Desc=\"%s\">\n",encode_url(url_buf,"讨论区使用状况统计",sizeof(url_buf))); for (i = 0; i < n; i++) { bp = getbcache(x[i].filename); if (bp == NULL || (bp->flag & BOARD_GROUP)) continue; if ((sec_id = get_seccode_index(bp->title[0])) < 0) continue; fprintf(fp, "<Board>\n"); fprintf(fp, "<EnglishName>%s</EnglishName>\n", encode_url(url_buf,encode_xml(xml_buf, x[i].filename, sizeof(xml_buf)),sizeof(url_buf))); fprintf(fp, "<ChineseName>%s</ChineseName>\n", encode_url(url_buf,encode_xml(xml_buf, x[i].title, sizeof(xml_buf)),sizeof(url_buf))); fprintf(fp, "<Online>%d</Online>\n", x[i].online); fprintf(fp, "<Articles>%d</Articles>\n", x[i].nowid-x[i].yesid); fprintf(fp, "<SecId>%d</SecId>\n", sec_id); fprintf(fp, "</Board>\n"); } fprintf(fp, "</BoardList>\n"); fclose(fp); }
int main() { FILE *fp; char board[80], dir[80], *ptr, flag[80]; struct shortfile *x1; struct fileheader x; int i, start, total, my_t_lines=0, chart=0, showhead=0; init_all(); strsncpy(board, getparm("board"), 32); my_t_lines=atoi(getparm("my_t_lines")); if(my_t_lines<10 || my_t_lines>40) my_t_lines=20; x1=getbcache(board); if(x1==0) http_fatal("错误的讨论区"); strcpy(board, x1->filename); board_ban_ip(board); if (!canenterboard (currentuser.userid, board) && !HAS_PERM(PERM_SYSOP)) http_fatal ("您已经被取消进入本板的权限"); if(!has_read_perm(¤tuser, board) && !HAS_PERM(PERM_SYSOP)) http_fatal("错误的讨论区"); if(!has_BM_perm(¤tuser, board)) http_fatal("您没有权限访问本页"); modify_mode(u_info,READING); //bluetent sprintf(dir, "boards/%s/.DIR", board); fp=fopen(dir, "r"); if(fp==0) http_fatal("错误的讨论区目录"); total=file_size(dir)/sizeof(struct fileheader); start=atoi(getparm("start")); if(strlen(getparm("start"))==0 || start>total-my_t_lines) start=total-my_t_lines; if(start<0) start=0; printf("<nobr><center>\n"); strcpy(u_info->board, board); /* printf("%s -- [讨论区: %s] 板主[%s] 文章数[%d]<hr color=green>\n", BBSNAME, board, userid_str(x1->BM), total); if(total<=0) http_fatal("本讨论区目前没有文章"); printf("<form name=form1 method=post action=bbsman>\n"); printf("<table width=613>\n"); printf("<tr><td>序号<td>管理<td>状态<td>作者<td>日期<td>标题\n"); fseek(fp, start*sizeof(struct fileheader), SEEK_SET);*/ printf("<script language=JavaScript>\ \ function MM_jumpMenu(selObj){\ eval(\"window.location='\"+selObj.options[selObj.selectedIndex].value+\"'\");\ }\ function SubmitFlag(flagmode){\ document.form1.mode.value=flagmode;\ document.form1.submit();\ }\ function selrange(x)\ {if(event.shiftKey){var min=x;var max=document.getElementById('lastsel').value;if(min>max){var tmp=min;min=max;max=tmp;}var stt=document.getElementById('chk'+x).checked;for(var i=min;i<=max;i++)document.getElementById('chk'+i).checked=stt;}document.getElementById('lastsel').value=x;}\ </script>\
/* * Get an announce path from a board name. */ int ann_get_path(char *board, char *path, size_t len) { const struct boardheader* bh; if ((bh=getbcache(board))!=NULL) { if (strlen(bh->ann_path)+strlen("/groups")>len) return -1; sprintf(path,"/groups/%s",bh->ann_path); return 0; } return -1; }
int testboard(char *board) { struct boardmem *x; x = getbcache(board); if (x && !(x->header.flag & CLOSECLUB_FLAG) && !x->header.level) { strsncpy(board, x->header.filename, 32); return 0; } return -1; }
int updatelastpost(char *board) { struct boardmem *bptr; if (shm_bcache == NULL) shm_init(); bptr = getbcache(board); if (bptr == NULL) return -1; return getlastpost(bptr->header.filename, &bptr->lastpost, &bptr->total); }
int TagPruner(int bid) { boardheader_t *bp=NULL; char direct[PATHLEN]; assert(bid >= 0); /* bid == 0 means in mailbox */ if (bid && currstat != RMAIL) { bp = getbcache(bid); if (is_readonly_board(bp->brdname)) return DONOTHING; setbdir(direct, bp->brdname); } else if(currstat == RMAIL) { sethomedir(direct, cuser.userid); } else { vmsg("抱歉,程式異常 - 請至 " BN_BUGREPORT " 報告您剛的詳細步驟。"); return FULLUPDATE; } if (IsEmptyTagList() || (currstat == READING && !(currmode & MODE_BOARD))) return DONOTHING; if (vans("刪除所有標記[N]?") != 'y') return READ_REDRAW; // ready to start. outmsg("處理中,請稍後..."); refresh(); // first, delete and backup all files apply_record(direct, _iter_delete_tagged, sizeof(fileheader_t), direct); // now, delete the header #ifdef SAFE_ARTICLE_DELETE if(bp && !(currmode & MODE_DIGEST) && bp->nuser >= SAFE_ARTICLE_DELETE_NUSER) safe_delete_range(currdirect, 0, 0); else #endif delete_range(currdirect, 0, 0); TagNum = 0; if (bid) setbtotal(bid); else if(currstat == RMAIL) setupmailusage(); return NEWDIRECT; }
int bbsclear_main(void) { if (!loginok) return BBS_ELGNREQ; const char *board = getparm("board"); struct boardheader *bp = getbcache(board); if (bp == NULL || !hasreadperm(¤tuser, bp)) return BBS_ENOBRD; const char *start = getparm("start"); brc_fcgi_init(currentuser.userid, board); brc_clear(NA, NULL, YEA); brc_update(currentuser.userid, board); char buf[STRLEN]; snprintf(buf, sizeof(buf), "doc?board=%s&start=%s", board, start); http_header(); refreshto(0, buf); printf("</head></html>"); return 0; }
int main(int argc, char **argv) { int ch, allboards = 0, i; boardheader_t *bptr; while( (ch = getopt(argc, argv, "ah")) != -1 ) switch( ch ){ case 'a': allboards = 1; break; case 'h': usage(); return 0; } chdir(BBSHOME); attach_SHM(); argc -= optind; argv += optind; now = time(NULL); if( allboards ){ for( i = 0 ; i < MAX_BOARD ; ++i ){ bptr = &bcache[i]; if( bptr->brdname[0] && !(bptr->brdattr & (BRD_TOP | BRD_GROUPBOARD)) && bptr->brdattr & BRD_HIDE ) chkhbf(bptr); } } else if( argc > 0 ){ int bid; for( i = 0 ; i < argc ; ++i ) if( (bid = getbnum(argv[i])) != 0 ) // XXX: bid start 1 chkhbf(getbcache(bid)); else fprintf(stderr, "%s not found\n", argv[i]); } else usage(); return 0; }
static void save_GoodBrd() // ±£´æÓû§¶©ÔĵİæÃæ { int i; FILE *fp; char fname[STRLEN]; if (GoodBrd.num <= 0) { GoodBrd.num = 1; if (getbcache(DEFAULTBOARD)) strcpy(GoodBrd.ID[0], DEFAULTBOARD); else strcpy(GoodBrd.ID[0], currboard); } setuserfile(fname, ".goodbrd"); if ((fp = fopen(fname, "wb+")) != NULL) { for (i = 0; i < GoodBrd.num; i++) fprintf(fp, "%s\n", GoodBrd.ID[i]); fclose(fp); } }
static int a_pastetagpost(menu_t * pm, int mode) { boardheader_t *bh = NULL; char dirname[PATHLEN]; _iter_paste_tag_param param = {0}; param.pm = pm; param.mode = mode; if (TagBoard == 0){ sethomedir(dirname, cuser.userid); } else{ bh = getbcache(TagBoard); setbdir(dirname, bh->brdname); param.bh = bh; } // prevent if anything wrong if (TagNum > MAXTAGS || TagNum < 0) { vmsg("內部錯誤。請把你剛剛進行的完整步驟貼到 " BN_BUGREPORT " 板。"); return 0; } if (IsEmptyTagList()) return 0; /* since we use different tag features, * copyqueue is not required/used. */ copyqueue_reset(); apply_record(dirname, _iter_paste_tag, sizeof(fileheader_t), ¶m); TagNum = 0; return param.copied; }
//struct file_to_appendix a; int main() { FILE *fp; char filename[80], dir[80], board[80], title[80], buf[80], *content, vfrom[80]; char tmpbuf [5], title2 [10]; char redirfile[80]; int r, i=0, length=0, sig, mode=0, accessed=0; struct fileheader x; struct shortfile *brd; init_all(); if(!loginok) http_fatal("匆匆过客不能发表文章,请先登录"); mode=atoi(getparm("mode")); if(mode) strsncpy(redirfile, getparm("redir"), 20); strsncpy(board, getparm("board"), 18); strsncpy(vfrom, getparm("vfrom"), 18); if (!*vfrom) { strcpy(vfrom, board); } if(dashf("NOPOST")&&!HAS_PERM(PERM_OBOARDS) && insec(1,board) ) http_fatal("对不起,系统进入只读状态,暂停发表文章.你先四处看看吧"); /* efan: very faint */ if (dashf ("NOPOST.2") && ! HAS_PERM (PERM_OBOARDS) && ( !strcmp (board, "VoiceofNankai") || !strcmp (board, "Military") || !strcmp (board, "TaiWan") || !strcmp (board, "Salon")) ) http_fatal("对不起,本板进入只读状态,暂停发表文章"); if(!(currentuser.userlevel & PERM_POST)&&strcmp(board, "appeal")&&strcmp(board, "sysop")) http_fatal("您尚未通过注册,暂无发表文章权限"); if(check_post_limit(board)) return 0; strsncpy(title, getparm("title"), 50); strsncpy (tmpbuf, getparm ("title2"), 5); if (tmpbuf [0] != 0) sprintf (title2, "【%s】", tmpbuf); else title2[0] = 0; content=getparm("text"); brd=getbcache(board); /* add by wzk for outgo post */ //out=strlen(getparm("out")); //if (!(brd->flag & OUT_FLAG)) out=0; /* end */ if(brd==0) http_fatal("错误的讨论区名称"); strcpy(board, brd->filename); //huangxu@070217:no_word_filter flag int bd=0; char temp[80]; if(!(brd->flag2&NOFILTER_FLAG)&&(bad_words(title) || bad_words (tmpbuf) || bad_words(content) )){ bd=1; printf("您的文章可能包含不便显示的内容,已经提交审核。请返回并进行修改。"); sprintf(temp,"TEMP-%s",board); strcpy(board,"TEMP"); }else strcpy(temp,board); for(i=0; i<strlen(title); i++) if(title[i]<=27 && title[i]>=-1) title[i]=' '; sig=atoi(getparm("signature")); if(title[0]==0) http_fatal("文章必须要有标题"); if (title2 [0] == 0 && !strcmp (board, "Secondhand")) http_fatal ("在Secondhand板请说清楚您的需要!"); if (tmpbuf [0] != ' ') { char tmptmpbuf [80]; sprintf (tmptmpbuf, "%s%s", title2, title); strcpy (title, tmptmpbuf); } sprintf(dir, "boards/%s/.DIR", board); if(bd==0) if(!has_post_perm(¤tuser, board)) http_fatal("此讨论区是唯读的, 或是您尚无权限在此发表文章."); sprintf(filename, "boards/%s/deny_users", board); if(file_has_word(filename, currentuser.userid)) http_fatal("很抱歉, 你被板务人员停止了本板的post权利."); if(abs(time(0) - *(int*)(u_info->from+36))<6) { *(int*)(u_info->from+36)=time(0); http_fatal("两次发文间隔过密, 请休息几秒后再试"); } *(int*)(u_info->from+36)=time(0); sprintf(filename, "tmp/%d.%s.tmp", getpid(),currentuser.userid); f_append(filename, content); accessed=0; if(strlen(getparm("noreply"))>0) accessed=FILE_NOREPLY; int outgo=0; if(strlen(getparm("outgo"))>0) outgo=1; int attach=atoi(getparm("attach")); r=0; r=post_article2(temp, title, filename, currentuser.userid, currentuser.username, fromhost, sig-1, accessed, attach,outgo); if(r<=0) http_fatal("内部错误,无法发文"); char path[STRLEN]; /* while( appendix != NULL ) { bzero(&a,sizeof(struct appendix)); strcpy(a.appendixname,appendix); a.filename=r; a.sign=0; strcpy(a.path,board); sprintf(path,"%s/file_appendix",UPLOAD_PATH); append_record(&a,sizeof(struct appendix),path); appendix = strtok( NULL, "," ); } */ sprintf(buf,"M.%d.A",r); brc_init(currentuser.userid, board); brc_add_read(buf); brc_update(currentuser.userid, board); unlink(filename); sprintf(buf, "posted WWW '%s' on '%s'", title, board); report(buf); if(mode==0) sprintf(buf, "bbsdoc?board=%s#bottom", vfrom); else if(mode==1) sprintf(buf, "bbstcon?board=%s&file=%s&vfrom=%s#bottom", board, redirfile, vfrom); else if(mode==2) sprintf(buf, "bbstdoc?board=%s#bottom", vfrom); if(!junkboard(board)) { currentuser.numposts++; save_user_data(¤tuser); // write_posts(currentuser.userid, board, title); } if(toptenboard(board)) { write_posts(currentuser.userid, board, title); } else if(!strcmp("Blessing",board)) write_posts(currentuser.userid, board, title); // return 0; if(bd==0) redirect(buf); }
int main(int argc, char **argv) { chdir(BBSHOME); #undef time bbssettime(time(0)); sleep(1); resolve_boards(); load_ucache(); if (argc == 2 && strcmp(argv[1], "--all") == 0) { printf("Transfering Board....\n"); apply_boards(strip_board, NULL); printf("Transfering user mail....\n"); apply_users(strip_mail, NULL); } else if (argc == 2 && strcmp(argv[1], "--mail") == 0) { apply_users(strip_mail, NULL); } else if (argc == 2 && strcmp(argv[1], "--board") == 0) { apply_boards(strip_board, NULL); } else if (argc == 2 && strcmp(argv[1], "--rollback") == 0) { //apply_boards(rollback_board, NULL); apply_users(rollback_mail, NULL); } else if (argc == 3 && strcmp(argv[1], "-b") == 0) { struct boardheader *bh; if ((bh = getbcache(argv[2])) == NULL) { fprintf(stderr, "Board <%s> not found!\n", argv[2]); exit(-1); } strip_board(bh, NULL); } else if (argc == 3 && strcmp(argv[1], "-m") == 0) { struct userec *user; if (!getuser(argv[2], &user)) { fprintf(stderr, "User <%s> not found!\n", argv[2]); exit(-1); } strip_mail(user, NULL); } else if (argc == 3 && strcmp(argv[1], "--rollback-board") == 0) { struct boardheader *bh; if ((bh = getbcache(argv[2])) == NULL) { fprintf(stderr, "Board <%s> not found!\n", argv[2]); exit(-1); } rollback_board(bh, NULL); } else if (argc == 3 && strcmp(argv[1], "--rollback-mail") == 0) { struct userec *user; if (!getuser(argv[2], &user)) { fprintf(stderr, "User <%s> not found!\n", argv[2]); exit(-1); } rollback_mail(user, NULL); } else { fprintf(stderr, "Usage:\n", argv[0]); fprintf(stderr, " %s --all Strip all fileheaders.\n", argv[0]); fprintf(stderr, " %s --mail Strip mail fileheaders.\n", argv[0]); fprintf(stderr, " %s --board Strip board fileheaders.\n", argv[0]); fprintf(stderr, " %s --rollback Rollback all fileheaders.\n", argv[0]); fprintf(stderr, " %s -b board Strip fileheaders of a board.\n", argv[0]); fprintf(stderr, " %s -m user Strip fileheaders of a user's mailbox.\n", argv[0]); fprintf(stderr, " %s --rollback-board board Rollback fileheaders of a board.\n", argv[0]); fprintf(stderr, " %s --rollback-mail user Rollback fileheaders of a user's mailbox.\n", argv[0]); exit(-1); } return 0; }
/*********** 根据type得到十大列表,已经经过排序等一系列检查,可以直接输出 type!=4的时候还得到分区十大 *******/ int get_top(int type) { MYSQL s; MYSQL_RES *res; MYSQL_ROW row; char sqlbuf[500]; char cmptime[200]; int start=0; int i,secid; int threadid; char title[81]; char userid[IDLEN+1]; int m,n; #ifdef BLESS_BOARD const struct boardheader *bh; #endif topnum = 0; if(type < 0 || type > 4) return 0; mysql_init (&s); if (! my_connect_mysql(&s) ){ return 0;; } if(type==0 || type==4){ //sprintf(cmptime,"YEAR(time)=YEAR(CURDATE()) AND MONTH(time)=MONTH(CURDATE()) AND DAYOFMONTH(time)=DAYOFMONTH(CURDATE())"); sprintf(cmptime,"time>curdate()"); }else if(type==1){ sprintf(cmptime,"YEAR(date)=YEAR(CURDATE()) AND WEEK(date)=WEEK(CURDATE())"); }else if(type==2){ sprintf(cmptime,"YEAR(date)=YEAR(CURDATE()) AND MONTH(date)=MONTH(CURDATE())"); }else if(type==3){ sprintf(cmptime,"YEAR(date)=YEAR(CURDATE())"); } bzero(top, TOPCOUNT * sizeof(struct postrec)); bzero(sectop, SECNUM * SECTOPCOUNT * sizeof(struct postrec)); for(i=0;i<SECNUM;i++) sectopnum[i]=0; sectopnumtotal=0; while(1){ if(type==4){ if(topnum>=mytop[type]) break; }else if(type==0){ if(topnum>=mytop[type] && sectopnumtotal>=SECNUM*SECTOPCOUNT) break; }else{ if(topnum >= mytop[type]) break; } if(start > MAXCMP) break; if(type==0 || type==4) sprintf(sqlbuf,"SELECT bname,threadid,MAX(UNIX_TIMESTAMP(time)) AS maxtime,count(DISTINCT userid) AS count FROM postlog WHERE %s GROUP BY bname,threadid ORDER BY count desc LIMIT %d,%d;", cmptime, start, INTERVAL); else sprintf(sqlbuf,"SELECT bname,threadid,UNIX_TIMESTAMP(time),count,title,userid FROM toplog WHERE %s ORDER BY count desc LIMIT %d,%d",cmptime,start, INTERVAL); if( mysql_real_query( &s, sqlbuf, strlen(sqlbuf) )){ printf("%s\n", mysql_error(&s)); mysql_close(&s); return topnum; } res = mysql_store_result(&s); while(1){ row = mysql_fetch_row(res); if(row==NULL) break; /***检查是否该计算十大***/ bh = getbcache(row[0]); if(bh==NULL || bh->flag & BOARD_POSTSTAT){ continue; } if(!normal_board(bh->filename)) continue; #ifdef BLESS_BOARD if(type==0){ if ( ! strcasecmp(row[0], BLESS_BOARD) ){ continue; } }else if(type==4){ if ( strcasecmp(row[0], BLESS_BOARD) ){ continue; } } #endif secid= get_seccode_index(bh->title[0]); if(topnum >= mytop[type] && ( secid==-1 || sectopnum[secid] >= SECTOPCOUNT)) continue; threadid = atoi(row[1]); if(type==0 || type==4){ if(get_file_title(row[0], threadid, title, userid) == NULL){ continue; } }else{ strncpy(title, row[4], 80); title[80]=0; strncpy(userid, row[5], IDLEN); userid[IDLEN]=0; } /**一个版面最多3个十大**/ if(type==0){ m = 0; for (n = 0; n < topnum; n++) { if (!strcmp(row[0], top[n].board)) m++; } if(m>0) continue; /***分区十大里一个版面也最多3个***/ if(secid!=-1){ m = 0; for (n = 0; n < sectopnum[secid]; n++) { if (!strcmp(row[0], sectop[secid][n].board)) m++; } if(m>0) continue; } } /***先记录正常十大的值***/ if(topnum < mytop[type]){ strncpy(top[topnum].board, row[0], BOARDNAMELEN); top[topnum].board[BOARDNAMELEN-1]='\0'; top[topnum].groupid = threadid; strncpy(top[topnum].title, title, 80); top[topnum].title[80]='\0'; strncpy(top[topnum].userid, userid, IDLEN); top[topnum].userid[IDLEN]='\0'; top[topnum].date = atol(row[2]); top[topnum].number = atoi(row[3]); topnum++; } /***计算分区十大***/ if(type==0){ i=secid; if(i!=-1){ if( sectopnum[i] < SECTOPCOUNT){ strncpy(sectop[i][sectopnum[i]].board, row[0], BOARDNAMELEN); sectop[i][sectopnum[i]].board[BOARDNAMELEN-1]='\0'; sectop[i][sectopnum[i]].groupid = threadid; strncpy(sectop[i][sectopnum[i]].title, title, 80); sectop[i][sectopnum[i]].title[80]='\0'; strncpy(sectop[i][sectopnum[i]].userid, userid, IDLEN); sectop[i][sectopnum[i]].userid[IDLEN]='\0'; sectop[i][sectopnum[i]].date = atol(row[2]); sectop[i][sectopnum[i]].number = atoi(row[3]); sectopnum[i]++; sectopnumtotal++; } } }//type==0 if(type==4){ if(topnum>=mytop[type]) break; }else if(type==0){ if(topnum >= mytop[type] && sectopnumtotal >= SECNUM*SECTOPCOUNT) break; }else{ if(topnum >= mytop[type]) break; } } mysql_free_result(res); start += INTERVAL; } mysql_close(&s); return topnum; }
int boarddetail_act(char * info) { int act; char buf[1024]; char opinfo[256]; *opinfo = 0; strncpy (board, getparm("board"), 79); act = atoi(getparm("act")); if (loginok) { wmlmode (u_info, READNEW); } x = getbcache(board); if (x) { if ((!canenterboard (currentuser.userid, board) || !has_read_perm(¤tuser, board)) && !HAS_PERM(PERM_SYSOP)) { x = NULL; } } if (x) { switch (act) { case 1://清除板面未读 if (loginok) { brc_init(currentuser.userid, board); brc_clear(); brc_update(currentuser.userid, board); strcpy (opinfo, "已标记本板为已读。"); } break; } printf ("<card title=\"%s/%s\">", x->title + 11, x->filename); if (*opinfo) { printf ("<p>%s</p>", opinfo); } printf ("<p>板面:<anchor><go href=\"bbsdoc.wml?board=%s\" />%s/%s</anchor></p>", x->filename, x->title + 11, x->filename); wmlUseridStr(buf, x->BM); printf ("<p>板主:%s %s %s</p>", *buf ? buf : "无", (x->flag & OUT_FLAG) ? "转信" : "", junkboard(board) ? "不计文章数" : "计文章数"); printf ("<p><anchor><go href=\"bbsdoc.wml?board=%s&mode=0\" />普通</anchor> ", board); printf ("<anchor><go href=\"bbsdoc.wml?board=%s&mode=1\" />文摘</anchor> ", board); printf ("<anchor><go href=\"bbsdoc.wml?board=%s&mode=8\" />置顶</anchor> ", board); if (has_BM_perm(¤tuser, x->filename) || HAS_PERM(PERM_FORCEPAGE)) { printf ("<anchor><go href=\"bbsdoc.wml?board=%s&mode=4\" />回收</anchor>", board); } printf ("</p>"); if (HAS_PERM(PERM_POST)) { if (x->flag & VOTE_FLAG) { printf ("<p><anchor><go href=\"bbsvote.wml?board=%s\" />投票</anchor></p>", x->filename); } printf ("<p><anchor><go href=\"bbspst.wml?board=%s\" />发文</anchor> <anchor><go href=\"bbspattern.wml?board=%s\" />模板</anchor> <anchor><go href=\"bbs0an.wml?path=%s\" />精华</anchor> <anchor><go href=\"boarddetail.wml?board=%s&act=1\" />清除未读</anchor> </p>", x->filename, x->filename, anno_path_of(x->filename), board); } printf ("<p><anchor><go href=\"bbscon.wml?board=%s&file=%s\" />封禁名单</anchor> <anchor><go href=\"bbscon.wml?board=%s\" />敏感词</anchor></p>", WML_VB_DENIED, board, WML_VB_HEXIE); return 0; } else { strcpy (info, "讨论区不存在或您无权进入此讨论区。"); return -1; } }
int generate_board_title(struct boardheader *bh,void* arg) { int fd2, size = sizeof(fileheader), total, i; struct boardheader btmp; char olddirect[PATHLEN]; char *ptr, *t, *t2; #ifdef GEN_ORIGIN FILE *fp=NULL; char opath[512]; #endif struct fileheader * ptr1; struct search_temp { bool has_pre; int digest; int thread_id; int id; int next; } *index=NULL; struct stat buf; int gen_threadid; struct BoardStatus* bs; #ifdef GEN_ORIGIN setbdir(DIR_MODE_ORIGIN, opath, bh->filename); #endif setbdir(DIR_MODE_NORMAL, olddirect, bh->filename); gen_threadid=1; if ((fd2 = open(olddirect, O_RDWR, 0664)) == -1) { perror(olddirect); return 0; } BBS_TRY { if (!safe_mmapfile_handle(fd2,PROT_READ|PROT_WRITE,MAP_SHARED,&ptr,&buf.st_size)) { close(fd2); return 0; } #ifdef GEN_ORIGIN fp = fopen(opath, "wb"); #endif total = buf.st_size / size; index = (struct search_temp *) malloc(sizeof(*index) * total); ptr1 = (struct fileheader *) ptr; for (i = 0; i < total; i++, ptr1++) { int j; t2 = ptr1->title; if (!strncmp(t2, "Re:", 3)) { index[i].has_pre = true; t2 += 4; } else index[i].has_pre = false; index[i].thread_id = 0; index[i].digest = simple_digest(t2, ARTICLE_TITLE_LEN); for (j = i - 1; j >= 0; j--) { struct fileheader *tmppost; if (index[j].digest != index[i].digest) continue; tmppost = ((struct fileheader *)(ptr + j * size)); t = tmppost->title; if (index[j].has_pre) t += 4; if (!strcmp(t, t2)) { index[j].next = i; index[i].thread_id = index[j].thread_id; index[i].next = 0; break; } } if (index[i].thread_id == 0) { index[i].thread_id = gen_threadid; index[i].id = gen_threadid; index[i].next = 0; gen_threadid++; } else { index[i].id = gen_threadid; gen_threadid++; } } ptr1 = (struct fileheader *) ptr; for (i = 0; i < total; i++, ptr1++) { ptr1->id = index[i].id; ptr1->groupid = index[i].thread_id; ptr1->reid = index[i].thread_id; #ifdef GEN_ORIGIN if (index[i].has_pre == false) fwrite(ptr1, 1, sizeof(struct fileheader), fp); #endif } } BBS_CATCH { } BBS_END; free(index); end_mmapfile((void *) ptr, buf.st_size, -1); close(fd2); #ifdef GEN_ORIGIN fclose(fp); #endif memcpy(&btmp,getbcache(bh->filename),sizeof(btmp)); bs=getbstatus(getbid(bh->filename,NULL)); bs->nowid=gen_threadid + 1; set_board(getbid(bh->filename,NULL), &btmp,NULL); setboardmark(bh->filename, 1); setboardtitle(bh->filename, 1); setboardorigin(bh->filename, 1); return 0; }
/* 返回值意义: -1 没有权限 0 有看的权限 1 有管理的权限 */ int ann_traverse_check(char *path, struct userec *user) { char *ptr; char *ptr2; size_t i = 0; char filename[256]; char buf[256], *fnameptr; char pathbuf[256]; char currpath[256]; char title[STRLEN]; FILE *fp; char board[STRLEN]; bool has_perm_boards = false, sysop_only = false; char *bmstr; int bms_level = 0; /* path parameter can not have leading '/' character */ if (path[0] == '/') return -1; board[0] = '\0'; if ((ptr = strstr(path, "groups/")) != NULL) ann_get_board(ptr, board, sizeof(board)); bzero(pathbuf, sizeof(pathbuf)); if (board[0] == '\0') { ptr = path; } else { const struct boardheader *bh; bh = getbcache(board); if (check_read_perm(user, bh) == 0) return -1; ann_get_path(board, filename, sizeof(filename)); snprintf(pathbuf, sizeof(pathbuf), "0Announce%s", filename); ptr = path + strlen(pathbuf); i = strlen(pathbuf); /* 如果是本版版主 则获得版主权限 TODO */ if (chk_currBM(bh->BM, user)) has_perm_boards = true; } /* 如果是站务 则获得版主权限 */ if (HAS_PERM(user, PERM_OBOARDS) || HAS_PERM(user, PERM_ANNOUNCE) || HAS_PERM(user, PERM_SYSOP)) has_perm_boards = true; /* 开始逐级判断权限 */ while (*ptr != '\0') { if (*ptr == '/') { snprintf(filename, sizeof(filename), "%s/.Names", pathbuf); } else { if (i < sizeof(pathbuf)) pathbuf[i] = *ptr; ptr++; i++; continue; } if ((fp = fopen(filename, "r")) == NULL) return -1; while (fgets(buf, sizeof(buf), fp) != NULL) { if ((ptr2 = strrchr(buf, '\n')) != NULL) *ptr2 = '\0'; if (strncmp(buf, "Name=", 5) == 0) { strncpy(title, buf + 5, sizeof(title) - 1); title[sizeof(title) - 1] = '\0'; continue; } if (strncmp(buf, "Path=~/", 7) == 0) fnameptr = buf + 7; else if (strncmp(buf, "Path=", 5) == 0) fnameptr = buf + 5; else continue; snprintf(currpath, sizeof(currpath), "%s/%s", pathbuf, fnameptr); if (strncmp(currpath, path, strlen(currpath)) != 0) continue; if (path[strlen(currpath)] != '/' && path[strlen(currpath)]!='\0' ) continue; /* 如果有指定BM 则按BM名单获得版主权限 */ bmstr = strstr(title, "(BM:"); if (bmstr != NULL) if (chk_currBM(bmstr + 4, user)) has_perm_boards = true; /* 如果指定BMS 则目录的版主权限级别升高 */ if (strstr(title, "(BM: BMS)")) bms_level++; /* 如果指定SYSOPS 则目录为仅站务可见 */ if (strstr(title, "(BM: SYSOPS)")) sysop_only = true; #ifdef ANN_CTRLK /* 如果Ctrl+K权限验证不通过 则禁止 */ if(!canread(has_perm_boards ? PERM_BOARDS : 0, pathbuf, fnameptr, title)) { fclose(fp); return -1; } #endif /* 如果在一级BMS目录下且用户不具备版主权限 则禁止 */ if ((bms_level >=1) && !HAS_PERM(user, PERM_BOARDS)) { fclose(fp); return -1; } /* 如果在二级BMS目录下且用户不具备本版版主权限 则禁止 */ if ((bms_level >=2) && !has_perm_boards) { fclose(fp); return -1; } /* 如果在SYSOPS目录下且用户不是站务 则禁止 */ if (sysop_only && !HAS_PERM(user, PERM_SYSOP)) { fclose(fp); return -1; } break; } if (feof(fp)) { fclose(fp); return -1; } fclose(fp); if (i < sizeof(pathbuf)) pathbuf[i] = *ptr; ptr++; i++; } return has_perm_boards ? 1 : 0; }
int main() { FILE *fp; char userid[80], buf[512], board[80], dir[80], file[512], filename[80]; char ch, tmp[80], *ptr; struct fileheader x; int i, found=0; init_all(); strsncpy(board, getparm("board"), 32); strsncpy(file, getparm("file"), 32); //printf("<head>我爱南开站-Telnet样式</head>"); printf("<script language='javascript' src='/js/telnetview.js'></script>");//Js支持 printf("<body bgproperties=fixed>",mytheme.bgpath); if (*file!='/') //帖子 { modify_mode(u_info,READING); //bluetent start=atoi(getparm("num")); if(!has_read_perm(¤tuser, board) && !HAS_PERM(PERM_SYSOP)) http_fatal("错误的讨论区"); if (!canenterboard (currentuser.userid, board) && !HAS_PERM(PERM_SYSOP)) http_fatal ("您已经被取消进入本板的权限"); strcpy(board, getbcache(board)->filename); if(loginok) brc_init(currentuser.userid, board); sprintf(dir, "boards/%s/.DIR", board); total=file_size(dir)/sizeof(struct fileheader); if(start>=total) start=total-1; if(start<0) start=0; fp=fopen(dir, "r+"); if(fp==0) http_fatal("目录错误"); if(start==0) { while(1) { if(fread(&x, sizeof(x), 1, fp)<=0) { printf("文章不存在!"); break; } if(!strcmp(x.filename, file)) { show_file(board,&x); break; } } fcloseall(); return 0; } fseek(fp,sizeof(struct fileheader)*start,SEEK_SET); if(fread(&x, sizeof(x), 1, fp)<=0) http_fatal("读取错误."); show_file(board,&x); fcloseall(); return 0; }//帖子结束 else {//精华区 FILE *fp; modify_mode(u_info,DIGEST+20000); //bluetent strsncpy(file, getparm("file"), 511); if(strstr(file, ".Search") || strstr(file, ".Names")|| strstr(file, "..")|| strstr(file, "SYSHome")) http_fatal("错误的文件名"); sprintf(buf, "0Announce%s", file); fp=fopen(buf, "r"); if(fp==0) http_fatal("错误的文件名"); printf("<table><tr><td id=\"c\" bgcolor=\"black\" style=\"font-size:16px;line-height:1\"></td></tr></table>"); printf("<script language=\"javascript\">\n\r init();\n\r"); printf("document.getElementById('c').innerHTML=previewthis('"); while(1) { if(fgets(buf, 256, fp)==0) break; jsprint(void1(buf)); } printf("');\n\r</script>"); fclose(fp); //check_msg();//bluetent 2002.10.31 } http_quit(); }
int main() { FILE *fp; char buf[1024], title[80], board[80], dir[80], first_file[80], userid[16]; struct shortfile *x1; struct fileheader x, x0; int sum=0, total=0, sumfirst=0; init_all(); strsncpy(board, getparm("board"), 32); strsncpy(title, getparm("title"), 42); x1=getbcache(board); if(x1==0) http_fatal("错误的讨论区"); strcpy(board, x1->filename); if(!has_read_perm(¤tuser, board) && !HAS_PERM(PERM_SYSOP)) http_fatal("错误的讨论区"); if (!canenterboard (currentuser.userid, board) && !HAS_PERM(PERM_SYSOP)) http_fatal ("您已经被取消了进本板的权限"); sprintf(buf, "bbsman?board=%s&mode=1", board); sprintf(dir, "boards/%s/.DIR", board); fp=fopen(dir, "r"); if(fp==0) http_fatal("错误的讨论区目录"); printf("<body background=%s bgproperties=fixed>",mytheme.bgpath); printf("<center>%s -- 同主题展开阅读 <a href=bbsdoc?board=%s>[讨论区: %s] </a>[主题 '%s']</center>\n", BBSNAME, board, board,nohtml(title)); // printf("<table width=100%% bgcolor=#65c8aa border=0 cellpadding=0 cellspacing=0 height=1><tr><td></table>"); // printf("<table border=1><tr><td>编号<td>作者<td>日期<td>标题\n"); while(1) { if(fread(&x, sizeof(x), 1, fp)==0) break; sum++; if(!strncmp(title, x.title, 40) || (!strncmp(title, x.title+4, 40) && !strncmp(x.title, "Re: ", 4))) { if(total==0) strcpy(first_file, x.filename); strcpy(userid, x.owner); /* printf("<tr><td>%d", sum); printf("<td>%s", userid_str(x.owner)); if(!(x.accessed[0]&(FILE_MARKED|FILE_DIGEST))) { char buf2[20]; sprintf(buf2, "&box%s=on", x.filename); if(strlen(buf)<500) strcat(buf, buf2); } printf("<td>%6.6s", Ctime(atoi(x.filename+2))+4); printf("<td><a href=bbscon?board=%s&file=%s&num=%d>%s</a>\n", board, x.filename, sum-1, void1(x.title));*/ if (userid[0]=='-') continue; else show_file(board, &x, sum-1); total++; if(total==1) sumfirst=sum-1; } } fclose(fp); printf("\n本主题共有文章 %d 篇 \n", total); printf("<a href=bbsdoc?board=%s&start=%d>本讨论区</a> ", board, sumfirst); if(total>0) { if(has_BM_perm(¤tuser, board)) printf("<a onclick='return confirm(\"确定同主题全部删除?\")' href=%s>同主题删除</a>", buf); } //printf("</center>"); http_quit(); }
static void answer_key(struct evbuffer *buf, const char *key) { int bid; boardheader_t *bptr; if (isdigit(*key)) { char *p; if ((bid = atoi(key)) == 0 || bid > MAX_BOARD) return; if ((p = strchr(key, '.')) == NULL) return; bptr = getbcache(bid); if (!bptr->brdname[0] || BOARD_HIDDEN(bptr)) return; key = p + 1; if (strcmp(key, "isboard") == 0) evbuffer_add_printf(buf, "%d", (bptr->brdattr & BRD_GROUPBOARD) ? 0 : 1); else if (strcmp(key, "over18") == 0) evbuffer_add_printf(buf, "%d", (bptr->brdattr & BRD_OVER18) ? 1 : 0); else if (strcmp(key, "hidden") == 0) evbuffer_add_printf(buf, "%d", BOARD_HIDDEN(bptr) ? 1 : 0); else if (strcmp(key, "brdname") == 0) evbuffer_add(buf, bptr->brdname, strlen(bptr->brdname)); else if (strcmp(key, "title") == 0) evbuffer_add(buf, bptr->title + 7, strlen(bptr->title) - 7); else if (strcmp(key, "class") == 0) evbuffer_add(buf, bptr->title, 4); else if (strcmp(key, "BM") == 0) evbuffer_add(buf, bptr->BM, strlen(bptr->BM)); else if (strcmp(key, "parent") == 0) evbuffer_add_printf(buf, "%d", bptr->parent); else if (strcmp(key, "count") == 0) { char path[PATH_MAX]; setbfile(path, bptr->brdname, FN_DIR); evbuffer_add_printf(buf, "%d", get_num_records(path, sizeof(fileheader_t))); } else if (strcmp(key, "children") == 0) { if (!(bptr->brdattr & BRD_GROUPBOARD)) return; for (bid = bptr->firstchild[1]; bid > 0; bid = bptr->next[1]) { bptr = getbcache(bid); evbuffer_add_printf(buf, "%d,", bid); } } else if (strncmp(key, "articles.", 9) == 0) { int offset, length; key += 9; if (!isdigit(*key) && *key != '-') return; offset = atoi(key); p = strchr(key, '.'); if (!p || (length = atoi(p+1)) == 0) length = DEFAULT_ARTICLE_LIST; article_list(buf, bptr, offset, length); } else if (strncmp(key, "article.", 8) == 0) { if (!is_valid_article_filename(key + 8)) return; char path[PATH_MAX]; struct stat st; int fd; setbfile(path, bptr->brdname, key + 8); if ((fd = open(path, O_RDONLY)) < 0) return; if (fstat(fd, &st) < 0 || st.st_size == 0 || evbuffer_add_file(buf, fd, 0, st.st_size) != 0) close(fd); } else if (strncmp(key, "articlestat.", 12) == 0) { if (!is_valid_article_filename(key + 12)) return; char path[PATH_MAX]; struct stat st; setbfile(path, bptr->brdname, key + 12); if (stat(path, &st) < 0) return; evbuffer_add_printf(buf, "%d-%d,%ld", (int) st.st_dev, (int) st.st_ino, st.st_size); } else if (strncmp(key, "articlepart.", 12) == 0) { answer_articleselect(buf, bptr, key + 12, select_article_part, NULL); } else if (strncmp(key, "articlehead.", 12) == 0) { answer_articleselect(buf, bptr, key + 12, select_article_head, NULL); } else if (strncmp(key, "articletail.", 12) == 0) { answer_articleselect(buf, bptr, key + 12, select_article_tail, NULL); } else return; } else if (strncmp(key, "tobid.", 6) == 0) { bid = getbnum(key + 6); bptr = getbcache(bid); if (!bptr->brdname[0] || BOARD_HIDDEN(bptr)) return; evbuffer_add_printf(buf, "%d", bid); #if HOTBOARDCACHE } else if (strncmp(key, "hotboards", 9) == 0) { for (bid = 0; bid < SHM->nHOTs; bid++) { bptr = getbcache(SHM->HBcache[bid] + 1); if (BOARD_HIDDEN(bptr)) continue; evbuffer_add_printf(buf, "%d,", SHM->HBcache[bid] + 1); } #endif } }
int main() { wml_init(); wml_head(); int i, tmp, max, min; int z; char board[80]; char buf[256], buf2[256], title[256]; FILE * fp; struct rmd r; if (loginok) { wmlmode(u_info, SELECT); } z = atoi(getparm("zone")); if (!*(getparm("zone")) || z < -1 || z >= SECNUM) { z = -3;//list mode } strncpy(board, getparm("board"), 79); if (*board)//zone模式 { z = -2; } if (z == -3) { printf ("<card title=\"选择讨论区 -- %s\" >", BBSNAME); printf ("<p>"); min = 0; if (loginok) { min -= 2; } for (i = min; i < SECNUM; i++) { if (i == -2) { printf ("  <anchor><go href=\"bbsboa.wml?zone=-1\" />我的收藏</anchor>"); } else if ( i == -1) { printf ("  <anchor><go href=\"bbsdoc.wml?board=%s\" />查看邮箱</anchor>", WML_VB_MAIL); } else { printf ("  <anchor><go href=\"bbsboa.wml?zone=%d\" />%s</anchor>", i, secname[i][0]); } if ((i & 1) && (i < SECNUM - 1)) { printf ("<br />"); } } printf ("</p>"); fp = fopen(PATHRMD, "rb"); if (fp) { printf ("<p><em>精彩推荐</em><br />"); while (fread (&r, sizeof(struct rmd), 1, fp)) { w_hsprintf(buf, "%s", r.cn); printf ("<anchor><go href=\"bbscon.wml?board=%s&file=%s\" />%s</anchor> <anchor><go href=\"bbsqry.wml?userid=%s\" />%s</anchor>@<anchor><go href=\"bbsdoc.wml?board=%s\" />%s</anchor><br />", r.board, r.en, buf, r.owner, r.owner, r.board, r.board); } printf ("</p>"); fclose (fp); } fp = fopen("etc/posts/day", "rt"); if (fp) { printf ("<p><em>十大热门话题</em><br />"); fgets(buf, 255, fp); fgets(buf, 255, fp);//跳过两行开头 for(i = 1; i <= 10; i++) { if (!fgets(buf, 255, fp)) { break; } sscanf (buf + 45, "%s", board); if (!fgets(buf, 255, fp))//话说,显示ID没有用啊,反正也老出错 { break; } strsncpy (title, buf + 27, 60); rtrims(title); printf ("<anchor><go href=\"bbstopic.wml?board=%s&topic=%s\" />", board, urlencode2(title)); w_hsprintf(buf2, "%s", title); printf ("%s</anchor> <anchor><go href=\"bbsdoc.wml?board=%s\" />%s板</anchor> <br />", buf2, board, board); } fclose (fp); printf ("</p>"); } printf ("<p><input name=\"inp_goto\" /><anchor><go href=\"bbssel.wml\" method=\"post\"><postfield name=\"goto\" value=\"$(inp_goto)\" /></go>带我去</anchor></p>"); wml_bar(0); printf ("</card>"); } else//板面 { struct shortfile data[MAXBOARD], *x; int total, br; printf ("<card title=\"%s -- %s\">", (z >= 0 ? secname[z][0] : (z == -1 ? "我的收藏" : board)), BBSNAME); if (z == -1) { char mybrd[GOOD_BRC_NUM][80]; int mybrdnum = 0; mybrdnum = LoadMyBrdsFromGoodBrd(currentuser.userid, mybrd); for(i=0; i<mybrdnum; i++) { if(!(x=getbcache(mybrd[i]))) { continue; } if(x->filename[0] <= 32 || x->filename[0] > 'z') { continue; } if(!has_read_perm(¤tuser, x->filename)) { continue; } if(x->flag & ZONE_FLAG) { continue; } data[total++] = *x; } } else { for(i = 0; i < MAXBOARD; i++) { x = &(shm_bcache->bcache[i]); if(x->filename[0] <= 32 || x->filename[0] > 'z') { continue; } if(!has_read_perm(¤tuser, x->filename)) { continue; } if(z >= 0 && !strchr(seccode[z], x->title[0])) { continue; } if (z == -2) //这是某个子分区 { if(!(x->flag & CHILDBOARD_FLAG) && strcasecmp(x->owner, board)) { continue; } } else //这是某个分区 { if(x->flag & CHILDBOARD_FLAG) { continue; } } if((x->flag & ZONE_FLAG) && !count_zone(BOARDS, x->filename)) { continue; } //节约资源? memcpy(&data[total], x, sizeof(struct shortfile)); total++; } qsort(data, total, sizeof(struct shortfile), cmpboard); //printf ("<p><anchor><go href=\"userindex.wml?zone=%d\" />本区导读</anchor></p>", z); } for (i = 0; i < total; i++) { printf ("<p>"); br = board_read(data[i].filename); printf ("<anchor><go href=\"%s.wml?board=%s\" />", (data[i].flag & ZONE_FLAG) ? "bbsboa" : "bbsdoc", data[i].filename); if (!br) { printf ("<em>*"); } w_hprintf ("%s/%s", data[i].title + 10, data[i].filename); if (!br) { printf ("</em>"); } printf ("</anchor></p>"); } wml_bar(0); printf ("</card>"); } wml_tail(); return 0; }
int main() { FILE *fp; int type=0, i, num, l; char userid[80], buf[512], path[512], file[512], board[512], title[80]=""; //struct shortfile *brd; struct fileheader *x; char c;//huangxu@060331 init_all(); modify_mode(u_info,EDIT+20000); //bluetent if(!loginok) http_fatal("匆匆过客不能修改文章,请先登录"); strsncpy(board, getparm("board"), 20); type=atoi(getparm("type")); brd=getbcache(board); if(brd==0) http_fatal("错误的讨论区!"); strcpy(board, brd->filename); strsncpy(file, getparm("file"), 20); if(!has_post_perm(¤tuser, board)) http_fatal("错误的讨论区或者您无权在此讨论区发表文章"); x=get_file_ent(board, file); if(strstr(file, "..") || strstr(file, "/")) http_fatal("错误的参数"); if(x==0) http_fatal("错误的参数"); if(strcmp(x->owner, currentuser.userid)) if(!has_BM_perm(¤tuser, board)) http_fatal("你无权修改此文章"); printf("<center>%s -- 修改文章 [使用者: %s]<hr color=green>\n", BBSNAME, currentuser.userid); if(type!=0) return update_form(board, file); printf("<table border=1>\n"); printf("<tr><td>"); printf("<tr><td><form method=post action=bbsedit>\n"); hsprintf(buf, "%s", x->title); printf("使用标题: %s 讨论区: %s<br>\n", buf, board); printf("本文作者:%s<br>\n", currentuser.userid); sprintf(path, "boards/%s/%s", board, file); fp=fopen(path, "r"); if(fp==0) http_fatal("文件丢失"); fseek(fp,0,2); l=ftell(fp); fseek(fp,0,0); for (i=4;l>0&&i>0;l--)//huangxu@060331 { c=fgetc(fp); if (c==0x0a) i--; } if (l<=0) http_fatal("错误的文件"); printf("<textarea name=text rows=20 cols=80 wrap=physicle>"); while(1) { if(fgets(buf, 500, fp)==0) break; //为什么这些代码无法工作? /*for (;i>0;i--) { printf("CHAR::%d::",*(buf+44)); pbuf++; pbuf=strchr(pbuf,0x0a); if (!pbuf) { printf("NOTFOUND%d",i); break; } printf("FOUND:%d,Length:%d,str=%s::",pbuf-buf,strlen(buf),buf); }*/ if(!strcasestr(buf, "</textarea>")) printf("%s", buf); } fclose(fp); printf("</textarea>\n"); printf("<tr><td class=post align=center>\n"); printf("<input type=hidden name=type value=1>\n"); printf("<input type=hidden name=board value=%s>\n", board); printf("<input type=hidden name=file value=%s>\n", file); printf("<input type=submit value=存盘> \n"); printf("<input type=button value=放弃编辑 onclick=javascript:history.go(-1)></form>\n"); printf("</table>"); http_quit(); }
int more_web(char *fpath, int promptend) { char *ch; char genbuf[41]; if (ch = strstr(fpath, "mailto:")) { if (!HAS_PERM(PERM_LOGINOK)) { outmsg("[41m ±zªºÅv¤£¨¬µLªk¨Ï¥Îinternet mail... [m"); return 0; } if (!not_addr(&ch[7]) && getdata(b_lines - 1, 0, "[±H«H]¥DÃD¡G", genbuf, 40, DOECHO, 0)) { do_send(&ch[7], genbuf); } else { outmsg("[41m ¦¬«H¤Hemail ©Î ¼ÐÃD ¦³»~... [m"); } return 0; } #if 0 if (ch = strstr(fpath, "gopher://")) { ITEM item; strcpy(item.X.G.server, &ch[9]); strcpy(item.X.G.path, "1/"); item.X.G.port = 70; gem(fpath, &item, 0); return 0; } #endif /* wildcat : ¤ä´©ª½±µ¶i¤J¬ÝªO */ if (ch = strstr(fpath, "board://")) { char bname[20], bpath[60], oldch[STRLEN]; struct stat st; int mode0 = currutmp->mode; int stat0 = currstat; int pos; boardheader *bhdr, *getbcache(); strcpy(oldch, ch); strcpy(bname, strtok(oldch + 8, "#")); setbpath(bpath, bname); if ((*bname == '\0') || (stat(bpath, &st) == -1)) { pressanykey(err_bid); return RC_FULL; } if (bhdr = getbcache(bname)) { if (Ben_Perm(bhdr) != 1) { pressanykey("§A¨S¦³¶i¤J¸ÓªOªºÅv"); return 0; } } else { pressanykey("§A¨S¦³¶i¤J¸ÓªOªºÅv"); return 0; } /* shakalaca.000123: ¤ä´©¬Ý¬Y¤@½g */ if (ch = strstr(fpath, "#")) { fileheader fhdr; pos = atoi(ch + 1); setbdir(bpath, bname); rec_get(bpath, &fhdr, sizeof(fileheader), pos); setbfile(bpath, bname, fhdr.filename); more(bpath, 0); } else { /* shakalaca.000124: ¸Ñ¨M "¥¼Åª" °ÝÃD.. */ brc_initial(bname); Read(); } currutmp->mode = mode0; currstat = stat0; return 0; } }
static void a_newitem(menu_t * pm, int mode) { char *mesg[3] = { "[新增文章] 請輸入標題:", /* ADDITEM */ "[新增目錄] 請輸入標題:", /* ADDGROUP */ }; char fpath[PATHLEN]; fileheader_t item; strlcpy(fpath, pm->path, sizeof(fpath)); if (strlen(pm->path) + FNLEN*2 >= PATHLEN) return; switch (mode) { case ADDITEM: stampfile(fpath, &item); strlcpy(item.title, "◇ ", sizeof(item.title)); /* A1BA */ break; case ADDGROUP: if (stampadir(fpath, &item, 0) == -1) { vmsg("抱歉,無法在本層建立新目錄。"); return; } strlcpy(item.title, "◆ ", sizeof(item.title)); /* A1BB */ break; } if (!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) { if (mode == ADDGROUP) rmdir(fpath); else unlink(fpath); return; } switch (mode) { case ADDITEM: { int edflags = 0; # ifdef BN_BBSMOVIE if (pm && pm->bid && strcmp(getbcache(pm->bid)->brdname, BN_BBSMOVIE) == 0) { edflags |= EDITFLAG_UPLOAD; edflags |= EDITFLAG_ALLOWLARGE; } # endif // BN_BBSMOVIE if (vedit2(fpath, 0, NULL, edflags) == -1) { unlink(fpath); pressanykey(); return; } } break; case ADDGROUP: // do nothing break; } strlcpy(item.owner, cuser.userid, sizeof(item.owner)); a_additem(pm, &item); }
int a_menu_rec(const char *maintitle, const char *path, int lastlevel, int lastbid, char *trans_buffer, a_menu_session_t *sess, const int *preselect, // we don't change root's value (but may change root pointer) // we may change parent's value (but never change parent pointer) const menu_t *root, menu_t* const parent) { menu_t me = {0}; char fname[PATHLEN]; int ch, returnvalue = FULLUPDATE; assert(sess); // prevent deep resursive directories if (strlen(path) + FNLEN >= PATHLEN) { // it is not save to enter such directory. return returnvalue; } if(trans_buffer) trans_buffer[0] = '\0'; if (parent) { parent->next = &me; } else { assert(root == NULL); root = &me; } me.header_size = p_lines; me.header = (fileheader_t *) calloc(me.header_size, FHSZ); me.path = path; strlcpy(me.mtitle, maintitle, sizeof(me.mtitle)); setadir(fname, me.path); me.num = get_num_records(fname, FHSZ); me.bid = lastbid; /* 精華區-tree 中部份結構屬於 cuser ==> BM */ if (!(me.level = lastlevel)) { char *ptr; // warning: this is only valid for me.level. // is_uBM should not do anything except returning test result: // for ex, setting user BM permission automatically. // such extra behavior will result in any sub-op to have PERM_BM // ability, which leads to entering BM board without authority. // Thanks to mtdas@ptt for reporting this exploit. if (HasBasicUserPerm(PERM_LOGINOK) && !HasUserPerm(PERM_NOCITIZEN) && (ptr = strrchr(me.mtitle, '['))) me.level = is_uBM(ptr + 1, cuser.userid); } me.page = A_INVALID_PAGE; if (preselect && !*preselect) preselect = NULL; me.now = preselect ? (*preselect -1) : 0; for (;;) { if (me.now >= me.num) me.now = me.num - 1; if (me.now < 0) me.now = 0; if (me.now < me.page || me.now >= me.page + me.header_size) { me.page = me.now - ((me.page == 10000 && me.now > p_lines / 2) ? (p_lines / 2) : (me.now % p_lines)); if (!a_showmenu(&me)) { // some directories are invalid, restart! sess->bReturnToRoot = 1; break; } } if (preselect && *preselect && preselect[1]) { // if this is not the last preselect entry, enter it ch = KEY_ENTER; } else { ch = cursor_key(2 + me.now - me.page, 0); } if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT) break; // TODO maybe we should let 1-9=simple search and z=tree-search // TODO or let 'z' prefix means 'back to root' if ((ch >= '1' && ch <= '9') || (ch == 'z' || ch == 'Z')) { int n = a_multi_search_num(ch, sess); me.page = A_INVALID_PAGE; if (n > 0) { // simple (single) selection me.now = n-1; me.page = 10000; // I don't know what's the magic value 10000... } else if (n == 0 && sess->z_indexes[0] == 0) { // empty/invalid input } else { // n == 0 with multiple selects preselect = sess->z_indexes; if (*preselect < 0) { // return to root first? if (parent) { sess->bReturnToRoot = 1; return DONOTHING; } // already in root preselect ++; } // handle first preselect (maybe zero due to previous 'already in root') if (*preselect > 0) me.now = *preselect - 1; else preselect = NULL; } continue; } switch (ch) { case KEY_UP: case 'k': if (--me.now < 0) me.now = me.num - 1; break; case KEY_DOWN: case 'j': if (++me.now >= me.num) me.now = 0; break; case KEY_PGUP: case Ctrl('B'): if (me.now >= p_lines) me.now -= p_lines; else if (me.now > 0) me.now = 0; else me.now = me.num - 1; break; case ' ': case KEY_PGDN: case Ctrl('F'): if (me.now < me.num - p_lines) me.now += p_lines; else if (me.now < me.num - 1) me.now = me.num - 1; else me.now = 0; break; case KEY_HOME: case '0': me.now = 0; break; case KEY_END: case '$': me.now = me.num - 1; break; case '?': case '/': if(me.num) { me.now = a_searchtitle(&me, ch == '?'); me.page = A_INVALID_PAGE; } break; case 'h': a_showhelp(me.level); me.page = A_INVALID_PAGE; break; case Ctrl('W'): a_where_am_i(root, me.now, me.header[me.now - me.page].title); vmsg(NULL); me.page = A_INVALID_PAGE; break; case 'e': case 'E': snprintf(fname, sizeof(fname), "%s/%s", path, me.header[me.now - me.page].filename); if (dashf(fname) && me.level >= MANAGER) { int edflags = 0; *quote_file = 0; # ifdef BN_BBSMOVIE if (me.bid && strcmp(getbcache(me.bid)->brdname, BN_BBSMOVIE) == 0) { edflags |= EDITFLAG_UPLOAD; edflags |= EDITFLAG_ALLOWLARGE; } # endif // BN_BBSMOVIE if (vedit2(fname, NA, NULL, edflags) != -1) { char fpath[PATHLEN]; fileheader_t fhdr; strlcpy(fpath, path, sizeof(fpath)); stampfile(fpath, &fhdr); unlink(fpath); strlcpy(fhdr.filename, me.header[me.now - me.page].filename, sizeof(fhdr.filename)); strlcpy(me.header[me.now - me.page].owner, cuser.userid, sizeof(me.header[me.now - me.page].owner)); setadir(fpath, path); substitute_record(fpath, me.header + me.now - me.page, sizeof(fhdr), me.now + 1); } me.page = A_INVALID_PAGE; } break; case 't': case 'c': if (me.now < me.num) { if (!isvisible_man(&me)) break; snprintf(fname, sizeof(fname), "%s/%s", path, me.header[me.now - me.page].filename); /* XXX: dirty fix 應該要改成如果發現該目錄裡面有隱形目錄的話才拒絕. 不過這樣的話須要整個搜一遍, 而且目前判斷該資料是目錄 還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b 須等該資料寫入 .DIR 內再 implement才有效率. */ if( !me.level && !HasUserPerm(PERM_SYSOP) && (me.bid==0 || !is_BM_cache(me.bid)) && dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); me.page = A_INVALID_PAGE; /* move down */ if (++me.now >= me.num) me.now = 0; break; } case KEY_ENTER: case KEY_RIGHT: case 'r': if (me.now >= me.num || me.now < 0) { preselect = NULL; continue; } else { fileheader_t *fhdr = &me.header[me.now - me.page]; const int *newselect = preselect ? preselect+1 : NULL; preselect = NULL; if (!isvisible_man(&me)) break; #ifdef DEBUG vmsgf("%s/%s", &path[11], fhdr->filename);; #endif snprintf(fname, sizeof(fname), "%s/%s", path, fhdr->filename); if (dashf(fname)) { int more_result; while ((more_result = more(fname, YEA))) { /* Ptt 範本精靈 plugin */ if (trans_buffer && (currstat == EDITEXP || currstat == OSONG)) { char ans[4]; move(22, 0); clrtoeol(); getdata(22, 1, currstat == EDITEXP ? "要把範例加入到文章內嗎?[y/N]" : "確定要選這篇嗎?[y/N]", ans, sizeof(ans), LCECHO); if (ans[0] == 'y') { strlcpy(trans_buffer, fname, PATHLEN); sess->bReturnToRoot = 1; if (currstat == OSONG) { log_filef(FN_USSONG, LOG_CREAT, "%s\n", fhdr->title); } free(me.header); return FULLUPDATE; } } if (more_result == READ_PREV) { if (--me.now < 0) { me.now = 0; break; } } else if (more_result == READ_NEXT) { if (++me.now >= me.num) { me.now = me.num - 1; break; } /* we only load me.header_size pages */ if (me.now - me.page >= me.header_size) break; } else break; if (!isvisible_man(&me)) break; snprintf(fname, sizeof(fname), "%s/%s", path, me.header[me.now - me.page].filename); if (!dashf(fname)) break; } } else if (dashd(fname)) { returnvalue = a_menu_rec(me.header[me.now - me.page].title, fname, me.level, me.bid, trans_buffer, sess, newselect, root, &me); if (returnvalue == DONOTHING) { // DONOTHING will only be caused by previous a_multi_search_num + preselect. assert(sess->bReturnToRoot); if (!parent) { // we've reached root menu! assert(sess->z_indexes[0] == -1); sess->bReturnToRoot = 0; returnvalue = FULLUPDATE; preselect = sess->z_indexes+1; // skip first 'return to root' if (*preselect > 0) me.now = *preselect-1; } } else { returnvalue = FULLUPDATE; } me.next = NULL; /* Ptt 強力跳出recursive */ if (sess->bReturnToRoot) { free(me.header); return returnvalue; } } me.page = A_INVALID_PAGE; } break; case 'F': case 'U': if (me.now < me.num) { fileheader_t *fhdr = &me.header[me.now - me.page]; if (!isvisible_man(&me)) break; snprintf(fname, sizeof(fname), "%s/%s", path, fhdr->filename); if (HasBasicUserPerm(PERM_LOGINOK) && dashf(fname)) { a_forward(path, fhdr, ch /* == 'U' */ ); /* By CharlieL */ } else vmsg("無法轉寄此項目"); me.page = A_INVALID_PAGE; } break; } if (me.level >= MANAGER) { switch (ch) { case 'n': a_newitem(&me, ADDITEM); me.page = A_INVALID_PAGE; break; case 'g': a_newitem(&me, ADDGROUP); me.page = A_INVALID_PAGE; break; case 'p': a_pasteitem(&me, 1); me.page = A_INVALID_PAGE; break; case 'f': a_editsign(&me); me.page = A_INVALID_PAGE; break; case Ctrl('P'): a_pastetagpost(&me, -1); returnvalue = DIRCHANGED; me.page = A_INVALID_PAGE; break; case Ctrl('A'): a_pastetagpost(&me, 1); returnvalue = DIRCHANGED; me.page = A_INVALID_PAGE; break; case 'a': a_appenditem(&me, 1); me.page = A_INVALID_PAGE; break; } if (me.num) switch (ch) { case 'm': a_moveitem(&me); me.page = A_INVALID_PAGE; break; case 'D': /* Ptt me.page = -1; */ a_delrange(&me, sess->backup_dir); me.page = A_INVALID_PAGE; break; case 'd': a_delete(&me, sess->backup_dir); me.page = A_INVALID_PAGE; break; case 'H': a_hideitem(&me); me.page = A_INVALID_PAGE; break; case 'T': a_newtitle(&me); me.page = A_INVALID_PAGE; break; #ifdef CHESSCOUNTRY case 'L': a_setchesslist(&me); break; #endif } } if (me.level >= SYSOP) { switch (ch) { case 'N': a_showname(&me); me.page = A_INVALID_PAGE; break; } } } free(me.header); return returnvalue; }
static int show_board_info(const char *board) { int i; struct boardheader *bp; struct bstat *bs; char secu[40]; bp = getbcache(board); bs = getbstat(board); clear(); prints("版面详细信息:\n\n"); prints("number : %d\n", getbnum(bp->filename, ¤tuser)); prints("英文名称: %s\n", bp->filename); prints("中文名称: %s\n", (HAS_PERM(PERM_SPECIAL0)) ? bp->title : (bp->title + 11)); prints("版 主: %s\n", bp->BM); prints("所属讨论区: %s\n", bp->group ? bcache[bp->group - 1].filename : "无"); prints("是否目录: %s\n", (bp->flag & BOARD_DIR_FLAG) ? "目录" : "版面"); prints("可以 ZAP: %s\n", (bp->flag & BOARD_NOZAP_FLAG) ? "不可以" : "可以"); if (!(bp->flag & BOARD_DIR_FLAG)) { prints("在线人数: %d 人\n", bs->inboard); prints("文 章 数: %s\n", (bp->flag & BOARD_JUNK_FLAG) ? "不计算" : "计算"); prints("可以回复: %s\n", (bp->flag & BOARD_NOREPLY_FLAG) ? "不可以" : "可以"); //prints ("可以 ZAP: %s\n", // (bp->flag & BOARD_NOZAP_FLAG) ? "不可以" : "可以"); prints("匿 名 版: %s\n", (bp->flag & BOARD_ANONY_FLAG) ? "是" : "否"); #ifdef ENABLE_PREFIX prints ("强制前缀: %s\n", (bp->flag & BOARD_PREFIX_FLAG) ? "必须" : "不必"); #endif prints("俱 乐 部: %s\n", (bp->flag & BOARD_CLUB_FLAG) ? (bp-> flag & BOARD_READ_FLAG) ? "读限制俱乐部" : "普通俱乐部" : "非俱乐部"); prints("now id : %d\n", bs->nowid); prints("读写限制: %s\n", (bp->flag & BOARD_POST_FLAG) ? "限制发文" : (bp->level ==0) ? "没有限制" : "限制阅读"); } if (HAS_PERM(PERM_SPECIAL0) && bp->level != 0) { prints("权 限: "); strcpy(secu, "ltmprbBOCAMURS#@XLEast0123456789"); for (i = 0; i < 32; i++) { if (!(bp->level & (1 << i))) secu[i] = '-'; else { prints("%s\n ", permstrings[i]); } } prints("\n权 限 位: %s\n", secu); } prints("URL 地址: http://"BBSHOST"/bbs/doc?bid=%d\n", bp - bcache + 1); pressanykey(); return FULLUPDATE; }