summaryrefslogtreecommitdiffstats
path: root/mbbsd/syspost.c
blob: 9ced99187a4d669735c0d78dfc2fd03b564e5c5a (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
/* $Id$ */
#include "bbs.h"

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

    /* 在 bname 板發表新文章 */
    setbpath(fname, bname);
    stampfile(fname, &fhdr);
    fp = fopen(fname, "w");

    if (!fp)
    return -1;

    fprintf(fp, "作者: %s 看板: %s\n標題: %s \n", author, bname, title);
    fprintf(fp, "時間: %s\n", ctime4(&now));

    /* 文章的內容 */
    fputs(msg, fp);
    fclose(fp);

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

int
post_file(const char *bname, const char *title, const char *filename, const 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, const char *sysopid, const char *userid)
{
    char genbuf[(NUMPERMS+1) * STRLEN*2] = "", reason[30] = "";
    char title[TTLEN+1];
    char *s = genbuf;
    int  i, flag = 0;

    // generate log (warning: each line should <= STRLEN*2)
    for (i = 0; i < NUMPERMS; i++) {
    if (((oldperm >> i) & 1) != ((newperm >> i) & 1)) {
        sprintf(s, "   站長" ANSI_COLOR(1;32) "%s%s%s%s" ANSI_RESET "的權限\n",
            sysopid,
           (((oldperm >> i) & 1) ? ANSI_COLOR(1;33) "關閉" : ANSI_COLOR(1;33) "開啟"),
            userid, str_permid[i]);
        s += strlen(s);
        flag++;
    }
    }

    if (!flag) // nothing changed
    return;

    clrtobot();
    clear();
    while (!getdata(5, 0, "請輸入理由以示負責:",
        reason, sizeof(reason), DOECHO));
    sprintf(s, "\n   " ANSI_COLOR(1;37) "站長%s修改權限理由是:%s" ANSI_RESET,
        cuser.userid, reason);

    snprintf(title, sizeof(title), "[公安報告] 站長%s修改%s權限報告",
        cuser.userid, userid);

    post_msg(GLOBAL_SECURITY, title, genbuf, "[系統安全局]");
}

void
post_violatelaw(const char *crime, const char *police, const char *reason, const char *result)
{
    char title[TTLEN+1];
    char msg[200];

    snprintf(title, sizeof(title), "[報告] %s:%-*s 判決", crime,
        (int)(37 - strlen(reason) - strlen(crime)), reason);

    snprintf(msg, sizeof(msg), 
        ANSI_COLOR(1;32) "%s" ANSI_RESET "判決:\n"
        "     " ANSI_COLOR(1;32) "%s" ANSI_RESET "因" ANSI_COLOR(1;35) "%s" ANSI_RESET "行為,\n"
        "違反本站站規,處以" ANSI_COLOR(1;35) "%s" ANSI_RESET ",特此公告\n",
        police, crime, reason, result);

    if (!strstr(police, "警察")) {
    post_msg("PoliceLog", title, msg, "[" BBSMNAME "法院]");

    snprintf(msg, sizeof(msg), 
        ANSI_COLOR(1;32) "%s" ANSI_RESET "判決:\n"
        "     " ANSI_COLOR(1;32) "%s" ANSI_RESET "因" ANSI_COLOR(1;35) "%s" ANSI_RESET "行為,\n"
        "違反本站站規,處以" ANSI_COLOR(1;35) "%s" ANSI_RESET ",特此公告\n",
        "站務警察", crime, reason, result);
    }

    post_msg("ViolateLaw", title, msg, "[" BBSMNAME "法院]");
}

void
post_newboard(const char *bgroup, const char *bname, const char *bms)
{
    char            genbuf[256], title[TTLEN+1];

    snprintf(title, sizeof(title), "[新板成立] %s", bname);
    snprintf(genbuf, sizeof(genbuf),
         "%s 開了一個新板 %s : %s\n\n新任板主為 %s\n\n恭喜*^_^*\n",
         cuser.userid, bname, bgroup, bms);

    post_msg("Record", title, genbuf, "[系統]");
}

void
post_policelog(const char *bname, const char *atitle, const char *action, const char *reason, const int toggle)
{
    char            genbuf[256], title[TTLEN+1];

    snprintf(title, sizeof(title), "[%s][%s] %s by %s", action, toggle ? "開啟" : "關閉", bname, cuser.userid);
    snprintf(genbuf, sizeof(genbuf),
         "%s (%s) %s %s 看板 %s 功\能\n原因 : %s\n%s%s\n",
         cuser.userid, fromhost, toggle ? "開啟" : "關閉", bname, action,
         reason, atitle ? "文章標題 : " : "", atitle ? atitle : "");

    post_msg("PoliceLog", title, genbuf, "[系統]");
}