Monday, July 5, 2021

php LDAP admin Import Sample Users | Import Sample Data LDAP Server

LDAP Server : Import Test Users

php LDAP admin is a user friendly client to operate LDAP server. If you want to use LDAP user data for your task, you might need dummy users. There are multiple reasons such as security policy when real users' data cannot be used for any automated task. 

Here we will see how you can import sample or dummy user data which is same as real data.

Steps :

1. Download zip file of LDIF Generator from here.

2. Extract it and open the software using command

java -jar LDIFGen.jar

3. Add Domain Component (dc) name of your LDAP server in the field "Base added to Generate Records". In my case it was

dc=example, dc=com

4. Number of records can be 500 or 5000 depends on your requirement.

5. Field 'Directory where input data is stored' : This is the path of the 'data' directory which you can find in the extracted LDIF generator folder. 

Make sure D is capital in the path name if it is capital in the extracted folder.

6. Output directory path can be anywhere on the system. Make sure you have write permission in the folder.

7. Click on 'Run' button. An output file output.ldif file will be generated.

8. Open php LDAP Admin and click on import option in the left menu. Select the output.ldif file and click on Proceed.

9. All sample users will be imported into the LDAP server.

You can see the complete procedure in the following video.




 

 


Friday, June 25, 2021

php LDAP Admin - Fatal error: Cannot redeclare password_hash

phpldapadmin - Fatal error: Cannot redeclare password_hash() in /var/www/html/phpldapadmin/lib/functions.php on line 2225

Make sure you have php 7.0 for phpldapadmin. The solution is tested on php 7.0

Solution :

If you install the phpldapadmin using command

sudo apt install phpldapadmin

in Ubuntu or any other Debian based system. You will not get this error  

Same is applied for Centos or Fedora.

sudo yum install phpldapadmin

This is an easy solution that's why you should not use the downloaded zip package. Use default package installation on command line. There should be less chances that you get the error.

But if you have downloaded phpldapadmin 1.2.2 or 1.2.3 zip file from sourceforge.net, you might get this error. If you have any other version, still this solution will fix the error.

Make sure you have php 7.0 where you have deployed the downloaded package of phpldapadmin.

Solution :

Change text password_hash to password_hash_custom in the all files of the lib directory.

This sed command will do the trick. Make sure you are in the phpldapadmin directory before executing the command.

sudo sed -i 's/password_hash/password_hash_custom/g' lib/*
After updating the text password_hash, the above error will be fixed but there are chances that you might get following error.

E_WARNING: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
To solve this error update the whole code of the function function dn_unescape($dn) in /var/www/html/phpldapadmin/lib/functions.php with
function dn_unescape($dn) {
    if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
        debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);

    if (is_array($dn)) {
        $a = array();

        foreach ($dn as $key => $rdn) {
            $a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/',
                function ($m) {
                    return ''.chr(hexdec('\\1')).'';
                },
                $rdn
            );
        }

        return $a;

    } else {
         return  preg_replace_callback('/\\\([0-9A-Fa-f]{2})/',
             function ($m) {
                return ''.chr(hexdec('\\1')).'';
            },
            $dn
        );
    }
}
This will solve the front error but if you click on the tree icon to maximize the tree items, you might get following error again.
E_WARNING: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
To solve the error completely update the whole code of the private function function dn_unescape($dn) in /var/www/html/phpldapadmin/lib/ds_ldap.php with
    private function unescapeDN($dn) {
        if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
            debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs);

        if (is_array($dn)) {
            $a = array();
            foreach ($dn as $key => $rdn) {
                $a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/',
                    function ($m) {
                        return ''.chr(hexdec('\\1')).'';
                    },
                    $rdn
                    );
            }

            return $a;

        } else
             return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/',
                function ($m) {
                    return ''.chr(hexdec('\\1')).'';
                },
                $dn
            );
    }

It should fix all errors of function.php and you should be able to use phpldapadmin smoothly.

You can see the complete solution here.


 

ejabberd Error - CRASH REPORT Process with 0 neighbours exited with reason

CRASH REPORT Process <0.645.0> with 0 neighbours exited with reason: {process_limit,{max_queue,xxxx}} in p1_fsm:terminate/8 line 755

Solution : 1
Change @all@ to @online@ in shared roster group. 
 
Now it does not disconnect immediately because it loads only online users instead of all registered users. 
 
@all@ was showing error because ejabberd was loading all registered users in the list that's why it was getting crashed but @online@ is not giving any error now because all registered users are not online yet. 
 
If you have more than 1000 registered users. This solution might work for you as all 1000 users might not be online at once and there are high chances that system will not have enough load.

Solution 2 :
Update following attribute in the ejabberd config file conf/ejabberd.yml
max_fsm_queue: 10000
You will find the attribute under "port 5222:" section

listen:
  -
    port: 5222
    module: ejabberd_c2s
    certfile: "/home/ubuntu/ejabberd-16.06/conf/server.pem"
    starttls: true
    resume_timeout: 0
    protocol_options:
      - "no_sslv3"
    max_stanza_size: 65536
    shaper: c2s_shaper
    access: c2s
    max_fsm_queue: 100000
I have tried this and
I did not get above error for 2000 users even if @all@ is selected in shared roster group.

I would suggest you to implement both solutions.