Page 1 of 2 12>
Topic Options
#68787 - 2002-07-31 10:56 PM get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
I have a list of users account (net use /domain >user.txt) which I'm trying to get the password age for. If the age is greater than X days, send a SMTP message to the user to change their password. I have the concept down but can't seem to get the coding right. Kix4.02 NT4 enviroment.
Top
#68788 - 2002-07-31 11:36 PM Re: get @pwage from user list and send notification e-mail.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Search the BBS for BLAT the primary SMTP mailer used. Code would look like this:
code:
$maxpwage=10
IF @PWAGE>$maxpwage
; does a NET SEND
$rc=SENDMESSAGE(@USERID,'Change your password!')
SHELL 'blat.exe .....' ; fill in appropriatre switches/parameters
ENDIF

in your login script. If you need it for all users, you will have to use ADSI for this.

[ 31 July 2002, 23:36: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#68789 - 2002-08-01 12:00 AM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
Thanks for the response, that's only part of what I'm trying to accomplish. We have 2 domains (Primary and Secondary), users have accounts in both domains, they primarily login to the Primary and rarely the Secondary domain. I have a users account list for the Secondary domain which looks like this:
[LIST]
usera userb userc
userd userf etc...
[/LIST]
I want to get the password age for all accounts on the list; if account(s) is over X days, then send a e-mail to user's e-mail address (which is username@company.com)

Top
#68790 - 2002-08-01 12:33 AM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
for all at the same time or when they log on?
if only when they log on it's simple as getting the age of the primary domain.

anyway, instead of using blad, on exchange enabled network I would use me own smpt mailer script...
foundable somewhere in the forum...
_________________________
!

download KiXnet

Top
#68791 - 2002-08-01 01:11 AM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
I can't do it at login because users lock (for a long time) their workstations instead of logging off. I know how to get a list of users for the domain, but how do I use that list to check for password age and send e-mail??
user.txt:
usera userb userc
userd usere etc...


code:
 
$maxpwage=10
open users.txt
realine(1)
while $rc=0
extract usera from line1
If usera password > $maxpwage
send e-mail to usera
endif
readline(1)
loop


Top
#68792 - 2002-08-01 01:25 AM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I'm just releasing my improvisations...

there should be a way to do it remotely.
why I know is, I've done it.

I did it already with kix 3.53 wit help of net commands.
all you need with net commands is list of DCs on the net...

I did a script which deleted a user account which didn't logon in the given time frame and this can be done the same way.

also, if you run it from from your own wksta, you don't have to use mail!
you get list in whatever format you like.
_________________________
!

download KiXnet

Top
#68793 - 2002-08-01 01:35 AM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
Would you be so kind as to post or point in the direction of your code [Big Grin] ?
Top
#68794 - 2002-08-01 01:44 AM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jake,
surely I would but I'm at home.
that means at the most cases I'm at my linux-server.
anyway, I can search for thr specific backupCD but easier would be if you say what knowledge you lack, if any...
and I'll get you up to date.
_________________________
!

download KiXnet

Top
#68795 - 2002-08-01 03:07 AM Re: get @pwage from user list and send notification e-mail.
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
you will want to use ADSI for this....

here is something to get you sarted on the password age bit...

code:
$usernamefromfile = @userid

$user = getobject("WinNT://@domain/$usernamefromfile")
$temp = split($user.PasswordExpirationDate,"/")
$temp[2] = substr($temp[2],1,4)
if len($temp[0]) <> 2
$temp[0] = "0" + $temp[0]
endif
$expdate = $temp[2] + "/" + $temp[0] + "/" + $temp[1]


? "number of days until " + $user.name + " will expire is " + val(serialdate($expdate) - serialdate(@date)) + " (" + $user.PasswordExpirationDate + ")"

as for email... BLAT is a very good program, i am guessing that along with a list of user names you also have a list of email addresses?

Bryce

[ 01 August 2002, 03:17: Message edited by: Bryce ]

Top
#68796 - 2002-08-01 03:12 AM Re: get @pwage from user list and send notification e-mail.
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Sorry! in my example i am using the UDF SerialDate()

[ 01 August 2002, 03:13: Message edited by: Bryce ]

Top
#68797 - 2002-08-01 03:59 AM Re: get @pwage from user list and send notification e-mail.
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Jake,

You should be able to snag some ideas from this post -

Password expiration for a service account

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#68798 - 2002-08-01 07:48 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
Bryce,
I ran your code and
quote:
the number of days the account will expire is -730447
, which is not correct since the accounts have a max age of 60.
quote:
i am guessing that along with a list of user names you also have a list of email addresses?
Once I figure out how to trim the user name from the user list [Confused] :
usera userb userc

Use that variable to send e-mail (i.e. $x=username, $x@company.com)

Kent,
I have taken a look at your script but I can not make heads or tails out of it, way over my head. Thanks for the link.

Top
#68799 - 2002-08-01 08:44 PM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the format of the file list?
are you using net user command to get the list?
or some administrative tool or object?
_________________________
!

download KiXnet

Top
#68800 - 2002-08-01 08:46 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
O.K. I have extracted informations from Kent's post
Password expiration for a service account
to calculate the days left before the password expires. Even though I don't understand the language or code [Big Grin]
code:
$ldomain = @domain
$lstrusername = "@username"
;$userobj = GetObject("LDAP://cn=ntdoc,ou=Users,ou=mybusinessOU,ou=cala,dc=MyCompany,dc=com")
$userobj = GetObject("WinNT://$LDomain/$lstrUserName")
$pwexpire = $userobj.passwordexpirationdate
?"UserName: " + $userobj.name
?"UserPasswordExpires: " + $pwexpire


$tt = SPLIT($pwexpire," ")
$mdy = SPLIT($tt[0],"/")
$expiredatearray = $mdy[2],$mdy[0],$mdy[1]
$currentdatearray = "@YEAR","@MONTHNO","@MDAYNO"


FUNCTION CalcDayofYear($ymdarray) ; Only works on non-millenium years after 2000.
$calendar = 31,28,31,30,31,30,31,31,30,31,30,31
IF VAL($ymdarray[0]) & 1 $ly = 0 ; leap year calculations
ELSE
IF (Val($ymdarray[0])/2) & 1 $ly = 0
ELSE
$ly = 1
ENDIF
ENDIF
$calendar[1] = $calendar[1] + $ly
$mdays = 0
FOR $m = 0 TO (Val($ymdarray[1]) -2)
$mdays = $mdays + $calendar[$m]
NEXT
$calcdayofyear = $mdays + $ymdarray[2]
ENDFUNCTION

$diffyears = VAL($expiredatearray[0]) - VAL($currentdatearray[0])
IF $diffyears > 0
$yearstodays = 0
FOR $countyear = VAL($currentdatearray[0]) TO (VAL($expiredatearray[0])-1)
$acountyear = $countyear,"12","31"
$yearstodays = $yearstodays + CalcDayofYear($acountyear)
NEXT
ENDIF

$daystoexpire = CalcDayofYear($expiredatearray) - CalcDayofYear($currentdatearray) + $yearstodays
?"Number of Days till password expires: " + $daystoexpire

Can someone show me how to extract the user name from a text file and feed it into the code above?
example text file:
usera userb userc userd
usere userf userg userh
etc.....

Thanks for everyone's help so far.

Top
#68801 - 2002-08-01 08:49 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
I am using the net users /domain >users.txt to get the list.
Top
#68802 - 2002-08-01 08:50 PM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jake, something like...
well, can do it all right away.
code:
$nul=open(1,"list.txt")
$line=readline(1)
while not @error
for each $user in split($line)
? $user
next
loop

so you can put the check at the place where it now just outputs the username.

[ 01 August 2002, 21:42: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#68803 - 2002-08-01 08:56 PM Re: get @pwage from user list and send notification e-mail.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Someone forgot the closing tag [/code] [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#68804 - 2002-08-01 09:34 PM Re: get @pwage from user list and send notification e-mail.
Jake Offline
Fresh Scripter

Registered: 2001-11-14
Posts: 26
This is really weird. If I use this code with a given username (i.e. guest), it works fine.
code:
$ldomain = @domain
$lstrusername = "guest"
$userobj = GetObject("WinNT://$LDomain/$lstrUserName")
$pwexpire = $userobj.passwordexpirationdate
?"UserName: " + $userobj.name
?"UserPasswordExpires: " + $pwexpire


$tt = SPLIT($pwexpire," ")
$mdy = SPLIT($tt[0],"/")
$expiredatearray = $mdy[2],$mdy[0],$mdy[1]
$currentdatearray = "@YEAR","@MONTHNO","@MDAYNO"


FUNCTION CalcDayofYear($ymdarray) ; Only works on non-millenium years after 2000.
$calendar = 31,28,31,30,31,30,31,31,30,31,30,31
IF VAL($ymdarray[0]) & 1 $ly = 0 ; leap year calculations
ELSE
IF (Val($ymdarray[0])/2) & 1 $ly = 0
ELSE
$ly = 1
ENDIF
ENDIF
$calendar[1] = $calendar[1] + $ly
$mdays = 0
FOR $m = 0 TO (Val($ymdarray[1]) -2)
$mdays = $mdays + $calendar[$m]
NEXT
$calcdayofyear = $mdays + $ymdarray[2]
ENDFUNCTION

$diffyears = VAL($expiredatearray[0]) - VAL($currentdatearray[0])
IF $diffyears > 0
$yearstodays = 0
FOR $countyear = VAL($currentdatearray[0]) TO (VAL($expiredatearray[0])-1)
$acountyear = $countyear,"12","31"
$yearstodays = $yearstodays + CalcDayofYear($acountyear)
NEXT
ENDIF

$daystoexpire = CalcDayofYear($expiredatearray) - CalcDayofYear($currentdatearray) + $yearstodays
?"Number of Days till password expires: " + $daystoexpire

But if I insert the above code in Lonkero code:
code:
break on
$nul=open(1,"c:\scriptlogic\kix2001.402\users.txt")
$line=readline(1)
while not @error
for each $user in split($line)
?$user
;*******************************************************************************
;Calculating account expire date

$ldomain = @domain
$lstrusername = $user
$userobj = GetObject("WinNT://$LDomain/$lstrusername")
$pwexpire = $userobj.passwordexpirationdate
?"UserName: " + $userobj.name
?"UserPasswordExpires: " + $pwexpire


$tt = SPLIT($pwexpire," ")
$mdy = SPLIT($tt[0],"/")
$expiredatearray = $mdy[2],$mdy[0],$mdy[1]
$currentdatearray = "@YEAR","@MONTHNO","@MDAYNO"


FUNCTION CalcDayofYear($ymdarray) ; Only works on non-millenium years after 2000.
$calendar = 31,28,31,30,31,30,31,31,30,31,30,31
IF VAL($ymdarray[0]) & 1 $ly = 0 ; leap year calculations
ELSE
IF (Val($ymdarray[0])/2) & 1 $ly = 0
ELSE
$ly = 1
ENDIF
ENDIF
$calendar[1] = $calendar[1] + $ly
$mdays = 0
FOR $m = 0 TO (Val($ymdarray[1]) -2)
$mdays = $mdays + $calendar[$m]
NEXT
$calcdayofyear = $mdays + $ymdarray[2]
ENDFUNCTION

$diffyears = VAL($expiredatearray[0]) - VAL($currentdatearray[0])
IF $diffyears > 0
$yearstodays = 0
FOR $countyear = VAL($currentdatearray[0]) TO (VAL($expiredatearray[0])-1)
$acountyear = $countyear,"12","31"
$yearstodays = $yearstodays + CalcDayofYear($acountyear)
NEXT
ENDIF

$daystoexpire = CalcDayofYear($expiredatearray) - CalcDayofYear($currentdatearray) + $yearstodays
?"Number of Days till password expires: " + $daystoexpire
;***************************************
;done calculating

next
$line=readline(1)
loop
exit

I receive the following error:
code:
Script Error: unknown command!
$pwexpire = $userobj.passwordexpirationdate



[ 01 August 2002, 21:45: Message edited by: Jake ]

Top
#68805 - 2002-08-01 09:42 PM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
fixed.
don't know how I could do that!
right after preaching to someone else...
_________________________
!

download KiXnet

Top
#68806 - 2002-08-01 09:45 PM Re: get @pwage from user list and send notification e-mail.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jake, try making your old code a subroutine.

and use in the part I wrote a gosub call.
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 293 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.071 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org