Metropoli BBS
VIEWER: rexxhost.new MODE: TEXT (CP437)
/******************************************************************************\
 *                                                                            *
 *   REXXHost                                                                 *
 *                                                                            *
 *   IMPORTANT !!! Set ASC DELAY in options transfer to 0                     *
 *   IMPORTANT !!! Set CD Valid in options transfer ON                        *
 *   IMPORTANT !!! Create your own HOSTOPTS, if necessary                     *
 *                                                                            *
\******************************************************************************/

/* use this to debug script
TRACE A */

ADDRESS ZOC

/* clear screen */
WRITE '^[[2J^[[1H'

/* check, whether valid cd option is set */
IF zoccarrier() == 'N/A' THEN
DO
  WRITE '"Please enable CD Valid in OPTIONS SERIAL^M^J^M^J"'
  EXIT
END

/* set variables with default values - may be changed */
curdrive        = 'c:'
curdir          = '\'
max_tries       = 3                         /* max login tries               */
try_count       = 0                         /* tries                         */
user_count      = 0                         /* user count                    */
user_index      = 0                         /* login user (default: unknown) */
superuser_index = 1                         /* superuser (0 = no superuser)  */
done            = 0                         /* done = false                  */
loop_count      = 1                         /* loop count                    */
passwd_file     = 'Login.dat'               /* file in ZOC dir               */


Do While Lines(passwd_file)
  user_count = user_count + 1
  tmp              = LINEIN(passwd_file)    /* Comment                       */
  user.user_count  = LINEIN(passwd_file)    /* username                      */
  pass.user_count  = LINEIN(passwd_file)    /* password                      */
  drive.user_count = LINEIN(passwd_file)    /* working drive                 */
  dir.user_count   = LINEIN(passwd_file)    /* working dir                   */
End

/* if last user empty */
If User.User_Anz = ''
Then
Do
  user_count = user_count - 1
End


/* load HOSTOPTS, if available */  
LOADOPTS hostopts
DELAY 3

/* give the other side no echo */
SETHOST 0

/* use a timeout of 60 for any input */
TIMEOUT 60

/* switch our modem into answer mode */
WRITE '^[[2J^[[1H'
SEND 'ATS0=1^M^J'
WAIT 'OK'      /* wait for OK from modem */
DO WHILE rc <> 0
  WAIT 'OK'
END
WAIT '^M'
DELAY 1


/* -------------------------------------------------------------- */
/* wait for connect, set serial speed and check password          */
/* -------------------------------------------------------------- */
allover:

/* put infos on screen */
WRITE '^[[2J^[[1H'
WRITE '"Waiting for call ...^M^J^M^J"'


WAIT 'CONNECT'    /* wait for connect */
DO WHILE rc <> 0
  WAIT 'CONNECT'
END

WAIT '^M'

CALL wsend '^[[2J^[[1H'
CALL wsend '"Press BACKSPACE key to start host ...^M^J"'
WAIT '^H'

IF zoccarrier()=='NO CARRIER' | rc <> 0
THEN
  SIGNAL endit

try_count = 0

Do While try_count < max_tries
  try_count = try_count + 1

  /* show welcome screen */
  CALL wsend '^[[2J^[[1H'
  CALL welcome

  CALL wsend '"Enter Loginname: "'
  SETHOST 1
  WAIT '^M'
  SETHOST 0
  loginname= zoclastline()
  loginname= STRIP(loginname)

  CALL wsend '^M^J^M^J'
  CALL wsend '"Enter Password: "'
  WAIT '^M'
  password= zoclastline()
  password= STRIP(password)

  done       = 0
  loop_count = 1

  Do While done = 0
    If user.loop_count = loginname
    Then
    Do
      If pass.loop_count = password
      Then
      Do
        user_index = loop_count
        try_count  = max_tries
        done       = 1
      End
      Else
      Do
        done = 1
      End
    End

    loop_count = loop_count + 1

    If loop_count > user_count
    Then
    Do
      done = 1
    End
  End
End

If user_index <> 0
Then
Do
  curdrive = drive.user_index
  curdir   = dir.user_index

  If user_index = superuser_index
  Then
  Do
    status = 'super'
  End
  Else
  Do
    status = user.user_index
  End
End
Else
Do
  CALL wsend '^M^J^M^J'
  CALL wsend '"Sorry, authorization failed !^M^M"'
  SIGNAL endit
End


/* -------------------------------------------------------------- */
/* print a new menu and ask choice                                */
/* -------------------------------------------------------------- */
menu:

/* now give the other side an echo */
SETHOST 1
choice= ' '

CALL showmenu
CALL wsend '^[[0m'
CALL wsend '^[[19;12H'

IF status= 'super' THEN
  CALL wsend '"Your Choice (C/F/S/T/U/D/H/G): "'
