荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: glutton.bbs@ttsx.cn-bbs.org (液态蛇), 信区: InstallBBS
标 题: outd.c
发信站: 亭台水榭BBS (Fri Apr 11 18:49:17 2003)
转信站: SZU!news.tiaozhan.com!news.zixia.net!TTSX
#include "/home/bbs/bbssrc/include/bbs.h"
#include "sys/socket.h"
#include "netdb.h"
#include "netinet/in.h"
#include "stdarg.h"
#define NEWS_SERVER "news.zixia.net"
#define NEWS_PORT 119
//#define GROUP_NAME "cn.bbs.admin.test"
//#define BOARD_NAME "Test"
#define DELAY 60 //循环发信周期
#define FORMAT(fmt, buf, len) va_list ap; va_start(ap, fmt); vsprintf(buf,fmt,
ap); va_end(ap); if(len>=1) buf[len-1]=0;
char *iconf[] = { //转出设置,格式:"新闻组 本地版面",
"cn.bbs.admin.test cnTest",
// "cn.bbs.admin.installbbs BBSDev",
"cn.bbs.admin cnAdmin",
NULL
};
char newsgroup[80],oboard[80];
int do_log(char *fmt, ...) {
FILE *fp;
char buf[256],buf2[256];
time_t t=time(0);
FORMAT(fmt, buf, 256);
sprintf(buf2,"reclog/outd%s.log",oboard);
fp=fopen(buf2, "a");
if(!fp) return;
fprintf(fp, "%24.24s %s\n", ctime(&t), buf);
fclose(fp);
}
int writes(int fd, char *fmt, ...) {
char buf[256];
FORMAT(fmt, buf, 256);
write(fd, buf, strlen(buf));
do_log("I say: %s", buf);
}
char *fgets2(char *buf, int len, FILE *fp) {
int i;
while(fgets(buf, len, fp)==0) {
do_log("connection closed.");
/* exit(0);*/
sleep(DELAY);
};
for(i=0; buf[i]; i++) if(buf[i]==10 || buf[i]==13) buf[i]=0;
do_log("Server say: %s", buf);
return buf;
}
int strsncpy(char *s, char *s2, int len) {
strncpy(s, s2, len);
if(len>=1) s[len-1]=0;
}
void pidlog(){
FILE *fp;
char pidfile[100];
sprintf(pidfile,"/home/bbs/tmp/outd.pid");
if ((fp = fopen(pidfile,"w"))==NULL)
{
do_log("can't create pid file\n");
do_log("%s\n",pidfile);
}
else{
fprintf(fp, "%d\n", getpid());
fflush(fp);
}
return;
}
int do_post(char *newsgroup,char *oboard) {
struct fileheader x;
struct sockaddr_in xs;
struct hostent *he;
char buf[256];
int i, fd;
FILE *fp;
char dirfile[80];
// pidlog();
BEGIN: chdir(MY_BBS_HOME);
for(i=0; i<100; i++) close(i);
bzero((char*) &xs, sizeof(xs));
xs.sin_family=AF_INET;
if(he=gethostbyname(NEWS_SERVER)) {
bcopy(he->h_addr, (char*) &xs.sin_addr, he->h_length);
} else {
xs.sin_addr.s_addr=inet_addr(NEWS_SERVER);
}
xs.sin_port=htons(NEWS_PORT);
fd=socket(AF_INET, SOCK_STREAM, 0);
if(connect(fd, (struct sockaddr*) &xs, sizeof(xs))<0){
do_log("Can't connect to %s", NEWS_SERVER);
sleep(1);
goto END;
}
dup2(fd, 0);
if(fd>0) close(fd);
dup2(0, 1);
fgets(buf, 256, stdin);
if(atoi(buf)<200 || atoi(buf)>=400){
do_log("connection denied.");
sleep(1);
goto END;
}
sprintf(dirfile, "boards/%s/.DIR", oboard);
do_log("open %s .DIR success.",oboard);
fp=fopen(dirfile, "r+");
if(!fp){
do_log("can't open .DIR!");
sleep(1);
goto END;
}
for(i=0; i<1000000; i++) {
if(fread(&x, sizeof(struct fileheader), 1, fp)<=0) break;
if(abs(atoi(x.filename+2)-time(0))>86400) continue;
if(strchr(x.owner, '.') || strchr(x.owner, '@')) continue;
if(!strcmp(x.owner, "deliver")) continue;
if(x.accessed[1]==8) continue;
post_file(&x);
x.accessed[1]=8;
fseek(fp, i*sizeof(struct fileheader), SEEK_SET);
fwrite(&x, sizeof(struct fileheader), 1, fp);
sleep(2);
}
END: writes(1, "quit\n");
// sleep(DELAY);
// goto BEGIN;
}
int post_file(struct fileheader *x) {
FILE *fp;
char file[80], buf[256];
int i;
sprintf(file, "boards/%s/%s", oboard, x->filename);
fp=fopen(file, "r");
if(!fp) return;
do_log("POST from %s to %s", oboard, newsgroup);
writes(1, "post\n");
fgets2(buf, 256, stdin);
if(atoi(buf)>=400 || atoi(buf)<200) {
do_log("ERR: can't post");
return;
}
printf("Path: %s\n", MY_BBS_DOMAIN);
printf("Newsgroups: %s\n", newsgroup);
printf("From: %s.bbs@%s\n", x->owner, MY_BBS_DOMAIN);
printf("Organization: %s\n", MY_BBS_NAME);
printf("X-Filename: %s/M.%d.A\n", oboard, atoi(x->filename+2));
printf("Subject: %s\n\n", x->title);
do_log("title is: %s", x->title);
for(i=0; i<4; i++) {
if(fgets(buf, 256, fp)==0) break;
if(buf[0]==10 || buf[0]==13) break;
if(strstr(buf, ": ")==0) break;
}
while(1) {
if(fgets(buf, 256, fp)==0) break;
if(buf[0]=='.') printf(".");
printf("%s", buf);
}
printf(".\n");
fflush(stdout);
fclose(fp);
fgets2(buf, 80, stdin);
if(atoi(buf)<200 || atoi(buf)>=400) do_log("post err!\n");
do_log("Done.");
}
int main(){
int i;
int tmp;
pidlog();
while(1){
tmp = 0;
for(i=0;iconf[i]!=0;i++){
tmp=sscanf(iconf[i],"%s %s",newsgroup,oboard);
if (tmp<2) continue;
do_post(newsgroup,oboard);
sleep(5);
}
sleep(DELAY);
}
}
--
▁▁▁▁▁◢▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
▕ ╲█◤ ︶ ▏
▕ ︶ ◢█◥◣ 你无声地落下, ︶ ◣◢ ▏
▕ ︶ ◤◥ 残酷地带走所有回忆.... ︶ ◥◣█◤ ▏
◥_______________︶_____________________glutton______◢█╲ __▏
◤
※ 来源:.亭台水榭 BBS ttsx.cn-bbs.org.[FROM: 202.114.12.13]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店