home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ftprxfe1.zip / FTPMRXFE.CMD next >
OS/2 REXX Batch file  |  1993-11-16  |  10KB  |  263 lines

  1. /* File FTPPM_VISUAL_REXX_FRONT_END.CMD
  2.  *
  3.  * Synopsis:    Presentation Manager front end (through Visual REXX)
  4.  *              for the TCP/IP file transfer program FTPPM.
  5.  *
  6.  * Author:      Michele Marziani
  7.  *              Dipartimento di Fisica
  8.  *              Universita' di Ferrara, ITALY
  9.  *              e-mail: marziani@ferrara.infn.it
  10.  *
  11.  * Requirements:IBM OS/2 2.x with REXX installed
  12.  *              IBM TCP/IP version 1.2.1 or higher (only tested with 1.2.1)
  13.  *              IBM EWS VREXX 1.0 or higher
  14.  *                (available via anonymous ftp from any major OS/2 archive,
  15.  *                 e.g. ftp.cdrom.com or software.watson.ibm.com)
  16.  *
  17.  * Description: Are you tired of re-typing the same information at all
  18.  *              times when FTPing to a remote host?
  19.  *              The TCP/IP FTPPM "Remote Logon" procedure reads your
  20.  *              NETRC file searching for "User" and "Password" for any
  21.  *              defined host name. However you are supposed to type in
  22.  *              the "Host" information anyway.
  23.  *              I think this is a very annoying feature of FTPPM.
  24.  *              This REXX procedure tries to remedy this behaviour.
  25.  *
  26.  *              This REXX cmd file is used to start the FTPPM program
  27.  *              through a Presentation Manager front end. This allows
  28.  *              the choice of a remote host entry in the TCP/IP NETRC
  29.  *              file via a PM listbox, without any user typing.
  30.  *
  31.  *              One more entry is added to the listbox: "UNLISTED HOST".
  32.  *              This allows the user to specify the name, user id (optional)
  33.  *              and password (optional) for an host not yet defined in the
  34.  *              NETRC file, by means of a standard PM dialog box (the
  35.  *              password is not echoed to the screen). This behaviour is
  36.  *              quite similar to the "Remote Logon" feature of FTPPM.
  37.  *              If you leave the user and password fields empty, however,
  38.  *              an anonymous ftp connection is tried with the specified
  39.  *              host, using "os2user@host.subdomain.domain" as a password.
  40.  *              The TCP/IP definition of "host.subdomain.domain" is
  41.  *              automatically retrieved from information returned by the
  42.  *              OS/2 TCP/IP command 'hostname'.
  43.  *              
  44.  *              This procedure expects a NETRC file in the standard format
  45.  *              as stated in an appendix of the TCP/IP 1.2.1 manual, i.e.
  46.  *                      machine NAME [login USER] [password PASS]
  47.  *              I think at least both NAME and USER have to specified in
  48.  *              order to have a reasonably automated login procedure.
  49.  *
  50.  * License:     This program is FREEWARE. It is donated to the public domain
  51.  *              granted that you are not charging anything (money etc.) for
  52.  *              it and derivates based upon it. You may freely distribute this
  53.  *              program, provided that no changes are made to it and that the
  54.  *              accompanying doc file FTPMRXFE.DOC is being distributed
  55.  *              together with FTPMRXFE.CMD in the unmodified archive
  56.  *              file FTPRXFE1.ZIP.
  57.  *
  58.  * Disclaimer:  The same standard disclaimers apply as for any piece of
  59.  *              shareware/freeware software. Therefore there is no guarantee
  60.  *              that it works without errors, etc. etc.
  61.  *
  62.  *              In fact this is my second REXX program in my life! All the
  63.  *              code below was partly inspired by very useful pieces of code
  64.  *              I've found at ftp.cdrom.com or software.watson.ibm.com
  65.  *              (e.g. VARC10B3, ZIPENG10, VREXX TESTDLGS.CMD, etc...).
  66.  *              Many thanks to their respective authors.
  67.  *
  68.  *              This program has only been tested with an 800x600 PM screen
  69.  *              mode. So there is a chance that the program windows are not
  70.  *              correctly positioned/displayed with different screen
  71.  *              resolutions. However window screen positioning shouldn't be
  72.  *              dependent on PM screen resolution. Furthermore, error checking
  73.  *              is far from extensive. So don't blame me too much.
  74.  *
  75.  *              Please, if you find an error, post me a message describing it.
  76.  *              I will try to fix and rerelease it to the net.
  77.  *              If you can improve it, please do so. All I ask is that you
  78.  *              drop me a note with a copy of the improvements.
  79.  *
  80.  *              You can contact me with suggestions or bug reports via e-mail
  81.  *              on the Internet at 'marziani@ferrara.infn.it' or on DECnet
  82.  *              at '39967::MARZIANI'.  Thank you.
  83.  *
  84.  * Revision history:
  85.  *   v1.00: 11/11/93    Initial version (not released)
  86.  *   v1.01: 15/11/93    Fixed bug in the NETRC file search mechanism
  87.  *                      Improved NETRC file opening logic
  88.  *                      Modified sign-on window font size
  89. ******************************************************************************/
  90.  
  91. '@echo off'
  92.  
  93. versionStr='v1.01'
  94. seconds = 3                     /* Number of seconds to wait */
  95.  
  96. /*---------------------------------------------------------------------------*/
  97. /* Load REXXUTIL and VREXX                                                   */
  98. /*---------------------------------------------------------------------------*/
  99. If RxFuncQuery('SysLoadFuncs') \= 0 Then
  100.   If RxFuncAdd('SysLoadFuncs','RexxUtil','SysLoadFuncs') <>0 Then Do
  101.     Say 'Unable to init REXX Utility function loader.'
  102.     Exit
  103.   End
  104. Call SysLoadFuncs
  105. /* register VREXX procedures as necessary */
  106. Call RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  107. If VInit()='ERROR' Then Do
  108.   Say 'This script requires VREXX running under OS/2 v2.x'
  109.   Say 'If VREXX is installed on this machine, then it is likely that a prior'
  110.   Say 'VREXX process has terminated uncleanly. Restart your computer or kill'
  111.   Say 'the process named "VREXX" to fix this problem.'
  112.   signal CLEANUP
  113. End
  114.  
  115. signal on failure name CLEANUP
  116. signal on halt name CLEANUP
  117. signal on syntax name CLEANUP
  118.  
  119.  
  120. /* open a window and draw some text */
  121.  
  122. win.left   = 25
  123. win.right  = 75
  124. win.top    = 60
  125. win.bottom = 40
  126. id = VOpenWindow('FTPMRXFE '||versionStr, 'WHITE', win)
  127.  
  128. text.1 = '       FTPPM VREXX Front End' versionStr
  129. text.2 = ''
  130. text.3 = ''
  131. text.4 = '       Copyright (c) 1993 by Michele Marziani'
  132. text.5 = '              e-mail: marziani@ferrara.infn.it'
  133.  
  134. call VForeColor id, 'BLACK'
  135. call VSetFont id, 'TIME', 24
  136.  
  137. x = 50
  138. y = 650
  139. call VSay id, x, y, text.1
  140.  
  141. call VSetFont id, 'TIME', 20
  142. do i = 2 to 5
  143.    call VSay id, x, y, text.i
  144.    y = y - 150
  145. end
  146.  
  147. Call SysSleep seconds           /* allow some time for display */
  148. Call VCloseWindow id            /* close window */
  149.  
  150.  
  151. do while queued()>0             /* Clean up process queue */
  152.   parse pull .
  153. end
  154.  
  155. 'hostname | rxqueue /fifo'      /* Query nameserver for host name */
  156. if rc <> 0 then signal CLEANUP
  157.  
  158. do queued()                     /* Should be = 1 */
  159.   parse pull my_host
  160. end
  161.  
  162. my_e_mail = "os2user"||"@"||my_host
  163.  
  164. netrc_file = value('NETRC',,'os2environment')   /* Find user NETRC file */
  165. if netrc_file = "" then
  166.   do
  167.     etc_dir = value('ETC',,'os2environment')    /* Find NETRC file */
  168.     if etc_dir = "" then etc_dir="C:\TCPIP\ETC" /+ TCP/IP default  */
  169.     netrc_file = etc_dir||"\NETRC"
  170.   end
  171.  
  172. /* Read and parse NETRC file */
  173.  
  174. if stream(netrc_file, "c", "query exists") == "" then
  175.   do
  176.     say ''
  177.     say "Can't find/open" netrc_file
  178.     signal CLEANUP
  179.   end
  180.  
  181. l      = 0                      /* initialize counters */
  182. host.0 = 0
  183. hstlen = 0
  184.  
  185. do until lines(netrc_file) = 0  /* repeat this loop until no lines   */
  186.                                 /* remain in the selected file...    */
  187.    l = l + 1                    /* increment the line-number counter */
  188.    line = linein(netrc_file)
  189.    parse var line . host.l .
  190.    hl = length(host.l)          /* find maximum host name length */
  191.    if hl > hstlen then hstlen=hl  
  192. end
  193. Call LINEOUT netrc_file         /* Close the file */
  194.  
  195. /* VListBox */
  196. l=l+1
  197. host.l = 'UNLISTED HOST'
  198. host.0 = l
  199. call VDialogPos 50, 40
  200. if VListBox('Select host name and Press OK', host, hstlen+5, 8, 3) = "CANCEL"
  201.   then signal CLEANUP
  202.  
  203. if host.vstring = "UNLISTED HOST" then
  204. do
  205.   /* VMultBox */
  206.   
  207.   prompt.0 = 3   /* 3 prompt lines */
  208.   prompt.1 = 'Host name'
  209.   prompt.2 = 'User ID'
  210.   prompt.3 = 'Password'
  211.   
  212.   width.0 = 3
  213.   width.1 = 35   /* widths in character units */
  214.   width.2 = 15   /* for entryfields */
  215.   width.3 = 15
  216.   
  217.   hide.0 = 3
  218.   hide.1 = 0     /* echo the Host name input */
  219.   hide.2 = 0     /* echo the User ID input */
  220.   hide.3 = 1     /* don't echo the Password */
  221.   
  222.   answer.0 = 3
  223.   answer.1 = ''  /* these are the default strings */
  224.   answer.2 = ''  /* which will contain the input */
  225.   answer.3 = ''
  226.   
  227.   do while answer.1 = ''
  228.     button = VMultBox('Input relevant data', prompt, width, hide, answer, 3)
  229.     if button = 'CANCEL' then signal CLEANUP
  230.     if answer.1 = '' then
  231.     do
  232.       msg.0 = 2
  233.       msg.1 = ''
  234.       msg.2 = '     Host name field cannot be empty!'
  235.       call VMsgBox 'Warning message', msg, 1
  236.     end
  237.   end
  238.  
  239.   tail = answer.1
  240.  
  241.   if answer.2 <> '' then
  242.     tail = tail || ' ' || answer.2
  243.   else
  244.     tail = tail || ' anonymous'
  245.  
  246.   if answer.3 <> '' then
  247.     tail = tail || ' ' || answer.3
  248.   else
  249.     tail = tail || ' ' || my_e_mail
  250. end
  251. else    /* An existing host name has been selected from VListBox */
  252.   tail = host.vstring
  253.  
  254. /* Now run FTPPM with proper command line*/
  255. 'start ftppm ' tail
  256.  
  257. /* end of CMD file */
  258.  
  259. CLEANUP:
  260.    call VExit
  261.  
  262. exit
  263.