bbslib.c

来自「linux/unix环境下的建站系统」· C语言 代码 · 共 1,534 行 · 第 1/4 页

C
1,534
字号
    if ((userid==NULL)||strcasecmp(userid, "guest")) {        /*         * 非guest在线用户处理          */        if (useridx < 1 || useridx >= MAXACTIVE) {            return -1;        }        (*y) = get_utmpent(useridx);        if (                    /*(strncmp((*y)->from, getSession()->fromhost, IPLEN))|| */               ((*y)->utmpkey != key))            return -2;        if ((((*y)->active == 0)) || ((*y)->userid[0] == 0)            || ((compat_telnet==0)&&((*y)->pid != 1)))            return -3;        if (userid&&strcmp((*y)->userid, userid))            return -4;        getuser((*y)->userid, x);        if (*x == 0)            return -5;        strncpy(getSession()->fromhost, (*y)->from, IPLEN);        getSession()->fromhost[IPLEN] = '\0';    } else {        /*         * guest用户处理          */        struct WWW_GUEST_S *guest_info;        if ((useridx < 0) || (useridx >= MAX_WWW_GUEST))            return -1;        guest_info = &wwwguest_shm->guest_entry[useridx];        if (guest_info->key != key) {            return -2;        }        inet_ntop(AF_INET, &guest_info->fromip, getSession()->fromhost, IPLEN);        strcpy(www_guest_uinfo.from, getSession()->fromhost);        www_guest_uinfo.freshtime = guest_info->freshtime;        www_guest_uinfo.utmpkey = key;        www_guest_uinfo.destuid = useridx;        www_guest_uinfo.logintime = guest_info->logintime;        *y = &www_guest_uinfo;        getuser("guest", x);        if (*x == NULL)            return -1;    }    set_idle_time(*y, time(0));    return 0;}int www_user_login(struct userec *user, int useridx, int kick_multi, char *fromhost, char *fullfrom, struct user_info **ppuinfo, int *putmpent){    int ret;    char buf[255];    struct userdata ud;    if (user != NULL && strcasecmp(user->userid, "guest")) {        struct user_info ui;        int utmpent;        time_t t;        int multi_ret = 1;         while (multi_ret != 0) {            int num;            struct user_info uin;            multi_ret = multilogin_user(user, useridx,1);            if ((multi_ret != 0) && (!kick_multi))                return -1;            if (multi_ret == 0)                break;            if (!(num = search_ulist(&uin, cmpuids2, useridx)))                continue;       /* user isn't logged in */            kick_user_utmp(useridx, get_utmpent(num), 0);            sleep(1);        }        if (!HAS_PERM(user, PERM_BASIC))            return 3;        if (check_ban_IP(fromhost, buf) > 0)            return 4;        t = user->lastlogin;        if (abs(t - time(0)) < 5)            return 5;        user->lastlogin = time(0);        user->numlogins++;        strncpy(user->lasthost, fromhost, IPLEN);        user->lasthost[IPLEN - 1] = '\0';       /* add by binxun ,fix the bug */        read_userdata(user->userid, &ud);	user->userlevel &= (~PERM_SUICIDE);        if (!HAS_PERM(user, PERM_LOGINOK) && !HAS_PERM(user, PERM_SYSOP)) {            if (strchr(ud.realemail, '@')                && valid_ident(ud.realemail)) {                user->userlevel |= PERM_DEFAULT;                /*                 * if (HAS_PERM(user, PERM_DENYPOST)  )                 * user->userlevel &= ~PERM_POST;                 */            }        }        memset(&ui, 0, sizeof(struct user_info));        ui.active = true;        /*         * Bigman 2000.8.29 智囊团能够隐身         */        if ((HAS_PERM(user, PERM_CHATCLOAK)             || HAS_PERM(user, PERM_CLOAK))            && (user->flags & CLOAK_FLAG))            ui.invisible = true;        ui.pager = 0;        if (DEFINE(user, DEF_FRIENDCALL)) {            ui.pager |= FRIEND_PAGER;        }        if (user->flags & PAGER_FLAG) {            ui.pager |= ALL_PAGER;            ui.pager |= FRIEND_PAGER;        }        if (DEFINE(user, DEF_FRIENDMSG)) {            ui.pager |= FRIENDMSG_PAGER;        }        if (DEFINE(user, DEF_ALLMSG)) {            ui.pager |= ALLMSG_PAGER;            ui.pager |= FRIENDMSG_PAGER;        }        ui.uid = useridx;        strncpy(ui.from, fromhost, IPLEN);        ui.logintime = time(0); /* for counting user's stay time */        /*         * refer to bbsfoot.c for details          */        ui.freshtime = time(0);        ui.mode = WEBEXPLORE;                strncpy(ui.userid, user->userid, 20);        strncpy(ui.realname, ud.realname, 20);        strncpy(ui.username, user->username, 40);        utmpent = getnewutmpent2(&ui, 1);        if (utmpent == -1)            ret = 1;        else {            struct user_info *u;            u = get_utmpent(utmpent);            u->pid = 1;			/*            if (addto_msglist(utmpent, user->userid) < 0) {                bbslog("3system", "can't add msg:%d %s!!!\n", utmpent, user->userid);                *ppuinfo = u;                *putmpent = utmpent;                ret = 2;            } else {			*/                *ppuinfo = u;                *putmpent = utmpent;                ret = 0;				/*            }			*/    	    /* Load getCurrentUser()'s mailbox properties, added by atppp */    	    u->mailbox_prop = load_mailbox_prop(user->userid);            getfriendstr(getCurrentUser(), u, getSession());            do_after_login(getCurrentUser(),utmpent,0);        }    } else {        /*         * TODO:alloc guest table          */		int idx = 0;		int exist;		struct in_addr fromhostn;#ifdef HAVE_INET_ATON    inet_aton(fromhost, &fromhostn);#elif defined HAVE_INET_PTON	inet_pton(AF_INET, fromhost, &fromhostn);#else    my_inet_aton(fromhost, &fromhostn);#endif		exist = www_new_guest_entry(&fromhostn, &idx);		/* exist:<0: error0: 正常登录,idx1: 有重复,使用idx的entry		*/        if (exist < 0)            ret = 5;        else {			if( ! exist ){            	int tmp = rand() % 100000000;            	wwwguest_shm->guest_entry[idx].key = tmp;				wwwguest_shm->guest_entry[idx].fromip.s_addr = fromhostn.s_addr;            	wwwguest_shm->guest_entry[idx].logintime = time(0);			}            wwwguest_shm->guest_entry[idx].freshtime = time(0);            www_guest_uinfo.freshtime = wwwguest_shm->guest_entry[idx].freshtime;            www_guest_uinfo.logintime = wwwguest_shm->guest_entry[idx].logintime;            www_guest_uinfo.destuid = idx;            www_guest_uinfo.utmpkey = wwwguest_shm->guest_entry[idx].key;            *ppuinfo = &www_guest_uinfo;            *putmpent = idx;            getuser("guest", &getCurrentUser());            ret = 0;			if( ! exist )            	do_after_login(getCurrentUser(),idx,1);        }    }    if ((ret == 0) || (ret == 2)) {        snprintf(buf, sizeof(buf), "ENTER ?@%s (ALLOC %d) [www]", fullfrom, *putmpent);        newbbslog(BBSLOG_USIES, "%s", buf);    }    return ret;}static void setflags(struct userec *u, int mask, int value){    if (((u->flags & mask) && 1) != value) {        if (value)            u->flags |= mask;        else            u->flags &= ~mask;    }}int www_user_logoff(struct userec *user, int useridx, struct user_info *puinfo, int userinfoidx){    int stay = 0;    stay = time(0) - puinfo->logintime;    if (stay < 0) stay = 0;#if 0 // atppp 20060221    /*     * 上站时间超过 2 小时按 2 小时计      */    if (stay > 7200)        stay = 7200;#endif    if(stay < 300) {        if (user->numlogins > 5)            user->numlogins--;    } else {        user->stay += stay;    }    user->exittime = time(0);    if (strcmp(user->userid, "guest")) {        newbbslog(BBSLOG_USIES, "EXIT: Stay:%3ld (%s)[%d %d](www)", stay / 60, user->username, getSession()->utmpent, useridx);        if (!puinfo->active)            return 0;        setflags(user, PAGER_FLAG, (puinfo->pager & ALL_PAGER));        if ((HAS_PERM(user, PERM_CHATCLOAK) || HAS_PERM(user, PERM_CLOAK)))            setflags(user, CLOAK_FLAG, puinfo->invisible);#if defined(HAVE_BRC_CONTROL)        init_brc_cache(user->userid,false,getSession());        brc_update(user->userid, getSession());#endif        clear_utmp(userinfoidx, useridx, 1);    } else {        newbbslog(BBSLOG_USIES, "EXIT: Stay:%3ld (guest)[%d %d](www)", stay / 60, puinfo->destuid, useridx);        www_free_guest_entry(puinfo->destuid);    }    return 0;}static void print_font_style(unsigned int style, buffered_output_t * output){    char font_class[8];    char font_style[STRLEN];    char font_str[256];    unsigned int bg;	int len;    if (STYLE_ISSET(style, FONT_BG_SET)) {        bg = 8;    } else        bg = STYLE_GET_BG(style);    sprintf(font_class, "f%01d%02d", bg, STYLE_GET_FG(style));    font_style[0] = '\0';    if (STYLE_ISSET(style, FONT_STYLE_UL))        strcat(font_style, "text-decoration: underline; ");    if (STYLE_ISSET(style, FONT_STYLE_ITALIC))        strcat(font_style, "font-style: italic; ");    if (font_style[0] != '\0')        sprintf(font_str, "<font class=\"%s\" style=\"%s\">", font_class, font_style);    else        sprintf(font_str, "<font class=\"%s\">", font_class);	len = strlen(font_str);    BUFFERED_OUTPUT(output, font_str, len);}/*static void html_output(char *buf, size_t buflen, buffered_output_t * output)*/#define html_output(buf, buflen, output) \do { \    size_t _ho_i; \	const char *_ho_ptr = buf; \\    for (_ho_i = 0; _ho_i < buflen; _ho_i++) { \        switch (_ho_ptr[_ho_i]) { \        case '&': \            BUFFERED_OUTPUT(output, "&amp;", 5); \            break; \        case '<': \            BUFFERED_OUTPUT(output, "&lt;", 4); \            break; \        case '>': \            BUFFERED_OUTPUT(output, "&gt;", 4); \            break; \        case ' ': \            BUFFERED_OUTPUT(output, "&nbsp;", 6); \            break; \        default: \            BUFFERED_OUTPUT(output, &(_ho_ptr[_ho_i]), 1); \        } \    } \} while(0)static void print_raw_ansi(char *buf, size_t buflen, buffered_output_t * output){    size_t i;    for (i = 0; i < buflen; i++) {        if (buf[i] == 0x1b)		{            html_output("*", 1, output);		}        else if (buf[i]=='\n') {			BUFFERED_OUTPUT(output, " <br /> ", 8);        } else {            html_output(&buf[i], 1, output);		}    }}static void generate_font_style(unsigned int *style, unsigned int *ansi_val, size_t len){    size_t i;    unsigned int color;    for (i = 0; i < len; i++) {        if (ansi_val[i] == 0)            STYLE_ZERO(*style);        else if (ansi_val[i] == 1)            STYLE_SET(*style, FONT_FG_BOLD);        else if (ansi_val[i] == 4)            STYLE_SET(*style, FONT_STYLE_UL);        else if (ansi_val[i] == 5)            STYLE_SET(*style, FONT_STYLE_BLINK);        else if (ansi_val[i] >= 30 && ansi_val[i] <= 37) {            color = ansi_val[i] - 30;            STYLE_SET_FG(*style, color);        } else if (ansi_val[i] >= 40 && ansi_val[i] <= 47) {            /*             * user explicitly specify background color              */            /*             * STYLE_SET(*style, FONT_BG_SET);              */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?