LynxBooster.ksc

#!/usr/local/bin/kermit +

# lynxbooster.ksc
#
# script for external programs for Lynx web browser
# ( by D. E. Legan, 23 Jan. 2001 )
#
# mailto:leganii@surfree.com
#
# http://www.lafn.org/~aw585/index.html
#
# http://www.lafn.org/~aw585/dlegan.html
#
# Documented at the Kermit Center, Columbia University:
#
# http://www.columbia.edu/kermit/case20.html

# Requires: Lynx, C-Kermit 7.1, 'FTP' link to kermit
# and whatever suplemental
# http user agents/browsers desired.

# According to the Lynx documentation, it can handle
# an URL of form:

# telnet://user:password@host:port

# and also can handle rlogin, tn3270, tn5250 protocols similarly

# Reading over the Lynx documentation for ftp URLs
# it can handle a form of:

# ftp://user@host:port/path;type=[D,I,orA]
# (D,I,A = directory, binary or ASCII)

# where user might be broken down to actually be
# a user:password. if this followed average ftp
# conventions, then it might actually be:

# ftp://username:user@homehost@remotehost:port/path;type=[D,I,orA]

# Personally, I've never seen the ';type=...' part of the URL,
# so for the time being, I will ignore it, but will allot for
# some of the other complications.
# For using C-Kermit 7.1 ftp personality,
# a soft link named 'FTP' has been made to the executable,
# to distinguish it from the plain vanilla conventional
# ftp executable.

# USAGE:
# In the lynx configuration file (typicly, lynx.cfg
# or lynx-ssl.cfg) there should be some lines
# like the following (not commented with '#' in column 1
# though :-) ) to activate this program:
#
#KEYMAP:,:EXTERN # run EXTERNAL with URL. added by d.e.l.
#...........
#USE_EXTERNALS:TRUE
#...........
#EXTERNAL:ftp:lynxbooster.ksc %s:TRUE
#EXTERNAL:http:lynxbooster.ksc %s:TRUE
#EXTERNAL:telnet:lynxbooster.ksc %s:TRUE
#EXTERNAL:rlogin:lynxbooster.ksc %s:TRUE
#EXTERNAL:tn3270:lynxbooster.ksc %s:TRUE
#EXTERNAL:tn5250:lynxbooster.ksc %s:TRUE
#EXTERNAL:iksd:lynxbooster.ksc %s:TRUE

# If not already defined, the KEYMAP value (in this case ',')
# should be chosen so as not to conflict with other Lynx control
# keys.
# (You can have more than one character KEYMAPped to EXTERN.)
# When over a link to one of these protocols, hit this key
# instead of return to activate this script for the link.
# The EXTERNAL statements define the protocols that external
# commands will be available for (in this case,
# ftp, http, telnet, rlogin, tn3270 tn5250 and iksd), and the
# program to be run for them (in this case this script.)

# Note that if any external programs are called for
# 'telnetish' protocols via pty/pipe/exec,
# they may require adjustments of this script.
# I don't have any of the IBM protocols on the system this
# script has been developed on.

# Variables:
# \%a - address of URL
# \%b - user input selection flag
# \%d - raw URL
# \%f - file name stripped of directory
# \%i - path/file
# \%p - port number
# \%q - path
# \%r - protocol this script is being used for
# \%t - index used in parsing the URL as specified above
# \%u - user ID
# \%w - password

echo {LYNX_VERSION = \$(LYNX_VERSION)}
# According to Lynx man pages, this variable is always set by Lynx

set case off

# First let's pick apart the URL for possibly usefull parts

.\%d := \%1
.\%a := \%d
.\%r := \%a

# strip the protocol from the URL:
.\%a := \Flop(\%a,:) ; strip off up to '://'
.\%a := \Fltrim(\%a,/)

