my fav list

  • www.creativehuman.blogspot.com

Sunday, February 22, 2009

Perl - Web Automation Lecture


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
yeah yeah I know everyones gonna /ignore kamikaze :)
and will come to that just in a few moments
actually i have a hell lot to say
and very lil time i suppose
*** P0rnKing is now known as X
how long do the lectures go on usually
* Kamikaze shuts up and listens up
this is the first time i am delivering one
as long as it takes till ppl are satisfactory
satisfied^
k..fine
so is the basic structire of a perl prog clear
yes
nope I missed it :)
*** s4m1k has joined #bsrf
then i revert back to the main topic of discussion
* Kamikaze will really shutup now... promise
*** ExposedTruth has quit IRC (Quit: )
now back to CGI_Perl
man the connection here in India sux
it is crawling
let us have a nice Graphical Interactivity
I'm now reading 'Teach yourself C in 21 days'
*** fatboyjoe has joined #bsrf
hmm
oops wrong chan
shite
*** s4m1k has quit IRC (Quit: [x]chat)
it's best if I leave
*** Kamikaze has left #bsrf
any doubts so far
any damn doubt that may be troubling anyone
what if it's not running UNIX?
then anyway u have to find a way to get ur program on the server
the web server..in the right location
the right path i mean
i am not familiar with the procedure for windowz tho
only when it is on the server .. can ur script be of any use
i have told .. how to get it running on UNIX
ok .. comin to where I left
the function for redirecting error messages
u have to try this .. code and learn
coz i have made it rigfht now
*** fatboyjoe has left #bsrf
so .. u get my point...;)
BEGIN {
use CGI::Carp qw(carpout)
open (LOG, ">>/var/local/cgi-logs/junk-error")
or die "Unable to append to junk-error: $!\n";
carpout(*LOG);
}
the carpout parameter is to carp-out or blurt out warnings or error returns
die is like exit()
to handle fatal errors
u can use
use CGI::Carp qw(fatalsToBrowser);
die "Fatal Error here!!";
Even if the error occurs before u get the HTTP header out
the module will try to take care of this to avoid the dreaded "500 server error"
how many of u r on a *NIX box
now?
yeah
or maybe do use a nix box freq.
*** snider has joined #bsrf
*** ChanServ sets mode: +o snider
i use it frequently but not right now
anyway .. even after taking care of errors if you happen to get the 500 server error
it means two things
on a Unix system either you dont have the right permissions
u can check that with the ls -l and assign the script (on the server of course) a 0755 pemission
0755 if u owned it
*** Satori has joined #bsrf
and 0555 owned by the designated user, assuming u r the SU
SU = super user
*** Dustin has joined #bsrf
kernel question:
also name it with a .cgi extension or .plx ext
the docs in one place say to use 2.7.2.3 to compile 2.4.6
in another it says NOT to use it
what gcc version do i need?
2.7.2.3 or 2.91.66 ?
tho not necessary some servers identify the ext also
*** suspect has quit IRC (Ping timeout: 180 seconds)
Dustin: The latest
in ur case 2.7 will do
i compiled a while ago with 2.96. something and got lots of errors
i maean 2.7.2.3
ok
wht errors
even though it says "*gcc 2.7.2.3 is no longer supportes*"
uhm,
yeah module and version dependencies are quite annoying and can be solved best by trial and error
*** zwanderer has joined #bsrf
let me rephrase it: it complied badly
x wouldnt start, lots of cryptic x errors
heheh i know it happens
anyway.. we are here for something else
a lecture is in progress
oh shit
so .. if u plz
*** SkyLemon has joined #bsrf
are the others listening
Hello, I need some help: What is the file on linux that you edit to shutdown any services / close ports??
...
for any queries regarding linux plz post them on messg board or mail me at tejanshu@rediffmail.com
*** Jesteruk has joined #bsrf
but plz do not go off the track
*** suspect has joined #bsrf
hum...hello peeps
just keep going bits
yeah .. ..
damn it i missed the lecture
a simple silly thing
never poo poo a lecture dude
* NIN_Dude kills jester
if u want to compile a perl prog
ah i see, nah i only write iot for CGI purposes
STFU
just use perl -wc cgi-script name=joe number=10
at the command prompt
*** HardW1r3 has quit IRC (Ping timeout: 180 seconds)
*** SkyLemon has quit IRC (Quit: )
this checks the validity of the program as well as runs with the mock input
aaah i see..i didnt know that
i got an apache web server setup..PHP mySQL support, and perl..i test em that way, didn't know you could simulate it liek that thru DOS prompt
well u know now ;)
DOS?
aye, NIN
*** zwanderer has quit IRC (Quit: off)
he means on the "console"
nm
yeah
i mean in that black bit where you type shit
;)
heh...
now how to make our scripts more efficient
this is mainly for Unix audience
As long as mine work, i'm happy
*** pitpat has joined #bsrf
Use mod_perl in the Apache server
wow bitsNbytes still going
go on dude...
>=)
also edit the httpd.conf as followz
I run mine on a unix server, just test em on here, i cant install linux cause i got a software modem, and im not financially able to buy new shit
*listenin*
Alias /perl/ /real/path/to/perl/scripts
the above line is not to be typed as it is
it means direct it to ur perl script directory
then in the next line
yeah, assign a virtual path to the system path

SetHandler perl-script
PerlHandler Apache::Registry
Options ExecCGI

