Thursday, December 20, 2007

Show Desktop missing?

Show Desktop
After opening hundreds of windows and you want to desperately do something with your desktop, you have to go on minimizing all the windows. This is where the Show Desktop is used. For those who have not seen it, it is there in the quick launch section of the Task Bar.



And for the more unlucky guys who have not enabled the quick launch, a google search would be more than enough to know more.

And for the lucky guys like me, who occassionally find it interesting to accidently delete files ;), here is the Show Desktop file
Filename : Show Desktop.scf
Contents ...

[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop

Saturday, December 8, 2007

Virtual Hosts on Apache 2.2.6 [Windows]

What ?
Virtual Hosts allow you to simulate multiple sites on a single server.
i.e, One Server many Websites.
Virtual Hosts is enabled by uncommenting the line :


# Virtual hosts
#Include conf/extra/httpd-vhosts.conf #Uncomment this line

on httpd.conf

The virtual host conf file ./conf/extra/httpd-vhosts.conf

Eg:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

<VirtualHost *:80>
ServerName localhost
DocumentRoot "F:/webs/localhost"
DirectoryIndex index.php index.html index.htm index.shtml
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "F:/webs/kitiyo.com"
ServerName pp.com
DirectoryIndex index.php index.html index.htm index.shtml
</VirtualHost>


In the above example shows localhost and kitiyo.com host on same server.
Remember to add the sites in the hosts file.

Apache 2.2.6 Getting 403 Forbidden on all pages

Intro
This is the issue about getting 403 Forbidden Error on all pages when you are working on localhost. I have used Virtual Host to simulate multiple sites on my computer. So I get 403 Forbidden on all pages. I tried for many solutions couldn't find anything much relevant. After sometime tweaking here is the solution or rather the problem I found.

...
The error forbidden arises due to


<Directory Directory Path, eg C:/www/>
# many things here ... :)
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>


If you have virtual hosts, you will have to allow permission to access those directories too which contain the sites. For eg. if you have another site on
C:/anotherwww/, you should include

<Directory Directory Path, eg C:/anotherwww/>
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>


Thats all
Restart Apache Server.
Your Problem is solved.

:)

Thursday, November 29, 2007

Presario V3000 TV settings S-Video PAL

Before starting ...
+ Make sure you have installed Nvidia GeForce Go 6190 drivers.
+ Plugged the TV in via the S-Video Port.

1.
Right click and select Laptop Display from the NVidia Display menu.


2.
Choose the desired option
+ Clone : makes the same screen on your laptop display and on the TV screen.
+ Dual View: makes your TV the extension of your laptop display, ie., the TV together with your laptop becomes a big screen.


+ Apply the changes.

3.
+ If your TV does not work, select the TV, click the Device Settings, Select TV format, Advanced
+ make sure you have put the correct TV output. PAL/B in this case and that
the Video output format as S-video.


Apply changes and you should see the changes on your screen.

:)

Asynchronous Reading from Input

Intro
Normal working of a C program taking an input is done via the scanf method. The problem in scanf is that when we invoke scanf it waits until we input something i.e, our program is waiting for the user input. This valuable time could be used for processing other things. Let us consider an example of a chat client made using C. When we want to send some message we type them and send. In all other cases it is required that the chat client listens for incoming messages. This is impossible using the normal scanf method, because at all times it would be waiting for our input and there would not be any recieved messages in that time period. So the process of receiving information while checking for input is an example of asynchronous reading.

How ?

On Windows ...
On windows the input STDIN can be tested for data by the function kbhit()
defined on conio.h. A simple program template would be


#include <conio.h>

int main()
{
//...
while(1) //Main Process loop
{
//Other Process Block
{
/*
* Something else to do
*/

}
if(kbhit())
{
//Input present and process input
}
}
}

kbhit does not take any arguments, it returns 1 if there has been a keyboard hit i.e., a key has been pressed.
The key can be read using getch() or similar functions.

On Linux...
the same thing seems to be a bit different. There is no conio.h defined for linux so there is no kbhit function that can be used in linux. However linux has a set of functions that can be used to test any input for the presence of input. The following is the list of functions that are used to test the input for data.

#include <sys/time.h>

int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *errorfds, struct timeval *timeout);

void FD_SET(int fd, fd_set *fdset);

void FD_CLR(int fd, fd_set *fdset);

int FD_ISSET(int fd, fd_set *fdset);

void FD_ZERO(fd_set *fdset);

Sunday, November 18, 2007

Happy Birthday Digitalpbk

18th November 2007, Internet : Digitalpbk.blogspot.com is entering its one year of enthusiasm. Although digitalpbk started the first post on November 2nd, it started its official statistics(counter) by 18th November. Since it there has been
80000+ visitors,
80 posts,
230 + comments,
etc...

Thanks everyone 4 visiting my blog
that drives the drivers to make me post more ........
:)

Keep visiting ...
digitalpbk.

Sunday, November 4, 2007

UNIX Networking : Sockets TCP Transmitter and Reciever

Intro

Networking in UNIX or Linux is done with sockets. The following are 2 programs I made up.
1. Sends messages in TCP, Client
2. Listens and Recieves messages from TCP, Server

TCP or Transmission Control Protocol is a 2way connection which is more like a stream or a pipe. Both the ends must be connected.


The Transmitter
Reads messages from input and sends it to localhost:34000.
To Setup a transmitter following must be done:
1. Setup a port address and open a socket and bind to it.
2. Connect to server
3. Send messages
4. Close connection when done

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>

/*Some are unused, But I read these are
general headers used in a network program
:)*/