# extract the protocol, up to '://':
.\%r := \Freplace(\%r,://\%a,)

# First, we set up any URL protocol specific items:
# (this section is largely an artifact of development process
# but left in for future complications.)
switch \%r {
:telnet,
:rlogin,
:ftp,
:file,
:http,
:iksd,
# this version, not much really needed here yet. :-)
.\%c := kermit
break

# I haven't actually seen any mention of the
# next five URL types yet, but what the heck.....
:ssh,
:telnet-ssl,
:s5telnet,
:ktelnet,
:srp-telnet,

# Back to reality:
:tn3270,
:tn5250,
:default,
# included for future generalization of this script
echo \%r protocol currently not supported.
ask \%z Press enter to continue
quit
.\%c = {pty \%r }
.\%s := { }
break
}
# Finished handling URL protocol specific stuff

# Check to see if a directory/filename is on the end of the URL
# indicates that this is a particular file to be downloaded from an IKSD:

.\%i := /\Flop(\%a,/) # i holds the path/filename
.\%a := \Freplace(\%a,\%i) # a holds usrid:password@host.domain:port

# extract filename:
.\%f := \Freplace(\%i,\Fstripx(\%i,/),) # f has the directory removed
.\%f := \Fltrim(\%f,/) # now f has any '/' trimmed off
.\%q := \Freplace(\%i,\%f,) # q holds just the path name

# Now handle 'User:password' part of URL:

# find the '@'s location in the URL:
.\%t := \Findex(@,\%a)
# Definitly set defaults for user and password:
.\%u := { }
set login userid
.\%w := { }

if > \%t 0 {
# extract and clean up the 'usrid:password':
.\%u := \Fstripx(\%a,@)
# extract and clean up the 'host.domain:port':
.\%a := \Flop(\%a,@)
.\%a := \Flop(\%a,@) # the ftp two '@' case
# is there a password?
.\%t := \Findex(:,\%u)
# Now seperate the user id from the password if present:
if > \%t 0 {
.\%w := \Flop(\%u,:)
.\%u := \Fright(\%u,\%t)
.\%u := \Ftrim(\%u,:)
}
# For kermit:
set ftp autologin on
set ftp user \%u \%w
set login userid \%u
}
# Finished extracting user/password

# Now handle any port part of the URL:
.\%p := { }
# Is there a port specified?
.\%t := \Findex(:,\%a) # 'host.domain:port' are divided at \%t index

# Now, if a port was specified:
if > \%t 0 {
.\%p := \Flop(\%a,:)
.\%a := \Freplace(\%a,\%p,)
if equal \%p kermit .\%p := 1649
.\%a := \Ftrim(\%a,:)
if equal \%r telnet if equal \%p 1649 -
if not equal {\%i} {} {
# this case is really not interactive, but in fact IKSD
# to a specific file
.\%r := IKSD
}
}
# End of handling port number

# Handle HTTP/interactive selections here:

# Make this script do double duty, by putting the following line
# in the printer setup part of the your Lynx configuration file.
# Then you can pass the URL of the currently viewed page
# (not just the currently active link) to other browsers:

# PRINTER:View URL with other browser:exec /path/lynxbooster.ksc ${LYNX_PRINT_URL}:TRUE
# PRINTER:View/edit current page source with other browser:exec /usr/local/bin/lynxbooster.ksc file\://%s :TRUE:10000000

# (hit the 'p' key, and select 'View URL with other browser' to bring
# up this menu.)
# (for the second, hit '\', to first bring up the source listing view,
# then p to get this menu)
# See the Lynx man pages for information on enviromental variable
# LYNX_PRINT_URL.

# if equal \%r http {
switch \%r {

:file,
:http,
# This part should be adjusted for whatever suplemental
# HTTP tools you want to use.

if equal {\%f} {} .\%f := \%a
clear screen
# -- try to keep this screen formating/menu simple and uncluttered
:wwwchoice
echo
echo To connect to \%a\, choose an alternate browser:
echo ( URL: \%d )
echo

# most of these are frame-capable browsers
# (Lynx barely handles frames.):

echo { N Netscape}
echo { E Lynx, edit source locally!}
echo { W w3m}
echo { L Links}
echo { D Debris}

# Warning about Debris: I'm certain it will be great when complete,
# but it is a work in progress. My experience is that
# if you notice this script flashing on the screen and aborting
# before you can do anything, you may of called Debris once too often.
# :-)

# and a few methods of dumping files/directories
# in background:

echo { Y Lynx/dump in background}
echo { R Wget/recurse in background}
echo { X Exit back to Lynx}
# echo { E Etc.........}

# echo { K Let the frog handle it....}
# if they ever add http to automatic file download.
# Could have Lynx with some drasticly different configuration
# file listed in here, maybe special provisions for handling
# cookies.

echo
ask \%b {Alternate browser choice: }
echo \%b

switch \%b {

# :N, exec netscape \%d
:N, exec lynx -image_links -nocolor -tna -resubmit_posts -
"-useragent=Mozilla/4.0 (compatible; MSIE 5.5; Windows 95; U)" \%d
break

:E, exec lynx -image_links -nocolor -tna -resubmit_posts \%d
break

:W, exec w3m -M -F -no-cookie -no-mouse \%d
break

:L, exec links \%d
break

:D, exec debris \%d
break

:Y, run lynx -source \%d > \%f &
# May want to put cookie handling capabilities
# with the above command
# or maybe nohup this to direct the output
# away from the screen
break

:R, run wget -D \%a -P \v(download) -np -brkl5 \%d
break
# -D \%a - restricted to \%a domain
# -P \v(download) - put in download directory
# -np - no parent directories
# -b - go to background
# -r - download recursively
# -k - 'konvert' to relative links
# -l5 - limit to just 5 levels of recursion

:X, break # exit back to Lynx

:default, echo {Invalid choice, try again}, goto wwwchoice
}
quit
break

:default, break

}
# end of HTTP/interactive selection

if not equal {\%p} { } .\%p := :\%p
else .\%p :=

# If a specific directory/file is defined to retreive, hop to
# non-interactive options
# if not equal {\%i} {} forward getafile
# temp (X) : set ftp autologin on
if not equal {\%f} {} forward getafile

# No file is specified
# Assumption is that they expect you to browse
# directory for whatever reason.
if equal \%r ftp {
if not equal {\%w} { } exec FTP -u \%u -P \%w -S -D \%q \%a \%p
if not equal {\%u} { } exec FTP -u \%u -S -D \%q \%a \%p
exec FTP -A -S -D \%q \%a \%p
}

if equal \%r iksd {
if equal {\%w} { } .\%w := \v(userid)@\v(host)
if equal {\%u} { } .\%u := anonymous

# It seems to work best for me if normal initialization
# is carried out before making an IKSD connection
take ~/.kermrc

set network type tcp
set host telnet://\%a\%p
remote login \%u \%w
remote cd \%i
end
}

# Parts from here to ':modechoice' will probably need modification
# if any protocols that actually use pty/pipe external
# programs are used.

# So if a password was given:
if not equal {\%w} { } {
echo { Remember, in the URL}
echo { the fools gave you this password: \%w}
ask \%z Press any key to continue
}

# If a userid was given:
if not equal {\%u} { } {
exec kermit -M \%u \%r://\%a\%p\%i
forward the_end
}

# If no userid was part of the URL:

exec kermit -J \%r://\%a\%p\%i
forward the_end

# Here handle getting a specific file:
:getafile

clear screen
# -- try to keep this screen formating/menu simple and uncluttered
:modechoice
echo
echo To connect to \%a and retreive \%i,
echo using \%r protocol, choose a mode:
echo
echo { F Foreground - 'I like to watch'}
echo { B Background - 'My time is precious'}
echo { X Exit - 'I need to do something else'}
echo
echo d is \%d
echo r is \%r
ask \%b {Job mode choice: }
echo \%b

switch \%b {
:f, if equal \%r ftp {
exec FTP \%d
# Using C-Kermit 7.1 FTP personality
break
}
exec kermit \%d
# Use IKSget if using older version, pre-7.1
# instead of kermit here.
# May want to nohup this to control output
break
:b, if equal \%r ftp {
run FTP \%d & # Again, Using C-Kermit 7.1's FTP personality
# May want to nohup this to control output
# otherwise may need to ^L to refresh screen as
# messages arrive from the background
break
}
run kermit \%d &
# Again, use IKSget if using older version, pre-7.1
# instead of kermit here.
# ditto the above ftp comments
break
:x, break
:default, echo {Invalid choice, try again}, goto modechoice
}

forward the_end

:the_end

echo Exiting lynxbooster.ksc
quit