Perl - Web Automation Lecture
By BitsNbytes
for
http://blacksun.box.sk
*** bitsNbytes has joined #bsrf
hi ppl
I am EXtremely sorry for being late
should we begin with the lecture
just when everyone had given up hope of seeing it
yeah ..sorry man
heh
oh well
better late than never I guess :)
K..is everyone eager and attentive
oh
yea
hehe
i'm all ears
finally
;O)
lol
=)
ok bits
are you doing it on perl?
k..the connection here in India is haywire t'day
and hence the delay
yeah..i'd like to know if there r total newbies too
<--- newbie of perl
i mean those who are absolutely oblivious to the existence of perl and its basics
*** Getalife has joined #bsrf
*** _ciR_ has quit IRC (Ping timeout: 180 seconds)
Any phreakers around?
<--- not that much of a newbie
hehe
hmm good then
what i am about to share with you t'day is the relation of perl and the web
cgi
common gateway interface
PRECISELY
;O)
hmm i have got a learned audience .. i must say
*** wascy|prepare_hack is now known as wascy
go on...
when we talk of cgi..
we are talking about dynamic information
and interactivity
server-side
web
yess.. that is what makes the web so ALIVE
*** jacs has quit IRC (Ping timeout: 180 seconds)
Perl very much like other languages
doesn't need to be compiled
supports the concept of modularity
ok.. that too (very basic tho) ;)
*** wascy has quit IRC (Quit: )
*** jacs has joined #bsrf
all modules are available today on Comprehensive Perl Archive Network (CPAN)
for Perl and CGI to be integrated we need the cgi.pm module
Any phreakers around?
*** fatboyjoe has quit IRC (Ping timeout: 180 seconds)
that has to be included in our pel script
*** _ciR_ has joined #bsrf
ciR
i found the lecturer
<_cir_> who
bitsNbytes
*** demontanus has quit IRC (Quit: Math is like sex. Add the people, subtract the clothes, divide the legs, and multiply.)
hehe
let us begin with a sample basic program
<_cir_> hehe
don't do the hello world plz
:O(
<_cir_> looks like bsrf ous u
nah don't worry
can you go a bit faster bits?
i'm getting sleepy
i am trying
but the network connection seems to be outof order
#! /usr/bin/perl -w
this is the line that acts like a include <> line in C
the -w is for warnings on
# a program for your type of babe
this was a comment
*** rek has joined #bsrf
*** ChanServ sets mode: +o rek
hey
*** Arrowhead has quit IRC (Quit: )
use CGI qw (param) # a very important line.. includes the cgi.pm module
no lecture?
yea bitsNbytes is doing it right now
print < Content-type: text/html #needs no explanation
My kinda girl
*** fatboyjoe has joined #bsrf
Can anyone assist me in making a scanner out of a cordless phone?
<_cir_> hahah not its HTML lecture
<_cir_> then hahah,
*** rek has quit IRC (Quit: Leaving)
Greetings Mortal
*** rek has joined #bsrf
*** ChanServ sets mode: +o rek
*** rek sets mode: +v bitsNbytes
END_of_start
*** sohed has joined #bsrf
*** zwanderer has joined #bsrf
my $favorite=param("brunette");
print " Your favorite flavor is $favorite.";
print <
ALL_Done
well was this understood
*** freespeachlamer has joined #bsrf
is the lecture over?
we just created a small basic interactive CGI-perl script that propmts the user for his
favorite chick type
*** TCL has joined #bsrf
*** ChanServ sets mode: +v TCL
umm can someone send me a log of the lecture?
no ... its just begun
oh
sorry :)
bitsNbytes: your a little late
now if we don't wanna type all that HTML stuff
OK .. so what do u sugget "rek"
i mean suggest
what u mean?
yeah .. i know i am late .....??
as long as there are a pair of attentive ears .. it's ok
well, we had a lot more people, lot of us left @ 1:30...
i was just makin sure u know.. go on with the lecture
yeah .. iknow and i am sorry (for the umpteenth time now)
*** jacs has quit IRC (Ping timeout: 180 seconds)
ok lemme ask how many of us are familiar with basic unix concepts and cgi scripting
not me =p
*** jacs has joined #bsrf
* rek is
* fatboyjoe is
so i can really move on to REAL stuff
* freespeachlamer is not
but dont worry about me :)
*** freespeachlamer has quit IRC (Quit: )
then let us begin with what we really can do
k let us see this bit complex program i'vbe written
#! /usr/bin/perl -w
*** rek sets mode: +m
*** zwanderer has quit IRC (Quit: bye bye peppe)
# this program loads the cgi module to decide information by web server
use strict;
bbl have to leave
*** pitpat has quit IRC (Quit: )
*** rek sets mode: -m
*** rek has quit IRC (Quit: )
man .. am i that boring
lol'
lol
nope, go on
# the strict module ensures your code is in order and within the norms
so we write
use strict;
use CGI qw (:standard escapeHTML);
# now to get a parameter from a form
my $value=param ('PARAM_NAME');
*** Getalife has quit IRC (Read error: 104 (Connection reset by peer))
# and output a document
print header(), start_html("Howdy there!"),
p("U typed: ", tt(escapeHTML($value))),
end_html
some explanation now
CGI scripts are called in two main ways
referred to as "methods" --> not HTTP methods
one is the procedural method.. the other is object oriented
procedural for simple tasks
and object oriented for complex ones
our little program here can be analyzed as follows
*** X has joined #bsrf
*** DigitalFallout has quit IRC (Read error: 104 (Connection reset by peer))
as u might have guessed $anything stands for variable declaration in perl
meaw
perl supports all kinds of data types
*** essex has joined #bsrf
collectively called as "scalar variables"
u no longer have to specify a "type"
Hi ya
u just say $whatever = somevalue
the "my" reserved word makes that particular variable or parameter
passed to a subroutine "local" to ur specific program
i.e. "my" for locality of reference ..ok
* essex want's to know if anyone knows a good VB decompiler
the header() returns a string content type
followed by the start_html
which returns the string, passed as parameter ,
*** phil has quit IRC (Remote closed the connection)
*** TCL has quit IRC (Quit: BBL)
ok.. now how do we use this program
i hope whatever i said was not too obvious
anywayz
i shall tell u how to get this prog running under UNIX
since I have very lil knowledge bout windowz
generally we place this program on a web server (running APACHE preferrably)
path-> /home/httpd/cgi-bin/program
where program is the program name
*** josh-hamster has joined #bsrf
and then use a browser lynx (for the console) Netscape, Amaya (for Xwin)
get the program running
am i .. making any sense to u ppl
feedbacks plz
yeh
yes
OKay!
:)
some of you might be wondering why the HELL use Perl
there are many reasons ..out of which some are
PERL -->Practical Extract Report Language--> created by Larry Wall
*** BootError has joined #bsrf
is one of the most Powerful Scripting language on earth
apart from being a scripting language .. it also incorpaorates the best of C and C++
thus in short PERL is a superset of scripting lang, C and C++
*** [PhaLanX] has joined #bsrf
Who was the only guy to get his work done by Friday ?
the creator and other contributors have now thought of bringing this power to the Web
eh ?
*** ^CoaXiaL^ has quit IRC (Quit: )
suspect: something important ....?
i guess not
* NIN_Dude slaps suspect around a bit with a large trout
so let us move on to error handling
supposing u have trouble tracking down you scripts warnings
and error mesages, or your scripts STDERR output is confusing you
*** kamm has quit IRC (Quit: Leaving)
we use the CGI::Carp module
it is easy to understand if u know C++
it is analogous to using a class called CGI
and the "carp" portion of it
*** essex has quit IRC (Read error: 104 (Connection reset by peer))
i will now create a small prototype
to redirect errors to files of your choice
BEGIN
{
i wonder why nobody has any doubts
guess either i am talkin to myself or i am speaking in ancient phoenetix
anywaz
BEGIN
{
im listening
me too
* NIN_Dude raises his hand
use CGI::Carp qw(carpout);
*** X is now known as Pr0nKing
yes
*** Pr0nKing is now known as P0rnKing
NIN_Dude:........?
um.. BEGIN?
as in class?
*** fatboyjoe has left #bsrf
* NIN_Dude cries
yes exactly
oh aight
notice the "qw" i am using frequently
it stands for quote words and is a wonderful lil reserved word
OK .. lemme switch back to basics and discuss a small simple perl program to
make things more clearer
*** [PhaLanX] has quit IRC (Quit: )
#! usr/bin/perl -w
print "Identify yourself!";
$name = ;
chomp ($name);
if ($name eq "PootieTang")
{
*** jacs has quit IRC (Quit: )
print " Hi there Pootie, You r simply the best!\n";
}
else{
print "Who r U $name\n";
}
chomp?
parsin?
coming .. to it
*** Kamikaze has joined #bsrf
what is an stdin, stdout, and stderr?
ok
standard
input
* NIN_Dude shuts up
aye...........
chomp cuts out the newline character
not really much help but thanks anyway
the entire string is taken along with the newline char also a part of it
so u need to cut it off
oh I see the tutorial is underway, sorry for interrupting
there is a function called "chop" also
does chomp cut off the last char or just the newline?
good question NIN
chop does cut off the last char
but not ole chomp
dammit this sounds like school
lol
it just does away with the \n
hehe
is it clear ;)
really sorry for interrupting here but have you covered website redirection yet?
i have covered basic perl-cgi script and error redirection