home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac_os2 / zoc195.zip / INSTALL.FIL / SCRIPT / HOSTS / KF_HOST < prev    next >
Text File  |  1994-08-07  |  39KB  |  804 lines

  1. ##############################################################################
  2. # This script is a small host.                                               #
  3. # It connects to incoming calls and allows to perform certain functions      #
  4. # according to the level of authorisation.                                   #
  5. # Ideas of Mike Nowostawsky's Script HOSTZOC2 are used.                      #
  6. #                                                                            #
  7. # 'nnnnnnnn' in the following text stands for the name of the phone book     #
  8. # entry calling this script. If the script was called directly then          #
  9. # 'nnnnnnnn' is substituted by 'KF_HOST' (held in variable SCRIPTNAME).      #
  10. # Unless using HPSF, nnnnnnnn should not exceed 8 characters.                #
  11. #                                                                            #
  12. # USED FILES AND THEIR NAMES                                                 #
  13. # --------------------------                                                 #
  14. # - Script file:                                                             #
  15. #   SCRIPT\KF_HOST                                                           #
  16. # - Password files:                                                          #
  17. #   SCRIPT\nnnnnnnn.PSW                                                      #
  18. #   File SCRIPT\KF_HOSTX.PSW is delivered with this script as a start.       #
  19. # - Option files:                                                            #
  20. #   OPTIONS\nnnnnnnn.STD is in use while waiting for incoming calls.         #
  21. #   OPTIONS\nnnnnnnn.CON is in use while being connected to remote.          #
  22. #   Files OPTIONS\KF_HOSTX.STD and OPTIONS\KF_HOSTX.CON are delivered with   #
  23. #   this script as a start.                                                  #
  24. # - Log file:                                                                #
  25. #   The name of the log file is taken from the phone book entry.             #
  26. #   If the script was called directly or was not specified in the phone      #
  27. #   entry, then the name of the log file is defaulted to 'KF_HOST.LOG'.      #
  28. #                                                                            #
  29. # FUNCTIONS AND LEVEL OF AUTHORIZATION:                                      #
  30. # -------------------------------------                                      #
  31. # There are two levels of authorisation.                                     #
  32. # Normal level of authorisation allows following functions:                  #
  33. # - Download of files from the host directory (default "D:\ZocD\HostDir\").  #
  34. # - Upload to host \ZocD\Download                                            #
  35. # - List of files in current directory in host.                              #
  36. # - Send message to host.                                                    #
  37. # Extended level of authorisation allows following additional functions:     #
  38. # - Changing of the host directory                                           #
  39. # - List of dirs in current directory in host.                               #
  40. # Wether extended functions are allowed or not is determined by the password.#
  41. # Passwords are held in ASCII file SCRIPT\nnnnnnnn.PSW.                      #
  42. # One password is represented by one line. The format of passwords is as     #
  43. # follows:                                                                   #
  44. #   e password                                                               #
  45. #   ┬ ───┬────                                                               #
  46. #   │    └────── Password. Passwords are case sensitive.                     #
  47. #   └─────────── 1 if Password authorizes for extended functions (else 0)    #
  48. # The delivered password file SCRIPT\KF_HOSTX.PSW has the following two      #
  49. # lines.                                                                     #
  50. #         0 KF_HOST                                                          #
  51. #         1 KF_HOSTEXT                                                       #
  52. #                                                                            #
  53. # COMMANDS WHICH CAN BE PERFORMED BY THIS SCRIPT:                            #
  54. # -----------------------------------------------                            #
  55. #    CD   alias  C = Change Dirctory                                         #
  56. #    DIR  alias  D = File-List of Current Directory                          #
  57. #    DIRD alias DD = Dir-List  of Current Directory                          #
  58. #    UL            = UpLoad   (Remote: ZModem UpLoad, Host ZModem DownLoad)  #
  59. #    DL            = DownLoad (Remote: ZModem DownLoad, Host ZModem UpLoad)  #
  60. #                    Wild cards in filespec are allowed.                     #
  61. #    >mmmmmmmm     = Send Message mmmmm to Host                              #
  62. #    >>mmmmmmmm    = Ring Bell at Host and Send Message mmmmm to Host        #
  63. #    Exit alias  E = Hangup                                                  #
  64. #    Help alias  ? = Help                                                    #
  65. #                                                                            #
  66. #  DEAFULT VARIABLES                                                         #
  67. #  -----------------                                                         #
  68. #  See                                                                       #
  69. #      ###################......########                                     #
  70. #      #  Set defaults                 #                                     #
  71. #      #################......##########                                     #
  72. #  in this script.                                                           #
  73. #                                                                            #
  74. ##############################################################################
  75.  
  76. ##############################################################################
  77. #                                                                            #
  78. #                                   SETUP                                    #
  79. #                                                                            #
  80. #  Two option files are used by this script. The names of this option files  #
  81. #  are held in the variables HOSTWAIT and HOSTECHO.                          #
  82. #  HOSTWAIT is active while waiting for an incoming call                     #
  83. #  HOSTCONN is active while being connected with the caller                  #
  84. #     HOSTWAIT is defaulted to OPTIONS\Standard                              #
  85. #     HOSTCONN is defaulted to OPTIONS\HostConn                              #
  86. #                                                                            #
  87. #  The file OPTIONS\HostConn should be set as follows:                       #
  88. #     - Load option file Standard                                            #
  89. #     - Make sure the following items are set:                               #
  90. #        - SERIAL:   RTS/CTS handshake (*ON* - check mark)                   #
  91. #        - TERMINAL: Incoming CR to CR/LF (*ON* - check mark)                #
  92. #                    Local echo (half duplex) (*ON* - check mark)            #
  93. #                    Send echo (host mode) (*ON* - check mark)               #
  94. #        - TRANSFER: ASCII Upload: CR -> CR/LF (*ON* - check mark)           #
  95. #                    char delay = 0 (faster ASCII up- and download           #
  96. #                    ZModem Options: Autotransfer.                           #
  97. #                    File Exists:    Overwrite.                              #
  98. #                    Warning: Existing files in Host \ZocD\DOWNLOAD will     #
  99. #                             be overwritten on file transfer from remote.   #
  100. #        - MODEM:    Empty the Initialisation string and turn off the two    #
  101. #                    associated checkmarks                                   #
  102. #                                                                            #
  103. #     - Save the options as HostConn                                         #
  104. #                                                                            #
  105. ##############################################################################
  106. :Start
  107.    ###########################################################################
  108.    #  Set defaults                                                           #
  109.    ###########################################################################
  110.    SetA  SCRIPTNAME    "KF_HOST"          ;#the name of this script
  111.    SetA  PHONEBOOKORG  "%lastline%" |BOX= ;#extract phonebook entry
  112.    SetA  PHONEBOOKNAME "%PHONEBOOKORG%"
  113.    SetA  LOGFILE       "%lastline%" |LOG= ;#extract name of logfile
  114.    ################# Set defaults to %SCRIPTNAME% if needed ##################
  115.    CompA "%PHONEBOOKORG%" with ""
  116.    IfEqu SetA PHONEBOOKNAME "%SCRIPTNAME%"
  117.    CompA "%LOGFILE%" with ""
  118.    IfEqu SetA LOGFILE "%SCRIPTNAME%.LOG"
  119.    ######################## Set names of option files ########################
  120.    SetA  HOSTWAIT      "OPTIONS\%PHONEBOOKNAME%.Std"
  121.    SetA  HOSTCONN      "OPTIONS\%PHONEBOOKNAME%.Con"
  122.    ########################## Set names of log file ##########################
  123.    Seta  PASSWORDFILE  "Script\%PHONEBOOKNAME%.PSW" ;#name of file with passwords
  124.    SetA  CURDIR        "D:\ZocD\HostDir\"  ;#default host directory for sending
  125.  
  126.    ################ NUMOFRINGS, WAITTIME, TEMPFILE, VERSION. #################
  127.    SetA  NUMOFRINGS    "3"
  128.    SetN  WAITTIME      "10"
  129.    SetA  TEMPFILE       "KF_HOST.TMP"
  130.    SetA  VERSION        "1.10"
  131.  
  132.    ###########################################################################
  133.    #  Start logging and write start messages                                 #
  134.    ###########################################################################
  135.    LogName "%LOGFILE%"
  136.    Logging 1
  137.    Writeln "*************************************************************************"
  138.    Writeln "Script >%SCRIPTNAME%< Version %VERSION% started."
  139.    Writeln "Following items are in use:"
  140.    Writeln "PhonebookEntry:  %PHONEBOOKORG%"
  141.    Writeln "PasswordFile:    %PASSWORDFILE%"
  142.    Writeln "OptionFiles:     OPTIONS\%PHONEBOOKNAME%.Std and OPTIONS\%PHONEBOOKNAME%.Con"
  143.    Writeln "LogFile:         %LOGFILE%"
  144.    Writeln "Number of rings: %NUMOFRINGS%"
  145.    Writeln "*************************************************************************"
  146.    ###########################################################################
  147.    #  Set case sensitive compare.                                            #
  148.    ###########################################################################
  149.    Exact   1
  150.    ###########################################################################
  151.    #  This is the Main loop                                                  #
  152.    ###########################################################################
  153.    :Main
  154.       Timeout %WAITTIME%
  155.       ########################################################################
  156.       #  Prepare for Wait                                                    #
  157.       ########################################################################
  158.       Call WaitSetup
  159.       ########################################################################
  160.       #  Wait for connect                                                    #
  161.       ########################################################################
  162.       Writeln "******* Waiting for call...."
  163.       :ConWait
  164.          Wait   "CONNECT"
  165.          IfBrk  Goto ConWait
  166.          Call   CheckModem
  167.          CompN  %modem% with 1
  168.          IfnEqu Goto ConWait
  169.          Wait   "^M"
  170.          IfBrk  Goto Main         ;#should not occur
  171.          Call   CheckModem
  172.          CompN  %modem% with 0
  173.          IfnEqu Goto Main         ;#should not occur
  174.       :ConWaitEnd
  175.       ########################################################################
  176.       #  Send 'Hit Enter... message and wait for Enter.                      #
  177.       #  This is to drain evtl. garbage characters.                          #
  178.       ########################################################################
  179.       delay  3                    ;#delay to give remote a chance to look
  180.       send   "^[[2J"              ;#clear screen on remote/caller side
  181.       send   "^MHit Enter key to start host..."
  182.       :ConWaitEnter
  183.          wait   "^M"               ;#wait for Enter to clear garbage characters
  184.          IfBrk  Goto ConWaitEnter
  185.          Call   CheckModem         ;#check for drop conditions
  186.          CompN  %modem% with 1
  187.          IfHigh Goto Main          ;#unexpected, da capo
  188.       :ConWaitEnterEnd
  189.  
  190.       ########################################################################
  191.       #  Send welcome message and ask for password                           #
  192.       ########################################################################
  193.       Send  "^M Welcome !!  Enter Password: "
  194.       :ConWaitPasswWait
  195.          WaitLine
  196.          IfBrk  Goto ConWaitPasswWait
  197.          Call   CheckModem         ;#check for drop conditions
  198.          CompN  %modem% with 1
  199.          IfHigh Goto Main          ;#error, da capo
  200.       :ConWaitPasswWaitEnd
  201.       ########################################################################
  202.       #  Check password                                                      #
  203.       ########################################################################
  204.       Call   CheckPassWord
  205.       CompN  %passwordok% with 1
  206.       IfEqu  Goto ConWaitPasswCheckEnd   ;#password ok
  207.          #####################################################################
  208.          #  Wrong password                                                   #
  209.          #####################################################################
  210.          Send  "^M^J>>>>>> Sorry, not authorized... Bye! <<<<<<^M^J"
  211.          Goto  Main
  212.       :ConWaitPasswCheckEnd
  213.       Send     "Password ok^M^J"
  214.       Writeln  "******* Loading option file %HOSTCONN% for Connect..."
  215.       LoadOpts "%HOSTCONN%"
  216.       Delay    1
  217.       ########################################################################
  218.       # Process orders from remote. Stay in routine Connect till break.      #
  219.       ########################################################################
  220.       Call Connect
  221.       Goto Main      ;#all over again
  222.    :MainEnd
  223. exit
  224.  
  225. ##############################################################################
  226. #                                SUBROUTINES                                 #
  227. ##############################################################################
  228.  
  229.  
  230. ##############################################################################
  231. #                                 WaitSetup                                  #
  232. ##############################################################################
  233. :WaitSetup
  234.    Writeln  "******* Loading option file %HOSTWAIT% for Wait..."
  235.    LoadOpts "%HOSTWAIT%"
  236.    Delay  1
  237.    HangUp
  238.    Delay  1
  239.    LoadOpts "%HOSTWAIT%"
  240.    Delay  1
  241.    ###########################################################################
  242.    #  Set up for Auto Answer                                                 #
  243.    ###########################################################################
  244.    Send   "ATS0=%NUMOFRINGS%^M"
  245.    Delay  1
  246.    Compa  "%lastline%" with "OK"
  247.    IfEqu  Goto WaitSetupEnd
  248.       SetA desaster "Failure on ATS0. %lastline%"
  249.       Goto Desaster
  250.    :WaitSetupEnd
  251. return
  252.  
  253. ##############################################################################
  254. #                              CheckDirPresent                               #
  255. # Checks wether Dir in filename exist.                                       #
  256. # filenamesave gets the original filename                                    #
  257. # If exists: filename is left as it is. Else filename is set to ""           #
  258. ##############################################################################
  259. :CheckDirPresent
  260.    ###########################################################################
  261.    # Evtl. add trailing \                                                    #
  262.    ###########################################################################
  263.    SetA     backsl "%filename%" -1 1
  264.    CompA    "%backsl%" with "\"
  265.    IfnEqu   SetA filename "%filename%\"
  266.    SetA     filenamesave "%filename%"
  267.    Shell    "dir /ad %filename%*>%TEMPFILE%"  ;#create list of dir names
  268.    OpenFile "%TEMPFILE%" "r"
  269.    ###########################################################################
  270.    # Check wether '<DIR>' appears in one of the lines                        #
  271.    ###########################################################################
  272.    :CheckDirPresentLoop
  273.       GetFile
  274.       CompA   "%lastline%" with "##"          ;#Check for end
  275.       IfnIn   Goto CheckDirPresentLoop10
  276.          #####################################################################
  277.          # Directory does not exist. Clear file name                         #
  278.          #####################################################################
  279.          SetA filename ""
  280.          Goto CheckDirPresentLoopEnd
  281.       :CheckDirPresentLoop10
  282.       CompA "%lastline%" with "<DIR>"
  283.       IfnIn Goto CheckDirPresentLoop
  284.    :CheckDirPresentLoopEnd
  285.    CloseFile
  286.    Shell "del %TEMPFILE%"
  287. return
  288.  
  289. ##############################################################################
  290. #                                 CheckModem                                 #
  291. # Num Variable modem is set to the following values according to the         #
  292. # contents of the system variable lastline:                                  #
  293. #                                                                            #
  294. #     2 "NO CARRIER", "x...x+++x...x", "HANGUP" or "HANG UP",                #
  295. #       "BUSY", "NOANSWER" or "NO ANSWER",                                   #
  296. #       "NODIALTONE" or "NO DIALTONE", "SYSTEM SUSPENDED", "ERROR"           #
  297. #     1 "CONNECTx....x"                                                      #
  298. #     0 None of the above                                                    #
  299. #                                                                            #
  300. ##############################################################################
  301. :CheckModem
  302.    ######## Error conditions, 1 ########
  303.    SetN  modem 2
  304.    CompA "%lastline%" with "SYSTEM SUSPENDED"
  305.    IfEqu Goto CheckModemRet
  306.    CompA "%lastline%" with "ERROR"
  307.    IfEqu Goto CheckModemRet
  308.    CompA "%lastline%" with "NODIALTONE"
  309.    IfEqu Goto CheckModemRet
  310.    CompA "%lastline%" with "NO DIALTONE"
  311.    IfEqu Goto CheckModemRet
  312.    CompA "%lastline%" with "NOANSWER"
  313.    IfEqu Goto CheckModemRet
  314.    CompA "%lastline%" with "NO ANSWER"
  315.    IfEqu Goto CheckModemRet
  316.    CompA "%lastline%" with "BUSY"
  317.    IfEqu Goto CheckModemRet
  318.    CompA "%lastline%" with "HANGUP"
  319.    IfEqu Goto CheckModemRet
  320.    CompA "%lastline%" with "HANG UP"
  321.    IfEqu Goto CheckModemRet
  322.    CompA "%lastline%" with "+++"
  323.    IfIn  Goto CheckModemRet
  324.    CompA "%lastline%" with "NO CARRIER"
  325.    IfEqu Goto CheckModemRet
  326.    ######## "CONNECT", 1 ########
  327.    SetN  modem 1
  328.    SetA worka "%lastline%" +1 7
  329.    CompA "%worka%" with "CONNECT"
  330.    IfEqu Goto CheckModemRet
  331.    ######## None of the above, 0 ########
  332.    SetN  modem 0
  333. :CheckModemRet
  334. return
  335.  
  336. ##############################################################################
  337. #                                CheckResult                                 #
  338. # Num Variable result is set to the following values according to the        #
  339. # contents of the system variable lastline:                                  #
  340. #                                                                            #
  341. #              9 none of the following                                       #
  342. #              8 ##xx...x## and none of the following                        #
  343. #            7-3 unused                                                      #
  344. #              2 ##ERROR##                                                   #
  345. #              1 ##CANCEL##                                                  #
  346. #              0 ##OK##                                                      #
  347. #                                                                            #
  348. ##############################################################################
  349. :CheckResult
  350.    ######## ##OK##, 0 ########
  351.    SetN result 0
  352.    CompA "%lastline%" with "##OK##"
  353.    IfEqu Goto CheckResultRet
  354.    ######## ##ERROR##, 2 ########
  355.    SetN result 2
  356.    CompA "%lastline%" with ##ERROR##
  357.    IfEqu Goto CheckResultRet
  358.    ######## ##CANCEL##, 1 ########
  359.    SetN result 1
  360.    CompA "%lastline%" with ##CANCEL##
  361.    IfEqu Goto CheckResultRet
  362.    ######## ##xx...x##, 8 ########
  363.    SetN result 8
  364.    IfEqu Goto CheckResultRet
  365.    SetA worka "%lastline%" +1 2         ;##   ##x....
  366.    CompA "%worka%" with "##"
  367.    IfEqu Goto CheckResultRet
  368.    SetA worka "%lastline%" -1 2         ;##   ....x##
  369.    CompA "%worka%" with "##"
  370.    IfEqu Goto CheckResultRet
  371.    ######## None of the previous, 9 ########
  372.    SetN result 9
  373.    :CheckResultRet
  374. return
  375.  
  376. ##############################################################################
  377. #                                SendToRemote                                #
  378. # Send filename to remote                                                    #
  379. # Check for errors. Result is in modem                                       #
  380. # If no error detected, filecountok is incremented                           #
  381. # If    error detected, filecountnok is incremented                          #
  382. ##############################################################################
  383. :SendToRemote
  384.    Writeln "******* File '%filename%' being send to remote..."
  385.    UpLoad  z "%filename%"
  386.    ########################################################################
  387.    # Check Result.  For some reason ##ERROR## is not an Error, sometimes. #
  388.    ########################################################################
  389.    call    CheckResult
  390.    Writeln "******* File '%filename%' sent to remote. Result: %lastline%, %result%"
  391.  
  392.    ########################################################################
  393.    # The next 2 lines are for the bug (?) returning not ##OK##            #
  394.    # after upload failed once. Erase if bug(?) cleared                    #
  395.    ########################################################################
  396.    CompN   %result% with 2      ;#erase line when bug cleared
  397.    IfEqu   SetN result 0        ;#erase line when bug cleared
  398.  
  399.    CompN   %result% with 0
  400.    IfnEqu  Inc filecountnok
  401.    IfEqu   Inc filecountok
  402.    CompN   0 with 0                   ;#set EQUAL
  403. return
  404.  
  405. ##############################################################################
  406. #                                  Connect                                   #
  407. # Send Choice                                                                #
  408. #   if valid choice go to appropriate routine                                #
  409. #   if exit or break condition leave routine                                 #
  410. ##############################################################################
  411. :Connect
  412.    ###########################################################################
  413.    # Load Options for connected period                                       #
  414.    ###########################################################################
  415.    LoadOpts "%HOSTCONN%"
  416.    SetN connectmenu 1
  417.    SetN connectend  0
  418.    SetN msgreceived 0
  419.    :ConnectLoop
  420.       ########################################################################
  421.       # Stay in this loop till error or exit                                 #
  422.       ########################################################################
  423.       CompN  %msgreceived% with 0
  424.       IfEqu  Send "^M^J[%CURDIR%] Enter Your Choice or ?:^M"
  425.       CompN  %connectmenu% with 0
  426.       IfEqu  Goto ConnectMenuEnd
  427.          #####################################################################
  428.          # Send Menu to remote. Only done on first pass or when calling Help #
  429.          #####################################################################
  430.          Send "╔═════════════════════════════ Your choice ═════════════════════════════╗^M"
  431.          Send "║DIR,  D   = FileList of Host Dir   │DIRD, DD * = DirList of Host Dir   ║^M"
  432.          Send "║CD,   C * = Change Host Dir        │                                   ║^M"
  433.          Send "║>mmmmmmm  = Message mmmm to Host   │>>mmmmmmm  = Bell & Message to Host║^M"
  434.          Send "║UL        = Upload to Host         │DL         = Download from Host    ║^M"
  435.          Send "║EXIT, X   = Exit                   │HELP,  ?   = Help, this Info       ║^M"
  436.          Send "╚════════════════════ * only valid in extended mode ════════════════════╝^M"
  437.          SetA connectmenu 0
  438.       :ConnectMenuEnd
  439.       CompN   %msgreceived% with 0
  440.       IfEqu   Writeln "^M******* Waiting for order from remote..."
  441.       SetA choice " "
  442.       :ConnectLoopWait
  443.          WaitLine
  444.          IfBrk  Goto ConnectLoopWait
  445.       :ConnectLoopWaitEnd
  446.       Call   CheckModem                 ;#check for drop conditions
  447.       CompN  %modem% with 1
  448.       IfHigh Goto ConnectLoopEnd        ;#Error
  449.       ########################################################################
  450.       # Evaluate choice and perform function                                 #
  451.       ########################################################################
  452.       SetN  modem 0
  453.       SetA  choice "%lastline%"
  454.       Lower choice
  455.       Ltrim choice
  456.       Rtrim choice
  457.  
  458.       ########## >, >> = Message to host ##########
  459.       SetN  msgreceived 1
  460.       SetA  choicemsg "%choice%" +1 1
  461.       CompA "%choicemsg%" with ">"
  462.       IfEqu Goto ConnectMsg
  463.       SetN  msgreceived 0
  464.  
  465.       Writeln "******* Order received from remote: '%choice%'"
  466.  
  467.       ########## Help, ? = Help ##########
  468.       CompA "%choice%" with "?"
  469.       IfEqu Goto ConnectHelp
  470.       CompA "%choice%" with "help"
  471.       IfEqu Goto ConnectHelp
  472.  
  473.       ########## Exit, X = Exit ##########
  474.       CompA "%choice%" with "x"
  475.       IfEqu Goto ConnectExit
  476.       CompA "%choice%" with "exit"
  477.       IfEqu Goto ConnectExit
  478.  
  479.       ########## DL = Download from Host ##########
  480.       CompA "%choice%" with "dl"
  481.       IfEqu Goto ConnectDL
  482.  
  483.       ########## UL = Upload to Host ##########
  484.       CompA "%choice%" with "ul"
  485.       IfEqu Goto ConnectUL
  486.  
  487.       ########## DIR, D = File-List of Host Dir ##########
  488.       CompA "%choice%" with "d"
  489.       IfEqu Goto ConnectDir
  490.       CompA "%choice%" with "dir"
  491.       IfEqu Goto ConnectDir
  492.  
  493.       ########## DIRD, DD = Dir-List of Host Dir ##########
  494.       CompN %extendedfunc% with 0
  495.       IfEqu Goto ConnectLoopDirDEnd
  496.          CompA "%choice%" with "dd"
  497.          IfEqu Goto ConnectDirD
  498.          CompA "%choice%" with "dird"
  499.          IfEqu Goto ConnectDirD
  500.       :ConnectLoopDirDEnd
  501.  
  502.       ########## CD, C = Change Host Dir ##########
  503.       CompN %extendedfunc% with 0
  504.       IfEqu Goto ConnectLoopCdEnd
  505.          CompA "%choice%" with "c"
  506.          IfEqu Goto ConnectCD
  507.          CompA "%choice%" with "cd"
  508.          IfEqu Goto ConnectCD
  509.       :ConnectLoopCdEnd
  510.  
  511.       ########## DEBUG0 & DEBUG1 ##########
  512.       :ConnectDebug0
  513.       CompA  "%password%" with "KF_HOSTEXT"
  514.       IfnEqu  Goto ConnectDebugEnd
  515.       CompA  "%choice%" with "debug0"
  516.       IfnEqu  Goto ConnectDebug1
  517.          debug  0
  518.          Goto   ConnectLoop
  519.       :ConnectDebug1
  520.       CompA  "%choice%" with "debug1"
  521.       IfnEqu Goto ConnectDebugEnd
  522.          debug  1
  523.          Goto   ConnectLoop
  524.       :ConnectDebugEnd
  525.  
  526.       ########## ConnectInvalid ##########
  527.       :ConnectInvalid
  528.       Send  "^M    %choice% is not a valid choice.^M"
  529.       Goto  ConnectLoop
  530.  
  531.       ########################################################################
  532.       # Check completion                                                     #
  533.       ########################################################################
  534.       :ConnectCheck
  535.          CompN  %connectend% with 0
  536.          IfEqu  Goto ConnectLoop        ;#dont't exit
  537.       :ConnectCheckEnd
  538.    :ConnectLoopEnd
  539.    Goto ConnectEnd
  540.  
  541.    ###########################################################################
  542.    # Perform function according to choice                                    #
  543.    ###########################################################################
  544.    :ConnectHelp                                  ;#Help
  545.       SetN connectmenu 1
  546.    Goto ConnectLoop
  547.  
  548.    :ConnectExit                                  ;#Exit
  549.       Send  "^MThanks for calling. Bye! ^M^J"
  550.       Delay 2
  551.       SetN connectend 1
  552.    Goto  ConnectCheck
  553.  
  554.    :ConnectMsg                                   ;#> Send message
  555.       call Msg
  556.       IfnEqu SetN connectend 1
  557.    Goto  ConnectCheck
  558.  
  559.    :ConnectDL                                    ;#DownLoad
  560.       call DownLoad
  561.       IfnEqu SetN connectend 1
  562.    Goto  ConnectCheck
  563.  
  564.    :ConnectUL                                    ;#UpLoad
  565.       Call UpLoad
  566.       IfnEqu SetN connectend 1
  567.    Goto  ConnectCheck                                
  568.  
  569.    :ConnectDir                                   ;#Dir
  570.       Call Dir
  571.       IfnEqu SetN connectend 1
  572.    Goto  ConnectCheck
  573.  
  574.    :ConnectDirD                                  ;#DirD
  575.       Call DirD
  576.       IfnEqu SetN connectend 1
  577.    Goto  ConnectCheck
  578.  
  579.    :ConnectCD                                    ;#ChangeDir
  580.       Call ChangeDir
  581.       IfnEqu SetN connectend 1
  582.    Goto  ConnectCheck
  583.  
  584. :ConnectEnd
  585. return
  586.  
  587.  
  588. ##############################################################################
  589. #                                    Msg                                     #
  590. ##############################################################################
  591. :Msg
  592.    SetA    choicemsg "%choice%" +2 1
  593.    CompA   "%choicemsg%" with ">"
  594.    IfnEqu  Goto MsgNoBell
  595.       Writeln "******* Beep from remote"
  596.       BEEP    3
  597.       DELAY   1
  598.       BEEP    2
  599.       DELAY   1
  600.       BEEP    3
  601.    :MsgNoBell
  602.    CompN 0 with 0          ;#set EQAUL
  603. return
  604.  
  605. ##############################################################################
  606. #                                    Dir                                     #
  607. ##############################################################################
  608. :Dir
  609.    Shell  "dir %CURDIR%>%TEMPFILE%"
  610.    Send   "^J"
  611.    UpLoad a "%TEMPFILE%"        ;#Upload ASCII
  612.    Shell  "del %TEMPFILE%"      ;#Delete temp file
  613.    CompN  0 with 0                 ;#set EQUAL
  614. return
  615.  
  616. ##############################################################################
  617. #                                    DirD                                    #
  618. ##############################################################################
  619. :DirD
  620.    Shell  "dir /ad %CURDIR%>%TEMPFILE%"
  621.    Send   "^M"
  622.    UpLoad a "%TEMPFILE%"        ;#Upload ASCII
  623.    Shell  "del %TEMPFILE%"      ;#Delete temp file
  624.    CompN  0 with 0                 ;#set EQUAL
  625. return
  626.  
  627. ##############################################################################
  628. #                                 ChangeDir                                  #
  629. ##############################################################################
  630. :ChangeDir
  631.    Send "^MEnter directory (blank cancels): "
  632.    :ChangeDirLoop
  633.       ########################################################################
  634.       # Get name of directory from remote                                    #
  635.       ########################################################################
  636.       WaitLine
  637.       IfBrk  Goto ChangeDirLoop
  638.    :ChangeDirLoopEnd
  639.    Call   CheckModem                 ;#check for drop conditions
  640.    CompN  %modem% with 1
  641.    IfHigh Goto ChangeDirExit         ;#drop condition
  642.    ###########################################################################
  643.    # Test wether directory exits                                             #
  644.    ###########################################################################
  645.    SetA   filename     "%lastline%"
  646.    CompA  "%filename%" with " "
  647.    IfEqu  Goto ChangeDirRet
  648.    Ltrim  filename
  649.    Rtrim  filename
  650.    Lower  filename
  651.    Call   CheckDirPresent              ;#filename is "" if dir not present
  652.    CompA  "%filename%" with "%filenamesave%"
  653.    IfEqu  Goto ChangeDirOk
  654.       Send "^M Directory %filenamesave% does not exist.^M"
  655.       Goto ChangeDirRet
  656.    :ChangeDirOk
  657.       SetA CURDIR "%filename%"
  658.    :ChangeDirRet
  659.    CompN  0 with 0                   ;#set EQUAL condition
  660.    :ChangeDirExit
  661. return
  662.  
  663. ##############################################################################
  664. #                   DownLoad (from remote's point of view)                   #
  665. ##############################################################################
  666. :DownLoad
  667.    SetN filecountok  0
  668.    SetN filecountnok 0
  669.    Send "^M^J^JEnter space to Cancel -or- Filename, wild cards are welcome: "
  670.    :DownLoadNameLoop
  671.       ########################################################################
  672.       # Get name of file(s) from remote                                      #
  673.       ########################################################################
  674.       Waitline
  675.       IfBrk  Goto DownLoadNameLoop
  676.    :DownLoadNameLoopEnd
  677.    Call   CheckModem                  ;#check for drop, set result to modem
  678.    CompN  %modem% with 1
  679.    IfHigh Goto DownloadEnd            ;#drop condition
  680.    :DownLoadNameLoopEnd
  681.  
  682.    ###########################################################################
  683.    # Writeln file spec. Check for Cancel, first char is " "                  #
  684.    ###########################################################################
  685.    SetA filename "%lastline%"
  686.    Writeln "File spec: '%CURDIR%%filename%'"
  687.    SetA blank "%filename%" +1 1
  688.    CompA "%blank%" with " "
  689.    IfEqu Goto DownLoadExit
  690.    ###########################################################################
  691.    # Get single file or create filelist of all files if there are wildcards  #
  692.    ###########################################################################
  693.    CompA "%filename%" with "*"
  694.    IfIn  Goto DownLoadWild
  695.    CompA "%filename%" with "?"
  696.    IfIn  Goto DownLoadWild
  697.       ########################################################################
  698.       # No wild cards. test wether file exists                               #
  699.       ########################################################################
  700.       SetA      filename "%CURDIR%%filename%"
  701.       OpenFile  "%filename%" "r"
  702.       CompA     "%lastline%", "##OK##"
  703.       IfnEqu    Goto DownLoadExit
  704.       CloseFile
  705.       Call      SendToRemote
  706.       Goto      DownLoadExit
  707.    :DownLoadNoWildEnd
  708.  
  709.    ###########################################################################
  710.    # Create and Read List. Call upload (from here) for each file             #
  711.    ###########################################################################
  712.    :DownLoadWild
  713.    Shell    "dir %CURDIR%%filename%>%TEMPFILE%"
  714.    OpenFile "%TEMPFILE%" "r"
  715.    Compa    "%lastline%" with "##OK##"
  716.    IfnEqu    Goto DownLoadExit
  717.    :DownLoadFileLoop
  718.       GetFile
  719.       Seta   fileline "%lastline%"
  720.       CompA  "%fileline%" with "##"      ;#Eof etc.
  721.       IfIn   Goto DownLoadFileLoopEnd
  722.       Seta   filename "%fileline%" +3 1
  723.       CompA  "%filename%" with "."       ;#dot in 3rd position is candidate
  724.       IfnEqu Goto DownLoadFileLoop
  725.       CompA  "%fileline%" with "<DIR>"   ;#Directory
  726.       IfIn   Goto DownLoadFileLoop
  727.       ########################################################################
  728.       # Coming here must be a file name in 41th position. Do upload          #
  729.       ########################################################################
  730.       Seta   filename "%fileline%" +41
  731.       Seta   filename "%CURDIR%%filename%"
  732.       Call   SendToRemote
  733.       Goto   DownLoadFileLoop
  734.    :DownLoadFileLoopEnd
  735.    CloseFile
  736.    shell "del %TEMPFILE%"
  737.    :DownLoadExit
  738.    Writeln "Files send to remote: Ok=%filecountok%, NotOk=%filecountnok%"
  739.    Send    "Files from host: Ok=%filecountok%, NotOk=%filecountnok%"
  740.    :DownloadEnd0
  741.    CompN   0 with 0          ;#set EQUAL condition
  742. :DownloadEnd
  743. return
  744.  
  745. ##############################################################################
  746. #                    UpLoad (from remote's point of view)                    #
  747. ##############################################################################
  748. :UpLoad
  749.    Send "^MStart your Zmodem upload.^M"
  750.    Send "To cancel hit Cancel in your Upload-Box and press Ctrl/X several times."
  751.    :UpLoadLoop
  752.       download z "dummy"
  753.       call CheckResult                   ;#check for drop
  754.       Writeln "Download completed. Result: %lastline%, %result%"
  755.    :UpLoadRet
  756.    CompN 0 with 0                        ;#set EQUAL
  757. return
  758.  
  759. ##############################################################################
  760. #                               CheckPassWord                                #
  761. # Check password. If Ok return with 'passwordok' set to 1 (else 0).          #
  762. # If Password does allow extended functions set 'extendedfunc' to 1 (else 0).#
  763. #                                                                            #
  764. # Password are held in file name held in file scripvariable PASSWORDFILE.      #
  765. #   Format of passwords                                                      #
  766. #   epassword                                                                #
  767. #   ┬ ───┬───                                                                #
  768. #   │    └────── Password                                                    #
  769. #   └─────────── 1 if Password authorizes for extended functions (else 0)    #
  770. #                                                                            #
  771. ##############################################################################
  772. :CheckPassWord
  773.    SetN      extendedfunc 0
  774.    SetN      passwordok 0
  775.    SetA      passw "%lastline%"
  776.    Rtrim     passw
  777.    OpenFile  "%PASSWORDFILE%" "r"
  778.    CompA     "%lastline%" with ##OK##
  779.    IfnEqu    Goto CheckPassWordEnd
  780.    :CheckPassWordLoop
  781.       GetFile
  782.       SetA    filepassw "%lastline%"
  783.       CompA   "%filepassw%" with "##"
  784.       IfIn    Goto CheckPassWordLoopEnd
  785.       SetA    filepasse "%filepassw%" +1 1
  786.       SetA    filepassw "%filepassw%" +3
  787.       CompA   "%filepassw%" with "%passw%"
  788.       IfnEqu  Goto CheckPassWordLoop
  789.       SetN    passwordok 1
  790.       CompA   %filepasse% with 1
  791.       IfEqu   SetN extendedfunc 1
  792.    :CheckPassWordLoopEnd
  793.    CloseFile
  794. :CheckPassWordEnd
  795. return
  796.  
  797. ##############################################################################
  798. # Desaster exit                                                              #
  799. ##############################################################################
  800. :Desaster
  801.    Writeln "******** Catastrophic Error. Script terminated. Rc=>%desaster%< ********"
  802.  exit
  803.  
  804.