int main(void)
{
struct sockaddr_in sin;
int s;

s = socket(AF_INET, SOCK_STREAM, 0);
if(!s)
{
perror("socket()");
return 1;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(9999);
sin.sin_addr.s_addr = INADDR_ANY;//Just any would do

if(bind(s, (struct sockaddr *)&sin, sizeof(sin)))
{
perror("bind()");
return 1;
}

struct sockaddr_in sout;

sout.sin_family = AF_INET;
sout.sin_port = htons(34000);//Destination PORT!
sout.sin_addr.s_addr = inet_addr("127.0.0.1");//Destination IP Address, here localhost.

connect(s,(struct sockaddr *)&sout, sizeof(sout));//Connect to Server
char msg[1000];//Buffer

do
{
printf("Message: ");
scanf("%s",msg);
sendto(s, msg, strlen(msg)+1, 0,NULL,0);
//Sends the message
}while(*msg!='0'); /*Just an exit condition*/

close(s);//Close Socket

return 0;
}


The Reciever
This program listens to localhost:34000 and accepts first connection and prints the messages whenever it recieves one.
To Setup a reciever following must be done:
1. Setup a port address and open a socket and bind to it.
2. Listens for Clients to connect.
3. Accept connections
4. Recieve data
5. Close connection

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>

int main(void)
{

struct sockaddr_in sin;
char msg[10000];
int ret;
int sin_length;


int s,s2;

s = socket(AF_INET, SOCK_DGRAM, 0);
if(!s)
{
perror("socket()");
return;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(34000);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
if(bind(s, (struct sockaddr *)&sin, sizeof(sin)))
{
perror("bind()");
return 1;
}
if(listen(s,10))//Listen for connections
{
perror("listen()");
return 1;
}
int size=sizeof(sin);
if((s2=accept(s,(struct sockaddr *)&sin, &size) < 0))//Accept connections
{
perror("accept()");
return 1;
}
printf("\nConnected to %s[%d]",inet_ntoa(sin.sin_addr),sin.sin_port);

do
{
ret = recv(s2, msg, 10000, 0);
//Waits until a message is recieved...
printf("Message : %s\n", msg);
}
while(msg[0]!='0');

close(s);//Close Socket
return 0;
}


Thats all
Tested and proved working on Fedora Core 6.
Do let me know your results and comments.....
To know more about the functions check the Linux Manual for each function.

Check out... (UDP Transciever)
:)

Monday, October 29, 2007

UNIX Networking : Sockets UDP Transmitter and Reciever

Intro

Networking in UNIX or Linux is done with sockets. The following are 2 programs I made up.
1. Sends messages in UDP.
2. Listens and Recieves messages from UDP.

User Datagram Protocol or in short UDP is like a letter or telegram, its arrival is not anticipated and there is no connect and disconnect procedures to send and recieve UDP messages unlike TCP/IP. So the program is a little more easier and simpler to understand.


The Transmitter
Reads messages from input and sends it to localhost:34000.
To Setup a transmitter following must be done:
1. Setup a port address and open a socket and bind to it.
2. Send message to specified port and IP addresses.

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>

/*Some are unused, But I read these are
general headers used in a network program
:)*/

int main(void)
{
struct sockaddr_in sin;
int s;

s = socket(AF_INET, SOCK_DGRAM, 0);
if(!s)
{
perror("socket()");
return 1;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(9999);
sin.sin_addr.s_addr = INADDR_ANY;//Just any would do

if(bind(s, (struct sockaddr *)&sin, sizeof(sin)))
{
perror("bind()");
return 1;
}

struct sockaddr_in sout;

sout.sin_family = AF_INET;
sout.sin_port = htons(34000);//Destination PORT!
sout.sin_addr.s_addr = inet_addr("127.0.0.1");//Destination IP Address, here localhost.

char msg[1000];//Buffer

do
{
printf("Message: ");
scanf("%s",msg);
sendto(s, msg, strlen(msg)+1, 0, (struct sockaddr *)&sout, sizeof(sout));
//Sends the message
}while(*msg!='0'); /*Just an exit condition*/

close(s);//Close Socket

return 0;
}


The Reciever
This program listens to localhost:34000 and prints the messages whenever it recieves one.
To Setup a reciever following must be done:
1. Setup a port address and open a socket and bind to it.
2. Start Recieving...

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>

int main(void)
{

struct sockaddr_in sin;
char msg[10000];
int ret;
int sin_length;


int s;

s = socket(AF_INET, SOCK_DGRAM, 0);
if(!s)
{
perror("socket()");
return;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(34000);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
if(bind(s, (struct sockaddr *)&sin, sizeof(sin)))
{
perror("bind()");
return 1;
}


do
{
sin_length = sizeof(sin);
ret = recvfrom(s, msg, 10000, 0, (struct sockaddr *)&sin, &sin_length);
//Waits until a message is recieved...
printf("Message[%s:%d] : %s\n",
inet_ntoa(sin.sin_addr), sin.sin_port,msg);
}
while(msg[0]!='0');

close(s);
return 0;
}


Thats all
Tested and proved working on Fedora Core 6.
Do let me know your results and comments.....
To know more about the functions check the Linux Manual for each function.

Check out... (TCP/IP Transciever)
:)

Saturday, October 20, 2007

Disable Autorun Windows XP

Do this very important!!

Most viruses uses the autorun.inf to get itself infected on your computer. Autorun.inf is a small file that instructs the windows os to do when the CD is inserted into the computer. In genuine cases , it runs a setup in case of a Software Installation Disc. In the other case it may run a virus and gets your system infected. All you got to do to get the virus is put the CD. Same is the case for Mass Storage Devices like Memory Sticks, Pen Drives, Flash Drives etc.

So Disable your Autorun now


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Services\Cdrom\Autorun Change from 1 to 0


To disable Autoplay of all drives
Start > Run > gpedit.msc

Enable : Computer Configuration > Administrative Templates > System > Turn Off Autoplay

Friday, October 12, 2007

XPM File format

Intro
XPM or XPixMap is a bitmap format in unix based systems. It is a relatively easy format to understand, XPM files have a format similar to a C source code of a string array.


/* XPM */
static char * var name[] = {
"","","" //etc....
};


The first line is XPM in standard C comments. Second is an array declaration with a valid token as variable name.
The array index 0 [0] : contains the following %d %d %d %d [%d %d] [%d]
which are :
Width,Height,Number of colors, Characters Per Pixel, optional X & Y Hotspots, optional XPM Extension.
The array indexes 1-> number of colors indicates the color section.
The strings in these section take the following format :
%s %s %s
The first contains the characters that represent the pixels. The number of characters used to represent a pixel is given by Characters Per Pixel field in array[0].
The second string represents control characters that defines what the following field is about.
switch(control character)
{
case 'm' : Mono color
case 's' : Symbolic name
case 'c' : Color value
case 'g4': 4 Level Gray Scale
case 'g' : Grayscale
}

the third string is then
a color name eg: black
a # followed by RGB Hex
a % followed by HSV Hex
a symbolic name
a "None" indicating a transparent.

The rest of the section contains the actual pixels. With each (Character Per Pixel) representing a pixel on the screen. Each string is width pixels long and there will be height number of strings.

There might be an optional XPM Extension following the pixels.

Examples:

/* XPM */
static char * plaid[] =
{
/* plaid pixmap */
/* width height ncolors chars_per_pixel */
"22 22 4 2 0 0 XPMEXT",
/* colors */
" c red m white s light_color",
"Y c green m black s ines_in_mix",
"+ c yellow m white s lines_in_dark ",
"x m black s dark_color ",
/* pixels */
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
"Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x x x x x x x x x x x x x ",
"x x x x x x x x x x x x + x x x x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
"x x x x x x x x x x x x x x x x x x x x x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
" x x x Y x x ",
" x x x x Y x x x ",
"XPMEXT ext1 data1",
"XPMEXT ext2",
"data2_1",
"data2_2",
"XPMEXT ext3",
"data3",
"XPMEXT",
"data4",
"XPMENDEXT"
};

Another one :

/* XPM */
static char * example_xpm[] = {
"24 20 3 1",
" c None",
". c #0000FF",
"+ c #FF0000",
" ",
" .. ",
" .... ",
" ......++++++++ ",
" .........+++++++ ",
" ..........+++++++ ",
" ............++++++ ",
" .............++++++ ",
" ..............++++ ",
" +.............+++ ",
" ++.............++ ",
" +++.............+ ",
" +++++............. ",
" ++++++.............. ",
" ++++++++............ ",
" +++++++++........... ",
" +++++++++......... ",
" ++++++++++....... ",
" ++++++++++..... ",
" +++++++++ ... "};


Thats all
for a Hi Fi version
refer this.

Monday, October 1, 2007

PERL Referencing and Dereferencing

Intro

PERL - Practical Extraction and Report Language.

Referencing a variable means creating a pointer to the variable.
Referencing in C is done by the & operator, but in PERL referencing is done by the \(backslash) operator.

Check out the following examples to understand better:

my $scalar = "http://digitalpbk.blogspot.com";
my $scalar_ptr = \$scalar; //Scalar reference

my $array= (1,2,4,3,5);
my $array_ptr = \@array; //Array reference
//or

my $array_ptr = [1,2,3,4,5];//Array reference
//Note the [Square brackets]


my %hash = ("one",1,"two",2);
my $hash_ptr = \%hash; //Hash reference
//or

my $hash_ptr = {"one" => 1,"two"=>2};//Hash reference
//Note the {Curly brackets}


my $sub_ref = \&a_subroutine;//Subroutine reference
//or

my $sub_ref = sub { print "somethings"; };//Sub reference




Dereferencing is the opposite of referencing i.e, to get the value pointed by the referencing/pointing variable. Dereferencing in C is done by the * operator, whereas in PERL it is done by prepending, adding an appropriate @,$ or % to the reference variable.



my $scalar_ptr = \$scalar; //Scalar reference
my $scalar = $$scalar_ptr; //Scalar Var

my $array_ptr = \@array; //Array reference
//or

my $array_ptr = [1,2,3,4,5];//Array reference
my $array = @$array; // Array Var


my $hash_ptr = \%hash; //Hash reference
my %hash = %$hash //Hash Var

my $sub_ref = \&a_subroutine;//Subroutine reference
my $sub_ref = sub { print "somethings"; };//Sub reference
&$sub_ref //Call Subroutine



Thats all about referencing and dereferencing...

Monday, September 17, 2007

Introduction to Windows - Programming for Windows

History - DOS
Disk Operating System aka DOS was one of the earlier operating systems, it was a single task system, where the whole system and the OS was devoted to executing a single program and was basically a text based OS.

With the advent of the Windows Operating System, multiple process or applications could be run and it became a graphical OS (interface). So in order to support new features the basic structure of C/C++ programs changed from the main(){...} procedure to
something of a program as shown below and the a new compiler is required for compiling and generating Windows Executables, Visual C++ is such an example.

/*Program to
Display a Window on Windows
Test Compiled using Visual C++
*/


#include <windows.h>

LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);

char szWinName[] = "MyWin";

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgs,
int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;

wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hInstance;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = NULL;
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);

wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;

wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

if(!RegisterClassEx(&wcl)) return 0;

hwnd = CreateWindow(szWinName,"Windows XP",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);


ShowWindow(hwnd,nWinMode);
UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WindowFunc(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}


Windows OS Skeleton
Windows is called so because all things you see on your desktop is broken into small Windows. A Window can have many child windows, parent window, and many other windows on the same level.

Getting Started to Windows Programming in C(++)?
A minimal Windows program must have atleast 2 functions
  • WinMain()
  • WindowFunc()


the WinMain() Function
The WinMain() function is the entry point to your program, i.e, the execution of your program starts with WinMain().
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszArgs,int WinMode)

The WinMain function must
  1. Define a window class

  2. Register the class (RegisterClassEx)

  3. Create Window (CreateWindowEx)

  4. Display Window (ShowWindow)

  5. Get the message loop running(while(GetMessage(...)))



The contents in italics is the functions used for doing the specified actions. Check them out in the code.

the Window Procedure
The window Procedure is the link between your program and windows. It is the window procedure that windows calls to send messages to your application.

That's all for now
stay tuned.

Saturday, September 8, 2007

Perl - cPanel V3 and the @INC

Modifying @INC in a SCRIPT

use Module;

is executed during compile time so if you modify the @INC array at run time it will not be reflected back in the compile time. So if you have to include any more include locations in the @INC inside a script, give it inside the BEGIN { }block.


BEGIN
{
push @INC,"location";
}

The BEGIN blocks are executed during compile time. So @INC is updated at compile time and the use module are correctly searched for in the updated directories.

cPanel-v3 Script

my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;
}
}


This script dint work for me much, so I manually included the include locations into the BEGIN segment.


#! /usr/bin/perl -w
BEGIN {
unshift @INC,"/home/directory/perl/usr/lib/perl5/site_perl/5.8.7/";
}
.
.
.

Monday, September 3, 2007

Multiple Instances of yahoo messenger

Yahoo Messenger
is a popular instant messaging software around. Yahoo messenger, by default, runs only a single copy on a single machine so for people with multiple yahoo id's this is a problem. Here is a short snippet that makes yahoo messenger to run multiple versions.

REGEDIT
Open the registry editor.
Start > Run > regedit

Navigate to


+- HKEY_CURRENT_USER
+- Software
+- yahoo
+- pager


Create a new key inside pager named Test
Now inside the Test folder create REG_DWORD named pluralwith value 1.

Now you should be able to run multiple instances of yahoo messenger.

Alternate Method

Copy paste the text below exactly to a file with extension ".reg"


REGEDIT4

[HKEY_CURRENT_USER\Software\yahoo\pager\Test]
"Plural"=dword:00000001



Double click the reg file and press "yes".

Thats all folks

Long time since made a post.
Howz life guys ?

Saturday, August 4, 2007

Undocumented 8085 Instructions

8085 undocumented instructions
These are the undocumented 8085 instructions, undocumented due to incompatibility with 8086, Use them at your discretion. (information here is not sure yet, still worth a post)

DSUB
Hex Code: 08H
Description: BC pair is subtracted from HL Pair affecting all flags.

JNK [16bit location] - Jump to Location if 'K' flag is reset
Hex code : DDH

JK [16bit location] - Jump to Location if 'K' flag is set
Hex Code: FDH

RRHL - Rotate Right HL Pair
Description: Rotates the HL pair 16 bit towards right.
Hex code : 10H
Operands : none
Flags unaffected


RLDE - Rotate Left DE Pair
Description: Rotates DE Pair to left.
Hex code: 18H
Operands : none
Carry affected : depends on Bit 15

ADI HL - Add Immidiate to HL pair
Description: Adds an 8 byte number to the HL pair.
Hex Code : 28H
Operands : 8 bit number
Flags: All affected

ADI SP - Add Immidiate to Stack Pointer
Description: Adds an 8 byte number to the SP
Hex Code : 38H
Operands : 8 bit number
Flags: All affected

RSTV
Description: Does a RST 8 instruction when the 'V' (must be overflow)flag is SET.
Hex Code: CBH

LHLX
Description: Loads HL Pair with the contents of address stored in the DE pair
Hex Code: EDH

SHLX
Description: Stores the HL Pair contents to the address specified in the DE pair.
Hex Code: D9H


Help me!
Whats this K flag ? Any Intel engineers out there ?

Monday, July 30, 2007

Laptop to TV using S-Video Out Port

This post is applicable only to those laptops that are equipped with a S Video Out port (like Compaq Presario V3000 Series). The S-Video Port looks like


S Video port can be used to connect to your TV using a S-Video to RCA Cable. The S Video end of the cable looks like this


You can buy the S-Video to RCA cable, but building it is pretty much simple and costs negligible.

All you have to do is,
connect the Pin 1 and Pin 2 of the connector in S-Video to Ground of RCA
and short the Pin 3 and Pin 4 of S-Video to the Main Pin of RCA.
Some sites recommend using a 470pF Capacitor in shorting the Pin4 to RCA, but i really don't find much of a different when skipping the capacitor. Thus its just a DIY (Do-It-Yourself) project to make your laptop a DVD/CD player or make your TV a secondary monitor screen.

Compaq Presario V3000 Settings
In order to use the S-Video port the NVidia GeForce Go Graphics Drivers must be installed and working.

Don't have an S-Video Port ?
See other options of connecting a laptop to your television

Tuesday, July 17, 2007

CAPTCHA - What ?

What is CAPTCHA ??

Seems like a weird word, but seems to be familiar ...
CAPTCHA stands for Completely Automated Public Turing test to tell Computers and Humans Apart.

Simply, its a test to check if you are a human or not. A simple form of CAPTCHA is an image that contains a language or a sign which can be easily understood by a human being. On the other hand a bot or a program or simply a machine cannot understand. Given the image to a program it cannot see into and tell what's written in it (easily). CAPTCHA's are present in most sites including here. Try posting a comment and you will be asked to enter a word as shown in the figure.

CAPTCHA's are used to prevent bots or programs to spam the site with lots of biasing information or advertisements.

Effectiveness of CAPTCHA
CAPTCHA has been here for a couple of years and hence programs defeating the CAPTCHA's have obviously been developed! So how does an effective CAPTCHA system work?
A good captcha

  • Bend, Orient or change the fonts randomly
  • Has a random background colour, which is not uniform
  • Has little contrast
  • Has minimum sharp edges


Making your own CAPTCHA system

A simple CAPTCHA system can be made with PHP and the GD Library.
The PHP-GD Library is used to make CAPTCHA images on the fly with random letters.
The original text used in the image can be hashed by one way hashing algorithms such as MD5 and SHA. These hashes must be passed through a top-secret function that alters or encrypts the text again. The text is then set as a cookie.

Eg:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 25 Nov 1987 12:00:00 GMT"); // Date in the past
// Set the content-type
header("Content-type: image/png");
error_reporting(0);
// Create the image
$im = imagecreatetruecolor(200, 40);

// Create some colors
$colors = array(
imagecolorallocate($im, 0, 0, 0),
imagecolorallocate($im, 128, 0, 0),
imagecolorallocate($im, 0, 128, 0),
imagecolorallocate($im, 0, 0, 128),
imagecolorallocate($im, 0, 128, 128),
imagecolorallocate($im, 128, 128, 0),
imagecolorallocate($im, 128, 0, 128),
imagecolorallocate($im, 255, 0, 128),
imagecolorallocate($im, 128, 0, 255),
imagecolorallocate($im, 0, 255, 128),
imagecolorallocate($im, 255, 0, 0),
imagecolorallocate($im, 255, 0, 0),
imagecolorallocate($im, 255, 255, 255)
);
imagefilledrectangle($im, 0, 0, 199, 39, $colors[12]);

// The text to draw
$text = randomkeys(rand(6,8));

setcookie("secrethash",secret_function($text),time()+3600,"/"); // make your own secret function
// Replace path by your own font path

$font = 'tahoma.ttf';

$thsc=$colors[rand(0,11)];
// Add the text
$x=0;
for($i=0;$i < 6; $i++){
$angle=rand(-2,5);
$x+=18;
imagettftext($im, 24, $angle*2, 10+$x, 24, $thsc, $font, $text[$i]);//Add some tilts to make bots tough to read
}
// Using imagepng() results in clearer text compared with imagejpeg()
imagecolortransparent($im,$colors[12]);
imagepng($im); //Outputs the PNG
imagedestroy($im);?>


This CAPTHCA uses no background and hence only moderately secure (ie Keeps the kids away)

Now on the checking part the users text is passed through the same hashing function and top-secret function. Then the cookie value and the newly calculated value is compared to catch the bot ;).

...
A disadvantage of using CAPTCHA is for the visually challenged people. People with unclear eyesights colour blindness etc may face a problem in reading the CAPTCHA code. So the other CAPTCHA method is to use an AUDIO file, an MP3 instead of a JPEG or PNG.

Currently I do not know of any PHP libraries that makes MP3's on the fly. If anyone has any information on similar info, Please share ...

Happy filling in the CAPTCHA
;)

Saturday, July 7, 2007

e-Mail structure and Mail Dir File format

The MAIL Dir Format
MAIL Directory format is a format followed to store emails as files.
The Mail Dir format has 3 directories

  • new
  • cur
  • tmp


The new directory contains all the new mails, ie unread mails.
The cur directory contains all the read mails.
The tmp directory is a temporary directory used to store mails that are being received.
When a mail is read it is moved from new to cur.

All the emails are stored in files with a unique name (usually the message id).

The emails are stored as plain text in these files with the full headers and content.

The e-Mail Structure

Emails stored in the file with full headers and content.
The Email structure can be divided into
the head and body.
The head contains all the email related information

Return-path:
Envelope-to:
Delivery-date:
Received:
Message-ID:
Date:
From:
To:
Subject:
In-Reply-To:
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_21969_10709103.1184337589825"
References:


The body actually contains the contents it can be of many parts
HTML Part, Plain Text Part, Attachments , etc...

The various parts are divided by a boundary which is a unique string that appears nowhere else in the content.

Wednesday, July 4, 2007

cPanel Mail Forwarder

Forwarder

This handly little program forwardes all emails coming to a certain specified email address and forwards to a forwarding list.

Setting up the email capturing

e-Mail can be captured using a PERL script. The contents of the email must be pipped in. The capturing an passing of the email can be done through cPanel.


Click Mail

Click Forwarders

Add Forwarder


In the text box to the right side, you can provide an email address or a path to your PERL program that can process your email and extract relevant information.

In order to send the contents of the email to a PERL program we have to PIPE it to the program. PIPING is just redirection of standard output of the mail receiving program to your custom PERL script.
Eg:


"|perl /home/domain/scripts/process.pl"



#!/usr/bin/perl
use strict;


my $Email = join '',<STDIN>;

$Email // has your email contents

Saturday, June 30, 2007

Apple I-Phone Snaps




Menu


Dimensions


Maps


Inbox


Internet


Media Player

Loose (iTunes Version)


Keyboard


Voicemail


Stocks



© Apple Corp.

Saturday, June 23, 2007

JSON- Javascript Object Notation

Intro
JSON stands for Javascript Object Notation. JSON is a way of writing or expressing JavaScript Objects so that it can be easily read by both the computer and humans. Unlike XML or eXtensible Mark up Language the JSON is much more compact and easier to Parse.

XML takes the form


<Tag>
<Tag2>Information</Tag2>
<Tag>


JSON takes the form

var obj = {
an_array : [element1, element2 , element3 ....],
a_property : "property",
a_multi_array : [ [,,,],[,,,],...]
};


In order to parse an XML response, we have to use the following notation,
Suppose we are returning an XML response from a server using Ajax. The common method to extract the useful information is :

var xml = xmlHttp.responseXML;
var list= xml.getElementsByTagName("TAG");

for(i=0;i < list.length;i++)
{
// loop through and extract the values
}


This can be replaced with the new JSON object notation by

var strobj = xmlHttp.responseText;
var obj = eval("("+strobj+")");
obj.an_array[0];
obj.a_multi_array[0][0];
// ....


The Notation
All object lies between the { }
each of the properties has a label and an associated value or an array.
It is specified as label : value
a , separates the label-value pairs.
Arrays are enclosed in square brackets [ ] and comma separated.

In short a JSON object looks like

var blog = {
name: "the Digital Me",
author : "arun prabhakar",
pages : ["http://url1/","http://url2/"];
complexarray: [[0,10,10],[7,5,7],[1,9,8],[7,1,4]];
};


JSON and PHP
PHP has 2 built in functions to help with the JSON format.
json_encode
json_decode

Links

json.org
php.net JSON Functions

Tuesday, June 19, 2007

Yahoo! Built in chat with mail

Yahoo!
Catches up with Google and introduces the same Inbox + Messenger bundle. On the new yahoo mail beta now you can chat to your friends too.





At first look yea it rocks. It has almost all the formatting and smilies used by messenger. (Of course the Gizmos are missing).

But still gmail is ahead because, gmail allows you to be signed in on more than one place. For eg: mail and google talk. Yahoo does not allow that when you sign in inside the mail, you get disconnected on the messenger. I donno about you but hmmm I dint like that.

Secondly the gMail client is neatly presented on top of your mails, So you can go on reading the mails while your slow friend is finding the keys on keyboard ;)
Third, I hate that advertisement on the right edge! And most importantly it refreshes too often making it a pain! Of course I know free always implies filled with ads , but I guess this is a little too much.

What do you think?

Sunday, June 17, 2007

Perl Script to HTML formatter

Intro
This script converts a Perl Script to HTML so that it looks good with colour code formatting for keywords and variables. This isn't yet completed and may contain bugs but I guess its worth posting. Anyone is free to modify and redistribute the code as long as the first line remains intact.

Usage


perl format.pl ScriptFile.pl

Output will be saved as ScriptFile.pl.html

Script

style="color:#0ff">$cnt =~ s/&/&amp;/g;

$cnt =~ s/</&lt;/g;

$cnt =~ s/>/&gt;/g;







#Keywords



