Displaying the Customer's Pic from AD using thumbnailPhoto

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Forum rules
Dont create your support topics here! No new topics with questions allowed!
Post Reply
StarDestroyer
Znuny newbie
Posts: 20
Joined: 05 Sep 2013, 22:26
Znuny Version: 5.0.x
Real Name: Jake
Company: Hilite International

Displaying the Customer's Pic from AD using thumbnailPhoto

Post by StarDestroyer »

Active Directory has the ability to hold a JPEG image for each user in the thumbnailPhoto attribute for that user's object. This is the attribute that Outlook 2010 and above uses to display the user's picture. It can also be used by other software such as Lync and SharePoint.

With a little bit of setup, you can have OTRS use this picture in the TicketZoom screen. We'll use the same trick found in How To use CustomerUser Map to link images (http-link).

While it is possible to embed an image right into the <img> tag, that would require code changes and is not supported by all browsers. So instead, what we're going to do is overload the URL for the attribute in the customer DB and point it to a script that will retrieve pictures from AD.

First, the script... but this in a file called "photo.php" (sorry it's in PHP instead of Perl... it's what I already have written):

Code: Select all

<?php

#Configuration options
$ldap_server = "dc.domain.net";
$ldap_user = "ldapuser@domain.net";
$ldap_pass = "password";
$dn = "dc=domain,dc=net";
# End config

$u = "";
if (isset($_GET['username']) and preg_match("/^[A-Za-z0-9]+$/", $_GET['username'])) {
    $ldap = ldap_connect($ldap_server, 3268);
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_bind($ldap, $ldap_user, $ldap_pass) or die ("No LDAP Bind to ".$ldap_server);

    $filter = '(samaccountname='.$_GET['username'].')';
    $sr = ldap_search($ldap, $dn, $filter, array('thumbnailphoto'));
    $u = ldap_get_entries($ldap, $sr);
}

header('content-type: image/jpeg');
if (isset($u[0]['thumbnailphoto'])) {
    echo $u[0]['thumbnailphoto'][0];
} else {
    $fp = fopen('default.jpg', 'r');
    fpassthru($fp);
}

?>
You'll then want to find a 96x96 shadow image to use as a default when the picture can't be found. You'll want to put both of these files someplace in your webspace that it makes sense. You can test the script by visiting http://yourserver.domain.net/path/photo.php?username=ad_user (replace ad_user with the login name of a user that has a picture). If you get that user's picture, you're golden. If not, something must be wrong.

Once you can load the user's picture, then you want to add the option to the map in Config.pm.

Code: Select all

        Map => [
          # note: Login, Email and CustomerID needed!
          # var, frontend, storage, shown, required, storage-type
          [ 'UserLogin', 'Login', 'sAMAccountName', 1, 0, 'var', '#"><img width="96" height="96" src="http://yourserver.domain.net/path/photo.php?username=[% Data.UserLogin | uri %]" /></a><br /><a href="#', 0 ],
          [ 'UserTitle', 'Title', 'title', 1, 0, 'var' ],
          [ 'UserFirstname', 'Firstname', 'givenname', 0, 1, 'var' ],
          [ 'UserLastname', 'Lastname', 'sn', 0, 1, 'var' ],
          [ 'UserFullname', 'Name', 'displayName', 1, 1, 'var'],
          [ 'UserEmail', 'Email', 'mail', 1, 0, 'var' ],
          [ 'UserCustomerID', 'CustomerID', 'userPrincipalName', 0, 1, 'var' ],
          [ 'UserPhone', 'Phone', 'telephonenumber', 1, 0, 'var' ],
          [ 'UserCell', 'Cell', 'mobile', 1, 0, 'var' ],
          [ 'UserAddress', 'Address', 'streetAddress', 1, 0, 'var' ],
        ],
Updated for OTRS 4 and the Template Toolkit

Make sure you replace the URL for the image source to be the script you just set up.

In my environment, I also have a script that will search AD as an online phonelist (giving the same information that Outlook gives). Instead of the # marks above, I used the URL to that search ( http://phonesearch.domain.net/phonelist.php?samaccountname=$Data{"UserLogin"} ). This makes it so the picture (and the User ID below the picture) link to my phonelist search. Though in actuality, most of the information phonelist search returns is now available in OTRS. The main exception to that being the manager and direct reports.
Last edited by StarDestroyer on 06 Apr 2015, 21:49, edited 1 time in total.
OTRS 5.0.x on CentOS 6 w/MySQL Database
TamaraS
Znuny newbie
Posts: 21
Joined: 25 Feb 2015, 21:51
Znuny Version: 4.0.6
Real Name: Tamara
Location: Bonn, Germany

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by TamaraS »

