Esempio n. 1
0
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());
}
Esempio n. 2
0
File: tmpl.c Progetto: zhouqt/kbs
/* make a deep copy of one specified template, caller guarantees permission
 * @to_board, from_board - board name, no NULL.
 **/
static int deepcopy(struct a_template *to,   const char *to_board,
                    struct a_template *from, const char *from_board)
{
    if (to == from)
        return -1;

    /* copy basic structure */
    if (!(to->tmpl = malloc(sizeof(struct s_template))))
        return -1;

    memcpy(to->tmpl, from->tmpl, sizeof(struct s_template));

    /* copy questions */
    if (to->tmpl->content_num > 0) {
        int size = (to->tmpl->content_num + 1) * sizeof(struct s_content);
        if (!(to->cont = malloc(size))) {
            free(to->tmpl); to->tmpl = NULL;
            return -1;
        }

        memcpy(to->cont, from->cont, size);

    } else {
        to->cont = NULL;
    }

    /* copy template text */
    if (from->tmpl->filename[0] != '\0') {
        char to_filepath[STRLEN];
        char from_filepath[STRLEN];

        setbfile(to_filepath, to_board, "");
        if (GET_POSTFILENAME(to->tmpl->filename, to_filepath) != 0) {
            free(to->tmpl); to->tmpl = NULL;
            free(to->cont); to->cont = NULL;
            return -2;
        }

        modify_user_mode(uinfo.mode);

        setbfile(to_filepath, to_board, to->tmpl->filename);
        setbfile(from_filepath, from_board, from->tmpl->filename);
        if (f_cp(from_filepath, to_filepath, 0)) {
            free(to->tmpl); to->tmpl = NULL;
            free(to->cont); to->cont = NULL;
            return -3;
        }
    }

