-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathuser.c
1634 lines (1457 loc) · 41.6 KB
/
user.c
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define PWCU_IMPL
#include "bbs.h"
#ifdef CHESSCOUNTRY
static const char * const chess_photo_name[4] = {
"photo_fivechess",
"photo_cchess",
"photo_connect6",
"photo_go",
};
static const char * const chess_type[4] = {
"五子棋",
"象棋",
"六子旗",
"圍棋",
};
#endif
void
ban_usermail(const userec_t *u, const char *reason) {
assert(u);
if (!(u->userlevel & PERM_LOGINOK))
return;
if (!strchr(u->email, '@'))
return;
if (!reason || !*reason)
reason = "(站長忘了打)";
log_filef("etc/banemail", LOG_CREAT,
"# %s: %s (by %s)\nA%s\n",
u->userid, reason, cuser.userid, u->email);
}
int
kill_user(int num, const char *userid)
{
userec_t u;
char src[256], dst[256];
if(!userid || num<=0 ) return -1;
sethomepath(src, userid);
snprintf(dst, sizeof(dst), "tmp/%s", userid);
friend_delete_all(userid, FRIEND_ALOHA);
if (dashd(src) && Rename(src, dst) == 0) {
snprintf(src, sizeof(src), "/bin/rm -fr home/%c/%s >/dev/null 2>&1", userid[0], userid);
system(src);
}
memset(&u, 0, sizeof(userec_t));
log_usies("KILL", getuserid(num));
setuserid(num, "");
passwd_sync_update(num, &u);
return 0;
}
int
u_loginview(void)
{
int i, in;
unsigned int pbits = cuser.loginview;
do {
vs_hdr("設定進站畫面");
move(4, 0);
for (i = 0; i < NUMVIEWFILE && loginview_file[i][0]; i++) {
// ignore those without file name
if (!*loginview_file[i][0])
continue;
prints(" %c. %-20s %-15s \n", 'A' + i,
loginview_file[i][1], ((pbits >> i) & 1 ? "ˇ" : "X"));
}
in = i; // max i
i = vmsgf("請按 [A-%c] 切換設定,按 [Return] 結束:", 'A'+in-1);
if (i == '\r')
break;
// process i
i = tolower(i) - 'a';
if (i >= in || i < 0 || !*loginview_file[i][0]) {
bell();
continue;
}
pbits ^= (1 << i);
} while (1);
if (pbits != cuser.loginview) {
pwcuSetLoginView(pbits);
}
return 0;
}
/* TODO(piaip) 把這自動化? */
int u_cancelbadpost(void)
{
int day, prev = cuser.badpost;
char ans[3];
int pass_verify = 1;
// early check.
if(cuser.badpost == 0) {
vmsg("你並沒有退文.");
return 0;
}
// early check for race condition
// XXX 由於帳號API已同步化 (pwcuAPI*) 所以這個 check 可有可無
if(search_ulistn(usernum,2)) {
vmsg("請登出其他視窗, 否則不受理.");
return 0;
}
// XXX reload account here? (also simply optional)
pwcuReload();
prev = cuser.badpost; // since we reloaded, update cache again.
if (prev <= 0) return 0;
// early check for time (must do again later)
day = (now - cuser.timeremovebadpost ) / DAY_SECONDS;
if (day < BADPOST_CLEAR_DURATION) {
vmsgf("離下次可以申請解除尚有 %d 天。", BADPOST_CLEAR_DURATION - day);
return 0;
}
// 某些 user 會一直失敗,原因不明;由 vmsg 改為 getdata.
clear();
// 無聊的 disclaimer...
mvprints(1, 0, "預計退文將由 %d 篇變為 %d 篇,確定嗎[y/N]? ", prev, prev-1);
do {
if (vgets(ans, sizeof(ans), VGET_LOWERCASE | VGET_ASCII_ONLY) < 1 ||
ans[0] != 'y') { pass_verify = 0; break; }
mvprints(3, 0, "我願意遵守站方規定,組規,以及板規[y/N]? ");
if (vgets(ans, sizeof(ans), VGET_LOWERCASE | VGET_ASCII_ONLY) < 1 ||
ans[0] != 'y') { pass_verify = 0; break; }
mvprints(5, 0, "我願意尊重與不歧視族群,不鬧板,尊重各板主權力[y/N]?");
if (vgets(ans, sizeof(ans), VGET_LOWERCASE | VGET_ASCII_ONLY) < 1 ||
ans[0] != 'y') { pass_verify = 0; break; }
mvprints(7, 0, "我願意謹慎發表有意義言論,不謾罵攻擊,不跨板廣告[y/N]?");
if (vgets(ans, sizeof(ans), VGET_LOWERCASE | VGET_ASCII_ONLY) < 1 ||
ans[0] != 'y') { pass_verify = 0; break; }
} while (0);
if(!pass_verify)
{
vmsg("回答有誤,刪除失敗。請仔細看清站規與系統訊息後再來申請刪除.");
return 0;
}
if (pwcuCancelBadpost() != 0) {
vmsg("刪除失敗,請洽站務人員。");
return 0;
}
log_filef("log/cancelbadpost.log", LOG_CREAT,
"%s %s 刪除一篇退文 (%d -> %d 篇)\n",
Cdate(&now), cuser.userid, prev, cuser.badpost);
vmsgf("恭喜您已成功\刪除一篇退文 (由 %d 變為 %d 篇)",
prev, cuser.badpost);
return 0;
}
void
user_display(const userec_t * u, int adminmode)
{
int diff = 0;
char genbuf[200];
// Many fields are available (and have sync issue) in user->query,
// so let's minimize fields here.
clrtobot();
prints(
" " ANSI_COLOR(30;41) "┴┬┴┬┴┬" ANSI_RESET
" " ANSI_COLOR(1;30;45) " 使 用 者" " 資 料 "
" " ANSI_RESET " " ANSI_COLOR(30;41) "┴┬┴┬┴┬" ANSI_RESET
"\n");
prints("\t代號暱稱: %s (%s)\n", u->userid, u->nickname);
// This funciton is called with adminmode == 0 only to display the user's
// own information. Limit displaying register info of other users to
// PERM_ACCOUNT and PERM_ACCTREG.
// For PERM_ACCTREG, this is used when reviewing register forms.
if (!adminmode || HasUserPerm(PERM_ACCOUNTS | PERM_ACCTREG)) {
prints("\t真實姓名: %s", u->realname);
#if FOREIGN_REG_DAY > 0
prints(" %s%s",
u->uflag & UF_FOREIGN ? "(外籍: " : "",
u->uflag & UF_FOREIGN ?
(u->uflag & UF_LIVERIGHT) ? "永久居留)" : "未取得居留權)"
: "");
#elif defined(FOREIGN_REG)
prints(" %s", u->uflag & UF_FOREIGN ? "(外籍)" : "");
#endif
outs("\n"); // end of realname
prints("\t職業學歷: %s\n", u->career);
prints("\t居住地址: %s\n", u->address);
#ifdef USEREC_EMAIL_IS_CONTACT
prints("\t聯絡信箱: %s\n", u->email);
#else
prints("\t電子信箱: %s\n", u->email);
#endif
}
prints("\t%6s幣: %d " MONEYNAME "\n", BBSMNAME, u->money);
prints("\t是否成年: %s滿18歲\n", u->over_18 ? "已" : "未");
prints("\t註冊日期: %s (已滿 %d 天)\n",
Cdate(&u->firstlogin), (int)((now - u->firstlogin)/DAY_SECONDS));
// See comment above
if (adminmode && HasUserPerm(PERM_ACCOUNTS | PERM_ACCTREG)) {
strcpy(genbuf, "bTCPRp#@XWBA#VSM0123456789ABCDEF");
for (diff = 0; diff < 32; diff++)
if (!(u->userlevel & (1 << diff)))
genbuf[diff] = '-';
prints("\t帳號權限: %s\n", genbuf);
prints("\t認證資料: %s\n", u->justify);
}
sethomedir(genbuf, u->userid);
prints("\t私人信箱: %d 封 (購買信箱: %d 封)\n",
get_num_records(genbuf, sizeof(fileheader_t)),
u->exmailbox);
prints("\t使用記錄: " STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY
,u->numlogindays);
prints(" / 文章 %d 篇\n", u->numposts);
if (adminmode) {
prints("\t最後上線: %s (掛站時每日增加) / %s\n",
Cdate(&u->lastlogin), u->lasthost);
} else {
diff = (now - login_start_time) / 60;
prints("\t停留期間: %d 小時 %2d 分\n",
diff / 60, diff % 60);
}
/* Thor: 想看看這個 user 是那些板的板主 */
if (u->userlevel >= PERM_BM) {
int i;
boardheader_t *bhdr;
outs("\t擔任板主: ");
for (i = num_boards(), bhdr = bcache; i > 0; i--, bhdr++) {
if ( is_uBM(bhdr->BM, u->userid)) {
outs(bhdr->brdname);
outc(' ');
}
}
outc('\n');
}
// conditional fields
#ifdef ASSESS
prints("\t退文數目: %u\n", (unsigned int)u->badpost);
#endif // ASSESS
#ifdef CHESSCOUNTRY
{
int i, j;
FILE* fp;
for(i = 0; i < 2; ++i){
sethomefile(genbuf, u->userid, chess_photo_name[i]);
fp = fopen(genbuf, "r");
if(fp != NULL){
for(j = 0; j < 11; ++j)
fgets(genbuf, 200, fp);
fgets(genbuf, 200, fp);
prints("%12s棋國自我描述: %s", chess_type[i], genbuf + 11);
fclose(fp);
}
}
}
#endif
#ifdef PLAY_ANGEL
if (adminmode)
prints("\t小 天 使: %s\n",
u->myangel[0] ? u->myangel : "無");
#endif
outs(" " ANSI_COLOR(30;41) "┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴"
"┬┴┬┴┬┴┬" ANSI_RESET);
if (!adminmode)
{
outs((u->userlevel & PERM_LOGINOK) ?
"\n您的註冊程序已經完成,歡迎加入本站" :
"\n如果要提昇權限,請參考本站公佈欄辦理註冊");
} else {
// XXX list user pref here
int i;
static const char *uflag_desc[] = {
"拒收外信",
"新板加最愛",
"外藉",
"居留權",
};
static uint32_t uflag_mask[] = {
UF_REJ_OUTTAMAIL,
UF_FAV_ADDNEW,
UF_FOREIGN,
UF_LIVERIGHT,
};
char buf[PATHLEN];
prints("\n其它資訊: [%s]", (u->userlevel & PERM_LOGINOK) ?
"已註冊" : "未註冊");
sethomefile(buf, u->userid, FN_FORWARD);
if (dashs(buf) > 0)
outs("[自動轉寄]");
for (i = 0; (size_t)i < sizeof(uflag_mask)/sizeof(uflag_mask[0]); i++)
{
if (!(u->uflag & uflag_mask[i]))
continue;
prints("[%s]", uflag_desc[i]);
}
prints("\n");
}
}
void
mail_violatelaw(const char *crime, const char *police, const char *reason, const char *result)
{
char genbuf[200];
fileheader_t fhdr;
FILE *fp;
sendalert(crime, ALERT_PWD_PERM);
sethomepath(genbuf, crime);
stampfile(genbuf, &fhdr);
if (!(fp = fopen(genbuf, "w")))
return;
fprintf(fp, "作者: [" BBSMNAME "警察局]\n"
"標題: [報告] 違法報告\n"
"時間: %s\n", ctime4(&now));
fprintf(fp,
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\n"
"請到 " BN_LAW " 查詢相關法規資訊,並從主選單進入:\n"
"(P)lay【娛樂與休閒】=>(P)ay【" BBSMNAME2 "量販店 】=> (1)ViolateLaw 繳罰單\n"
"以繳交罰單。\n",
police, crime, reason, result);
fclose(fp);
strcpy(fhdr.title, "[報告] 違法判決報告");
strcpy(fhdr.owner, "[" BBSMNAME "警察局]");
sethomedir(genbuf, crime);
append_record(genbuf, &fhdr, sizeof(fhdr));
}
void
kick_all(const char *user)
{
userinfo_t *ui;
int num = searchuser(user, NULL), i=1;
while((ui = (userinfo_t *) search_ulistn(num, i)) != NULL)
{
if(ui == currutmp) i++;
if ((ui->pid <= 0 || kill(ui->pid, SIGHUP) == -1))
purge_utmp(ui);
log_usies("KICK ALL", user);
}
}
void
violate_law(userec_t * u, int unum)
{
char ans[4], ans2[4];
char reason[128];
move(1, 0);
clrtobot();
move(2, 0);
outs("(1)Cross-post (2)亂發廣告信 (3)亂發連鎖信\n");
outs("(4)騷擾站上使用者 (8)其他以罰單處置行為\n(9)砍 id 行為\n");
getdata(5, 0, "(0)結束", ans, 3, DOECHO);
switch (ans[0]) {
case '1':
strcpy(reason, "Cross-post");
break;
case '2':
strcpy(reason, "亂發廣告信");
break;
case '3':
strcpy(reason, "亂發連鎖信");
break;
case '4':
while (!getdata(7, 0, "請輸入被檢舉理由以示負責:", reason, 50, DOECHO));
strcat(reason, "[騷擾站上使用者]");
break;
case '8':
case '9':
while (!getdata(6, 0, "請輸入理由以示負責:", reason, 50, DOECHO));
break;
default:
return;
}
getdata(7, 0, msg_sure_ny, ans2, 3, LCECHO);
if (*ans2 != 'y')
return;
if (ans[0] == '9') {
if (HasUserPerm(PERM_POLICE) && u->numlogindays > 60)
{
vmsg("使用者" STR_LOGINDAYS "超過 60,無法砍除。");
return;
}
kick_all(u->userid);
delete_allpost(u->userid);
ban_usermail(u, reason);
kill_user(unum, u->userid);
post_violatelaw(u->userid, cuser.userid, reason, "砍除 ID");
} else {
kick_all(u->userid);
u->userlevel |= PERM_VIOLATELAW;
u->timeviolatelaw = now;
u->vl_count++;
passwd_sync_update(unum, u);
if (*ans == '1' || *ans == '2')
delete_allpost(u->userid);
post_violatelaw(u->userid, cuser.userid, reason, "罰單處分");
mail_violatelaw(u->userid, "站務警察", reason, "罰單處分");
}
pressanykey();
}
void Customize(void)
{
char done = 0;
int dirty = 0;
int key;
const int col_opt = 54;
/* cuser.uflag settings */
static const unsigned int masks1[] = {
UF_ADBANNER,
UF_ADBANNER_USONG,
UF_REJ_OUTTAMAIL,
UF_DEFBACKUP,
UF_SECURE_LOGIN,
UF_FAV_ADDNEW,
UF_FAV_NOHILIGHT,
UF_NO_MODMARK ,
UF_COLORED_MODMARK,
#ifdef DBCSAWARE
UF_DBCS_AWARE,
UF_DBCS_DROP_REPEAT,
UF_DBCS_NOINTRESC,
#endif
UF_CURSOR_ASCII,
#ifdef USE_PFTERM
UF_MENU_LIGHTBAR,
#endif
#ifdef PLAY_ANGEL
UF_NEW_ANGEL_PAGER,
#endif
0,
};
static const char* desc1[] = {
"ADBANNER 顯示動態看板",
"ADBANNER 顯示使用者心情點播(需開啟動態看板)",
"MAIL 拒收站外信",
"BACKUP 預設備份信件與其它記錄", //"與聊天記錄",
"LOGIN 只允許\使用安全連線(ex, ssh)登入",
"MYFAV 新板自動進我的最愛",
"MYFAV 單色顯示我的最愛",
"MODMARK 隱藏文章修改符號(推文/修文) (~)",
"MODMARK 使用色彩代替修改符號 (+)",
#ifdef DBCSAWARE
"DBCS 自動偵測雙位元字集(如全型中文)",
"DBCS 忽略連線程式為雙位元字集送出的重複按鍵",
"DBCS 禁止在雙位元中使用色碼(去除一字雙色)",
#endif
"CURSOR 使用新式簡化游標",
#ifdef USE_PFTERM
"CURSOR (實驗性)啟用光棒選單系統",
#endif
#ifdef PLAY_ANGEL
"ANGEL (小天使)啟用新的神諭呼叫器設定界面",
#endif
0,
};
while ( !done ) {
int i = 0, ia = 0; /* general uflags */
int iax = 0; /* extended flags */
clear();
showtitle("個人化設定", "個人化設定");
move(2, 0);
outs("您目前的個人化設定: \n");
prints(ANSI_COLOR(32)" %-11s%-*s%s" ANSI_RESET "\n",
"分類", col_opt-11,
"描述", "設定值");
move(4, 0);
/* print uflag options */
for (i = 0; masks1[i]; i++, ia++)
{
#ifdef PLAY_ANGEL
// XXX dirty hack: ANGEL must be in end of list.
if (strstr(desc1[i], "ANGEL ") == desc1[i] &&
!HasUserPerm(PERM_ANGEL)) {
ia--;
continue;
}
#endif
clrtoeol();
prints( ANSI_COLOR(1;36) "%c" ANSI_RESET
". %-*s%s\n",
'a' + ia,
col_opt,
desc1[i],
HasUserFlag(masks1[i]) ?
ANSI_COLOR(1;36) "是" ANSI_RESET : "否");
}
/* extended stuff */
{
static const char *wm[PAGER_UI_TYPES+1] =
{"一般", "進階", "未來", ""};
prints("%c. %-*s%s\n",
'1' + iax++,
col_opt,
"PAGER 水球模式",
wm[cuser.pager_ui_type % PAGER_UI_TYPES]);
#ifdef PLAY_ANGEL
// TODO move this to Ctrl-U Ctrl-P.
if (HasUserPerm(PERM_ANGEL))
{
static const char *msgs[ANGELPAUSE_MODES] = {
"開放 (接受所有小主人發問)",
"停收 (只接受已回應過的小主人的問題)",
"關閉 (停止接受所有小主人的問題)",
};
prints("%c. %s%s\n",
'1' + iax++,
"ANGEL 小天使神諭呼叫器: ",
msgs[currutmp->angelpause % ANGELPAUSE_MODES]);
}
#endif // PLAY_ANGEL
}
/* input */
key = vmsgf("請按 [a-%c,1-%c] 切換設定,其它任意鍵結束: ",
'a' + ia-1, '1' + iax -1);
if (key >= 'a' && key < 'a' + ia)
{
/* normal pref */
key -= 'a';
if (masks1[key] == UF_SECURE_LOGIN && !mbbsd_is_secure_connection()) {
vmsg("您必須使用安全連線才能修改此設定");
continue;
}
dirty = 1;
pwcuToggleUserFlag(masks1[key]);
continue;
}
if (key < '1' || key >= '1' + iax)
{
done = 1; continue;
}
/* extended keys */
key -= '1';
switch(key)
{
case 0:
{
pwcuSetPagerUIType((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER);
vmsg("修改水球模式後請正常離線再重新上線");
dirty = 1;
}
continue;
}
#ifdef PLAY_ANGEL
if( HasUserPerm(PERM_ANGEL) ){
if (key == iax-1)
{
angel_toggle_pause();
// dirty = 1; // pure utmp change does not need pw dirty
continue;
}
}
#endif //PLAY_ANGEL
}
grayout(1, b_lines-2, GRAYOUT_DARK);
move(b_lines-1, 0); clrtoeol();
if(dirty)
{
outs("設定已儲存。\n");
} else {
outs("結束設定。\n");
}
redrawwin(); // in case we changed output pref (like DBCS)
vmsg("設定完成");
}
static void set_chess(const char *name, int y,
uint16_t *p_win, uint16_t *p_lose, uint16_t *p_tie) {
char buf[STRLEN];
char prompt[STRLEN];
char *p;
char *strtok_pos;
snprintf(buf, sizeof(buf), "%d/%d/%d", *p_win, *p_lose, *p_tie);
snprintf(prompt, sizeof(prompt), "%s 戰績 勝/敗/和:", name);
if (!getdata_str(y, 0, prompt, buf, 5 * 3 + 3, DOECHO, buf))
return;
p = strtok_r(buf, "/\r\n", &strtok_pos);
if (!p) return;
*p_win = atoi(p);
p = strtok_r(NULL, "/\r\n", &strtok_pos);
if (!p) return;
*p_lose = atoi(p);
p = strtok_r(NULL, "/\r\n", &strtok_pos);
if (!p) return;
*p_tie = atoi(p);
}
void
uinfo_query(const char *orig_uid, int adminmode, int unum)
{
userec_t x;
int i = 0, fail;
int ans;
char buf[STRLEN];
char genbuf[200];
char pre_confirmed = 0;
int y = 0;
int perm_changed;
int money_changed;
bool update_emaildb = false;
int tokill = 0;
int changefrom = 0;
int xuid;
fail = 0;
money_changed = perm_changed = 0;
// verify unum
xuid = getuser(orig_uid, &x);
if (xuid == 0)
{
vmsgf("找不到使用者 %s。", orig_uid);
return;
}
if (xuid != unum)
{
move(b_lines-1, 0); clrtobot();
prints(ANSI_COLOR(1;31) "錯誤資訊: unum=%d (lookup xuid=%d)"
ANSI_RESET "\n", unum, xuid);
vmsg("系統錯誤: 使用者資料號碼 (unum) 不合。請至 " BN_BUGREPORT "報告。");
return;
}
if (strcmp(orig_uid, x.userid) != 0)
{
move(b_lines-1, 0); clrtobot();
prints(ANSI_COLOR(1;31) "錯誤資訊: userid=%s (lookup userid=%s)"
ANSI_RESET "\n", orig_uid, x.userid);
vmsg("系統錯誤: 使用者 ID 記錄不不合。請至 " BN_BUGREPORT "報告。");
return;
}
ans = vans(adminmode ?
#ifdef USEREC_EMAIL_IS_CONTACT
"(1)改資料(2)密碼(3)權限(4)砍帳(5)改ID(6)寵物(7)審判(8)退文(M)信箱(V)認證 " :
#else
"(1)改資料(2)密碼(3)權限(4)砍帳(5)改ID(6)寵物(7)審判(8)退文(V)認證 [0]結束 " :
#endif
#ifdef USEREC_EMAIL_IS_CONTACT
"請選擇 (1)修改資料 (2)設定密碼 (M)聯絡信箱 (V)認證資料 [0]結束 ");
#else
"請選擇 (1)修改資料 (2)設定密碼 (V)認證資料 [0]結束 ");
#endif
if (ans != '1' && ans != '2' && ans != 'v'
#ifdef USEREC_EMAIL_IS_CONTACT
&& ans != 'm'
#endif
&& !adminmode)
ans = '0';
if (ans == '1' || ans == '3') {
clear();
y = 1;
move(y++, 0);
outs(msg_uid);
outs(x.userid);
}
if (adminmode && (ans >= '1' && ans <= '8') &&
search_ulist(unum))
{
if (vans("使用者目前正在線上,修改資料會先踢下線。確定要繼續嗎? (y/N): ")
!= 'y')
return;
if (unum == usernum &&
vans("您正試圖修改自己的帳號;這可能會造成帳號損毀,確定要繼續嗎? (y/N): ")
!= 'y')
return;
}
switch (ans) {
#ifdef USEREC_EMAIL_IS_CONTACT
case 'm':
if (!adminmode) {
change_contact_email(0);
return;
} else {
char email[EMAILSZ];
move(y+1, 0);
outs("請注意在此修改聯絡信箱將跳過黑白名單檢查。");
if (!getdata_str(y++, 0, "請修改聯絡信箱: ", email, sizeof(email),
DOECHO, x.email))
return;
// Nothing changed.
if (!strcmp(email, x.email)) {
vmsg("E-Mail 與原本相同。");
fail++;
break;
}
char reason[30];
while (!getdata(y++, 0, "請輸入理由以示負責:",
reason, sizeof(reason), DOECHO));
if (vans(msg_sure_ny) != 'y') {
fail++;
break;
}
pre_confirmed = 1;
// Log change for security reasons.
char title[TTLEN], buf[STRLEN + EMAILSZ*2 + sizeof(reason)];
snprintf(title, sizeof(title), "%s 的聯絡信箱變更通知 (by %s)",
orig_uid, cuser.userid);
snprintf(buf, sizeof(buf), "站長 %s 修改 %s 的聯絡信箱 %s -> %s\n理由:%s\n",
cuser.userid, orig_uid, x.email, email, reason);
post_msg(BN_SECURITY, title, buf, "[系統安全局]");
// Notify user
strlcpy(title, "聯絡信箱變更通知", sizeof(title));
snprintf(buf, sizeof(buf), "您的聯絡信箱已變更為 %s\n", email);
mail_log2id_text(orig_uid, title, buf, cuser.userid, 1);
// Log to user log.
char logfn[PATHLEN];
sethomefile(logfn, x.userid, FN_USERSECURITY);
log_filef(logfn, LOG_CREAT, "%s %s (ContactEmail) %s -> %s\n",
Cdatelite(&now), "[Admin]", x.email, email);
strlcpy(x.email, email, sizeof(x.email));
}
break;
#endif
case '1':
move(0, 0);
outs("請逐項修改。");
getdata_buf(y++, 0, " 暱 稱 :", x.nickname,
sizeof(x.nickname), DOECHO);
if (adminmode) {
getdata_buf(y++, 0, "真實姓名:",
x.realname, sizeof(x.realname), DOECHO);
getdata_buf(y++, 0, "居住地址:",
x.address, sizeof(x.address), DOECHO);
getdata_buf(y++, 0, "學歷職業:", x.career,
sizeof(x.career), DOECHO);
}
do {
snprintf(buf, sizeof(buf), x.over_18 ? "y" : "n");
mvouts(y, 0, "本站部份看板可能有限制級內容只適合成年人士閱\讀。");
getdata_buf(y+1, 0,"您是否年滿十八歲並同意觀看此類看板"
"(若否請輸入n)[y/n]: ", buf, 3, LCECHO);
} while (buf[0] != 'y' && buf[0] != 'n');
x.over_18 = buf[0] == 'y' ? 1 : 0;
mvprints(y, 0, "是否年滿十八歲: %s\n\n", x.over_18 ? "是" : "否");
y++;
#ifdef PLAY_ANGEL
if (adminmode) {
const char* prompt;
userec_t the_angel;
if (x.myangel[0] == 0 || x.myangel[0] == '-' ||
(getuser(x.myangel, &the_angel) &&
the_angel.userlevel & PERM_ANGEL))
prompt = "小 天 使:";
else
prompt = "小天使(此帳號已無小天使資格):";
while (1) {
userec_t xuser;
getdata_str(y, 0, prompt, buf, IDLEN + 1, DOECHO,
x.myangel);
if (buf[0] == 0 || strcmp(buf, "-") == 0) {
strlcpy(x.myangel, buf, IDLEN + 1);
break;
}
if (strcmp(x.myangel, buf) == 0)
break;
if (getuser(buf, &xuser) && (xuser.userlevel & PERM_ANGEL)) {
strlcpy(x.myangel, xuser.userid, IDLEN + 1);
x.timesetangel = now;
log_filef(BBSHOME "/log/changeangel.log",LOG_CREAT,
"%s 站長 %s 修改 %s 的小天使為 %s\n",
Cdatelite(&now), cuser.userid, x.userid, x.myangel);
break;
}
prompt = "小 天 使:";
}
++y;
}
#endif
#ifdef CHESSCOUNTRY
{
int j, k;
FILE* fp;
for(j = 0; j < 2; ++j){
sethomefile(genbuf, x.userid, chess_photo_name[j]);
fp = fopen(genbuf, "r");
if(fp != NULL){
FILE* newfp;
char mybuf[200];
for(k = 0; k < 11; ++k)
fgets(genbuf, 200, fp);
fgets(genbuf, 200, fp);
chomp(genbuf);
snprintf(mybuf, 200, "%s棋國自我描述:", chess_type[j]);
getdata_buf(y, 0, mybuf, genbuf + 11, 80 - 11, DOECHO);
++y;
sethomefile(mybuf, x.userid, chess_photo_name[j]);
strcat(mybuf, ".new");
if((newfp = fopen(mybuf, "w")) != NULL){
rewind(fp);
for(k = 0; k < 11; ++k){
fgets(mybuf, 200, fp);
fputs(mybuf, newfp);
}
fputs(genbuf, newfp);
fputc('\n', newfp);
fclose(newfp);
sethomefile(genbuf, x.userid, chess_photo_name[j]);
sethomefile(mybuf, x.userid, chess_photo_name[j]);
strcat(mybuf, ".new");
Rename(mybuf, genbuf);
}
fclose(fp);
}
}
}
#endif
if (adminmode) {
int tmp;
if (HasUserPerm(PERM_BBSADM)) {
snprintf(genbuf, sizeof(genbuf), "%d", x.money);
if (getdata_str(y++, 0, BBSMNAME "幣:", buf, 10, DOECHO, genbuf))
if ((tmp = atol(buf)) != 0) {
if (tmp != x.money) {
money_changed = 1;
changefrom = x.money;
x.money = tmp;
}
}
}
snprintf(genbuf, sizeof(genbuf), "%d", x.exmailbox);
if (getdata_str(y++, 0, "購買信箱:", buf, 6,
DOECHO, genbuf))
if ((tmp = atoi(buf)) != 0)
x.exmailbox = (int)tmp;
getdata_buf(y++, 0, "認證資料:", x.justify,
sizeof(x.justify), DOECHO);
getdata_buf(y++, 0, "最近光臨機器:",
x.lasthost, sizeof(x.lasthost), DOECHO);
while (1) {
struct tm t = {0};
time4_t clk = x.lastlogin;
localtime4_r(&clk, &t);
snprintf(genbuf, sizeof(genbuf), "%04i/%02i/%02i %02i:%02i:%02i",
t.tm_year + 1900, t.tm_mon+1, t.tm_mday,
t.tm_hour, t.tm_min, t.tm_sec);
if (getdata_str(y, 0, "最近上線時間:", buf, 20, DOECHO, genbuf) != 0) {
int y, m, d, hh, mm, ss;
if (ParseDateTime(buf, &y, &m, &d, &hh, &mm, &ss))
continue;
t.tm_year = y-1900;
t.tm_mon = m-1;
t.tm_mday = d;
t.tm_hour = hh;
t.tm_min = mm;
t.tm_sec = ss;
clk = mktime(&t);
if (!clk)
continue;
x.lastlogin= clk;
}
y++;
break;
}
do {
int max_days = (x.lastlogin - x.firstlogin) / DAY_SECONDS;
snprintf(genbuf, sizeof(genbuf), "%d", x.numlogindays);
if (getdata_str(y++, 0, STR_LOGINDAYS ":", buf, 10, DOECHO, genbuf))
if ((tmp = atoi(buf)) >= 0)
x.numlogindays = tmp;
if ((int)x.numlogindays > max_days)
{
x.numlogindays = max_days;
vmsgf("根據此使用者最後上線時間,最大值為 %d.", max_days);
move(--y, 0); clrtobot();
continue;
}
break;
} while (1);
snprintf(genbuf, sizeof(genbuf), "%d", x.numposts);
if (getdata_str(y++, 0, "文章數目:", buf, 10, DOECHO, genbuf))
if ((tmp = atoi(buf)) >= 0)
x.numposts = tmp;
move(y-1, 0); clrtobot();
prints("文章數目: %d (退: %d, 修改退文數請選項8)\n",
x.numposts, x.badpost);
snprintf(genbuf, sizeof(genbuf), "%d", x.vl_count);
if (getdata_str(y++, 0, "違法記錄:", buf, 10, DOECHO, genbuf))
if ((tmp = atoi(buf)) >= 0)
x.vl_count = tmp;
set_chess("五子棋", y++, &x.five_win, &x.five_lose, &x.five_tie);
set_chess("象棋", y++, &x.chc_win, &x.chc_lose, &x.chc_tie);
set_chess("圍棋", y++, &x.go_win, &x.go_lose, &x.go_tie);
set_chess("暗棋", y++, &x.dark_win, &x.dark_lose, &x.dark_tie);
y -= 4; // rollback games set to get more space
move(y++, 0); clrtobot();
prints("棋類: 五子:%d/%d/%d 象:%d/%d/%d 圍:%d/%d/%d 暗:%d/%d/%d\n",
x.five_win, x.five_lose, x.five_tie,
x.chc_win, x.chc_lose, x.chc_tie,
x.go_win, x.go_lose, x.go_tie,
x.dark_win, x.dark_lose, x.dark_tie);
#ifdef FOREIGN_REG
if (getdata_str(y++, 0, "住在 1)台灣 2)其他:", buf, 2, DOECHO, x.uflag & UF_FOREIGN ? "2" : "1"))
if ((tmp = atoi(buf)) > 0){
if (tmp == 2){
x.uflag |= UF_FOREIGN;
}
else
x.uflag &= ~UF_FOREIGN;
}
if (x.uflag & UF_FOREIGN)
if (getdata_str(y++, 0, "永久居留權 1)是 2)否:", buf, 2, DOECHO, x.uflag & UF_LIVERIGHT ? "1" : "2")){
if ((tmp = atoi(buf)) > 0){
if (tmp == 1){
x.uflag |= UF_LIVERIGHT;
x.userlevel |= (PERM_LOGINOK | PERM_POST);
}
else{
x.uflag &= ~UF_LIVERIGHT;
x.userlevel &= ~(PERM_LOGINOK | PERM_POST);
}
}
}
#endif
}
if (!adminmode) {
mvouts(b_lines-1, 0,
"其它資料若需修改請洽 " BN_ID_PROBLEM " 看板\n");
}
break;
case '2':