home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / DOS / telemate.ARJ / HOST.EXE / HOST.SCR < prev    next >
Encoding:
Text File  |  1995-06-14  |  20.8 KB  |  743 lines

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