svnlogger v0.1

This one is for the Unix freaks (that includes me !).  Remember the textual “ChangeLog” files we used to see in a lot of open source softwares ? It used to have the list of changes made to the software along with revisions number, contributor’s name and timestamp. I always liked the format of a particular kind of ChangeLog which showed all the details in a compact manner without losing any, helps me keep track of ‘What’s new!’ in my next version of the software. Anyways, so how do I make it ? For those of you who have been thinking that they’re hand-written, you’re so wrong ! After all, how can you expect an open source freak to do something ‘manually’ when he can easily automate any task in his computer using cool scripts ?? Anyways, usually they have some kind of Version Tracking System like CVS, SVN or GIT. I happen to use SVN most of the time, actually always, and since I needed to maintain a ChangeLog as well, I found there was a nice command called “svn log” which would generate a textual log of all the commits along with all the information I needed to see. Well, everything was there, but not in a way I wanted it to be. ‘svn log’ is good enough for ‘grep’ but not so good in terms of direct readability. So I wrote this small shell script that is basically a wrapper around the svn log but it uses AWK to reformat the data in a way I like it !

Copy paste the code below into a file called ‘’ and then execute it like

> sh <path-to-svn-repo> <path-to-changelog>

Continue reading

Perfect configuration for Conky

Okay, this one’s about some eye candy. One thing I regretted while parting my ways with Ubuntu was the good looking themes and applets it had. But no more, as they say, ‘thou shall seek, thou shall find’ and I’ve found whatever I needed in Arch Linux. After configuring everything, from kernel modules to gnome, I finally came to peace with the last missing piece in my puzzle – the Conky system monitor. Configuring it to suit the looks of my desktop was a hell of a task but I finally succeeded thanks to numerous tutorials on the internet and needless to say, google. For starters, Conky is just a system monitor that can be configured to monitor everything from your CPU’s temperature to internet speed to processes and hard disk space. You can even configure it to monitor your email or some RSS feeds you like. And the best part, is the looks, okay, take a look :

Continue reading

Upgrading to PHP 5.3 in Ubuntu

I’ve been using PHP 5.2 for a long time now. I’m not so apt towards change but PHP 5.3 has some cool features which I needed very much for my projects. So yesterday I decided to do that conversion. The process was not at all so simple and it took lots of googling and searching the forums, especially for removing the post-installation bugs. Finally, at Dec 27 12:45 AM I achieved 100% transformation to PHP 5.3. As my usual habit, I like documenting the stuff I do, so here it goes.

First thing before starting the process is to make sure that none of my existing projects would break. Because as the developers have said, PHP 5.3 is a major release with lots of changes. Many new features were added while many were removed or deprecated. And to avoid getting unnecessary warnings or notices, it was better to recheck my codes for compatibility with PHP 5.3. The PHP developers have written a good page in the PHP Manual which tells in detail about the things to take care of when migrating to 5.3 from 5.2. You can check it here :

So don’t forget to go through that page once, at the least the section which tells about the “removed and deprecated” features in PHP 5.3 and use the alternatives as suggested. Now you’re ready to upgrade. BUT, before that, you’ve to know that any software you use like phpMyAdmin or ldapPhpAdmin which uses PHP might broke. Well, you cannot do anything about it but you’ll have to reinstall them. Anyways, moving ahead, take a backup copy of your php.ini configuration file. You may need it for reconfiguring your PHP 5.3. If you’re using Apache 2, it can be found in /etc/php5/apache2/php.ini

Now, just run the following commands one by one,

Continue reading

PHP Optimizations

PHP is my favourite web development language.(Not anymore, its Python now). Nevertheless, here are a few tips I follow to make PHP work faster :

  • When you’re creating PHP files, you’ll start with <?php tags as usual, but DON’T end the file with ?> tags if its not your main index.php file. Its optional and ignoring it is not just safe but recommended. So always leave the <?php tags unclosed in files which you are going to include in your main file. Do close it properly in your main index.php file though.
  • Don’t use functions in FOR loop condition if the function returns the same result always e.g.
for($i=0; $i&lt;length(arr); $i++)


for($i=0, $N=length($arr); $i&lt;$N; $i++)

