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.


Tuesday, June 8, 2021

php 5.3 / 5.4 on Ubuntu 20.04 / 18.04

Deploy php 5.3 or php 5.4 web application on latest Ubuntu LTS 20.04 or Ubuntu 18.04

If you want to deploy your older php application on latest Ubuntu or Centos server, 32 bit library error can be an issue. You might have tried to download and install older version of xampp but your newer 64 bit OS does not support 32 bit xampp hence you are not able to install it.

Do not worry about the issue. Here is the solution for you.

You need to install xampp inside a docker container and deploy your application there.

1. Install docker.

There are plenty of guides available which can help you to install docker on your Linux OS. Once docker is installed, follow the guide.

2. Pull an Ubuntu 12.04 image using command.

docker pull ubuntu:12.04

3. Launch a container. Here we need to map host system's port 80 with docker container's port 80 and /opt folder of host system with /opt folder of container. You can choose different port and directory of host system also.

But if you choose port 80 of host system, make sure no service is running on it. Kill all the services of port 80 of host and launch a container with mapped port 80 and mapped volume /opt using following command.

docker run -i -t -p 80:80 -v /opt:/opt ubuntu:12.04 /bin/bash

4. Now you are inside the container. You can confirm by command `uname -m` that it is 32 bit, now you can install xampp of required php version.

To reach inside the directory /opt of container, Run command

cd /opt; ls

You should be able to see all the folders of /opt of your host system in the container.

5. Now open your browser and download the xampp of php 5.3.5 using following url.

https://sourceforge.net/projects/xampp/files/XAMPP%20Linux/1.7.4/xampp-linux-1.7.4.tar.gz

Extract the compressed file and copy folder lampp in /opt.

If you have an existing folder lampp in /opt, make sure you have renamed it before copying php 5.3.5 lampp in the /opt, otherwise it can overwrite your existing lampp setup.

6. Start the lampp in the container terminal using command

/opt/lampp/lampp start

If you have closed the container terminal, login again using following commands.

sudo service docker start

sudo docker start `sudo docker ps -a | grep "12.04" | awk '{print $1}'`

sudo docker exec -t `sudo docker ps -a | grep "12.04" | awk '{print $1}'` /bin/bash

/opt/lampp/lampp start

7. Once lampp is started successfully, open a tab in the browser and open url

http://localhost/

You should be able to open xampp dashboard. Verify php version on phpinfo page.

Deploy the application in the same way you deploy on your host system.

Note : 

1. If you want to shift on existing lampp, stop the container and rename the current lampp as 12.04 and existing lampp as lampp in /opt.

2. Whatever changes you make in lampp folder of 12.04 in /opt host system, it will be updated in the container because /opt of host system is mapped with /opt of container.