I love Free Software!

Pages

Funny Quotes to Think

When you say "I wrote a program that crashed Windows", people just stare at You blankly and say "Hey, I got those with the system, for free"

-Torvalds, Linus(1995-03-08)-

Wednesday, December 30, 2009

How to configure bridge in Debian

A bridge connects two or more different physical ethernets together to form one large (logical) ethernet.
The physical ethernets being connected together correspond to network interfaces in your linux box. The bigger (logical) ethernet corresponds to a virtual network interface in linux


Install package bridge-utils in your linux box
#     aptitude install bridge-utils

Here my physical ethernets are `eth0` and `eth1` to form a logical ethernet `br0`

create an instance of the bridge.
#     brctl addbr br0

Now enslave eth0 and eth1 to this bridge
#    brctl addif br0 eth0
#    brctl addif br0 eth1

We only need one IP address for the bridge. This address we assign to br0.
eth0 and eth1 should not have IP addresses allocated to them.
# ifconfig eth0 0.0.0.0
# ifconfig eth1 0.0.0.0
# ifconfig br0 my.ip.address.here

This will bridge `eth0` and `eth1` to form a logical ethernet `br0`

Tuesday, December 29, 2009

CAPTCHE in PHP email form







Here I am giving a small PHP email program using CAPTCHE verification

Download the reCAPTCHA Library, unzip it, and copy recaptchalib.php to the directory where your forms live 

 
If you don't have API key then sign UP for get key

 
You can modify below php code to match your form


<html>
<head>
<title> CAPCHE verification for email script </title>
</head>
<body bgcolor="#151B8D">
<form action="" method="post">
<!-- Display all fiels in a Table -->
tr><td width=30%>Name<input type = "text" name = "reported" size = "30"></td>
<td width = 20%>Location <input type = "text" name = "location" size = "30"></td></tr>
<tr><td width=40%>Enter Your Email Address</td>
<td width =60%><input type = "text" name = "name" size = "60"></td></tr>
<tr><td width=40%>Comments</td>
<td width=60%><TEXTAREA NAME="comments" COLS=77 ROWS=3></TEXTAREA></td></tr>
is_valid) {
rtsendmail($email,$_POST["name"],$_POST["comments"],$_POST["reported"],$_POST["location"]);
header('Location:thankyou.html');
} else {
header('Location:error.html');
# echo "Error";
}
}
echo recaptcha_get_html($publickey, $error);
?>
<p><input type = "submit" value = "Register">
<input type = "reset" value = "Clear "></p>
</form>
</body>
</html>

Saturday, December 26, 2009

ServerTokens in apache2 debian

ServerTokens will display description of the generic OS-type of the server as well as information about compiled-in modules.
By setting this to `prod` will avoid displaying all module information under server-generated documents (error messages, mod_proxy, ftp directory listings, mod_info output). The default for this directive is 'Full'

In debian you can set this directive in /etc/apache2/conf.d/security file

Also set ServerSignature Off to diable Signature

This will helps to hide your Apache server information from others

Look at apache online document for more information

http://httpd.apache.org/docs/2.2/mod/core.html

Tuesday, December 15, 2009

Search and replace content of file in entire directory

How can I search and replace file contents??

Every editor will have an options to search and replace content of a file .When we require to search all files in a directory and replace with new string, we can use below command

perl -pi -e 's/<Search-string>/<Replace-String>/' *

For example If You want to replace windows with linux in all perl files under a directory, You can use this command

perl -pi -e 's/windows/linux/' *.pl

Monday, December 7, 2009

Perl script for adding a LDAP group members to another group

This script will help you to add an LDAP group to another group.
  •  Script will accept two arguments. Parent group and child group (Group which you need to be merged)
  • Script will take each member from child group and add to parent group
  • If member is already exists, script will skip adding member
  • If member does not exists, this will add attributes `member` and `memberUid`

#!/usr/bin/perl
# This script is used to merge members of one group to another.
# Script need two arguments parent and child groups. All members from child group will be -
# added to Parent group. Script skip adding if member already exist.
# Created by Praveen C (praveen.velu84@yahoo.com)

use Net::LDAP;

$ldap = Net::LDAP->new("localhost");
$ldap->bind("cn=admin,dc=example,dc=com", password=>"secret");

# Get Parent Group Email-ID here

print "Enter Email id of parent group:";
$parentid = <STDIN>
chomp $parentid;

# Get Child group Email-ID(Group need to be merged)

print "Enter Email id of child group:";
$childid = <STDIN>
chomp $childid;

# Search for Both Parent and Child groups in ldap

$parent = $ldap->search(filter=>"(&(mail=$parentid)(objectclass=posixGroup))"
, base=>"dc=example,dc=com");
$child = $ldap->search(filter=>"(&(mail=$childid)(objectclass=posixGroup))"
, base=>"dc=example,dc=com");
$pentry = $parent->entry(0);
$centry = $child->entry(0);

# Assign `maildrop` of child group in to array
@cemails = $centry->get( 'maildrop' );

# Get count of members in child group
my $max = scalar @cemails;
print "$max Members found in Child Group\n\n";
print "Parent DN: " . $pentry->dn(). "\n";
print "Child DN: " . $centry->dn(). "\n";
for( my $index = 0 ; $index < $max ; $index++){ $r = $ldap->compare( $pentry->dn(),attr => 'member',value => @cemails[$index]);
if($r->code == 5){
$getuid = $ldap->search(filter=>"(&(mail= @cemails[$index])(objectclass=posixAccount))"
, base=>"dc=example,dc=com");
$uentry = $getuid->entry(0);
@myuid = $uentry->get( 'uid' );
$msg = $ldap->modify($pentry->dn(),add=>{'member' => @cemails[$index]});
$msg = $ldap->modify($pentry->dn(),add=>{'memberUid' => @myuid[0]});
print "Adding @cemails[$index] with memberuid @myuid[0]\n";
}
else{
print "Member @cemails[$index] already exists\n";
}
}

How to backup postgres database without issuing password

pq_dump command does not accept any password as argument. Here I am adding a small script which will
help you to take backup of your postgres database

#!/bin/bash

TODAY=`date +%b%d%Y`
DST=/path/to/put/backup

export PGPASSWORD=password #Adding postgres password in script
find $DST/* -maxdepth 0 -type f -mtime +40 -exec rm -v '{}' \;
pg_dump -U dbuser -h localhost dbname | bzip2 -c > $DST/pg.db.$TODAY.bz2

Perl script for converting a string to md5_base64

This script will convert a string to md5_base64 digest. You must install libmd5-perl for running this script. This will be useful for storing passwords in md5_base64 digests

#!/usr/bin/perl -w

use warnings;
use Digest::MD5 'md5_base64';

print "Enter your Password:";
my $pass = ;
chomp $pass;
print "Digest md5_base64 :\t", md5_base64($pass), "\n
";