/*---------------------------------------------------------------------------*\
|   SET all PASSWORDS to a LAN Server 3.0 and higher                          |
|   from an ASCII File                                                        |
|                                 (C) Alain Rykaert IBM Belgium - SEP95-MAY96 |
\*---------------------------------------------------------------------------*/
    Parse Arg Option

    Call INIT                    /* Initialisation of DLL's and other stuff*/
    Call CHKOPT                          /* Check Options & display Welcome*/
    Call CHKPWS                               /* Check the PWS & Admin name*/
    Call MAIN                                            /* do the main job*/
    Call QUIT                                                       /* Quit*/

 MAIN:/* ------------------------------------------------------ MAIN: -------*/

    Call Time('R')
   'if exist' CHKF 'del' CHKF
    EC = 0

   'if not exist \\'SRVNAME'\IBMLAN$\NETPROG\PWDIMP.EXE copy PWDIMP.EXE \\'SRVNAME'\IBMLAN$\NETPROG'

    do while Lines(INPF)
       LLINE = LineIN(INPF)
       parse value LLINE with USERID ':' PASSWORD .
       if \MUTE
        then do
                Call SysCurState OFF
                Call SysCurPos 19,20
                say ESC'[K'
                Call SysCurPos 19,20
             end
        else Nop
       say 'UserID :' USERID
       Call LOGIT LLINE
      'net admin \\'SRVNAME '/C PWDIMP' LLINE '>>' LOGF
    end

    say '0909'x 'Total Time  =' Trunc(Time('E'),2)

    Return

 CHKOPT:/* ---------------------------------------------------- CHKOPT: -----*/

    SRVNAME = '';
    INPF = 'USERS.PWD';
    LOGF = 'PASSWORD.LOG';
    CHKF = 'USERS.CHK';
    PIPE = '';
    TRACE = 0;
    MUTE  = 0;

    OPTION = Translate(OPTION)
    do while OPTION <> ''
       Parse value OPTION with ARGUMENT ' ' OPTION
       select
        when Left(ARGUMENT,5) = '/SRV:' then SRVNAME = Substr(ARGUMENT,6)
        when Left(ARGUMENT,5) = '/INP:' then INPF    = Substr(ARGUMENT,6)
        when Left(ARGUMENT,5) = '/LOG:' then LOGF    = Substr(ARGUMENT,6)
        when Left(ARGUMENT,5) = '/CHK:' then CHKF    = Substr(ARGUMENT,6)
        when Left(ARGUMENT,5) = '/PIP:' then PIPE    = Substr(ARGUMENT,6)
        when Left(ARGUMENT,2) = '/M'    then MUTE    = 1
        when Left(ARGUMENT,2) = '/T'    then TRACE   = 1
        otherwise Nop
       end
    end

    if SRVNAME = '' then signal GETHELP

    if \MUTE
     then do
             Topic1='SETWELCOME'
             Topic_String.Topic1.1=SRVNAME;
             Topic_String.Topic1.2=INPF;
             Topic_String.Topic1.3=LOGF;
             Topic_String.Topic1.4=CHKF;
             Topic_String.Topic1.5=PIPE' ';
             Topic_List='WELCOMELOGO' Topic1 'SETPWD';
             Call GETANS
             Parse VALUE SysCurPos() With Old_R Old_C; '@pause'
             Call SysCurPos Old_R, Old_C; say ESC'[K'
          end
     else do
             say 'ServerName =' SRVNAME
             say 'InputFile  =' INPF
             say 'LogFile    =' LOGF
             say 'CheckFile  =' CHKF
            'pause'
          end

    Return

 CHKPWS:/* ---------------------------------------------------- CHKPWS: -----*/

    RC = NetGetInfo(350, 'WKSTAINFO','')
    if RC = 0
     then do
             ADMNAME = WKSTAINFO.UserName
             PWSNAME = WKSTAINFO.ComputerName
          end
     else do
            Call LOGIT 'Get PWS Info', ,RC
            Call Quit
          end
    Return

 INIT:/* ------------------------------------------------------ INIT: -------*/

    Call RgUtil   '/m'                                    /* Rexx Utilities*/
    Call RgUtils  '/m'                                    /* Rexx Utilities*/
    Call RgLSRXUT '/m'                             /* Lan Server Rexx Utils*/

    Parse Upper Source . . P_NAME
    PRGN = Filespec('N', Left(P_NAME, Length(P_NAME) -4))

   '@echo off'
    ESC   = '1B'x
    REDIR = '>NUL 2>NUL'

    Call CHKFILE 'PWDIMP.EXE'          /* External program of Steve Freeman*/

    Resource_File = 'LSMT.RSC'
    Call CHKFILE Resource_File

    Return

 GETANS:/* ---------------------------------------------------- GETANS: -----*/

    Vars_List =Ansi_Say(Resource_File Topic_List);
    Parse VALUE SysCurPos() With Old_R Old_C;
    Do While Vars_List <> '';
       Parse VALUE Vars_List With Topic_Id ';' Var_Id ';' Row ';' Column ';' Color ';' Vars_List;
       Call SysCurPos Row, Column;
       Say x2c(Color) || Topic_String.Topic_Id.Var_Id || '1B'x || '[0m';
       End;
    Call SysCurPos Old_R, Old_C;

    Return

 GETHELP:/* --------------------------------------------------- GETHELP: ----*/

    if \MUTE
     then do
             Topic1='SETHELP'
             Topic_String.Topic1.1=PRGN;
             Topic_List=Topic1;
             Call GETANS
          end
     else say 'Incorrect options.'

    Call QUIT

    Return

 CHKFILE:/* --------------------------------------------------- CHKFILE: ----*/

    Parse Arg FILE
    RC = Stream(FILE, 'C', 'QUERY EXIST')
    if RC = ''
     then do
             say ' File' FILE 'not found.'
             Call QUIT
          end
     else Nop
    Call Stream FILE, 'C', 'CLOSE'

    Return

 LOGIT:/* ----------------------------------------------------- LOGIT: ------*/

    Parse Arg LOGT
    if \MUTE
     then say ESC'[0;1;32m' LOGT ESC'[0m'
     else say LOGT
    LOGT = '('Date('E') Left(Time(),5) ADMNAME Substr(PWSNAME,3)')' LOGT
    Call LineOut LOGF, LOGT
    Call Stream  LOGF, 'C', 'CLOSE'

    if PIPE <> ''
     then do
             parse value RxNPOpen(PIPE) with RC HANDLE .
             if RC <> 0
              then Return
              else do
                      RC = RxNPWrite(HANDLE, LOGT)
                      if RC <> 0
                       then Return
                       else Call RxNPClose HANDLE
                   end
           end
     else Nop

    Return

 QUIT:/* ------------------------------------------------------ QUIT: -------*/

    Call LineOut 'LSMT.END', PRG, 1
    Call Stream  'LSMT.END', 'C', 'CLOSE'
    Call Stream   INPF,      'C', 'CLOSE'
    Call Stream   LOGF,      'C', 'CLOSE'
    Call Stream   CHKF,      'C', 'CLOSE'
    Exit

 /*--------------------------------------------------------------------------*/
