summaryrefslogtreecommitdiffstats
path: root/util/initbbs.c
blob: a8468290cd718b8234c706e00589251e014c5b6b (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* $Id$ */
#include "bbs.h"

static void initDir() {
    mkdir("adm", 0755);
    mkdir("boards", 0755);
    mkdir("etc", 0755);
    mkdir("man", 0755);
    mkdir("man/boards", 0755);
    mkdir("out", 0755);
    mkdir("tmp", 0755);
    mkdir("run", 0755);
}

static void initHome() {
    int i;
    char buf[256];
    
    mkdir("home", 0755);
    strcpy(buf, "home/?");
    for(i = 0; i < 26; i++) {
    buf[5] = 'A' + i;
    mkdir(buf, 0755);
    buf[5] = 'a' + i;
    mkdir(buf, 0755);
    }
}

static void initBoardsDIR() {
    int i;
    char buf[256];
    
    mkdir("boards", 0755);
    strcpy(buf, "boards/?");
    for(i = 0; i < 26; i++) {
    buf[7] = 'A' + i;
    mkdir(buf, 0755);
    buf[7] = 'a' + i;
    mkdir(buf, 0755);
    }
}

static void initManDIR() {
    int i;
    char buf[256];
    
    mkdir("man", 0755);
    mkdir("man/boards", 0755);
    strcpy(buf, "man/boards/?");
    for(i = 0; i < 26; i++) {
    buf[11] = 'A' + i;
    mkdir(buf, 0755);
    buf[11] = 'a' + i;
    mkdir(buf, 0755);
    }
}

static void initPasswds() {
    int i;
    userec_t u;
    FILE *fp = fopen(".PASSWDS", "w");
    
    memset(&u, 0, sizeof(u));
    if(fp) {
    for(i = 0; i < MAX_USERS; i++)
        fwrite(&u, sizeof(u), 1, fp);
    fclose(fp);
    }
}

static void newboard(FILE *fp, boardheader_t *b) {
    char buf[256];
    
    fwrite(b, sizeof(boardheader_t), 1, fp);
    sprintf(buf, "boards/%c/%s", b->brdname[0], b->brdname);
    mkdir(buf, 0755);
    sprintf(buf, "man/boards/%c/%s", b->brdname[0], b->brdname);
    mkdir(buf, 0755);
}

static void initBoards() {
    FILE *fp = fopen(".BRD", "w");
    boardheader_t b;
    
    if(fp) {
    memset(&b, 0, sizeof(b));
    
    strcpy(b.brdname, "SYSOP");
    strcpy(b.title, "嘰哩 ◎站長好!");
    b.brdattr = BRD_POSTMASK | BRD_NOTRAN | BRD_NOZAP;
    b.level = 0;
    b.gid = 2;
    newboard(fp, &b);

    strcpy(b.brdname, "1...........");
    strcpy(b.title, ".... Σ中央政府  《高壓危險,非人可敵》");
    b.brdattr = BRD_GROUPBOARD;
    b.level = PERM_SYSOP;
    b.gid = 1;
    newboard(fp, &b);
    
    strcpy(b.brdname, "junk");
    strcpy(b.title, "發電 ◎雜七雜八的垃圾");
    b.brdattr = BRD_NOTRAN;
    b.level = PERM_SYSOP;
    b.gid = 2;
    newboard(fp, &b);
    
    strcpy(b.brdname, "Security");
    strcpy(b.title, "發電 ◎站內系統安全");
    b.brdattr = BRD_NOTRAN;
    b.level = PERM_SYSOP;
    b.gid = 2;
    newboard(fp, &b);
    
    strcpy(b.brdname, "2...........");
    strcpy(b.title, ".... Σ市民廣場     報告  站長  ㄜ!");
    b.brdattr = BRD_GROUPBOARD;
    b.level = 0;
    b.gid = 1;
    newboard(fp, &b);
    
    strcpy(b.brdname, "ALLPOST");
    strcpy(b.title, "嘰哩 ◎跨板式LOCAL新文章");
    b.brdattr = BRD_POSTMASK | BRD_NOTRAN;
    b.level = PERM_SYSOP;
    b.gid = 5;
    newboard(fp, &b);
    
    strcpy(b.brdname, "deleted");
    strcpy(b.title, "嘰哩 ◎資源回收筒");
    b.brdattr = BRD_NOTRAN;
    b.level = PERM_BM;
    b.gid = 5;
    newboard(fp, &b);
    
    strcpy(b.brdname, "Note");
    strcpy(b.title, "嘰哩 ◎動態看板及歌曲投稿");
    b.brdattr = BRD_NOTRAN;
    b.level = 0;
    b.gid = 5;
    newboard(fp, &b);
    
    strcpy(b.brdname, "Record");
    strcpy(b.title, "嘰哩 ◎我們的成果");
    b.brdattr = BRD_NOTRAN | BRD_POSTMASK;
    b.level = 0;
    b.gid = 5;
    newboard(fp, &b);
    
    
    strcpy(b.brdname, "WhoAmI");
    strcpy(b.title, "嘰哩 ◎呵呵,猜猜我是誰!");
    b.brdattr = BRD_NOTRAN;
    b.level = 0;
    b.gid = 5;
    newboard(fp, &b);
    
    strcpy(b.brdname, "EditExp");
    strcpy(b.title, "嘰哩 ◎範本精靈投稿區");
    b.brdattr = BRD_NOTRAN;
    b.level = 0;
    b.gid = 5;
    newboard(fp, &b);
    
#ifdef GLOBAL_DIGEST
    strcpy(b.brdname, GLOBAL_DIGEST);
    strcpy(b.title, "文摘 ◎" BBSNAME "文摘 好文的收集地");
    b.brdattr = BRD_NOTRAN | BRD_POSTMASK;
    b.level = PERM_SYSOP;
    b.gid = 5;
    newboard(fp, &b);
#endif

#ifdef GLOBAL_FIVECHESS_LOG
    strcpy(b.brdname, GLOBAL_FIVECHESS_LOG);
    strcpy(b.title, "棋藝 ◎" BBSNAME "五子棋譜 站上對局全紀錄");
    b.brdattr = BRD_NOTRAN | BRD_POSTMASK;
    b.level = PERM_SYSOP;
    b.gid = 5;
    newboard(fp, &b);
#endif

    fclose(fp);
    }
}

static void initMan() {
    FILE *fp;
    fileheader_t f;
    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    
    memset(&f, 0, sizeof(f));
    strcpy(f.owner, "SYSOP");
    sprintf(f.date, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday);
    f.multi.money = 0;
    f.filemode = 0;
    
    if((fp = fopen("man/boards/N/Note/.DIR", "w"))) {
    strcpy(f.filename, "SONGBOOK");
    strcpy(f.title, "◆ 【點 歌 歌 本】");
    fwrite(&f, sizeof(f), 1, fp);
    mkdir("man/boards/N/Note/SONGBOOK", 0755);
    
    strcpy(f.filename, "SONGO");
    strcpy(f.title, "◆ <點歌> 動態看板");
    fwrite(&f, sizeof(f), 1, fp);
    mkdir("man/boards/N/Note/SONGO", 0755);
    
    strcpy(f.filename, "SYS");
    strcpy(f.title, "◆ <系統> 動態看板");
    fwrite(&f, sizeof(f), 1, fp);
    mkdir("man/boards/N/Note/SYS", 0755);
    
    strcpy(f.filename, "AD");
    strcpy(f.title, "◆ <廣告> 動態看板");
    fwrite(&f, sizeof(f), 1, fp);
    mkdir("man/boards/N/Note/AD", 0755);
    
    strcpy(f.filename, "NEWS");
    strcpy(f.title, "◆ <新聞> 動態看板");
    fwrite(&f, sizeof(f), 1, fp);
    mkdir("man/boards/N/Note/NEWS", 0755);
    
    fclose(fp);
    }
    
}

static void initSymLink() {
    symlink(BBSHOME "/man/boards/N/Note/SONGBOOK", BBSHOME "/etc/SONGBOOK");
    symlink(BBSHOME "/man/boards/N/Note/SONGO", BBSHOME "/etc/SONGO");
    symlink(BBSHOME "/man/boards/E/EditExp", BBSHOME "/etc/editexp");
}

static void initHistory() {
    FILE *fp = fopen("etc/history.data", "w");
    
    if(fp) {
    fprintf(fp, "0 0 0 0");
    fclose(fp);
    }
}

int main(int argc, char **argv)
{
    if( argc != 2 || strcmp(argv[1], "-DoIt") != 0 ){
    fprintf(stderr,
        "警告!  initbbs只用在「第一次安裝」的時候.\n"
        "若您的站台已經上線,  initbbs將會破壞掉原有資料!\n\n"
        "將把 BBS 安裝在 " BBSHOME "\n\n"
        "確定要執行, 請使用 initbbs -DoIt\n");
    return 1;
    }

    if(chdir(BBSHOME)) {
    perror(BBSHOME);
    exit(1);
    }
    
    initDir();
    initHome();
    initBoardsDIR();
    initManDIR();
    initPasswds();
    initBoards();
    initMan();
    initSymLink();
    initHistory();
    
    return 0;
}