Hello StarDestroyer,

thank you for the script.
There might be a problem with current PHP-versions.

Code: Select all

PHP Parse error:  syntax error, unexpected 'and' (T_LOGICAL_AND) in /var/www/html/userphoto/photo.php on line 11
Another specific problem at our side are usernames with a space in it like "Name Surname".

Could you have a look at it again?

Kind regards
Tamara
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by crythias »

You might try $QData instead of $Data but a multi word username? That's ... unusual.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
TamaraS
Znuny newbie
Posts: 21
Joined: 25 Feb 2015, 21:51
Znuny Version: 4.0.6
Real Name: Tamara
Location: Bonn, Germany

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by TamaraS »

Hello crythias,

thank you for your reply. That would affect the integration into Mapping.
But the error says, it's an error in the php-script. Line 11 says

Code: Select all

if (isset($_GET['username'])) and preg_match("/^[A-Za-z0-9]+$/", $_GET['username'])) {
Windows-Usernames with space are not unnormal, e.g. in our company we seperate between Surname and given name.
I saw this in different companys around the world until now (maybe because users will not forget how to write their name).

Kind regards,
Tamara
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by crythias »

too many )) reduce by one.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
TamaraS
Znuny newbie
Posts: 21
Joined: 25 Feb 2015, 21:51
Znuny Version: 4.0.6
Real Name: Tamara
Location: Bonn, Germany

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by TamaraS »

Yes, there was really a ) to much.
I corrected that, but the parse error is still there
StarDestroyer
Znuny newbie
Posts: 20
Joined: 05 Sep 2013, 22:26
Znuny Version: 5.0.x
Real Name: Jake
Company: Hilite International

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by StarDestroyer »

TamaraS wrote:Hello StarDestroyer,
There might be a problem with current PHP-versions.

Code: Select all

