Using FOP2 Phonebook with LDAP server

Hi,

I've a Freebpx installed with about 400 contacts in a openLDAP directory. My customer uses FOP2. He manages only the LDAP directory.

Can I make a connection between FOP2 Phonebook and the LDAP directory ? So when he add a contact into LDAP, it will also be automaticaly add to FOP2 Phonebook ? And so on...

Regards.

Comments

  • searches from the dial box are done via the vphonebook.php file, you could adapt that php code to look into openldap instead of doing mysql searches. Support is not done, but it is standard php and if you have time and a little bit of an idea, you can get that working.

    Best regards,
  • Dear,
    Is there any update concering this request?
    Regards.

  • Hi, not for now...

  • FOP2 has its own phonebook/contacts and scripts to tie that with the switchboard itself. Code is there for users to modify if they so like/need.
    The dial box will query the visual_phonebook table that the contacts app uses, but it can be modified, as I expalined originally, as it is a standard php script. You are free to modify it to query whatever you want instead of FOP2 tables.

    In any case, that feature is not on the roadmap, you can purchase development time if you want us to work on this particular integration, or just look at doing it yourself, it is just one php script (vphonebook.php) that is used for querying contacts from the dial box.

  • Thanks for the answer. Will try to do something before paid for a full licence. I have also see VOP which could do the trick. Will give a try.
    Regards.

  • Whitch syntax does the result have to be return for matching contact form query?

  • Hi,
    Ideallly you should work directly by modifying the vphonebook.php script and adding your custom query to it, replacing or not the ones provided. Return format is a json array like:

    [
      {"name":"","value":"John  <1234567>"},
      {"name":"","value":"Peter  <7654321>"}
    ]
    
  • edited October 2019

    Thanks ;)
    Yes I am working on a separate php file for testing only and then I will modify vphonebook.php.

  • edited October 2019

    I have wrote a little script to query on LDAP and formating the result in a json array but not working when adding it in vphonebook.php

    <?php
    
    // ---------------------------- VARIABLES ----------------------------
    $ldapURL = 'LDAP_URL';
    $ldapPort = 389; // Port par defaut = 389
    $ldapVersionProtocole = 3; // Version par defaut = 2
    $ldapIdentifiant = 'cn=ADMIN,dc=DOMAIN,dc=COM';
    $ldapMotDePasse = 'PASSWD';
    
    // ---------------------------- CONNEXION ----------------------------
    $ldap = ldap_connect($ldapURL, $ldapPort);
    if (false === $ldap) die('Echec de la connexion');
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $ldapVersionProtocole);
    $retour = ldap_bind($ldap, $ldapIdentifiant, $ldapMotDePasse);
    if (false === $retour) die('Echec de l\'authentification (ou de la connexion)');
    
    // ---------------------------- RECHERCHE ----------------------------
    $dn = "OU=PERSON,DC=DOMAIN,DC=COM";
    $recherche = "UID=*$texto*";
    $requete = ldap_search($ldap, $dn, $recherche);
    if (false === $requete) die('La recherche a echoue');
    
    // ---------------------------- RESULTAT ----------------------------
    $resultats = ldap_get_entries($ldap, $requete);
    $myArray = array();
    for ($i=0; $i<$resultats["count"]; $i++) {
        $myArray[] = "{\"name\":\"\",\"value\":\"" . $resultats[$i]["cn"][0] . " <" . $resultats[$i]["telephonenumber"][0] . ">\"}";
    }
    
    // ---------------------------- FORMATAGE ----------------------------
    //print_r($myArray);
    $results = json_encode($myArray,JSON_UNESCAPED_UNICODE);
    $results = str_replace('\"', '"', $results);
    $results = str_replace('"{', '{', $results);
    $results = str_replace('}"', '}', $results);
    
    // ---------------------------- FERMETURE ----------------------------
    ldap_close($ldap);
    
    return $results;
    
    ?>
    
  • Hi,

    You must add before your code something like this:

    $texto     = $_REQUEST['term'];
    

    What happens when you use the dial box and start typing something?

  • edited October 2019

    Thank Nicolas for your help.
    Finally as I only use ldap for my search my vphonebook.php look like

    <?php
    
    $texto     = $_REQUEST['term'];
    
    // ---------------------------- VARIABLES ----------------------------
    $ldapURL = 'LDAP_URL';
    $ldapPort = 389; // Port par defaut = 389
    $ldapVersionProtocole = 3; // Version par defaut = 2
    $ldapIdentifiant = 'cn=ADMIN,dc=DOMAIN,dc=COM';
    $ldapMotDePasse = 'PASSWD';
    
    // ---------------------------- CONNEXION ----------------------------
    $ldap = ldap_connect($ldapURL, $ldapPort);
    if (false === $ldap) die('Echec de la connexion');
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $ldapVersionProtocole);
    $retour = ldap_bind($ldap, $ldapIdentifiant, $ldapMotDePasse);
    if (false === $retour) die('Echec de l\'authentification (ou de la connexion)');
    
    // ---------------------------- RECHERCHE ----------------------------
    $dn = "OU=PERSON,DC=DOMAIN,DC=COM";
    $recherche = "UID=*$texto*";
    $requete = ldap_search($ldap, $dn, $recherche);
    if (false === $requete) die('La recherche a echoue');
    
    // ---------------------------- RESULTAT ----------------------------
    $resultats = ldap_get_entries($ldap, $requete);
    $myArray = array();
    for ($i=0; $i<$resultats["count"]; $i++) {
        $myArray[] = "{\"name\":\"\",\"value\":\"" . $resultats[$i]["cn"][0] . " <" . $resultats[$i]["telephonenumber"][0] . ">\"}";
    }
    
    // ---------------------------- FORMATAGE ----------------------------
    //print_r($myArray);
    $results = json_encode($myArray,JSON_UNESCAPED_UNICODE);
    $results = str_replace('\"', '"', $results);
    $results = str_replace('"{', '{', $results);
    $results = str_replace('}"', '}', $results);
    
    // ---------------------------- FERMETURE ----------------------------
    ldap_close($ldap);
    
    echo $results;
    
    ?>
    
  • Here is the full fixed code:

    <?php
    $texto     = $_REQUEST['term'];
    
    // ---------------------------- VARIABLES ----------------------------
    $ldapURL = 'LDAP_URL';
    $ldapPort = 389; // Port par defaut = 389
    $ldapVersionProtocole = 3; // Version par defaut = 2
    $ldapIdentifiant = 'cn=ADMIN,dc=DOMAIN,dc=COM';
    $ldapMotDePasse = 'PASSWD';
    
    // ---------------------------- CONNEXION ----------------------------
    $ldap = ldap_connect($ldapURL, $ldapPort);
    if (false === $ldap) die('Echec de la connexion');
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $ldapVersionProtocole);
    $retour = ldap_bind($ldap, $ldapIdentifiant, $ldapMotDePasse);
    if (false === $retour) die('Echec de l\'authentification (ou de la connexion)');
    
    // ---------------------------- RECHERCHE ----------------------------
    $dn = "OU=PERSON,DC=DOMAIN,DC=COM";
    $recherche = "UID=*$texto*";
    $requete = ldap_search($ldap, $dn, $recherche);
    if (false === $requete) die('La recherche a echoue');
    
    // ---------------------------- RESULTAT ----------------------------
    $resultats = ldap_get_entries($ldap, $requete);
    $myArray = array();
    for ($i=0; $i<$resultats["count"]; $i++) {
        $myArray[] = "{\"name\":\"\",\"value\":\"" . $resultats[$i]["cn"][0] . " <" . $resultats[$i]["telephonenumber"][0] . ">\"}";
    }
    
    // ---------------------------- FORMATAGE ----------------------------
    //print_r($myArray);
    $results = json_encode($myArray,JSON_UNESCAPED_UNICODE);
    $results = str_replace('\"', '"', $results);
    $results = str_replace('"{', '{', $results);
    $results = str_replace('}"', '}', $results);
    
    // ---------------------------- FERMETURE ----------------------------
    ldap_close($ldap);
    
    echo $results;
    
    ?>
    
  • edited October 2019

    Yes! Thanks for pointing my fault. As I'm not using this query in a function, I forgot changing return $results; to echo $results;
    I firstly trying to add this code inside the original in a function with no luck. Then I have blank vphonebook.php and fill it with this code only but still not working. Finally Nicolas help me to fix the problem.

Sign In or Register to comment.