bbslib.c

来自「bbs server linux平台下软件源码」· C语言 代码 · 共 2,630 行 · 第 1/5 页

C
2,630
字号
    if (urec->numlogins <= 3)        return (45 * 1440 - i) / 1440;    if (!(urec->userlevel & PERM_LOGINOK))        return (90 * 1440 - i) / 1440;    return (180 * 1440 - i) / 1440;}int modify_mode(struct user_info *x, int newmode){    if (x == 0)        return;    x->mode = newmode;}int save_user_data(struct userec *x){    int n;    n = getusernum(x->userid);    update_user(x, n, 1);    return 1;}int is_bansite(char *ip){    FILE *fp;    char buf3[256];    fp = fopen(".bansite", "r");    if (fp == 0)        return 0;    while (fscanf(fp, "%s", buf3) > 0)        if (!strcasecmp(buf3, ip))            return 1;    fclose(fp);    return 0;}int user_perm(struct userec *x, int level){    return (x->userlevel & level);}int getusernum(char *id){    return searchuser(id);}int loadfriend(char *id){    FILE *fp;    char file[256];    if (!loginok)        return;    sprintf(file, "home/%c/%s/friends", toupper(id[0]), id);    fp = fopen(file, "r");    if (fp) {        friendnum = fread(fff, sizeof(fff[0]), 200, fp);        fclose(fp);    }}int isfriend(char *id){    return myfriend(searchuser(id), NULL);}int loadbad(char *id){    FILE *fp;    char file[256];    if (!loginok)        return;    sprintf(file, "home/%c/%s/rejects", toupper(id[0]), id);    fp = fopen(file, "r");    if (fp) {        badnum = fread(fff, sizeof(fff[0]), MAXREJECTS, fp);        fclose(fp);    }}int isbad(char *id){    static inited = 0;    int n;    if (!inited) {        loadbad(currentuser->userid);        inited = 1;    }    for (n = 0; n < badnum; n++)        if (!strcasecmp(id, bbb[n].id))            return 1;    return 0;}void http_redirect(char *url){    printf("Status: 302 Found\n");    printf("Location: %s\n", url);    printf("Content-type: text/html; charset=%s\n\n", CHARSET);}int init_all(){    srand(time(0) * 2 + getpid());    chdir(BBSHOME);    http_init();    /*     * seteuid(BBSUID);     * if(geteuid()!=BBSUID) http_fatal("uid error.");      */    shm_init();    loginok = user_init(&currentuser, &u_info);    if (loginok < 0) {        /*         * http_redirect(NOLOGIN_PAGE);         * exit(0);         */        printf("Content-type: text/html; charset=%s\n\n", CHARSET);        /*         * redirect(NOLOGIN_PAGE);          */        printf("<script>top.window.location='/nologin.html';</script>\n");        exit(0);    }    html_init();    init_bbslog();}int init_no_http(){    srand(time(0) + getpid());    chdir(BBSHOME);    shm_init();}char *void1(unsigned char *s){    int i;    int flag = 0;    for (i = 0; s[i]; i++) {        if (flag == 0) {            if (s[i] >= 128)                flag = 1;            continue;        }        flag = 0;        if (s[i] < 32)            s[i - 1] = 32;    }    if (flag)        s[strlen(s) - 1] = 0;    return s;}char *sec(char c){    int i;    for (i = 0; i < SECNUM; i++) {        if (strchr(seccode[i], c))            return secname[i][0];    }    return "(unknown.)";}char *flag_str(int access){    static char buf[80];    char *flag2 = "";    strcpy(buf, "  ");    if (access & FILE_DIGEST)        flag2 = "G";    if (access & FILE_MARKED)        flag2 = "M";    if ((access & FILE_MARKED) && (access & FILE_DIGEST))        flag2 = "B";    sprintf(buf, "%s", flag2);    return buf;}char *flag_str2(int access, int has_read){    static char buf[80];    strcpy(buf, "   ");    if (loginok)        strcpy(buf, "N  ");    if (access & FILE_DIGEST)        buf[0] = 'G';    if (access & FILE_MARKED)        buf[0] = 'M';    if ((access & FILE_MARKED) && (access & FILE_DIGEST))        buf[0] = 'B';    if (has_read)        buf[0] = tolower(buf[0]);    if (buf[0] == 'n')        buf[0] = ' ';    return buf;}char *userid_str(char *s){    static char buf[512];    char buf2[256], tmp[256], *ptr, *ptr2;    strsncpy(tmp, s, 255);    buf[0] = 0;    ptr = strtok(tmp, " ,();\r\n\t");    while (ptr && strlen(buf) < 400) {        if (ptr2 = strchr(ptr, '.')) {            ptr2[1] = 0;            strcat(buf, ptr);            strcat(buf, " ");        } else {            ptr = nohtml(ptr);            sprintf(buf2, "<a href=\"bbsqry?userid=%s\">%s</a> ", ptr, ptr);            strcat(buf, buf2);        }        ptr = strtok(0, " ,();\r\n\t");    }    return buf;}int fprintf2(FILE * fp, char *s){    int i, tail = 0, sum = 0;    if (s[0] == ':' && s[1] == ' ' && strlen(s) > 79) {        sprintf(s + 76, "..\n");        fprintf(fp, "%s", s);        return;    }    for (i = 0; s[i]; i++) {        fprintf(fp, "%c", s[i]);        sum++;        if (tail) {            tail = 0;        } else if (s[i] < 0) {            tail = s[i];        }        if (sum >= 78 && tail == 0) {            fprintf(fp, "\n");            sum = 0;        }    }}int get_file_ent(char *board, char *file, struct fileheader *x){    char dir[80];    sprintf(dir, "boards/%s/.DIR", board);    return search_record(dir, x, sizeof(struct fileheader), (RECORD_FUNC_ARG) cmpname, file);}int set_my_cookie(){    FILE *fp;    char path[256], buf[256], buf1[256], buf2[256];    int my_t_lines = 20, my_link_mode = 0, my_def_mode = 0;    sprintf(path, "home/%c/%s/.mywww", toupper(currentuser->userid[0]), currentuser->userid);    fp = fopen(path, "r");    if (fp) {        while (1) {            if (fgets(buf, 80, fp) == 0)                break;            if (sscanf(buf, "%80s %80s", buf1, buf2) != 2)                continue;            if (!strcmp(buf1, "t_lines"))                my_t_lines = atoi(buf2);            if (!strcmp(buf1, "link_mode"))                my_link_mode = atoi(buf2);            if (!strcmp(buf1, "def_mode"))                my_def_mode = atoi(buf2);        }        fclose(fp);    }    sprintf(buf, "%d", my_t_lines);    setcookie("my_t_lines", buf);    sprintf(buf, "%d", my_link_mode);    setcookie("my_link_mode", buf);    sprintf(buf, "%d", my_def_mode);    setcookie("my_def_mode", buf);}int has_fill_form(){    FILE *fp;    int r;    char userid[256], tmp[256], buf[256], *ptr;    fp = fopen("new_register", "r");    if (fp == 0)        return 0;    while (1) {        if (fgets(buf, 100, fp) == 0)            break;        r = sscanf(buf, "%s %s", tmp, userid);        if (r == 2) {            if (!strcasecmp(tmp, "userid:") && !strcasecmp(userid, currentuser->userid)) {                fclose(fp);                return 1;            }        }    }    fclose(fp);    return 0;}/* added by flyriver, 2001.12.17 * using getcurrusr() instead of using currentuser directly */struct userec *getcurrusr(){    return currentuser;}struct userec *setcurrusr(struct userec *user){    if (user == NULL)        return NULL;    currentuser = user;    return currentuser;}char *getcurruserid(){    return currentuser->userid;}unsigned int getcurrulevel(){    return currentuser->userlevel;}int define(unsigned int x){    return x ? currentuser->userdefine & x : 1;}time_t get_idle_time(struct user_info * uentp){    return uentp->freshtime;}bcache_t *getbcacheaddr(){    return bcache;}uinfo_t *getcurruinfo(){    return u_info;}uinfo_t *setcurruinfo(uinfo_t * ui){    u_info = ui;    return u_info;}/* should do some locking before calling this function */int eat_file_content(int fd, off_t start, off_t len){    struct stat fs;    char *addr;    int i, r;    if (start < 0 || len <= 0)        return 1;    if (fstat(fd, &fs) < 0)        return -1;    if (start >= fs.st_size)        return 1;    addr = mmap(0, fs.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);    if (addr == MAP_FAILED)        return -1;    if (start + len > fs.st_size)        len = fs.st_size - start;    r = fs.st_size - start - len;    for (i = start; i < r; i++)        addr[start + i] = addr[start + len + i];    munmap(addr, fs.st_size);    ftruncate(fd, fs.st_size - len);    return 0;}int count_online(){    return get_utmp_number();}int count_www(){    int i, total = 0;    for (i = 0; i < MAXACTIVE; i++) {        if (utmpshm->uinfo[i].mode == WEBEXPLORE)            total++;    }    return total;}int get_ulist_length(){    return sizeof(user_record) / sizeof(user_record[0]);}struct user_info **get_ulist_addr(){    return user_record;}uinfo_t *get_user_info(int utmpnum){    if (utmpnum < 1 || utmpnum > USHM_SIZE)        return NULL;    return &(utmpshm->uinfo[utmpnum - 1]);}int get_friends_num(){    return get_utmpent(utmpent)->friendsnum;    ;}struct boardheader *getbcache_addr(){    return bcache;}/* from talk.c */int cmpfuid(a, b)struct friends *a, *b;{    return strcasecmp(a->id, b->id);}/* from bbs.c */static void record_exit_time(char *userid){                               /* 记录离线时间  Luzi 1998/10/23 */    char path[80];    FILE *fp;    time_t now;    sethomefile(path, userid, "exit");    fp = fopen(path, "wb");    if (fp != NULL) {        now = time(NULL);        fwrite(&now, sizeof(time_t), 1, fp);        fclose(fp);    }}/* from list.c */int set_friendmode(int mode){    friendmode = mode;    return friendmode;}int get_friendmode(){    return friendmode;}int full_utmp(struct user_info *uentp, int *count){    if (!uentp->active || !uentp->pid) {        return 0;    }    if (!HAS_PERM(currentuser, PERM_SEECLOAK) && uentp->invisible && strcmp(uentp->userid, getcurruserid())) {  /*Haohmaru.99.4.24.让隐身者能看见自己 */        return 0;    }    if (friendmode && !myfriend(uentp->uid, NULL)) {        return 0;    }    user_record[*count] = uentp;    (*count)++;    return COUNT;}int fill_userlist(){    static int i, i2;    struct user_info *u;    i2 = 0;    if (!friendmode) {        apply_ulist_addr((APPLY_UTMP_FUNC) full_utmp, (char *) &i2);    } else {        u = get_utmpent(utmpent);        for (i = 0; i < u->friendsnum; i++) {            if (u->friends_uid[i])                apply_utmpuid((APPLY_UTMP_FUNC) full_utmp, u->friends_uid[i], (char *) &i2);        }    }    range = i2;    return i2 == 0 ? -1 : 1;}int countusers(struct userec *uentp, char *arg){    char permstr[USER_TITLE_LEN];    if (uentp->numlogins != 0 && uleveltochar(permstr, uentp) != 0)        return COUNT;    return 0;}int allusers()

⌨️ 快捷键说明

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