SetupBBS 板


【 以下文字转载自 deleted 讨论区 】 【 原文由 [email protected] 所发表 】 /** 改造版 delspam 称为 rmspam , make 好以後放到 ~bbs/bin/rmspam **/ /** 配合自动砍信版版 bbsmail.c 使用,效果不错 **/ /** rmspam 和 delspam 的差异只有把目录简化成从 ~bbs/home 开始 **/ /** 第一个参数是要进去砍信的使用者 id , 如此而已 **/ /** benyx/萧还 990825 **/ /** 以下是 leeym 的原版说明和小弟涂改过配合 bbsmail 的程式: **/ /* 想必大家今天都看到 [config] 版上的风暴了. 交大资工站一天被灌了 5000 篇的广告. 小小的成大土木站也没有幸免於难.最可恶的是连我都被灌到 :( 看到 mfchen 大大放出来一个程式专砍广告. 可惜 Maple & Sob 的 .DIR 规格不合. file.owner 只有 13 characters. 所以就改抓信件的第一行来判断发信人 写了一个程式给大家玩玩. 这个是 BETA 版. 如果有要更新我会在成大土木站 [sob] 贴出来. Spam ? 肉品罐头? 我也不知道为什麽..那程式就叫 delspam 好了 另外补充一下.我使用 /etc/sendmail.baduser 来当 sendmail-8.8.x 挡 bad user 的设定档. 用法 delspam <boards|home> [spam mailer1] [spam mailer2]... 用法: delspam home 找出 ~bbs/home 里面发信人列在 /etc/sendmail.baduser 里的 delspam home [email protected] [email protected] 找出 ~bbs/home 里面这两个家伙灌进来的广告 (光这两个就在我这里被灌了上百封) delspam boards [email protected] 找出 ~bbs/boards 下 [email protected] 的信件 (这个人今天在全球 news groups 上徵炮友) 找出来以後看你是定义 define DELETE 还是 undef DELETE define DELETE 的.会把信件砍掉. undef DELETE 的.会把信件移到 ~bbs/tmp 下. 要把 ~bbs/tmp 下的广告信灌回去的请自己斟酌.後果自己负责. (嗯?嘿嘿...) 以下程式码开始 */ /*-------------------------------------------------------*/ /* util/delspam.c ( NTHU CS MapleBBS Ver 2.36.sob )*/ /*-------------------------------------------------------*/ /* target : 砍掉 Spam mailer 的垃圾信件 .DIR 重建 */ /* create : 96/01/10 <= 我的 20 岁生日前两天 */ /* update : 随时更新 */ /*-------------------------------------------------------*/ /* author : [email protected] */ /*-------------------------------------------------------*/ /* syntex : delspam <board|home> [mailer1] [mailer2].. */ /*-------------------------------------------------------*/ #define ERROR /* 错误警告 */ #undef DEBUG /* 除错模式 */ #undef DELETE /* 砍掉广告信 */ /* undef DELETE 则为搬移广告信到 ~bbs/tmp , 以便嘿嘿.. */ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/dir.h> #include <fcntl.h> #include <time.h> #include <string.h> #include "bbs.h" #define SENDMAIL_BADUSER "/home/bbs/etc/spam.list" #define BUFSIZE 256 #ifndef MAXPATHLEN #define MAXPATHLEN 1024 #endif int alphasort(); int summary = 0; int visit = 0; int junkmail = 0; char *currfilename = "\0"; /* woju Cross-fs rename() */ Rename(char* src, char* dst) { char cmd[200]; if (rename(src, dst) == 0) return 0; sprintf(cmd, "/bin/mv %s %s", src, dst); return system(cmd); } int getindex(fpath,fname,size) char *fpath; char *fname; int size; { int fd, now=0; fileheader fhdr; if ((fd = open(fpath, O_RDONLY, 0)) != -1) { while((read(fd, &fhdr, size) == size)){ now++; if(!strcmp(fhdr.filename,fname)){ close(fd); return now; } } close(fd); } return 0; } int delete_file(dirname, size, ent, filecheck) char *dirname; int size, ent; int (*filecheck) (); { char abuf[BUFSIZE]; int fd; struct stat st; long numents; if ((fd = open(dirname, O_RDWR)) == -1) return -1; flock(fd, LOCK_EX); fstat(fd, &st); numents = ((long) st.st_size) / size; if (((long) st.st_size) % size) fprintf(stderr, "align err\n"); if (lseek(fd, size * (ent - 1), SEEK_SET) != -1) { if (read(fd, abuf, size) == size) if ((*filecheck) (abuf)) { int i; for (i = ent; i < numents; i++) { if (lseek(fd, i * size, SEEK_SET) == -1) break; if (read(fd, abuf, size) != size) break; if (lseek(fd, (i - 1) * size, SEEK_SET) == -1) break; if (write(fd, abuf, size) != size) break; } ftruncate(fd, (off_t) size * (numents - 1)); flock(fd, LOCK_UN); close(fd); return 0; } } lseek(fd, 0, SEEK_SET); ent = 1; while (read(fd, abuf, size) == size) { if ((*filecheck) (abuf)) { int i; for (i = ent; i < numents; i++) { if (lseek(fd, (i + 1) * size, SEEK_SET) == -1) break; if (read(fd, abuf, size) != size) break; if (lseek(fd, i * size, SEEK_SET) == -1) break; if (write(fd, abuf, size) != size) break; } ftruncate(fd, (off_t) size * (numents - 1)); flock(fd, LOCK_UN); close(fd); return 0; } ent++; } flock(fd, LOCK_UN); close(fd); return -2; } int belong(filelist, key) char *filelist; char *key; { FILE *fp; int rc = 0; if (fp = fopen(filelist, "r")) { char buf[STRLEN], *ptr; while (fgets(buf, STRLEN, fp)) { if ((ptr = strtok(buf, " \t\n\r")) && !strcasecmp(ptr, key)) { rc = 1; break; } } fclose(fp); } return rc; } int cmpfilename(fhdr) fileheader *fhdr; { return (!strcmp(fhdr->filename, currfilename)); } int dashd(fname) char *fname; { struct stat st; return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); } int dirselect(dir) struct direct *dir; { register char *name = dir->d_name; return (strchr("MDSGH", *name) && name[1] == '.'); } main(argc, argv) int argc; char *argv[]; { DIR *dirp; struct dirent *de; char *fname; time_t start, end; if (argc == 1) { printf("usage: %s <boards|home> [spam mailer1] [spam mailer2]..\n",argv[0]); printf(" if [spam mailer] exist, find out it.\n"); printf(" else find spam mailer in sendmail setting file\n"); exit(-1); } setuid(BBSUID); setgid(BBSGID); chdir(BBSHOME); chdir("home"); /* visit the first hierarchy */ if (!(dirp = opendir("."))) { printf("unable to enter %s\n","home"); exit(-1); } #ifdef DEBUG printf("now entering %s\n","home"); #endif // time(&start); while (de = readdir(dirp)) { fname = de->d_name; /** DeltaStar BBS -- benyx **/ /** 只有修改把 home 当成预设,并且指定进入的使用者目录 **/ if(strcmp(argv[1],fname)) continue; if (fname[0] > ' ' && fname[0] != '.' && dashd(fname)) { int fdir, i, j, bonus =0; struct stat st; char genbuf[512], path[256], *name, arthor[80], dirname[80]; FILE *fp; int total, count; fileheader fhdr; struct direct **dirlist; time_t filetime; struct tm *ptime; sprintf(path, "%s/.DIR", fname); sprintf(dirname,BBSHOME"/%s/%s","home",path); if (fdir = open(path, O_RDWR) == -1) { #ifdef ERROR printf("%s open error\n",path); #endif continue; } total = scandir(fname, &dirlist, dirselect, alphasort); fname = strrchr(path, '.'); #ifdef DEBUG printf("path: %s\n",path); printf("fname: %s\n",fname); #endif for (count = 0; count < total; count++) { int junk = 0; name = dirlist[count]->d_name; strcpy(fname, name); currfilename = strrchr(path,'M'); if (!stat(path, &st)) { if (st.st_size && (fp = fopen(path, "r"))) { fgets(genbuf, 256, fp); if (!strncmp(genbuf, "作者: ", 6) || !strncmp(genbuf, "发信人: ", 8)) { bzero(&fhdr, sizeof(fhdr)); i = 5; while (genbuf[i] != ' ') i++; while (genbuf[i] == ' ') i++; j = i + 1; while (genbuf[j] != ' ' && genbuf[j] != '\n' && genbuf[j] != '\r' && genbuf[j] != '\t') j++; /* ban bad user e-mail */ strncpy(arthor, &genbuf[i], j); arthor[j-i] = '\0'; strcpy(fhdr.filename,name); j -= i; if(j > IDLEN +1) j = IDLEN+1; if (argc > 2) for(i= 2; i < argc; i++){ if (!strcmp(arthor, argv[i])) { #ifdef DELETE unlink(path); #else sprintf(genbuf,BBSHOME"/%s/%s","home",path); Rename(genbuf,BBSHOME"/tmp"); #endif #ifdef DEBUG printf("no:%d arthor:%s, %s deleted, file size:%d\n", count, arthor, path, st.st_size); #endif i=getindex(dirname,fhdr.filename,sizeof(fileheader)); j=delete_file(dirname, sizeof(fileheader), i,cmpfilename); #ifdef ERROR if (j){ printf("delete no:%d %s in %s error %d\n", count, fhdr.filename, dirname,j); printf("delete %s in %s error\n",name, dirname); printf("fhdr.filename: %s, currfilename: %s\n", fhdr.filename ,currfilename); break; } #else /* do nothing */ ; #endif bonus += st.st_size; junkmail++; junk = 1; } } if (belong(SENDMAIL_BADUSER, arthor) && argc == 2) { #ifdef DELETE unlink(path); #else sprintf(genbuf,BBSHOME"/%s/%s","home",path); Rename(genbuf,BBSHOME"/tmp"); #endif #ifdef DEBUG printf("no:%d arthor:%s, %s deleted, file size:%d\n", count+1, arthor, path, st.st_size); #endif i=getindex(dirname,fhdr.filename,sizeof(fileheader)); j=delete_file(dirname, sizeof(fileheader), i,cmpfilename); #ifdef ERROR if (j){ printf("delete no:%d %s in %s error %d\n", count,fhdr.filename, dirname,j); printf("delete %s in %s error\n",name, dirname); printf("fhdr.filename: %s, currfilename: %s\n", fhdr.filename ,currfilename); break; } #else /* do nothing */ ; #endif bonus += st.st_size; junk = 1; junkmail++; } #ifdef DEBUG if(!junk) printf("no:%d arthor:%s, %s kept\n", count+1, arthor, path,st.st_size); #endif } fclose(fp); } if (!st.st_size) { #ifdef DEBUG printf("%s size 0, deleted\n",path); #endif unlink(path); } } } close(fdir); // summary += bonus; // visit++; } } closedir(dirp); // time(&end); /* printf("\n# start: %s", ctime(&start)); printf("# end : %s", ctime(&end)); end -= start; start = end % 60; end /= 60; printf("# time : %d:%d:%d\n", end / 60, end % 60, start); printf("# Visit: %10d\n", visit); printf("# Number: %10d\n", junkmail); printf("# Summary: %10d\n", summary); */ exit(0); } -- ┬────────────────────┬ 发现 ”小威威 ” ꠠ 保育专线 : [email protected] 〞小威威 〞ꨠ美观实用 生命力强韧 请认明 〞benyx小威威 〞 不要抓错喔 ﹗ ────────────────────┴ -- ※ 心耘缘起 (h239.s221.ts32.hinet.net) ※ 无限星云 (star.ee.ttu.edu.tw) -- ※ 转载:‧大红花的国度 msia.twbbs.org‧[FROM: seong.Dorm13.NCTU.ed]







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草
伺服器连线错误,造成您的不便还请多多包涵!
「赞助商连结」






like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP