Friday, July 3, 2009

How I solve the "PHP Fatal error: Class 'DOMDocument' not found in ....." problem on zend framework at the time of project creation.

I have fedora 9 with PHP 5 installed in my PC. While creating project using the command

" create project myproject"

on Zend framework(minimal) I have faced a PHP fatal error just like..

"PHP Fatal error: Class 'DOMDocument' not found in /var/www/html/ZendFramework-1.8.3/library/Zend/Tool/Project/Profile/FileParser/Xml.php on line 74"

I thought that the error is generated because I was trying to install minimal version. After then I have installed full version of Zend framework which is more than 38MB in size.

But the problem was not solved.

Again I start searching the net to find out any solution.

At last I have found a solution.....some one wrote a document almost 2 years ago. He said that the problem might occur because of unavailability of libhtml2 support for php and he suggested to install php-xml to solve the problem.

This suggestion helps me to solve the problem. Now it is working and I have already created projects on Zend framework.

Saturday, June 13, 2009

How I customize 'Change Password' plugin of SquirrelMail so that the plugin can change '/etc/passwd' & '/etc/shadow' of remote server.

The Scenario

In my organization we have following setup . Mail server has user accounts and runs SMTP and IMAP / POP service. Incomming mails are stored in mail server following normal mail route.

Users have the option of checking their mail from local network through installed mail clients like thunderbird / outlook etc. and checking them through webmail. http server runs webmail and access user inboxes IMAP and SMTP service from mail server.

The requirement was to enable user password change through squirrelmail interface.

I have faced problem when I installed 'Change Password' plugins in SquirrelMail system. The plugin can't change the password of mail user. This is because the working logic of 'Change Password' plugin is something different.

The working logic of 'Change Password' plugin

The 'Change password' plugin contains more than one php files and one executable ('chpasswd') file. The executable file is the core execution program of the plugin. This plugin can only work on '/etc/passwd' or '/etc/shadow' files of local server (http server) on which the SquirrelMail application is installed.

When ever an user issue the command to change the password through web form, the SquirrelMail executes 'chpasswd' command with proper parameters to achive the job.

The modified working logic of 'Change Password' plugin

I have changed the working logic of plugin to incorporate the remote password change feature.

The new working logic is, when ever some user will issue the command to change the password, the SquirrelMail server (http server) will pass the control of execution to the mail server to change the password of mail server rather than http server.

The implementation of modified working logic

To implement the logic, first of all I break up the whole job in three parts.

Part One

In the first part I have configured the mail server by coping 'chpasswd' executable program from the plugin directory of http server to the same directory of mail server. In my case it is in '/usr/share/squirrelmail/plugins/change_passwd'. At the time of copy I have followed all the guidance as guided by the README file of plugin. Please check the README file of the plugin for the configuration commands.

Part Two

In the second part I have modified the configuration php file of plugin itself. The actions I have followed in second phase are listed below.

1. Open the file config.php from the 'Change password' plugin directory.
2. Find out the line containing the string

$overridePathToChpasswd = '';

3. Replace the line with

$overridePathToChpasswd = 'ssh {user}@{ip_address} {full_path}/chpasswd';

[PLEASE NOTE: replace the {user} with your administrative user_id of your mail server, replace {ip_address} with your mail server's ip address and also replace the {full_path} with absolute path of 'chpasswd' program on mail server]

Part Three

This is the most important part in this customization phase. As we know ssh is secured terminal connection between server & client. ssh has two type of authentication method; one is password authentication and another is encryption key authentication. In case of password authentication ssh will ask the user for password interactively. Now, imagine how can one enter password non-interactively through php code. No way..! way left,as I know. I have used encryption key based authentication (without pass phrase) procedure. The steps are as follows..

1. Find out which server in this case is acting as ssh client. In my case the http server is acting as ssh client and the mail server as ssh server.

2. Now find out which linux user is the owner of the http/apache server. You can find out this information from the configuration file 'httpd.conf' of apache in /etc/httpd/conf/ directory.

3. Switch to that user from root using the command.

su - apache

[NOTE 1: In my case the 'apache' user is the owner of http/apache server]
[NOTE 2: debian users can do this very easily. But the fedora/redhat users can't., Because in fedora/redhat 'nologin' shell has been defined as login shell in /etc/passwd file.


4. Open /etc/passwd file from root user. Go to the proper line where login information has been written for that specific user who is the owner of http/apache server. In my case it is 'apache'. Now replace the characters '/sbin/nologin' with '/bin/bash' or '/bin/sh' from that particular line only. Now you can switch to the user, owner of the http/apache server issuing the command.

su - apache


5. Now issue the command.

ssh-keygen -t dsa

[NOTE: System will ask for a pass phrase. Keep it blank and press enter for pass phrase field]

A file '' will be created in the directory '/home/{user}/.ssh/'. In my case it is in '/home/apache/.ssh' directory.

6. Copy the dsa public key file to the user directory of administrator user of ssh server(in my case it is in mail server).

7. Issue the command

cat >> .ssh/authorized_keys

Now, please try to login from ssh client to ssh server. If all the processes have been done properly then it is highly possible to login from ssh client to ssh server.

Every thing have been done. Now, try to change the password from SquirrelMail web form.