From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 20-MAR-1989 15:31
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Termlock v1.16, part 4 of 5


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue, 14 MAR 89 09:00:32 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue, 14 Mar 89 08:58:35 PST
Received: by ucbvax.Berkeley.EDU (5.61/1.36)
	id AA05089; Tue, 14 Mar 89 08:40:21 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 9 Mar 89 05:16:07 GMT
From: ssbell!mcmi!amperif!unocss!dent@uunet.uu.net  (Dave Caplinger)
Organization: U. of Nebraska at Omaha
Subject: Termlock v1.16, part 4 of 5
Message-Id: <705@unocss.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


+-+-+-+ Beginning of part 4 +-+-+-+
X        strncpy(header.weekday,&day_list[i],10);/* put in output buffer */
X`125
X`032
X/***********************************************************************/
X/* reset the cursor to command line, used after message or bad command */
X/***********************************************************************/
X`032
Xreset_input()
X`123
X`009display_user_count();
X`009display_sys_count();
X`009display_old_count();
X`009display_failed_unlocks();
X`009if (!password[0]) display_status("UNLOCKED!");
X`009  else display_status("LOCKED!");
X`009display_prompt();
X        update_time();
X`125
X`032
X/***********************************************************************/
X/* Display the time and the date on screen every few seconds please... */
X/***********************************************************************/
X`032
Xupdate_time()
X`123
Xint     time[4], i, j;
X$DESCRIPTOR(delta, "0 ::30");
Xstatic`009char oldchar = ' ';
Xchar`009newchar;
X
X        get_time(); header.time[5] = 0;         /* get time, test timeout */
X`009for(i=j=0; header.weekday[i] != ' '; i++,j++)
X`009  date_string[j] = header.weekday[i];
X`009while (header.weekday[i] == ' ') i++;   /* skip first batch of spaces */
X`009date_string[j++] = ' ';
X`009while (i <= strlen(header.weekday))
X`009  date_string[j++] = header.weekday[i++];
X
X`009display_time();
X`009newchar = date_string[strlen(date_string)-1];
X
X`009if ((newchar != oldchar) && (TIME_OUT != 0)) `123
X`009  START_TIME++;
X`009  if (START_TIME == TIME_OUT) `123
X`009    cgoto(12,1);
X`009    printf("\n\n\n* TERMLOCK timed out after %d minutes *\n",TIME_OUT);
X `009    logout();
X`009  `125
X`009  oldchar = newchar;
X`009`125
X`009if (TIME_OUT != 0)
X`009  display_timeout();
X
X        sys$cantim(0,3);                        /* kill time interupts */
X        sys$bintim(&delta, &time);              /* gets new time delay */
X        sys$setimr(0,&time,update_time,0);      /* sets interupt timer */
X`032
X`009cursor_to_prompt();
X`125
X`032
X/***********************************************************************/
X/* View the file, simulating type/page in the scroll region.           */
X/***********************************************************************/
X`032
Xview_messages()
X`123
X        char nothing[2], line[128], c[2];
X`009int i;
X`009double x;
X        FILE *fd;
X`032
X        if (unlock_term() != 0) return;
X
X        reset_terminal();                       /* reset terminal now */
X
X/**/`009printf("%c[21;1H%c[0J",esc,esc);    /* clear btm. */
X/**/`009printf("%c[11;r%c[11;1H",esc,esc);  /* set scroll */
X
X        fd = fopen((LOGFILE[0]) ? LOGFILE : "SYS$LOGIN:TERMLOCK.LOG",
X`009`009"r", "rat=cr", "rfm=var");
X
X`009i = 0;
X        while (fgets(line, 127, fd) != NULL) `123
X`009`009if (++i % 12 == 0) `123
X`009`009`009x = (i/((user_cnt+sys_cnt+old_cnt)*2.0))*100;
X`009`009`009printf(" (%d%%) <Press a key>", (int) (x + 0.5));
X`009                sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X`009`009`009printf("\n");
X`009`009`009if (toupper(c[0]) == 'Q') `123 i = -1; break; `125
X`009`009`125
X`009`009if (strlen(line) > 80) i++;    /* count long lines twice */
X`009`009if (line[0]==7) line[0] = 32;
X                printf("%s",line);
X        `125
X`032
X        if (status != 1) lib$signal(status); /* exit if any errors */
X        fclose(fd);
X
X`009switch (i) `123
X`009`009case -1 : printf(" Aborted -");
X`009`009`009  break;
X`009`009case  0 : printf(" No messages received -");
X`009`009`009  break;
X`009`009default : printf(" End of messages -");
X`009`125
X        printf(" <Press a key>");
X        sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X
X/**/`009printf("%c[;r",esc);`009`009`009/* reset scroll region */
X`032
X        open_file();                            /* open the file again */
X        setup_term();                           /* sets terminal again */
X`125
X
X/***********************************************************************/
X/* Call editor (EDIT$INIT) on the message log, conditional on lock     */
X/***********************************************************************/
X
Xcall_editor()
X`123
Xchar`009*junk;
Xchar`009*editor = "TERMLOCK$EDIT";
X$DESCRIPTOR(tpu_dsc,"TPU SYS$LOGIN:TERMLOCK.LOG");
X$DESCRIPTOR(edt_dsc,"SYS$LOGIN:TERMLOCK.LOG");
X$DESCRIPTOR(userlog_tpu_dsc, "TPU TERMLOCK$LOGFILE");
X$DESCRIPTOR(userlog_edt_dsc, "TERMLOCK$LOGFILE");
X
X        if (unlock_term() != 0) return;
X
X`009reset_terminal();
X
X`009junk = tranlog(editor,1);
X
X`009if (!strcmp(junk,"TPU"))
X`009  status = tpu$tpu( (LOGFILE[0]) ? &userlog_tpu_dsc : &tpu_dsc );
X`009else
X`009  status = edt$edit( (LOGFILE[0]) ? &userlog_edt_dsc : &edt_dsc );
X
X`009if (!odd(status)) lib$signal(status);
X
X`009open_file();
X`009setup_term();
X`125
X
X`032
X/***********************************************************************/
X/* get the users name and node if needed & send reply message to him.  */
X/***********************************************************************/
X`032
Xget_name(start)
Xint start;
X`123
Xint`009i, j = 0;
V    ignore = self = send = file = phone = mail = job = local = reply = cmd =
X 0;
X    for(i = 0; i < 9; i++) who[i] = where[i] = what[i] = ' ';
X    for(i = 9; i <20; i++) what[i] = ' ';
X    who[0] = where[0] = what[0] = '\0';
X
X    if (mbx.message[i = start] == '(') `123
X`009for(j = i; mbx.message[j] != ')'; j++);
X`009if (mbx.message[j] == ')') `123
X`009`009strncpy(where,&mbx.message[i+1],j-i-1);
X`009`009where[j-i-1] = '\0';
X`009`009start += strlen(where) + 2;
X`009`009if (!strncmp(bitnet_node,where,strlen(where))) local=1;
X`009`125
X    `125 else local = 1;
X
X    sscanf(&mbx.message[start], "%s - ", who);
X    start += strlen(who) + 3;
X    if (mbx.message[start] == '*') ignore = 1;
X    if (!strncmp(who, myself, strlen(myself))) self = 1;
X    if (!strcmp(who, "-")) ignore = 1;
X    if (!strcmp(who, "New")) mail = 1;
X    if (!strcmp(who, "Job")) job = 1;
X    if (!strcmp(who, "Reply")) reply = 1;
X    if (!strcmp(who, "*URGENT*")) `123 reply = 1; ignore = 0; `125
X
X/* note: our help reply/shutdown says "*SHUTDOWN* - etc", but actually
X    doing it shows that it's just "SHUTDOWN - etc".  So I put in both. */
X
X    if (!strcmp(who, "SHUTDOWN")) reply = 1;
X    if (!strcmp(who, "*SHUTDOWN*")) reply = 1;
X    if (strchr(who,':') != NULL) phone = 1;
X    if (strchr(who,'(') != NULL) phone = 0;
X    if (!strncmp(who, decnet_node, strlen(decnet_node))) local = 1;
X    for(i=0; mbx.message[i] != '-'; i++) ;
X
X    if ((mbx.message[i+2] == ':') && (self)) cmd = 1;
X
X    if (cmd) got_cmd_message(i+2);
X    else if (phone) got_phone_message();
X         else if (reply) got_reply_message();
X              else if ((!mail) && (!job)) got_send_message();
X`125
X
Xgot_send_message()
X`123
Xint`009i = 0;
Xchar`009temp[20];
X
X`009while (mbx.message[i] != '-') i++;
X`009if ((i < strlen(mbx.message)) && (mbx.message[i] == '-') &&
X`009    (sscanf(mbx.message + i, "- Received network file %s from %s",
X`009    what,temp) == 2)) `123
X`009`009if (!strncmp(temp,myself,strlen(myself))) ignore = 1;
X`009`009 else ignore = 0;
X`009`009sprintf(send_msg, "send %s \"* File %s received.",temp, what);
X`009`009reply_to_user();
X`009`009file = 1;
X`009`009return;
X`009`125
X`009strcpy(send_msg, "send ");
X`009for (i = 0; who[i] != '('; i++);
X`009if ((i < strlen(who)) && (who[i] == '(')) who[i] = '\0';
X`009strcat(send_msg, who);
X`009if (local == 0) `123
X`009`009strcat(send_msg, "@");
X`009`009strcat(send_msg, where);
X`009`125
X`009strcat(send_msg, " \"");
X`009if (reply_string[0] != '*') strcat(send_msg, "* ");
X`009strcat(send_msg, reply_string);
X`009reply_to_user();
X`009send = 1;
X`125
X
Xgot_phone_message()
X`123
X#ifdef JNET33
X    return;
X#endif
X
X#ifdef JNET32
Xint`009i = 0;
X
X    strcpy(send_msg,"send ");
X    strcat(send_msg,who);
X    strcat(send_msg," \"");
X    strcat(send_msg, phone_string);
X    reply_to_user();
X#endif
X`125
X
Xgot_reply_message()
X`123
X`009cgoto(21,1);
X`009printf("%c[0J\007%s",esc,mbx.message);  /* clr to bottom and show msg */
X`125
X
Xgot_cmd_message(start)
Xint start;
X`123
X    ignore = 0;
X
X    if (!strncmp(&mbx.message[start],":help",5)) `123
X      sprintf(send_msg, "send %s \"* TERMLOCK: Valid commands --",myself);
X      reply_to_user();
X      sprintf(send_msg,`032
V        "send %s \"* TERMLOCK:   status  : Show message counts, etc.",myself)
X;
X      reply_to_user();
X      sprintf(send_msg,
X        "send %s \"* TERMLOCK:   message : Change reply message.",myself);
X      reply_to_user();
X      sprintf(send_msg,
V        "send %s \"* TERMLOCK:   logout  : Log out TERMLOCK process.",myself)
X;
X      reply_to_user();
X      sprintf(send_msg,
X        "send %s \"* TERMLOCK: (Command complete.)",myself);
X      reply_to_user();
X      return;
X    `125
X    if (!strncmp(&mbx.message[start],":message",8)) `123
X        if (strlen(&mbx.message[start+9]) < 101)
X            strcpy(reply_string, &mbx.message[start+9]);
X        else `123
X            strncpy(reply_string, &mbx.message[start+9], 100);
X            reply_string[strlen(reply_string)] = '\0';
X        `125
X        sprintf(send_msg,
V          "send %s \"* TERMLOCK: The reply message has been changed.", myself
X);
X        reply_to_user();
X        return;
X    `125
X    if (!strncmp(&mbx.message[start],":status",7)) `123
X`009sprintf(send_msg,
V         "send %s \"* TERMLOCK: %d user, %d system, %d old, %d bad unlocks --
X ",
X`009  myself, user_cnt, sys_cnt, old_cnt, bad_tries);
X`009if (!password[0]) strcat(send_msg, "UNLOCKED.");
X`009else strcat(send_msg, "LOCKED.");
X`009reply_to_user();
X`009if (TIME_OUT != 0) `123
X`009  sprintf(send_msg, "send %s \"* TERMLOCK: %d minutes until timeout.",
X`009    myself, TIME_OUT/2 - START_TIME/2);
X`009  reply_to_user();
X`009`125
X`009return;
X    `125
X    if (!strncmp(&mbx.message[start],":logout",7)) `123
X`009sprintf(send_msg, "send %s \"* TERMLOCK: Process terminated.",myself);
X`009reply_to_user();
V        lib$wait(&(10.0));        /* wait 10 seconds for SEND to go through *
X/
X`009logout();
X    `125
V    sprintf(send_msg, "send %s \"* TERMLOCK: Command not recognized.",myself)
X;
X    reply_to_user();
X`125
X
Xreply_to_user()
X`123
X    if (!ignore) `123
X`009status = sys$qiow(0,mbx_chan,IO$_WRITEVBLK,0,0,0,
X`009`009&send_msg,strlen(send_msg),0,0,0,0);
X`009if (status != 1) lib$signal(status);
X    `125
X`125
X
X/***********************************************************************/
X/* Translate a logical name to the real physical name, if there is one */
X/***********************************************************************/
X`032
Xchar *tranlog(s,flag)
Xchar *s;
Xint  flag;
X`123
X$DESCRIPTOR(tab0desc,"LNM$SYSTEM_TABLE");
X$DESCRIPTOR(tab1desc,"LNM$PROCESS_TABLE");
Xstruct dsc name;
Xchar *cp;
Xint loglen,status;
Xint attr_arg;
X`032
X        cp = malloc( 256 );                     /* go get us some memory */
X        name.addr = s;                          /* address for string... */
X        name.len  = strlen(s);                  /* length of the strings */
X        attr_arg = LNM$M_CASE_BLIND;            /* don't care about case */
X        trnlist[0].bufferlength = 100;          /* set up an itemlist... */
X        trnlist[0].item_code    = LNM$_STRING;  /* say it is a string... */
X        trnlist[0].addr.charbuf = cp;           /* buffer for the result */
X        trnlist[0].retlength    = &loglen;      /* the length for result */
X        trnlist[1].bufferlength = 0;
X        trnlist[1].item_code    = 0;
X        if (flag)`032
X           status = sys$trnlnm(&attr_arg,&tab1desc,&name,0,&trnlist);
X        else
X           status = sys$trnlnm(&attr_arg,&tab0desc,&name,0,&trnlist);
X        if ( status == SS$_NOLOGNAM `124`124 ( status & 1 ) == 0) loglen = 0;
X        *(cp + (loglen&255)) = 0;               /* null terminate result */
X        return(cp);                             /* and return the result */
X`125
X
Xlock_term()
X`123
X        int status, i;
X        char c[2], TEMP1[10], TEMP2[10];
X
X        if (password[0] != 0) return;
X`032
X`009for(i=0; i<11; TEMP1[i] = TEMP2[i] = password[i++] = 0);
X`032
X`009display_status("Password?");
X        status = 1;
X        i = 0;
X        while ((status==1) && (i < 11) && (c[0] != 13)) `123
X                status = sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X                TEMP1[i++] = toupper(c[0]);
X        `125
X
X`009display_status("Confirm?");
X`009status = 1;
X`009i = c[0] = 0;
X`009while ((status==1) && (i < 11) && (c[0] != 13)) `123
X                status = sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X                TEMP2[i++] = toupper(c[0]);
X`009`125
X
X`009if (strcmp(TEMP1,TEMP2) != 0) `123
X`009`009beep();
X`009`009display_status("UNLOCKED!");
X`009`009cursor_to_prompt();
X`009`009password[0] = 0;
X`009`009return;
X`009`125
X
X`009strcpy(password,TEMP1);
X`009display_status("LOCKED!");
X`009cursor_to_prompt();
X        return;
X`125
X`032
Xunlock_term()
X`123
X        int status, i;
X        char c[2], TEMP[10];
X`032
X        for(i = 0; i < 11; TEMP[i++] = 0);
X`032
X        if (password[0] == 0) return (0);
X`032
X`009display_status("Unlock?");
X        status = 1;
X        i = 0;
X        while ((status==1) && (i < 11) && (c[0] != 13)) `123
X                status = sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X                TEMP[i++] = (char) toupper(c[0]);
X        `125
X`032
X`009display_status(" ");
X`032
X        if (strcmp(TEMP,password) != 0) `123
X`009`009beep();
X`009`009display_status("LOCKED!");
X`009`009bad_tries++;
X`009`009display_failed_unlocks();
X`009`009cursor_to_prompt();
X                return (-1);
X        `125
X`032
X`009bad_tries = 0;
X`009display_failed_unlocks();
X`009display_status("UNLOCKED!");
X`009cursor_to_prompt();
X        password[0] = 0;
X        return (0);
X`125
X
X/*
X *   Beginning of screen routines and character-graphic routines...
X */
X
Xdraw_screen()
X`123
Xcls();
Xgon();
Xdraw_box(2,7,10,73);
Xgoff();
Xcgoto(2,10); printf(" TERMLOCK %s ",VERSION);
Xcgoto(4,10); puts("L - Lock the terminal.");
Xcgoto(5,10); puts("U - Unlock the terminal.");
Xcgoto(6,10); puts("E - Edit the message file.");
Xcgoto(7,10); puts("V - View the message file.");
Xcgoto(8,10); puts("Q - Quit.");
Xreset_input();
X`125
X
Xdisplay_user_count()
X`123
X`009cgoto(3,44);
X`009printf("%d User messages received",user_cnt);
X`125
X
Xdisplay_sys_count()
X`123
X`009cgoto(4,44);
X`009printf("%d System messages received",sys_cnt);
X`125
X
Xdisplay_old_count()
X`123
X`009cgoto(5,44);
X`009printf("%d Old messages in file",old_cnt);
X`125
X
Xdisplay_failed_unlocks()
X`123
X`009cgoto(6,44);
X`009printf("%d Failed unlocks",bad_tries);
X`125
X
Xdisplay_timeout()
X`123
Xchar time[5];
Xint i;
X
X`009sprintf(time,"%d",(TIME_OUT/2 - START_TIME/2));
X`009cgoto(7,46);
X`009printf("TIMEOUT in %s minutes.",time);
X`009if (strlen(time) < 5) for(i=1;i<strlen(time);i++) printf(" ");
X`125
X
Xdisplay_time()
-+-+-+-+-+ End of part 4 +-+-+-+-+-

