Saturday, May 26, 2007

Custom extenstion for a Server Script

Intro
PHP files have a ".PHP" extension and is by default the extension used to run php scripts. Thats ordinary. Now it would be cool if we could name another extension (say .do or .html) for a PHP script and get the same output. This is precisely what the following is about.

In order to map a particular extension to a particular application, apache uses handlers. Basically you can define an extension and add the corresponding handler. This can be done in 2 ways :

CPanel / Apache Handlers
Add extension html and handler application/x-httpd-php to make a new handler :

html application/x-httpd-php

This makes any ordinary html file to be handled and processed by the PHP engine before it is output.

.htaccess
For those who dont have cPanel access, the .htaccess file can be edited.
Add
AddHandler application/x-httpd-php html

this line to your .htaccess file. This makes the same effect as done in the previous method.

Tip
  • Adding html extension as php can be cool, because a statically appearing page is actually dynamic. But the disadvantage of using this is that, all HTML files will be passed through the PHP engine and parsed for the PHP codes. This puts unnecessary pressure on the servers and makes it slow.
  • It is better to choose someother extension, if there is a lot of static content on your website. If most of your pages are in PHP, this effect is cool.
  • If for some reason your .htaccess gets deleted or restored to default, All the PHP codes will be echoed to the users browser and all the source would be revealed!. So beware when using this.

Monday, May 14, 2007

Xorg.conf File Settings for Beryl and Desktop-effects

Note
The following is my /etc/X11/xorg.conf file on which beryl and desktop-effects work.
NVidia Graphics Card. If you are unable to enable the desktop-effects or beryl,
try copy pasting the Module, Device and Screen Sections to your xorg.conf file.
Please back up your existing xorg.conf file before changing anything.


# Xorg configuration created by livna-config-display

Section "ServerLayout"
Identifier "single head configuration"
Screen 0 "Screen0" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Synaptics" "CorePointer"
EndSection

Section "Files"
ModulePath "/usr/lib/xorg/modules/extensions/nvidia"
ModulePath "/usr/lib/xorg/modules"
EndSection

Section "Module"
Load "fbdevhw"
Load "glx"
Load "dbe"
Load "extmod"
Load "glx"
Load "dbe"
Load "extmod"
EndSection

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
EndSection

Section "InputDevice"
Identifier "Synaptics"
Driver "synaptics"
Option "Device" "/dev/input/mice"
Option "Protocol" "auto-dev"
Option "Emulate3Buttons" "yes"
EndSection

Section "Monitor"

### Comment all HorizSync and VertSync values to use DDC:
### Comment all HorizSync and VertSync values to use DDC:
### Comment all HorizSync and VertSync values to use DDC:
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
### Comment all HorizSync and VertSync values to use DDC:
HorizSync 30.0 - 110.0
VertRefresh 50.0 - 150.0
Option "DPMS"
EndSection

Section "Device"
Identifier "Videocard0"
Driver "nvidia"
Option "AddARGBGLXVisuals" "True"
Option "DisableGLXRootClipping" "True"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Videocard0"
Monitor "Monitor0"
DefaultDepth 24
Option "HWcursor" "On" # This prevents the flickering and incorrect redrawing of the mouse
Option "AddARGBGLXVisuals" "True"
SubSection "Display"
Viewport 0 0
Depth 24
EndSubSection
EndSection

Friday, May 11, 2007

Installing Misc Softwares on FC6

VLC Player
Installing VideoLanC Player on Fedora Core 6.


# rpm -ivh http://rpm.livna.org/livna-release-6.rpm
# yum -y install vlc


First install the Livna repository,
Install VLC...


Firefox 2.0
FC6 comes shipped with Firefox 1.5 by default to install Firefox 2,
Download firefox 2.


