Ask not what osTicket community can do for you - ask what you can do for osTicket community

Go Back   osTicket Forums > osTicket 1.6.x > Mods and Customizations

Reply
 
Thread Tools Search this Thread Display Modes
  #21  
Old 03-09-2010, 04:47 AM
JoseLuis JoseLuis is offline
Member
 
Join Date: Nov 2009
Location: GMR, Portugal
Posts: 54
Arrow

Hope jpastin doesn't bother that I remake the step-by-step tutorial with the line numbering (referring to the original file) and some steps reworked.


ALL CREDITS TO jpastin!



FIRST STEP
First create a file userfind.php with the following content:

PHP Code:
<?php
// START MOD06 AD lookup of Name and Email
// Jpastin http://osticket.com/forums/showthread.php?p=13780#post13780

//       START EDIT
// Replace this with your AD Domain Controller
$ds=ldap_connect('ldap://servername.domain.local:389/') or die("Couldn't connect to AD!");
//Replace this with a username that has read permissions on your AD
$connect_u "DOMAIN\AdminUser";
//Replace this with the password of the user
$conect_p="PPAASSWWOORRDD";
//Replace this with the DN of the base OU you want to search
$search_user_dn "OU=Users,DC=domain,DC=local"
//       STOP EDIT

$inforequired = array("displayName","mail");


if (!
ldap_bind$ds$connect_u$conect_p) ) {
        
$error_msg[] = "Could not bind AD connection<br>";
}
else
{
        if (!empty(
$_REQUEST['mail'])) {
                
$curMail=$_REQUEST['mail'];
                
$curMail strtolower($curMail);
                
$curMail.='*';
                
$filter="(&(mail=$curMail)(objectCategory=person))";
        }
        elseif (!empty(
$_REQUEST['name'])) {
                
$curName=$_REQUEST['name'];
                
$curName strtolower($curName);
                
$curName.='*';
                
$filter="(&(displayName=$curName)(objectCategory=person))";
        }
        
$user_result ldap_search($ds,$search_user_dn,$filter,$inforequired);
        
$user_info ldap_get_entries($ds,$user_result);
        
header("Content-Type: application/json");
                echo
"{\"results\": [";
                
$arr=Array();
                if (
count($user_info) > $_REQUEST['maxEntries'])
                {
                        
$max=$_REQUEST['maxEntries'];
                }
                else
                {
                        
$max=count($user_info);
                }
                for ( 
$i=1$i<$max$i+=1)
                {

                        if (!empty(
$_REQUEST['mail'])) {
                                
$arr[]= "{\"id\": \"".$i."\", \"value\": \"".$user_info[$i-1]['mail'][0]."\", \"info\": \"".$user_info[$i-1]['displayname'][0]."\"}";
                        }
                        elseif (!empty(
$_REQUEST['name'])) {
                                
$arr[]= "{\"id\": \"".$i."\", \"value\": \"".$user_info[$i-1]['displayname'][0]."\", \"info\": \"".$user_info[$i-1]['mail'][0]."\"}";
                        }
                }
        echo 
implode (", "$arr);
        echo 
"]}";
}
//END MOD06
?>
WARNING: Search the "START EDIT" and modify the fields according with your Active Directory connect settings.

Copy the userfind.php to following path: osTicketRootFolder/scp/





SECOND STEP
make the following modifications:

File: include/client/header.inc.php.

FIND ~10
PHP Code:
<link rel="stylesheet" href="./styles/main.css" media="screen">
<
link rel="stylesheet" href="./styles/colors.css" media="screen"
REPLACE BY
PHP Code:
<link rel="stylesheet" href="./styles/main.css" media="screen">
<
link rel="stylesheet" href="./styles/colors.css" media="screen">
<!-- 
START MOD06 Change to add auto lookup of name and email -->
<
script type="text/javascript" src="./scp/js/bsn.AutoSuggest_2.1.3.js" charset="utf-8"></script>
<link rel="stylesheet" href="./scp/css/autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />
<!-- END MOD06 --> 




THIRD STEP

File: include/client/open.inc.php.

FIND ~37
PHP Code:
<input type="text" name="email" size="25" value="<?=$info['email']?>">
REPLACE BY
PHP Code:
<!-- START MOD06 Change to auto populate name and email address from AD -->
<input type="text" id="email" name="email" size="25" value="<?=$info['email']?>">
<!-- END MOD06 -->




