From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 15-SEP-1988 02:08
To:	ARISIA::EVERHART
Subj:	Termlock v1.05 (part 3 of 3)


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Wed, 14 SEP 88 10:08:04 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Wed, 14 Sep 88 09:59:29 PDT
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AB28629; Tue, 13 Sep 88 06:09:23 PDT
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: 8 Sep 88 23:41:25 GMT
From: mcmi!hdr!unocss!dent@uunet.uu.net  (Dave Caplinger)
Organization: U. of Nebraska at Omaha
Subject: Termlock v1.05 (part 3 of 3)
Message-Id: <403@unocss.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


+-+-+-+ Beginning of part 3 +-+-+-+
X           printf("%c[4;42H%d System messages received",esc,sys_cnt);
X           printf("%c[5;42H%d Old messages in file",esc,old_cnt);
X           printf("%c[6;42H%d Failed unlocks",esc,bad_tries);
X`009   if (!password[0]) printf("%c[9;42HUNLOCKED!",esc);
X`009   else printf("%c[9;42HLOCKED!  ",esc);
X           printf("%c[9;57HSelection:",esc);
X           update_time();
X}
X 
X/***********************************************************************/
X/* Display the time and the date on screen every few seconds please... */
X/***********************************************************************/
X 
Xupdate_time()
X{
Xint     time[4];
X$DESCRIPTOR(delta, "0 ::30");
X 
X        get_time(); header.time[5] = 0;         /* get time, terminate */
X        printf("%c[9;8H%s%c[4;46H", esc,header.weekday,esc);
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 
X        printf("%c[9;67H",esc);
X}
X 
X/***********************************************************************/
X/* View the file, simulating type/page in the scroll region.           */
X/***********************************************************************/
X 
Xview_messages()
X{
X        char nothing[2], line[128], c[2];
X`009int i;
X`009double x;
X        FILE *fd;
X 
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        printf("%c[11;r%c[11;1H",esc,esc);  /* set scroll */
X        fd = fopen("sys$login:termlock.log", "r");
X
X`009i = 0;
X        while (fgets(line, 127, fd) != NULL) {
X`009`009if (++i % 12 == 0) {
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') { i = -1; break; }
X`009`009}
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        }
X 
X        if (status != 1) lib$signal(status); /* exit if any errors */
X        fclose(fd);
X
X`009switch (i) {
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}
X        printf(" <Press a key>");
X        sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X        printf("%c[;r",esc);
X 
X        open_file();                            /* open the file again */
X        setup_term();                           /* sets terminal again */
X}
X
X/***********************************************************************/
X/* Call editor (EDIT$INIT) on the message log, conditional on lock     */
X/***********************************************************************/
X
Xcall_editor()
X{
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
X        if (unlock_term() != 0) return;
X
X`009reset_terminal();
X
X`009junk = tranlog(editor,1);
X`009if (!strcmp(junk,"TPU")) status = tpu$tpu(&tpu_dsc);
X`009 else status = edt$edit(&edt_dsc);
X`009if (!odd(status)) lib$signal(status);
X
X`009open_file();
X`009setup_term();
X}
X
X 
X/***********************************************************************/
X/* get the users name and node if needed & send reply message to him.  */
X/***********************************************************************/
X 
Xget_name(start)
Xint start;
X{
Xint`009i, j = 0;
X
X`009ignore = send = file = phone = mail = job = local = reply = 0;
X`009for(i = 0; i < 9; i++) who[i] = where[i] = what[i] = ' ';
X`009for(i = 9; i <20; i++) what[i] = ' ';
X`009who[0] = where[0] = what[0] = '\0';
X
X`009if (mbx.message[i = start] == '(') {
X`009`009for(j = i; mbx.message[j] != ')'; j++);
X`009`009if (mbx.message[j] == ')') {
X`009`009`009strncpy(where,&mbx.message[i+1],j-i-1);
X`009`009`009where[j-i-1] = '\0';
X`009`009`009start += strlen(where) + 2;
X`009`009`009if (!strncmp(bitnet_node,where,strlen(where))) local=1;
X`009`009}
X`009} else local = 1;
X
X`009sscanf(&mbx.message[start], "%s - ", who);
X`009start += strlen(who) + 3;
X`009if (mbx.message[start] == '*') ignore = 1;
X`009if (!strncmp(who, myself, strlen(myself))) ignore = 1;
X`009if (!strcmp(who, "-")) ignore = 1;
X`009if (!strcmp(who, "New")) mail = 1;
X`009if (!strcmp(who, "Job")) job = 1;
X`009if (!strcmp(who, "Reply")) reply = 1;
X`009if (!strcmp(who, "*URGENT*")) { reply = 1; ignore = 0; }
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`009if (!strcmp(who, "SHUTDOWN")) reply = 1;
X`009if (!strcmp(who, "*SHUTDOWN*")) reply = 1;
X`009if (strchr(who,':') != NULL) phone = 1;
X`009if (strchr(who,'(') != NULL) phone = 0;
X`009if (!strncmp(who, decnet_node, strlen(decnet_node))) local = 1;
X`009if (phone) got_phone_message();
X`009else if (reply) got_reply_message();
X`009     else if ((!mail) && (!job)) got_send_message();
X}
X
Xgot_send_message()
X{
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)) {
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}
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) {
X`009`009strcat(send_msg, "@");
X`009`009strcat(send_msg, where);
X`009}
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}
X
Xgot_phone_message()
X{
Xint`009i = 0;
X
X`009strcpy(send_msg,"send ");
X`009strcat(send_msg,who);
X`009strcat(send_msg," \"");
X`009strcat(send_msg, phone_string);
X`009reply_to_user();
X}
X
Xgot_reply_message()
X{
X`009printf("%c[21;1H%c[0J\007%s",esc,esc,mbx.message);
X}
X
Xreply_to_user()
X{
X    if (!ignore) {
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    }
X}
X
X/***********************************************************************/
X/* Translate a logical name to the real physical name, if there is one */
X/***********************************************************************/
X 
Xchar *tranlog(s,flag)
Xchar *s;
Xint  flag;
X{
X$DESCRIPTOR(tab0desc,"LNM$SYSTEM_TABLE");
X$DESCRIPTOR(tab1desc,"LNM$PROCESS_TABLE");
Xstruct dsc name;
Xchar *cp;
Xint loglen,status;
Xint attr_arg;
X 
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) 
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 || ( status & 1 ) == 0) loglen = 0;
X        *(cp + (loglen&255)) = 0;               /* null terminate result */
X        return(cp);                             /* and return the result */
X}
X
Xlock_term()
X{
X        int status, i;
X        char c[2], TEMP[10];
X
X        if (password[0] != 0) return;
X 
X`009for(i=0; i<11; TEMP[i] = password[i++] = 0);
X 
X        printf("%c[9;42H",esc);
X`009printf("Password? ");
X        status = 1;
X        i = 0;
X        while ((status==1) && (i < 11) && (c[0] != 13)) {
X                status = sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X                password[i++] = toupper(c[0]);
X        }
X
X`009printf("%c[9;42H",esc);
X`009printf("Confirm?  ");
X`009status = 1;
X`009i = c[0] = 0;
X`009while ((status==1) && (i < 11) && (c[0] != 13)) {
X                status = sys$qiow(2,tt_chan,97,0,0,0,&c,1,0,0,0,0);
X                TEMP[i++] = toupper(c[0]);
X`009}
X
X`009if (strcmp(TEMP,password) != 0) {
X`009`009printf("%c[9;42H",esc);
X`009`009printf("Unlocked!\007");
X`009`009printf("%c[9;67H",esc);
X`009`009password[0] = 0;
X`009`009return;
X`009}
X
X        printf("%c[9;42H",esc);
X`009printf("LOCKED!  ");
X        printf("%c[9;67H",esc);
X        return;
X}
X 
Xunlock_term()
X{
X        int status, i;
X        char c[2], TEMP[10];
X 
X        for(i = 0; i < 11; TEMP[i++] = 0);
X 
X        if (password[0] == 0) return (0);
X 
X        printf("%c[9;42H",esc);
X`009printf("Unlock?  ");
X        status = 1;
X        i = 0;
X        while ((status==1) && (i < 11) && (c[0] != 13)) {
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        }
X 
X        printf("%c[9;42H         ",esc);
X 
X        if (strcmp(TEMP,password) != 0) {
X                printf("%c[9;42H",esc);
X`009`009printf("LOCKED!  \007");
X                printf("%c[9;67H",esc);
X`009`009printf("%c[6;42H",esc);
X`009`009printf("%d Failed unlocks",++bad_tries);
X`009        printf("%c[9;67H",esc);
X                return (-1);
X        }
X 
X`009printf("%c[6;42H%d Failed unlocks",esc, (bad_tries = 0));
X`009printf("%c[9;42H",esc);
X`009printf("UNLOCKED!  ");
X        printf("%c[9;67H",esc);
X        password[0] = 0;
X        return (0);
X}
$ GOSUB UNPACK_FILE
$ EXIT
-+-+-+-+-+ End of part 3 +-+-+-+-+-

