home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tm400-3.zip / HOST.EXE / HOST.SCR < prev    next >
Text File  |  1993-01-01  |  21KB  |  725 lines

  1. ;
  2. ; HOST.SCR by White River Software, 1 January, 1993
  3. ;
  4.  
  5. ;
  6. ; constant
  7. ;
  8. TRUE = 1
  9. FALSE = 0
  10. FOREVER = TRUE
  11. FILEDIR = "\HOST.DIR"        ; temp. file for F)ile command
  12.  
  13. ;
  14. ; global variable
  15. ;
  16. integer local,userlevel,exist,xport
  17. string username,password,filename,ch,file
  18. integer NEWUSERLEVEL,SYSOPLEVEL,DETECTBAUD,INITIALBAUD,YELLTIME,YELLSOUND,CLOSESYSTEM
  19. string HOSTDIR,DOWNLOADDIR,UPLOADDIR
  20.  
  21. integer oldAlarmTime,oldAlarmSound,oldZAuto,oldZRecovery,oldBaud,oldConnection
  22. string oldDirUpload
  23.  
  24.    procedure StoreOptions
  25.    query alarmtime,oldAlarmTime
  26.    query alarmsound,oldAlarmSound
  27.    query dirupload,oldDirUpload
  28.    query zautodownload,oldZAuto
  29.    query zrecovery,oldZRecovery
  30.    query baud,oldBaud
  31.    query connection,oldConnection
  32.    endproc
  33.  
  34.    procedure RestoreOptions
  35.    set alarmtime,oldAlarmTime
  36.    set alarmsound,oldAlarmSound
  37.    set dirupload,oldDirUpload
  38.    set zautodownload,oldZAuto
  39.    set zrecovery,oldZRecovery
  40.    set baud,oldBaud
  41.    set connection,oldConnection
  42.    endproc
  43.  
  44.    procedure CheckDirectory string dir
  45.    integer l
  46.    string ch
  47.    length dir,l
  48.    if l>0
  49.       substr dir,l,1,ch
  50.       if ch<>"\" and ch<>":"
  51.          concat dir,"\"
  52.       endif
  53.    endif
  54.    endproc
  55.  
  56.    procedure HostConfig         ; read the configuration file
  57.    string s,ch                  ; HCONFIG.HST from the current directory
  58.    open "HCONFIG.HST"
  59.    if success
  60.       read s
  61.       atoi s,NEWUSERLEVEL       ; new user level
  62.       read s
  63.       atoi s,SYSOPLEVEL         ; sysop level
  64.       read s
  65.       atoi s,DETECTBAUD         ; detect baud rate
  66.       read s
  67.       atoi s,INITIALBAUD        ; initial baud rate
  68.       read s
  69.       atoi s,YELLTIME           ; yell time
  70.       read s
  71.       atoi s,YELLSOUND          ; yell sound
  72.       read HOSTDIR              ; directory containing H*.HST
  73.       read DOWNLOADDIR          ; download directory
  74.       read UPLOADDIR            ; upload directory
  75.       read s
  76.       atoi s,CLOSESYSTEM        ; open or close system
  77.       close
  78.       CheckDirectory HOSTDIR
  79.       CheckDirectory DOWNLOADDIR
  80.       CheckDirectory UPLOADDIR
  81.       set alarmtime,YELLTIME    ; setup yell alarm
  82.       set alarmsound,YELLSOUND
  83.       set dirupload,UPLOADDIR   ; setup upload directory
  84.    else
  85.       print "Cannot open HCONFIG.HST in the current directory"
  86.       print
  87.       print "Do you want to setup host mode (y/n)? ",
  88.       repeat
  89.          inputch ch
  90.       until success
  91.       if ch="y"
  92.          print ch
  93.          RestoreOptions
  94.          script "HCONFIG"       ; chain to HCONFIG.SCR
  95.       else
  96.          print "n"              ; abort host mode
  97.          print "Host mode aborted"
  98.          stop
  99.       endif
  100.    endif
  101.    endproc
  102.  
  103.    procedure HostBegin
  104.    set zautodownload,off
  105.    set zrecovery,off
  106.    set baud,INITIALBAUD
  107.    clear key                            ; clear keyboard buffer
  108.    clear com                            ; clear com buffer
  109.    clear text
  110.    print
  111.    print "Initializing modem"
  112.    put "^)",                            ; send modem answer string
  113.    if connected
  114.       print "Carrier signal is high, trying to make it reflect the online status"
  115.       put "~AT&C1^M~",                  ; make carrier signal reflect online status
  116.       if connected
  117.          print "Carrier signal is still high, host mode may not work correctly"
  118.          print "Please check your modem manual for correct DIP switch setting"
  119.       else
  120.          print "Carrier signal is now correct"
  121.       endif
  122.       print
  123.    endif
  124.    put "~ATQ0E0X4^M~",                  ; disable responds from modem
  125.    print
  126.    print
  127.    print "Host mode, waiting for call"
  128.    print
  129.    print "Press 'L' for local mode, 'C' for configuration,"
  130.    print "      [Esc] to exit and [Alt-H] to terminate user."
  131.    print
  132.    clear key                            ; clear keyboard buffer
  133.    clear com                            ; clear com buffer
  134.    endproc
  135.  
  136.    procedure HostEnd
  137.    clear key                            ; clear keyboard buffer
  138.    clear com                            ; clear com buffer
  139.    print
  140.    print "Ending host mode"
  141.    put "^(","~",                        ; send modem init string
  142.    print
  143.    delete FILEDIR                       ; delete temp file
  144.    RestoreOptions
  145.    stop
  146.    endproc
  147.  
  148.    procedure Disconnect                 ; end session
  149.    delay 10
  150.    if not local
  151.       hangup
  152.    endif
  153.    set connection,modem
  154.    local = FALSE
  155.    endproc
  156.  
  157.    procedure Output string s
  158.    print s,
  159.    if not local
  160.       put s,
  161.    endif
  162.    endproc
  163.  
  164.    procedure InputChar string ch        ; input and display locally
  165.    repeat
  166.       if not local
  167.          getch ch
  168.       endif
  169.       if local or not success
  170.          inputch ch
  171.          if success
  172.             if ch = "^["
  173.                HostEnd                  ; abort by operator
  174.             endif
  175.             print ch,
  176.          endif
  177.       endif
  178.    until success or not connected
  179.    endproc
  180.  
  181.    procedure InputEcho string ch        ; input and echo to remote
  182.    InputChar ch
  183.    if not local
  184.       put ch,
  185.    endif
  186.    if ch = "^M"                         ; add line feed
  187.       Output "^J"
  188.    endif
  189.    endproc
  190.  
  191.    procedure DotEcho string ch          ; input and echo "." to remote
  192.    InputChar ch
  193.    if not local
  194.       if ch="^H" or ch="^M"
  195.          put ch,
  196.       else
  197.          put ".",                       ; echo with "."
  198.       endif
  199.    endif
  200.    if ch = "^M"                         ; add line feed
  201.       Output "^J"
  202.    endif
  203.    endproc
  204.  
  205.    procedure InputString string str     ; input a string
  206.    string ch
  207.    str = ""
  208.    repeat
  209.       InputEcho ch
  210.       if ch <> "^M"
  211.          if ch = "^H"
  212.             if str = ""
  213.                Output " "
  214.             else
  215.                Output " ^H"
  216.             endif
  217.          endif
  218.          concat str,ch
  219.       endif
  220.    until ch = "^M" or not connected
  221.    if str="" or not connected
  222.       success = FALSE
  223.    else
  224.       success = TRUE
  225.    endif
  226.    endproc
  227.  
  228.    procedure InputFilename string filename,dir
  229.    string name
  230.    integer pos
  231.    InputString name                     ; input a filename
  232.    repeat
  233.       strpos name,":",pos               ;  strip drive part
  234.       if pos>0
  235.          strdel name,1,pos
  236.       endif
  237.    until pos=0 or not connected
  238.    repeat
  239.       strpos name,"\",pos               ; strip directory part
  240.       if pos>0
  241.          strdel name,1,pos
  242.       endif
  243.    until pos=0 or not connected
  244.    if name="" or not connected
  245.       success = FALSE
  246.       filename = ""
  247.    else
  248.       success = TRUE
  249.       filename = dir
  250.       concat filename,"\"               ; concat <dir>
  251.       strpos filename,"\\",pos
  252.       if pos>0
  253.          strdel filename,pos,1          ; avoid root directory"
  254.       endif
  255.       concat filename,name
  256.    endif
  257.    endproc
  258.  
  259.    procedure InputPassword string password ; input password
  260.    password = ""
  261.    repeat
  262.       DotEcho ch
  263.       if ch <> "^M"
  264.          if ch = "^H"
  265.             if password = ""
  266.                Output " "
  267.             else
  268.                Output " ^H"
  269.             endif
  270.          endif
  271.          concat password,ch
  272.       endif
  273.    until ch = "^M" or not connected
  274.    if password="" or not connected
  275.       success = FALSE
  276.    else
  277.       success = TRUE
  278.    endif
  279.    endproc
  280.  
  281.    procedure CheckUser string username,password,integer level,valid
  282.    integer found,pos1,pos2
  283.    string record,name,pass,lev
  284.    strpos username,";",pos1     ; record format: "first last;password#level"
  285.    strpos username,"#",pos2
  286.    if pos1>0 or pos2>0
  287.       valid = FALSE
  288.       return
  289.    endif
  290.    strpos password,";",pos1     ; check password for invalid character
  291.    strpos password,"#",pos2     ;  prevent "#2" etc
  292.    if pos1>0 or pos2>0
  293.       valid = FALSE
  294.       return
  295.    endif
  296.    file = HOSTDIR
  297.    concat file,"HUSER.HST"
  298.    open file                    ; passwords in HUSER.HST
  299.    if not success
  300.       create file
  301.    endif
  302.    if not success
  303.       Output "System error, please call again later^M^J"
  304.       print "SYSOP: Cannot create HUSER.HST"
  305.       Disconnect
  306.       alarm "SYSOP: Cannot create HUSER.HST, disk full ?"
  307.       return
  308.    endif
  309.    found = FALSE
  310.    read record
  311.    while success and not found
  312.       strpos record,";",pos1    ; get fields from the record
  313.       strpos record,"#",pos2
  314.       if pos1>0 and pos2>0
  315.          substr record,1,pos1-1,name
  316.          substr record,pos1+1,pos2-pos1-1,pass
  317.          if name=username
  318.             found = TRUE
  319.             if pass=password
  320.                valid = TRUE
  321.                substr record,pos2+1,1,lev
  322.                atoi lev,level
  323.             else
  324.                valid = FALSE
  325.             endif
  326.          endif
  327.       endif
  328.       if not found
  329.          read record
  330.       endif
  331.    endwhile
  332.    if not found                 ; new users
  333.       if CLOSESYSTEM
  334.          valid = FALSE
  335.       else
  336.          seek -1                ; add user if open system
  337.          write username,";",password,"#",NEWUSERLEVEL
  338.          level = 1
  339.          valid = TRUE
  340.       endif
  341.    endif
  342.    close
  343.    endproc
  344.  
  345.    procedure Pause              ; request a key
  346.    string ch
  347.    Output "Press [Enter] to continue "
  348.    InputEcho ch
  349.    Output "^M^J"
  350.    if ch<>"^M"
  351.       Output "^M^J"
  352.    endif
  353.    endproc
  354.  
  355.    procedure TypeFile string filename,integer more
  356.    string ch                            ; display a file
  357.    integer i
  358.    i = 0
  359.    open filename
  360.    if not success
  361.       Output "File not found.^M^J"
  362.    else
  363.       while success
  364.          inputch ch
  365.          if success and ch = "^C"        ; operator break
  366.             clear com
  367.             Output "^M^J"
  368.             exit
  369.          endif
  370.          if not local
  371.             getch ch
  372.             if success and ch = "^C"     ; caller break
  373.                clear com
  374.                Output "^M^J"
  375.                exit
  376.             endif
  377.          endif
  378.  
  379.          read s                         ; display a line
  380.          Output s
  381.          Output "^M^J"
  382.  
  383.          i = i+1
  384.          if i = 22 and more             ; pause if <more> is TRUE
  385.             i = 0
  386.             Output "-- More --"
  387.             InputChar ch
  388.             if ch = "^C"
  389.                clear com
  390.                Output "^M^J"
  391.                exit
  392.             endif
  393.             Output "^M                    ^M"
  394.          endif
  395.       endwhile
  396.       close
  397.       if more
  398.          Pause
  399.       endif
  400.    endif
  401.    endproc
  402.  
  403.    procedure Directory string dir       ; display download directory
  404.    string cmd
  405.    cmd = "DIR "                         ; DIR
  406.    concat cmd,dir                       ; DIR \DOWNLOAD\
  407.    concat cmd,"*.* >"                   ; DIR \DOWNLOAD\*.* >
  408.    concat cmd,FILEDIR                   ; DIR \DOWNLOAD\*.* >\HOST.DIR
  409.    dos cmd                              ; shell to DOS
  410.    TypeFile FILEDIR,TRUE                ; display \HOST.DIR
  411.    endproc
  412.  
  413.    procedure FileTransfer string mode,protocol,filename
  414.    print "^M^JPlease start your transfer procedure or press Ctrl-X to abort^M^J"
  415.    delay 20
  416.    if mode = "r"
  417.       if filename=""                    ; receive batch files
  418.          receive protocol
  419.       else
  420.          receive protocol,filename      ; receive single file
  421.       endif
  422.    else
  423.       send protocol,filename            ; send multiple files
  424.    endif
  425.    if success
  426.       Output "File transfer completed^M^J"
  427.    else
  428.       Output "File transfer aborted^M^J"
  429.    endif
  430.    Pause
  431.    endproc
  432.  
  433.    procedure WaitForCall                ; wait for connected
  434.    integer i,len,valid,exist,baudrate
  435.    string file
  436.    set connection,modem
  437.    local = FALSE
  438.    xport = FALSE
  439.    while not connected                  ; wait for carrier signal
  440.       inputch ch                        ; sysop commands
  441.       if success
  442.          switch ch
  443.            case "^[":                   ; abort
  444.               HostEnd
  445.            case "L":                    ; local mode
  446.               set connection,computer   ; this will set connected = 1
  447.               local = TRUE
  448.            case "C":                    ; configuration
  449.               RestoreOptions
  450.               script "HCONFIG"          ; chain to HCONFIG.SCR
  451.          endswitch
  452.       endif
  453.    endwhile
  454.    if not local and DETECTBAUD
  455.       waitfor "CONNECT^M","CONNECT 1200","CONNECT 2400","CONNECT 9600","CONNECT 19200",10
  456.       if found
  457.          switch found
  458.             case 1: baudrate = 300
  459.             case 2: baudrate = 1200
  460.             case 3: baudrate = 2400
  461.             case 4: baudrate = 9600
  462.             case 5: baudrate = 19200
  463.          endswitch
  464.          set baud,baudrate
  465.          Output "Connected at "
  466.          if not local
  467.             put baudrate,"^M^J"
  468.          endif
  469.          print baudrate
  470.       endif
  471.    endif
  472.    Output "^M^J"
  473.    delay 5
  474.    clear com
  475.    delay 5
  476.    file = HOSTDIR
  477.    concat file,"HWELCOME.HST"
  478.    TypeFile file,FALSE                  ; display welcome message
  479.    i = 1
  480.    len = 0
  481.    username = ""                        ; enter name (at most 3 times)
  482.    while i<=3 and len<4 and connected
  483.       Output "Please enter your First and Last name: "
  484.       InputString username
  485.       i = i+1
  486.       length username,len               ; check the length of name
  487.       if len<4
  488.          Output "Name too short, please try again^M^J^M^J"
  489.       else
  490.          Output username
  491.          Output " [Y/n]? "
  492.          InputString ch
  493.          if ch="n"
  494.             len=0
  495.          endif
  496.       endif
  497.    endwhile
  498.    if len<4 and connected
  499.       Output "Goodbye^M^J"
  500.       Disconnect
  501.    else
  502.       i = 1
  503.       len = 0
  504.       password = ""                     ; enter password (at most 3 times)
  505.       while i<=3 and len<4 and connected
  506.          Output "Password: "
  507.          InputPassword password
  508.          i = i+1
  509.          length password,len            ; check the length of ot
  510.          if len<4
  511.             Output "Password too short, please try again^M^J^M^J"
  512.          endif
  513.       endwhile
  514.       if len>=4                         ; check password and get user level
  515.          CheckUser username,password,userlevel,valid
  516.       endif
  517.       if (len<4 or not valid) and connected
  518.          Output "Invalid password, access denied^M^J^M^J"
  519.          Disconnect
  520.       else
  521.          file = HOSTDIR
  522.          concat file,"HNOTICE.HST"
  523.          FileExist file,exist           ; display notice
  524.          if exist
  525.             Output "^M^J"
  526.             TypeFile file,TRUE
  527.          endif
  528.       endif
  529.    endif
  530.    endproc
  531.  
  532.    procedure ChatMode                   ; chat mode
  533.    integer x
  534.    string rch,lch
  535.    Output "^M^JChat mode begin:^M^J"
  536.    repeat
  537.       if not local
  538.          getch rch
  539.          if success
  540.             put rch,
  541.             if rch = "^M"
  542.                Output "^J"
  543.             endif
  544.             wherex x
  545.             if rch = " " and x > 65
  546.                Output "^M^J"
  547.             endif
  548.          endif
  549.       endif
  550.       inputch lch
  551.       if success and lch<>"^["          ; abort if sysop press [Esc]
  552.          Output lch
  553.          if lch = "^M"
  554.             Output "^J"
  555.          endif
  556.          wherex x
  557.          if lch = " " and x > 65
  558.             Output "^M^J"
  559.          endif
  560.       endif
  561.    until lch="^[" or not connected
  562.    Output "^M^JChat mode end.^M^J^M^J"
  563.    Pause
  564.    endproc
  565.  
  566.    procedure DoCommand                  ; do a command
  567.    if xport
  568.       Output "Command F,U,D,T,C,X,G,(S,R,Z): "  ; export mode
  569.    else
  570.       Output "^M^J^M^J"
  571.       file = HOSTDIR
  572.       concat file,"HMENU.HST"
  573.       TypeFile file,FALSE               ; display menu
  574.       Output "Command: "
  575.    endif
  576.    InputEcho ch
  577.    if ch<>"^M"
  578.       Output "^M^J"
  579.    endif
  580.    switch ch
  581.       case "F":                         ; file directory
  582.          Directory DOWNLOADDIR
  583.       case "T":                         ; type a file
  584.          Output "Enter filename: "
  585.          InputFilename filename,DOWNLOADDIR
  586.          if success
  587.             TypeFile filename,TRUE
  588.          endif
  589.       case "U":                         ; upload a file
  590.          Output "^M^J"
  591.          file = HOSTDIR
  592.          concat file,"HPROT.HST"
  593.          TypeFile file,FALSE
  594.          Output "Select protocol: "
  595.          InputEcho protocol
  596.          Output "^M^J"
  597.          if local
  598.             Output "Function not available in local mode^M^J"
  599.          else
  600.             switch protocol
  601.                case "X","R":
  602.                   Output "Enter filename: "
  603.                   InputFilename filename,""
  604.                   if success
  605.                      FileTransfer "r",protocol,filename
  606.                   endif
  607.                case "Z","S","T","M","Y","B","G":
  608.                   FileTransfer "r",protocol,""
  609.             endswitch
  610.          endif
  611.       case "D":                         ; download a file
  612.          Output "^M^J"
  613.          file = HOSTDIR
  614.          concat file,"HPROT.HST"
  615.          TypeFile file,FALSE
  616.          Output "Select protocol: "
  617.          InputEcho protocol
  618.          Output "^M^J"
  619.          if local
  620.             Output "Function not available in local mode^M^J"
  621.          else
  622.             switch protocol
  623.                case "X","Y","Z","S","T","M","R","B","G":
  624.                   Output "Enter filename: "
  625.                   InputFilename filename,DOWNLOADDIR
  626.                   if success
  627.                      FileTransfer "s",protocol,filename
  628.                   endif
  629.             endswitch
  630.          endif
  631.      case "C":                          ; yell
  632.          Output "Yelling Sysop, please wait ... ^M^J"
  633.          alarm "User is yelling ...^JPress [Enter] to accept, [Esc] to deny"
  634.          if success
  635.             print "^M^JSYSOP: press [Esc] to terminate chat mode"
  636.             ChatMode
  637.          else
  638.             Output "^M^JSorry, Sysop is not here^M^J"
  639.          endif
  640.       case "X":                         ; toggle export mode
  641.          xport = not xport
  642.       case "G":                         ; goodbye
  643.          file = HOSTDIR
  644.          concat file,"HGOODBYE.HST"
  645.          TypeFile file,FALSE
  646.          Disconnect
  647.  
  648.       case "S":                         ; shell to DOS
  649.          if userlevel<SYSOPLEVEL
  650.             Output "Sorry, this command is for Sysop only^M^J"
  651.          else
  652.             if local                    ; local mode shell to DOS
  653.                Output "Shelling to DOS ... ^M^J"
  654.                dos
  655.                Output "Return from DOS shell^M^J"
  656.             else
  657.                file = HOSTDIR
  658.                concat file,"HSHELL.BAT"
  659.                fileexist file,exist     ; check for HSHELL.BAT
  660.                if exist
  661.                   Output "Shelling to DOS ... ^M^J"
  662.                   dos file
  663.                   Output "Return from DOS shell^M^J"
  664.                else
  665.                   Output "SYSOP: Cannot find HSHELL.BAT^M^J"
  666.                endif
  667.             endif
  668.          endif
  669.       case "R":                         ; run remote program
  670.          if userlevel<SYSOPLEVEL
  671.             Output "Sorry, this command is for Sysop only^M^J"
  672.          else
  673.             file = HOSTDIR
  674.             if local                    ; run HLOCAL.BAT if local mode
  675.                concat file,"HLOCAL.BAT"
  676.                fileexist file,exist
  677.                if exist
  678.                   Output "Loading external program ... ^M^J"
  679.                   dos file
  680.                   Output "Return from external program^M^J"
  681.                else
  682.                   Output "SYSOP: Cannot find HLOCAL.BAT^M^J"
  683.                endif
  684.             else                        ; run HREMOTE.BAT if remote mode
  685.                concat file,"HREMOTE.BAT"
  686.                fileexist file,exist
  687.                if exist
  688.                   Output "Loading remote program ... ^M^J"
  689.                   dos file
  690.                   Output "Return from remote program^M^J"
  691.                else
  692.                   Output "SYSOP: Cannot find HREMOTE.BAT^M^J"
  693.                endif
  694.             endif
  695.          endif
  696.       case "Z":                         ; shut down host mode
  697.          if userlevel<SYSOPLEVEL
  698.             Output "Sorry, this command is for Sysop only^M^J"
  699.          else
  700.             Output "Are you sure [y/N]? "
  701.             InputString ch
  702.             if ch="y"
  703.                Output "Shutting down host mode^M^J"
  704.                Disconnect
  705.                HostEnd
  706.             endif
  707.          endif
  708.    endswitch
  709.    endproc
  710.  
  711. ;
  712. ; begin main program
  713. ;
  714. StoreOptions
  715. HostConfig              ; read configuration file HCONFIG.HST
  716. while FOREVER
  717.    HostBegin            ; initial mode
  718.    WaitForCall          ; wait for a call
  719.    while connected
  720.       DoCommand         ; do commands
  721.    endwhile
  722. endwhile
  723.  
  724.  
  725.