Saturday, November 07, 2009

Pidgin : Log in invisible for Google Talk (XMPP/Jabber)

I am a big fan of pidgin, primarily due to it's configurability and plugin support. One of major turn-off people report around me is that pidgin does not support logging in as invisible with gtalk account. Not that I am a big fan of invisibility, I built a plugin that lets you do just that.

Not supporting neat 'sign on as invisible' for gtalk is basically due to lack of time and willingness on Pidgin developers' part. Not that they can't, they just don't want to at the moment due to some extra stuff gtalk uses/needs.

Installation instructions:

It is written in Perl, which means you need perl 5+, pidgin-perl and libpurple-perl packages.


On apt based systems (like Ubuntu), do (as root)
apt-get install pidgin-perl

looks like Ubuntu 9.10 has this built in.

on fedora and alike

yum install pidgin-perl

That should install all required packages, with dependencies.

Download and extract the plugin perl script.
Save it to your ~/.purple/plugins/ directory. That is, /home/{username}/.purple/plugins/.
If you find that hard, there is an install script included.

Usage:
Go to Tools->Plugins. Find 'Google Talk Invisible Plugin' and enable it.
Now, when you set your status as "Extended Away", you become invisible. Simple!

This is the pre-pre-pre-...-alpha release, which means I did not go through the trouble of activating the INVISIBLE status for gtalk accounts, and hijacked xa instead. I hope it is not a big mistake.

Update : there is a serious bug in this plugin. After you become invisible, you can not get updates to your contact list, and hence if you start pidgin with the plugin enabled in extended away mode, you may not see any online friends at all. I am working on it.

Thursday, September 10, 2009

Basic Authenticating pseudo-proxy with bash/netcat

Yes, you can also do authentication with netcat.


#!/bin/bash
# @author : Prashant Borole (prashantb  :can be reached at:     cse iitb ac in)

# A simple proxy-proxy that authenticates on users' behalf.
# Known limitations :
#       Works for Basic proxy authentication at the moment (though it is not that hard to add digest support)
#       Can process single request at a time. Any parallel requests will not be satisfied. This may lead to referred elements not being loaded, eg. images. Download accelerators are rendered useless.
#       Due to the logging format, there can be storage issues when downloading huge files.
#       Significantly slower than squid or some custom asyncio implementation as each request spawns bunch of new processes
#       No cache. Each request is strictly sent to upstream proxy
#       no https or ftp support

# TODO put this in some standard location
CONFIG_FILE="$HOME/.proxy.conf"

export LISTEN_PORT=
export PROXY=
export PROXY_PORT=
export LOG_FILE=

init()
{
        exec   2>&- 2>&1
        exec   5>&1
        exec   >>"$LOG_FILE"
}

readConfig()
{
        # really cheap config parsing.
        # FIXME improve
        # echo "Loading Configuration from $CONFIG_FILE"
        export LISTEN_PORT=$(grep "LISTEN_PORT=" "$CONFIG_FILE" | cut -d '=' -f2)
        export PROXY=$(grep "PROXY=" "$CONFIG_FILE" | cut -d '=' -f2)
        export PROXY_PORT=$(grep "PROXY_PORT=" "$CONFIG_FILE" | cut -d '=' -f2)
        export LOG_FILE=$(grep "LOG_FILE=" "$CONFIG_FILE" | cut -d '=' -f2)
}

if [ "$1" != "--" ]; then
        # read the config initially
        readConfig
        
        # accept credentials
        echo -n "$PROXY:$PROXY_PORT    user name : "
        read USER_NAME
        echo -n "$USER_NAME@$PROXY:$PROXY_PORT Password : "
        read -s PASSWORD
        echo
        export B64CRED=`echo -ne "$USER_NAME:$PASSWORD" | base64`
        unset USER_NAME PASSWORD
        echo "Credentials accepted."

        # launch in background
        $0 -- &
        exit 0
else
        trap 'echo "cleaning up $TMP_DIR" ; rm -fr "$TMP_DIR"; killall -9  nc tee >/dev/null 2>&1' EXIT
        trap 'echo "Shutting down proxy server on port $LISTEN_PORT" ; exit 0' SIGUSR1
        trap 'echo "Reloading config..." ; readConfig' SIGUSR2
        trap 'echo "[UNCLEAN] Shutting down proxy server on port $LISTEN_PORT" ; exit 1' SIGINT SIGKILL SIGSEGV SIGPIPE SIGHUP SIGTERM SIGABRT

        readConfig
        init
        echo "`date`   Server $0[$$] started"
fi

TMP_DIR=`mktemp -d /tmp/proxy.XXXXXXXX`

BACK_FIFO="$TMP_DIR"/back_fifo
# create a pipe
mknod "$BACK_FIFO" p

echo "Accepting connections on port $LISTEN_PORT"
while true ; do
        nc -l "$LISTEN_PORT" 0<$BACK_FIFO | tee request | (while read line ; do if [ "$line" = "^M" ] ; then echo "Proxy-Authorization: Basic $B64CRED" ; echo ; else echo "$line" ; fi;  done) | nc -w 5 "$PROXY" "$PROXY_PORT" | tee response 1>$BACK_FIFO
        head -n+1 request
        head -n+1 response