# tar -xzvf /downloadlocation/firefox-2.0.tar.gz -C /usr/lib/
# yum install compat-libstdc++-33
# $ cd /usr/bin/
# rm firefox
# rm: remove regular file `firefox'? y
# ln -s /usr/lib/firefox/firefox


  • In the first step we untar the downloaded files to /usr/lib

  • compat-libstdc++-33 is a module that is required for Firefox, skip this step if you are sure you have the module

  • Next we remove the previous link/ init script of Firefox from /usr/bin

  • Finally we make a new link in /usr/bin to the new Firefox 2.



NVidia Graphics Driver
Download the latest nvidia driver (1.0-9626) from here.

# init 3
Command not found
# /sbin/init 3
# sh NVIDIA-Linux-x86-1.0-9629-pkg1.run
# reboot


NTFS file system support
$ su
Password:
# yum install ntfs-3g
# mount -t ntfs-3g /dev/sda# /target folder -o force

Thursday, May 10, 2007

ANSI Escape Sequences

Intro
ANSI Escape sequences are used to perform special operations on the terminal, such as changing the output color, making it bold, printing at a specified coordinate etc.

The sequences

Wherever you see '#', that should be replaced by the appropriate number.

ESC code sequence Function
------------------- ---------------------------
Cursor Controls:
ESC[#;#H or ESC[#;#f Moves cusor to line #, column #
ESC[#A Moves cursor up # lines
ESC[#B Moves cursor down # lines
ESC[#C Moves cursor forward # spaces
ESC[#D Moves cursor back # spaces
ESC[#;#R Reports current cursor line & column
ESC[s Saves cursor position for recall later
ESC[u Return to saved cursor position

Erase Functions:
ESC[2J Clear screen and home cursor
ESC[K Clear to end of line

Set Graphics Rendition:
ESC[#;#;....;#m Set display attributes where # is
00 for normal display (or just 0)
01 for bold on (or just 1)
02 faint (or just 2)
03 standout (or just 3)
04 underline (or just 4)
05 blink on (or just 5)
07 reverse video on (or just 7)
08 nondisplayed (invisible) (or just 8)
22 normal
23 no-standout
24 no-underline
25 no-blink
27 no-reverse
30 black foreground
31 red foreground
32 green foreground
33 yellow foreground
34 blue foreground
35 magenta foreground
36 cyan foreground
37 white foreground
39 default foreground
40 black background
41 red background
42 green background
43 yellow background
44 blue background
45 magenta background
46 cyan background
47 white background
49 default background

ESC[=#;7h or Put screen in indicated mode where # is
ESC[=h or 0 for 40 x 25 black & white
ESC[=0h or 1 for 40 x 25 color
ESC[?7h 2 for 80 x 25 b&w
3 for 80 x 25 color
4 for 320 x 200 color graphics
5 for 320 x 200 b & w graphics
6 for 640 x 200 b & w graphics
7 to wrap at end of line

ESC[=#;7l or ESC[=l or Resets mode # set with above command
ESC[=0l or ESC[?7l

Keyboard Reassignments:

ESC[#;#;...p Keyboard reassignment. The first ASCII
or ESC["string"p code defines which code is to be
or ESC[#;"string";#; changed. The remaining codes define
#;"string";#p what it is to be changed to.

E.g. Reassign the Q and q keys to the A and a keys (and vice versa).

ESC [65;81p A becomes Q
ESC [97;113p a becomes q
ESC [81;65p Q becomes A
ESC [113;97p q becomes a

E.g. Reassign the F10 key to a DIR command.

ESC [0;68;"dir";13p The 0;68 is the extended ASCII code
for the F10 key and 13 is the ASCII
code for a carriage return.

Other function key codes F1=59,F2=60,F3=61,F4=62,F5=63
F6=64,F7=65,F8=66,F9=67,F10=68



Source : The Internet

ESC
The Escape sequence on Linux is \e. Replace the ESC by \e on linux to make it work.
For example,
\e[31;1m
Prints this in RED BOLD.

Have more info? Please do comment...

Perl Script to Login to Orkut

Finally
Succeeded in making the Perl Script that logs you into Orkut! Signing into Orkut is much more than a simple POST, Google is always clever so that they make things complex for automating the login process. Anyway here is the complex script, ..

Algorithm


  1. Goto www.orkut.com

  2. Check whether the title is Home.

  3. If not find the source of login page IFRAME

  4. Fill the username and password and submit the FORM.

  5. Find the follow link from the next page.

  6. Goto the followlink and GET the redirect page URL

  7. Goto the redirect page

  8. Goto Orkut.com/home.aspx

  9. Your done.



Note:
Tested on Linux (FC6, Perl 5.8.8)
The following script is for linux, Will run on Windows too but the ANSI coloring may not work...
Windows Program is given below the program for Linux (without ANSI coloring).
For Linux (with ANSI coloring)

use WWW::Mechanize;
use HTTP::Cookies;
use HTTP::Request::Common;

$cj=HTTP::Cookies->new(file => "cookie.jar",autosave=>1,ignore_discard=>1);
$mech = WWW::Mechanize->new(cookie_jar => $cj);

@prc = ("\e[0m\n","[\e[1;31mFAILED\e[0m]","[\e[2;32m OK \e[0m]\n");

print "\n\e[31;1mG\e[0mmail iD : ";
$email = ;
print "\e[31;1mP\e[0massword : \e[97m";
$pass = ;
print $prc[0];

chomp $email;chomp $pass;

RELOGIN:
for($i=3; $i>=0;$i--)
{
printf("\e[2m%-60s","GET /Home.aspx");
$mech->get("http://www.orkut.com/Home.aspx");
last if($mech->success());

printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}

return if($i<=0);
print $prc[2];


$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

if($mech->title =~ m/orkut.*home/i)
{
print "\n\e[34mAlready Logged In",$prc[0];

$cnt =~ m/<b>(.*)\@gmail.com<\/b>/;

print "\nLogout $1?[n] : ";
$com=;chomp $com;
if($com eq "y")
{
logout;
goto RELOGIN;
}
else
{
return;
}
}

$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

printf("\e[2m%-60.59s","Parsing for Login Page ");
#print $cnts;
if($cnt !~ m/id='liframe'.*?src='(.*)'/)
{
printf("%10s",$prc[1]);
print "\e[2;37m Login page URL Not Found!\nTry Again OR Update the script! ".$prc[0];

return;
}

print $prc[2];
$url = $1;
$j=3;
REDO:
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());

printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}

return if($i<=0);

print $prc[2];

$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

$mech->form_number(1);
$mech->field("Email",$email."\@gmail.com");
$mech->field("Passwd",$pass);


printf("\e[2m%-60.59s","Logging In ... ");

$mech->click("null");

$j--;
if($j && !$mech->success())
{
printf("%10s\n",$prc[1]);
goto REDO;
}
return unless($j);

$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

if(!$mech->find_link(text => "click here to continue"))
{
printf("%10s",$prc[1]);
print "\n\e[31;1mWrong Usename or Password!",$prc[0];
return;
}


print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","Continuing ...");
$mech->follow_link(text => "click here to continue");
last if($mech->success());

printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}

return if($i<=0);

print $prc[2];

printf("\e[2m%-60s","Parsing REDIRECT URL");
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

if($cnt !~ m/location.replace\("(.*)"\)/)
{
printf("%10s",$prc[1]);
print "\n\e[31;1mRedirect script missing!",$prc[0];
return;
}

$url = $1;
$url =~ s/\\u003d/=/g;

print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());

printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);

print $prc[2];
print "\e[34mLogged In!\e[0m";
exit 0;


sub logout
{

printf("\e[0;2m%-60s","Parsing Logout");
if(!$mech->find_link(text => "Logout"))
{
printf("%10s",$prc[1]);
print "\n\e[31;1mNot Logged In?",$prc[0];
return;
}


print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","Logging Out ...");
$mech->follow_link(text => "Logout");
last if($mech->success());

printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);

print $prc[2];
}


For windows:

use WWW::Mechanize;
use HTTP::Cookies;
use HTTP::Request::Common;

$cj=HTTP::Cookies->new(file => "cookie.jar",autosave=>1,ignore_discard=>1);
$mech = WWW::Mechanize->new(cookie_jar => $cj);

@prc = ("\n","[FAILED]","[ OK ]\n");

print "\nEmail iD : ";
$email = ;
print "Password : \e[97m";
$pass = ;
print $prc[0];

chomp $email;chomp $pass;

RELOGIN:
for($i=3; $i>=0;$i--)
{
printf("%-60s","GET /Home.aspx");
$mech->get("http://www.orkut.com/Home.aspx");
last if($mech->success());

printf("%10s",$prc[1]);
print " Retry (",$i,")".$prc[0] if($i);
}

return if($i<=0);
print $prc[2];


$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

if($mech->title =~ m/orkut.*home/i)
{
print "\nAlready Logged In",$prc[0];

$cnt =~ m/<b>(.*)\@gmail.com<\/b>/;

print "\nLogout $1?[n] : ";
$com=;chomp $com;
if($com eq "y")
{
logout;
goto RELOGIN;
}
else
{
return;
}
}

$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

printf("%-60.59s","Parsing for Login Page ");
#print $cnts;
if($cnt !~ m/id='liframe'.*?src='(.*)'/)
{
printf("%10s",$prc[1]);
print "Login page URL Not Found!\nTry Again OR Update the script! ".$prc[0];

return;
}

print $prc[2];
$url = $1;
$j=3;
REDO:
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());

printf("%10s",$prc[1]);
print " Retry (",$i,")".$prc[0] if($i);
}

return if($i<=0);

print $prc[2];

$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

$mech->form_number(1);
$mech->field("Email",$email."\@gmail.com");
$mech->field("Passwd",$pass);


printf("%-60.59s","Logging In ... ");

$mech->click("null");

$j--;
if($j && !$mech->success())
{
printf("%10s\n",$prc[1]);
goto REDO;
}
return unless($j);

$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

if(!$mech->find_link(text => "click here to continue"))
{
printf("%10s",$prc[1]);
print "\nWrong Usename or Password!",$prc[0];
return;
}


print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","Continuing ...");
$mech->follow_link(text => "click here to continue");
last if($mech->success());

printf("%10s",$prc[1]);
print "Retry (",$i,")".$prc[0] if($i);
}

return if($i<=0);

print $prc[2];

printf("%-60s","Parsing REDIRECT URL");
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;

if($cnt !~ m/location.replace\("(.*)"\)/)
{
printf("%10s",$prc[1]);
print "\nRedirect script missing!",$prc[0];
return;
}

$url = $1;
$url =~ s/\\u003d/=/g;

print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());

printf("%10s",$prc[1]);
print " Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);

print $prc[2];
print "Logged In!";
exit 0;


sub logout
{

printf("%-60s","Parsing Logout");
if(!$mech->find_link(text => "Logout"))
{
printf("%10s",$prc[1]);
print "\nNot Logged In?",$prc[0];
return;
}


print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","Logging Out ...");
$mech->follow_link(text => "Logout");
last if($mech->success());

printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);

print $prc[2];
}




Libs needed
LWP;
WWW::Mechanize;

Description
Script that logs you into orkut, It has its own Fail-retry methods and all the action is presented neatly in the terminal, using color codes (ANSI Escape sequences for LINUX)
There is more of this script currently in the beta version, for mass scrapping etc. For more information about the beta codes, leave your email as a comment.

Bugs ?
Please do let me know the bugs , so that i can update the script here...
It works for me... Did it work for you? Let me know... (else I may think this is all crap!)

Happy Automating,.. :)

Friday, May 4, 2007

Windows Folder Extensions

Intro

Well you all know about file extensions and what they mean etc... But have you heard about a Folder Extension ? I suppose not. Windows has some set of pretty extraordinary extensions for folders, to mark them as something different. Read more to get what I mean...


List of extensions


  • .{21EC2020-3AEA-1069-A2DD-08002B30309D} Control Panel

  • .{9E56BE61-C50F-11CF-9A2C-00A0C90A90CE} Desktop

  • .{645FF040-5081-101B-9F08-00AA002F954E} Recycle Bin

  • .{20D04FE0-3AEA-1069-A2D8-08002B30309D} My Computer

  • .{208D2C60-3AEA-1069-A2D7-08002B30309D} Network

  • .{2227A280-3AEA-1069-A2DE-08002B30309D} Printer

  • .{25336920-03F9-11CF-8FD0-00AA00686F13} HTML Document

  • .{0003000D-0000-0000-C000-000000000046} Wave File

  • .{00022602-0000-0000-C000-000000000046} Video Clip

  • .{00021401-0000-0000-C000-000000000046} Makes it a file



What to do?

Make a New folder and name it something. Now when you rename add one of the following extension to it. (ie Append the .{XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX} to the end of the folder name just as adding an extension to a file) and see the changes.

** Try these on a blank folder or a folder that contains nothing important!

Tested on Windows XP, you are welcome to comment about success or failure on other Windows OS's .... This method can be used to hide/protect important folders.. ;)

Wednesday, May 2, 2007

Sitemeter selling your stats to Ad Company

Sitemeter
is or rather Was a popular site tracking service that reports about traffic stats on sites. Recently it was found by many that certain advertising company specificclick.net cookies were found in the browsers. Following it up I investigated the sitemeter code provided and here is the solid proof that sitemeter sells your stats to the company :

The source code that is being generated by the sitemeter script that contains the ad code:



I have removed all sitemeter codes from my sites and I recommend you too to do the same...

Tuesday, May 1, 2007

My First useful PERL program

#!/usr/bin/perl -w

$username = $ARGV[0];
$username = "s28arunpbk" if(!$username);
#
# Get the username from the first command line argument
# If null assign my user id.
#

use LWP;
use LWP::UserAgent;
#
# Initialize objects
#


$ua = LWP::UserAgent->new;
$ua->agent("Checkmap/1.0");
my $req=HTTP::Request->new(GET => "http://sitemeter.com/?a=stats&s=$username&r=0");

my $res = $ua->request($req);
#
# Send a request and grab the response...
#

if($res->is_success)
{
$contents = $res->content;
$contents =~ m/<title>(.*)<\/title>/i; #regexp to find the title
if($1 =~ m/Site Meter/)
{
print "Wrong User name!\nAborting\n";
exit 0;
#
# If the web page title contains the words "Site Meter",
# it means the username was invalid and got redirected to
# index.
#

}

print "$1\n","="x length $1,"\n";

#
# Print the title and draw an underline...
#


$contents =~ s/ //g; #Strip `&nbsp;`
$contents =~ s/\<.*?\>//g; #Strip all HTML tags
$contents =~ s/\s+//g; #Strip all spaces
$contents =~ m/Total(([0-9]|,)+)Average/g; #The data we need.

print "Visits : ",$1;

$contents =~ m/Total(([0-9]|,)+)Average/g;
printf "\nPageviews : $1\n";
}
else
{
print "Error : $! ",$res->as_string;
exit 1;
#Messed up somewhere.
}
exit 0;
#thats all


What does this do ?

The script gives me the total number of visitors and pageviews on my site via sitemeter.com. By passing an optional username as a command line argument you can get the same information of that account.

How to use ?

Check whether you have Perl installed on your computer.
Start a command prompt and type perl -v, if the command is not found download and install Perl.

Copy the source code given above and paste it in a new file say dstat.pl
Run the code by perl dstat.pl.