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
";

Monday, November 23, 2009

Enable SpellChecker in Request Tracker FCK editor

SpellerPages can configure for enabling spell checker in FCK editor. Do the following steps for enable SpellerPages in FCKEditor
covert spellchecker.pl file to unix compatible then copy the file to Apache CGI directory


# dos2unix spellchecker.pl
# cp spellchecker.pl /usr/lib/cgi-bin/

Configure fckconfig.js file to use SpellerPages as spell checker in FCK Editor. make below changes in fckconfig.js

FCKConfig.SpellChecker                  = 'SpellerPages';
FCKConfig.SpellerPagesServerScript = '/cgi-bin/spellchecker.pl' ;       // Available extension: .php .cfm .pl
FCKConfig.FirefoxSpellChecker   = true ;
Update spellchecker.pl as below 

my $spellercss = '/rt/NoAuth/RichText/FCKeditor/editor/dialog/fck_spellerpages/spellerpages/spellerStyle.css'; 
my $wordWindowSrc = '/rt/NoAuth/RichText/FCKeditor/editor/dialog/fck_spellerpages/spellerpages/wordWindow.js';
my $aspell_cmd = '/usr/bin/aspell';
 
This will enable Spell Checking option in FCK editor

Friday, October 9, 2009

Using Perl for Managing LDAP

Perl script for adding LDAP attributes

For accessing LDAP database from perl scripts install Net::LDAP perl module.
# aptitude install libnet-ldap-perl 
 
Script will search for DN which have mail attribute and objectClass is  
posixGroup 
Script only return the group which does not have attribute company 
Script will add attribute company and value blablabla to those DN returned by
search filter  
 
#!/usr/bin/perl
# This script is used for adding new attribute and values 
 
use Net::LDAP;
$ldap = Net::LDAP->new("localhost");
$ldap->bind("cn=admin,dc=example,dc=com", password=>"secret");
$mesg = $ldap->search(filter=>"(&(mail=*)(&(objectclass=posixGroup)\
                                    (!(company=*))))",base=>"dc=example,dc=com");
@entries = $mesg->entries;
foreach $entry (@entries){
       print "DN: " . $entry->dn(). "\n";
       $mesg = $ldap->modify ($entry->dn(), \
               add => {"company" => "blablabla"});
}

Delete LDAP attribute using Perl scripts

If you want to delete any attribute. You can use this in ldapmodify section  

# $mesg = $ldap->modify ($entry->dn(), delete => { company => [] });

How to Add multiple values for an attributes

We require two files in which one file contains list of group DN (Here referred as group_list) and another contains list of employees name that to be added to employee (referred as employees.txt in this script)
Script will set company value to blablabla and add each employees to employee Create a script add_employee.pl with below content 


#!/usr/bin/perl

use Net::LDAP;

$ldap = Net::LDAP->new("localhost");
$ldap->bind("cn=admin,dc=example,dc=com", password=>"secret");
while(<>) {
      chomp $_;
      $dn = $_;
      print "DN: $_.\n";
      $mesg = $ldap->modify ($dn, add => {"company" => "blablabla"});
      open (MYFILE, 'employees.txt');
      while () {
                        chomp;
                        print "$_\n";
                        $mesg = $ldap->modify($dn, add => { "employee" => "$_"} );
      }
close (MYFILE);
}
$ldap->unbind();
Run script group_policy.pl using below command

#  cat group_list| ./add_employee.pl

Wednesday, October 7, 2009

ssh-copy-id not accepting port other than default

When I was copying my ssh id to my client machines using ssh-copy-id, I am unable to copy to hosts where ssh-server running on different port.
After a long search i found there is a bug already raised in Debian bug report #431731.

Cheers for debian :)
using patches provided in the bug report I patched my ssh-copy-id and I was able to fix my issue

I would like to share the patched ssh-copy-id file. To avoid the conflicts I have named the script as ssh-copy-id-new.

Download the script from below mentioned site.

Copy the script to /usr/local/bin directory 
# cp ssh-copy-id-new  /usr/local/bin

Change script permission to be executable 
# chmod +x ssh-copy-id-new

Now run the ssh-copy-id-new with port number
# ssh-copy-id-new -p 28 -i ~/ssh-id user@remote_server


Dowload link ssh-copy-id-new



QOTD plugin in Squirrelmail

Squirrelmail qotd plugin is not showing any quotes nowadays. Please find the fix explained below.


How qotd plugin works ?
QOTD plugin retrieves random quotes from qotd.org site. Then it will be formatted using explode and str_replace functions.
for more about these functions can be found here.

What happened to qotd plugins now?

qotd.org site has modified the random quotes output. Due to this plugin is unable to find the pattern and the result will be a blank text.

How to fix this ?

After digging in to the code, I was able to fix this issue with small changes. 
 


Go to plugins directory (/usr/share/squirrelmail/plugins/qotd_login)
Edit functions.php using favorite editor
Under parse quote out of web page
replace `font size="-1"` with `strong`


This will fix your problem, cheers !!


Thursday, September 17, 2009

Testing Bandwidth in linux machine

Here I am giveing couple of tools which can be used to Test bandwidth in Linux

1. Bing
Bing determines bandwidth  on  a  point-to-point  link  by sending  ICMP  ECHO_REQUEST  packets  and  measuring their roundtrip times for different packet sizes on each end  of the link.

To Install bing :
aptitude install bing
Where I get Help ???
* man bing
* http://linux.die.net/man/8/bing

2.
Bandwidth

BandwidthD tracks usage of TCP/IP network subnets and builds html files with graphs to display utilization.
Charts are built by individual IPs, and display utilization over 2 day, 8 day, 40 day, and 400 day periods.
Fur‐thermore, each ip address’s utilization can be logged out at intervals of 2.5 minutes, 10 minutes, 1 hour or 12 hours in cdf format.
HTTP, TCP, UDP, ICMP, VPN, and P2P traffic are color coded
How to install:
aptitude install bandwidthd
Where I get Help ???
* man bandwidthd