forked from 7jXlqS-hmpBUGsK/iscabbs-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_aide.c
757 lines (618 loc) · 17.3 KB
/
doc_aide.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
/*
* doc_aide.c - Handles functions of the sysop (formerly aide) menu.
*/
#include "defs.h"
#include "ext.h"
static void aide_logout(void);
static void createroom(void);
static void deleteroom(void);
static void editdesc(void);
static void editroom(void);
static void invite(void);
static void kickout (void);
static void logout_all (void);
static void whoknows(void);
/**********************************************************************
* aide menu
* Access to this menu is restricted to those with aide status.
* Wizards can do everything
* System Aides can do all but aideify
* Room Aides can only get here if it's their room and they can
* NOT do <A>ideify <C>reateroom <Z>ap room.
**********************************************************************/
void
aide_menu(void)
{
int chr = '?';
/* Can't get here unless you're at least a room aide for this room */
while (chr != 'M' && chr != ' ' && chr != '\n')
{
switch (chr)
{
// case 'B':
// if (ouruser->f_prog || ouruser->f_admin)
// system("/bin/bash -il");
// else
// chr = 0;
// break;
case 'C':
my_printf("Create new forum\n");
createroom();
loadroom();
break;
case 'D':
my_printf("Edit forum description\n\n");
editdesc();
break;
case 'E':
my_printf("Edit forum\n");
editroom();
break;
case 'H':
my_printf("Help!\n");
if (ouruser->f_admin)
help("aidemenu", YES);
else
help("fmmenu", YES);
break;
case 'I':
my_printf("Invite user\n");
invite();
break;
case 'K':
my_printf("Kick out user\n");
kickout();
break;
case 'L':
if (ouruser->f_admin)
{
my_printf("Logout all users\n");
logout_all();
break;
}
/* FALL THRU */
case 'l':
my_printf("Logout user\n");
aide_logout();
break;
case 'O':
show_online(1);
break;
case 'S':
searchtool();
break;
case 'W':
whoknows();
break;
case 'X':
if (ouruser->f_prog || ouruser->f_admin)
xbroadcast();
else
chr = 0;
break;
case 'Z':
my_printf("Zap (delete) forum\n");
deleteroom();
loadroom();
break;
case '?':
case '/':
if (ouruser->f_admin)
help("aidecmd", NO);
else
help("fmcmd", NO);
break;
default:
break;
}
if (chr)
colorize("\n@Y[%s]@M Forum command ->@G ", msg->room[curr].name);
if (ouruser->f_admin)
chr = get_single_quiet("BCDEHIKlLMOSWXZ* \n/?");
else
chr = get_single_quiet("DEHIKMW \n/?");
} /* end of while loop */
my_printf("Forum level\n");
}
/**********************************************************************
* createroom
**********************************************************************/
static void
createroom(void)
{
int i;
int found;
char *newroom;
char opt;
int rm_nbr;
int qpos;
char pas[11];
if (ouruser->f_novice)
{
my_printf("Are you sure? (Y/N) ->");
if (!yesno(-1))
return;
}
newroom = get_name("Name for new forum? ", 3);
if (!*newroom)
return;
found = NO;
/* Simultaneously search for a duplicate and the first unused room */
for (qpos = rm_nbr = 0; rm_nbr < MAXROOMS && !found; ++rm_nbr)
{
/* quit searching if you find a duplicate */
if ((msg->room[rm_nbr].flags & QR_INUSE)
&& !strcmp(msg->room[rm_nbr].name, newroom))
found = YES;
/* get position of FIRST available room */
if (!(msg->room[rm_nbr].flags & QR_INUSE) && !qpos)
qpos = rm_nbr;
}
if (found)
{
my_printf("There is already a forum by that name\n");
return;
}
/* qpos never gets set if all rooms are in use */
/* the rest of the function depends on qpos being set -sf */
if (!qpos)
{
my_printf("Sorry, no space is available for another forum.\n");
return;
}
/* Set the access for the new room */
help("roomaccess", NO);
my_printf("\n<1>Public <2>Guess name <3>Passworded <4>Private\n");
my_printf("Enter forum type-> ");
opt = get_single_quiet("1234");
my_printf("\n\n\042%s\042, will be a", newroom);
switch (opt)
{
case 1:
my_printf(" public");
break;
case 2:
my_printf(" guess-name");
break;
case 3:
my_printf(" passworded");
break;
case 4:
my_printf(" private");
break;
}
my_printf(" forum\n");
my_printf("Install it? (y/n) -> ");
if (!yesno(-1))
{
my_printf("Create Forum aborted\n");
return;
}
if (opt == 3)
{
get_string ("Enter Password: ", -10, pas, -1);
}
/* delete & zero room info & whoknows files if they exist */
/* NOTE: Need exclusive access here! */
// TODO: there's a better way to do this.
{
char * filename = my_sprintf(NULL,"%sroom%d", DESCDIR, qpos);
unlink(filename);
open(filename, O_WRONLY | O_CREAT, 0640);
free(filename);
}
{
char * filename = my_sprintf(NULL,"%srm%d", WHODIR, qpos);
unlink(filename);
open(filename, O_WRONLY | O_CREAT, 0640);
free(filename);
}
locks(SEM_MSG);
if (msg->room[qpos].flags & QR_INUSE)
{
unlocks(SEM_MSG);
my_printf("\nForum slot taken, please try again.\n");
return;
}
curr = qpos;
strcpy(msg->room[curr].name, newroom);
msg->room[curr].highest = 0L;
msg->room[curr].posted = 0L;
if (++msg->room[curr].gen == 100)
msg->room[curr].gen = 10;
/* want a clean slate to work with */
msg->room[curr].flags = QR_INUSE;
if (opt > '1')
msg->room[curr].flags |= QR_PRIVATE;
if (opt == '2')
msg->room[curr].flags |= QR_GUESSNAME;
if (opt == '3')
{
msg->room[curr].flags |= QR_PASSWORD;
strcpy (msg->room[curr].passwd, pas);
}
for (i = 0; i < MSGSPERRM; i++)
{
msg->room[curr].pos[i] = 0;
msg->room[curr].num[i]= 0;
msg->room[curr].chron[i]= 0;
}
unlocks(SEM_MSG);
my_printf("Use edit description to assign forum moderator.\n");
my_printf("\n%s> (#%d) created as a", msg->room[curr].name, curr);
if (!(msg->room[curr].flags & QR_PRIVATE))
my_printf(" public");
if (msg->room[curr].flags & QR_PRIVATE)
my_printf(" [private]");
if (msg->room[curr].flags & QR_GUESSNAME)
my_printf(" [guessname]");
if (msg->room[curr].flags & QR_PASSWORD)
my_printf(" [passworded]");
my_printf(" forum\n");
/* Join user to the room that was just created */
ouruser->forget[curr] = TWILIGHTZONE;
ouruser->generation[curr] = msg->room[curr].gen;
return;
}
/**********************************************************************
* deleteroom
**********************************************************************/
static void
deleteroom(void)
{
char confirm[7];
if (curr <= AIDE_RM_NBR)
{
my_printf("Can't kill this forum.\n");
return;
}
get_string("Type 'DELETE' to kill this forum -> ", 6, confirm, -1);
if (strcmp(confirm, "DELETE"))
return;
my_putchar('\n');
locks(-1);
msg->room[curr].flags = 0;
char * filename = my_sprintf(NULL,"%sroom%d", DESCDIR, curr);
unlink(filename);
free(filename);
filename = my_sprintf(NULL,"%srm%d", WHODIR, curr);
unlink(filename);
free(filename);
unlocks(-1);
/* you just nuked the room, need to go somewhere! */
curr = LOBBY_RM_NBR;
}
/**********************************************************************
* edit room description
* Ask user if they want to edit <R>oom aide only, <D>escription only,
* <B>oth, or <Q>uit.
* Contingent on option chosen, edit the item(s). When done, write
* the description to the descfile.
* raname is taken either from reading the description or set anew.
* If a new aide is chosen, read his/her user file and assign ->usernum
* to be roomaide.
**********************************************************************/
static void
editdesc(void)
{
char choice = '0';
int dfd; /* desc file descriptor */
int dummy; /* readmsg() needs this: returns YES/NO */
int err; /* makemessage returns this */
char raname[MAXALIAS+1];
int upload;
char *cp;
struct mheader *mh;
size_t size;
unsigned char *infop;
struct user *tmpuser;
char * descfile = my_sprintf(NULL,"%sroom%d", DESCDIR, curr);
char * newdescfile = my_sprintf(NULL,"%sroom%d.NEW", DESCDIR, curr);
size = 0;
if (!(infop = mmap_file(descfile, &size)) || !size)
{
colorize("@RDescription doesn't yet exist@G\n");
choice = 'B';
}
else
{
readmessage(infop, &dummy, raname, FALSE, 0);
munmap((void *)infop, size);
}
/* if it's a new description, don't bother prompting for choice */
if (choice != 'B')
{
my_printf("\nEdit <F>orum moderator only, <D>escription only, <B>oth, <Q>uit -> ");
choice = get_single_quiet("FDBQ \n");
my_putchar('\n');
}
if (choice == 'Q' || choice == ' ' || choice == '\n')
goto Return;
if (choice == 'B' || choice == 'F')
{
cp = get_name("\nEnter 'Sysop' for default administrator moderation.\nNew forum moderator -> ", 2);
if (!*cp)
goto Return;
if (!strcmp(cp, "Sysop"))
msg->room[curr].roomaide = 0;
else
if (!(tmpuser = getuser(cp)) || tmpuser->f_invisible)
{
if (tmpuser)
freeuser(tmpuser);
my_printf("\nThere is no user %s on this BBS.\n", cp);
goto Return;
}
else
{
msg->room[curr].roomaide = tmpuser->usernum;
freeuser(tmpuser);
}
if (choice == 'F')
goto Return;
}
my_printf("\nHit Y to upload a description or N to enter it normally (Y/N) -> ");
if ((upload = yesno(-1)))
my_printf("\n(Use control-D to end!)\n");
my_printf("\nEnter a new forum description...\n\n");
err = makemessage(NULL, MES_DESC, upload);
if (err == ABORT)
colorize("@RDescription not entered\n@G");
else if (err != SAVE)
colorize("@RSome mystical error - can't make description\n@G");
else if ((dfd = open(newdescfile, O_WRONLY | O_CREAT | O_EXCL, 0640)) < 0)
my_printf("error opening desc file to make final copy\n");
else
{
mh = (struct mheader *)(void *)tmpstart;
write(dfd, tmpstart, mh->hlen + mh->len + 1);
close(dfd);
rename(newdescfile, descfile);
}
munmap((void *)tmpstart, 53248);
if (err == SAVE)
{
my_printf("\nMark forum info as having been updated? (Y/N) -> ");
if (yesno(-1))
msg->room[curr].descupdate = msg->room[curr].highest;
}
Return:; // free the mallocs
free(descfile);
free(newdescfile);
}
/**********************************************************************
* editroom
* <E>dit room in aide menu
**********************************************************************/
static void
editroom(void)
{
char anon_opt;
char opt;
char *roomname;
char pas[11];
int flags;
int gen;
if (curr <= AIDE_RM_NBR && !ouruser->f_admin)
{
my_printf("Only programmers can edit Lobby, Mail, or Aide forums!\n");
return;
}
flags = msg->room[curr].flags;
gen = msg->room[curr].gen;
/* Edit the room name */
my_printf("Forum name is currently: %s>\n", msg->room[curr].name);
roomname = get_name("New forum name (return leaves it unchanged) -> ", 3);
/* If you're an aide or wizard, you can edit the permissions of the room */
if (ouruser->f_admin)
{
/************************************************************
* These ifs form a sentence onscreen.
************************************************************/
my_printf("\n%s> was a", msg->room[curr].name);
if (!(msg->room[curr].flags & QR_PRIVATE))
my_printf(" public");
if (msg->room[curr].flags & QR_PRIVATE)
my_printf(" private");
if (msg->room[curr].flags & QR_GUESSNAME)
my_printf(" guessname");
if (msg->room[curr].flags & QR_PASSWORD)
my_printf(" passworded");
if (msg->room[curr].flags & QR_ANONONLY)
my_printf(" Anonymous-only");
if (msg->room[curr].flags & QR_ANON2)
my_printf(" Anonymous-optional");
my_printf(" forum\n");
my_printf("New forum type <1>pub <2>guessname <3>passworded <4>inv-only -> ");
opt = get_single_quiet("1234");
my_putchar('\n');
/**********************************************************************
* Option 1 (public) is default.
* Non-public rooms have only 1 or 2 "privacy" bits:
* QR_PRIVATE by itself means invite-only,
* otherwise also set QR_GUESSNAME || QR_PASSWORD
* Turn off all but inuse bits, we're going to reset everything
* Turn bits back on as we go along
**********************************************************************/
flags = QR_INUSE;
if (opt > '1')
flags |= QR_PRIVATE;
if (opt == '2')
flags |= QR_GUESSNAME;
if (opt == '3')
flags |= QR_PASSWORD;
if (opt != '1')
{
my_printf("(Answer yes to start a private forum)\n");
my_printf("Cause users to forget forum? (y/n) -> ");
gen = msg->room[curr].gen;
if (yesno(-1) == YES)
{
if (++gen == 100)
gen = 10;
}
}
if (flags & QR_PASSWORD)
get_string ("Enter Password (enter for no change): ", -10, pas, -1);
}
flags &= ~(QR_ANONONLY | QR_ANON2);
my_printf("Identity: <1>Normal <2>Anon <3>Anon-optional -> ");
anon_opt = get_single_quiet("123");
if (anon_opt == '1')
my_printf("Normal\n");
else if (anon_opt == '2')
{
flags |= QR_ANONONLY;
my_printf("Anonymous only\n");
}
else
{
flags |= QR_ANON2;
my_printf("Anonymous optional\n");
}
colorize("@YSave changes? (Y/N) ->@G ");
if (yesno(-1) == YES)
{
locks(SEM_MSG);
if (*roomname)
strcpy(msg->room[curr].name, roomname);
msg->room[curr].flags = flags;
if (flags & QR_PASSWORD && *pas)
strcpy(msg->room[curr].passwd, pas);
msg->room[curr].gen = gen;
unlocks(SEM_MSG);
}
my_printf("\nUse edit <D>escription to change description/forum moderator.\n");
}
/**********************************************************************
* invite
* Modifies the user's generation and forget numbers to make a member
* of the room.
**********************************************************************/
static void
invite(void)
{
struct user *tmpuser;
char *uname;
uname = get_name("Name of user to invite? ", 2);
if (*uname)
{
if (!(tmpuser = getuser(uname)) || tmpuser->f_invisible)
{
if (tmpuser)
freeuser(tmpuser);
my_printf("There is no user %s on this BBS.\n", uname);
return;
}
if (tmpuser->generation[curr] == msg->room[curr].gen || (!(msg->room[curr].flags & QR_PRIVATE) && tmpuser->generation[curr] != RODSERLING))
{
freeuser(tmpuser);
my_printf("%s is already invited to this forum.\n", uname);
return;
}
locks(SEM_USER);
tmpuser->generation[curr] = msg->room[curr].gen;
tmpuser->forget[curr] = TWILIGHTZONE;
unlocks(SEM_USER);
freeuser(tmpuser);
my_printf("%s invited to %s>\n", uname, msg->room[curr].name);
}
}
/**********************************************************************
* kickout
* Edit a user's generation number for a room so (s)he can't get to it.
**********************************************************************/
static void
kickout(void)
{
struct user *tmpuser;
char *uname;
if (curr == LOBBY_RM_NBR)
{
my_printf("Get a clue! You can't kick a user out of the Lobby!\n");
return;
}
uname = get_name("Name of user to kick out? ", 2);
if (*uname)
{
if (!(tmpuser = getuser(uname)) || tmpuser->f_invisible)
{
if (tmpuser)
freeuser(tmpuser);
my_printf("There is no user %s on this BBS.\n", uname);
return;
}
else
{
if ((tmpuser->generation[curr] == ((msg->room[curr].flags & QR_PRIVATE) ? TWILIGHTZONE : RODSERLING)) && tmpuser->forget[curr] == TWILIGHTZONE)
{
freeuser(tmpuser);
my_printf("%s doesn't belong to this forum.\n", uname);
return;
}
locks(SEM_USER);
tmpuser->generation[curr] = ((msg->room[curr].flags & QR_PRIVATE) && !(msg->room[curr].flags & QR_GUESSNAME)) ? TWILIGHTZONE : RODSERLING;
tmpuser->forget[curr] = TWILIGHTZONE;
tmpuser->generation[curr] = RODSERLING;
unlocks(SEM_USER);
freeuser(tmpuser);
my_printf("%s is now kicked out of %s>\n", uname, msg->room[curr].name);
}
}
}
static void
aide_logout(void)
{
struct user *tmpuser;
char *uname;
struct btmp btmp;
uname = get_name("Name of user to log out? ", 2);
if (*uname){
if (!(tmpuser = getuser(uname)))
my_printf("There is no user %s on this BBS.\n", uname);
else
{
if (tmpuser->f_prog && !ouruser->f_admin)
my_printf("Can't do that!\n");
else if (!is_online(&btmp, tmpuser, NULL))
my_printf("%s is not online.\n", uname);
else
logout_user(tmpuser, NULL, 0);
freeuser(tmpuser);
}
}
}
static void
logout_all(void)
{
int i;
my_printf("Are you are you want to logout all users on the BBS? (Y/N) -> ");
if (yesno(-1))
{
my_printf("\nLogging off all users...");
fflush(stdout);
for (i = 0; i < MAXUSERS; i++)
if (bigbtmp->btmp[i].pid != pid)
logout_user(NULL, &bigbtmp->btmp[i], 0);
sleep(10);
my_printf("\n\nForcing off any stragglers...");
fflush(stdout);
for (i = 0; i < MAXUSERS; i++)
if (bigbtmp->btmp[i].pid != pid)
logout_user(NULL, &bigbtmp->btmp[i], 1);
sleep(5);
my_putchar('\n');
}
}
/**********************************************************************
* whoknows
* Simply mores the whoknows list for current room
* update aide list is called after an aide change
**********************************************************************/
static void
whoknows(void)
{
char * filename = my_sprintf(NULL,"%srm%d", WHODIR, curr);
more(filename, 0);
free(filename);
}