home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / alt / gopher / 1123 < prev    next >
Encoding:
Text File  |  1992-07-29  |  20.9 KB  |  754 lines

  1. Newsgroups: alt.gopher
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!schemers
  3. From: schemers@leland.Stanford.EDU (Roland Schemers)
  4. Subject: go4gw daemon (Was: Re: Wish List Re:  gopher<->NNTP et al.)
  5. Message-ID: <1992Jul30.074045.15852@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: Distributed Computing Group, Stanford University
  8. References: <1992Jul25.002513.22566@leland.Stanford.EDU> <Bs687G.8Cp@knot.ccs.queensu.ca> <1992Jul30.002659.17260@leland.Stanford.EDU>
  9. Date: Thu, 30 Jul 92 07:40:45 GMT
  10. Lines: 742
  11.  
  12. go4gw  (gopher gateway)
  13. -------------------------
  14. Ok, here it is! A master perl gopher gateway daemon, and some sample
  15. gateways. Using this gateway, you only need to add one program to
  16. /etc/inetd.conf, and it can handle requests for many different
  17. perl gateways.
  18.  
  19. There is a go4gw.conf file which configures which gateways can be run.
  20. Instead of forking off a process, or including all the gateways
  21. in one huge perl script, the gateways can be written independent
  22. of each other, and are dynamically loaded at the time they are invoked.
  23. Also, common routines have been placed in go4gw which all the gateways
  24. can use.
  25.  
  26. I'm including the shar file here for people without access to boombox.
  27. I'll also down load it to boombox as go4gw.shar.
  28.  
  29. I've included re-written webster/whois/nntp scripts. The whois script
  30. is Stanford specific, and if Paul chooses to use go4gw then he can
  31. modify his general purpose whois gateway to follow go4gw conventions.
  32. The new gateways are called: g2whois g2nntp g2webster. You'll notice
  33. they are much smaller (since they use some common routines in go4gw)
  34. and even easier to understand ;-)
  35.  
  36. enjoy,
  37.  
  38. Roland
  39.  
  40. #! /bin/sh
  41. # This is a shell archive.  Remove anything before this line, then unpack
  42. # it by saving it into a file and typing "sh file".  To overwrite existing
  43. # files, type "sh file -c".  You can also feed this as standard input via
  44. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  45. # will see the following message at the end:
  46. #        "End of shell archive."
  47. # Contents:  README go4gw go4gw.conf g2nntp g2nntp_groups g2whois
  48. #   g2webster
  49. # Wrapped by schemers@Slapshot.Stanford.EDU on Thu Jul 30 00:36:18 1992
  50. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  51. if test -f 'README' -a "${1}" != "-c" ; then 
  52.   echo shar: Will not clobber existing file \"'README'\"
  53. else
  54. echo shar: Extracting \"'README'\" \(4449 characters\)
  55. sed "s/^X//" >'README' <<'END_OF_FILE'
  56. X
  57. Xgo4gw is a daemon which can handle many different gopher gateways
  58. Xwritten in perl. It should be started from inetd.
  59. X
  60. XYou need to put the following line in /etc/services:
  61. X
  62. Xgo4gw         4320/tcp
  63. X
  64. XAnd the following line in /etc/inetd.conf (depending on your system type):
  65. X
  66. Xgo4gw  stream  tcp     nowait  /usr/local/etc/go4gw  go4gw
  67. X
  68. XThe go4gw script has a few variables you might want to change:
  69. X
  70. X$Gconf_file = "/usr/local/etc/go4gw.conf"; # configuration file
  71. X$Gport=4320;                               # port THIS daemon is running on
  72. X$Ghost="Slapshot.Stanford.EDU";            # host THIS daemon is running on
  73. X
  74. XYou need to set Gport to the same port as in /etc/services, and Ghost to
  75. Xyour fully qualified host name.
  76. X
  77. XWhy aren't these two auto-magically figured out?
  78. XMainly for speed, but also because some `hostname` commands don't
  79. Xhave the domain, some do, etc. Its easier just to define them here.
  80. XSince all the other gateways are run in the context of this perl script,
  81. Xthe gateways don't need any of this stuff in them.
  82. X
  83. XGconf_file should be set to the location of your go4gw.conf file. The
  84. Xformat of this file is:
  85. X
  86. X#
  87. X# format
  88. X# gateway : user : module : gopher title
  89. X#
  90. Xwhois:-2:/usr/local/etc/g2whois:Whois:
  91. Xnntp:-2:/usr/local/etc/g2nntp:USENET News:
  92. Xwebster:-2:/usr/local/etc/g2webster:Webster:
  93. X#
  94. X
  95. XWhere gateway is the name of the gateway, user is either a numeric uid
  96. Xor name,  module is the name of the perl script that go4gw will dynamically 
  97. Xload, and title is the title that will show up in the gopher menu if go4gw 
  98. Xis sent the string "". If the gateway doesn't take an empty string, the title
  99. Xshould be "" and it won't show up in the menu. By writing all your gateways so
  100. Xthey take a "" command, you can point a link at the go4gw daemon with
  101. Xpath set to "" and get a menu of all your gateways. The menu order will
  102. Xbe the same order as the go4gw.conf file.
  103. X
  104. XWriting go4gw gateways
  105. X-----------------------
  106. Xgo4gw gateways need to a follow a few simple conventions:
  107. X
  108. XYou need to have a routine called "${gateway}_main", where gateway
  109. Xis the name of your gateway. For example, if your gateway is called 
  110. Xwhois, then you need:
  111. X
  112. Xwhois_main {
  113. X  local($_) = @_;
  114. X  ...
  115. X}
  116. X
  117. XIn your module (/usr/local/etc/g2whois for example).
  118. X
  119. XYour *_main will be passed the string sent to go4gw WITHOUT your gateway 
  120. Xprefix. For example, if someone sends the following string to go4gw:
  121. X
  122. Xnntp ls su.jobs
  123. X
  124. XThen go4gw will call &nntp_main("ls su.jobs"),  after loading g2nntp.
  125. X
  126. XYou should define any variables that users might have to change at the
  127. Xfront of your script, and prefix them with your gateway name. 
  128. X
  129. XWhen your gateway has to return selector string, hostname, and port, it
  130. Xshould use the following variables:
  131. X
  132. X$Ggw    -> name of this gateway
  133. X$Gport  -> port this gateway is running on
  134. X$Ghost  -> host this gateway is running on
  135. X
  136. XFor example, nntp might do the following:
  137. X
  138. X&Greply("0$Subject\t$Ggw article $group $article\t$Ghost\t$Gport");
  139. X
  140. XSo when the user selects this they will send:
  141. X
  142. Xnntp article su.jobs 104
  143. X
  144. XBack to the go4gw daemon, which will figure out that "article su.jobs 104"
  145. Xneeds to get passed to g2nntp.
  146. X
  147. XThe following variables and routines are defined in go4gw, and can be used 
  148. Xby gateways:
  149. X
  150. X$GnotServer    You can define this in perl scripts that want to include
  151. X               the go4gw script without running the server. See the
  152. X               g2nntp_groups script.
  153. X
  154. X$Ggw           Can be used by gateway routines to determine their gateway     
  155. X               name.
  156. X
  157. X$Gport         Can be used by gateway routines to determine which port go4gw
  158. X               is running on.
  159. X
  160. X$Ghost         Can be used by gateway routines to determine which host go4gw
  161. X               is running on.
  162. X
  163. XGSERVER        File handle which is opened when GopenServer is called.
  164. X
  165. X&Greply(reply) Sends string back to gopher client with \r\n on the end.
  166. X
  167. X&Gabort(mess)  Sends error message back to gopher client with 
  168. X               "3mess\r\n.\r\n" on end.
  169. X              
  170. X&GopenServer(server,port)
  171. X               Opens TCP port at server or calls Gabort.
  172. X
  173. X&GcloseServer  Closes server.
  174. X
  175. X$Gdebug        define this to turn on debugging in &Gsend and &Grecv.
  176. X
  177. X&Gsend(cmd)    Sends "cmd\r\n" to GSERVER.
  178. X
  179. X$_ = &Grecv;   Gets response from GSERVER and strips \r and \n.
  180. X
  181. X&Gsorry        Sends message about data that cannot be delivered due to
  182. X               restrictions.
  183. X
  184. XOther "standard" routines and variables may be added. They will start
  185. Xwith a 'G'.
  186. X
  187. XRolandEND_OF_FILE
  188. if test 4449 -ne `wc -c <'README'`; then
  189.     echo shar: \"'README'\" unpacked with wrong size!
  190. fi
  191. # end of 'README'
  192. fi
  193. if test -f 'go4gw' -a "${1}" != "-c" ; then 
  194.   echo shar: Will not clobber existing file \"'go4gw'\"
  195. else
  196. echo shar: Extracting \"'go4gw'\" \(2497 characters\)
  197. sed "s/^X//" >'go4gw' <<'END_OF_FILE'
  198. X#!/usr/local/bin/perl
  199. X#----------------------------------------------------------------------
  200. X# variables to change
  201. X
  202. X$Gconf_file = "/usr/local/etc/go4gw.conf"; # configuration file
  203. X$Gport=4320;                               # port THIS daemon is running on
  204. X$Ghost="Slapshot.Stanford.EDU";            # host THIS daemon is running on
  205. X
  206. X#----------------------------------------------------------------------
  207. X
  208. X&go4gw_main if (!defined($GnotServer));
  209. X
  210. Xsub go4gw_main {
  211. X
  212. X# get command
  213. X$_ = <STDIN>; s/\r//; s/\n//;
  214. X
  215. X($gw,$args) = /^(\w+)\s*(.*)$/ if (!/^$/);
  216. X
  217. Xopen(CONF,$Gconf_file) || &Gabort("$Gconf_file: $!");
  218. Xwhile(<CONF>) { 
  219. X     chop;
  220. X     next if /^#/ || /^$/;
  221. X     ($gateway,$user,$module,$title) = split(/:/);
  222. X     if ($gw eq '') { &Greply("1$title\t$gateway\t$Ghost\t$Gport"); }
  223. X     elsif ($gw eq $gateway) { &launch_gateway($user,$gateway,$module,$args); }
  224. X}
  225. X
  226. Xif ($gw eq '') { &Greply("."); exit; }
  227. Xelse { &Gabort("3No such gateway: $gw"); }
  228. X
  229. X}
  230. Xsub launch_gateway {
  231. X   local($user,$gateway,$module,$args) = @_;
  232. X
  233. X   if ($user =~ /^\-?\d+$/) { $Guid = $user; }
  234. X   elsif ($user eq '') { $Guid = -2; }
  235. X   else {           
  236. X       ($n,$pw,$Guid) = getpwnam($user);
  237. X       if ($Guid eq '') { $Guid = "-2"; }
  238. X   }
  239. X
  240. X  ($<,$>) = ($Guid,$Guid) unless $>;
  241. X   &Gabort("Can't load gateway: $module") if (! -e $module);
  242. X   require "$module";
  243. X   $main = "${gateway}_main";
  244. X   $Ggw = $gateway;
  245. X   &$main($args);
  246. X   &Greply(".");  # shouldn't really get here, but what the hack!
  247. X   exit;
  248. X}
  249. X
  250. X#
  251. X# standard routines
  252. X#
  253. X
  254. Xsub Greply { print "$_[0]\r\n"; }
  255. X
  256. Xsub Gabort { print "3$_[0]\r\n.\r\n"; exit; }
  257. X
  258. Xsub GopenServer {
  259. X
  260. X local($server,$port) = @_;
  261. X $sockaddr = 'S n a4 x8';
  262. X (($name, $aliases, $type, $len, $saddr) = gethostbyname($server))
  263. X        || &Gabort("3Can't get address of: $server");
  264. X $sin = pack($sockaddr, 2, $port, $saddr);
  265. X socket(GSERVER, 2, 1, 0) || &Gabort("Can't create socket: $!");
  266. X connect(GSERVER, $sin)   || &Gabort("Can't connect to server: $!");
  267. X select(GSERVER); $| = 1; select(STDOUT); $| = 1;
  268. X}
  269. X
  270. Xsub GcloseServer {
  271. X  close(GSERVER);
  272. X}
  273. X
  274. Xsub Gsend { 
  275. X     print "send -> |$_[0]|\n" if (defined($Gdebug));
  276. X     print GSERVER "$_[0]\r\n"; 
  277. X}
  278. X
  279. Xsub Grecv { 
  280. X   local ($_); 
  281. X   $_= <GSERVER>; 
  282. X   s/\n$//;
  283. X   s/\r$//;
  284. X   print "recv -> |$_|\n" if (defined($Gdebug));
  285. X   return $_; 
  286. X}
  287. X
  288. Xsub Gsorry {
  289. X
  290. Xprint<<EOF;
  291. X
  292. XSorry! You have selected information that cannot be delivered off
  293. Xof campus due to restrictions.
  294. X
  295. X   -- The Mole Hole Guardian
  296. X
  297. XEOF
  298. X
  299. X&Greply(".");
  300. Xexit;
  301. X
  302. X}
  303. X
  304. X1;  # for require
  305. END_OF_FILE
  306. if test 2497 -ne `wc -c <'go4gw'`; then
  307.     echo shar: \"'go4gw'\" unpacked with wrong size!
  308. fi
  309. chmod +x 'go4gw'
  310. # end of 'go4gw'
  311. fi
  312. if test -f 'go4gw.conf' -a "${1}" != "-c" ; then 
  313.   echo shar: Will not clobber existing file \"'go4gw.conf'\"
  314. else
  315. echo shar: Extracting \"'go4gw.conf'\" \(193 characters\)
  316. sed "s/^X//" >'go4gw.conf' <<'END_OF_FILE'
  317. X#
  318. X# format
  319. X# gateway : username (or uid):module : gopher title
  320. X#
  321. Xwhois:-2:/usr/local/etc/g2whois:Whois:
  322. Xnntp:-2:/usr/local/etc/g2nntp:USENET News:
  323. Xwebster:-2:/usr/local/etc/g2webster:Webster:
  324. X#END_OF_FILE
  325. if test 193 -ne `wc -c <'go4gw.conf'`; then
  326.     echo shar: \"'go4gw.conf'\" unpacked with wrong size!
  327. fi
  328. chmod +x 'go4gw.conf'
  329. # end of 'go4gw.conf'
  330. fi
  331. if test -f 'g2nntp' -a "${1}" != "-c" ; then 
  332.   echo shar: Will not clobber existing file \"'g2nntp'\"
  333. else
  334. echo shar: Extracting \"'g2nntp'\" \(4088 characters\)
  335. sed "s/^X//" >'g2nntp' <<'END_OF_FILE'
  336. X#!/usr/local/bin/perl
  337. X
  338. X#----------------------------------------------------------------------
  339. X# variables you might have to change:
  340. X
  341. X$nntp_server = "leland.stanford.edu";
  342. X$nntp_port   = 119;
  343. X$nntp_groups = "/usr/local/etc/newsgroups.gopher"; # could be active file
  344. X$nntp_reverse = 0;  # to list articles in reverse order
  345. X
  346. X#----------------------------------------------------------------------
  347. X
  348. X@nntp_acl=(
  349. X#     ipaddress  group    access + = allow, - = deny    
  350. X     '^36\.      .*       +',
  351. X     '.*         ^clari   -',
  352. X     '.*         .*       +'
  353. X  );
  354. X# end of variables
  355. X
  356. X# Commands this server responds to:
  357. X# 
  358. X# ""                         -> list top level groups
  359. X# ls $group                  -> list group's articles and sub-groups
  360. X# article $group $number     -> get 1 article
  361. X# sorry                      -> send sorry message
  362. X#
  363. X
  364. Xsub nntp_main {
  365. X  local($_) = @_;
  366. X
  367. X  &do_ls("") if /^$/;
  368. X  &do_ls($1) if /^ls\s+(.*)/i;
  369. X  &do_article($1,$2) if /^article\s+(\S+)\s+(\d+)/i;
  370. X  &Gsorry if /^sorry$/;
  371. X  &Gabort("Unknown command!");
  372. X  exit;
  373. X}
  374. X
  375. Xsub do_article {
  376. X  local($group,$number) = @_;
  377. X
  378. X  if (&check_access($group) eq '-')  { &Gsorry; }
  379. X  &open_nntp;
  380. X
  381. X  &Gsend("GROUP $group");
  382. X  $_ = &Grecv;
  383. X  &Gabort($_) if !/^211/;
  384. X
  385. X  &Gsend("ARTICLE $number");
  386. X  $_ = &Grecv;
  387. X  &Gabort($_) if !/^220/;
  388. X  while(<GSERVER>) {
  389. X    print;
  390. X    last if /^\.\r\n$/;
  391. X  }
  392. X
  393. X  &close_nntp;
  394. X  exit;
  395. X}
  396. X
  397. Xsub list_group {
  398. X  local($group) = @_;
  399. X
  400. X  &Gsend("GROUP $group");
  401. X  $_ = &Grecv;
  402. X  &Gabort($_) if !/^211/;
  403. X
  404. X  ($n,$f,$l) = /211\s+(\d+)\s+(\d+)\s+(\d+)/;
  405. X
  406. X  &Gsend("XHDR Subject $f-$l");
  407. X  $_ = &Grecv;
  408. X  &Gabort($_) if !/^221/;
  409. X  while(<GSERVER>) {
  410. X    chop; chop;
  411. X    last if /^\.$/;
  412. X    ($article,$subject) = /^(\d+)\s+(.*)/;
  413. X    $subject =~ s/\t/ /g; # just in case!
  414. X    if ($nntp_reverse) {
  415. X       push(@reply,"0$subject\t$Ggw article $group $article\t$Ghost\t$Gport");
  416. X    } else {
  417. X       &Greply("0$subject\t$Ggw article $group $article\t$Ghost\t$Gport");
  418. X    }
  419. X  }
  420. X
  421. X  if ($nntp_reverse) {
  422. X    for ($i=$#reply; $i!= -1; $i--) { &Greply($reply[$i]); } 
  423. X  }
  424. X
  425. X  &Greply(".");
  426. X  &close_nntp;
  427. X  exit;
  428. X}
  429. X
  430. Xsub do_ls {
  431. X  local($prefix) = @_;
  432. X
  433. X  if (&check_access($prefix) eq '-') {
  434. X      &Greply("0Sorry! No access off of campus!\t$Ggw sorry\t$Ghost\t$Gport");
  435. X      &Greply("."); 
  436. X      exit; 
  437. X  }
  438. X
  439. X  &open_nntp;
  440. X  &get_groups;
  441. X
  442. X  foreach ( sort @groups) {
  443. X    if ($_ eq $prefix) { $do_list_group = $_; }
  444. X    elsif (/^$prefix\.([^.]*)\.?/) {
  445. X      $leaf=$1;
  446. X      $save{"$prefix.$leaf"} = "1$leaf\t$Ggw ls $prefix.$leaf\t$Ghost\t$Gport";
  447. X    }
  448. X    elsif ($prefix eq '' && /([^.]*)/) {
  449. X         $save{"$1"} = "1$1\t$Ggw ls $1\t$Ghost\t$Gport";
  450. X    }
  451. X  }
  452. X
  453. X  foreach ( sort keys %save) { &Greply($save{$_}); }
  454. X  &list_group($do_list_group) if ($do_list_group);
  455. X
  456. X  &Greply(".");
  457. X  &close_nntp;
  458. X  exit;
  459. X}
  460. X
  461. Xsub open_nntp {
  462. X  local($_);
  463. X  &GopenServer($nntp_server,$nntp_port);
  464. X  $_ = &Grecv;
  465. X  &Gabort($_) if !/^2/;
  466. X}
  467. X
  468. Xsub close_nntp {
  469. X  &Gsend("QUIT");
  470. X  close(GSERVER);
  471. X}
  472. X
  473. Xsub get_groups {
  474. X if (open(GROUPS,$nntp_groups)) {
  475. X      while(<GROUPS>) {
  476. X          chop;
  477. X          ($grp) = /^(\S+)/;
  478. X          push(@groups,$grp);
  479. X      }
  480. X      close(GROUPS);
  481. X } else {                  # can't open file, get list from server!
  482. X  &load_groups;
  483. X }
  484. X}
  485. X
  486. Xsub load_groups {
  487. X
  488. X  &open_nntp;
  489. X  &Gsend("LIST");
  490. X  $_ = &Grecv;
  491. X  &Gabort($_) if !/^215/;
  492. X
  493. X  while(<GSERVER>) {
  494. X    chop; chop;
  495. X    last if /^\.$/;
  496. X    s/^(\S+).*/$1/;
  497. X    push(@groups,$_);
  498. X  }
  499. X
  500. X}
  501. X
  502. Xsub create_groups { 
  503. X  &load_groups;
  504. X  open(GROUPS,">$nntp_groups") || die "$nntp_groups: $!";
  505. X  foreach (@groups) { print GROUPS "$_\n"; }
  506. X  close GROUPS;
  507. X  &close_nntp;
  508. X  exit;
  509. X}
  510. X
  511. Xsub check_access {
  512. X   local($group)=@_;
  513. X
  514. X   return 1 if (-t STDIN);
  515. X   $sockaddr = 'S n a4 x8';
  516. X   $mysockaddr = getpeername(STDIN);
  517. X   ($ramily,$rport,$raddr) = unpack($sockaddr,$mysockaddr);
  518. X   ($a,$b,$c,$d) = unpack('C4',$raddr);
  519. X   $ipaddress = "$a.$b.$c.$d";
  520. X
  521. X   foreach (@nntp_acl) {
  522. X      ($ipacl,$groupacl,$access)=split;
  523. X      return $access if  ($ipaddress =~ /$ipacl/) && ($group =~ /$groupacl/);
  524. X   }
  525. X   return '-'; #default is to restrict access
  526. X}
  527. X
  528. X1; # for require
  529. END_OF_FILE
  530. if test 4088 -ne `wc -c <'g2nntp'`; then
  531.     echo shar: \"'g2nntp'\" unpacked with wrong size!
  532. fi
  533. chmod +x 'g2nntp'
  534. # end of 'g2nntp'
  535. fi
  536. if test -f 'g2nntp_groups' -a "${1}" != "-c" ; then 
  537.   echo shar: Will not clobber existing file \"'g2nntp_groups'\"
  538. else
  539. echo shar: Extracting \"'g2nntp_groups'\" \(428 characters\)
  540. sed "s/^X//" >'g2nntp_groups' <<'END_OF_FILE'
  541. X#!/usr/local/bin/perl
  542. X
  543. X#----------------------------------------------------------------------
  544. X# variables you might have to change
  545. X
  546. X$g2nntp = "/usr/local/etc/g2nntp";
  547. X$go4gw  = "/usr/local/etc/go4gw";
  548. X
  549. X#----------------------------------------------------------------------
  550. X
  551. X$GnotServer=1;  # so go4gw doesn't think its a server!
  552. X
  553. Xrequire "$go4gw";
  554. Xrequire "$g2nntp";
  555. X
  556. X#create the group file listed in g2nntp.
  557. X
  558. X&create_groups;
  559. END_OF_FILE
  560. if test 428 -ne `wc -c <'g2nntp_groups'`; then
  561.     echo shar: \"'g2nntp_groups'\" unpacked with wrong size!
  562. fi
  563. chmod +x 'g2nntp_groups'
  564. # end of 'g2nntp_groups'
  565. fi
  566. if test -f 'g2whois' -a "${1}" != "-c" ; then 
  567.   echo shar: Will not clobber existing file \"'g2whois'\"
  568. else
  569. echo shar: Extracting \"'g2whois'\" \(1424 characters\)
  570. sed "s/^X//" >'g2whois' <<'END_OF_FILE'
  571. X#!/usr/local/bin/perl
  572. X
  573. X#----------------------------------------------------------------------
  574. X# variables you should change:
  575. X
  576. X$whois_server = "stanford.edu";   
  577. X$whois_port   = 43;
  578. X
  579. X#----------------------------------------------------------------------
  580. X
  581. Xsub whois_main {
  582. X local($_) = @_;
  583. X
  584. X if (/^$/) {
  585. X    &Greply("0Whois Help\thelp\t$whois_server\t$whois_port");
  586. X    &Greply("7Query Whois\t$Ggw\t$Ghost\t$Gport");
  587. X    &Greply(".");
  588. X    exit(0);
  589. X }
  590. X
  591. X $query = $_;
  592. X &GopenServer($whois_server,$whois_port);
  593. X &Gsend($query);
  594. X
  595. X  while(<GSERVER>) {
  596. X        chop; chop;
  597. X        push(@lines,$_);
  598. X  }
  599. X
  600. X  &Greply("0Raw search results\t$query\t$whois_server\t$whois_port");
  601. X
  602. X  if ($lines[$#lines] eq '') {
  603. X        foreach (@lines) {
  604. X           if (/^\s+name:\s+(.*)/) {
  605. X               &Greply("0$1\t$query\t$whois_server\t$whois_port");
  606. X               &Greply(".");
  607. X               exit(0);
  608. X           }
  609. X        }
  610. X    } elsif ($lines[$#lines] eq 'NO MATCH') {
  611. X       &Greply("0No Match Was Found!\thelp\t$gopher_server\t$gopher_port");
  612. X    } elsif ($lines[$#lines] =~ /^\(returned/) {
  613. X       foreach (@lines) {
  614. X           if (/(.*)<(.*)>.*\s+(.*)$/) {
  615. X               $text=$1; $handle=$2; $rest = $3;
  616. X               $text =~ s/\s+$//;
  617. X               $rest =~ s/\s+/ /g;
  618. X               &Greply("0$text ($rest)\t!$handle\t$whois_server\t$whois_port");
  619. X           }
  620. X        }
  621. X    }
  622. X    &Greply(".");
  623. X    exit(0);
  624. X}
  625. X
  626. X
  627. X
  628. X
  629. X1; # for requireEND_OF_FILE
  630. if test 1424 -ne `wc -c <'g2whois'`; then
  631.     echo shar: \"'g2whois'\" unpacked with wrong size!
  632. fi
  633. chmod +x 'g2whois'
  634. # end of 'g2whois'
  635. fi
  636. if test -f 'g2webster' -a "${1}" != "-c" ; then 
  637.   echo shar: Will not clobber existing file \"'g2webster'\"
  638. else
  639. echo shar: Extracting \"'g2webster'\" \(2572 characters\)
  640. sed "s/^X//" >'g2webster' <<'END_OF_FILE'
  641. X#!/usr/local/bin/perl
  642. X
  643. X#----------------------------------------------------------------------
  644. X# variables you can change:
  645. X
  646. X#$webster_server  = "webster.lcs.mit.edu";
  647. X#$webster_port    = 103;
  648. X
  649. X$webster_server = "webster-server.stanford.edu";
  650. X$webster_port   = 765;
  651. X
  652. X@webster_acl=(
  653. X#     ipaddress  access + = allow, - = deny    
  654. X     '^36\.      +',
  655. X     '.*         -'
  656. X  );
  657. X
  658. X#----------------------------------------------------------------------
  659. X
  660. Xsub webster_main {
  661. X local($_ )= @_;
  662. X
  663. X &Gsorry if /^sorry$/;
  664. X
  665. X  if (&check_access() eq '-') {
  666. X      &Greply("0Sorry! No access off of campus!\t$Ggw sorry\t$Ghost\t$Gport");
  667. X      &Greply("."); 
  668. X      exit; 
  669. X  }
  670. X
  671. X if (/^$/) {
  672. X  &Greply("7Lookup word in dictionary\t$Ggw default SPELL\t$Ghost\t$Gport");
  673. X  &Greply("7Lookup word in dictionary (phonetic match)\t$Ggw default PSPELL\t$Ghost\t$Gport");
  674. X  &Greply("7Search text of entire dictionary\t$Ggw dictionary-full SPELL\t$Ghost\t$Gport");
  675. X  &Greply("7Show words that start with\t$Ggw default ENDINGS\t$Ghost\t$Gport");
  676. X  &Greply("7Thesaurus\t$Ggw thesaurus SPELL\t$Ghost\t$Gport");
  677. X  &Greply(".");
  678. X  exit(0);
  679. X }
  680. X
  681. X ($index,$cmd,$query) = /^(\S+)\s+(\S+)\s+(.+)$/;
  682. X
  683. X  &GopenServer($webster_server,$webster_port);
  684. X
  685. X  &Gsend("INDEX $index") if ($index ne 'default');
  686. X
  687. X  if ($cmd eq "PSPELL") {                     # phonetic lookup
  688. X       &Gsend("SPELL $query ?");
  689. X  } else {
  690. X       &Gsend("$cmd $query");
  691. X  }
  692. X
  693. X$_ = &Grecv;
  694. X
  695. X  if (/^SPELLING 0/ || /^WILD 0/) {
  696. X        &Greply(".");
  697. X   } elsif (/^SPELLING 1/) {
  698. X      &Greply("0$query\t$Ggw $index DEFINE $query\t$Ghost\t$Gport"); 
  699. X      &Greply(".");
  700. X   } elsif (/^SPELLING$/ || /^MATCHS$/ || /^WILD/) {
  701. X        $/ = "\200";
  702. X        $buf = <GSERVER>;
  703. X        $buf =~ s/[\r\200]//g;
  704. X        foreach (split(/\n/,$buf)) { /\d+\s+(\S+)/; $words{$1}=""; }
  705. X        foreach (sort keys %words) { 
  706. X               &Greply("0$_\t$Ggw $index DEFINE $_\t$Ghost\t$Gport"); 
  707. X        }
  708. X        &Greply(".");
  709. X   } elsif (/^DEFINITION/) {
  710. X        $/ = "\200";
  711. X        $buf = <GSERVER>;
  712. X        $buf =~ s/[\r\200]//g;
  713. X        print $buf;
  714. X   } else {
  715. X        &Greply(".");
  716. X   }
  717. X  &Gsend("QUIT");
  718. X  &GcloseServer;
  719. X  exit;
  720. X}
  721. X
  722. Xsub check_access {
  723. X
  724. X   return 1 if (-t STDIN);
  725. X   $sockaddr = 'S n a4 x8';
  726. X   $mysockaddr = getpeername(STDIN);
  727. X   ($ramily,$rport,$raddr) = unpack($sockaddr,$mysockaddr);
  728. X   ($a,$b,$c,$d) = unpack('C4',$raddr);
  729. X   $ipaddress = "$a.$b.$c.$d";
  730. X
  731. X   foreach (@webster_acl) {
  732. X      ($ipacl,$access)=split;
  733. X      return $access if  ($ipaddress =~ /$ipacl/);
  734. X   }
  735. X   return '-'; #default is to restrict access
  736. X}
  737. X
  738. X1; # for requireEND_OF_FILE
  739. if test 2572 -ne `wc -c <'g2webster'`; then
  740.     echo shar: \"'g2webster'\" unpacked with wrong size!
  741. fi
  742. chmod +x 'g2webster'
  743. # end of 'g2webster'
  744. fi
  745. echo shar: End of shell archive.
  746. exit 0
  747. -- 
  748. Roland J. Schemers III              |            Networking Systems
  749. Systems Programmer                  |            168 Pine Hall   (415)-723-6740
  750. Distributed Computing Group         |            Stanford, CA 94305-4122
  751. Stanford University                 |            schemers@Slapshot.Stanford.EDU
  752.