ELSE
  CALL wsend '"Your Choice (F/T/U/D/G): "'


menuask:
WAIT '^M'

/* if the carrier was lost, restart the whole story */
IF zoccarrier()=='NO CARRIER' THEN SIGNAL endit

/* if input timed out redo input */
IF rc <> 0 THEN SIGNAL menuask

/* text cosmetics for user input string */
choice= zoclastline()
choice= STRIP(choice)

/* change directory */
IF (choice='C' | choice='c') & status= 'super' THEN CALL changedir

/* show files in directory */
IF choice='F' | choice='f' THEN CALL showdir ddir

/* search for entry */
IF (choice='S' | choice='s') & status= 'super' THEN CALL search

/* type file */
IF choice='T' | choice='t' THEN CALL type

/* zmodem upload */
IF choice='U' | choice='u' THEN CALL upload

/* zmodem download */
IF choice='D' | choice='d' THEN CALL download

/* shutdown host */
IF (choice='H' | choice='h') & status= 'super' THEN CALL shutdown

/* goodbye */
IF choice='G' | choice='g' THEN
DO
  CALL wsend '^[[21;12H'
  CALL wsend '"Have a nice day ...^M^J"'
  CALL endit
END

SIGNAL menu


endit:

/* give the other side no echo */
SETHOST 0
HANGUP
DELAY 5
SIGNAL allover



/* ============================================================== */
/* SUBROUTINES                                                    */
/* ============================================================== */

/* -------------------------------------------------------------- */
/* change current directory                                       */
/* -------------------------------------------------------------- */
changedir:

CALL wsend '^[[21;12H'
CALL wsend '"Enter full directory path: "'
WAIT '^M'

IF rc= 0 THEN
DO
  curdir= zoclastline()
  IF RIGHT(curdir, 1) \= '\' THEN curdir= curdir'\'
  IF SUBSTR(curdir, 2, 1) = ':' THEN
  DO
  curdrive= SUBSTR(curdir, 1, 2)
  curdir= RIGHT(curdir, length(curdir)-2)
  END
  IF SUBSTR(curdir, 1, 1) \= '\' THEN curdir= '\'curdir
END

RETURN


/* -------------------------------------------------------------- */
/* show current directory                                         */
/* -------------------------------------------------------------- */
showdir: 
ADDRESS CMD '"dir 'curdrive||curdir' >shellout.tmp"'
CALL wsend '^[[2J^[[1H'
UPLOAD a1 'shellout.tmp' 
ADDRESS CMD 'del shellout.tmp'
CALL wsend '^M^J'
CALL wsend '"Press Enter to return..."'
WAIT '^M'
RETURN


/* -------------------------------------------------------------- */
/* search on current drive                                        */
/* -------------------------------------------------------------- */
search: 
CALL wsend '^[[21;12H'
CALL wsend '"Enter filename to search on drive 'curdrive' "'
WAIT '^M'

IF rc= 0 THEN
DO
  sname= zoclastline()
  sname= STRIP(sname)
END
ELSE
  RETURN

CALL wsend '^[[22;12H'
CALL wsend '"Searching on drive 'curdrive', please wait ..."'
ADDRESS CMD '"dir 'curdrive'\'sname' /s >shellout.tmp"'
CALL wsend '^[[2J^[[1H'
UPLOAD a1 'shellout.tmp' 
ADDRESS CMD 'del shellout.tmp'
CALL wsend '^M^J'
CALL wsend '"Press Enter to return..."'
WAIT '^M'
RETURN


/* -------------------------------------------------------------- */
/* type file                                                      */
/* -------------------------------------------------------------- */
type: 
CALL wsend '^[[21;12H'
CALL wsend '"Enter filename to type: 'curdrive||curdir'"'
WAIT '^M'

IF rc= 0 THEN
DO
  sname= zoclastline()
  sname= STRIP(sname)
END
ELSE
  RETURN

ADDRESS CMD '"type 'curdrive||curdir||sname' >shellout.tmp"'
CALL wsend '^[[2J^[[1H'
UPLOAD a1 'shellout.tmp' 
ADDRESS CMD 'del shellout.tmp'
CALL wsend '^M^J'
CALL wsend '"Press Enter to return..."'
WAIT '^M'
RETURN


/* -------------------------------------------------------------- */
/* upload file                                                    */
/* -------------------------------------------------------------- */
upload:
CALL wsend '^[[21;12H'
CALL wsend '"Please start your Zmodem upload"'
CALL wsend '^[[22;12H'

DOWNLOAD z curdrive||curdir 
RETURN


/* -------------------------------------------------------------- */
/* download file                                                  */
/* -------------------------------------------------------------- */
download:
CALL wsend '^[[21;12H'
CALL wsend '"Enter filename to receive: 'curdrive||curdir'"'
WAIT '^M'
CALL wsend '^[[22;12H'