That’s because since the condition is checked on every iteration. The function is called again and again to check the lenght of the same array every time. Instead since you know the array length is the same, why not save it in $N so that it won’t have to calculate it again and again. Though if your array $arr may change in length, you can use that. Continue reading

Quickly configuring an LDAP + NFS client in Fedora

Recently I needed to configure 6 PCs for a central workplace. I needed central authentication as well as Network File System(NFS) on all those machines. All this was to facilitate the people of my technical club (the “Delta Force” Webteam) to use those machines for working on collaborative projects. The central authentication assured that I can easily manage user accounts from say, an LDAP server i.e. I can disable login of a user in a client machine or create a new user without having to touch the client machine at all. Similarly, NFS assured that no matter in which of those 6 machines the user logs in, he will always see the same files in his home directory and same configurations like his background-image, firefox addons, etc on that machine as if he always used the same computer for all his work. This eliminates the problem of people complaining that the machine in which their files resides are being used by someone else.

So my overall network configuration has the following prototype :

1) 6 client machines in which user will be able to login (Subnet of the machines :
2) An LDAP server ( IP : ) to take care of authentication when user logs into a client machine
3) The LDAP base DN which has the list of all users is ou=people,ou=delta,,dc=edu
4) An NFS server ( IP : ) which has the user home-directories of all users inside /webteam folder.
Overall working : When a user (say “jereme”) logs into a client machine, his username and password are checked from the LDAP server at If authentication is successful, he’s logged into the machine and his home directory is actually mounted from /webteam/jereme in the NFS server at

I assume you already have the fully configured LDAP and NFS servers since this article is only about configuring the “clients”. So here we go. Pick any of your client machines and do the following :

First we will configure NFS client. For this purpose, we will use the autofs package.

Continue reading

Defending against SQL Injection Attack in PHP any version

Internet Security is a very sensitive issue and many websites have vulnerabilities which are easily exploitable. One such vulnerability is SQL Injection, in which the attacker can literally execute any kind of query in your database, even gain administrator privileges and if things are even worse, then he may also gain access to your system and execute any command. No wonder how dangerous this vulnerability is, but it has a very easy fix. I’d like to introduce you with a small function escape(), I’ve written for sanitizing data while querying the database, which will disable SQL Injection attacks in PHP, irrespective of the PHP version you use.

function escape($input)
if (!get_magic_quotes_gpc()) {
$input = addslashes($input);
return $input;


By default the Magic GPC Quotes feature of PHP is turned ON. So it will automatically sanitize any data it receives from $_GET and $_POST by placing slashes before any ‘, ” or \ characters. However, as of PHP 5.0+, this feature is deprecated and hence relying on it is highly discouraged. Instead, use the addslashes() function which does the same thing. So the function I wrote will basically identify whether the Magic GPC feature is turned ON, if it is, then it will simply return the query as it is, else it will call the addslashes() method on the query. So simple !
However, there’s a more “secure” version of it. But this one is not suitable for large-scale systems as it requires an extra-connection to the MySQL server.

function escape($input)
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
return mysql_real_escape_string($input);


You can use the above function as follows :

Find out all the form variables that you receive in your PHP code i.e. all the occurrences of $_GET and $_POST and whenever you use then, use


instead of just $_POST[‘var’]. Similary for $_GET variables also.

For example, suppose you have stored the mysql query like :

$query=”SELECT * FROM `users` WHERE `username`=’$username’ AND `password`=’$password'”;

To secure the above code, use this code instead :

$query=”SELECT * FROM `users` WHERE `username`=’$username’ AND `password`=’$password'”;

or, by writing it in a single line only :

$query=”SELECT * FROM `users` WHERE `username`='”.escape($username).”‘ AND `password`='”.escape($password).”‘”;

This simple thing will completely disable any kind of SQL Injection attacks in your website or web-application, irrespective of the PHP version you use. However, beware of other attacks ! đŸ™‚

Connecting MTS Mblaze USB Modem in Ubuntu

I recently bought myself an MTS Mblaze wireless USB Modem. Connecting it on Linux was difficult because there was practically no tutorial for MTS USB Modem, while many were available for Reliance and Tata Indicom Modems. So here is what I did to finally get it connected (Note : Execute all commands as ROOT )

i) You’d have to install the package USB-ModeSwitch. It is available here :

