home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxftpsrc.zip / LOGIN.VRX < prev    next >
Text File  |  1995-10-05  |  8KB  |  327 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end
  20.     InitArgs.0 = argCount
  21.     if( argCount > 0 )then do i = 1 to argCount
  22.         InitArgs.i = arg( i + argOff )
  23.     end
  24.     drop calledAs argCount argOff
  25.  
  26. /*  Load the windows
  27. */
  28.     call VRInit
  29.     parse source . . spec
  30.     _VREPrimaryWindowPath = ,
  31.         VRParseFileName( spec, "dpn" ) || ".VRW"
  32.     _VREPrimaryWindow = ,
  33.         VRLoad( parent, _VREPrimaryWindowPath )
  34.     drop parent spec
  35.     if( _VREPrimaryWindow == "" )then do
  36.         call VRMessage "", "Cannot load window:" VRError(), ,
  37.             "Error!"
  38.         _VREReturnValue = 32000
  39.         signal _VRELeaveMain
  40.     end
  41.  
  42. /*  Process events
  43. */
  44.     call Init
  45.     signal on halt
  46.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  47.         _VREEvent = VREvent()
  48.         interpret _VREEvent
  49.     end
  50. _VREHalt:
  51.     _VREReturnValue = Fini()
  52.     call VRDestroy _VREPrimaryWindow
  53. _VRELeaveMain:
  54.     call VRFini
  55. exit _VREReturnValue
  56.  
  57. VRLoadSecondary: procedure
  58.     name = arg( 1 )
  59.  
  60.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  61.     call VRMethod window, "CenterWindow"
  62.     call VRSet window, "Visible", 1
  63.     call VRMethod window, "Activate"
  64. return window
  65.  
  66. /*:VRX         BasicErrMsg
  67. */
  68. BasicErrMsg:
  69.     /* Easy way of showing simple error messages, thanks to VX-REXX's
  70.      * ability to expand the dialog box to fit the message.
  71.      */
  72.     ErrMessage = arg(1)
  73.  
  74.     OK = 1
  75.     Buttons.OK = "OK"
  76.     Cancel = 2
  77.     Buttons.Cancel = "Cancel"
  78.     Buttons.0 = 2
  79.     
  80.     id = VRMessage( VRWindow(), ErrMessage, "Error", ,
  81.                      "Error", "Buttons.", OK, Cancel )
  82.     drop ErrMessage
  83. return
  84.  
  85. /*:VRX         BuildAliasList
  86. */
  87. BuildAliasList:
  88.     rc = VRMethod( "Application", "GetVar", "IniFile" )
  89.     Aliases = VRGetIni( "VxFTP", "Aliases", IniFile )
  90.  
  91.     if ( Aliases = "" ) then 
  92.         LAliases.0 = 0
  93.     else do
  94.        /* Create the LAliases. variable for holding the Aliases
  95.         */
  96.         i = 0
  97.         do until Aliases = ""
  98.             i = i + 1
  99.             parse value Aliases with LAliases.i "}{" Aliases
  100.         end
  101.         LAliases.0 = i
  102.  
  103.        /* Build the Alias list in AliasName. for displaying the 
  104.         * Aliases' names in the list box
  105.         */
  106.         do i = 1 to LAliases.0
  107.             parse value LAliases.i with AliasName.i "|" junk
  108.         end
  109.         AliasName.0 = i - 1
  110.  
  111.         rc = VRMethod( "DDCB_Aliases", "AddStringList", "AliasName.",  )
  112.  
  113.         drop junk
  114.     end
  115.  
  116. return
  117.  
  118. /*:VRX         BuildHostOSList
  119. */
  120. BuildHostOSList:
  121.     HostOS.1 = "auto detect"
  122.     HostOS.2 = "OS/2"
  123.     HostOS.3 = "UNIX"
  124.     HostOS.4 = "Windows NT"
  125.     HostOS.5 = "NetWare"
  126.     HostOS.6 = "IBM VM"
  127.     HostOS.7 = "VAX VMS"
  128.     HostOS.8 = "Macintosh"
  129.     HostOS.0 = 8
  130.     rc = VRMethod( "DDCB_HostOS", "AddStringList", "HostOS.",  )
  131.     rc = VRSet( "DDCB_HostOS", "Value", HostOS.1 )
  132.  
  133. return
  134.  
  135. /*:VRX         CB_AnonFtp_Click
  136. */
  137. CB_AnonFtp_Click:
  138.     AnonFTP = VRGet( "CB_AnonFtp", "Set" )
  139.     if ( AnonFTP = 1 ) then do
  140.         rc = VRSet( "EF_Login", "Value", "anonymous" )
  141.         rc = VRMethod( "Application", "GetVar", "IniFile" )
  142.         anonPasswd = VRGetIni( "VxFTP", "Email", IniFile )
  143.         
  144.         if ( rc = 1 ) then
  145.             rc = VRSet( "EF_Password", "Value", anonPasswd )
  146.         else
  147.             rc = VRSet( "EF_Password", "Value", "os2user@here.org" )
  148.     end
  149.     else do
  150.         rc = VRSet( "EF_Login", "Value", "" )
  151.         rc = VRSet( "EF_Password", "Value", "" )
  152.     end /* else */
  153. return
  154.  
  155. /*:VRX         DDCB_Aliases_Click
  156. */
  157. DDCB_Aliases_Click:
  158.     /* Get all the data associated with the Alias that the User 
  159.      * selected and stick it in the entry fields
  160.      */
  161.     aliasSelected = VRGet( "DDCB_Aliases", "SelectedString" )
  162.  
  163.     if ( aliasSelected = "" ) | ( LAliases.0 = 0 ) then
  164.         return
  165.     else do
  166.         do i = 1 to AliasName.0 
  167.             if (AliasName.i \= aliasSelected) then 
  168.                 iterate
  169.  
  170.             else do
  171.                 parse value LAliases.i with junk "|" AliasHost "|" AliasLogin "|" AliasPasswd "|" AliasCWD "|" AliasHostOS
  172.                 call VRSet "EF_Host",     "Value", AliasHost
  173.                 call VRSet "DDCB_HostOS", "Value", AliasHostOS
  174.                 call VRSet "EF_Login",    "Value", AliasLogin
  175.                 call VRSet "EF_Password", "Value", AliasPasswd
  176.                 call VRSet "EF_CWD",      "Value", AliasCWD
  177.  
  178.                 if ( translate( AliasLogin ) = "ANONYMOUS" ) | ,
  179.                    ( translate( AliasLogin ) = "FTP" ) then
  180.                     rc = VRSet( "CB_AnonFtp", "Set", 1 )
  181.                 else
  182.                     rc = VRSet( "CB_AnonFtp", "Set", 0 )
  183.  
  184.             end /* end else */
  185.  
  186.         end /* end do */
  187.     end /* end else */
  188.  
  189.     drop junk
  190. return
  191.  
  192. /*:VRX         Fini
  193. */
  194. Fini:
  195.     window = VRWindow()
  196.     call VRSet window, "Visible", 0
  197.     drop window
  198.  
  199. /* return the stuff we packaged in PB_OK (in retCode) */
  200.  
  201. return retCode
  202.  
  203. /*:VRX         Halt
  204. */
  205. Halt:
  206.     signal _VREHalt
  207. return
  208.  
  209. /*:VRX         Init
  210. */
  211. Init:
  212.     /* Initialize the Login() function's return code (retCode)
  213.      * to null.
  214.      */
  215.     retCode = ""
  216.     call BuildAliasList
  217.     call BuildHostOSList
  218.  
  219.     window = VRWindow()
  220.     call VRMethod window, "CenterWindow"
  221.     call VRSet window, "Visible", 1
  222.     call VRMethod window, "Activate"
  223.  
  224.     call VRMethod "EF_Host", "SetFocus"
  225.     drop window
  226. return
  227.  
  228. /*:VRX         PB_Cancel_Click
  229. */
  230. PB_Cancel_Click:
  231.     call Quit
  232. return
  233.  
  234. /*:VRX         PB_OK_Click
  235. */
  236. PB_OK_Click:
  237.  
  238.     host = VRGet("EF_Host", "Value")
  239.     login = VRGet("EF_Login", "Value")
  240.     passwd = VRGet("EF_Password", "Value")
  241.     cwd = VRGet("EF_CWD", "Value")
  242.     systype = VRGet( "DDCB_HostOS", "Value" )
  243.  
  244.     if ( host = "" ) | ( login = "" ) then do
  245.         call BasicErrMsg "You must specify a Host and Login"
  246.         return -1
  247.     end
  248.  
  249.     /* Strip away leading or trailing blanks        */
  250.     host = strip(host)
  251.     login = strip(login)
  252.     passwd = strip(passwd)
  253.     cwd = strip(cwd)
  254.  
  255.     /* If user sets the "Add to Alias" checkbox, then add 
  256.      * values in all the fields and call UpdateAliases to
  257.      * save it in the IniFile.
  258.      */
  259.     AddAlias = VRGet( "CB_AddToAlias", "Set" )
  260.     if ( AddAlias = 1 ) then do
  261.         NewAlias = VRGet( "DDCB_Aliases", "Value" )
  262.         if ( NewAlias = "" ) then do
  263.             call BasicErrMsg "You must specify an Alias Name"
  264.             return -1
  265.         end
  266.  
  267.         do i = 1 to LAliases.0
  268.             if ( NewAlias = AliasName.i ) then do
  269.                 leave /* leave the do-loop */
  270.             end /* if */        
  271.         end /* do */
  272.  
  273.         /* Going all the way through a DO-loop sequence has the side
  274.          * effect of leaving your index variable (i) incremented by
  275.          * one above the upper bound (LAliases.0). So to add on, we
  276.          * just use the index, i, as the new upper bound.
  277.          */
  278.         if ( i > LAliases.0 ) then
  279.             LAliases.0 = i
  280.         LAliases.i = NewAlias || "|" || host || "|" || login || "|" || passwd || "|" || cwd || "|" || systype
  281.  
  282.         call UpdateAliases
  283.     end
  284.  
  285.     Anon = VRGet( "CB_AnonFtp", "Set" )
  286.     if ( Anon = 1 ) then
  287.         Anon = "TRUE"
  288.     else
  289.         Anon = "FALSE"
  290.  
  291.     retCode = host || "|" || login || "|" || passwd || "|" || cwd || "|" || Anon || "|" || systype
  292.     call Quit
  293.  
  294. return
  295.  
  296. /*:VRX         Quit
  297. */
  298. Quit:
  299.     window = VRWindow()
  300.     call VRSet window, "Shutdown", 1
  301.     drop window
  302. return
  303.  
  304. /*:VRX         UpdateAliases
  305. */
  306. UpdateAliases:
  307.     /* Extract the Aliases from the LAlias stem and update
  308.      * the Aliases in the IniFile.
  309.      */
  310.     NewAliases = ""
  311.     do i = 1 to LAliases.0
  312.         NewAliases = NewAliases || LAliases.i || "}{"
  313.     end
  314.  
  315.     rc = VRSetIni( "VxFTP", "Aliases", NewAliases, IniFile )
  316.  
  317.     drop NewAliases
  318.  
  319. return
  320.  
  321. /*:VRX         Window1_Close
  322. */
  323. Window1_Close:
  324.     call Quit
  325. return
  326.  
  327.