Showing posts with label Dataone. Show all posts
Showing posts with label Dataone. Show all posts

Monday, July 7, 2008

Hosting a Site at your Home using Dataone

Intro

This is just a timepass for anyone who would want to try making their home PC to a server. The details are for my BSNL Dataone Router WA300XXX, But you can do it on any router provided your ISP supports, it works for BSNL (Bharath Sanchar Nigam Limited, INDIA) (Hurray!) .

So the first step is to setup apache, HTTP Server. I have covered this topic in my earlier post and doesnt want to repeat

Quick install for Linux/Debian way :

sudo apt-get install apache2


On the router..
Once having done that next step is to open a PORT in the router and forward the port to our PORT 80 on your computer. Port 80 is the default HTTP port. You can open up any port in the router, say 2345.

I did it using telnet and the way to open up a port differs from router to router.
Most modem hosts a site and runs a server internally at port 80, so you can try http://192.168.1.1
or the IP address of the router.

It will ask for a username and password.
The default username and password for the router is admin

Find out NAT
Here is my screen shot of the page


Add an entry similar to that

Name : http # Whats in a name ?
External Port : 2345 #You choose, 80 may not work
Protocol : TCP
Internal Port : 80
Server IP : 192.168.1.232 #thts me


Ok I guess thats it!

Restart your modem
Find your IP
and suppose your ip is AAA.BBB.CCC.DDD

People outside can access your site http://AAA.BBB.CCC.DDD:2345/
(as long as your ip is valid and your computer is on)

What abt something like www.yourname.com?

For that you gotta pay, Since remebering numbers is not so good when compared to memorizing a name a DNS system is used. And to get into a DNS you will need a static IP and pay to point a www.yourname.com to your static IP. There are workarounds for everything, if anyone is generous to comment on this, please help. :)

One more thing
You cant access the site from http://AAA.BBB.CCC.DDD:2345/, for that http://localhost is better.

Try it out...

Sunday, June 29, 2008

Dataone Account Usage Checker in PERL

The following Script in PERL is a Dataone account usage checker.


#!/usr/bin/perl
# http://digitalpbk.blogspot.com/2008/06/free-dataone-account-usage-checker-perl.html

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

my $verbose = 0;
my $username;
my $password;
my $url="http://10.240.64.195/weblogin.jsp";

for(my $i=0;$i<=$#ARGV;$i++)
{
if($ARGV[$i] eq "-v" or $ARGV[$i] eq "--verbose"){ $verbose = 1; }
elsif($ARGV[$i] eq "-u" or $ARGV[$i] eq "--user"){ $username = $ARGV[++$i]; }
elsif($ARGV[$i] eq "-p" or $ARGV[$i] eq "--pass"){ $password = $ARGV[++$i]; }
elsif($ARGV[$i] eq "-i" or $ARGV[$i] eq "--url"){ $url = $ARGV[++$i]; }
}
unless($username)
{
print "Username : ";chomp($username = <STDIN>);
}
unless($password)
{
print "Password : ";
`stty -echo`;
chomp($password = <STDIN>);
`stty echo`;
print "\n";
}
$cj = HTTP::Cookies->new(file => "cookie.jar",autosave=>1);
$mech=WWW::Mechanize->new(cookie_jar=>$cj);

print "GET $url\n" if($verbose);
$mech->get($url);
exit unless($mech->success());

my $cnt = $mech->response->as_string;

$cnt =~ s[action="../(.*?)"][action="$1"]is;
$mech->update_html($cnt);

$mech->form_number(1);
$mech->field("username",$username);
$mech->field("password",$password);
print "LOGIN\n" if($verbose);
$mech->submit();

exit unless($mech->success());
$cnt = $mech->response->as_string;

$|=1;
my $uri;my $maxre=0;
while($cnt =~ m/location.replace\('(.*?)'\)/is)
{
print "FOLLOWING .. " if($verbose);

$uri = $1;
if($uri =~ m/loginerr/g)
{
print "\nLOGIN Failed !\n";
exit;
}

$mech->get($uri);
exit unless($mech->success());
print $uri,"\n" if($verbose);
$cnt = $mech->response->as_string;
last if($maxre++ > 4);
}

exit if($maxre > 4);
print "GET Service Records\n" if($verbose);
$mech->get("serviceRecords.jsp");
exit unless($mech->success());
$cnt = $mech->response->as_string;

$mech->form_number(1);
$mech->submit();
print "POST Form\n" if($verbose);

$cnt = $mech->response->content;
$cnt = $1 if($cnt =~ m:<body[^>]*>(.*?)</body>:sig);

$cnt =~ s/<[^>]+>//sig;
$cnt =~ s/&nbsp;/ /sig;
$cnt =~ s/([\n\r\t ]){2,}/;/sig;

$cnt = $1 if($cnt =~ m/(Total Send Volume([^;]+;){10})/);

@sl = split /;/,$cnt;

$sl[4] = "Excluding Night";
for($i=0;$i<=($#sl/2);$i++)
{
printf("%25s : %s\n",$sl[$i],$sl[$i+5]);
}

$mech->get("../logout.jsp");



Installation

On Linux
Copy paste to a new file data1.pl
Install WWW::Mechanize if not already installed.

chmod 755 data1.pl


On Windows
Copy paste to a new file data1.pl
Get Active Perl and install if PERL is not installed.
Install Module WWW::Mechanize.

Usage
Linux
./data1.pl Options


Windows, not TESTED
perl data1.pl Options

PS : Comment `stty` lines when using on windows or ignore the errors
perl data1.pl -u username -p password


Options
No need any if your not good at the Command line.
-v to turn on Verbose, describe what is being done.
-u username to specify username
-p password to specify password

...
Any more doubts ?
Use the link that says comment
;)


100th

Post