leave a line
*** Dustin has quit IRC (Read error: 104 (Connection reset by peer))
PerlModule Apache::Registry
PerlModule CGI
PerlHandler On
this is what u have to type in your /etc/httpd.conf file
how exactly down the mod_perl thingy simply scripting?
the PerlModule CGI preloads the CGI module
down=does (beer)
*** pitpat has quit IRC (Quit: )
PerlHeader On makes most of your scripts run out of the box with mod_perl
hum , i see
now .. perl was designed to be a glue language
Recently ive been readin about perl with mySQL, i dun like PHP
that means it provide sscope for embedding code excerpts from other langs or some system calls
it has all the cool shit from other languages, and dont have the uncool shit..apparently
you can do so easily
i found a few good reads
and some shit ones
* NIN_Dude shoots jester in the face
hehehe
i fear you now.
now how about formatting lists and tables with HTML shortcuts
im listenin
for this purpose the CGI module provides HTML helper functions
*** Norton has joined #bsrf
which, when passed as array refernces(pointers to arrays)
*** TCL has joined #bsrf
*** ChanServ sets mode: +v TCL
which does what exactly?
oops...
apply themselves to each element of the referenced array ;)
for example
print ol(li(qw(red blue green)])};
sorry the last } is actually a )
hum, that looks irish to me
HTML
ol
li
ah..
qw?
perl?
what's perl?
yeah the qw is NEAT
you went over earlier
i forgot
:\
well damn it
rather than qoute each individual element passed as parameter
u just say qw(....)
*** TCL has quit IRC (Quit: 3 2 1, 1 2 3, who the heck is haxoring me?!)
so like string?
all the words within the braces get quoted individually
aaah
just like in the above line qw (red blue green) means
*** Grendel has quit IRC (Quit: brb)
("red", "blue", "green")
yeah
i got it now
*** Grendel has joined #bsrf
ok now the next line is
*** CHAOS has joined #bsrf
*** ChanServ sets mode: +v CHAOS

  1. red
  2. blue
  3. green

*** Jesteruk has left #bsrf
let us see how this workz when implemented actually
www.www.www
what's the print ol(li(qw(red blue green))) do?
coming to it
k
just give me some time
i am having a nasty time with the ****ing connection here
use CGI qw(:standard :html3);
%hash = (
*yawwwnie!*
"BitsNbytes => ["Alcoholic", "druggie", "nerd"]
*** _ciR_ has quit IRC (Ping timeout: 180 seconds)
"lamest1 => ["Cool", "lame", "funny"]
);
$\ = "\n";
print "
*** nskl has joined #bsrf
print Tr (th [qw(people type)]);
for $k (sort keys %hash) {
*** Binary_Dealer has joined #bsrf
yummy.. I got an italian sub from 7-11
ppl =)
What's Up?
*** blue|bestbuy is now known as bluehaze
*** NIN_Dude has quit IRC (Quit: )
print Tr(th($k), td( [sort @hash($k)}]));
somebody saw essex
}
??
hehhe
he was on last night
yes
today?
print "
People I know
;
dunno
*** NeoMeg has joined #bsrf
this generates text like

is this the perl lecture?

yep
ok
*** divinator has joined #bsrf
so u see perl a small perl code can generate a neatly formatted form with lists and tables
*** div|busy has quit IRC (Local kill by divinator (get lost you damn prick))
u can generate a lengthy HTML form
*** divinator has left #bsrf
*** divinator has joined #bsrf
full of lists and tables just by one statemet
*** sohed has quit IRC (Quit: )
*** phanatic has joined #bsrf
print table caption(text), Tr(th [qw(text)])
i got a question...
map {tr(th($_), td( [sort @($hash)})
can perl help us get laid?
cuz I told everyone that it could
and I just want to be sure
u mean as in ****ed laid
yes of course
yes
yeah sur
bluehaze has never gotten laid
cool
in his life
*** HaloScan has quit IRC (Ping timeout: 180 seconds)
back to the pearl
lol
where can i learn to chain proxies??
someone wanted to know redirection to other sites in PERL-CGI
certainly not here and not now .. sorry ;)
*** Leper has joined #bsrf
u use the redirect function
I have a peice of code for that too
i know i have become terrible and painsatakingly annoyingly boring by now
but hey .. that's me aight
so plz bear
hey you're cool enough to do this, how can we complain?
any one from the beginning still hangin around
*** josh-hamster is now known as josh-hamsTERRORIST
(dozin around would do.. :)
I just got here
so you gotta start over
nooooooooo
hehehe
you have to ask questions and i answer them in short .. after seeing the code that is
oh
so HERE COMES THE CODE
well...
oh
ok
ok
actually it is quite a skill to write code on the fly and on demand
i am trying to do so right now
*** NeoMeg has quit IRC (Quit: )
anywaz here it comes
*** barcode has joined #bsrf
#! /usr/bin/perl -w
# orebounce - aprogram to redirect browser and set a cookie
*** wHiTE_zoMBIe has joined #bsrf
use CGI qw(:cgi);
$oreo = cookie (- NAME => 'filling',
how big is X?
-VALUE => "Lard Ass",
-EXPIRES => '+3M',
-DOMAIN => ',perl.com');
*** Leper has quit IRC (Quit: Leaving)
$whithergo = "http://somewhere.perl.com/nothinghere.html';
*** bluehaze has quit IRC (Quit: 15,1?ShowDowN v12 PrO?1 since 1996: 16,1http://www.sci.fi/~showdown/)
print rediredt(-URL => $withergo,
-COOKIE => $oreo);
well that was the code
and that would produce something like
Status: 302 Moved Temporarily
*** wHiTE_zoMBIe has quit IRC (Quit: Client Exiting)
Set-Cookie: filling=LardASS; domain= .perl.com;
expires = DD-MM-YY Time GMT
*** zwanderer has joined #Bsrf
Date: day DD-MM-YY Time GMT
Location: http://somewhere.perl.com/nothinghere.html
Content-Type: text/html
B<>
any questions


End Of Lecture

No comments:

Post a Comment

 
People I have Known
People