home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume41 / planner / part01 next >
Text File  |  1994-01-09  |  36KB  |  983 lines

  1. Newsgroups: comp.sources.misc
  2. From: franklin@ug.cs.dal.ca (Steve Franklin)
  3. Subject: v41i082:  planner - Named pipe for random .plan or .signature, Part01/01
  4. Message-ID: <1994Jan10.033921.11121@sparky.sterling.com>
  5. Summary: Superior finger logging
  6. X-Md4-Signature: f7c1df91c7aa695c33d8bdc1ba983d7b
  7. Sender: kent@sparky.sterling.com (Kent Landfield)
  8. Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
  9. Date: Mon, 10 Jan 1994 03:39:21 GMT
  10. Approved: kent@sparky.sterling.com
  11.  
  12. Submitted-by: franklin@ug.cs.dal.ca (Steve Franklin)
  13. Posting-number: Volume 41, Issue 82
  14. Archive-name: planner/part01
  15. Environment: Finger
  16. Supersedes: planner: Volume 39, Issue 48
  17.  
  18. Here is another update to the planner script that has been contributed
  19. to by countless users that are all mentioned throughout the README file. I 
  20. have certainly contributed the least to any of the code of this project,
  21. but was more concerned with putting some utility and functionality into it. 
  22.    Hopefully people will continue to have more ideas that they can put into
  23. this. In case people are curious, I've logged approximately 30,000 finger 
  24. requests to my account, and it's still as reliableas ever. I have looked
  25. at all the available packages, and have to say that this seems to be the
  26. sturdiest and "frilliest" package that is available. Basically lets you do
  27. anything to your .plan that you could ever want. Check it out by fingering
  28.     franklin@ug.cs.dal.ca
  29.  
  30. The change to this package that merits a repost is that it will no longer
  31. hang your machine when a mirror host (NFS mounted volume) is fingered. Before,
  32. the .plan was a named pipe which pointed to a background process. However,
  33. this background process did not exist on other machiens that had the same
  34. file system, so it would just hang the finger daemon (bad). So, to get around 
  35. this, the named pipe is placed in the /tmp disk, and a symbolic link to 
  36. the .plan file is made (credits go to Fumiaki Kamiya). Then, people will
  37. simply get a "No Plan" message when they finger other hosts that do not have
  38. the resident background process.
  39.  
  40. People should also note that this is incredibly cpu-friendly. It gets the
  41. host-name of the machine that is fingering you through a simple step involving
  42. netstat (but only taking a head-20 of the output). 
  43.  
  44. It should also be noted that this will NOT run on ULTRIX, disabled finger 
  45. daemons, or, of course, VMS. I would not recommend that any new users
  46. work with this, because it can definitely peeve your system administrator,
  47. and because you will have to play with the code to get it working. To any
  48. moderate to advanced UNIX user, it should be quite easy - just take a bit
  49. of tweaking. I haven't been able to figure out an easy way to make the code
  50. universal, because there are so many places where you have to change pathnames,
  51. usernames, etc. But, you should be able to get it running flawlessly in under
  52. an hour at the very most.
  53.  
  54. Hoping you have fun with this, and hoping your New Year's Celebration was
  55. as good as mine,
  56.  
  57. Steve Franklin
  58. ---------------
  59. #! /bin/sh
  60. # This is a shell archive.  Remove anything before this line, then feed it
  61. # into a shell via "sh file" or similar.  To overwrite existing files,
  62. # type "sh file -c".
  63. # Contents:  planner planner/Makefile planner/Makefile.old
  64. #   planner/README planner/README.old planner/changes
  65. #   planner/logfinger planner/plan.1 planner/plan.c planner/planner
  66. #   planner/planner1.0.header planner/scripts planner/scripts/delplan
  67. #   planner/scripts/killplan planner/scripts/lf
  68. #   planner/scripts/renewplan planner/scripts/rf
  69. # Wrapped by kent@sparky on Sun Jan  9 21:35:11 1994
  70. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  71. echo If this archive is complete, you will see the following message:
  72. echo '          "shar: End of archive 1 (of 1)."'
  73. if test ! -d 'planner' ; then
  74.     echo shar: Creating directory \"'planner'\"
  75.     mkdir 'planner'
  76. fi
  77. if test -f 'planner/Makefile' -a "${1}" != "-c" ; then 
  78.   echo shar: Will not clobber existing file \"'planner/Makefile'\"
  79. else
  80.   echo shar: Extracting \"'planner/Makefile'\" \(32 characters\)
  81.   sed "s/^X//" >'planner/Makefile' <<'END_OF_FILE'
  82. Xplan: plan.c
  83. X    cc -o plan plan.c
  84. END_OF_FILE
  85.   if test 32 -ne `wc -c <'planner/Makefile'`; then
  86.     echo shar: \"'planner/Makefile'\" unpacked with wrong size!
  87.   fi
  88.   # end of 'planner/Makefile'
  89. fi
  90. if test -f 'planner/Makefile.old' -a "${1}" != "-c" ; then 
  91.   echo shar: Will not clobber existing file \"'planner/Makefile.old'\"
  92. else
  93.   echo shar: Extracting \"'planner/Makefile.old'\" \(1401 characters\)
  94.   sed "s/^X//" >'planner/Makefile.old' <<'END_OF_FILE'
  95. XDEST          = /home/napalm/bin/fifo
  96. X
  97. XEXTHDRS          = /usr/include/fcntl.h \
  98. X        /usr/include/signal.h \
  99. X        /usr/include/stdio.h \
  100. X        /usr/include/sys/fcntl.h \
  101. X        /usr/include/sys/file.h \
  102. X        /usr/include/sys/stat.h \
  103. X        /usr/include/sys/sysmacros.h \
  104. X        /usr/include/sys/sysmacros.h \
  105. X        /usr/include/sys/types.h \
  106. X        /usr/include/sys/types.h
  107. X
  108. XHDRS          =
  109. X
  110. XLDFLAGS          =
  111. X
  112. XLIBS          =
  113. X
  114. XLINKER          = cc
  115. X
  116. XMAKEFILE      = Makefile
  117. X
  118. XOBJS          = plan.o
  119. X
  120. XPRINT          = pr
  121. X
  122. XPROGRAM          = plan
  123. X
  124. XSRCS          = plan.c
  125. X
  126. Xall:        $(PROGRAM)
  127. X
  128. X$(PROGRAM):     $(OBJS) $(LIBS)
  129. X        @echo -n "Loading $(PROGRAM) ... "
  130. X        @$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM)
  131. X        @echo "done"
  132. X
  133. Xclean:;        @rm -f $(OBJS)
  134. X
  135. Xdepend:;    @mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
  136. X
  137. Xindex:;        @ctags -wx $(HDRS) $(SRCS)
  138. X
  139. Xinstall:    $(PROGRAM)
  140. X        @echo Installing $(PROGRAM) in $(DEST)
  141. X        @install -s $(PROGRAM) $(DEST)
  142. X
  143. Xprint:;        @$(PRINT) $(HDRS) $(SRCS)
  144. X
  145. Xprogram:        $(PROGRAM)
  146. X
  147. Xtags:           $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)
  148. X
  149. Xupdate:        $(DEST)/$(PROGRAM)
  150. X
  151. X$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS)
  152. X        @make -f $(MAKEFILE) DEST=$(DEST) install
  153. X###
  154. Xplan.o: /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
  155. X    /usr/include/sys/sysmacros.h /usr/include/sys/file.h \
  156. X    /usr/include/sys/fcntl.h /usr/include/sys/types.h \
  157. X    /usr/include/fcntl.h /usr/include/stdio.h /usr/include/sys/stat.h \
  158. X    /usr/include/signal.h
  159. END_OF_FILE
  160.   if test 1401 -ne `wc -c <'planner/Makefile.old'`; then
  161.     echo shar: \"'planner/Makefile.old'\" unpacked with wrong size!
  162.   fi
  163.   # end of 'planner/Makefile.old'
  164. fi
  165. if test -f 'planner/README' -a "${1}" != "-c" ; then 
  166.   echo shar: Will not clobber existing file \"'planner/README'\"
  167. else
  168.   echo shar: Extracting \"'planner/README'\" \(3946 characters\)
  169.   sed "s/^X//" >'planner/README' <<'END_OF_FILE'
  170. XSteve Franklin  (not the original author)
  171. Xfranklin@ug.cs.dal.ca
  172. XCompiled on January 1st, 1994 
  173. X
  174. XBefore I continue by describing what all of this does, I should point out that
  175. XI am not the original author of this software. I have modified it like
  176. Xmany before me and am now trying to simplify the documentation as so many
  177. Xusers have requested.
  178. X
  179. XPurpose: The purpose of planner is to create an ultra cool .plan file so
  180. X         that people can get random .plan's when they finger you. It
  181. X         can be used in a variety of ways, and depending on how creative
  182. X         you are, can make you rich beyond your wildest dreams (well, sorta)
  183. X
  184. XContents:   Makefile      Self-explanatory - type "make" to compile
  185. X            delplan       Kills the current running plan process on this host
  186. X            killplan      Creates an at job to keep track of plan so that if
  187. X                          the machine reboots, then it resets itself
  188. X            logfinger     Hardly changed this - perl script to log whos fingering
  189. X            lf            Short script to let you know when you were last fin'd
  190. X            plan.1        Man page
  191. X            plan.c        C-code for the plan application
  192. X            planner       Shell script that shows a couple of neat tricks
  193. X            readme.orig   Original read me that was getting a tad "congested"
  194. X            renewplan     Script for starting up plan cleanly.
  195. X            rf            Takes a numeric argument to show you the last # of
  196. X                          fingers
  197. XChanges: The latest big change has been the eradication of the 'hanging'
  198. X         problem on shadow machines (NFS mounted volumes). To get around
  199. X         this, Fumiaki Kamiya <kamiya@SLINKY.CS.NYU.EDU> recommended putting
  200. X         the named pipe file on the tmp disk, then doing a symbolic link
  201. X         to the $HOME/.plan file. Then, when fingered on any mirror sites, 
  202. X         the .plan file doesn't point to anything, giving the "No Plan" msg.
  203. X
  204. X         The original plan seemed quite concerned with who was fingering you 
  205. X         from your local machine, but just logged "somebody" as fingering
  206. X         you if it was from another machine. All it took was a few additions
  207. X         (a la netstat) to let you figure out which machine is fingering you
  208. X         and a few more changes to impress the fingerer by letting them
  209. X         know their hostname. These settings are recorded into a file that
  210. X         you can later query.
  211. X
  212. XRequirements:  In order to run plan, you need bsd-ish architecture. Users
  213. X               running ULTRIX are out of luck, as are VMS users of course.
  214. X
  215. XInstructions:  The simplest way to sort through this is to first edit
  216. X               "planner","renewplan" and "logfinger" to resemble your environ.
  217. X               and your preferences. Then, place plan and renewplan in 
  218. X               your bin directory or any dir that your $PATH variable points 
  219. X               to. Simply type "renewplan" and it does the rest for you.
  220. X
  221. XQuestions:     Feel free to send questions to franklin@ug.cs.dal.ca
  222. X               but please try to read through all the documentation as well.
  223. X
  224. XCautions:      If your machine reboots, you will have an empty named pipe
  225. X               pointing at no process (it doesn't exist since the machine 
  226. X               rebooted). So, you have to restart the plan process (renewplan)
  227. X               after a reboot. If you don't catch it, people's finger 
  228. X               processes will clog up your finger port. To get around this
  229. X               I had an "at + 1 hour..." included in "renewplan" to re-exec
  230. X               renewplan every hour - if there was a reboot, plan would
  231. X               start up no more than an hour after the reboot. 
  232. X
  233. XExample:       Check out franklin@ug.cs.dal.ca for an example of how the
  234. X               planner pipe can be used - hopefully it's up and running :)
  235. X               Hopefully you guys will mail me if you get neat ideas of
  236. X               your own...
  237. END_OF_FILE
  238.   if test 3946 -ne `wc -c <'planner/README'`; then
  239.     echo shar: \"'planner/README'\" unpacked with wrong size!
  240.   fi
  241.   # end of 'planner/README'
  242. fi
  243. if test -f 'planner/README.old' -a "${1}" != "-c" ; then 
  244.   echo shar: Will not clobber existing file \"'planner/README.old'\"
  245. else
  246.   echo shar: Extracting \"'planner/README.old'\" \(5668 characters\)
  247.   sed "s/^X//" >'planner/README.old' <<'END_OF_FILE'
  248. XAll I did was to put in a function that keeps track of the PID for
  249. Xplan by writing it to a file called ".planpid" in your home directory.
  250. XNow you run plan in your .login, and, to kill the process when you log
  251. Xout, put something like this in your .logout:
  252. X
  253. X    kill `cat /home/mine/.planpid`
  254. X    rm -f /home/mine/.planpid
  255. X
  256. XYou have to remove the .planpid (or modify the code), because the 
  257. Xprogram will not run if a plan is already running, which it assumes
  258. Xwhen it finds a .planpid file already there.
  259. X
  260. XIf someone wanted to run multiple plans, maybe one for a .signature
  261. Xand another for a .plan, the save name for the PID could be changed,
  262. Xand the program compiled twice (the binary is not that big, ~40K on
  263. Xthe HP 425's I used), or, if someone is really motivated, they could
  264. Xadd a command line argument for the save name.
  265. X
  266. XSure, my modification isn't very complex, but it does what I needed
  267. Xit to do, and maybe someone else can use it.
  268. X
  269. XKaren    (napalm@ugcs.caltech.edu)
  270. X
  271. X****  Additions by Geoff Loker ****
  272. X
  273. XI have modified Tony Rems' code for plan a bit to get rid of the
  274. Xnecessity for hard-coding in the file name to be set up as a FIFO.
  275. XThe program will now accept an optional argument that specifies the
  276. Xname of the FIFO to be used.  If that argument is not set, the default
  277. XFIFO is $HOME/.plan.
  278. X
  279. XIn order to use this program, your O/S needs to support named pipes.
  280. XYou also need to link in getopt for the changes to work.
  281. X
  282. XAny executable program can be set up to run when the specified FIFO is
  283. Xopened, but don't forget that the program you specify to run is being
  284. Xrun under your userid.
  285. X
  286. X****  Original README ****
  287. X
  288. XDate: Thu, 11 Apr 91 14:09:10 MST
  289. XFrom: Jim Armstrong <armstron@cs.arizona.edu>
  290. XSubject: RE: fingeree ...
  291. X
  292. X> >About a month ago there was a sample program posted to this newsgroup that
  293. X> >set up a FIFO named pipe as your .plan file.  I modified the code to set up
  294. X> >a simple (perhaps naive) finger monitor for users on my machine.  The process
  295. X> do you still have the source for it? would you send it to me?
  296. X
  297. XHere is the article which appeared in comp.unix.questions a while back.  It
  298. Xcontains generic code that will run any program you want whenever a certain
  299. Xfile is accessed (i.e. the .plan file in this case).  All you have to do is
  300. Xcompile it (it creates an executable called 'plan') and then to get it
  301. Xrunning say 'plan a.out &' where a.out is some program you have written.
  302. XI don't have my program any more, but basically what I did was a ps au
  303. Xwithin that program.  It used egrep to search for someone currently fingering
  304. Xme and appended the output to a file.  To get really fancy you could then
  305. Xread from that file to find out exactly who it is (all in the same program)
  306. Xand print out a nice personal message to whoever is fingering you as part
  307. Xof what looks to be your .plan file.  A couple of things to watch out for:
  308. XIf the finger is remote, the ps au won't find anything.  Also, if two people
  309. Xfinger you at the same time you may run into trouble, but I didn't try
  310. Xexperimenting with this too much.  I also found it helpful to timestamp a
  311. Xdate to the file, too (I used localtime() for efficiency).  This makes it
  312. Xeasier to look back later at the file and see who's been fingering you and
  313. Xwhen while you were not logged on.  It also helpful in debugging your program.
  314. X
  315. XSo set up this code and experiment with different programs.  Just be creative
  316. Xand see what else you can do with it.  One idea I used for a while is making
  317. Xit print a different quote each time.  The possibilites are endless.  Enjoy.
  318. X
  319. XJim
  320. X
  321. X
  322. XArticle 31270 of comp.unix.questions:
  323. XFrom: rembo@unisoft.UUCP (Tony Rems)
  324. XNewsgroups: comp.unix.questions
  325. XSubject: Re: Finger
  326. XDate: 22 Feb 91 02:44:17 GMT
  327. XReply-To: rembo@unisoft.UUCP (Tony Rems)
  328. XOrganization: UniSoft Corporation -- UNIX R Us.
  329. X
  330. XIn article <37675@netnews.upenn.edu> minzhi@eniac.seas.upenn.edu (Min-Zhi Shao) writes:
  331. X>
  332. X>    When I fingered our system administrator, I got the following result:
  333. X>
  334. X>_________________________________________________________________________
  335. X>Login name: gardella              In real life: Ed Gardella [CETS]
  336. X>Directory: /home/cets/gardella          Shell: /usr/local/bin/bash
  337. X>On since Feb 15 19:49:04 on ttyp1 from TSTEST.SEAS.UPEN
  338. X>14 minutes Idle Time
  339. X>No unread mail
  340. X>Project: System Administrator eniac.seas.upenn.edu
  341. X>Plan:
  342. X>         Meander about until something interesting comes along.
  343. X>
  344. X>Office: 154 Moore Building           Work Phone: 898-2491
  345. X>                                     Home Phone: 387-4104
  346. X>
  347. X>I have been fingered 3 times today
  348. X>_________________________________________________________________________
  349. X>
  350. X>the .plan file in his home directory looks like:
  351. X>
  352. X>prw-r--r--  1 gardella        0 Feb 15 23:48 /home/cets/gardella/.plan
  353. X>^
  354. X
  355. XAs you have found out by now, I'm sure, the p means that this is 
  356. Xa named pipe aka a FIFO.  If you'd like to do this yourself, here
  357. Xis a little program I wrote to do it (see the comments at the
  358. Xthe beginning of the plan.c file for usage info):  
  359. X
  360. XHere's the shar of my plan program, just cut up until it says
  361. X"cut here", and then type 'sh filename' using whatever filename
  362. Xyou save it as.  If you use 'plan' it will get overwritten.
  363. X
  364. XThe code here should compile w/o any problems on any BSD machine,
  365. XI have tried it on a Sun, Vax 750, and Pyramid 90x.  It should
  366. Xalso work properly on any SVR4.0 machine.  
  367. X
  368. XThe code is pretty heavily commented so it should be self
  369. Xexplanatory.  
  370. X
  371. XNote that you should put a -DFILENAME="your_home_dir/.plan"
  372. Xto get it to put your path in, or you can just edit the 
  373. Xsource and change the value of FILENAME permanently.  
  374. X
  375. XIf you have any problems getting it compiled, just send me mail.
  376. X
  377. XEnjoy.  
  378. X
  379. X-Tony
  380. X
  381. END_OF_FILE
  382.   if test 5668 -ne `wc -c <'planner/README.old'`; then
  383.     echo shar: \"'planner/README.old'\" unpacked with wrong size!
  384.   fi
  385.   # end of 'planner/README.old'
  386. fi
  387. if test -f 'planner/changes' -a "${1}" != "-c" ; then 
  388.   echo shar: Will not clobber existing file \"'planner/changes'\"
  389. else
  390.   echo shar: Extracting \"'planner/changes'\" \(431 characters\)
  391.   sed "s/^X//" >'planner/changes' <<'END_OF_FILE'
  392. XSteve Franklin  (not the original author)
  393. Xfranke1@llnl.gov
  394. XAugust 10, 1993
  395. X
  396. XHere is yet another modification of the origial plan FIFO utility.o
  397. XPlease see README.old and readme.orig for more information.
  398. X
  399. XChanges:
  400. X    Added -d daemon command switch.
  401. X    Karen's PID stuff was changed to cleanup .plan and .planpid upon exit.
  402. X    Added PIDCHECK precompiler directive to comment the above out if you wish.
  403. X    Cleaned up code a bit.
  404. END_OF_FILE
  405.   if test 431 -ne `wc -c <'planner/changes'`; then
  406.     echo shar: \"'planner/changes'\" unpacked with wrong size!
  407.   fi
  408.   # end of 'planner/changes'
  409. fi
  410. if test -f 'planner/logfinger' -a "${1}" != "-c" ; then 
  411.   echo shar: Will not clobber existing file \"'planner/logfinger'\"
  412. else
  413.   echo shar: Extracting \"'planner/logfinger'\" \(615 characters\)
  414.   sed "s/^X//" >'planner/logfinger' <<'END_OF_FILE'
  415. X#!/usr/bin/perl -- # -*-Perl-*-
  416. X
  417. X$me = "franklin";
  418. X$logfile = "/users/students/franklin/.dots/.fingerees";
  419. X$pscommand = "ps -auw";
  420. X
  421. Xopen(PS, "$pscommand |");
  422. X@fingers = grep(/(f\s+$me)|(finger\s+$me)/, <PS>);
  423. Xclose(PS);
  424. X
  425. X#($num) = unpack("A9", `wc -l $logfile`); # =~ s/^\s*(\d+).*\n/\1/;
  426. X#($num2) = $num/2;
  427. X#printf "I have been fingered %d time", $num2;
  428. X#print "s" if ($num - 1);
  429. X#print " today\n";
  430. X#close(STDOUT);
  431. X
  432. Xopen(LOG, ">>$logfile");
  433. Xforeach $line (@fingers) {
  434. X    ($user) = $line =~ /^\s*(\S+)/;
  435. X    print LOG "$user, at ", `date`;
  436. X}
  437. X
  438. Xprint(LOG "somebody, at ", `date`) if (! ($#fingers + 1));
  439. Xclose(LOG);
  440. END_OF_FILE
  441.   if test 615 -ne `wc -c <'planner/logfinger'`; then
  442.     echo shar: \"'planner/logfinger'\" unpacked with wrong size!
  443.   fi
  444.   chmod +x 'planner/logfinger'
  445.   # end of 'planner/logfinger'
  446. fi
  447. if test -f 'planner/plan.1' -a "${1}" != "-c" ; then 
  448.   echo shar: Will not clobber existing file \"'planner/plan.1'\"
  449. else
  450.   echo shar: Extracting \"'planner/plan.1'\" \(1603 characters\)
  451.   sed "s/^X//" >'planner/plan.1' <<'END_OF_FILE'
  452. X.TH PLAN L "\*(V)" "4BSD"
  453. X.SH NAME
  454. Xplan - run an executable when a specified FIFO is opened
  455. X.SH SYNOPSIS
  456. X.B plan
  457. X[
  458. X.BR -d
  459. X] [
  460. X.BR -f file
  461. X]
  462. X.B executable
  463. X.SH DESCRIPTION
  464. X.I plan
  465. Xtakes the name of an executable program and runs it on a FIFO that
  466. Xis specified on the command line or on a FIFO in the user's home directory
  467. Xnamed .plan.  Whenever the FIFO is accessed, the output of the executable
  468. Xprogram goes to the FIFO.  It writes it's PID a file, so the process
  469. Xcan be killed during logout, and it checks for the existence of this
  470. Xfile to make sure plan isn't already running.
  471. X.SH OPTIONS
  472. X.TP
  473. X.B \-d
  474. XRun \fIplan\fR in daemon mode.
  475. X.PP
  476. X.TP
  477. X.B \-f file_name
  478. XThe \fB\-f flag causes \fIplan\fR to set up the specified \fBfile_name\fR
  479. Xas a FIFO rather than the default \fB$HOME/.plan\fR.
  480. X.PP
  481. XSome sample uses of \fIplan\fR would be:
  482. X.TP
  483. X.B plan -d /usr/games/fortune
  484. XThis will display a randomly selected fortune as the contents of
  485. Xyour .plan file whenever you are fingered.
  486. X.TP
  487. X.B plan -d -f ~/.signature ~/bin/gensig
  488. XThis will run the program gensig whenever your .signature file is accessed,
  489. Xallowing you to change your .signature whenever you post.
  490. X.TP
  491. X.B plan -d ~/bin/logfinger
  492. XThis will run the program logfinger whenever your .plan file is accessed,
  493. Xand you can log all instances of people fingering you.
  494. X.SH AUTHOR
  495. XTony Rems (rembo@unisoft.com)
  496. X.PP
  497. XModifications by Geoff Loker (geoff@mdms.moore.com).
  498. XMore modifications by Karen Bruner (napalm@ugcs.caltech.edu).
  499. XEven more modifications by Norman Franke (franke1@llnl.gov).
  500. X.SH BUGS
  501. XYour system must support named pipes in order for this to work.
  502. END_OF_FILE
  503.   if test 1603 -ne `wc -c <'planner/plan.1'`; then
  504.     echo shar: \"'planner/plan.1'\" unpacked with wrong size!
  505.   fi
  506.   # end of 'planner/plan.1'
  507. fi
  508. if test -f 'planner/plan.c' -a "${1}" != "-c" ; then 
  509.   echo shar: Will not clobber existing file \"'planner/plan.c'\"
  510. else
  511.   echo shar: Extracting \"'planner/plan.c'\" \(4953 characters\)
  512.   sed "s/^X//" >'planner/plan.c' <<'END_OF_FILE'
  513. X/*    THIS IS THE UNPUBLISHED SOURCE CODE OF REMBO        */
  514. X/*    The copyright notice above does not evidence any       */
  515. X/*    actual or intended publication of such source code.    */
  516. X/*    So, use it if you like, but give me credit.        */
  517. X
  518. X/*
  519. X    Usage: plan [-d] [-f file_name] program_name
  520. X
  521. X    Description:
  522. X
  523. X    This program takes the full pathname of an executable and runs it on a
  524. X    fifo in the user's home directory named .plan.  This way, when finger
  525. X    is executed, the output of the program goes to the fifo.
  526. X
  527. XWritten by:  Tony Rems
  528. X    Send bugs and flames to /dev/null or
  529. X    rembo@unisoft.com
  530. X
  531. XModifications:
  532. X
  533. X    September 1991 (by Geoff Loker geoff@mdms.moore.com)
  534. X
  535. X    Modified the program so that the path to the .plan file is not
  536. X    hardcoded in.  Now any number of users can use the program at the same
  537. X    time.  I also modified the program to use an optional argument to
  538. X    specify which file to use.  The default file used is still the user's
  539. X    .plan, but this can now also be used to set up .signatures or any other
  540. X    file the user wants.
  541. X
  542. X    January 1992 (by Karen Bruner napalm@ugcs.caltech.edu)
  543. X
  544. X    Added pid_deal function, so people can stick the program in their
  545. X    .login, and then have it killed by their .logout.  Program will not run
  546. X    if a .planpid file, the file with the PID for plan, already exists in
  547. X    the user's home Directory.
  548. X
  549. X    August 10, 1993 (by Norman Franke franke1@llnl.gov)
  550. X
  551. X    Cleaned up indenting, made PID stuff selectable via precompiler
  552. X    directive. Added chmod, else it wouldn't work on my system. Made it
  553. X    clean up old .plan and .planpid upon exit.  Made it fork, so one
  554. X    doesn't need to run in the background.
  555. X*/
  556. X
  557. X#include <sys/types.h>
  558. X#include <sys/file.h>
  559. X#include <stdio.h>
  560. X#include <fcntl.h>
  561. X#include <sys/stat.h>
  562. X#include <signal.h>
  563. X#include <string.h>
  564. X
  565. X/* Defines */
  566. X#define PERMS 0666
  567. X#define USAGE "%s [-d] [-f file_name] program_name\n"
  568. X#define PIDCHECK
  569. X
  570. X/* Function prototypes */
  571. Xvoid sig_handler();
  572. Xint pid_deal();    
  573. Xvoid write_pid();
  574. X
  575. X/* Files for later cleanup */
  576. Xchar plan[256];
  577. Xchar savepid[100];
  578. X
  579. Xextern char *optarg;
  580. Xextern int optind;
  581. X
  582. Xmain (argc, argv)
  583. Xint argc;
  584. Xchar *argv[];
  585. X{
  586. X    int c, fflg;
  587. X    char *file;
  588. X    int fd, pid, status;
  589. X    char *getenv(), *home, *strcat(), *strcpy();
  590. X    int pid_check, daemon = 0;
  591. X
  592. X    fflg = c = 0;
  593. X    while ((c = getopt(argc, argv, "df:")) != EOF) {
  594. X    switch (c) {
  595. X        case 'f':
  596. X        file = optarg;
  597. X        fflg++;
  598. X        break;
  599. X        case 'd':
  600. X        daemon = 1;
  601. X        break;
  602. X    }
  603. X    }
  604. X
  605. X#ifdef PIDCHECK
  606. X    pid_check = pid_deal();
  607. X#else
  608. X    pid_check = 1;
  609. X#endif
  610. X
  611. X    if (pid_check != 1) {
  612. X    printf("plan already running\n");
  613. X    exit(1);
  614. X    }
  615. X
  616. X    if (fflg)
  617. X    strcpy(plan, file);
  618. X    else {
  619. X    home = getenv("HOME");
  620. X    strcpy(plan, home);
  621. X    strcat(plan, "/.plan");
  622. X    }
  623. X
  624. X    if ( argc != optind + 1 ) {
  625. X    fprintf (stderr, USAGE, argv[0]);
  626. X    exit(1);
  627. X    }
  628. X
  629. X/* Catch interrupts for cleanup */
  630. X    signal(SIGTERM, sig_handler);
  631. X    signal(SIGINT, sig_handler);
  632. X    signal(SIGHUP, sig_handler);
  633. X
  634. X    unlink (plan);
  635. X
  636. X/* Make the fifo */
  637. X    if ((mknod(plan, S_IFIFO | PERMS, 0)) < 0 ) {
  638. X        perror("mknod");
  639. X        exit(2);
  640. X    }
  641. X    if ((chmod(plan, 0644)) < 0) {
  642. X        perror("chmod");
  643. X        exit(2);
  644. X    }
  645. X
  646. X    if (daemon) {
  647. X    switch (pid = fork()) {
  648. X        case -1:
  649. X        perror("fork");
  650. X        exit(4);
  651. X        case 0:
  652. X        break;
  653. X        default:
  654. X        exit(0);
  655. X    }
  656. X    }
  657. X
  658. X#ifdef PIDCHECK
  659. X    write_pid();
  660. X#endif
  661. X
  662. X    while (1) {
  663. X    if ((fd = open(plan, O_WRONLY)) < 0 ) {
  664. X        perror("open");
  665. X        exit(3);
  666. X    }
  667. X
  668. X/* Once our open completes we know that someone else has
  669. X* opened the FIFO for reading, so we can know run our 
  670. X* program on it.  So, we fork, exec our program and
  671. X* wait for the child to complete.
  672. X*/
  673. X    switch (pid = fork()) {
  674. X        case -1:
  675. X        perror("fork");
  676. X        exit(4);
  677. X        break;
  678. X/* If we're in the child, we copy our fifo to stdout */
  679. X/* and exec the program given */
  680. X        case 0:
  681. X        dup2(fd, 1);
  682. X        execlp(argv[optind],argv[optind],(void *)NULL);
  683. X        perror("child returned");
  684. X        exit(5);
  685. X        break;
  686. X/* If we're in the parent, we close the pipe and wait */
  687. X        default:
  688. X        close(fd);
  689. X        while (wait(&status) != pid);
  690. X        break;
  691. X    }
  692. X    sleep(2);
  693. X    close(fd);
  694. X    }
  695. X}
  696. X
  697. Xvoid sig_handler()  /* cleanup */
  698. X{
  699. X    unlink(plan);
  700. X    unlink(savepid);
  701. X    exit(0);
  702. X}
  703. X
  704. X#ifdef PIDCHECK
  705. Xint pid_deal()
  706. X{
  707. X    FILE *sp;
  708. X    int checker;
  709. X    char *home;
  710. X
  711. X    home = getenv("HOME");        /* put save name for file */
  712. X    strcpy(savepid, home);        /* in savepid */
  713. X    strcat(savepid, "/.planpid");
  714. X
  715. X/* test for existence of .planpid by trying to open the file for reading */
  716. X/* return a zero if read was successful, i.e., file already exists */
  717. X/* file doesn't exist, return a 1 to execute the rest of the program */
  718. X    if ((sp = fopen(savepid, "r")) != NULL) checker = 0;
  719. X    else checker = 1;
  720. X    fclose(sp);
  721. X
  722. X    return checker;
  723. X}
  724. X
  725. Xvoid write_pid()
  726. X{
  727. X    FILE *sp;
  728. X
  729. X    if (!(sp = fopen(savepid, "w"))) {
  730. X    perror("fopen");
  731. X    exit(1);
  732. X    }
  733. X    fprintf(sp, "%d", getpid());     /* puts PID for plan into file */
  734. X    fclose(sp);
  735. X} 
  736. X#endif
  737. END_OF_FILE
  738.   if test 4953 -ne `wc -c <'planner/plan.c'`; then
  739.     echo shar: \"'planner/plan.c'\" unpacked with wrong size!
  740.   fi
  741.   # end of 'planner/plan.c'
  742. fi
  743. if test -f 'planner/planner' -a "${1}" != "-c" ; then 
  744.   echo shar: Will not clobber existing file \"'planner/planner'\"
  745. else
  746.   echo shar: Extracting \"'planner/planner'\" \(1481 characters\)
  747.   sed "s/^X//" >'planner/planner' <<'END_OF_FILE'
  748. X#!/bin/sh
  749. Xecho ""
  750. Xecho ""
  751. X/pub/bin/stfortune
  752. Xecho ""
  753. Xecho ""
  754. X
  755. X
  756. Xperl $HOME/bin/planner/logfinger
  757. X#  This previous line points to the logfinger script
  758. XWHO=`netstat -n | head -25 | grep 129.173.4.4.79 | grep ESTABLISHED | head -1 | awk '{ p=NF-1;printf "%s\n",$p}' | awk -F. '{printf "%s.%s.%s.%s\n",$1,$2,$3,$4}'`
  759. X#                                                     ^^^^^^^^^^^^^
  760. X#                                  This is the finger port. Your IP number
  761. X#                                  plus .79 (the finger port suffix)
  762. X#                                  Change the IP number to reflect yours
  763. X
  764. Xif [ -z "$WHO" ]
  765. X   then WHO='129.173.4.4'
  766. Xfi
  767. X
  768. X#  If it doesn't catch any IP number fingering you then it must be a local
  769. X#  finger
  770. X
  771. XHOST=`host $WHO 2>/dev/null| grep Name | awk '{ printf "%s\n",$2 }'`
  772. Xecho "     " $WHO "->" $HOST >> $HOME/.dots/.fingerees
  773. Xecho "You're fingering me from "$WHO ", which is "$HOST
  774. XTIME=`date '+%H:%M, %D'`
  775. Xecho ""
  776. Xecho ""
  777. Xstardate=`/pub/bin/stardate`
  778. Xecho "Today's date/time is "$stardate" (STTNG format)"
  779. Xecho ""
  780. X#echo "Mail franklin@ug.cs.dal.ca, subject 00LIST (capitalized, with zeroes)"
  781. X#echo "for the latest version of the Macintosh shareware FAQ"
  782. X#echo ""
  783. Xecho "If you're not from around here..."
  784. Xnumber=`expr $$ % 13 + 1`
  785. Xif [ $number -eq "10" ]
  786. X    then number=9
  787. Xfi
  788. Xecho ""
  789. Xdotplan $number "Drop me some e-mail and say hello!"
  790. XFILE=/pub/lib/today/`date +%h.%d`
  791. Xcat $FILE
  792. Xecho "(If you do/don't like the .plan change - MAIL me and let me know!)"
  793. END_OF_FILE
  794.   if test 1481 -ne `wc -c <'planner/planner'`; then
  795.     echo shar: \"'planner/planner'\" unpacked with wrong size!
  796.   fi
  797.   chmod +x 'planner/planner'
  798.   # end of 'planner/planner'
  799. fi
  800. if test -f 'planner/planner1.0.header' -a "${1}" != "-c" ; then 
  801.   echo shar: Will not clobber existing file \"'planner/planner1.0.header'\"
  802. else
  803.   echo shar: Extracting \"'planner/planner1.0.header'\" \(2371 characters\)
  804.   sed "s/^X//" >'planner/planner1.0.header' <<'END_OF_FILE'
  805. X   Well, here is another update to the planner script that has been contributed
  806. Xto by countless users that are all mentioned throughout the README file. I 
  807. Xhave certainly contributed the least to any of the code of this project,
  808. Xbut was more concerned with putting some utility and functionality into it. 
  809. X   Hopefully people will continue to have more ideas that they can put into
  810. Xthis. In case people are curious, I've logged approximately 30,000 finger 
  811. Xrequests to my account, and it's still as reliableas ever. I have looked
  812. Xat all the available packages, and have to say that this seems to be the
  813. Xsturdiest and "frilliest" package that is available. Basically lets you do
  814. Xanything to your .plan that you could ever want. Check it out by fingering
  815. X    franklin@ug.cs.dal.ca
  816. X
  817. X   The change to this package that merits a repost is that it will no longer
  818. Xhang your machine when a mirror host (NFS mounted volume) is fingered. Before,
  819. Xthe .plan was a named pipe which pointed to a background process. However,
  820. Xthis background process did not exist on other machiens that had the same
  821. Xfile system, so it would just hang the finger daemon (bad). So, to get around 
  822. Xthis, the named pipe is placed in the /tmp disk, and a symbolic link to 
  823. Xthe .plan file is made (credits go to Fumiaki Kamiya). Then, people will
  824. Xsimply get a "No Plan" message when they finger other hosts that do not have
  825. Xthe resident background process.
  826. X
  827. X   People should also note that this is incredibly cpu-friendly. It gets the
  828. Xhost-name of the machine that is fingering you through a simple step involving
  829. Xnetstat (but only taking a head-20 of the output). 
  830. X
  831. X   It shouldalso be noted that this will NOT run on ULTRIX, disabled finger 
  832. Xdaemons, or, of course, VMS. I would not recommend that any new users
  833. Xwork with this, because it can definitely peeve your system administrator,
  834. Xand because you will have to play with the code to get it working. To any
  835. Xmoderate to advanced UNIX user, it should be quite easy - just take a bit
  836. Xof tweaking. I haven't been able to figure out an easy way to make the code
  837. Xuniversal, because there are so many places where you have to change pathnames,
  838. Xusernames, etc. But, you should be able to get it running flawlessly in under
  839. Xan hour at the very most.
  840. X
  841. X
  842. XHoping you have fun with this, and hoping your New Year's Celebration was
  843. Xas good as mine,
  844. X
  845. X
  846. XSteve Franklin
  847. X
  848. END_OF_FILE
  849.   if test 2371 -ne `wc -c <'planner/planner1.0.header'`; then
  850.     echo shar: \"'planner/planner1.0.header'\" unpacked with wrong size!
  851.   fi
  852.   # end of 'planner/planner1.0.header'
  853. fi
  854. if test ! -d 'planner/scripts' ; then
  855.     echo shar: Creating directory \"'planner/scripts'\"
  856.     mkdir 'planner/scripts'
  857. fi
  858. if test -f 'planner/scripts/delplan' -a "${1}" != "-c" ; then 
  859.   echo shar: Will not clobber existing file \"'planner/scripts/delplan'\"
  860. else
  861.   echo shar: Extracting \"'planner/scripts/delplan'\" \(171 characters\)
  862.   sed "s/^X//" >'planner/scripts/delplan' <<'END_OF_FILE'
  863. X    if [ -f $HOME/.planpid ] ; then
  864. X        builtin kill -9 -9 `cat $HOME/.planpid` >/dev/null 2>&1 ;
  865. X        trm -f $HOME/.plan $HOME/.planpid >/dev/null 2>&1  ;
  866. X    fi
  867. X
  868. END_OF_FILE
  869.   if test 171 -ne `wc -c <'planner/scripts/delplan'`; then
  870.     echo shar: \"'planner/scripts/delplan'\" unpacked with wrong size!
  871.   fi
  872.   chmod +x 'planner/scripts/delplan'
  873.   # end of 'planner/scripts/delplan'
  874. fi
  875. if test -f 'planner/scripts/killplan' -a "${1}" != "-c" ; then 
  876.   echo shar: Will not clobber existing file \"'planner/scripts/killplan'\"
  877. else
  878.   echo shar: Extracting \"'planner/scripts/killplan'\" \(618 characters\)
  879.   sed "s/^X//" >'planner/scripts/killplan' <<'END_OF_FILE'
  880. X#!/bin/sh
  881. X
  882. Xat now + 10 minute /users/students/franklin/bin/killplan 2>/dev/null >/dev/null 2>&1
  883. X
  884. Xif [ ! -f /tmp/franklinsplan_file ]
  885. Xthen /users/students/franklin/bin/renewplan
  886. Xelse echo "planfile is there" 2>/dev/null >/dev/null
  887. Xfi
  888. X
  889. Xzz=`ps guxw | grep planner | grep franklin | grep -v "grep" |awk '{printf"%s\n",$2}'`
  890. X
  891. Xif [ ! -z "$zz" ]
  892. X    then echo "process is there" 2>/dev/null >/dev/null
  893. X    zzz=`cat $HOME/.planpid`
  894. X        if [ "$zz" -eq "$zzz" ]
  895. X         echo $zz >> $HOME/.file
  896. X            then echo "hi" 2>/dev/null >/dev/null
  897. X            else /users/students/franklin/bin/renewplan
  898. X        fi
  899. X    else /users/students/franklin/bin/renewplan
  900. Xfi
  901. END_OF_FILE
  902.   if test 618 -ne `wc -c <'planner/scripts/killplan'`; then
  903.     echo shar: \"'planner/scripts/killplan'\" unpacked with wrong size!
  904.   fi
  905.   chmod +x 'planner/scripts/killplan'
  906.   # end of 'planner/scripts/killplan'
  907. fi
  908. if test -f 'planner/scripts/lf' -a "${1}" != "-c" ; then 
  909.   echo shar: Will not clobber existing file \"'planner/scripts/lf'\"
  910. else
  911.   echo shar: Extracting \"'planner/scripts/lf'\" \(234 characters\)
  912.   sed "s/^X//" >'planner/scripts/lf' <<'END_OF_FILE'
  913. X#!/bin/sh
  914. Xtimeit=`/usr/5bin/ls -l /users/students/franklin/.dots/.fingerees | cut -c42-54`
  915. Xuser=`tail -2 /users/students/franklin/.dots/.fingerees | head -1 | cut -c1-8 | tr "," " "`
  916. Xecho "you were last fingered at:" $timeit by $user
  917. END_OF_FILE
  918.   if test 234 -ne `wc -c <'planner/scripts/lf'`; then
  919.     echo shar: \"'planner/scripts/lf'\" unpacked with wrong size!
  920.   fi
  921.   chmod +x 'planner/scripts/lf'
  922.   # end of 'planner/scripts/lf'
  923. fi
  924. if test -f 'planner/scripts/renewplan' -a "${1}" != "-c" ; then 
  925.   echo shar: Will not clobber existing file \"'planner/scripts/renewplan'\"
  926. else
  927.   echo shar: Extracting \"'planner/scripts/renewplan'\" \(560 characters\)
  928.   sed "s/^X//" >'planner/scripts/renewplan' <<'END_OF_FILE'
  929. X#!/bin/sh
  930. X#if [ "$HOST" = "ug" ]
  931. X#then
  932. X#at now + 1 hour /users/students/franklin/bin/renewplan > /dev/null 2>&1
  933. X    if [ -f $HOME/.planpid ] ; then
  934. X        kill -9 `cat $HOME/.planpid` >/dev/null 2>&1 ;
  935. X        rm -f $HOME/.plan $HOME/.planpid /tmp/.planlink >/dev/null 2>&1 ;
  936. X    fi
  937. X    if [ ! -f $HOME/.fingerees ] ; then
  938. X        echo " " >$HOME/.fingerees  ;
  939. X    fi;
  940. X    $HOME/bin/planner/plan -d -f /tmp/.planlink $HOME/bin/planner/planner & sleep 2;
  941. X    ln -s /tmp/.planlink $HOME/.plan
  942. X    chmod a+r /tmp/.planlink 
  943. X    touch /tmp/franklinsplan_file
  944. X#fi
  945. END_OF_FILE
  946.   if test 560 -ne `wc -c <'planner/scripts/renewplan'`; then
  947.     echo shar: \"'planner/scripts/renewplan'\" unpacked with wrong size!
  948.   fi
  949.   chmod +x 'planner/scripts/renewplan'
  950.   # end of 'planner/scripts/renewplan'
  951. fi
  952. if test -f 'planner/scripts/rf' -a "${1}" != "-c" ; then 
  953.   echo shar: Will not clobber existing file \"'planner/scripts/rf'\"
  954. else
  955.   echo shar: Extracting \"'planner/scripts/rf'\" \(61 characters\)
  956.   sed "s/^X//" >'planner/scripts/rf' <<'END_OF_FILE'
  957. X#!/bin/sh
  958. Xtail -$1 /users/students/franklin/.dots/.fingerees
  959. END_OF_FILE
  960.   if test 61 -ne `wc -c <'planner/scripts/rf'`; then
  961.     echo shar: \"'planner/scripts/rf'\" unpacked with wrong size!
  962.   fi
  963.   chmod +x 'planner/scripts/rf'
  964.   # end of 'planner/scripts/rf'
  965. fi
  966. echo shar: End of archive 1 \(of 1\).
  967. cp /dev/null ark1isdone
  968. MISSING=""
  969. for I in 1 ; do
  970.     if test ! -f ark${I}isdone ; then
  971.     MISSING="${MISSING} ${I}"
  972.     fi
  973. done
  974. if test "${MISSING}" = "" ; then
  975.     echo You have the archive.
  976.     rm -f ark[1-9]isdone
  977. else
  978.     echo You still must unpack the following archives:
  979.     echo "        " ${MISSING}
  980. fi
  981. exit 0
  982. exit 0 # Just in case...
  983.