Metropoli BBS
VIEWER: rexxhost MODE: TEXT (CP437)
/* REXX */

	/* 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= '\'
	guestdrive= ''
	guestdir= 'script\guest\'
	superpass= '"secret"'
	guestpass= '"guest"'

	/* ask for passwords */
	ASK '"Supervisor password"' superpass
	if(zocresult()="##CANCEL##") then
	do
		write "REXXHOST cancelled^M^J^M^J"
		exit
	end
	else
		superpass= zocresult()
	ASK '"Guest password"' guestpass
	if(zocresult()="##CANCEL##") then
	do
		write "REXXHOST cancelled^M^J^M^J"
		exit
	end
	else
		guestpass= zocresult()

	/* don't give other side an echo */
	SETHOST 0
	
	/* use a timeout of 60 for any input */
	TIMEOUT 60

	/* switch our modem into answer mode */
	WRITE '^[[2J^[[1H'
	SETAUTOANSWER 1
	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

	/* show welcome screen */
	CALL wsend '^[[2J^[[1H'
	CALL welcome
	CALL wsend '"Enter Password: "'

	WAIT '^M'
	pass= zoclastline()
	pass= STRIP(pass)

	IF pass= superpass THEN
		status= 'super'
	ELSE
	IF pass= guestpass THEN
	DO
		status= 'guest'
		curdrive= guestdrive
		curdir= guestdir
	END
	ELSE
	DO
		CALL wsend '^M^J^M^J'
		CALL wsend '"Sorry, authorization failed !"'
		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"'
		SIGNAL 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+0 '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+0 '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+0 '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'
	
	SAY curdrive||curdir
	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
	SETAUTOANSWER 0
	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 ]