$keywords =~ s/ /)|(?:/g;



#Comments

$cnt =~ s/$singlecomment(.*)\n/<span style="color:#080">$singlecomment$1<\/span>\n/g;



$cnt =~ s/(?:<.*?>)*([\s)\[{;])((?:$keywords))([\s\[{(;])(?:<\/.*?>)*/$1<span style="color:#008;font-weight:bold;">$2<\/span>$3/g;

$cnt =~ s/([^\\])([\@\$].*?)([^a-zA-Z0-9_])/$1<span style="color:#0ff">$2<\/span>$3/g;



print $ARGV[0].".html";

open FILE,">".$ARGV[0].".html";

print FILE "<pre>$cnt</pre>";

close FILE;




Found a bug? (Plenty I know)
Post a comment with Line Number , Code , Correction.

Orkut Perl Script - Login, Scrapper and more

Intro
This is a PERL script that logs you into Orkut and allows you to scrap yiur friends. Following is the program and beneath it lies the manual to use the program. I assume that you already have PERL installed on your system with the required modules:

  • LWP
  • WWW::Mechanize


Program
#! /usr/bin/perl -w

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

use subs qw(print_c login logout home grab proces scrap);


#autoflush STDOUT 1;

printf ("%45s","Command Line Orkut\n");
printf ("%50s","By http://digitalpbk.blogspot.com\n");

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

@prc = ("\n","[FAILED]","[ OK ]\n");
#main loop
print_c;
while(<STDIN>)
{
chomp;
@args = split(/ /);

if(@args)
{
exit 0 if($args[0] eq "exit" || $args[0] eq "q");

if($args[0] eq "login") {login(@args);}
elsif($args[0] eq "home") {home(@args);}
elsif($args[0] eq "logout") {logout(@args);}
elsif($args[0] eq "grab") {grab(@args);}
elsif($args[0] eq "process") {proces(@args);}
elsif($args[0] eq "scrap") {scrap(@args);}
elsif($args[0] eq "populate") {populate(@args);}
elsif($args[0] eq "captchaget") {captchaget(@args);}
elsif($args[0] eq "clear") {system("clear");}
print "\n";
}
print_c;
}

exit 0;


sub print_c
{
print "";
print "> ";
print "";
}

sub login
{


print "\nGmail iD : ";
$email = <STDIN>;
print "Password : ";
$pass = <STDIN>;
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=<STDIN>;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!";

#for($i=3; $i>=0;$i--)
#{
# printf("\n%-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];

}

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 " Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);

print $prc[2];
}

sub home
{
REHOME:
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);
}

if($i<=0)
{
print $mech->response->as_string;
return;
}
print $prc[2];

if($mech->title !~ m/orkut.*home/i)
{

print $mech->response->as_string;
print "Not Logged In!",$prc[0];
print "\nLogin? [y] : ";
$com=<STDIN>;chomp $com;
if(not($com eq "n"))
{
login;
goto REHOME;
}
else
{
return;
}
}

#$mech->save_content("home.html");

$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
if($cnt =~ m/You are connected to <b>(.*)<\/b> people through <b>(.*)<\/b> friends./){
printf("\n%-20s: %0s (%0s)","Friends",$2,$1);}

if($cnt =~ m/([0-9]+) fans/){
printf("\n%-20s: %0s","Fans",$1);}

if($cnt =~ m/<b>([0-9]+)<\/b> scraps/i){
printf("\n%-20s: %0s","Scraps",$1);}

$cnt =~ m/my friends/g;
print "\nRecent : ";
while($cnt =~ m/Profile\.aspx\?uid=(.*?)">(<b>)*([^<]+)(<\/b>)*<\/a>/g)
{
print "\n\t$3";
}
}

sub grab_community
{
$comid = shift;
unless($file = shift)
{
print "\nFile to store : ";
$file = <STDIN>;
chomp $file;
}

$url = "/CommMembers.aspx?cmm=$comid";


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

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

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

if($mech->title !~ m/orkut.*Community.*Members/)
{
print "Unexpected Page ! : ",$mech->title;
return 0;
}


$cnt = $mech->response->as_string;
#$cnt =~ m/showing <b>1-15<\/b> of (.*?)<\/b>/g;
#print " $1";

open APP,">$file";
$grabed=0;
printf("%-25s","Grabbed: $grabed ");
for($page=2;;$page++)
{
while($cnt =~ m/Profile\.aspx\?uid=(.*?)">(<b>)*([^<]+)(<\/b>)*<\/a>/g)
{
$grabed++;
print APP "\n$1>$3";
}
print "\e[25D";
printf("%-25s","Grabbed: $grabed ");
sleep(3);
if($mech->find_link(text_regex => qr/next/i))
{
$mech->follow_link(text_regex => qr/next/i);
}
else
{
last;
}

last if(!$mech->success());

$cnt = $mech->response->as_string;
}
print "\nSaved to \"$file\"".$prc[0];
close APP;
return $grabed;
}

sub grab_flist
{

$comid = shift;
unless($file = shift)
{
print "\nFile to store : ";
$file = <STDIN>;
chomp $file;
}

$url = "/FriendsList.aspx?uid=$comid";


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

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

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

if($mech->title !~ m/orkut - (.*) Friends/)
{
print "Unexpected Page ! : ",$mech->title;
return 0;
}

print "$1 Friends : ".$prc[0];
$cnt = $mech->response->as_string;
#$cnt =~ m/showing <b>1-15<\/b> of (.*?)<\/b>/g;
#print " $1";

#$file =~ s/>//;
open APP,">$file";
$grabed=0;
printf("%-25s","Grabbed: $grabed ");
for($page=2;;$page++)
{
$cnt =~ m/Profile\.aspx\?uid=(.*?)">(<b>)*([^<]+)(<\/b>)*<\/a>/g;
while($cnt =~ m/Profile\.aspx\?uid=(.*?)">(<b>)*([^<]+)(<\/b>)*<\/a>/g)
{
$grabed++;
print APP "\n$1>$3";
}
print "\e[25D";
printf("%-25s","Grabbed: $grabed ");
sleep(3);
if($mech->find_link(text=> $page))
{
$mech->follow_link(text => $page);
}
else
{
last;
}

last if(!$mech->success());

$cnt = $mech->response->as_string;
}
print "\nSaved to \"$file\"".$prc[0];
close APP;
return $grabed;
}

sub grab_wild
{
$limit = shift;
$got = 0;
my $file;

unless($file=shift)
{
print "\nFile to store : ";
$file = <STDIN>;
chomp $file;
}


print "\nCommunity ID : ";
$comid = <STDIN>;chomp $comid;


open APP4, ">>$file";
print APP4 "\n<comment>CommMem $comid</comment>";
close APP4;

if($comid)
{
$got = grab_community($comid,">$file");
}
else
{
print "\nFriend ID : ";
$comid=<STDIN>;chomp $comid;
print $comid;
return 0 unless($comid);

open APP3, ">>$file";
print APP3 "\n<comment>FriendOf $comid</comment>";
close APP3;

$got = grab_flist($comid,">$file");
}

return 0 unless($got);

$offset=0;
$visits=0;
RESPIDER:
$file =~ s/>//;
open DLL, "$file";
@uids = <DLL>;
close DLL;

$cnt = join("\n",@uids);
$cnt =~ s/<comment>.*?<\/comment>//g;
@uids = split(/\n/,$cnt);
@uids = @uids[$offset..$#uids];

foreach $userid (@uids)
{
if($userid =~ m/([0-9]+)>/)
{
$file =~ s/>//;
if(open APP2, ">>$file")
{
print APP2 "\n<comment>FriendOf $1</comment>";
close APP2;
}
else {print $!," $file";exit}

$got+= grab_flist($1,">$file");
$visits++;
print " Got $got ".$prc[0];
last if($limit < $got);
}
}
if($limit > $got)
{
$offset = $#uids + 1;
goto RESPIDER;
}
print "\n Spider Results : ".$prc[0];
printf("%-30s : %0s\n","Indexed",$got);
printf("%-30s : %0s\n","Spidered",$visits);
print " Tip : Dont forget to simplify the uid file ".$prc[0];
}

sub grab
{
shift;
$what = shift;
$where = shift;
$file = shift;
if(!($what && $where))
{

print "\nArguments missing".$prc[0];
return;
}
if(lc($what) eq "comm" || lc($what) eq "community") {grab_community($where,$file);}
elsif(lc($what) eq "flist" || lc($what) eq "friendlist") {grab_flist($where,$file);}
elsif(lc($what) eq "wild") {grab_wild($where,$file);}
}



sub process_uids
{
my $file;
unless($file=shift)
{
print "\nFile to read : ";
$file = <STDIN>;
chomp $file;
}

open DLL, "$file";
@uids = <DLL>;
close DLL;

$cnt = join("\n",@uids);
$cnt =~ s/<comment>.*?<\/comment>\n//g;
$cnt =~ s/[\n]+/>/g;
$cnt =~ s/>//;

%hc = split(/>/,$cnt);

$file .= ".s";
if($dest = shift) {$file=$dest;}

open DLL,">$file" or die("$!");

$inx=0;
foreach $key (sort keys %hc)
{
$val = $hc{$key};
$inx++;
printf("%6d %28s %0s\n",$inx,"$key","$val");
print DLL "$key>$val>";
}
close DLL;

}


sub proces
{
shift;
$what = shift;
$file = shift;
$extra = shift;
unless($what)
{
print "\nArguments missing".$prc[0];
return;
}

if(lc($what) eq "uids") {process_uids($file,$extra); }

}






sub scrap
{
shift;
$pat = shift;

unless($source=shift)
{
print "\nFile to read : ";
$source = <STDIN>;
chomp $source;
}

if(!open FILE,"$source")
{
print " File not found!".$prc[0];
return;
}
@contents = <FILE>;
close FILE;
chomp @contents;
$cnts = join("",@contents);

$cnts =~ s/<//g;

%hc = split(/>/,$cnts);
$no = 1;
$scrapall=0;
$sc_start=0;
$sc_end=0;
@fkeys=();

$pat = ".*" unless($pat);

foreach $key (sort keys %hc)
{
$val = $hc{$key};
if($val =~ m/$pat/i)
{
printf("%6d %28s %0s\n",$no,"$key","$val");
$no++;
push @fkeys, $key;
}
}

if($no==0)
{
print " Friend Not found !".$prc[0];
}

print "Enter Friend # : ";
$myc = <STDIN>;
chomp $myc;
#todos ...

if($myc =~ m/([0-9]+)-([0-9]+)/)
{
$scrapall=1;
$myc=$sc_start=$1;
$sc_end=$2;
}

if($myc > $no)
{
print "Invalid Response!!!".$prc[0];return;
}
print "Enter Scrap Text : ";
$sctext = <STDIN>;
$sctext =~ s/\\n/\n/g;
#PS: Please do not remove the following if you really like this .... :)
#Please post a link to my website http://digitalpbk.blogspot.com
#thank you :)
$sctext = $sctext."\n[red](Powered by [blue]digitalpbk[/blue].blogspot.com)";
chomp $sctext;

SCRAPNEXT:
$friendid = $fkeys[$myc-1];

print " Scrapping $myc $friendid [$hc{$friendid}]".$prc[0];
sleep(4);
$url = "/Scrapbook.aspx?uid=$friendid";


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

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


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

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

if(($mech->title()) =~ m/orkut.*login/i)
{

print "Not Logged In!",$prc[0];
print "\nLogin? [y] : ";
$com=<STDIN>;chomp $com;
if(not($com eq "n"))
{
login;
goto SCRAPNEXT;
}
else
{
return;
}

sleep(3);
goto SCRAPNEXT;
}


if($cnt =~ m/"POST_TOKEN" value="(.*?)"/){
$post_token = $1;}

#print $post_token," ";
if($cnt =~ m/"signature" value="(.*?)"/){
$signature=$1;}
#print $signature;
sleep(3);
for($i=3;$i>=0;$i--)
{
printf( "%-60s","POST scrap");

#$mech->agent_alias("Linux Mozilla");
$mech->request(POST "http://www.orkut.com$url",["POST_TOKEN"=>$post_token,"signature"=>$signature,"scrapText"=>$sctext,"Action.writeScrapBasic"=>"Submit+Query"]);
last if($mech->success());

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

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

if($scrapall && $myc < $sc_end)
{
$myc++;
goto SCRAPNEXT;
}
print " Done.".$prc[0];
}

sub populate
{

shift;
$pat = shift;

unless($source=shift)
{
print "\nFile to read : ";
$source = <STDIN>;
chomp $source;
}

if(!open FILE,"$source")
{
print " File not found!".$prc[0];
return;
}
@contents = <FILE>;
close FILE;
chomp @contents;
$cnts = join("",@contents);

$cnts =~ s/<//g;

%hc = split(/>/,$cnts);
$no = 1;
$scrapall=0;
$sc_start=0;
$sc_end=0;
@fkeys=();

$pat = ".*" unless($pat);

foreach $key (sort keys %hc)
{
$val = $hc{$key};
if($val =~ m/$pat/i)
{
printf("%6d %28s %0s\n",$no,"$key","$val");
$no++;
push @fkeys, $key;
}
}

if($no==0)
{
print " Friend Not found !".$prc[0];
}

print "Enter Friend # : ";

$myc = <STDIN>;
chomp $myc;
#todos ...

if($myc =~ m/([0-9]+)-([0-9]+)/)
{
$scrapall=1;
$myc=$sc_start=$1;
$sc_end=$2;
}

if($myc > $no)
{
print "Invalid Response!!!".$prc[0];return;
}

ADDNEXT:
$friendid = $fkeys[$myc-1];

print " Adding $myc $friendid [$hc{$friendid}]".$prc[0];
sleep(4);
$url = "/FriendAdd.aspx?uid=$friendid";


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

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


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

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

if(($mech->title()) =~ m/orkut.*login/i)
{

print "Not Logged In!",$prc[0];
print "\nLogin? [y] : ";
$com=<STDIN>;chomp $com;
if(not($com eq "n"))
{
login;
goto ADDNEXT;
}
else
{
return;
}

sleep(3);
goto ADDNEXT;
}


if($cnt =~ m/"POST_TOKEN" value="(.*?)"/){
$post_token = $1;}

#print $post_token," ";
if($cnt =~ m/"signature" value="(.*?)"/){
$signature=$1;}
#print $signature;
sleep(3);
for($i=3;$i>=0;$i--)
{
printf( "%-60s","POST add");

#$mech->agent_alias("Linux Mozilla");
$mech->request(POST "http://www.orkut.com$url",["POST_TOKEN"=>$post_token,"signature"=>$signature,"level"=>"3","Action.yes"=>"Submit+Query"]);
last if($mech->success());

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

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

if($scrapall && $myc < $sc_end)
{
$myc++;
goto ADDNEXT;
}
print " Done.".$prc[0];



}


sub captchaget
{
$mech->request(GET "http://www.orkut.com/CaptchaImage.aspx");
open JPEG, ">captcha.jpg";

print JPEG $mech->response->content;
close JPEG;

}


Installing and Executing
To Install Copy the above full program. Paste it in a new text file and rename it as orkut.pl.
To Execute the program open a terminal / DOS Prompt and navigate to the folder where you have the orkut.pl.
Then type
perl orkut.pl


Getting Started
Once you execute the program you get a screen as follows

Command Line Orkut
By http://digitalpbk.blogspot.com
>


Quick Start Scrap all your friends

Command Line Orkut
By http://digitalpbk.blogspot.com
> login
> home
> grab flist [uid here Profile.aspx?uid=some numbers right? copy that numbers here]
Enter File : myfriends
> process uids myfriends
> scrap
Enter File : myfreinds.s
1
2
3
4
.
.
.
N
Enter Friend Number: 1-N
Enter Scrap text : This is coooool.




Avaliable commands
  • login: This command is used to Login into Orkut.com, you will have to enter a valid Username and Password to enter the site. If someone is already logged in the command asks your confirmation to logout that person and log you in or to continue with the existing.

    > login

    Gmail ID : example@example.com
    Password : Password

    GET /Home.aspx [ OK ]
    Parsing for Login Page [ OK ]
    GET https://www.google.com/accounts/ServiceLoginBox?service [ OK ]
    Logging In ... [ OK ]
    Continuing ... [ OK ]
    Parsing REDIRECT URL [ OK ]
    GET http://www.orkut.com/RedirLogin.aspx?msg=0&page=http%3A [ OK ]
    Logged In!



  • home: This command parses the Home.aspx file and gives you a summary of the page as shown below. If you are not logged in the command executes the login and continues if successful.

    > home
    GET /Home.aspx [ OK ]

    Friends : 291 (57,431,788)
    Fans : 138
    Scraps : 4
    Recent :
    abcd (305)
    xyz (391)
    def (151)
    I maybe wrong... (301)
    fghhh (376)
    someone (289)
    exmple (673)
    real (679)


    The number in brackets in friends indicate the total number of people in orkut.
    Recent shows the recently online friends on orkut. All others mean what they stand for.

  • grab what from [to] : Before you can start scrapping or do anything further, you must first build a database of friends or list of orkut id's. The Grab function is used to make the database. It takes two parameters and an optional third parameter:
    • what where: can take values [comm or community | flist or friendlist | wild ]

      comm or community : indicates that the list of friends is going to be grabbed from a community. In this case the from specifies a community id. (Community.aspx?cmm=ID)

      flist or friendlist: indicates that the list of friends is going to be from a friend's friends. In this case the from specifies the Orkut uid (FriendsList.aspx?uid=ID)

      wild : this is a combo of the above and grabs as much people specified by second parameter.

    • to : is an optional parameter that specifies the file to store the grabbed id's. If this parameter is left out, you will be asked to enter the file. If the file exists the new data is appended to the old file.


  • process uids : The grabbed ids by grab is not well formatted and may contain duplicates the process uids command formats the database and makes a final file. This command asks for the source file and makes a new destination file named by appending a .s extension to the original file. The formatted database is displayed.


  • scrap [filter] [source db] : is used to scrap multiple people. It takes 2 optional arguments.
    1. Filter : filters the source db according to the name. If skiped all persons in the database will be marked for scrapping.
    2. Source DB : The .s file that is required. If skiped you will be asked to enter location.


    > scrap just

    File to read : sample.id.s
    1 12312312313123123123 Just for keepin the communities
    Enter Friend # : 1
    Enter Scrap Text : hii \n how are you?
    Scrapping 1 12312312313123123123 [Just for keepin the communities]
    GET /Scrapbook.aspx?uid=12312312313123123123 [ OK ]
    POST scrap [FAILED] Retry (3)
    POST scrap [ OK ]
    Done.

    Enter Friend #: Takes a number or a format like X-X where X is a number. When X-X format is given all people between those two numbers will be marked for scrapping.

    Enter Scrap Text: The scrap text to be entered. To add new lines type \n and the scrap will have newlines when scrapped.

  • populate [Filter] [Source DB]: Same as scrap but this time its used to add the specified people as your friends.

  • captchaget : Just to read a Captcha and store the image as captcha.jpg



License
You are free to modify and edit by retaining a link or reference to this site.
There is no warranty what so ever. Any incidents of Orkut Banning you, or similar events shall not be my responsibility. Provided solely for education purpose. Any damage or inconvenience caused by the script is deeply regretted.
You have been warned.

Winding up...
I know this manual was too brief. I have tried as much to describe the Script. You will have confusions and doubts regarding the usage so please post your questions as a comment. I will be more than glad to answer them. If you really loved it or got it working or was helpful to you let me know. And dont forget to place a link to this page, if you are submitting to another site or forum.

Thanx Happy Orkutting...
:)

PS: If you noticed the Perl script colour coded, and like that check this out.