home *** CD-ROM | disk | FTP | other *** search
/ The Best of the Best / _.img / 02172 / tele1.exe / HOST.EXE / HOST.SCR < prev    next >
Text File  |  1992-08-01  |  21KB  |  719 lines

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