|
|
1.1 root 1: #include "parms.h"
2: #include "structs.h"
3:
4: #ifdef RCSIDENT
5: static char rcsid[] = "$Header: dropt.c,v 1.7.0.1 85/09/09 18:31:21 notes Rel $";
6: #endif RCSIDENT
7:
8: #define BUFSZ 128
9:
10: /*
11: * this file processes the director options.
12: *
13: * call: contains the io pointer to the file.
14: *
15: * allows continued access only if the user if a director.
16: *
17: * the functions of the director options includes:
18: * 1) granting/denial of director priviledges
19: * 2) granting/denial of regular access priviledges
20: * 3) changing the director message
21: * 4) writing a policy note
22: *
23: * Returns: -1 normally
24: * -4 if the user hit cntrl d ( to total exit)
25: *
26: * original author/outliner : Ray Essick may 29, 1981
27: *
28: */
29:
30: static int anonrow, /* allow anon */
31: openrow, /* is open */
32: archrow, /* is archive */
33: keeprow, /* expire action */
34: dirmsgrow, /* expire w/dirmsg */
35: netrow, /* networked */
36: expirerow, /* expire age */
37: longrow, /* longest ok text */
38: worksetrow; /* working set */
39: static int lastrow;
40:
41: direct (io) struct io_f *io;
42: {
43: int i; /* scratch */
44: int c;
45: long expires;
46: long workset;
47: long textlength; /* scratch */
48: char title[DMLEN + 1]; /* hold new director message */
49: char ntitle[NNLEN + 1]; /* hold note file title */
50: struct note_f note;
51: struct auth_f auth; /* author of policy note */
52: struct daddr_f where;
53: char *r,
54: buff[BUFSZ + 1];
55: int buffptr;
56: int start,
57: end,
58: nnotes,
59: nresps;
60: int redraw; /* paint screen */
61:
62: if (allow (io, DRCTOK) == 0)
63: {
64: at (0, PROMPTMSGX);
65: printf ("Sorry, you are not a director");
66: fflush (stdout);
67: sleep (2);
68: return (-1);
69: }
70:
71: redraw = 1;
72: while (1)
73: {
74: if (redraw)
75: dirplot (io);
76: getkey: /* suck in a key */
77: at (-1, 1);
78: printf ("Option: \010");
79: c = gchar (); /* get command */
80: printf ("\010 "); /* overwrite the character */
81: redraw = 0; /* draw if want it */
82: switch (c)
83: {
84: case '?':
85: case 'h':
86: help (DIRHLP);
87: redraw++;
88: break;
89:
90: case 'r': /* replot the screen */
91: case '\f': /* control-L also */
92: redraw++;
93: break;
94:
95: #ifdef K_KEY
96: case 'k': /* same as q */
97: #endif K_KEY
98: case 'q': /* leave */
99: return (-1);
100:
101: case '\004':
102: return QUITFAST; /* Universal exit */
103:
104: case '!': /* give him a shell */
105: gshell ();
106: redraw++;
107: break;
108:
109: case 'p': /* run access lists */
110: if (accessedit (io) == QUITFAST)
111: return QUITFAST; /* doit */
112: redraw++;
113: break; /* skipt out of the loop */
114:
115: case 'a': /* toggle anonymous option */
116: locknf (io, DSCRLOCK); /* lock the thing for a minute */
117: getdscr (io, &io -> descr); /* get up to date descriptor */
118: if (io -> descr.d_stat & ANONOK)
119: io -> descr.d_stat &= NOT ANONOK;
120: else
121: io -> descr.d_stat |= ANONOK;
122: putdscr (io, &io -> descr);
123: unlocknf (io, DSCRLOCK);
124: at (anonrow, 18);
125: printf (io -> descr.d_stat & ANONOK ? "ON " : "OFF");
126: redraw = 0;
127: break;
128:
129: case 'A': /* Archive option */
130: locknf (io, DSCRLOCK); /* lock the thing for a minute */
131: getdscr (io, &io -> descr); /* get up to date descriptor */
132: if (io -> descr.d_stat & ISARCH)
133: io -> descr.d_stat &= NOT ISARCH;
134: else
135: io -> descr.d_stat |= ISARCH;
136: putdscr (io, &io -> descr);
137: unlocknf (io, DSCRLOCK);
138: at (archrow, 18);
139: printf (io -> descr.d_stat & ISARCH ? "YES" : "NO ");
140: redraw = 0;
141: break;
142:
143: case 'l': /* message length */
144: while (1)
145: {
146: at (lastrow, 10);
147: printf ("New Maximum Message Size: ");
148: ceol (); /* clear to eol */
149: if (gline (buff, BUFSZ) == 1) /* empty line */
150: {
151: at (lastrow + 1, 10);
152: printf ("Maximum Message Size Unchanged");
153: goto getkey;
154: }
155: if (sscanf (buff, "%ld", &textlength) == 1)
156: {
157: if (textlength <= HARDMAX) /* too big? */
158: break;
159: else
160: {
161: at (lastrow + 1, 10);
162: printf ("Maximum Allowed is %d", HARDMAX);
163: continue;
164: }
165: }
166: at (lastrow + 1, 10);
167: printf ("Enter an integer or <return>");
168: }
169: locknf (io, DSCRLOCK); /* CRITICAL SECTION */
170: getdscr (io, &io -> descr); /* update descriptor */
171: io -> descr.d_longnote = textlength; /* new value */
172: putdscr (io, &io -> descr);
173: unlocknf (io, DSCRLOCK); /* all done ... */
174: at (longrow, 27);
175: printf ("%ld bytes ", io -> descr.d_longnote);
176: redraw = 0;
177: break;
178:
179: case 'c': /* compress the notefile */
180: redraw = 0;
181: if (io -> descr.d_stat & OPEN)
182: {
183: at (lastrow, 10);
184: printf ("Notefile must be closed to compress");
185: break;
186: }
187: else
188: {
189: at (lastrow, 10);
190: if (askyn ("Really Compress? (y/n) ") != 'y')
191: {
192: at (lastrow + 1, 10);
193: printf ("Compress not done");
194: break;
195: }
196: at (lastrow + 1, 1);
197: printf ("Compressing ");
198: if (compress (io, LOCKIT, 1, &nnotes, &nresps) >= 0)
199: {
200: dirplot (io); /* show it */
201: at (-3, 1);
202: printf ("Compress left %d notes and %d responses",
203: nnotes, nresps);
204: }
205: else
206: {
207: dirplot (io); /* show page */
208: at (-3, 1);
209: printf ("Compress not done");
210: }
211: break;
212: }
213: break;
214:
215: case 'e': /* change expiration time */
216: while (1)
217: {
218: at (lastrow, 10);
219: printf ("New Expiration time: ");
220: ceol (); /* clear to eol */
221: if (gline (buff, BUFSZ) == 1) /* empty line */
222: {
223: at (lastrow + 1, 10);
224: printf ("Expiration Threshold Unchanged");
225: goto getkey;
226: }
227: if (!strcmp (buff, "Never") || !strcmp (buff, "never") ||
228: !strcmp (buff, "NEVER"))
229: {
230: expires = NEVER;
231: break;
232: }
233: if (!strcmp (buff, "Default") || !strcmp (buff, "default") ||
234: !strcmp (buff, "DEFAULT"))
235: {
236: expires = 0;
237: break;
238: }
239: if (sscanf (buff, "%ld", &expires) == 1)
240: {
241: break;
242: }
243:
244: at (lastrow + 1, 10);
245: printf ("Want `default', `never', or a number");
246: at (lastrow + 2, 10);
247: printf ("<return> to leave unchanged");
248: }
249:
250: locknf (io, DSCRLOCK); /* critical section */
251: getdscr (io, &io -> descr);
252: io -> descr.d_archtime = expires; /* update */
253: putdscr (io, &io -> descr); /* replace */
254: unlocknf (io, DSCRLOCK); /* leave critical */
255: at (expirerow, 27);
256: switch ((int) (io -> descr.d_archtime)) /* update screen */
257: {
258: case NEVER:
259: printf ("Never ");
260: break;
261: case 0:
262: printf ("Default ");
263: break;
264: default:
265: printf ("%ld days ", io -> descr.d_archtime);
266: break;
267: }
268: redraw = 0;
269: break;
270:
271: case 'W': /* working Set size */
272: while (1)
273: {
274: at (lastrow, 10);
275: printf ("New Working Set Size: ");
276: ceol (); /* clear to eol */
277: if (gline (buff, BUFSZ) == 1) /* empty line */
278: {
279: at (lastrow + 1, 10);
280: printf ("Working Set Size Unchanged");
281: goto getkey;
282: }
283: if (!strcmp (buff, "Default") || !strcmp (buff, "default") ||
284: !strcmp (buff, "DEFAULT"))
285: {
286: workset = 0;
287: break;
288: }
289: if (sscanf (buff, "%ld", &workset) == 1)
290: {
291: break;
292: }
293:
294: at (lastrow + 1, 10);
295: printf ("Want `default' or a number");
296: at (lastrow + 2, 10);
297: printf ("<return> to leave unchanged");
298: }
299:
300: locknf (io, DSCRLOCK); /* critical section */
301: getdscr (io, &io -> descr);
302: io -> descr.d_workset = workset; /* update */
303: putdscr (io, &io -> descr); /* replace */
304: unlocknf (io, DSCRLOCK); /* leave critical */
305: at (worksetrow, 27);
306: switch ((int) io -> descr.d_workset)
307: {
308: case 0:
309: printf ("Default ");
310: break;
311: default:
312: printf ("%ld Notes ", io -> descr.d_workset);
313: }
314: redraw = 0;
315: break;
316:
317: case 'E': /* keep/delete/default */
318: locknf (io, DSCRLOCK); /* critical section */
319: getdscr (io, &io -> descr);
320: switch ((int) io -> descr.d_archkeep) /* change it */
321: {
322: case KEEPNO:
323: io -> descr.d_archkeep = KEEPYES;
324: break;
325: case KEEPYES:
326: io -> descr.d_archkeep = KEEPDFLT;
327: break;
328: case KEEPDFLT:
329: default:
330: io -> descr.d_archkeep = KEEPNO;
331: break;
332: }
333: putdscr (io, &io -> descr); /* replace */
334: unlocknf (io, DSCRLOCK); /* leave critical */
335: at (keeprow, 27);
336: switch ((int) io -> descr.d_archkeep) /* update display */
337: {
338: case KEEPYES:
339: printf ("ARCHIVE");
340: break;
341: case KEEPNO:
342: printf ("DELETE ");
343: break;
344: case KEEPDFLT:
345: printf ("Default");
346: break;
347: default:
348: printf ("UNKNOWN");
349: break;
350: }
351: redraw = 0;
352: break;
353:
354: case 'D': /* Archive dirmsg */
355: locknf (io, DSCRLOCK); /* critical section */
356: getdscr (io, &io -> descr);
357: switch ((int) io -> descr.d_dmesgstat) /* change it */
358: {
359: case DIRNOCARE:
360: io -> descr.d_dmesgstat = DIRON;
361: break;
362: case DIRON:
363: io -> descr.d_dmesgstat = DIROFF;
364: break;
365: case DIROFF:
366: io -> descr.d_dmesgstat = DIRDFLT;
367: break;
368: case DIRDFLT:
369: default:
370: io -> descr.d_dmesgstat = DIRNOCARE;
371: break;
372: }
373: putdscr (io, &io -> descr); /* replace */
374: unlocknf (io, DSCRLOCK); /* leave critical */
375: at (dirmsgrow, 27);
376: switch ((int) io -> descr.d_dmesgstat)
377: {
378: case DIRNOCARE:
379: printf ("NOCARE ");
380: break;
381: case DIRON:
382: printf ("ON ");
383: break;
384: case DIROFF:
385: printf ("OFF ");
386: break;
387: case DIRDFLT:
388: printf ("Default ");
389: break;
390: default:
391: printf ("UNKNOWN ");
392: break;
393: }
394: redraw = 0;
395: break;
396:
397: case 'o': /* toggle open status */
398: locknf (io, DSCRLOCK);
399: getdscr (io, &io -> descr);
400: if (io -> descr.d_stat & OPEN)
401: io -> descr.d_stat &= NOT OPEN;
402: else
403: io -> descr.d_stat |= OPEN;
404: putdscr (io, &io -> descr);
405: unlocknf (io, DSCRLOCK);
406: at (openrow, 18);
407: printf (io -> descr.d_stat & OPEN ? "OPEN " : "CLOSED");
408: redraw = 0;
409: break;
410:
411: case 'n': /* toggle network status */
412: locknf (io, DSCRLOCK);
413: getdscr (io, &io -> descr);
414: if (io -> descr.d_stat & NETWRKD)
415: {
416: io -> descr.d_stat &= NOT NETWRKD;
417: }
418: else
419: {
420: io -> descr.d_stat |= NETWRKD;
421: }
422: putdscr (io, &io -> descr);
423: unlocknf (io, DSCRLOCK);
424: at (netrow, 18);
425: printf (io -> descr.d_stat & NETWRKD ? "YES" : "NO ");
426: redraw = 0;
427: break;
428:
429:
430: case 'm': /* collect a new director message */
431: redraw++;
432: at (lastrow, 10);
433: printf ("Enter new director message");
434: at (lastrow + 2, 10);
435: for (i = 0; i < DMLEN; i++)
436: printf ("-");
437: at (lastrow + 1, 10);
438: i = gline (title, DMLEN - 1); /* grab message */
439: if (i <= 1)
440: break; /* no new message */
441: locknf (io, DSCRLOCK); /* mutual exclusion */
442: getdscr (io, &io -> descr); /* get up-to-date */
443: strncpy (io -> descr.d_drmes, title, DMLEN);/* replace */
444: putdscr (io, &io -> descr);
445: unlocknf (io, DSCRLOCK); /* uncritical now */
446: break;
447:
448: case 't': /* write title for note file */
449: redraw++;
450: at (lastrow, 10);
451: printf ("Enter new title for notefile");
452: at (lastrow + 2, 10);
453: for (i = 0; i < NNLEN; i++)
454: printf ("-");
455: at (lastrow + 1, 10);
456: i = gline (ntitle, NNLEN - 1); /* suck the title */
457: if (i <= 1)
458: break; /* no new message */
459: locknf (io, DSCRLOCK); /* MUTEX */
460: getdscr (io, &io -> descr); /* current descr */
461: strncpy (io -> descr.d_title, ntitle, NNLEN);/* update */
462: putdscr (io, &io -> descr); /* and replace */
463: unlocknf (io, DSCRLOCK); /* uncritical now */
464: break;
465:
466: case 'w': /* let him write a new policy note */
467: if (io -> descr.d_plcy)
468: {
469: at (0, PROMPTMSGX);
470: if (askyn ("Rewrite policy? (y/n) :") == 'n')
471: {
472: redraw++;
473: break;
474: }
475: }
476: at (0, PROMPTMSGX);
477: printf ("\nEdit New Policy Text:\n");
478: if (gettext (io, &where, (FILE *) NULL, EDIT) == 0)
479: {
480: redraw++;
481: break;
482: }
483: r = title;
484: strcpy (title, "POLICY NOTE");
485: gettime (¬e.n_date); /* date of writing */
486: getname (&auth, 0); /* get author */
487: putnote (io, &where, title, 0, ¬e, &auth, 1, 1, 1, System, 1);
488: dspnote (io, ¬e, 0); /* show it to him */
489: redraw++;
490: break;
491:
492: case 'z': /* zap a lot of notes/responses */
493: case 'u': /* undelete a bunch */
494: {
495: char *action; /* del/undel */
496:
497: redraw++; /* want to repaint */
498: action = c == 'z' ? "delete" : "un-delete";/* for prompts */
499: at (lastrow, 1);
500: printf ("Enter list of notes to %s: ", action);
501: gline (buff, BUFSZ); /* grab line */
502: at (lastrow + 1, 1);
503: printf ("Going to %s: %s", action, buff);
504: at (lastrow + 2, 1);
505: if (askyn ("Do you really want to do that? ") != 'y')
506: break; /* chicken out */
507: buffptr = 0;
508: at (lastrow + 3, 1);
509: while (listget (buff, &buffptr, &start, &end))
510: {
511: if (start > end)
512: {
513: printf ("IGNORING %d-%d", start, end);
514: continue;
515: }
516: if (start == end)
517: printf ("%d ", start);
518: else
519: printf ("%d-%d ", start, end);
520: mdelete (io, start, end, c == 'z');/* zap those */
521: }
522: goto getkey; /* leave this stuff on screen */
523: }
524:
525: default:
526: printf ("\07");
527: redraw = 0;
528: goto getkey; /* hit a bad key */
529:
530: }
531: }
532: }
533: /*
534: * dirplot - Plot the notesfile status
535: */
536:
537: dirplot (io)
538: struct io_f *io;
539: {
540: int atrow;
541: int atcol;
542:
543: erase ();
544: center (io -> descr.d_title, NNLEN, 1, 40 - NNLEN / 2);
545: center (io -> descr.d_drmes, DMLEN, 2, 40 - DMLEN / 2);
546: atrow = 4; /* start filling in */
547: atcol = 1;
548: at (anonrow = atrow++, atcol);
549: printf ("(a) Anonymous: "); /* at (3,18); */
550: printf (io -> descr.d_stat & ANONOK ? "ON" : "OFF");
551: at (openrow = atrow++, atcol);
552: printf ("(o) Notesfile: "); /* at(4,18); */
553: printf (io -> descr.d_stat & OPEN ? "OPEN " : "CLOSED");
554: at (netrow = atrow++, atcol);
555: printf ("(n) Networked: "); /* at(5,18); */
556: printf (io -> descr.d_stat & NETWRKD ? "YES" : "NO ");
557: at (archrow = atrow++, atcol);
558: printf ("(A) Is Archive: "); /* at(6,18); */
559: printf (io -> descr.d_stat & ISARCH ? "YES" : "NO");
560: at (expirerow = atrow++, atcol);
561: printf ("(e) Expiration Threshold: "); /* at (6,27); */
562: switch ((int) (io -> descr.d_archtime))
563: {
564: case NEVER:
565: printf ("Never");
566: break;
567: case 0:
568: printf ("Default");
569: break;
570: default:
571: printf ("%ld days", io -> descr.d_archtime);
572: break;
573: }
574: at (keeprow = atrow++, atcol);
575: printf ("(E) Expiration Action: "); /* at(?,27); */
576: switch ((int) io -> descr.d_archkeep)
577: {
578: case KEEPYES:
579: printf ("ARCHIVE");
580: break;
581: case KEEPNO:
582: printf ("DELETE ");
583: break;
584: case KEEPDFLT:
585: printf ("Default");
586: break;
587: default:
588: printf ("UNKNOWN");
589: break;
590: }
591: at (dirmsgrow = atrow++, atcol);
592: printf ("(D) Expire with Dirmsg: "); /* at (?,27) */
593: switch ((int) io -> descr.d_dmesgstat)
594: {
595: case DIRNOCARE:
596: printf ("NOCARE ");
597: break;
598: case DIRON:
599: printf ("ON ");
600: break;
601: case DIROFF:
602: printf ("OFF ");
603: break;
604: case DIRDFLT:
605: printf ("Default ");
606: break;
607: default:
608: printf ("UNKNOWN ");
609: break;
610: }
611: at (worksetrow = atrow++, atcol);
612: printf ("(W) Working Set Size: "); /* at (5,27) */
613: switch ((int) io -> descr.d_workset)
614: {
615: case 0:
616: printf ("Default");
617: break;
618: default:
619: printf ("%ld Notes", io -> descr.d_workset);
620: }
621: at (longrow = atrow++, atcol);
622: printf ("(l) Maximum text/article: "); /* at (6,27) */
623: printf ("%ld bytes", io -> descr.d_longnote);
624:
625: lastrow = atrow; /* for queries */
626:
627: /*
628: * Second Column
629: */
630:
631: atrow = 4;
632: atcol = 40;
633: at (atrow++, atcol);
634: printf ("Policy Note Exists: %s", io -> descr.d_plcy ? "YES" : "NO");
635: at (atrow++, atcol);
636: printf ("Next note in slot: %d", io -> descr.d_nnote + 1);
637: at (atrow++, atcol);
638: printf ("Deleted Notes (holes): %ld ", io -> descr.d_delnote);
639: at (atrow++, atcol);
640: printf ("Deleted Responses (holes): %ld ", io -> descr.d_delresp);
641: /*
642: * Should we show more statistics here?
643: * Things like orphans, adoptions, etc.
644: */
645:
646: if (atrow > lastrow)
647: lastrow = atrow;
648: lastrow++;
649: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.