int bbsnet_report(char *station, char *addr, long id, int mode) { struct fileheader fh; char buf[1024]; char fname[256]; time_t now; FILE *fp; bzero(&fh, sizeof(fh)); setbpath(buf, BBSNET_LOG_BOARD); GET_POSTFILENAME(fname, buf); strncpy(fh.filename, fname, sizeof(fh.filename)-1); fh.filename[sizeof(fh.filename)-1] = '\0'; setbfile(fname, BBSNET_LOG_BOARD, fh.filename); now = time(NULL); strcpy(fh.owner, "deliver"); fh.innflag[0] = 'L'; fh.innflag[1] = 'L'; if (mode == 0) snprintf(fh.title, ARTICLE_TITLE_LEN, "[%ld]%s穿梭到%s", id, user, station); else snprintf(fh.title, ARTICLE_TITLE_LEN, "[%ld]%s结束到%s的穿梭", id, user, station); if ((fp = fopen(fname, "w")) == NULL) return -1; fprintf(fp, "发信人: deliver (自动发信系统), 信区: %s\n", BBSNET_LOG_BOARD); fprintf(fp, "标 题: %s\n", fh.title); fprintf(fp, "发信站: %s (%24.24s)\n\n", BBS_FULL_NAME, ctime(&now)); fprintf(fp, " \033[1;33m%s\033[m 于 \033[1;37m%24.24s\033[m 利用本站bbsnet程序,\n", user, ctime(&now)); if (mode == 0) { fprintf(fp, " 穿梭到 \033[1;32m%s\033[m 站, 地址为\033[1;31m%s\033[m.\n", station, addr); } else { int t; int h; fprintf(fp, " 结束到 \033[1;32m%s\033[m 站的穿梭, 地址为\033[1;31m%s\033[m.\n", station, addr); t = now - id; if (t < 2400) sprintf(buf, "\033[1;32m%d\033[m分钟", t/60); else { h = t / 2400; t -= h * 2400; sprintf(buf, "\033[1;32m%d\033[m小时\033[1;32m%d\033[m分钟", h, t/60); } fprintf(fp, " 本次穿梭一共用了 %s.\n", buf); } fprintf(fp, " 该用户从 \033[1;31m%s\033[m 登录本站.\n", getSession()->fromhost); fclose(fp); return after_post(NULL, &fh, BBSNET_LOG_BOARD, NULL, 0, getSession()); }
static char *post_article(char *homepath, char *userid, char *board, int (*writebody)(), char *pathname, char *firstpath) { struct fileheader header; struct fileheader threadfh; /* char *subject = SUBJECT; */ char index[MAXPATHLEN]; static char name[MAXPATHLEN]; char article[MAXPATHLEN]; FILE *fidx; int fh; int ret; int linkflag; char conv_buf[256]; char old_path[255]; getcwd(old_path, 255); sprintf(index, "%s/.DIR", homepath); if ((fidx = fopen(index, "r")) == NULL) { if ((fidx = fopen(index, "w")) == NULL) { innbbsdlog(":Err: Unable to post in %s.\n", homepath); return NULL; } } fclose(fidx); if (GET_POSTFILENAME(name, homepath) < 0) { innbbslog(" Err: can't get a postfile name\n"); return NULL; } sprintf(article, "%s/%s", homepath, name); fh = open(article, O_WRONLY, 0644); #ifdef DEBUG printf("post to %s\n", article); #endif linkflag = 1; if (firstpath && *firstpath) { close(fh); unlink(article); #ifdef DEBUGLINK innbbsdlog("try to link %s to %s", firstpath, article); #endif linkflag = link(firstpath, article); if (linkflag) { fh = open(article, O_CREAT | O_EXCL | O_WRONLY, 0644); } } if (linkflag != 0) { if (writebody) { if ((*writebody) (fh, board, pathname) < 0) return NULL; } else { if (bbspost_write_post(fh, board, pathname) < 0) return NULL; } close(fh); } bzero((void *) &header, sizeof(header)); strcpy(header.filename, name); strncpy(header.owner, userid, OWNER_LEN); header.owner[OWNER_LEN - 1] = 0; str_decode((unsigned char*)conv_buf, (unsigned char*)SUBJECT); /* big 标题转码,original patch by dgwang @ 笔山书院 */ if(strstr(SUBJECT,"=?big5?") || strstr(SUBJECT,"=?Big5?") || strstr(SUBJECT,"=?BIG5?") ){ int len; len = strlen(conv_buf); big2gb(conv_buf,&len,0,getSession()); } strnzhcpy(header.title, conv_buf, ARTICLE_TITLE_LEN); header.innflag[1] = 'M'; set_posttime(&header); /* * if append record record, should return fail message */ chdir(BBSHOME); resolve_boards(); linkflag = find_thread(&threadfh, board, header.title); header.eff_size = get_effsize(article); ret = after_post(NULL, &header, board, linkflag ? &threadfh : NULL, 0, getSession()); if ((ret < 0) && (ret != -2)) { innbbslog(":Err:after_post Unable to post.\n"); chdir(old_path); return NULL; } chdir(old_path); return name; }