1. Kayako Download customers: we will continue to develop and support Kayako Download beyond July 2017, alongside the new Kayako for existing customers.

    Find out more.

  2. The forum you are viewing relates to Kayako Classic. If you signed up or upgraded to the new Kayako (after the 4th July 2016), the information in this thread may not apply to you. You can visit the forums for the new Kayako here.

Active Directory User Sync Script

Discussion in 'Apps and modifications' started by Dylan Lindgren, Aug 26, 2009.

  1. Dylan Lindgren

    Dylan Lindgren Established Member

    Jamie Edwards likes this.
  2. idxman01

    idxman01 Member

    We're about to go live on V4 on Friday and while AD sync isn't 100% critical, I would like to have it in place like we do for V3.

    From looking at the script I'm wondering if we're going to run into problems since it's keying off the default email address. We currently have two domains and have switched staff over to the new one for their default outgoing email. This means that 90% of users have their "old" domain in eSupport and the rest had their eSupport profile created with the new. For daily operations of our V3 setup this is fine since it refers to the loginapi_userid field, though that was removed for V4.

    I'm going to test soon, but suspect this will end up creating new user accounts instead of associating the new email with the existing accounts. As a slight workaround I do have user loginShare setup and have it modified to bring back all email addresses based off the 'proxyaddresses' field. So once they login it will automatically add any missing addresses.

    Any thoughts on a sync solution?
     
  3. Dylan Lindgren

    Dylan Lindgren Established Member

    Hey mate,

    Is the first part of the email always the same, regardless of which of the two domains their primary email is using? If so, it's definitely possible but would require a big addition to the comparison functionality within my code. Hopefully you know your PHP!

    What I would do is compare only the first part of the email address, as long as the domain is one of yours - i.e. strip the email address so that everything after and including the @ is removed for your domains, and ignore anything that isn't your domain. For example, take these email addresses...
    1. dylan@yourdomain1.com
    2. dylan@yourdomain2.com
    3. idxman01@yourdomain1.com
    4. idxman01@otherdomain.com
    If you ran the strip I mentioned on them, they would look like this
    1. dylan
    2. dylan
    3. idxman01
    4. idxman01@otherdomain.com
    You could then tell that user 1 and 2 are the same user, however user 3 and user 4 are different users.
    Hope this helps.
    Dylan
     
  4. idxman01

    idxman01 Member

    Hi Dylan,

    I appreciate the reply and that's exactly what I was thinking. I was being lazy and hoping someone else has run into the same scenario. :) I'm not too bad with PHP so I'm sure I can figure something out soon. (and yes. 99.99% of users have the same username in both domains)

    We just went live this afternoon with V4 and I now think that converting all addresses is going to be required. It seems that when a user replies to an existing ticket, the system will automatically create a new user account since it doesn't know to match the existing account on domain1.

    I should probably also do this soon so we're not flooded with duplicate accounts starting next week... (if only there was an easy way to merge..)
     
  5. Larry Yu

    Larry Yu Member

    Any chance someone can help me out with this? Been trying to get this working for the past few days on the lastest trial v4.4.986 and not having any luck.

    Getting the error below

    PHP Notice: Undefined variable: kayakoDir in C:\inetpub\ADUserSync.php on line 55
    PHP Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 404' in C:\inetpub\wwwroot\KayakoAPI\kyBase.php:198
    Stack trace:
    #0 C:\inetpub\wwwroot\KayakoAPI\kyBase.php(223): kyBase::processRequest(NULL, 'GET', Array)
    #1 C:\inetpub\wwwroot\KayakoAPI\kyObjectBase.php(104): kyBase::_get(Array)
    #2 C:\inetpub\wwwroot\KayakoAPI\kyUser.php(118): kyObjectBase::getAll(Array)
    #3 C:\inetpub\ADUserSync.php(58): kyUser::getAll()
    #4 {main}
    thrown in C:\inetpub\wwwroot\KayakoAPI\kyBase.php on line 198

    Modify the ADUserSync.php file on Line #34 from "$kayakoInstall = "http://helpdesk.com"; TO "$kayakoDir = "http://helpdesk.com"; and got rid of the first error above "PHP Notice: Undefined variable: kayakoDir in C:\inetpub\ADUserSync.php on line 55" but still not sure what the other errors mean. Am I not configuring Line #34 correctly?

    Any help would be greatly appreciated! TIA.

    Update #1:
    It seems like the "$KayakoDir" on line #34 is asking for the Kayako API URL and not the full address to the Kayako install as indicated. Now that I have gotten pass the errors above, but now face with a new set of errors. Are these codes not 2008 Active Directory friendly or I'm just missing a load of configures somewhere? I'm in no way PHP literate, but will try to nail this on the butt. I can't possibly be the only one that can't get this to work ;)

    PHP 5.3.5 Error log
    PHP Warning: ldap_search(): Search: Can't contact LDAP server in C:\inetpub\ADUserSync.php on line 61
    PHP Warning: curl_setopt_array(): cannot represent a stream of type MEMORY as a STDIO FILE* in C:\inetpub\wwwroot\KayakoAPI\kyBase.php on line 190
    PHP Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 401' in C:\inetpub\wwwroot\KayakoAPI\kyBase.php:198
    Stack trace:
    #0 C:\inetpub\wwwroot\KayakoAPI\kyBase.php(246): kyBase::processRequest('/Base/User', 'PUT', Array, Array)
    #1 C:\inetpub\wwwroot\KayakoAPI\kyObjectBase.php(171): kyBase::_put(Array, Array)
    #2 C:\inetpub\ADUserSync.php(148): kyObjectBase->update()
    #3 {main}
    thrown in C:\inetpub\wwwroot\KayakoAPI\kyBase.php on line 198
     
  6. EgNk

    EgNk New Member

    Hi, Dylan Lindgren!
    Does your script work with PHP 5.2? Because i can't get it to work
    :( I try script adoldap-import by LOGVince, it works, but no one can login, seems script doesn't import passwords. Sorry for my bad English.
    UPD.: Intsall PHP 5.3 + Ioncube. Now script give this:
    <br />
    <b>Strict Standards</b>: Declaration of kyDepartment::createNew() should be com
    patible with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyDepart
    ment.php</b> on line <b>13</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyStaff::createNew() should be compatib
    le with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyStaff.php</
    b> on line <b>433</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyStaffGroup::createNew() should be com
    patible with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyStaffG
    roup.php</b> on line <b>120</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicket::getAll() should be compatible
    with that of kyObjectBase::getAll() in <b>C:\Site\custom\KayakoAPI\kyTicket.php
    </b> on line <b>1257</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicket::createNew() should be compati
    ble with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyTicket.php
    </b> on line <b>1257</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketAttachment::getAll() should be
    compatible with that of kyObjectBase::getAll() in <b>C:\Site\custom\KayakoAPI\ky
    TicketAttachment.php</b> on line <b>261</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketAttachment::get() should be com
    patible with that of kyObjectBase::get() in <b>C:\Site\custom\KayakoAPI\kyTicket
    Attachment.php</b> on line <b>261</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketAttachment::createNew() should
    be compatible with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\ky
    TicketAttachment.php</b> on line <b>261</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketCustomFieldGroup::getAll() shou
    ld be compatible with that of kyObjectBase::getAll() in <b>C:\Site\custom\Kayako
    API\kyTicketCustomFieldGroup.php</b> on line <b>12</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketNote::getAll() should be compat
    ible with that of kyObjectBase::getAll() in <b>C:\Site\custom\KayakoAPI\kyTicket
    Note.php</b> on line <b>481</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketNote::get() should be compatibl
    e with that of kyObjectBase::get() in <b>C:\Site\custom\KayakoAPI\kyTicketNote.p
    hp</b> on line <b>481</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketNote::createNew() should be com
    patible with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyTicket
    Note.php</b> on line <b>481</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketPost::getAll() should be compat
    ible with that of kyObjectBase::getAll() in <b>C:\Site\custom\KayakoAPI\kyTicket
    Post.php</b> on line <b>419</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketPost::get() should be compatibl
    e with that of kyObjectBase::get() in <b>C:\Site\custom\KayakoAPI\kyTicketPost.p
    hp</b> on line <b>419</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketPost::createNew() should be com
    patible with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyTicket
    Post.php</b> on line <b>419</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketTimeTrack::getAll() should be c
    ompatible with that of kyObjectBase::getAll() in <b>C:\Site\custom\KayakoAPI\kyT
    icketTimeTrack.php</b> on line <b>493</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketTimeTrack::get() should be comp
    atible with that of kyObjectBase::get() in <b>C:\Site\custom\KayakoAPI\kyTicketT
    imeTrack.php</b> on line <b>493</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyTicketTimeTrack::createNew() should b
    e compatible with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyT
    icketTimeTrack.php</b> on line <b>493</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyUser::createNew() should be compatibl
    e with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyUser.php</b>
    on line <b>581</b><br />
    <br />
    <b>Strict Standards</b>: Declaration of kyUserGroup::createNew() should be comp
    atible with that of kyBase::createNew() in <b>C:\Site\custom\KayakoAPI\kyUserGro
    up.php</b> on line <b>139</b><br />

    Fatal error: Class 'kyBase' not found in C:\ADUserSync.php on line 55
    Any ideas?:(
    Best Regards
     
  7. Larry Yu

    Larry Yu Member

    Hi EgNk,

    I don't think any of the import scripts will import the accounts passwords. If you are able to successfully import users accounts into Kayako, you'll need to configure Kayako to do LDAP authentication by means of loginshare. Check out the link below if you haven't already done so. Hope it helps.

    AD LDaP Authentication
    http://forums.kayako.com/threads/php-ad-ldap-authenticator.24269/page-7#post-130351

     
  8. EgNk

    EgNk New Member

    Hi Larry Yu!
    Thanks for your reply!
    I have already read this thread and have troubles with this script , because i have in AD account Full Name in Russian and that is why script stops parse xml:(
     
  9. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi Larry,

    Sorry about the late reply. I have released a patch which fixes the "undeclared variable" error you are getting. The 404 error you're getting is because you probably copied and pasted the API URL from the Admin Console, which has a ? at the end of the URL string. This question mark is not needed, and causes this error. I have modified the comment on that line to reflect this.

    Please download the new version 1.0.1 from the project page at http://forge.kayako.com/projects/adusersync and see how you get on.

    Kind regards,

    Dylan
     
  10. Larry Yu

    Larry Yu Member

    No need to apologize Dylan. I'm sure I can speak for everyone else that we appreciate you for just being here to help.

    I seem to be getting a bit closer and closer with getting your script to work. I have done a new install and all, but now getting the error below. I'm no coder and can't really decipher what it means or what needs to be done to fix. I'll keep playing around with it and see if I can get it fixed before you reply. Thanks again!

    "PHP Catchable fatal error: Argument 1 passed to kyUser::setUserOrganization() must be an instance of kyUserOrganization, null given, called in C:\inetpub\wwwroot\sts\ADUserSync.php on line 138 and defined in C:\inetpub\wwwroot\sts\KayakoAPI\kyUser.php on line 253"

     
  11. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi Larry,

    You're very close, tripped up by another bug in my code unfortunately.

    Please download the new version 1.0.2 from the project page at http://forge.kayako.com/projects/adusersync. I've added another setting you need to define called $kayakoOrgName which is the full name of the organization that users will be imported under, for example for our installation I use "Henry Davis York" as the value for that field.

    Let us know how you get on. Hopefully this will be the last of the errors!

    Kind regards,

    Dylan
     
  12. Larry Yu

    Larry Yu Member

    Hi Dylan,

    We're definitely getting closer. After using your updated file, I was able to only create one user account and then got an error below. This happened to both the old install and new. Maybe I'm missing a setting somewhere?

    Error #1 - Getting this error when the accounts doesn't exist in the database (Only creates 1st account)
    PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0
    PHP Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 500' in C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php:198
    Stack trace:
    #0 C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php(235): kyBase::processRequest(NULL, 'POST', Array, Array)
    #1 C:\inetpub\wwwroot\sts\KayakoAPI\kyObjectBase.php(157): kyBase::_post(Array, Array)
    #2 C:\inetpub\wwwroot\sts\ADUserSync.php(146): kyObjectBase->create()
    #3 {main}
    thrown in C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php on line 198

    Error #2 - Getting this error when the account is already in the database (Ran the script the 2nd time after Error #1 - no other accounts are created)
    PHP Warning: curl_setopt_array(): cannot represent a stream of type MEMORY as a STDIO FILE* in C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php on line 190
    [18-Apr-2012 13:12:43] PHP Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 401' in C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php:198
    Stack trace:
    #0 C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php(246): kyBase::processRequest('/Base/User', 'PUT', Array, Array)
    #1 C:\inetpub\wwwroot\sts\KayakoAPI\kyObjectBase.php(171): kyBase::_put(Array, Array)
    #2 C:\inetpub\wwwroot\sts\ADUserSync.php(136): kyObjectBase->update()
    #3 {main}
    thrown in C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php on line 198

    Thanks!

     
  13. Dylan Lindgren

    Dylan Lindgren Established Member

    Ah yep, I know what's going on. Since I wrote this there has been a new PHP API release, and it appears that the new API must have some changes that break the script. I will fix this in a future release, but for the mean time please download version 1.0.0 of the API from http://forge.kayako.com/projects/kayako-php-api-library/files and use that as your API instead.

    I just tested the new API with my install and I was getting the exact same errors. Reverted back to the old one and the import script works now.

    Kind regards,

    Dylan
     
  14. Larry Yu

    Larry Yu Member

    Hi Dylan,

    It seems like changing the API version doesn't help. I'm still getting the exact error. I also downloaded a fresh copy as well just to see if I have a bad copy, but still the same result. Possible something else at fault? Thx.

     
  15. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi Larry,

    Firstly, in the Kayako PHP API please modify kyBase.php on line 170 from...

    PHP:
    case self::METHOD_PUT:
                    if (
    self::$put_memory_stream) {
                        
    $fh fopen('php://memory''rw');
                        
    fwrite($fh$request_body);
    to...

    PHP:
    case self::METHOD_PUT:
                    if (
    self::$put_memory_stream) {
                        
    $fh fopen('php://temp''rw');
                        
    fwrite($fh$request_body);
    That should fix the STDIO issue. Try running that and let me know if that fixes it for you.

    Secondly, I think I have found a bug in the Fusion/PHP API which I think may be causing another error. I have posted up a forum thread detailing the issue and will hopefully hear back from someone soon regarding it. In the meantime you may be able to work around the issue by deleting ALL users that my script has created, and then re-running the script. If it runs successfully with no errors, all the users should be inserted however on the second run it will give errors. If you find that you get errors on the first run and not all users are imported please post it up here and let me know what it is.

    Kind regards,

    Dylan
     
  16. Larry Yu

    Larry Yu Member

    Hi Dylan,

    I updated the code as indicated below and it did fix the "Memory as a STDIO File" error, but all other errors still exist. There is however a new "HTTP Error: 405" instead of the "HTTP Error: 401" on the 2nd run. Still only creating only the first user on the 1st run.

    1st Run (W/ updated code - Pretty much the same as previous error)
    PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0
    PHP Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 500' in C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php:198
    Stack trace:
    #0 C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php(235): kyBase::processRequest(NULL, 'POST', Array, Array)
    #1 C:\inetpub\wwwroot\sts\KayakoAPI\kyObjectBase.php(157): kyBase::_post(Array, Array)
    #2 C:\inetpub\wwwroot\sts\ADUserSync.php(146): kyObjectBase->create()

    2nd Run (W/ updated code - Fix "Memory as a STDIO FILE error, but with new "HTTP error: 405" error)
    PHP Fatal error: Uncaught exception 'Exception' with message 'HTTP error: 405' in C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php:198
    Stack trace:
    #0 C:\inetpub\wwwroot\sts\KayakoAPI\kyBase.php(246): kyBase::processRequest('/Base/User', 'PUT', Array, Array)
    #1 C:\inetpub\wwwroot\sts\KayakoAPI\kyObjectBase.php(171): kyBase::_put(Array, Array)
    #2 C:\inetpub\wwwroot\sts\ADUserSync.php(136): kyObjectBase->update()

     
  17. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi Larry,

    I've uploaded a new version of the script, version 1.1. Please try downloading that and let me know if it fixes the issue. I'm not sure if it will, however if it doesn't can you please private message me the settings you're using for your installation? Probably a good idea to blank out the API key/secret and the AD username/password before PMing me them. Just copy and paste directly from your script.

    Kind regards,

    Dylan
     
  18. Larry Yu

    Larry Yu Member

    Hi Dylan,

    Not pushing or anything, but just wondering if you got my PM last week with my results. Thanks for the help.
     
  19. Dylan Lindgren

    Dylan Lindgren Established Member

    Hi Larry, sorry yes I did get it I just haven't had a chance to look into it any further. The script is running 100% on my server without any errors so the only thing I can think of is it's a problem with your environment. Your configuration settings look ok to me.

    HTTP error 500's mean "Internal Server Errors"
    HTTP error 405's mean "Method not allowed"

    Can you please try turning ON error reporting in PHP and see what happens? I think that will instead of showing an internal server error 500, it will actually output the error message. This may give you more of an idea as to exactly what's failing. You should be able to do this by modifying the ADUserSync.php and adding a
    PHP:
    error_reporting(E_ALL);
    at the start of it, around about line 2 so it looks like this

    PHP:
    <?php
    error_reporting
    (E_ALL);
    /*--------------------------------------------
    | ACTIVE DIRECTORY TO FUSION SYNC SCRIPT
    |---------------------------------------------
    | Current Version: 1.0
    | Created by: Dylan Lindgren (dylan.lindgren@gmail.com)
    | Creation Date: 01/12/2011
    | Last Modified: 13/04/2011
    |
    */
    http://php.net/manual/en/function.error-reporting.php
    http://php.net/manual/en/errorfunc.configuration.php

    Kind regards,

    Dylan
     
  20. Larry Yu

    Larry Yu Member

    Thanks for all the help Dylan! Will try to get this to work with my developer. Will report back if I'm successful.
     

Share This Page