FIND ~119
PHP Code:
</form
REPLACE BY
PHP Code:
</form>
<
script type="text/javascript">
// START - MOD06 Active directory look up 
   
var name_options = {
        
script"./scp/userfind.php?maxEntries=10&",
        
varname"name",
        
jsontrue,
        
delay100,
        
cachefalse,
        
callback: function (obj) {document.getElementById('email').value=obj.info;}
    };
    
    var 
email_options = {
        
script"./scp/userfind.php?maxEntries=10&",
        
varname"mail",
        
jsontrue,
        
cachefalse,
        
callback: function (obj) {document.getElementById('name').value=obj.info;}
    };
        
        var 
email_as=new bsn.AutoSuggest('email'email_options);
        var 
name_as=new bsn.AutoSuggest('name'name_options);
// END - MOD06 Active directory look up
</script> 




FOURTH STEP
File: include/staff/newticket.inc.php.

FIND ~163
PHP Code:
</table>
<
script type="text/javascript">
    
    var 
options = {
        
script:"ajax.php?api=tickets&f=searchbyemail&limit=10&",
        
varname:"input",
        
jsontrue,
        
shownoresults:false,
        
maxresults:10,
        
callback: function (obj) { document.getElementById('email').value obj.iddocument.getElementById('name').value obj.info; return false;}
    };
    var 
autosug = new bsn.AutoSuggest('email'options);
</script> 
REPLACE BY
PHP Code:
</table>

<
script type="text/javascript">
// START - MOD06 Active directory look up
   
var name_options = {
        
script"userfind.php?maxEntries=10&",
        
varname"name",
        
jsontrue,
        
delay100,
        
cachefalse,
        
callback: function (obj) {document.getElementById('email').value=obj.info;}
    };
    
    var 
email_options = {
        
script"userfind.php?maxEntries=10&",
        
varname"mail",
        
jsontrue,
        
cachefalse,
        
callback: function (obj) {document.getElementById('name').value=obj.info;}
    };
        
        var 
email_as=new bsn.AutoSuggest('email'email_options);
        var 
name_as=new bsn.AutoSuggest('name'name_options);
// END MOD06 - Active directory look up
</script> 
Reply With Quote
  #22  
Old 03-09-2010, 05:49 AM
pti_breton pti_breton is offline
Member
 
Join Date: Mar 2010
Location: France
Posts: 31
Smile

I tried your version and it works !
The error in the jpastin's version came from the links in include/client/header.inc.php and in include/client/open.inc.php (you must add a point before scp/[...]).

Thanks a lot guys !

Do you know how to display the caracted accents received from the AD ?

If the username is "MARTIN Stéphanie", it displays "MARTIN St?anie"
I tried to change the charset to iso-8859-1 in include/client/header.inc.php :

Code:
header("Content-Type: text/html; charset=iso-8859-1\r\n");
[...]
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
[...]
<script type="text/javascript" src="./scp/js/bsn.AutoSuggest_2.1.3.js" charset="iso-8859-1"></script>
<link rel="stylesheet" href="./scp/css/autosuggest_inquisitor.css" type="text/css" media="screen" charset="iso-8859-1" />
but it's the same... I think the problem could be in bsn.AutoSuggest_2.1.3.js or in userfind.php but i don't find where
Reply With Quote
  #23  
Old 03-09-2010, 06:15 AM
pti_breton pti_breton is offline
Member
 
Join Date: Mar 2010
Location: France
Posts: 31
Default

I think i have to rewrite the $user_info[$i-1]['displayname'][0] with the HTML Special Characters like &eacute; or &egrave;... in scp/userfind.php in this part of code :

Code:
      if (!empty($_REQUEST['mail'])) {
                $arr[]= "{\"id\": \"".$i."\", \"value\": \"".$user_info[$i-1]['mail'][0]."\", \"info\": \"".$user_info[$i-1]['displayname'][0]."\"}";
      }elseif (!empty($_REQUEST['name'])) {
                $arr[]= "{\"id\": \"".$i."\", \"value\": \"".$user_info[$i-1]['displayname'][0]."\", \"info\": \"".$user_info[$i-1]['mail'][0]."\"}";
      }
Reply With Quote
  #24  
Old 03-09-2010, 08:22 AM
pti_breton pti_breton is offline
Member
 
