summaryrefslogtreecommitdiffstats
path: root/util/birth.c
blob: 20bd65c03050976740027280a5fda90a9ddc9df8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*     壽星程式               96 10/11            */

#define _UTIL_C_
#include "bbs.h"

#define OUTFILE    BBSHOME "/etc/birth.today"

struct userec_t cuser;

int bad_user_id(char *userid) {
    register char ch;
    int j;
    if (strlen(cuser.userid) < 2 || !isalpha(cuser.userid[0]))
    return 1;
    if (cuser.numlogins == 0 || cuser.numlogins > 15000)
    return 1;
    if (cuser.numposts > 15000)
    return 1;
    for (j = 1; (ch = cuser.userid[j]); j++)
    {
    if (!isalnum(ch))
        return 1;
    }
    return 0;
}

int Link(char *src, char *dst) {
    char cmd[200];

    if (link(src, dst) == 0)
    return 0;

    sprintf(cmd, "/bin/cp -R %s %s", src, dst);
    return system(cmd);
}

int main(argc, argv)
    int argc;
    char **argv;
{
    FILE *fp1;
    fileheader_t mymail;
    //int i, day = 0;
    time_t now;
    struct tm *ptime;
    int j;

    attach_SHM();
    now = time(NULL);       /* back to ancent */
    ptime = localtime(&now);

    if(passwd_init())
    exit(1);

    printf("*製表\n");
    fp1 = fopen(OUTFILE, "w");

    fprintf(fp1, "\n                      "
        "★★★★★★ 壽星大觀 "
        "★★★★★★ \n\n");
    fprintf(fp1, "【本日壽星】 \n");
    for(j = 1; j <= MAX_USERS; j++) {
    passwd_query(j, &cuser);
    if (bad_user_id(NULL))
        continue;
    if (cuser.month == ptime->tm_mon + 1)
    {
        if (cuser.day == ptime->tm_mday)
        {
        char genbuf[200];
        sprintf(genbuf, BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid);
        stampfile(genbuf, &mymail);
        strcpy(mymail.owner, BBSNAME);
        strcpy(mymail.title, "!! 生日快樂 !!");
        unlink(genbuf);
        Link(BBSHOME "/etc/Welcome_birth", genbuf);
        sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid);
        append_record(genbuf, &mymail, sizeof(mymail));
        if ((cuser.numlogins + cuser.numposts) < 20)
            continue;

                fprintf(fp1,
         "   [%2d/%-2d] %-14s %-24s login:%-5d post:%-5d\n",
            ptime->tm_mon + 1, ptime->tm_mday, cuser.userid,
            cuser.username, cuser.numlogins, cuser.numposts);
        }
    }
    }
    fclose(fp1);
    return 0;
}