IF rc= 0 THEN
DO
  file= zoclastline()
  file= STRIP(file)
END
ELSE
  RETURN

IF file \= '' THEN
  UPLOAD z curdrive||curdir||file
RETURN


/* -------------------------------------------------------------- */
/* Shutdown host                                                  */
/* -------------------------------------------------------------- */
shutdown:
CALL wsend '^[[21;12H'
CALL wsend '"Hostmode will be quit now ...^M^J"'
SETHOST 0
HANGUP
DELAY 5
SEND 'ATS0=0^M^J'
EXIT


/* ============================================================== */
/* HELP-FUNCTIONS */
/* ============================================================== */

/* -------------------------------------------------------------- */
/* draw one menu-point with ARG(line, col, shortcut, name)        */
/* -------------------------------------------------------------- */
menupoint:

CALL wsend '"^[['ARG(1)';'ARG(2)'H"'
CALL wsend '"^[[1;37;47m┌───^[[0;30;47m┐"'
CALL wsend '"^[[1;37m┌────────────────────^[[0;30;47m┐^[[40m"'

CALL wsend '"^[['ARG(1)+1';'ARG(2)'H"'
CALL wsend '"^[[1;37;47m│ ^[[0;34;47m'ARG(3)' ^[[30m│"'
CALL wsend '"^[[1;37m│^[[0;30;47m'ARG(4)'│^[[40m"'

CALL wsend '"^[['ARG(1)+2';'ARG(2)'H"'
CALL wsend '"^[[1;37;47m└^[[0;30;47m───┘"'
CALL wsend '"^[[1;37m└^[[0;30;47m────────────────────┘^[[40m"'

RETURN


/* -------------------------------------------------------------- */
/* draw one info-point with ARG(line, col, text)                  */
/* -------------------------------------------------------------- */
infopoint:

CALL wsend '"^[['ARG(1)';'ARG(2)'H"'
CALL wsend '"^[[1;37;47m┌──────────────────────────────────"'
CALL wsend '"──────────────────────────^[[0;30;47m┐"'

CALL wsend '"^[['ARG(1)+1';'ARG(2)'H"'
CALL wsend '"^[[1;37;47m│ ^[[0;30;47m'ARG(3)' ^[[30m│"'

CALL wsend '"^[['ARG(1)+2';'ARG(2)'H"'
CALL wsend '"^[[1;37;47m└^[[0;30;47m────────────────────────"'
CALL wsend '"────────────────────────────────────┘"'

RETURN


/* -------------------------------------------------------------- */
/* draw the whole menu with alle menu- and info-points            */
/* -------------------------------------------------------------- */
showmenu:
CALL wsend '"^[[2J^[[1H"'

IF status= 'super' THEN
DO
  CALL menupoint 2,  10, 'C', ' (C)hange directory '
  CALL menupoint 5,  10, 'F', ' Show dir (F)iles   ' 
  CALL menupoint 8,  10, 'S', ' (S)earch a file    '
  CALL menupoint 11, 10, 'T', ' (T)ype a file      ' 
  CALL menupoint 2,  45, 'U', ' (U)pload a file    '
  CALL menupoint 5,  45, 'D', ' (D)ownload a file  '
  CALL menupoint 8,  45, 'H', ' Shutdown (H)ost    '
  CALL menupoint 11, 45, 'G', ' (G)oodbye          '
 END
ELSE
DO
  CALL menupoint 3,  10, 'F', ' Show dir (F)iles   ' 
  CALL menupoint 6,  10, 'T', ' (T)ype a file      ' 
  CALL menupoint 3,  45, 'U', ' (U)pload a file    '
  CALL menupoint 6,  45, 'D', ' (D)ownload a file  '
  CALL menupoint 10, 27, 'G', ' (G)oodbye          '
END

curpath= curdrive||curdir
CALL infopoint 15, 10, '^[[0;34;47mCurrent Dir:^[[30m  'overlay(curpath,'                                            ')
RETURN


/* -------------------------------------------------------------- */
/* draw beginning text                                            */
/* -------------------------------------------------------------- */
welcome:
CALL wsend '"                 ^M^J"'
CALL wsend '" ___  ___ ___    ^M^J"'
CALL wsend '"|__ || _ | __|   ^M^J"'
CALL wsend '" / /_||_|| |_     ZOC RexxHost-Script V1.0^M^J"'
CALL wsend '"|____|___|___|   ^M^J^M^J^M^J"'

RETURN


/* -------------------------------------------------------------- */
/* send and write at the same time                                */
/* -------------------------------------------------------------- */
wsend:

SEND ARG(1)
WRITE ARG(1)

RETURN



/* END OF REXX-MODULE */


[ RETURN TO DIRECTORY ]