PHP Parse error:  syntax error, unexpected 'and' (T_LOGICAL_AND) in /var/www/html/userphoto/photo.php on line 11
I'm really not sure why you'd be getting that error. I looked over the code and it seems to be the exact same as what I'm using on my server. The only noticeable difference I have is that I get the configuration information at the top from a different script.
TamaraS wrote:Hello StarDestroyer,
Another specific problem at our side are usernames with a space in it like "Name Surname".
Similar to crythias, I have never heard of a space in the username. However, I just made a minor update to the original post (changed $Data{"UserLogin"} to [% Data.UserLogin | uri %] in order to support OTRS 4 and the Template Toolkit. Because this runs the username through TT's uri filter, it should automatically change your space to %20 in the URL. You would also have to change the regular expression to accept a space in the if statement that's causing you issues already. Without testing, I think it should be preg_match("/^[A-Za-z0-9 ]+$/", $_GET['username']) ... this would allow the username to start or end with a space for the LDAP query which may or may not work (again, I've never used a space in a user name).
OTRS 5.0.x on CentOS 6 w/MySQL Database
TamaraS
Znuny newbie
Posts: 21
Joined: 25 Feb 2015, 21:51
Znuny Version: 4.0.6
Real Name: Tamara
Location: Bonn, Germany

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by TamaraS »

Thank you StarDestroyer,
it is working right now with your changes.

Kind regards
Tamara
lameventanas
Znuny newbie
Posts: 7
Joined: 15 Apr 2015, 11:15
Znuny Version: 4.0.7

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by lameventanas »

I decided to embed the image in the <img> tag.
It's supposed to work in all browsers that are supported by OTRS 4.

Pros:
- less overhead (uses the same http request)
- better integrated, no need for separate php + ldap config
- looks professional, the photo is a separate record
- it should work with CustomerUser::DB too

Cons:
- requires a change in OTRS

Maybe a new Frontend::CustomerUser::Item module would be better, if anybody is up to this task, please share.

Here is the patch for OTRS master branch:
https://github.com/lameventanas/otrs/co ... 5407e79040

And your mapping should look like this:

Code: Select all

    Map => [
        [ 'UserFirstname',  'Firstname',  'givenname',          1, 1, 'var', '', 0 ],
        [ 'UserLastname',   'Lastname',   'sn',                 1, 1, 'var', '', 0 ],
...
        [ 'UserPhoto',      'Photo',      'thumbnailPhoto',     1, 0, 'image/jpeg', '', 0 ],
    ],
Notice the "image/jpeg", this is the mime type. I didn't see any side effect by reusing this field for this, but perhaps it should be a new field.

It looks like this:
customer.png
You do not have the required permissions to view the files attached to this post.
TamaraS
Znuny newbie
Posts: 21
Joined: 25 Feb 2015, 21:51
Znuny Version: 4.0.6
Real Name: Tamara
Location: Bonn, Germany

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by TamaraS »

I added UserLogin a second time in Config.pm, works well.

Code: Select all

Map => [
[ 'UserLogin', '', '', 1, 0, 'var', '#"></span><img width="96" height="96" src="http://vserv072/userphoto/photo.php?username=[% Data.UserLogin | uri %]" style="background: #eeeeee;border: 1px solid #137469;border-radius: 10px;-moz-border-radius: 10px;-webkit-border-radius: 10px;" /></a><br /><span style="text-transform: uppercase; color:#137469!important; text-color:#137469!important; text-decoration: none !important;"><a href="#', 0 ],

    [ 'UserFirstname', 'Firstname', 'givenname', 1, 1, 'var', '' ],
    [ 'UserLastname', 'Lastname', 'sn', 1, 1, 'var', '' ],
    [ 'UserLogin', 'Login', 'sAMAccountName', 1, 1, 'var', '' ],
    [ 'UserEmail', 'Email', 'mail', 1, 1, 'var', 'mailto:[% Data.UserEmail | uri %]' ],
    [ 'UserCustomerID', 'CustomerID', 'mail', 0, 1, 'var', '' ],
    [ 'UserPhone', 'Phone', 'telephonenumber', 1, 0, 'var', 'dialto:[% Data.UserPhone | uri %]' ],
    [ 'UserMobile', 'Mobile', 'mobile', 1, 0, 'var', 'dialto:[% Data.UserMobile | uri %]' ],
    [ 'UserPersonnelNo', 'Personalnummer',     'employeeNumber',     1, 0, 'var', '', 0 ],
    [ 'UserDepartment', 'Abteilung',     'department',     1, 0, 'var', '', 0 ],
    [ 'UserComment',      'Kommentar',     'info',     1, 0, 'var', '', 0 ],
    [ 'UserPostition',      'Position',     'title',     1, 0, 'var', '', 0 ],
    [ 'UserManager',      'Vorgesetzter',     'manager',     0, 0, 'var', '', 0 ],
  ],
};
I only just can't get the Link out of the picture...
otrs_kundeninfo.png
You do not have the required permissions to view the files attached to this post.
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by jojo »

lameventanas wrote: Here is the patch for OTRS master branch:
https://github.com/lameventanas/otrs/co ... 5407e79040

Yoiu might create a pull request for master...
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
alf12
Znuny newbie
Posts: 11
Joined: 10 Jan 2014, 11:52
Znuny Version: 3.3.3
Location: Dresden

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by alf12 »

Hello,
I like the idea of embedding the image.
But I have to add a new column 'thumbnailPhoto' to the mysql-table 'customer_user'. I have used the data type mediumblob and it's filled with data from LDAP. Still I get an internal server error when trying to display the ticket.
Any idea? What data type should the column be?
Gruß
Norman
jaczdown
Znuny newbie
Posts: 1
Joined: 11 Jul 2012, 23:13
Znuny Version: oneorzero

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by jaczdown »

Hola a todos no pude solucionar un problema en el que no traducia la variable "photo.php?username=[% Data.UserLogin | uri %]" lo he reemplazado por "/photo.php?username=$Data{"UserLogin"}" style= "background...." y funciona perfectamente.. Gracias a Todos.


Traslate
Hello everybody can not solve a problem that did not translate the variable "photo.php username = [% Data.UserLogin | uri%]?" I've replaced by "/photo.php?username=$Data{"UserLogin" } "style =" background .... "and it works perfectly .. Thanks to all.
Sayannara
Znuny advanced
Posts: 118
Joined: 22 May 2012, 12:37
Znuny Version: OTRS 7.06
Real Name: Yann
Company: FVE
Contact:

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by Sayannara »

In case somebody want to extract picture from AD with PowerShell here is the necessery code

Code: Select all

Import-Module ActiveDirectory  
$users = Get-ADUser -filter {description -eq "Compte utilisateur"} -Properties thumbnailPhoto | ? {$_.thumbnailPhoto}

$p_target = "your_path"

foreach ($user in $users) {
    $name = $user.SamAccountName + ".jpg"  
    $user.thumbnailPhoto | Set-Content "$p_target\$name" -Encoding byte
}
Centos 7 / OTRS::ITSM 6 Business Solutions / MariaDB / Apache
spiderpig
Znuny expert
Posts: 198
Joined: 15 Dec 2011, 02:26
Znuny Version: OTRS 5

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by spiderpig »

lameventanas wrote:I decided to embed the image in the <img> tag.
It's supposed to work in all browsers that are supported by OTRS 4.

Pros:
- less overhead (uses the same http request)
- better integrated, no need for separate php + ldap config
- looks professional, the photo is a separate record
- it should work with CustomerUser::DB too

Cons:
- requires a change in OTRS

Maybe a new Frontend::CustomerUser::Item module would be better, if anybody is up to this task, please share.

Here is the patch for OTRS master branch:
https://github.com/lameventanas/otrs/co ... 5407e79040

And your mapping should look like this:

Code: Select all

    Map => [
        [ 'UserFirstname',  'Firstname',  'givenname',          1, 1, 'var', '', 0 ],
        [ 'UserLastname',   'Lastname',   'sn',                 1, 1, 'var', '', 0 ],
...
        [ 'UserPhoto',      'Photo',      'thumbnailPhoto',     1, 0, 'image/jpeg', '', 0 ],
    ],
Notice the "image/jpeg", this is the mime type. I didn't see any side effect by reusing this field for this, but perhaps it should be a new field.

It looks like this:
customer.png
HI,

Is someone running OTRS 5 getting this to work?
spiderpig
Znuny expert
Posts: 198
Joined: 15 Dec 2011, 02:26
Znuny Version: OTRS 5

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by spiderpig »

lameventanas wrote:I decided to embed the image in the <img> tag.
It's supposed to work in all browsers that are supported by OTRS 4.

Pros:
- less overhead (uses the same http request)
- better integrated, no need for separate php + ldap config
- looks professional, the photo is a separate record
- it should work with CustomerUser::DB too

Cons:
- requires a change in OTRS

Maybe a new Frontend::CustomerUser::Item module would be better, if anybody is up to this task, please share.

Here is the patch for OTRS master branch:
https://github.com/lameventanas/otrs/co ... 5407e79040

And your mapping should look like this:

Code: Select all

    Map => [
        [ 'UserFirstname',  'Firstname',  'givenname',          1, 1, 'var', '', 0 ],
        [ 'UserLastname',   'Lastname',   'sn',                 1, 1, 'var', '', 0 ],
...
        [ 'UserPhoto',      'Photo',      'thumbnailPhoto',     1, 0, 'image/jpeg', '', 0 ],
    ],
Notice the "image/jpeg", this is the mime type. I didn't see any side effect by reusing this field for this, but perhaps it should be a new field.

It looks like this:
customer.png


HI,

should this method also work with OTRS 5?

I'm running OTRS 5 and getting "Internal error"

there are no "Kernel/Output/HTML/LayoutTicket.pm", but I guess they changed it to Kernel/Output/HTML/Layout/Ticket.pm in OTRS 5
Sayannara
Znuny advanced
Posts: 118
Joined: 22 May 2012, 12:37
Znuny Version: OTRS 7.06
Real Name: Yann
Company: FVE
Contact:

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by Sayannara »

Hello here is the line

1. extract picture from AD and make sure if you want to match picture with samAccountName to named you picture with samAccountName
2. put them in a web server for example
3. modify the following line (or as you like)

Code: Select all

[ 'UserLogin', 'Login', 'sAMAccountName', 1, 0, 'var', '#"><img src="http://otrspics.fednet.local/pic/[% Data.UserLogin %].jpg" /></a><br /><a href="#', 0 ],
Note that you can match picture with customer by means of

Code: Select all

[% Data.UserLogin %]
Centos 7 / OTRS::ITSM 6 Business Solutions / MariaDB / Apache
Alegator2222
Znuny newbie
Posts: 13
Joined: 21 Apr 2016, 14:53
Znuny Version: OTRS 5.0.8
Real Name: Oleg

Re: Displaying the Customer's Pic from AD using thumbnailPhoto

Post by Alegator2222 »

Hi all.
I try to do so.
[ 'UserPhoto', 'Photo', 'thumbnailPhoto', 1, 0, 'image/jpeg', '', 0 ],
and I get it here
Image
in AD Photo clients have.
Post Reply