    return 0;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
File: tmpl.c Progetto: zhouqt/kbs
static int tmpl_key(struct _select_def *conf, int key)
{
    int oldmode;
    switch (key) {
        case 'a' :
            tmpl_check_limit(template_num);
            tmpl_add();
            return SHOW_DIRCHANGE;
            break;
        case 'd' : {
            char ans[3];

            getdata(t_lines - 1, 0, "确实要删除吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true);
            if (ans[0] == 'Y' || ans[0] == 'y') {
                int i;

                deepfree(ptemplate + conf->pos - 1, currboard->filename);

                template_num--;
                for (i=conf->pos-1; i<template_num; i++)
                    memcpy(ptemplate+i, ptemplate+i+1, sizeof(struct a_template));
                ptemplate[template_num].tmpl = NULL;
                ptemplate[template_num].cont = NULL;


                tmpl_save();
            }
            if (template_num > 0)
                return SHOW_DIRCHANGE;
            else
                return SHOW_QUIT;
        }
        break;
        case 'c':
            do {
                extern bool in_do_sendmsg;
                extern int super_select_board(char *bname);

                int ret;
                char bname[STRLEN] = "";

                move(0,0); clrtoeol();
                prints("%s","复制到讨论区 [ \033[1;32mSPACE/TAB\033[m - 自动补全, \033[1;32mESC\033[m - 退出 ]");
                move(1,0); clrtoeol();
                prints("请输入讨论区名称 [\033[1;32m%s\033[m]: ",currboard->filename);

                make_blist(0, 3);
                in_do_sendmsg=1;
                ret = namecomplete(NULL, bname);
                in_do_sendmsg=0;
                CreateNameList();   /*  free list memory. */

                if (ret == KEY_ESC) {
                    /* noop */
                } else if (!*bname || !strcmp(bname, currboard->filename)) {
                    /* copy to current board */
                    tmpl_check_BM(currboard->filename); /* sanity check, how about stick here when deposing? */
                    tmpl_check_limit(template_num);
                    if (tmpl_copy(conf->pos))
                        tmplcp_sorry();
                    else
                        tmplcp_success();
                } else { /* copy to another board */
                    struct a_template *ptemp;
                    int temp_num = tmpl_init_ex(0, bname, &ptemp);
                    if (temp_num >= 0) {
                        tmpl_check_BM(bname); /* sanity check */
                        tmpl_check_limit(temp_num);
                        if (tmpl_copy_to_board(bname, &ptemp, &temp_num, conf->pos))
                            tmplcp_sorry();
                        else
                            tmplcp_success();
                        tmpl_free_ex(&ptemp, temp_num);
                    }
                }
            } while (0);
            return SHOW_DIRCHANGE;
            /* etnlegend, 2006.05.19, move templates... */
        case 'm':
            do {
                struct a_template temp;
                char ans[4];
                int i,pos;
                getdata(t_lines-1,0,"请输入希望移动到的位置序号: ",ans,4,DOECHO,NULL,true);
                trimstr(ans);
                if (!isdigit(ans[0]))
                    break;
                pos=atoi(ans);
                pos=((pos<1)?1:((pos>template_num)?template_num:pos));
                if (pos==conf->pos)
                    break;
                memcpy(&temp,&ptemplate[conf->pos-1],sizeof(struct a_template));
                if (pos>conf->pos) {
                    for (i=(conf->pos-1); i<(pos-1); i++)
                        memcpy(&ptemplate[i],&ptemplate[i+1],sizeof(struct a_template));
                } else {
                    for (i=(conf->pos-1); i>(pos-1); i--)
                        memcpy(&ptemplate[i],&ptemplate[i-1],sizeof(struct a_template));
                }
                memcpy(&ptemplate[pos-1],&temp,sizeof(struct a_template));
                tmpl_save();
            } while (0);
            return SHOW_DIRCHANGE;
            /* END - etnlegend, 2006.05.19, move templates ... */
        case 't' : {
            char newtitle[60];

            strcpy(newtitle, ptemplate[conf->pos-1].tmpl->title);
            getdata(t_lines - 1, 0, "新名称: ", newtitle, 50, DOECHO, NULL, false);

            if (newtitle[0] == '\0' || newtitle[0]=='\n' || ! strcmp(newtitle,ptemplate[conf->pos-1].tmpl->title))
                return SHOW_REFRESH;

            strncpy(ptemplate[conf->pos-1].tmpl->title, newtitle, 50);
            ptemplate[conf->pos-1].tmpl->title[49]='\0';

            tmpl_save();

            return SHOW_REFRESH;
        }
        break;/*
 case 'z' :
  {
   char newtitle[30];

   strcpy(newtitle, ptemplate[conf->pos-1].tmpl->title_prefix);
getdata(t_lines - 1, 0, "请输入此模板的文章标题前缀: ", newtitle, 20, DOECHO, NULL, false);

   if( newtitle[0] == '\0' || newtitle[0]=='\n' || ! strcmp(newtitle,ptemplate[conf->pos-1].tmpl->title_prefix) )
return SHOW_REFRESH;

   strncpy(ptemplate[conf->pos-1].tmpl->title_prefix, newtitle, 20);
   ptemplate[conf->pos-1].tmpl->title_prefix[19]='\0';

   tmpl_save();

   return SHOW_REFRESH;
  }*/
        case 'f' : {
            char filepath[STRLEN];
            int oldmode;

            oldmode = uinfo.mode;
            modify_user_mode(EDITUFILE);

            if (ptemplate[conf->pos-1].tmpl->filename[0] == '\0') {

                setbfile(filepath, currboard->filename, "");
                if (GET_POSTFILENAME(ptemplate[conf->pos-1].tmpl->filename, filepath) != 0) {
                    clear();
                    move(3,0);
                    prints("创建模板文件失败!");
                    pressanykey();
                    return SHOW_REFRESH;
                }
                tmpl_save();
            }

            setbfile(filepath, currboard->filename, ptemplate[conf->pos-1].tmpl->filename);

            vedit(filepath,0,NULL,NULL,0);
            modify_user_mode(oldmode);

            return SHOW_REFRESH;
        }
        case 's' : {
            char filepath[STRLEN];
            setbfile(filepath, currboard->filename, ptemplate[conf->pos-1].tmpl->filename);
            clear();
            ansimore(filepath,1);
            return SHOW_REFRESH;
        }
        case 'b' : {
            if (ptemplate[conf->pos-1].tmpl->flag & TMPL_BM_FLAG)
                ptemplate[conf->pos-1].tmpl->flag &= ~TMPL_BM_FLAG ;
            else
                ptemplate[conf->pos-1].tmpl->flag |= TMPL_BM_FLAG;

            tmpl_save();

            return SHOW_REFRESH;
        }
        case 'i' : {
            char newtitle[STRLEN];

            strcpy(newtitle, ptemplate[conf->pos-1].tmpl->title_tmpl);
            getdata(t_lines - 1, 0, "新文章标题: ", newtitle, STRLEN, DOECHO, NULL, false);

            if (newtitle[0] == '\0' || newtitle[0]=='\n' || ! strcmp(newtitle,ptemplate[conf->pos-1].tmpl->title_tmpl))
                return SHOW_REFRESH;

            strncpy(ptemplate[conf->pos-1].tmpl->title_tmpl, newtitle, STRLEN);
            ptemplate[conf->pos-1].tmpl->title_tmpl[STRLEN-1]='\0';

            tmpl_save();

            return SHOW_REFRESH;
        }
        case 'x' : {
            clear();
            move(2,0);
            prints("此模版的标题设置为");
            move(4,0);
            prints("%s",ptemplate[conf->pos-1].tmpl->title_tmpl);
            pressanykey();
            return SHOW_REFRESH;
        }
        /*
        case 'h':
        {
         clear();
         move(1,0);
         prints("  x  :  查看标题格式\n");
         prints("  i  :  修改标题格式");
         pressanykey();
         return SHOW_REFRESH;
        }
        */
        case 'l': /* by pig2532 on 2005.12.01 */
            oldmode = uinfo.mode;
            show_allmsgs();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'w':                  /* by pig2532 on 2005-12-1 */
            oldmode = uinfo.mode;
            if (!HAS_PERM(getCurrentUser(), PERM_PAGE))
                break;
            s_msg();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'u':                  /* by pig2532 on 2005-12-1 */
            clear();
            oldmode = uinfo.mode;
            modify_user_mode(QUERY);
            t_query(NULL);
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'U':  /* pig2532 2005.12.10 */
            board_query();
            return SHOW_REFRESH;
        default :
            break;
    }

    return SHOW_CONTINUE;
}