Manipulate Customer Information from AD

Moderator: crythias

Post Reply
fsidoli
Znuny newbie
Posts: 24
Joined: 24 Nov 2011, 12:01
Znuny Version: 5.0.20
Real Name: Fabrizio Sidoli

Manipulate Customer Information from AD

Post by fsidoli »

Hi All,

I would like help to understand how to manipulate customer data pulled from Active Directory, and in particular, how to show the Account Expiry date for each user in a human readable format.

In Kernel/Config.pm I have the following entry for the Account Expiry

Map => [
# Note: Login, Email and CustomerID are required!
#Var, frontend, storage, shown, required, storage-type
# 20160125 FS
#[ 'UserSalutation', 'Title', 'title', 1, 0, 'var' ],
[ 'UserFirstname', 'Firstname', 'givenname', 1, 1, 'var' ],
[ 'UserLastname', 'Lastname', 'sn', 1, 1, 'var' ],
<snip>
[ 'AccountExpiry', 'Account Expires', 'accountExpires', 1, 0, 'int' ],

In the ticket view, this displays as the following, which isn't particularly helpful.

Account Expires: 141690816000000000

I fully understand that this is how AD stores the date, but I would like to convert it to something more sensible.

On a terminal command line I can do the following conversion, but I'm not sure how to do this without OTRS.

~> echo 141690816000000000 | perl -pne 's/(\d{11})\d{7}/"".scalar(localtime($1-11644473600)).""/e'
Sat Jan 1 00:00:00 2050

Does anyone know how to do this. My perl is virtually non existent.

Thanks,
Fab
root
Administrator
Posts: 3955
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Manipulate Customer Information from AD

Post by root »

Hi,

This might not be the hardest thing to do and could be a nice feature in Znuny. Do you have a source for the calculation? Maybe a link in to MS TechNet?

- Roy
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
fsidoli
Znuny newbie
Posts: 24
Joined: 24 Nov 2011, 12:01
Znuny Version: 5.0.20
Real Name: Fabrizio Sidoli

Re: Manipulate Customer Information from AD

Post by fsidoli »

Hi Roy,

Thanks for the swift reply.

I got the conversion from this link. There's nothing technical here and it was essentially a bit of luck with a google search.

https://www.commandlinefu.com/commands/ ... ate-format

As I've said, I know nothing about perl. I don't understand it's syntax and have no idea how to do anything with it.

Thanks,
Fab
zzz
Znuny superhero
Posts: 889
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Manipulate Customer Information from AD

Post by zzz »

Hey Fab,

That's a cool idea!
This solution is super hacky but should fit your needs without any code changes.

Within the 'Map' field in Config.pm:

Code: Select all

[ 'AccountExpiry',    Translatable('Account Expires'),     'accountExpires',            1, 0, 'var', '"></a>[% USE date %][% date.format((Data.AccountExpiry.substr(0, 11) - 11644473600), format => "%Y-%m-%d %H:%M %Z") %]<a style="display:none;>', 0, undef, undef ],
Explanation:
Microsoft stores the time (e.g. accountExpires) starting from 01-01-1601 in nanoseconds (that's why we only use the first 11 digits).
Unix, however, starting from 01-01-1970.

11644473600 is the offset between these times.

You can adjust the format, but be aware of the time zone; I did not test if you can change that.

Best regards
Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
fsidoli
Znuny newbie
Posts: 24
Joined: 24 Nov 2011, 12:01
Znuny Version: 5.0.20
Real Name: Fabrizio Sidoli

Re: Manipulate Customer Information from AD

Post by fsidoli »

Hi Emin,

Perfect! It was exactly what I was after and seems to do exactly what I want! Thank you very much.

Cheers,
Fab
fsidoli
Znuny newbie
Posts: 24
Joined: 24 Nov 2011, 12:01
Znuny Version: 5.0.20
Real Name: Fabrizio Sidoli

Re: Manipulate Customer Information from AD

Post by fsidoli »

Hi Emin,

Another cheeky request. Any idea how I manipulate a string?

Thought I'd have a crack at figuring out how to tidy up the Manager Field, which is reported back as CN=Manager Name,OU=...., so it just reads as 'Manager Name'.

I was hoping the string plugin would help but I can't figure out how to use it. I've tried adding [% USE String %] but I just get an error telling me the plugin doesn't exist. I've clearly missed the point!

Fab
wurzel
Znuny guru
Posts: 3228
Joined: 08 Jul 2010, 22:25
Znuny Version: x.x.x
Real Name: Florian

Re: Manipulate Customer Information from AD

Post by wurzel »

Hi,

viewtopic.php?f=35&t=39168

kind regards
Flo
OTRS 8 SILVER (Prod)
OTRS 8 auf Debian 11 (Test)
Znuny 7.x latest version testing auf Debian 11

-- Ich beantworte keine Forums-Fragen PN - No PN please

I won't answer to unfriendly users any more. A greeting and regards are just polite.
fsidoli
Znuny newbie
Posts: 24
Joined: 24 Nov 2011, 12:01
Znuny Version: 5.0.20
Real Name: Fabrizio Sidoli

Re: Manipulate Customer Information from AD

Post by fsidoli »

Hi Flo,

Thank you very much!

Between you and Emin I have managed to achieve what I wanted in a matter of a few days. I've actually been trying to figure this out on and off for about 4 years so this is very much appreciated!

Best wishes!
Fab
Post Reply