home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / comm / tm412_3.zip / HOST.EXE / HOST.SCR < prev    next >
Text File  |  1993-07-20  |  21KB  |  736 lines

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