summaryrefslogtreecommitdiffstats
path: root/mbbsd/syspost.c
blob: f6b30551b1d2acc53b8767f426ed3d0f8b00f760 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* $Id$ */
#include "bbs.h"

int
post_msg(char *bname, char *title, char *msg, char *author)
{
    FILE           *fp;
    int             bid;
    fileheader_t    fhdr;
    char            genbuf[256];

    /* 在 bname 板發表新文章 */
    snprintf(genbuf, sizeof(genbuf), "boards/%c/%s", bname[0], bname);
    stampfile(genbuf, &fhdr);
    fp = fopen(genbuf, "w");

    if (!fp)
    return -1;

    fprintf(fp, I18N[2551], author, bname, title);
    fprintf(fp, I18N[2552], ctime(&now));

    /* 文章的內容 */
    fprintf(fp, "%s", msg);
    fclose(fp);

    /* 將檔案加入列表 */
    strlcpy(fhdr.title, title, sizeof(fhdr.title));
    strlcpy(fhdr.owner, author, sizeof(fhdr.owner));
    setbdir(genbuf, bname);
    if (append_record(genbuf, &fhdr, sizeof(fhdr)) != -1)
    if ((bid = getbnum(bname)) > 0)
        setbtotal(bid);
    return 0;
}

int
post_file(char *bname, char *title, char *filename, char *author)
{
    int             size = dashs(filename);
    char           *msg;
    FILE           *fp;

    if (size <= 0)
    return -1;
    if (!(fp = fopen(filename, "r")))
    return -1;
    msg = (char *)malloc(size + 1);
    size = fread(msg, 1, size, fp);
    msg[size] = 0;
    size = post_msg(bname, title, msg, author);
    fclose(fp);
    free(msg);
    return size;
}

void
post_change_perm(int oldperm, int newperm, char *sysopid, char *userid)
{
    FILE           *fp;
    fileheader_t    fhdr;
    char            genbuf[200], reason[30];
    int             i, flag = 0;

    strlcpy(genbuf, "boards/S/Security", sizeof(genbuf));
    stampfile(genbuf, &fhdr);
    if (!(fp = fopen(genbuf, "w")))
    return;

    fprintf(fp, I18N[2553], ctime(&now));
    for (i = 5; i < NUMPERMS; i++) {
    if (((oldperm >> i) & 1) != ((newperm >> i) & 1)) {
        fprintf(fp, I18N[2554],
            sysopid,
           (((oldperm >> i) & 1) ? I18N[2555] : I18N[2556]),
            userid, I18N[str_permid[i]]);
        flag++;
    }
    }

    if (flag) {
    clrtobot();
    clear();
    while (!getdata_str(5, 0, I18N[2557],
                reason, sizeof(reason), DOECHO, I18N[2558]));
    fprintf(fp, I18N[2559],
        cuser.userid, reason);
    fclose(fp);

    snprintf(fhdr.title, sizeof(fhdr.title),
         I18N[2560],
         cuser.userid, userid);
    strlcpy(fhdr.owner, I18N[2561], sizeof(fhdr.owner));
    append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr));
    } else
    fclose(fp);
}

void
post_violatelaw(char *crime, char *police, char *reason, char *result)
{
    char            genbuf[200];
    fileheader_t    fhdr;
    FILE           *fp;
/*
    strlcpy(genbuf, "boards/S/Security", sizeof(genbuf));
    stampfile(genbuf, &fhdr);
    if (!(fp = fopen(genbuf, "w")))
    return;
    fprintf(fp, "作者: [Ptt法院] 看板: Security\n"
        "標題: [報告] %-20s 違法判決報告\n"
        "時間: %s\n"
        "\033[1;32m%s\033[m判決:\n     \033[1;32m%s\033[m"
        "因\033[1;35m%s\033[m行為,\n違反本站站規,處以\033[1;35m%s\033[m,特此公告",
        crime, ctime(&now), police, crime, reason, result);
    fclose(fp);
    snprintf(fhdr.title, sizeof(fhdr.title),
         "[報告] %-20s 違法判決報告", crime);
    strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner));
    append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr));

*/
    strlcpy(genbuf, "boards/V/ViolateLaw", sizeof(genbuf));
    stampfile(genbuf, &fhdr);
    if (!(fp = fopen(genbuf, "w")))
    return;
    fprintf(fp, I18N[2562],
        crime, ctime(&now), police, crime, reason, result);
    fclose(fp);
    snprintf(fhdr.title, sizeof(fhdr.title),
         I18N[2563], crime);
    strlcpy(fhdr.owner, I18N[2564], sizeof(fhdr.owner));

    append_record("boards/V/ViolateLaw/.DIR", &fhdr, sizeof(fhdr));

}

void
post_newboard(char *bgroup, char *bname, char *bms)
{
    char            genbuf[256], title[128];
    snprintf(title, sizeof(title), I18N[2565], bname);
    snprintf(genbuf, sizeof(genbuf),
         I18N[2566],
         cuser.userid, bname, bgroup, bms);
    post_msg("Record", title, genbuf, I18N[2567]);
}

void
give_money_post(char *userid, int money)
{
    FILE           *fp;
    fileheader_t    fhdr;
    time_t          now = time(0);
    char            genbuf[200];

    strlcpy(genbuf, "boards/S/Security", sizeof(genbuf));
    stampfile(genbuf, &fhdr);
    if (!(fp = fopen(genbuf, "w")))
    return;
    fprintf(fp, I18N[2568], cuser.userid, ctime(&now));
    clrtobot();
    clear();
    fprintf(fp, I18N[2569],
        cuser.userid, userid, money);

    fclose(fp);
    snprintf(fhdr.title, sizeof(fhdr.title), I18N[2570],
         cuser.userid);
    strlcpy(fhdr.owner, I18N[2571], sizeof(fhdr.owner));
    append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr));
}