>From: lenny@icus.UUCP (Lenny Tropiano)
Newsgroups: comp.sys.att,unix-pc.sources
Subject: What does phtoggle really do... (was Re: Voice --> Data)
Date: 9 Aug 88 04:24:19 GMT

In article <300@amanue.UUCP> jr@amanue.UUCP (Jim Rosenberg) writes:
|>In article <618@gvgspd.GVG.TEK.COM> mrk@gvgspd.GVG.TEK.COM (Michael R. Kesti) writes:
|>>Can someone tell us how to switch from voice to data (and vice versa)
|>>from other than UA?
|>
|>You need to get phtoggle.  Do I remember correctly that this is public domain
|>& was posted to unix-pc.sources?

phtoggle & phdial really are *very* simple programs.  Most of the work
is done by the phone manager itself (/etc/ph).   The method used in
communicating with the phone manager is to place commands in the file
/usr/lib/ua/phnum, and then send the signal 17 (SIGUSR2) to the pid of
the ph process (ie. /usr/lib/ua/phpid).

For those who care on how this is done, I've included my implementation
of the phtoggle program [ NOTE: the executable is the same size as the
/usr/bin/phtoggle -- Pretty good reverse engineering :-) ]

There are noted bugs using the message(3T) calls to put the error messages
on the screen.  message(3T) is supposed to create a window first and then
use it.  I don't see it creating a window, therefore if you do get an
error you will need something like "windy" to restore your window size...

For those binary hackers:  Look in the string table of /etc/ph for valid
commands for /usr/lib/ua/phnum... 
eg.
	Dial %s -- Dial a phone number (used by phdial)
	Line    -- Switch lines
	Newdir  -- Pull up the directory/call screen
	Login   -- tell the phone manager you logged in
	Logout  -- conversely tell them you logged out

	Logname -- tell the phone manager you are working with Logname's
		   phone stuff.

	Syntax for the phnum file with 'Logname'

		Logname
		login-id
		home-directory

	eg.
		Logname
		lenny
		/u/lenny

There seems to be a little security problem (what else is new...) with phstub.
It doesn't do any sanity checking making sure you aren't trying to get
someone else's phone info.  I guess that's what you get from s-bit'd 
programs...

Try this:

$ phstub someone-else /u/someone-else's-directory

Someone should rewrite phstub (before I do) to check to make sure you
are the user who is requesting the information (unless you are "root",
maybe).

--- snip here --- --- snip here --- --- snip here --- --- snip here ---
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile phtoggle.c
# Wrapped by lenny@icus on Tue Aug  9 00:10:18 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(394 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile for phtoggle implementation.
X# By Lenny Tropiano            (lenny@icus.UUCP)
X# (c)1988 ICUS Software Systems
X
XCFLAGS = -v -O 
XLDFLAGS = -s
XBINDIR = /usr/lbin
XSHAREDLIB = /lib/crt0s.o /lib/shlib.ifile
X
Xphtoggle: phtoggle.o
X	ld $(LDFLAGS) -o phtoggle phtoggle.o $(SHAREDLIB)
X
Xinstall: phtoggle 
X	chown root phtoggle 
X	chgrp root phtoggle 
X	chmod 4755 phtoggle 
X	mv phtoggle $(BINDIR)
END_OF_FILE
if test 394 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'phtoggle.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'phtoggle.c'\"
else
echo shar: Extracting \"'phtoggle.c'\" \(3253 characters\)
sed "s/^X//" >'phtoggle.c' <<'END_OF_FILE'
X/************************************************************************\
X**                                                                      **
X** Program name: phtoggle.c (Toggle phone line)                         **
X** Programmer:   Lenny Tropiano            UUCP: ...icus!lenny          **
X** Organization: ICUS Software Systems                                  **
X** Date:         August 8, 1988                                         **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X** Program use:                                                         **
X**                                                                      **
X** This program is the source code (not derived from AT&T source) but   **
X** reverse engineered from binary of /usr/bin/phtoggle.   This will     **
X** tell the phone manager to toggle the lines.                          **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X** Caveats:                                                             **
X**                                                                      **
X** I believe this program will only be functional under release 3.51    **
X** of the UNIX PC operating system.  It needs to send certain commands  **
X** to the /etc/ph (phone manager process) via the a file and then send  **
X** a signal to wake up the process.  It may run under 3.5, but I don't  **
X** have a machine running it.  I doubt it will work under 3.0 at all.   **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X** Permission is granted to copy, redistribute and modify without any   **
X** explicit contact with the author, as long as, the above header       **
X** remains intact.   Any bugs, revisions, modifications or updates      **
X** should be sent to the author so that he can keep future enhancements **
X** up to date.                                                          **
X**                                                                      **
X\************************************************************************/
X
X#include <stdio.h>
X#include <message.h>
X#include <fcntl.h>
X#include <sys/signal.h>
X#include <sys/window.h>
X
Xmain()
X{
X	int	phpid;			/* process id of the /etc/ph process */
X	FILE	*pidfp, *numfp;
X
X	winit();
X	if ((pidfp = fopen("/usr/lib/ua/phpid", "r")) != NULL) {
X		if (fscanf(pidfp, "%d", &phpid) != NULL) {
X			if ((numfp = fopen("/usr/lib/ua/phnum", "w")) != NULL) {
X				fprintf(numfp, "Line");
X				fclose(numfp);
X				kill(phpid, SIGUSR2);
X			} else 
X				message(MT_ERROR, (char *) NULL, (char *) NULL, 
X				     "Error communicating with Phone Manager");
X		}
X		fclose(pidfp);
X	} else 
X		message(MT_ERROR, (char *) NULL, (char *) NULL, 
X		     "Error Obtaining Phone Manager Process ID");
X	wexit(0);
X}
END_OF_FILE
if test 3253 -ne `wc -c <'phtoggle.c'`; then
    echo shar: \"'phtoggle.c'\" unpacked with wrong size!
fi
# end of 'phtoggle.c'
fi
echo shar: End of shell archive.
exit 0
-- 
Paper-net: Lenny Tropiano          | @-net:         lenny@icus.UUCP
           ICUS Software Systems   | !-net:      ...sbcs   \
           PO Box 1                |                boulder \
           Islip Terrace, NY 11752 |                talcott  !icus!lenny
Vocal-net: (516) 582-5525 [work]   |                pacbell /
           (516) 968-8576 [home]   |                hombre /
Telex-net: 154232428 ICUS          | Another-net:   attmail!icus!lenny



