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)-

Thursday, August 12, 2010

Shell script to export roundcube address book to csv

Below shell script will convert roundcube address book to csv. I am using postgresql for roundcube database. ouput csv file can found in /tmp folder

#!/bin/bash
# Roundcube Address book must be stored in PostgreSQL database.
# This script is created by Praveen C. please feel free to contact me on praveen.velu84@yahoo.com-
# for any query. You can modify this script to suit your requirement

# Enter roundcube user_name. Script will query this user in DB and export Address book
USER="user_name"
 
# Export your roundcube database passwor. This password will be used for `psql` command
# This will help us to avoid psql prompt for password
export PGPASSWORD=password

#  Find the `user_id` of the user
echo "COPY(SELECT user_id from users where username='$USER') \
                   TO STDOUT" | psql -h localhost -U roundcube  \
                   -o /tmp/rc_query_id roundcube

# Read user_id stored in file rc_query_id file and store to variable _USER_ID
user_list=`cat /tmp/rc_query_id`
for id in $user_list; do
_USER_ID=$id
done

# Query user contacts in and sent output to csv.
echo "COPY (SELECT name,email,firstname,surname from contacts where user_id=$_USER_ID) \
                     TO STDOUT with CSV HEADER" | psql -h localhost -U roundcube \
                     -o /tmp/$USER.csv roundcube

Tuesday, August 3, 2010

PHP script to monitor your multiple ISP link connected to firewall


I have configured multiple ISP links in a linux firewall. But it is very difficult for users to understand which like is up or down. I decided to create a simple webpage which gives the status of each link in a  webpage. This will avoid the hassle of login to linux machine as a normal user and running commands with root privilage


You can use php and fping to check your ISP links status. Make sure that fping is installed in your firewall.
For a better appearance I am using images to show status of link
Image Courtesy:  Open ClipArt

Image which I used to show when a link is Active. Image name is  up.png

Image which I used to show when a link is down.  Image name is down.gif

I have copied both images in to folder img. Below is the php script. For checking the ping response I am using OpenDNS IP address as my destination server


<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Link Monitor</title></head><body>
<?
// This is the remote host used for fping. Do not change. I am using OpenDNS IP
$remote_host = "208.67.222.222";
// Add you links in to array. Chang these IP address according to IP addres configured in your firewall. You can  one or more IP address in to array
$isps = array('111.222.333.444','555.666.777.888');
$status = array();

foreach ($isps as $isp) 
{
   $fping = `/usr/sbin/fping -u -S$isp $remote_host`;
   if ($fping == "")
   {
      array_push ($status , "up.png");
   }
   else
   {
      array_push ($status , "down.gif");
   }
}
?>
</br>
<table style="text-align: left; width: 1062px; height: 75px;" border="0" cellpadding="2" cellspacing="2">

<?
$count = 1;
foreach ($isps as $isp) {?>
<tr><td  width=20%><FONT COLOR=black FACE="Geneva, Arial" SIZE=5>Link  <?echo $count?></font></td><td  width=30%><FONT COLOR=Blue FACE="Geneva, Arial" SIZE=5><?echo array_pop($isps);?></font></td><td width=30%><IMG SRC="img/<?echo array_pop($status);?>" height="60" width="61"></td></tr>
<?$count ++;}?>
</table>
</body></html>