home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / comm / ca24_1.zip / BBS&HOST.ZIP / HOST-SRC.CMD < prev    next >
OS/2 REXX Batch file  |  1989-02-23  |  13KB  |  531 lines

  1.     ASSIGN S0 "****"        ; This is the logon password we'll use
  2.     ASSIGN S3 "xxxx"        ; This is the DOS password we'll use
  3. ;    trace on        ; Debugging
  4. ;
  5. ; ----- COM-AND Scripted host mode ----------------------------------
  6. ;
  7. ;    Goals:
  8. ;    o    Must autodetect caller's baud rate
  9. ;    o    Must work correctly for modems reporting true CD and otherwise.
  10. ;    o    Must log all activity
  11. ;
  12. ;    Functions:
  13. ;    o    Passworded log-on
  14. ;    o    DIR of current directory
  15. ;    o    CHDIR command
  16. ;    o    UP and DOWNLOADS
  17. ;    o    Graphical path display (using P/D TREED program)
  18. ;    o    Passworded DOS access (dangerous!)
  19. ;
  20. ;    Commenced: 10/29/87 R.McG
  21. ;    Updated:    2/--/89 R.McG
  22. ;    --------------------------------------------------------------
  23. ;    Initialize
  24. ;
  25.     LEGEND "Scripted host mode.  Press ESC to exit, and then hangup."
  26.     SET BAUD 1200
  27.     SET PARITY NONE
  28.     SET DATA 8
  29.     SET STOP 1
  30.     SET PORT COM2
  31.     SET ALARM OFF            ; Turn off alarm
  32.     SET ATIME 1            ; Set alarm time to 1 second
  33.     SET ASCII UP_LF LF        ; Send LFs
  34.     TRANSMIT "~~~+++~~~ATZ^M"       ; Initialize modem
  35.     SET MASK ON            ; Set 7-bit masking
  36.     LOG MARK ON            ; Timestamp logging
  37.     SUBDIR S2            ; Save starting subdir
  38.     CLOG "* Host script loaded"
  39.     GOTO Restart            ; Branch around subroutines
  40. ;
  41. ;    Subroutine: Read from the caller into S9
  42. ;    .. This handles 'disconnect' and timeouts.
  43. ;
  44. Read_Comm:
  45.     RGET S9 80 180        ; wait for a connection
  46.     IF NOT CONNECTED    ; If modem reports CD dropped
  47.        GOTO Disconnect    ; Goto disconnect
  48.        ENDIF
  49.  
  50.     IF NOT SUCCESS        ; If timeout on the RGET
  51.        GOTO Timeout     ; .. issue message and disconnect
  52.     ENDIF
  53.  
  54.     FIND S9 "NO CARRIER"    ; Test for message from modem
  55.     IF FOUND        ; If modem didn't report 'CD' true
  56.        GOTO Disconnect    ; Goto disconnect
  57.        ENDIF
  58.  
  59.     SET FLAG(0) OFF     ; Report to caller
  60.     RETURN            ; Return with text in S9
  61. ;
  62. ;    Timeout on the call
  63. ;
  64. Timeout:
  65.     TRAN "^M^J... autodisconnect due to timeout"
  66.     MESSAGE "^M^J... autodisconnect due to timeout"
  67.     GOTO RComm_Exit     ; Exit cycle in the usual manner
  68. ;
  69. ;    Disconnect was reported.
  70. ;
  71. Disconnect:
  72.     MESSAGE  "^M^JCaller disconnected"
  73. ;
  74. ;    Read_Comm error exit
  75. ;
  76. RComm_Exit:
  77.     SET FLAG(0) ON        ; Report to caller
  78.     RETURN            ; Return to the caller
  79. ;
  80. ;    Usages:
  81. ;      S0 -> main password
  82. ;      S1 -> ID
  83. ;      S2 -> Default drive/subdir
  84. ;      S3 -> DOS password
  85. ;      S8 -> File name buffer
  86. ;      S9 -> General read buffer
  87. ;
  88. ;    Begin the sequence...
  89. ;
  90. Restart:
  91.     CHDIR S2        ; Reset to default drive
  92.     SET RECHO OFF        ; Turn off echo for us
  93.     CLEAR            ; Clear screen
  94.     LOCATE 0,0        ; Set to home
  95. ;
  96. ;    Go into auto answer (echo off, answer on 3rd)
  97. ;    Also: Return result codes, word form, with CONNECT 1200
  98. ;
  99. ;
  100.     MESSAGE "^M^JWaiting..."
  101.     Pause 3         ; Wait 3 seconds
  102.     HANGUP            ; HANGUP and leave modem in cmd mode
  103.     PAUSE 3         ; Wait 3 secs
  104.     TRANSMIT "ATE0Q0V1X1S0=2 S7=30 S9=10^M"
  105. ;
  106. ;    Wait for a connect
  107. ;
  108. WAIT_IT_OUT:
  109.     RGET S9 80 180
  110.     IF NOT SUCCESS
  111.        GOTO Wait_IT_Out
  112.        ENDIF
  113.  
  114.     FIND S9 "NO CARRIER"
  115.     IF FOUND
  116.        GOTO Restart
  117.        ENDIF
  118.  
  119.     FIND S9 "CONNECT"
  120.     IF NOT FOUND
  121.        GOTO WAIT_IT_OUT
  122.        ENDIF
  123.  
  124. ;***    IF NOT CONNECTED
  125. ;***       GOTO Wait_IT_Out
  126. ;***       ENDIF
  127. ;
  128. ;    Connection established: Adjust our linespeed if need be
  129. ;
  130.     GOSUB AutoBaud        ; Change rate according to CONNECT MSG
  131. ;
  132. ;    Issue a greeting
  133. ;
  134.     TRAN "^M^JThe Flying Scotsman greets you!!"
  135.     SET RECHO ON        ; Turn on echo (back to caller)
  136.     LOG OPEN "HOSTLOG"
  137. ;
  138. ;    Request an ID
  139. ;
  140. ID_Query:
  141.     TRANSMIT "^M^JEnter your ID: "
  142.  
  143.     GOSUB Read_Comm     ; Read into S9
  144.     IF FLAG(0)        ; If first flag rtns set
  145.        GOTO Exit        ; .. disconnect and start over
  146.        ENDIF        ; ..
  147.  
  148.     SWITCH S9
  149.        CASE "_NULL"         ; Test for nothing entered
  150.           TRAN "You must be someone^M^J"
  151.           GOTO Exit     ; Don't let noone in
  152.       ENDCASE        ; End of ridicule
  153.     ENDSWITCH        ; End of ID test
  154.  
  155.     CLOG "* Host mode logon by "*S9
  156. ;
  157. ;    Request a password
  158. ;
  159.     TRANSMIT "^M^JEnter your password: "
  160.     LOG SUSPEND
  161.     SET RECHO OFF        ; Turn of echo of received text
  162.     SET RDISPLAY OFF    ; Turn off echo to console too
  163.  
  164.     GOSUB Read_Comm     ; Read into S9
  165.     IF FLAG(0)        ; If first flag rtns set
  166.        GOTO Exit        ; .. disconnect and start over
  167.        ENDIF        ; ..
  168.  
  169.     LOG RESUME        ; Restore logging
  170.     SET RECHO ON        ; Restore echo
  171.     SET RDISPLAY ON     ; Turn on echo to console again
  172. ;
  173. ;    Test for the main password
  174. ;
  175.     SWITCH S9
  176.        CASE S0        ; Test for match with S0
  177.           TRANSMIT "^M^J"   ; OK - good password
  178.        ENDCASE        ; End match with S0
  179.        DEFAULT        ; Not one of the above
  180.           TRANSMIT "Sorry , but you're not authorized."
  181.           GOTO Exit     ; And disconnect
  182.        ENDCASE        ; End of DEFAULT
  183.     ENDSWITCH
  184. ;
  185. ;    Now - do something
  186. ;
  187. Main_Prompt:
  188.     MESS "^M^JMain prompt"  ; Local console indicator
  189.     TRAN "^M^JC)hdir F)ilelist, P)athlist, U)pload, D)ownload, or E)xit: "
  190.  
  191.     GOSUB Read_Comm     ; Read into S9
  192.     IF FLAG(0)        ; If first flag rtns set
  193.        GOTO EXIT        ; .. disconnect and start over
  194.        ENDIF        ; ..
  195.  
  196.     SWITCH S9        ; Test the entry
  197.        CASE "C"
  198.           GOTO CHDIR
  199.        ENDCASE
  200.  
  201.        CASE "D"
  202.           GOTO DOWNLOAD
  203.        ENDCASE
  204.  
  205.        CASE "E"
  206.           TRAN "Ok... bye"
  207.           GOTO EXIT
  208.        ENDCASE
  209.  
  210.        CASE "F"
  211.           GOTO FILELIST
  212.        ENDCASE
  213.  
  214.        CASE "P"
  215.           GOTO PATHLIST
  216.        ENDCASE
  217.  
  218.        CASE "U"
  219.           GOTO UPLOAD
  220.        ENDCASE
  221.  
  222.        CASE "X"
  223.           GOTO DOS
  224.        ENDCASE
  225.  
  226.        CASE "OFF"
  227.           TRAN "Ok... bye"
  228.           GOTO EXIT
  229.        ENDCASE
  230.     ;
  231.     ;    Default case for typists
  232.     ;
  233.        DEFAULT
  234.           FIND S9 "CHDIR"   ; Try for larger
  235.           IF FOUND        ; If entry contained "CHDIR"
  236.          GOTO CHDIR
  237.          ENDIF
  238.  
  239.           FIND S9 "DOWN"    ; Try for larger
  240.           IF FOUND        ; If entry contained 'Down"
  241.          GOTO DOWNLOAD
  242.          ENDIF
  243.  
  244.           FIND S9 "FILE"    ; Try for larger
  245.           IF FOUND        ; If entry contained 'FILE"
  246.          GOTO FILELIST
  247.          ENDIF
  248.  
  249.           FIND S9 "PATH"    ; Try for larger
  250.           IF FOUND        ; If entry contained 'PATH"
  251.          GOTO PATHLIST
  252.          ENDIF
  253.  
  254.           FIND S9 "UP"      ; Try for larger
  255.           IF FOUND        ; If entry contained 'up"
  256.          GOTO UPLOAD
  257.          ENDIF
  258.  
  259.           FIND S9 "DOS"     ; Try for larger
  260.           IF FOUND        ; If entry contained 'DOS"
  261.          GOTO DOS
  262.          ENDIF
  263.  
  264.           TRAN "^M^JCommand not recognized... try again"
  265.           GOTO Main_Prompt    ; If none of the above
  266.        ENDCASE        ; End of DEFAULT
  267.     ENDSWITCH
  268. ;
  269. ;    Can't get here because of the DEFAULT in the SWITCH above
  270. ;
  271.     TRAN "^M^JThank you veddy much.^M^J"
  272.     GOTO Main_Prompt
  273. ;
  274. ;    General exit routine - don't GOTO from within a subroutine!!!
  275. ;
  276. EXIT:
  277.     CLOG "* Host mode exit"
  278.     LOG CLOSE        ; Turn off logging
  279.     MESS "^G"               ; Beep to indicate completion
  280.     GOTO Restart        ; And start over
  281. ;
  282. ;    Subroutine: Query for a file name - return in S8
  283. ;
  284. File_Query:
  285.     MESS "^M^JFname query"  ; Local console indicator
  286.     TRAN "^M^JEnter the file name: "
  287.  
  288.     GOSUB Read_Comm     ; Read into S9
  289.     IF FLAG(0)        ; If first flag rtns set
  290.        RETURN        ; .. disconnect and start over
  291.        ENDIF        ; ..
  292.  
  293.     ASSIGN S8 S9        ; Move fname into another variable
  294.     SWITCH S8
  295.        CASE "_NULL"         ; Test for nothing entered
  296.           SET FLAG(1) ON    ; Report to caller
  297.           RETURN        ; Return right here w/ flag set
  298.        ENDCASE
  299.     ENDSWITCH        ; End of ID test
  300.  
  301.     SET FLAG(1) OFF     ; Report to caller
  302.     RETURN            ; Return to caller
  303. ;
  304. ;    XMODEM Upload (up from caller)
  305. ;
  306. UPLOAD:
  307.     MESS "^M^JUpload from caller"
  308.  
  309.     GOSUB File_Query    ; Ask for a file name
  310.     IF FLAG(0)        ; If first flag rtns set
  311.        GOTO EXIT        ; .. disconnect and start over
  312.        ENDIF        ; ..
  313.  
  314.     IF FLAG(1)        ; If no file returned
  315.        GOTO Main_Prompt    ; .. start over
  316.        ENDIF        ; ..
  317.  
  318.  
  319.     ISFILE S8        ; Test for file already
  320.     IF SUCCESS        ; If file exists
  321.        TRAN "^M^JFile already exists"
  322.        GOTO UPLOAD        ; Ask again
  323.        ENDIF
  324.  
  325.     MESS "^M^JMethod prompt"; Local console indicator
  326.     TRAN "^M^JW)xmodem, X)modem, Y)modem, or K)ermit: "
  327.  
  328.     GOSUB Read_Comm     ; Read into S9
  329.     IF FLAG(0)        ; If first flag rtns set
  330.        GOTO Main_Prompt    ; .. disconnect and start over
  331.        ENDIF        ; ..
  332.  
  333.     SWITCH S9        ; Test the entry
  334.        CASE "W"
  335.           GETFILE WXMODEM S8
  336.        ENDCASE
  337.        CASE "X"
  338.           GETFILE XMODEM S8
  339.        ENDCASE
  340.        CASE "Y"
  341.           GETFILE YMODEM S8
  342.        ENDCASE
  343.        CASE "K"
  344.           GETFILE KERMIT    ; FIle name supplied by caller
  345.        ENDCASE
  346.        DEFAULT
  347.           TRAN "^M^JInvalid transfer selection"
  348.           GOTO Main_Prompt
  349.        ENDCASE
  350.     ENDSWITCH
  351.  
  352.     GOTO EOTransfer         ; Report success/failure
  353. ;
  354. ;    XMODEM Download (down to caller)
  355. ;
  356. DOWNLOAD:
  357.     MESS "^M^JDownload to caller"
  358.  
  359.     GOSUB File_Query    ; Ask for a file name
  360.     IF FLAG(0)        ; If first flag rtns set
  361.        GOTO EXIT        ; .. disconnect and start over
  362.        ENDIF        ; ..
  363.  
  364.     IF FLAG(1)        ; If no file returned,
  365.        GOTO Main_Prompt    ; .. start over
  366.        ENDIF        ; ..
  367.  
  368.     ISFILE S8        ; Test for file already
  369.     IF NOT SUCCESS        ; If file doesn't exist
  370.        TRAN "^M^JFile doesn't exist"
  371.        GOTO DOWNLOAD    ; Ask again
  372.        ENDIF
  373.  
  374.     MESS "^M^JMethod prompt"
  375.     TRAN "^MW)xmodem, X)modem, Y)modem, K)ermit, or A)scii: "
  376.  
  377.     GOSUB Read_Comm     ; Read into S9
  378.     IF FLAG(0)        ; If first flag rtns set
  379.        GOTO Main_Prompt    ; .. disconnect and start over
  380.        ENDIF        ; ..
  381.  
  382.     SWITCH S9        ; Test the entry
  383.        CASE "A"
  384.           SENDFILE ASCII S8
  385.        ENDCASE
  386.        CASE "W"
  387.           SENDFILE WXMODEM S8
  388.        ENDCASE
  389.        CASE "X"
  390.           SENDFILE XMODEM S8
  391.        ENDCASE
  392.        CASE "Y"
  393.           SENDFILE YMODEM S8
  394.        ENDCASE
  395.        CASE "K"
  396.           SENDFILE KERMIT S8
  397.        ENDCASE
  398.        DEFAULT
  399.           TRAN "^M^JInvalid transfer selection"
  400.           GOTO Main_Prompt
  401.        ENDCASE
  402.     ENDSWITCH
  403.  
  404.     GOTO EOTransfer         ; Report success/failure
  405. ;
  406. ;    End of transfer... note result on local console
  407. ;
  408. EOTRANSFER:
  409.     IF NOT SUCCESS
  410.        MESS "^M^JTransfer failed"
  411.     ELSE
  412.        MESS "^M^JTransfer OK"
  413.        ENDIF
  414.     GOTO Main_Prompt
  415. ;
  416. ;    Filelist... awkward... but it works
  417. ;
  418. FILELIST:
  419.     MESS "^M^JFilelist command"     ; Local console indicator
  420.     TRAN "^M^J Working..."          ; May take a moment
  421.  
  422.     DOS "DIR >HOSTTEMP.TXT"         ; To a temp file
  423.     TRAN "^M^J"                     ; Send a c/r
  424.     SENDFILE ASCII "HOSTTEMP.TXT"
  425.     TRAN "^M^J"                     ; Send a c/r
  426.  
  427.     DOS "DEL HOSTTEMP.TXT"          ; Clean up after us
  428.     GOTO Main_Prompt        ; And continue
  429. ;
  430. ;    CHDIR... Query for a path.
  431. ;
  432. CHDIR:
  433.     MESS "^M^JCHDIR Command"        ; Local console indicator
  434.     TRAN "^M^JEnter the drive:subdirectory: "
  435.  
  436.     GOSUB Read_Comm     ; Read into S9
  437.     IF FLAG(0)        ; If first flag rtns set
  438.        GOTO Main_Prompt    ; .. disconnect and start over
  439.        ENDIF        ; ..
  440.  
  441.     CHDIR S9        ; Do it.
  442.     GOTO Main_Prompt    ; And continue
  443. ;
  444. ;    Path tree... awkward... but it works
  445. ;
  446. PATHLIST:
  447.     MESS "^M^JPathlist command" ; Local console indicator
  448.     TRAN "^M^J Working..."  ; May take a moment
  449.  
  450.     DOS "Treed >HOSTTEMP.TXT" ; To a temp file
  451.     TRAN "^M^J"             ; Send a c/r
  452.     SENDFILE ASCII "HOSTTEMP.TXT"
  453.     TRAN "^M^J"             ; Send a c/r
  454.  
  455.     DOS "DEL HOSTTEMP.TXT"  ; Clean up after us
  456.     GOTO Main_Prompt    ; And continue
  457. ;
  458. ;    DOS command: Request a password
  459. ;
  460. DOS:
  461.     MESSAGE "^M^JRequesting DOS password"
  462.     LOG SUSPEND        ; Turn off logging
  463.     SET RECHO OFF        ; .. and don't echo passsword
  464.     SET RDISPLAY OFF    ; Turn off echo to console too
  465.  
  466.     TRANSMIT "^M^JEnter the DOS password: "
  467.  
  468.     GOSUB Read_Comm     ; Read into S9
  469.     IF FLAG(0)        ; If first flag rtns set
  470.        GOTO Main_Prompt    ; .. disconnect and start over
  471.        ENDIF        ; ..
  472.  
  473.     LOG RESUME        ; Turn on logging again
  474.     SET RECHO ON        ; .. and begin echoing again
  475.     SET RDISPLAY ON     ; Turn on echo to console again
  476. ;
  477. ;    Test for the our password
  478. ;
  479.     SWITCH S9
  480.        CASE S3        ; Test for match with S3
  481.           TRANSMIT "^M^J"   ; OK - good password
  482.        ENDCASE        ; End match with S3
  483.        DEFAULT        ; Not one of the above
  484.           TRANSMIT "Sorry , but you're not authorized."
  485.           GOTO Main_Prompt    ; And continue
  486.        ENDCASE        ; End of DEFAULT
  487.     ENDSWITCH
  488.     LOG RESUME
  489. ;
  490. ;    DOS... Query for a command
  491. ;
  492.     MESS "^M^JDOS Command"  ; Local console indicator
  493.     TRAN "^M^JEnter the command: "
  494.  
  495.     GOSUB Read_Comm     ; Read into S9
  496.     IF FLAG(0)        ; If first flag rtns set
  497.        GOTO Main_Prompt    ; .. disconnect and start over
  498.        ENDIF        ; ..
  499.  
  500.     TRAN "^M^J Working..."  ; May take a moment
  501.  
  502.     CONCAT S9 ">HOSTTEMP.TXT"
  503.     DOS   S9        ; Do it.
  504.  
  505.     TRAN "^M^J"             ; Send a c/r
  506.     SENDFILE ASCII "HOSTTEMP.TXT"
  507.     TRAN "^M^J"             ; Send a c/r
  508.  
  509.     DOS "DEL HOSTTEMP.TXT"  ; Clean up after us
  510.     GOTO Main_Prompt    ; And continue
  511. ;
  512. ;    Auto baudrate detect (according to message in S9)
  513. ;
  514. AutoBaud:
  515.     FIND S9 "1200"          ; Test for 1200 baud
  516.     IF FOUND        ; IF found
  517.        SET BAUD 1200    ; Set to 1200 baud
  518.        RETURN        ; We're done.
  519.        ENDIF
  520.  
  521.     FIND S9 "2400"          ; Test for 1400 baud
  522.     IF FOUND        ; IF found
  523.        SET BAUD 2400    ; Set to 1400 baud
  524.        RETURN        ; We're done.
  525.        ENDIF
  526. ;
  527. ;    None of the above... set to 300
  528. ;
  529.     SET BAUD 300        ; Set to 1200 baud
  530.     RETURN            ; We're done.
  531.