home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / te2pro20.zip / TPHOST.SCR < prev    next >
Text File  |  1996-05-31  |  14KB  |  570 lines

  1. /* TE/2 Pro! host Mode Script */
  2. signal on syntax
  3.  
  4. /* Control variable */
  5. HostModeActive = 1
  6.  
  7. /* Handy character constants */
  8. lf          = D2C(10)
  9. ff          = D2C(12)
  10. cr          = D2C(13)
  11. esc         = D2C(27)
  12. crlf        = cr||lf
  13.  
  14. /* Modem initialization.  Edit these for your modem. */
  15. ModemInit   = 'ATZ'||cr
  16. AnswerCall  = 'ATA'||cr
  17. MaximumBaud = 57600
  18. StdParity   = 'none'
  19. StdWordLen  = 8
  20. StdStopBits = 1
  21. MatchBaud   = 0
  22. DevHandle   = 0 /* This is filled in at startup */
  23.  
  24. /* Files and paths.  Edit these for your system. */
  25. HomePath    = 'C:\te2pro\host'
  26. PublicPath  = 'C:\te2pro\host\dl'
  27. HostULPath  = 'C:\te2pro\host\ul'
  28. UserFile    = 'C:\te2pro\host\user.tph'
  29.  
  30. /* Control variable.  None of these are active at present, they are */
  31. /* reserved for future use.                                         */
  32. WatchUser   = 1
  33. HotKeys     = 1
  34. LocalLogin  = 0
  35.  
  36. /* Timing for WatForCall routine. WaitCallD1 is timeout value while */
  37. /* waiting for "RING", WaitCallD2 is sleep time between waits.      */
  38. WaitCallD1  = 60
  39. WaitCallD2  = 1
  40.  
  41. /* Set MatchBaud to 1 if your modem needs to match baud to the      */
  42. /* caller (2400bps modems) or set to 0 otherwise.  CallerBaud       */
  43. /* records the caller's baud if MatchBaud is 1 or is set to         */
  44. /* MaximumBaud otherwise.                                           */
  45. MatchBaud   = 0
  46. CallerBaud  = 0
  47.  
  48. /* Color attributes for menus, etc. */
  49. DfltAttr    = esc||'[36;0m'
  50. BoldOn      = esc||'[33;1m'
  51. BoldOff     = DfltAttr
  52. WarnOn      = esc||'[37;1m'
  53. WarnOff     = DfltAttr
  54. ClrTerm     = esc||'[2J'
  55.  
  56. /* Menus */
  57. Menu.       = ''
  58. Menu.0      = 4
  59. Menu.1      = '[F]ile directory'
  60. Menu.2      = '[D]ownload'
  61. Menu.3      = '[U]pload'
  62. Menu.4      = '[G]oodbye'
  63.  
  64. XMenu.      = ''
  65. XMenu.0     = 6
  66. XMenu.1     = '[X]modem'
  67. XMenu.2     = 'Xmodem-[1]K'
  68. XMenu.3     = '[Y]modem'
  69. XMenu.4     = 'Ymodem-[G]'
  70. XMenu.5     = '[Z]modem'
  71. XMenu.6     = '[ENTER] = return to main menu.'
  72.  
  73. /* User list and current user */
  74. Users.      = ''
  75. Users.0     = 0
  76. CurUser     = 0
  77. UserOK      = 0
  78.  
  79.  
  80. /* ---------------------------------------------------------------------
  81.    -- FaxWorks interoperability section
  82.       FaxAns  is a boolean flag to enable or disable answering of
  83.               incoming fax calls.  Set to 1 to enable, 0 to disable.
  84.       FaxPgm  is the full path to your copy of the FaxWorks executable
  85.               file.
  86.       FaxInit is your modem setup to enable answering of both fax and
  87.               data calls.  For Class 1 fax modems, this would be
  88.               "AT+FAE=1"||cr.  For Class 2 and 2.0 modems, this would be
  89.               "AT+FAA=1"||cr.
  90. ------------------------------------------------------------------------ */
  91. FaxAns  = 0
  92. FaxPgm  = 'd:\comm\pmfax\pmfax.exe'
  93. FaxInit = 'AT+FAE=1'||cr
  94. /* --------------------------------------------------------------------- */
  95.  
  96.  
  97. Main:
  98.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  99.   call SysLoadFuncs
  100.   call ReadUserList
  101.   SavedPath = directory()
  102.   'query devicehandle DevHandle'
  103.   do while HostModeActive = 1
  104.     'cls'
  105.     say 'TE/2 Pro Host Mode Script'
  106.     say
  107.     say
  108.     call InitModem
  109.     call WaitForCall
  110.     if HostModeActive = 1 then call HostMode
  111.   end
  112.   call directory SavedPath
  113.   exit 0
  114.  
  115.  
  116.  
  117. ReadUserList:
  118.   r = stream(UserFile, 'C', 'open read')
  119.   if r = 'READY:' then
  120.     do
  121.       do while lines(UserFile) > 0
  122.         r = linein(UserFile)
  123.         if length(r) > 0 then
  124.           do
  125.             parse var r lv ',' ln ',' fn ',' pw ',' cf ',' ct
  126.             if length(ct) > 0 then
  127.               do
  128.                 i = Users.0 + 1
  129.                 Users.i.Level     = lv
  130.                 Users.i.LastName  = ln
  131.                 Users.i.FirstName = fn
  132.                 Users.i.Password  = pw
  133.                 Users.i.Color     = translate(cf)
  134.                 Users.i.Lines     = ct
  135.                 Users.0 = i
  136.               end
  137.           end
  138.       end
  139.       call stream UserFile, 'C', 'close'
  140.     end
  141.   else
  142.     say 'Cannot read User File:' UserFile '(rescode='r')'
  143.   return
  144.  
  145.  
  146.  
  147. InitModem:
  148.   'set baud'     MaximumBaud
  149.   'set parity'   StdParity
  150.   'set databits' StdWordLen
  151.   'set stopbits' StdStopBits
  152.   'transmit' ModemInit
  153.   'sleep 2'
  154.   if FaxAns = 1 then
  155.     do
  156.       'transmit' FaxInit
  157.       'sleep 2'
  158.     end
  159.   return
  160.  
  161.  
  162.  
  163. WaitForCall:
  164.   say 'Waiting for call...'
  165.   do forever
  166.     say date() time() 'Waiting...'
  167.     'wait' WaitCallD1 'RING'
  168.     WaitResult = rc
  169.     select
  170.       when WaitResult = 1 then
  171.         do
  172.           'rcvcapture true'
  173.           'transmit' AnswerCall
  174.           GotFax = 0
  175.           if FaxAns = 1 then
  176.             do 5
  177.               'receive CR255 10 NOECHO'
  178.               ln = FixRmtInp(rc)
  179.               select
  180.                 when translate(word(ln, 1)) = 'DATA' then
  181.                   leave
  182.                 when translate(word(ln, 1)) = 'FAX' then
  183.                   do
  184.                     GotFax = 1
  185.                     leave
  186.                   end
  187.                 otherwise
  188.                   nop
  189.               end
  190.             end
  191.           if GotFax = 1 then
  192.             do
  193.               'rcvcapture false'
  194.               call ReceiveFax
  195.               iterate
  196.             end
  197.  
  198.           GotConnect = 0
  199.           do 5
  200.             'receive CR255 10 NOECHO'
  201.             ln = FixRmtInp(rc)
  202.             if translate(word(ln, 1)) = 'CONNECT' then
  203.               do
  204.                 GotConnect = 1
  205.                 leave
  206.               end
  207.           end
  208.           'rcvcapture false'
  209.           if GotConnect = 1 then
  210.             do
  211.               if MatchBaud = 1 then
  212.                 do
  213.                   tmpstrg = substr(ln, wordindex(ln, 2))
  214.                   do i = 1 to length(tmpstrg)
  215.                     if datatype(substr(tmpstrg)) \= 'NUM' then
  216.                       do
  217.                         tmpstrg = substr(tmpstrg, i)
  218.                         leave
  219.                       end
  220.                   end
  221.                   CallerBaud = tmpstrg
  222.                   'set baud' CallerBaud
  223.                 end
  224.               else
  225.                 CallerBaud = MaximumBaud
  226.               leave
  227.             end
  228.         end
  229.       when WaitResult = 10000 then
  230.         do
  231.           AskYN.Text  = 'Okay to exit host mode?'
  232.           AskYN.Title = 'TE/2 Pro! Host Mode'
  233.           AskYN.Style = X2D('4014') /* MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO */
  234.           'messageboxv askyn'
  235.           if rc = 6 /* MBID_YES */ then
  236.             do
  237.               HostModeActive = 0
  238.               leave
  239.             end
  240.         end
  241.       otherwise
  242.         'sleep' WaitCallD2
  243.     end
  244.   end
  245.   return
  246.  
  247.  
  248.  
  249. HostMode:
  250.   'sleep 3'
  251.   'transmit "'ff||crlf'Hello Caller...'crlf'"'
  252.   say
  253.   say date() time() 'Answered call'
  254.   'rcvcapture true'
  255.   call GetLogin
  256.   MenuLevel = 'MAIN'
  257.   if CurUser > 0 & UserOK > 0 then
  258.     do forever
  259.       'query carrier'
  260.       if rc = 1 then
  261.         do
  262.           call ShowMenu MenuLevel
  263.           call ExecMenu MenuLevel
  264.         end
  265.       else
  266.         leave
  267.     end
  268.   else
  269.     'hangup'
  270.   'rcvcapture false'
  271.   return
  272.  
  273.  
  274.  
  275. GetLogin:
  276.   CurUser = 0
  277.   UserOK  = 0
  278.   do 4
  279.     'transmit "'crlf'Enter FIRST and LAST name: '
  280.     'receive CR255 120 ECHO'
  281.     r = FixRmtInp(rc)
  282.     say
  283.     if length(r) > 0 then
  284.       do
  285.         parse upper var r fn ln
  286.         do i = 1 to Users.0
  287.           say fn ln 'vs.' Users.i.FirstName Users.i.LastName
  288.           if translate(Users.i.FirstName) = fn & translate(Users.i.LastName) = ln then
  289.             do
  290.               CurUser = i
  291.               leave
  292.             end
  293.         end
  294.         if CurUser > 0 then
  295.           leave
  296.         else
  297.           'transmit "'crlf'Could not locate username: 'r'"'
  298.       end
  299.   end
  300.   if CurUser > 0 then
  301.     do 4
  302.       'transmit "'crlf'Enter password: '
  303.       'receive CR255 120 NOECHO'
  304.       r = FixRmtInp(rc)
  305.       if length(r) > 0 then
  306.         do
  307.           if translate(Users.CurUser.Password) = translate(r) then
  308.             do
  309.               UserOK = 1
  310.               leave
  311.             end
  312.           else
  313.             'transmit "'crlf'Wrong password!"'
  314.         end
  315.     end
  316.   if CurUser > 0 & UserOK > 0 then
  317.     'transmit "Welcome' Users.CurUser.FirstName Users.CurUser.LastName||cr||lf'"'
  318.   else
  319.     'transmit "Bye!"'
  320.   return
  321.  
  322.  
  323.  
  324. ShowMenu:
  325.   parse arg MenuID
  326.  
  327.   TmpMenu.  = ''
  328.   select
  329.     when MenuID = 'MAIN' then
  330.       do
  331.         TmpMenu.0 = Menu.0
  332.         do i = 1 to Menu.0
  333.           TmpMenu.i = Menu.i
  334.         end
  335.       end
  336.     when MenuID = 'DOWNLOAD' | MenuID = 'UPLOAD' then
  337.       do
  338.         TmpMenu.0 = XMenu.0
  339.         do i = 1 to XMenu.0
  340.           TmpMenu.i = XMenu.i
  341.         end
  342.       end
  343.     otherwise TmpMenu.0 = 0
  344.   end
  345.  
  346.   if TmpMenu.0 > 0 then
  347.     do
  348.       if Users.CurUser.Color = 'Y' then
  349.         do
  350.           'transmit "'clrTerm'"'
  351.           'transmit "'BoldOn||MenuID||DfltAttr' Menu'crlf||crlf
  352.         end
  353.       else
  354.         do
  355.           'transmit "'crlf||crlf'"'
  356.           'transmit "'MenuID' Menu'crlf||crlf
  357.         end
  358.  
  359.       do i = 1 to TmpMenu.0
  360.         tmp = TmpMenu.i
  361.         if Users.CurUser.Color = 'Y' then
  362.           do
  363.             x1 = pos('[', tmp)
  364.             x2 = pos(']', tmp)
  365.             tmp = DfltAttr ||,
  366.                   substr(tmp, 1,    x1)      ||BoldOn  ||,
  367.                   substr(tmp, x1+1, x2-x1-1) ||DfltAttr||,
  368.                   substr(tmp, x2)
  369.           end
  370.         'transmit "'tmp||crlf'"'
  371.       end
  372.  
  373.       'transmit "'crlf||crlf'"'
  374.       prmpt = 'Select: '
  375.       if Users.CurUser.Color = 'Y' then
  376.         prmpt = WarnOn||prmpt||WarnOff
  377.       'transmit "'prmpt'"'
  378.     end
  379.  
  380.   return
  381.  
  382.  
  383.  
  384. ExecMenu:
  385.   parse arg MenuID
  386.  
  387.   'receive CR255 180 ECHO'
  388.   r = FixRmtInp(rc)
  389.   if length(r) > 0 then
  390.     do
  391.       r = translate(substr(r, 1))
  392.       select
  393.         when MenuID = 'MAIN' then
  394.           do
  395.             select
  396.               when r = 'F' then
  397.                 call GetFileDirectory
  398.               when r = 'D' then
  399.                 MenuLevel = 'DOWNLOAD'
  400.               when r = 'U' then
  401.                 MenuLevel = 'UPLOAD'
  402.               when r = 'G' then
  403.                 do
  404.                   if Users.CurUser.Color = 'Y' then
  405.                     'transmit "'crlf||crlf||BoldOn'Bye!'BoldOff||crlf||crlf'"'
  406.                   else
  407.                     'transmit "'crlf||crlf'Bye!'crlf||crlf'"'
  408.                   'hangup'
  409.                   'sleep 5'
  410.                 end
  411.               otherwise
  412.                 nop
  413.             end
  414.           end
  415.  
  416.         when MenuID = 'DOWNLOAD' then
  417.           do
  418.             select
  419.               when r = 'X' then call SendFile r
  420.               when r = '1' then call SendFile r
  421.               when r = 'Y' then call SendFile r
  422.               when r = 'G' then call SendFile r
  423.               when r = 'Z' then call SendFile r
  424.               otherwise
  425.                 nop
  426.             end
  427.           end
  428.  
  429.         when MenuID = 'UPLOAD' then
  430.           do
  431.             select
  432.               when r = 'X' then call GetFile r
  433.               when r = '1' then call GetFile r
  434.               when r = 'Y' then call GetFile r
  435.               when r = 'G' then call GetFile r
  436.               when r = 'Z' then call GetFile r
  437.               otherwise
  438.                 nop
  439.             end
  440.           end
  441.  
  442.         otherwise
  443.           nop
  444.       end
  445.     end
  446.   else
  447.     MenuLevel = 'MAIN'
  448.  
  449.   return
  450.  
  451.  
  452.  
  453. GetFileDirectory:
  454.   'transmit "'crlf||crlf'Enter file spec [CR=*]:"'
  455.   'receive CR255 180 ECHO'
  456.   r = FixRmtInp(rc)
  457.   if length(r) = 0 then r = '*'
  458.   Files.  = ''
  459.   Files.0 = 0
  460.   call SysFileTree r, 'Files'
  461.   'transmit "'Files.0' files found:'crlf'"'
  462.   do i = 1 to Files.0
  463.     'transmit "'Files.i||crlf'"'
  464.   end
  465.   'transmit "'crlf'Press ENTER:"'
  466.   'receive CR255 180 NOECHO'
  467.   return
  468.  
  469.  
  470.  
  471. SendFile:
  472.   parse arg XferType
  473.   select
  474.     when XferType = 'X' then XferType = 'xmodem'
  475.     when XferType = '1' then XferType = 'xmodem1k'
  476.     when XferType = 'Y' then XferType = 'ymodem'
  477.     when XferType = 'G' then XferType = 'ymodemg'
  478.     when XferType = 'Z' then XferType = 'zmodem'
  479.     otherwise nop
  480.   end
  481.  
  482.   'transmit "'crlf||crlf'Enter file spec:"'
  483.   'receive CR255 180 ECHO'
  484.   r = FixRmtInp(rc)
  485.   if length(r) > 0 then
  486.     do
  487.       fspec = r
  488.       r = stream(fspec, 'C', 'query exists')
  489.       if length(r) > 0 then
  490.         do
  491.           'transmit "'crlf'Start your 'XferType' receive...'
  492.           'upload' XferType fspec
  493.           /*
  494.           if rc \= 0 then
  495.             'transmit "ERROR starting' XferType' file transfer."'
  496.           else
  497.             'waitxfer'
  498.           */
  499.           'sleep 2'
  500.           'waitxfer'
  501.         end
  502.       else
  503.         'transmit "'crlf'ERROR: 'fspec' not found!'crlf'"'
  504.  
  505.       'transmit "Press ENTER:"'
  506.       'receive CR255 180 NOECHO'
  507.     end
  508.   return
  509.  
  510.  
  511.  
  512. GetFile:
  513.   parse arg XferType
  514.   select
  515.     when XferType = 'X' then XferType = 'xmodem'
  516.     when XferType = '1' then XferType = 'xmodem1k'
  517.     when XferType = 'Y' then XferType = 'ymodem'
  518.     when XferType = 'G' then XferType = 'ymodemg'
  519.     when XferType = 'Z' then XferType = 'zmodem'
  520.     otherwise nop
  521.   end
  522.  
  523.   if XferType = 'xmodem' | XferType = 'xmodem1k' then
  524.     do
  525.       'transmit "'crlf||crlf'Enter file name:"'
  526.       'receive CR255 180 ECHO'
  527.       r = FixRmtInp(rc)
  528.     end
  529.   else
  530.     r = 'automatic'
  531.  
  532.   if length(r) > 0 then
  533.     do
  534.       'transmit "'crlf'Start your 'XferType' upload...'
  535.       'download' XferType r
  536.       'sleep 2'
  537.       'waitxfer'
  538.       'transmit "Press ENTER:"'
  539.       'receive CR255 180 NOECHO'
  540.     end
  541.  
  542.   return
  543.  
  544.  
  545.  
  546. FixRmtInp:
  547.   parse arg friRC
  548.   friRC = strip(friRC, 'B', D2C(13))
  549.   friRC = strip(friRC, 'B', D2C(10))
  550.   friRC = strip(friRC, 'B', D2C(13))
  551.   friRC = strip(friRC, 'B', D2C(10))
  552.   return friRC
  553.  
  554.  
  555.  
  556. ReceiveFax:
  557.   'execwait' FaxPgm '-n7,'||DevHandle
  558.   return
  559.  
  560.  
  561. syntax:
  562.   syxRC = rc
  563.   msgbox.Text  = 'rc    =' syxRC||D2C(10)||,
  564.                  'line# =' sigl||D2C(10)||,
  565.                  'line  = ['sourceline(sigl)']'
  566.   msgbox.Title = 'Syntax Error!'
  567.   msgbox.Style = X2D('4046') /* MB_MOVEABLE|MB_CRITICAL|MB_CANCEL */
  568.   'messageboxv msgbox'
  569.   exit 1
  570.