done

echo "THIS SHOULD NEVER HAPPEN. SOMETHING IS WRONG !!!"
exit 1


Note that you can NOT use something like sed or awk, because they simply give up when there is no text to read. This breaks the pipe. A "while read" loop just cuts it :)

Tuesday, August 18, 2009

Java Unicode (source code)

We all know that Java is great with Unicode. I was surprised to know that the compiler itself has moved on. The Java source itself can be in Unicode now!!

Check out the sample Java source file

 1 /**
 2  * @author prashant
 3  *
 4  */
 5 public class JavaUnicodeTest{
 6     static class मज्जाआहे  {
 7         public मज्जाआहे()     {
 8             System.out.println("constructor of " + this.getClass().getCanonicalName());
 9         }
10
11         int पाचद्या()       {
12             return 5;
13         }
14     }
15
16     public static void main(String[] args) {
17         मज्जाआहे o = new मज्जाआहे();
18         System.out.println(o.पाचद्या());
19     }
20 }

Using OpenJDK
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.5) (fedora-27.b16.fc11-x86_64)
OpenJDK 64-Bit Server VM (build 14.0-b15, mixed mode)

It runs fine, giving

constructor of JavaUnicodeTest.मज्जाआहे
5


weird, eh?

Sunday, July 26, 2009

random status in Pidgin :- fortune

There is a nice utility called 'fortune' for linux. Basically a database of funny/witty quotes accumulated over decades which can be read either directly from flat files or using the 'fortune' front-end.

What can you use it for? Display random quotes in your mail signature (with due references/credits), on your home page or IM status :P

#!/bin/bash
while true :;

do
MSG=`fortune -ae`
zenity --question --text="$MSG" && (purple-remote "setstatus?message=$MSG" && sleep 1800);
done;
Make sure you have zenity and fortune packages installed.

Start pidgin and then this script. It will get a new random status every 1800 seconds and ask whether you want it as status, the process repeats immediately if you press cancel, and status is set otherwise.

'fortune' is used for name sake here. You can pull in random statuses from some web page (and probably scrape them), or some RSS feed if available, or from your own compiled database of statuses, reading one at random.

This is what you do when you are bored to core sitting in an office on Monday afternoon waiting for the benchmarks to complete.

Sunday, July 05, 2009

raided

Bought a new Seagate 500GB internal disc drive last week. One of the obvious things I'd try out was to RAID my old drive with this one. Though asymmetric in both sizes and performance, I wanted to give it a try. Without very high expectations of speedups, I went ahead.

RAID on windows turned out to be a disappointment. The so called Windows Dynamic Discs must span an entire physical disk, which means I could not install linux on any of these drives. Pfft; what a nice way to cut out competition! Moreover, from what I read, dynamic discs are not reliably readable in linux.
Someone has posted an article that tells how to dual boot RAID windows with linux installed. Though I have not tried it, it is worth trying out in a VM first.

RAID-ing on Linux was like a breeze. This time I decided to trust the anaconda installer GUI for partitioning and not doing it the usual command line way. With two raid partitions of same size on each drive, the setup created /dev/md0 comfortably for me. Then I created a PV out of raid and added it to LVM. Partitioned the lvm group in the usual way and my system was up flawlessly. Though not exaggeratingly massive, I can sense some speedup in my day to day activities. Not to mention, boot times are affected. Disc I/O bound programs are ones most boosted. One of my projects where data is read from a 15G file at random runs at 1.5x now :D.

Wednesday, February 11, 2009

Starting gdm or xdm and kde by default in FreeBSD 7.1

After installation, by default FreeBSD gives you a nice terminal based login. I am pretty much happy with that as I have a high-res VESA console (after recompiling the kernel with VESA console support and then setting respective mode using vidcontrol).

But if you are more of a clicky-clicky type of person, you probably want it to start off directly into some graphical greeter and login manager like gdm or xdm.

Starting gdm by default


add
gdm_enable="YES"


in /etc/rc.conf

and reboot. You should get gdm after boot.
One problem I could not come over with gdm is that I could not select or start KDE from it. It would always try to load gnome.
FailSafe Terminal and then running startkde works, but is again not for the clicky-clicky user.

Starting xdm+kde by default


This needs minor serious work.

First, edit /etc/ttys
under #Virtual terminals
change
ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure

to
ttyv8 "/usr/local/bin/xdm -nodaemon" xterm on secure


This should start xdm with an xterm console log on virtual tty8 (the one you get when you hit ).

If you want to log in to kde after authenticating in xdm,

create/open ~/.xsession

and make it look like
#!/bin/sh
exec startkde


This will start off kde after authenticating in xdm.

USB mouse under X / kde / gnome in FreeBSD 7.1

During FreeBSD 7.1 installation, many users with USB mouse respond in negative when the setup asks if they have PS2 or serial mouse (as USB =/= serial). And then they end up with kde up and running and no mouse.


The quick way to fix that is to add
moused_enable="YES"
moused_type="auto"

to your /etc/rc.conf file and reboot.
Xorg server picks up the device /dev/sysmouse nicely.