home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / www / amitrix / awebftp.lha / AWebftp.awebrx next >
Text File  |  1997-01-23  |  17KB  |  435 lines

  1. /* AwebFTP - FTP plug-in for Aweb
  2.  
  3. */ vers="Version 1.3a (AmiTrix 2.1)"
  4. /*
  5.     By Josef Faulkner (panther@gate.net) IRC: Josef
  6.         Modified by AmiTrix Development for inclusion with AWeb-II
  7.           Added config program and file
  8.           Fixed a couple bugs 
  9.  
  10.     Description:
  11.     ¯¯¯¯¯¯¯¯¯¯¯¯
  12.     This plugin will allow you to do inline FTPing of files on the net,
  13.     without the need to call an external FTP program (except FTPMount, which
  14.     is transparent).  It will distinguish between a directory and a file, and
  15.     act accordingly.
  16.  
  17.     Features:
  18.     ¯¯¯¯¯¯¯¯¯
  19.         o Fast reaction, since FTPMount does a lot of cacheing of dirs
  20.         o Asyncronous download (thanks to Aweb), you can continue browsing
  21.           while it downloads, and Aweb will inform you when the transfer
  22.           has completed!
  23.         o Brings up a requestor to ask what you want to save as
  24.     New for 1.1:
  25.         o You can now upload to the directory if you type the name of a file
  26.           in a form at the bottom of the list (or leave blank, and it will
  27.           give you a requester asking for a file)
  28.         o Make directories
  29.         o Delete a file (only one at a time, currently)
  30.     New for 1.2:
  31.         o WBCopy command used to copy files w/ progress meter
  32.           Thanks to Bastian H. Frank for developing this handy program!
  33.     New for 1.3:
  34.         o Much faster:
  35.             o No longer parses list output, uses lformat to create listing
  36.         o AmiFTP is now loadable from the inside!
  37.             o Will detect if amiftp is already loaded, and go to the directory
  38.             o Doesn't disconnect and reconnect if amiftp already has the host open
  39.     New for 1.3a:
  40.         o Plaincopy used by default for Aweb II Distribution.
  41.         o Fixed some minor bugs
  42.  
  43.     Requirements:
  44.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  45.     FTPMount version 8 (or newer) must be installed and running
  46.         available on Aminet:
  47.         FTPMount-1.0.lha  comm/tcp   109K Mounts FTP sites
  48.     Copy command, choose one (set below, must be in your path):
  49.         plaincopy (included in this archive)
  50.         WBCopy (aminet/util/cli/WBCopy.lha) - Does progress meters
  51.         copy (comes with workbench) - has problems with softlinked files
  52.     AmiFTP (from http://www.lysator.liu.se/~lilja/AmiFTP.html)
  53.         To be launched by a button if a separate GUI is preferred!
  54.         (optional)
  55.  
  56.     Installation:
  57.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  58.     1) Put this script in the same directory that the Aweb executable is in.
  59.     2) Set Aweb to the following settings:
  60.       ----------------------------------------------
  61.         Network 3: External Programs
  62.                    ftp:
  63.           Command:  sys:rexxc/rx
  64.         Arguments:  awebftp.awebrx %h %f <--- *** NOTE: %n is not usually 
  65.                                                         needed for FTPMount ***
  66.       ----------------------------------------------
  67.     3) Put plainCopy in your path (ie C:)
  68.     4) Set your preferences for this script below:
  69.  
  70.     Known Bugs:
  71.     ¯¯¯¯¯¯¯¯¯¯¯
  72.     Linked files are sometimes thought to be directories in AmigaDOS, and
  73.     may wind up returning an empty directory listing instead of the actual
  74.     file.
  75.     I've attempted to correct this by checking if the link clicked on has a
  76.     period in the name, if so, it assumes it's a file instead.
  77.     Hopefully this bug is obsolete with the new copy program.  Let me know if
  78.     you find any URL's that this still happens on.
  79.  
  80.     Many people are getting "out of memory" errors.  This should only be
  81.     occuring on old versions of AwebFTP, and usually only when they forget
  82.     to pass the correct arguments in aweb's preferences.
  83. */
  84.  
  85. /****AwebFTP Preferences***********************************************/
  86.  
  87. savedir='RAM:'                /* Default directory to download to */
  88. copycommand='AWeb-II:plugins/AwebFTP/plaincopy'       /* Set to program used to copy (use plaincopy for best compatibility) */
  89. amiftpexe=''                  /* Path and name of your amiftp executable */
  90.  
  91. /* Change by Amitrix to get configuration from file and find the current    */
  92. /* AWeb Window   */
  93.  
  94. options results
  95.  
  96. ports = show('P')
  97. parse var ports dummy 'AWEB.' portnr .
  98. address value 'AWEB.' || portnr
  99.  
  100. 'GET ACTIVEPORT'
  101.  
  102. awebhost = result
  103.  
  104. if Open(config_fp,"AWebFtp.config",r) then
  105.   do
  106.     savedir = readln(config_fp)
  107.     amiftpexe = readln(config_fp)
  108.     call close(config_fp)
  109.    end
  110.  
  111. parse source prog_type result_flag called resolved ext host .
  112.  
  113. last_slash = lastpos('/',called)
  114. last_colon = lastpos(':',called)
  115.  
  116. dir_pos = max(last_slash,last_colon)
  117. if dir_pos > 0 then
  118.   current_dir = left(called,dir_pos)
  119.  else
  120.    current_dir = '' 
  121.  
  122. Address value awebhost
  123.  
  124.  
  125. if Open(config_fp,current_dir||"AWebFTP.config",r) then
  126.   do
  127.     save_dir = readln(config_fp)
  128.     AmiFTPexe = readln(config_fp)
  129.     call close(config_fp)
  130.    end
  131. /* End AmiTrix Changes */
  132.  
  133. /**********************************************************************/
  134.  
  135. if ~show('L','rexxsupport.library') then
  136.   if ~addlib('rexxsupport.library',0,-30,0) then 
  137.     exit 20
  138.  
  139. tmpfile='t:awebftp'time(S)'.html'
  140. address command 'delete t:awebftp#? >NIL:'
  141. parse arg cmds
  142.  
  143. /* Added by AmiTrix to Check for screen not being passed and FTP: not */
  144. /* being mounted                                                      */
  145.  
  146. parse var cmds '"'server'"' '"'file'"' screen
  147. if screen = '' then
  148.   do
  149.     'GET SCREEN'
  150.     screen = result
  151.    end
  152.  
  153. address command 'assign FTP: >NIL: exists'
  154.  
  155. if rc > 0 then
  156.   if exists('sys:storage/dosdrivers/ftp') then
  157.     address command 'mount ftp:'
  158.  
  159. /* End AmiTrix changes */
  160.      
  161. if left(upper(cmds),3)='URL' then do
  162.     do until cmds=''
  163.         parse var cmds name'="'value'"'cmds
  164.         if left(cmds,1)='&' then cmds=right(cmds,length(cmds)-1)
  165.         interpret name'=value'
  166.     end
  167.     select
  168.         when function='upload' then do
  169.             call open(1,tmpfile,w)
  170.             call writeln(1,'<html><head><title>About AwebFTP</title></head><body>')
  171.             if (exists(file))&(file~='FILE') then do
  172.                 address command 'copy 'text' 'url        
  173.                 if rc<20 then call writeln(1,'<h1>Transfer Successful</h1><h2>'text' uploaded.</h2>')
  174.                 else call writeln(1,'<h1>Error</h1><h3>Could not transfer <b>'text'</b> to 'url'</h3>')
  175.             end
  176.             else do
  177.                 address command 'requestfile RAM: >t:awebftp.tmp'
  178.                 call open(2,'t:awebftp.tmp',r)
  179.                 text=readln(2)
  180.                 call close(2)
  181.                 if word(text,1)~='no' then do
  182.                     parse var text .'"'text'"'.
  183.                     if exists(text) then do
  184.                         call putawebmsg('<h3>Now uploading 'text' to 'url'.</h3>You may continue using Aweb asyncronously (especially if file is long).')
  185.                         address command 'copy 'text' 'url
  186.                         if rc<10 then call writeln(1,'<h1>Transfer Successful</h1><h2>'text' uploaded.</h2><a href="'url'">Go Back</a>')
  187.                         else call writeln(1,'<h1>Error</h1><h3>Could not transfer <b>'text'</b> to 'url'</h3>')
  188.                     end
  189.                     else call writeln(1,'<h1>Error</h1><h3>Could not open <b>'text'</b> to send</h3>')
  190.                 end
  191.                 else call writeln(1,'<h1>Transfer Cancelled</h1>')
  192.             end
  193.             call writeln(1,'</body></html>')    
  194.             call close(1)
  195.             'OPEN file://localhost/'tmpfile
  196.             exit
  197.         end
  198.         when function='makedir' then do
  199.             if file~='FILE' then do
  200.                 if exists(url||file) then call putawebmsg("Directory already exists!")
  201.                 else do
  202.                     call putawebmsg("Making directory.  Please wait.<h5>(Ignore this if [Back]ing up)</h5>")
  203.                     address command 'makedir 'url||file
  204.                     if rc<10 then call putawebmsg('Directory 'file' created successfully. <br><a href="'url'">Go Back</a>')
  205.                     else call putawebmsg("<h1>Error</h1>Directory was NOT created.")
  206.                 end
  207.             end
  208.             else call putawebmsg("No directory specified.")
  209.             exit
  210.         end
  211.         when function='delete' then do
  212.             if file~='FILE' then do
  213.                 if exists(url||file) then do
  214.                     address command 'requestchoice "Delete File" "Delete 'file' ?" "Delete|Cancel" >t:awebftpchoice.tmp'
  215.                     if open(1,'t:awebftpchoice.tmp',r) then do
  216.                         text=readln(1)
  217.                         if strip(text)='1' then do
  218.                             address command 'delete 'url||file' >t:awebftp.tmp'
  219.                             if rc<10 then call putawebmsg('File <b>'file'</b> deleted. <br><a href="'url'">Go Back</a>')
  220.                             else call putawebmsg("<h1>Error</h1>Error with deletion")                
  221.                         end
  222.                         else call putawebmsg("Delete Cancelled.")
  223.                     end
  224.                 end
  225.                 else call putawebmsg('<h1>Error</h1><b>'file'</b> does not exist!')
  226.             end
  227.             else call putawebmsg("No directory specified.")
  228.             exit
  229.         end
  230.         when function='amiftp' then do
  231.             parse var url 'ftp://'hostname'/'dirs
  232.             dirs='/'dirs
  233.             if showlist(P,'AMIFTP') then do
  234.                 address 'AMIFTP' 'GETATTR STEM ainfo'
  235.                 if (ainfo.HOST ~= hostname) then do
  236.                     address 'AMIFTP' 'DISCONNECT'
  237.                     address 'AMIFTP' 'SETATTR HOST' hostname
  238.                     address 'AMIFTP' 'CONNECT NOSCAN'
  239.                 end
  240.                 address 'AMIFTP' 'CD' dirs
  241.             end
  242.             else do
  243.                 address command amiftpexe
  244.                 timeout=0
  245.                 address command 'waitforport AMIFTP'
  246.                 if (showlist(P,'AMIFTP')) then do
  247.                     address 'AMIFTP' 'GETATTR STEM ainfo'
  248.                     if (ainfo.HOST ~= hostname) then do
  249.                         address 'AMIFTP' 'DISCONNECT'
  250.                         address 'AMIFTP' 'SETATTR HOST' hostname
  251.                         address 'AMIFTP' 'CONNECT NOSCAN'
  252.                     end
  253.                     address 'AMIFTP' 'CD' dirs
  254.                 end
  255.                 else do
  256.                     putawebmsg('Error: Couldn''t run AmiFTP')
  257.                     exit
  258.                 end
  259.             end
  260.         end    
  261.         otherwise do
  262.             call putawebmsg('Program Error: please <a href="mailto:panther@gate.net">mail</a> author w/ errorcode: F-'function' and conditions under which it failed.')
  263.         end
  264.     end
  265.     exit
  266. end
  267.  
  268. if server='about' then do
  269.     call open(1,tmpfile,w)
  270.     call writeln(1,'<html><head><title>About AwebFTP</title></head><body>')
  271.     call writeln(1,'<h1>About AwebFTP 'word(vers,2)'</h1>')
  272.     call writeln(1,'AwebFTP is an FTP plug-in arexx script for Aweb, which does FTP inside Aweb''s GUI, provided you have FTPMount installed')
  273.     call writeln(1,'<p><h2>Features of AwebFTP</h2><ul>')
  274.     call writeln(1,'<li>Fast reaction, since FTPMount does caches dirs.')
  275.     call writeln(1,'<li>Inline - Stays within the Aweb GUI.')
  276.     call writeln(1,'<li>Asyncronous download (thanks to Aweb), you can continue browsing while it downloads, and Aweb will inform you when the transfer has completed!')
  277.     call writeln(1,'<li>Brings up a requestor to ask what you want to save as.')
  278.     call writeln(1,'</ul>New for 1.1:<ul>')
  279.     call writeln(1,'<li>You can now upload to the directory if you type the name of a file in a form at the bottom of the list (or leave blank, and it will give you a requester asking for a file)')
  280.     call writeln(1,'<li>Make directories')
  281.     call writeln(1,'<li>Delete a file (currently only one file at a time)')
  282.     call writeln(1,'<li>Title is now a link: click to refresh the list after send/makedir/delete, etc')
  283.     call writeln(1,'</ul>New for 1.2:<ul>')
  284.     call writeln(1,'<li>WBCopy command used to copy files with progress meter')
  285.     call writeln(1,'<br>Thanks to Bastian H. Frank for developing this handy program!')
  286.     call writeln(1,'</ul>New for 1.3:<ul>')
  287.     call writeln(1,'<li>Much faster:<ul>')
  288.     call writeln(1,'<li>No longer parses list output, uses lformat to create listing')
  289.     call writeln(1,'</ul><li>AmiFTP can now be automatically loaded and set to the current dir!<ul>');
  290.     call writeln(1,'<li>Will detect if amiftp is already loaded, and go to the directory');
  291.     call writeln(1,'<li>Doesn''t disconnect and reconnect if amiftp already has the host open');
  292.     call writeln(1,'</ul></ul>')
  293.     call writeln(1,'</ul><p><h2>Known Bugs</h2><ul>')
  294.     call writeln(1,'<li>Linked files are sometimes thought to be directories in AmigaDOS, and may wind up returning an empty directory listing instead of the actual file.')
  295.     call writeln(1,'<p>I''ve attempted to correct this by checking if the link clicked on has a period in the name, if so, it assumes it''s a file instead.  Hopefully this bug is obsolete with the new copy program.  Let me know if you find any URL''s that this still happens on.<p>')
  296.     call writeln(1,'<li>Many people are getting "out of memory" errors.  This should only be    occuring on old versions of AwebFTP, and usually only when they forget    to pass all three %s arguments in aweb''s preferences.  If this is still occuring in this version for you, PLEASE let me know the URL.')
  297.     call writeln(1,'</ul><p><h2>AwebFTP Author</h2>')
  298.     call writeln(1,'<p>AwebFTP is written by <a href="http://www.versanet.com/~josef/">me</a> (<a href="mailto:panther@gate.net">panther@gate.net</a>), Josef on <a href="irc://innernet.org/#Amiga">IRC</a>.  I have also written a few other arexx scripts for Aweb, and over a hundred arexx scripts for Grapevine IRC client (mostly available on my <a href="http://www.versanet.com/~josef/">home page</a>.')
  299.     call writeln(1,'<hr><a href="http://ftp.wustl.edu/aminetbin/find?ftpmount">Latest FTPMount from Aminet</a> | <a href="http://www.versanet.com/~josef/aweb">Other Aweb Scripts</a> | <a href="http://www.versanet.com/~josef/crap/net.html">Other Net Applications</a>')
  300.     call writeln(1,'</body></html>')
  301.     call close(1)
  302.     'OPEN file://localhost/'tmpfile
  303.     exit
  304. end
  305. if server='upload' then do
  306. end
  307. do
  308.     if right(server,1)~='/' then server=server'/'
  309.     if length(file)>0 then do
  310.         filebk=file
  311.         dir=''
  312.         do until index(filebk,'/')=0
  313.             parse var filebk dirbk'/'filebk
  314.             dir=dir||dirbk'/'
  315.         end
  316.         file=filebk
  317.         url='ftp://'server||dir||file
  318.     end
  319.     else url='ftp://'server
  320.     call putawebmsg('Opening 'url' -  Please wait. <h5>(Ignore this if [Back]ing up)</h5>')
  321.     if exists(url) then do
  322.         info=statef(url)
  323.         type=word(info,1)
  324.         if type='DIR' then do
  325.             if index(file,'.')>0 then type='FILE'
  326.         end
  327.         size=word(info,2)
  328.         select
  329.             when type='DIR' then do
  330.                 if right(url,1)~='/' then url=url'/'
  331.                 call open(2,tmpfile,w)
  332.                 call writeln(2,'<html><head><title>'url'</title></head><body>')
  333.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  334.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  335.                 call writeln(2,'<input type=hidden name=function value=amiftp>')
  336. /* Changed by AmiTrix to only put AmiFTP button up if configured. */    
  337.                      if amiftpexe ~== '' then
  338.                    if(showlist(P,'AMIFTP')) then do
  339.                       call writeln(2,'<input type=submit value="Update AmiFTP!")></form>')
  340.                   end
  341.                   else do
  342.                     call writeln(2,'<input type=submit value="Load AmiFTP!")></form>')
  343.                   end
  344.                 call writeln(2,'<pre><h2>Directory of <a href="'url'">'url'</a></h2>')
  345.                 call writeln(2,'<hr>   Date          Size    Name<hr>')
  346.                 call close(2)
  347.                 address command 'list 'url' lformat "%10d %10l  <a href='url'%n>%s</a>" >>'tmpfile
  348.                 call open(2,tmpfile,a)
  349.                 call writeln(2,'</pre><hr>')
  350.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  351.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  352.                 call writeln(2,'<input type=hidden name=function value=upload>')
  353.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  354.                 call writeln(2,'<input type=submit value="Send File")></form>')
  355.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  356.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  357.                 call writeln(2,'<input type=hidden name=function value=makedir>')
  358.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  359.                 call writeln(2,'<input type=submit value="Make Dir")></form>')
  360.                 call writeln(2,'<form action="x-aweb:rexx/'||called||'">')
  361.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  362.                 call writeln(2,'<input type=hidden name=function value=delete>')
  363.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  364.                 call writeln(2,'<input type=submit value="Delete File")></form>')
  365.                 call writeln(2,'<hr><a href="ftp://about/">AwebFTP</a> 'vers' by <a href="mailto:panther@gate.net">Josef Faulkner</a>.')
  366.                 call writeln(2,'</body></html>')
  367.                 call close(1)
  368.                 call close(2)
  369.                 'open file://localhost/'tmpfile
  370.                                 'ALLOWCMD'
  371.             end
  372.             when type='FILE' then do
  373.                 if open(11,url,r) then do
  374.                     call close(11)
  375.                     address command 'requestchoice "AWebFTP" "View or Save 'file'?" "View|Save|Cancel" pubscreen="'screen'" >t:awebftpchoice.tmp'
  376.                     call open(1,'t:awebftpchoice.tmp',r)
  377.                     text=readln(1)
  378.                     call close(1)
  379.                     select
  380.                         when text=0 then do
  381.                             call putawebmsg('Transfer aborted.')
  382.                         end
  383.                         when text=1 then do
  384.                             call putawebmsg('Downloading 'url' to view in Aweb.')
  385.                             address command copycommand' 'url' 'tmpfile' >nil:'
  386.                             'open file://localhost/'tmpfile
  387.                         end
  388.                         when text=2 then do
  389.                             address command 'requestfile drawer='savedir' file='file' pubscreen='screen' >'tmpfile
  390.                             call open(1,tmpfile,r)
  391.                             text=readln(1)
  392.                             call close(1)
  393.                             if left(text,7)~='no more' then do
  394.                                 call putawebmsg('Downloading 'file' ('size' bytes).<br> You may resume using Aweb, and a message will appear when transfer is complete.')
  395.                                 address command copycommand' 'url' 'text' >nil:'
  396.                                 call putawebmsg('Download of 'file' to 'text' complete.')
  397.                             end
  398.                             else do
  399.                                 call putawebmsg('Transfer aborted.')
  400.                             end
  401.                         end
  402.                         otherwise do
  403.                             call putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #2-'text)
  404.                             exit
  405.                         end
  406.                     end
  407.                 end
  408.                 else do
  409.                     call putawebmsg('Sorry, could not open 'url' for read access.')
  410.                 end
  411.             end
  412.             otherwise do
  413.                 call putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #1-'type)
  414.                 exit
  415.             end
  416.         end
  417.     end
  418.     else do
  419.         call putawebmsg('Sorry, 'url' doesn''t exist.')
  420.     end
  421. end
  422. exit
  423.  
  424. PUTAWEBMSG: procedure
  425. parse arg text
  426.     address command 'delete t:awebmsg#?.html >NIL:'
  427.     fname='t:awebmsg'time(S)'.html'
  428.     call open(4,fname,w)
  429.     call writeln(4,'<html><head><title>AwebFTP Message</title></head><body>')
  430.     call writeln(4,'<h3>'text'</h3>')
  431.     call writeln(4,'</body>')
  432.     call close(4)
  433.     'OPEN file://localhost/'fname
  434. return
  435.