Join Date: Mar 2010
Location: France
Posts: 31
Default

I tried the PHP function htmlentities() but it displays (in my example) St&eacute;phanie in the input.

The html code is not decoded

A solution seems to be in the charset but the iso-8859-1 doesn't work.
I also loouk up in the bsn.AutoSuggest_2.1.3.js but i don't really understand the _b.AutoSuggest.prototype.createList function.

Can someone help me ?

Last edited by pti_breton; 03-09-2010 at 08:44 AM.
Reply With Quote
  #25  
Old 03-09-2010, 10:31 AM
jpastin jpastin is offline
Member
 
Join Date: Sep 2009
Location: Chicago
Posts: 32
Default

Great job JoseLuis. I didn't include line numbers because my setup is so hacked up they would be worse than meaningless. That will definitely help people out.

pti_breton: I'm not really sure how to make it deal with the special characters well. I would try UTF-8, hopefully that can handle it. Good Luck!!

Last edited by jpastin; 03-09-2010 at 10:39 AM.
Reply With Quote
  #26  
Old 03-09-2010, 11:54 AM
pti_breton pti_breton is offline
Member
 
Join Date: Mar 2010
Location: France
Posts: 31
Default

I found a workaround by disabling the accented characters in userfing.php
with strtr() function


I hope i will find a real solution...
Reply With Quote
  #27  
Old 03-09-2010, 12:07 PM
JoseLuis JoseLuis is offline
Member
 
Join Date: Nov 2009
Location: GMR, Portugal
Posts: 54
Exclamation

Don't forget that file encoding is also a "problem" I had some issues with encoding my national characters like "ãõêçÇ".

And solved by setting the php files to utf-8 in Notepad++ like:
Reply With Quote
  #28  
Old 04-28-2010, 03:46 AM
schnarchnase schnarchnase is offline
Junior Member
 
Join Date: Mar 2010
Posts: 2
Default Some Questions

First of all I would say that this Mod is great and works perfectly.

Is there a way to supplement the modification so that even the phone number is read from the AD and placed in the appropriate field.

Perhaps it there also the ability to view the login name in the select list ?

I have already started a few experiments, unfortunately without success.

Regards

Schnarchnase
Reply With Quote
  #29  
Old 06-10-2010, 11:00 PM
brendan_hooper brendan_hooper is offline
Junior Member
 
Join Date: May 2010
Posts: 2
Default No Errors displayed, but not working

Hi guys, Im sure this is a great script when i can get it to work. I am trying to get this to work without success, i dont get any error messages its as there there is code in the file but nothing is happening with it. It wouldn't suprise me if its the domain string. I go to scp->tickets->new ticket, doesn't matter what i type in the name or email there is no popup box appearig to do auto fill.

Code:
// Replace this with your AD Domain Controller
$ds=ldap_connect('ldap://brg-inet.schools.mn.local:389/') or die("Couldn't connect to AD!");
//Replace this with a username that has read permissions on your AD
$connect_u = "SCHOOLS.MN\brg.serviceaccount";
//Replace this with the password of the user
$conect_p="*********";
//Replace this with the DN of the base OU you want to search
$search_user_dn = "OU=Users,OU=BRG,OU=Lakes,OU=Schools,DC=Schools,DC =mn";
//STOP EDIT
=======

Will it search the sub folders of the Users OU or do i need to specify each level?
Code:
= "OU=Admins,OU=Users,OU=BRG,OU=Lakes,OU=Schools,DC= Schools,DC=mn";
= "OU=Staff,OU=Users,OU=BRG,OU=Lakes,OU=Schools,DC=S chools,DC=mn";
= "OU=Library,OU=Staff,OU=Users,OU=BRG,OU=Lakes,OU=S chools,DC=Schools,DC=mn";

Is there some code i can place into a php script to test the connection? am using IE8 and Mozilla 2.0.0.14
How do we get it to do user login autentication is there another script for this?

Last edited by brendan_hooper; 06-10-2010 at 11:12 PM. Reason: updated.
Reply With Quote
  #30  
Old 07-13-2010, 05:37 AM
Burnout Burnout is offline
Junior Member
 
Join Date: Jul 2010
Posts: 4
Default

Mhh, I made every changes like in the tutorial above and i get following error message:

"Ajax error: 500"

Any ideas?
Reply With Quote


Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:13 PM.