Popular Posts

Saturday, February 7, 2015

Change LDAP password using php script

Hey Guys,

Hope you all are doing well :)

Today I would like to share how to change LDAP password using simple web interface (php). We are using openldap configured on linux server and I wanted to make simple web interface to change openldap password, below are the scripts and procedure how did I achieve it.

1. Create a shell script to change ldap password and test it for some user.


E.g. - This is my shell script.

Please note that, values marked with red colour need to be replaced with your ldap configuration settings.


############Start of the Script##############

#!/bin/bash
#Script developed by - Kuldeep Kulkarni

if [ $# -ne 3 ]
then
        echo "Invalid number of arguments!"
        exit 10;
fi


ldappasswd -x -D "cn="Admin account username(e.g. Manager)",dc=your-domain,dc=com" "uid=$1,ou=people,dc=your-domain,dc=com" -a $2 -s $3 -w "your ldap password for admin user"


pass_change_status=$?

if [ $pass_change_status -eq 0 ]
then
        echo "0";
else
        echo  "Found error while resetting your password! Please contact Admin team.";   
fi


############End of the Script##############


2. Save above script as /var/www/html/change_ldap_pass.sh on your openldap server  (assuming here that you have httpd pkg installed on your linux machine )



3. Create /var/www/html/index.php script with below contents on your openldap server



############Start of the Script##############

<?php
$message="";
function changePassword($username, $old_password, $new_password)
{
$return_message=exec("sh change_ldap_pass.sh $username $old_password $new_password");
if($return_message=="0")
 {
   echo "Your password has been Changed!";
 }
 else
 {
        echo "Error while changing password : $return_message";
 }

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Password Change Page</title>
<style type="text/css">
body { font-family: Verdana,Arial,Courier New; font-size: 0.7em; }
th { text-align: right; padding: 0.8em; }
#container { text-align: center; width: 500px; margin: 5% auto; }
.msg_yes { margin: 0 auto; text-align: center; color: green; background: #D4EAD4; border: 1px solid green; border-radius: 10px; margin: 2px; }
.msg_no { margin: 0 auto; text-align: center; color: red; background: #FFF0F0; border: 1px solid red; border-radius: 10px; margin: 2px; }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<div id="container">
<h2>Password Change Page</h2>
<p>Your new password must be 8 characters long or longer and have at least:<br/>
one capital letter, one lowercase letter, &amp; one number.<br/>
You must use a new password, your current password<br/>can not be the same as your new password.</p>
<?php
      if (isset($_POST["submitted"])) {
        changePassword($_POST['username'],$_POST['oldPassword'],$_POST['newPassword1'],$_POST['newPassword2']);
}
 ?>
<form action="<?php print $_SERVER['PHP_SELF']; ?>" name="passwordChange" method="post">
<table style="width: 400px; margin: 0 auto;">
<tr><th>Username:</th><td><input name="username" type="text" size="20px" autocomplete="off" /></td></tr>
<tr><th>Current password:</th><td><input name="oldPassword" size="20px" type="password" /></td></tr>
<tr><th>New password:</th><td><input name="newPassword1" size="20px" type="password" /></td></tr>
<tr><th>New password (again):</th><td><input name="newPassword2" size="20px" type="password" /></td></tr>
<tr><td colspan="2" style="text-align: center;" >
<input name="submitted" type="submit" value="Change Password"/>
<button onclick="$('frm').action='changepassword.php';$('frm').submit();">Cancel</button>
</td></tr>
</table>
</form>
</div>
</body>
</html>


############End of the Script##############


4. Hit $IP_address_of_openldap_server or $openldap_server_name/index.php in your browser and it should work!






5. Feel free to comment if you face any issues :)



-Kuldeep Kulkarni
kuldeepkulkarni09@gmail.com

Sunday, October 5, 2014

dstat command with examples

What is dstat ?

dstat is one of the powerful utility in the Linux environment, using it we can get many kinds of performance related statistics to analyse the system performance. system admin generally use this to monitor system's performance.

How to install dstat in rpm based environments ?

yum install dstat

How to use dstat ?

Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics

Dstat options:

  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats
  -n, --net              enable network stats
     -N eth1,total          include eth1 and total
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats

  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total

  --bw, --blackonwhite   change colors for white background terminal
  --float                force float values on screen
  --integer              force integer values on screen
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers
  --noupdate             disable intermediate updates
  --output file          write CSV output to file

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)

Sunday, June 15, 2014

How to safely uninstall linux from dual boot windows 7

If you have dual boot OS installed on your system and want to uninstall linux safely from it then here are the easy instructions :

By default GRUB is the boot-loader when you install dual boot OS i.e linux and windows that means without modifying MBR you cannot simply uninstall linux!

Important Note : Please backup your stuff from linux before moving ahead with the steps!


1. Download EasyBCD tool in windows 7 from below link.

http://neosmart.net/Download/Register/1

2. Install EasyBCD and run it as Administrator

3. Go to the option - BCD Deployment ( see highlighted section in below screenshot )




4. Select "Install the Windows Vista/7 bootloader to the MBR" option (highlighted in yellow colour in above screenshot)

5. Click on Write MBR button - This will remove GRUB and install windows 7 boot loader.

6.  Now click on Edit Boot Menu option (Highlighted in red circle in below screenshot)


7. Select Windows 7 ( Red underline in below screenshot )

8. Click on "Skip boot menu" radio button ( highlighted in yellow color in below screenshot )


9. Finally click on "Save Settings" option






10. Congratulations!! You have successfully modified default boot loader from GRUB to windows 7 :)

 11. Now if you want, you can gain your linux disk back to windows by deleting linux partition from windows disk management tool.