[comp.sys.att] phconfig

dca@toylnd.UUCP (08/27/87)

Here is my stuff for manipulating the phone lines from the shell.
Not much to it.  Hope others find it useful.

David Albrecht
-------- cut here ---------
#!/bin/sh
echo 'Start of ../phcon, part 01 of 01:'
echo 'x - READ.ME'
sed 's/^X//' > READ.ME << '/'
XThis is a collection of stuff I use to manage my files on my 7300.
XI only use one phone line which I mostly want to dial out on.
XThese shell scripts allow me to easily control the phone line from
Xthe shell.  The uucico.c executable is meant to be put in place of
Xuucico while uucico is renamed to uucico.exe.  The main function of
Xuucico.c is simply to invoke a shell for uucico.sh.  I didn't feel
Xlike recoding uucico.sh in C.  You will find uucico in '/usr/lib/uucp'.
XThe uucico.sh should also be put in '/usr/lib/uucp'.
X
XI included my little uupoll exe which I also use quite frequently.
XNote: if you use uupoll it must be chown to uucp and the suid
Xbit set to work.
X
XDavid Albrecht
/
echo 'x - makefile'
sed 's/^X//' > makefile << '/'
Xinclude $(MAKEINC)/Makepre.h
X
Xuucico: uucico.o
X	$(LD) $(SHAREDLIB) -o uucico uucico.o
X
Xuupoll: uupoll.o
X	$(LD) $(SHAREDLIB) -o uupoll.exe uupoll.o
X    
/
echo 'x - phconfig'
sed 's/^X//' > phconfig << '/'
Xif [ ! -s /usr/spool/uucp/LCK..ph0 ]
Xthen
X    TYP="$1"
X    SYS="$2"
X    if [ "x$SYS" != "x" ]
X    then
X	SYSTEM=`fgrep $SYS /usr/lib/uucp/L.sys | tail -1`
X	if [ "x$SYSTEM" = "x" ]
X	then
X	    echo "invalid system specification = $SYS"
X	    exit
X	fi
X	set $SYSTEM
X	if [ "$1" != "$SYS" ]
X	then
X	    echo "invalid system specification = $SYS"
X	    exit
X	fi
X    fi
X
X    case $TYP in
X	-b) TYP="BIDIRECTIONAL";setgetty ph0 1 ;;
X 	-r) TYP="INCOMING";	setgetty ph0 1 ;;
X	-s) TYP="OUTGOING";	setgetty ph0 0 ;;
X	-d) TYP="OFF";		setgetty ph0 0 ;;
X	-o) TYP="ONESHOT";	setgetty ph0 0 ;;
X	BIDIRECTIONAL)		setgetty ph0 1 ;;
X	INCOMING)		setgetty ph0 1 ;;
X	OUTGOING)		setgetty ph0 0 ;;
X	OFF)			setgetty ph0 0 ;;
X	ONESHOT)		setgetty ph0 0 ;;
X	 *) echo "invalid type specification = $TYP"; exit ;;
X    esac
X
X    rm -f /usr/spool/uucp/.phconfig
X    if [ "$TYP" != "OFF" ]
X    then
X	cat >/usr/spool/uucp/.phconfig <<END
XTYP="$TYP"
XSYS="$SYS"
XEND
X    fi
Xelse
X    echo "line locked, unable to config"
Xfi
/
echo 'x - phconfig.1'
sed 's/^X//' > phconfig.1 << '/'
X.TH MAN 1 "20 May 1987"
X.SH NAME
Xphconfig \- configure uucp phone line
X.SH SYNOPSIS
X.B phconfig \-[rsdb]
X.PP
X.B phconfig [\-o]
X[
X.B system
X]
X.SH DESCRIPTION
X.I Phconfig
Xis process which allows easy alteration of a dial-in/dial-out line
Xon a single line 7300 Unix PC.
XThe various command line options setup the phone line for each of the
Xvarious permutations of dial-in/dial-out access.  As any option is
Xexclusive of the other options only one is valid for configuration.
X.PP
XSpecifically:
X.TP 1.0i
X.B "-r"
Xdial-in only access.
X.TP
X.B "-s"
Xdial-out only access.
X.TP
X.B "-b"
Xdial-in/dial-out access.
X.TP
X.B "-d"
Xdisabled access.
X.PP
XThe \-o option is a special case of the \-s form which reverts to disabling
Xboth dial-in and dial-out after a successful uucico transmission to
Xthe specified system.
X.PP
XNote that this program requires wrapping a shell around the uucico process
Xwhich checks the .phconfig file and that it interfaces poorly with the phone
Xmanager (i.e. not at all).  More specifically you must re-phconfig any
Xtime after altering the line status from VOICE to DATA in the phone manager
Xto get the incoming line setup right, the outgoing line setup is not affected
Xby the phone manager, however.  Alternatively you can use the phset command in some
Xconvenient place and it will setup the phone line appropriately.
X.SH FILES
X.TP 38
X/usr/spool/uucp/.phconfig
X.SH AUTHOR
XDavid C. Albrecht
X.SH DIAGNOSTICS
XHopefully self-explanatory.
X.SH BUGS
X.I Phconfig
Xis really only a hack which can be useful but isn't generic enough i.e.
Xit is only meant for one phone line systems.  It also interfaces poorly
Xwith the phone manager mainly because I don't know how to trap an exit from the
Xphone manager.
X
/
echo 'x - phset'
sed 's/^X//' > phset << '/'
X/usr/bin/phstub $1 $2
Xif [ -s /usr/spool/uucp/.phconfig ]
Xthen
X    . /usr/spool/uucp/.phconfig
Xelse
X    TYP="OFF"
X    SYS=""
Xfi
X/usr/local/bin/phconfig "$TYP" "$SYS"
X
/
echo 'x - uucico.c'
sed 's/^X//' > uucico.c << '/'
Xchar *exe = "/bin/sh";
Xchar *script = "/usr/lib/uucp/uucico.sh";
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{   char *nargv[20], **ap1, **ap2;
X
X    
X    ap2 = nargv;
X    *(ap2++) = exe;
X    *(ap2++) = script;
X    ap1 = argv + 1;
X    while (*ap1) *(ap2++) = *(ap1++);
X    execv("/bin/sh", nargv);
X}
/
echo 'x - uucico.sh'
sed 's/^X//' > uucico.sh << '/'
Xif [ ! -s /usr/spool/uucp/LCK..ph0 ]
Xthen
X    if [ -s /usr/spool/uucp/.phconfig ]
X    then
X 	. /usr/spool/uucp/.phconfig
X	if [ "$TYP" != "INCOMING" ]
X	then
X	    /usr/lib/uucp/uucico.exe $*
X	fi
X	if [ "$TYP" = "ONESHOT" ]
X	then
X	    if [ "x$SYS" = "x" ]
X	    then
X		set `egrep OK\|FAILED /usr/spool/uucp/LOGFILE | tail -1`
X	    else
X		set `fgrep $SYS /usr/spool/uucp/LOGFILE | egrep OK\|FAILED | tail -1`
X	    fi
X	    if [ "$4" = "OK" ]
X	    then
X		rm -f /usr/spool/uucp/.phconfig
X	    fi
X	fi
X	if [ "$TYP" != "INCOMING" -a "$TYP" != "BIDIRECTIONAL" ]
X	then
X	    setgetty ph0 0
X	fi
X    fi
Xfi
/
echo 'x - uupoll'
sed 's/^X//' > uupoll << '/'
Xif [ -s /usr/spool/uucp/LCK..ph0 ]
Xthen
X    echo "phone device ph0 is locked"
Xelse
X    if [ ! -s /usr/spool/uucp/.phconfig ]
X    then
X	echo "communication line is disabled by configuration file"
X    else
X	. /usr/spool/uucp/.phconfig
X	if [ "$TYP" != "BIDIRECTIONAL" -a "$TYP" != "OUTGOING" -a "$TYP" != "ONESHOT" ]
X	then
X	    echo "outgoing line is disabled by configuration file"
X	else
X	    /usr/local/bin/uupoll.exe $*
X	fi
X    fi
Xfi
/
echo 'x - uupoll.c'
sed 's/^X//' > uupoll.c << '/'
X#define TRUE 1
X#define FALSE 0
X#define MAXSTRING 132
X
X#include <stdio.h>
X#include <string.h>
X
XFILE *lsys;
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{   int found = FALSE;
X    char *str, in_string[MAXSTRING];
X
X    if (argc == 2) {
X	lsys = fopen("/usr/lib/uucp/L.sys","r");
X	while (fgets(in_string, MAXSTRING, lsys)) {
X	    if (*in_string != '#') {
X		if (str = strchr(in_string,' ')) {
X		    *str = '\0';
X		    if (!strcmp(in_string, argv[1])) {
X			found = TRUE;
X			break;
X		    }
X		}
X	    }
X	}
X    }
X    if (found) {
X	strcpy(in_string, "/usr/spool/uucp/STST.");
X	strcat(in_string, argv[1]);
X	unlink(in_string);
X	sprintf(in_string, "-c%s", argv[1]);
X	execl("/usr/lib/uucp/uusub", "uusub", in_string, 0);
X    }
X    else {
X	fprintf(stderr, "%s : Invalid system specification\n", argv[0]);
X    }
X}
/
echo 'Part 01 of ../phcon complete.'
exit