/**************************************************************************\
      $VER: ReVive DataBase Manager, v3.02 (5-Apr-97) by Dotoran!
\**************************************************************************/
options results;signal on SYNTAX;signal on ERROR;signal on IOERR;call IERROR
a=sourceline(2);parse var a . ", "ver" ("vdate")" .;tr=transmit;se=sendstring;gu=getuser
a="rexxsupport.library";if ~show("l",a) then if ~addlib(a,0,-30) then exit
parse source . . fp .;df=left(fp,max(lastpos('/',fp),lastpos(':',fp)))

changewhere "ReViveDBM"

mail=2          /* Should Users' Mail Directories be Backed Up as well?
                   (0=No, 1=Yes, during Logoff, 2=Yes, during AMaint)     */

kill=0          /* Should BackUp Mail Dir be KILLED, before Backing Up?
                   (0=No, Copy Over Existing Files, 1=Yes, Start Anew)    */

skip=""         /* ID's to SKIP backup of mail dirs. Parsed in SPACES     */

users2="DH0:ReVive/"   
                /* Path to create/store the "users2/" directory. This path
                   needs to END with either a slash (/) or a colon (:). It
                   is HIGHLY RECOMMENDED this location be on a different
                   PHYSICAL drive than that which houses your MAIL:USERS/
                   directory for maximum benefit of ReVival ability!      */

arg v1;zz="00"x;if v1=2 then signal AMAINT

if v1=1 then do;gu 2400088;acts=result
/**/;z=forbid()
    call open(f1,df"ReViveDB","r")
      total=strip(readch(f1,4),,zz)
    call close(f1)
    diff=0;if acts>total then diff=acts-total
    if diff>0 then do;logentry 'cbExpanded ReVive Database...q1'
      call open(f1,df"ReViveDB","a")
        call seek(f1,0,"b")
        call writech(f1,left(acts,4,zz))
        call seek(f1,0,"e")
        call writech(f1,left(zz,38*diff))
      call close(f1);end
    gu 40;id=result;in=((id*38)-38)+4
    call open(f1,df"ReViveDB","r");call seek(f1,in,"b")
      uid=translate(strip(readch(f1,4),,zz),reverse(bb),bb)
      han=translate(strip(readch(f1,20),,zz),reverse(bb),bb)
      pas=translate(strip(readch(f1,14),,zz),reverse(bb),bb)
    call close(f1);gu 41;sid=result;gu 1;handle=result
    gu 2;password=result;gu 39;mdir=result
    if sid~=uid|handle~=han|password~=pas then do
      logentry 'cbUpdated ReVive Database...q1'
      se "ceUpdating cbReVive cadatabasec6..."
      call open(f1,df"ReViveDB","r")
        call seek(f1,in,"b")
        z1=translate(sid,bb,reverse(bb))
        z2=translate(handle,bb,reverse(bb))
        z3=translate(password,bb,reverse(bb))
        z=left(z1,4,zz)left(z2,20,zz)left(z3,14,zz)
        call writech(f1,z)
      call close(f1);tr "cddonec6.";end
/**/;z=permit()
  if mail~=1|find(skip,id)>0 then exit
  logentry 'cbBacked Up UUCP MAIL Directory...q1'
  se "caBacking up c6mail directory..."
  if ~exists(users2"users2/"mdir) then tr "@4#4 makedir "users2"users2/"mdir"}"
  if kill=1 then se "@4#4 delete "users2"users2/"mdir"/#?}"
  tr "@4#4 copy mail:users/"mdir"/ "users2"users2/"mdir"/ all}"
  tr "cdcompletedc6!";exit;end

gu 2400088;acts=result;time=time('r')
tr "f1n2caCreating cbReVive cdDataBasecb: [scd0000 c6of ca"acts" c6Accounts."
/**/;z=forbid()
  call open(f1,df"ReViveDB","w");call writech(f1,left(acts,4,"00"x))
    do i=1 to acts;se "[ucd"right("cb"i,7,"0")
      loadscratch i;st=result;savescratch (-i)
      getscratch 1;z2=translate(result,bb,reverse(bb))
      getscratch 2;z3=translate(result,bb,reverse(bb))
      getscratch 41;z1=translate(result,bb,reverse(bb))
      call writech(f1,left(z1,4,zz)left(z2,20,zz)left(z3,14,zz))
    end i
  call close(f1)
/**/;z=permit()
tr "n1cdCompletedc6!n1";if mail=0 then exit
if ~exists(users2"users2/") then address command "makedir "users2"users2"
tr "caCreating cbReVive ceDuplicate UUCP Directoriesc6...c9n1"
address command "copy mail:users/ "users2"users2/ all"
tr "n1cdDone in "time('e')/60" minutes!";exit

AMAINT:;tr "@4n1Backing up user mail directories..."
  if ~exists(users2"users2/") then address command "makedir "users2"users2"
  if kill=1 then address command "delete "users2"users2/#? all"
  address command "copy mail:users/ "users2"users2/ all"
  tr "n1Done!";exit

IERROR:;bb="`~!@#$%^&*()_-+=|\abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ[]{};':"d2c(34)",./<>?";return
SYNTAX:;ERROR:;IOERR:;e1="n1 Error: "rc" ("errortext(rc)")";e2="  Line: "left(sigl,4)"File:";c="`"fp", "ver"'";e2=e2" "c;tr e1;tr e2
  logentry e1;logentry e2;e=strip(translate(sourceline(sigl),"\{",""));do while e~="";e3="Source: "left(e,37);tr e3;logentry e3;e=substr(e,38);end
  bufferflush
/**************************************************************************\
\****************************************** Frontiers BBS (716)/823-9892 **/