Note : When you open the above link, you should check out its dependencies and also install the dependency package ” usb-modeswitch-data”.

Just download and double-click on it to install the package.

ii) After you’ve installed usb-modeswitch and usb-modeswitch-data packages, reboot your computer.

iii) Connect the Mblaze Modem and wait for 30 seconds. While you’re waiting, the usb-modeswitch package is doing magic in the background, you can check the status through the following command :


iv) I hope you have “wvdial” pre-installed on your system. You can check that by typing “wvdial” and see if the computer recognises it. If it doesn’t then you’d have to install it. Its easy, refer this link.

v) Now edit the file /etc/wvdial.conf (If it doesn’t exists, then create it) as Root and copy paste the following code :

[Dialer cdma]
Stupid Mode = 1
Inherits = Modem0
Password = mts
Username =
Phone = #777

Init1 = ATZ
SetVolume = 0
Modem = /dev/ttyUSB0
Baud = 115200
FlowControl = Hardware (CRTSCTS)
Dial Command = ATDT

Note that ttyUSB0 may be different for your system. However, first try with the above code, if it doesn’t works and says some error like “ttyUSB0 doesn’t exists” or something similar to it, then find out the actual one by going through the output of following command :

dmesg | grep -e “modem” -e “tty”

vi) That’s it, you’re done. Now start browsing with the following command :

wvdial cdma

As soon as you start seeing some IP addresses, you’re online! DO NOT close the terminal in which you executed the command, otherwise you will get disconnected.

And from next time, you don’t have to it all over again. Simply connect your modem, wait for 30 seconds and type the last command. To disconnect, goto the terminal, and press Ctrl + C.

Hope it worked for you, if any problems occured, you can leave a reply !

Basics of IRC : Internet Relay Chat

IRC or Internet Relay Chat is a widely used chat protocol over the Internet. From a birds-eye view, its just like any other chat application you use like Yahoo or Gtalk. It lets you talk to other people using text messages over the Internet. So then what’s so different about it?

Lets have a more closer look. IRC is a “protocol” like HTTP,FTP and not an “application” like Yahoo or Gtalk. Speaking in a technical way, IRC is a well-defined Application Layer Chat Protocol (RFC 1459) that uses port 6667 over TCP connection while chat messengers like Yahoo are applications that uses their own proprietary protocols. There are many advantages and some disadvantages of using IRC. Advantages being its an open-protocol means anyone can design his own IRC client. Its very simple, there are just list of rules which you have to follow to talk. Disadvantage is that it doesn’t support features like Video or Audio chat and other real-time multimedia applications. It can, at most, share text and files.

Also IRC is not meant for individual chat (although it is supported). Its developed for groups discussing development of open-source softwares, contribute to research-based discussions and take part in online debates, or just spend time fooling around and see other people talk! IRC have “nodes” or “channels” similar to “chat rooms”. As soon as you join a channel, you start receiving real-time conversations going on. You can just hop in then and say what you have to say to all the members in that channel. Be aware though, the @admin can kick you out anytime if he doesn’t like what you’re saying!

So as I said, its basically for chat related to open-source, discussions and debates, between people with great minds and less time, between old-fashioned geeks who hates twitter and facebook and between people who take inspiration from secretly hearing others talk. To be frank, I myself never used it before the Google Summer of Code 2010 which widely advertise the use of IRC with mentors. Since I’m participating in it, I had to talk to my mentor and for that I needed to learn IRC. It was very difficult to find a nice tutorial especially which deals with making a linux-based IRC client work behind the combo of a proxy and NAT firewall in my college, which blocks the port 6667 with extra-pleasure đŸ˜¦ .

After some googling I found a solution to my problem. Since I needed to chat mostly in the freenode server, the web-based IRC chat client offered by was perfect. Check it out here : . You can pick any name and login to any channel. However, if that name is registered, you have to change it within 2 minutes or you will be automatically renamed to some random number. So lets start my actual tutorial on using IRC :

Continue reading