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.

Wednesday, June 23, 2021

ffmpeg - Create a Video from Images

To create a video from images, you must have used software like Kdenlive and Shotcut. Yeah it is quite easy and fast in Shotcut but you cannot use UI softwares everytime for your task.

If you need to automate this task, you must need scripting. ffmpeg is an excellent command line tool to perform audio and video jobs.

Suppose you have six-seven images which you want to convert in a video, you have to consider these two important points.

1) Images should not appear and disappear abruptly. They should have some effect. Fade in and Fade out is the best effect you can add for your video.

2) All images should have same size, you will find this important when you will see a video of images with different size.

Here I have used image names 1.jpg, 2.png, 3.png, 4.png, 5.png, 6.png and 7.png. You can use jpeg/jpg images also. I have used first image as a black image, it provides correct effect of fade in when second image (originally my first) appears. Resolution of my images are 1312 x 706

This is the command to generate video from images.

ffmpeg -loop 1 -t 5 -i 1.jpg -loop 1 -t 5 -i 2.png -loop 1 -t 5 -i 3.png -loop 1 -t 5 -i 4.png -loop 1 -t 5 -i 5.png -loop 1 -t 5 -i 6.png -loop 1 -t 5 -i 7.png -filter_complex "[0:v]fade=t=out:st=4:d=1[v0]; \
 [1:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1]; \
 [2:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; \
 [3:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; \
 [4:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v4]; \
 [5:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v5]; \
 [6:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v6]; \
 [v0][v1][v2][v3][v4][v5][v6]concat=n=7:v=1:a=0,format=yuv420p[v]" -map "[v]" ouptput.mp4
First try with seven images for creating a video and make good understanding of command. Then you can reduce or increase number of images, you will find where exactly you have to make changes in the command.