home *** CD-ROM | disk | FTP | other *** search
- Util-Lib
- #Author: Josias L. de Santana Basilio
- #Do not change the lines of @headers. Add news headers to the final.
- #Sintax: &headers([number[:value]],...);
- sub headers{
-
- local(@in) = @_;
-
- @in = sort {$a <=> $b} @in;
-
- local($_,$name,$value,$age,$path,$num,@header);
-
- @header = ('200 Ok',
- '201 Created',
- '202 Accepted',
- '203 Non-Authoritative',
- '204 Non Content',
- '300 Multiple Choice',
- '301 Moved Permanentely',
- '302 Moved Temporarily',
- '303 See Other',
- '304 Not Modified',
- '400 Bad Request',
- '401 Unauthorized',
- '402 Payment Required',
- '403 Forbidden',
- '404 Not Found',
- '405 Method Not Allowed',
- '406 None Acceptable',
- '407 Proxy Authentication(Unauthorized) Required',
- '408 Request Timeout',
- '409 Conflict',
- '410 Gone',
- '411 Authorization Required',
- 'Server:',
- 'Date:',
- 'Expires:',
- 'Location:',
- 'Last-modified:',
- 'Set-cookie:',
- 'Allow: Get, Post',
- 'text/html',
- 'image/gif',
- 'image/jpeg',
- 'text/plain',
- 'text/richtext',
- 'image/tiff',
- 'image/x-rgb',
- 'image/x-bitmap',
- 'audio/basic',
- 'audio/x-wav',
- 'video/mpeg',
- 'video/quicktime',
- 'video/x-msvideo');
-
- foreach(@in)
- {
- # STATUS
- if($_<22)
- {
- if(!$num)
- {
- print "HTTP/1.0 $header[$_]\n";
- $num++;
- }
- }
- # SERVER
- elsif($_==22)
- {
- print "Server: $ENV{'SERVER_SOFTWARE'}\n";
- }
- # DATE
- elsif($_==23)
- {
- &date(0);
- print "Date: $result\n";
- }
- elsif(/\:/)
- {
- # EXPIRES
- if($`==24)
- {
- &date($');
- print "Expires: $result\n";
- }
- # LOCATION
- elsif($`==25)
- {
- print "Location: http:\/\/$'\n";
- }
- # LAST-MODIFIED
- elsif($`==26)
- {
- $age = -M "$'";
- $age *= 86400;
- &date(-$age);
- print "Last-modified: $result\n";
- }
- # SET-COOKIE
- elsif($`==27)
- {
- ($name,$value,$age,$path) = split(/\&/,$',4);
- if($age)
- {
- $age = "\; expires=".&date($age);
- }
- else
- {
- undef $age;
- }
- $path = "\; path=\/$path" if $path;
- print "Set-Cookie: $name\=$value$age$path\n";
- }
- }
- # CONTENT-TYPE
- elsif($_>28&&$_<40)
- {
- print "Content-type: $header[$_]\n";
- }
- # OTHERS
- else
- {
- print "$header[$_]\n";
- }
- }
- #Blank line. End of headers
- print "\n";
-
- return 1;
- }
- #---------------------------------------------------------------------------
- #By Steven Brenner. URL: http://cgi-lib.stanford.edu/cgi-lib/
- sub ReadParse {
-
- local (*in) = @_ if @_;
-
- local ($i, $loc, $key, $val);
-
- if ($ENV{'REQUEST_METHOD'} eq "GET")
- {
- $in = $ENV{'QUERY_STRING'};
- }
- elsif ($ENV{'REQUEST_METHOD'} eq "POST")
- {
- read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
- }
-
- @in = split(/&/,$in);
-
- foreach $i (0..$#in)
- {
- $in[$i] =~s/\+/ /g;
- ($key, $val) = split(/=/,$in[$i],2);
-
- $key =~s/%(..)/pack("c",hex($1))/ge;
- $val =~s/%(..)/pack("c",hex($1))/ge;
-
- $in{$key} .= "\0" if (defined($in{$key}));
- $in{$key} .= $val;
- }
- return 1;
- }
- #---------------------------------------------------------------------------
- #Sintax: &parseVar(Scalar_to_be_parsed);
- sub parseVar{
-
- local($in) = @_;
-
- if($in=~/[\s]/g)
- {
- $in=~s/\s//g;
- }
-
- #Bad Characteres
- #if($in=~/\W/g)
- if($in=~/[\"\'\!\@\#\$\%\¿\&\*\(\)\_\+\=\\\<\>\:\?\/]/g)
- {
- $_ = "Data with invalid character(s)!";
- return 1;
- }
- elsif(not($in))
- {
- $_ = "No Data!\n";
- return 1;
- }
-
- return 0;
- }
- #---------------------------------------------------------------------------
- #Based on the example at:
- # http://www-frd.fsl.noaa.gov/~moninger/web101/4-lecture/big_code.cgi/
- # 1_expire_example.cgi.htm
- #Sintax: &date[seconds_to_add];
- sub date{
-
- $ENV{'TZ'}="GMT";
-
- local($_)=@_;
-
- local(@month,@day);
-
- local($time)=time() + $_;
-
- local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($time);
-
- @month=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
- @day=(Sun,Mon,Tue,Wed,Thu,Fri,Sat);
-
- #@month e @day
- $wday_name=$day[$wday];
- $month_name=$month[$mon];
-
- $exp_time = sprintf("$wday_name, "."%02.2d $month_name 19$year ".
- "%02.2d:%02.2d:%02.2d GMT",$mday,$hour,$min,$sec);
-
- $result="$exp_time";
-
- return ($result);
- }
- #---------------------------------------------------------------------------
- #Sintax: &pass(current_password,[new_password],[repeated_new_password]);
- sub pass{
-
- if($#_==2)
- {
- local($current_password,$new_password,$rep_password) = @_;
- if(($current_password eq "") && ($new_password eq "") && ($rep_password eq ""))
- {
- $_ = 'No password writen!';
- return 0;
- }
- elsif(($current_password eq "") or ($new_password eq "") or ($rep_password eq ""))
- {
- $_ = 'Any required password not writen!';
- return 0;
- }
- elsif($current_password =~ /\W/g)
- {
- $_ = 'Current Password with invalid character!';
- return 0;
- }
- elsif($current_password eq $new_password)
- {
- $_ = 'Current password equal New Password!';
- return 0;
- }
- elsif($new_password =~ /\W/g)
- {
- $_ = 'New password with invalid character!';
- return 0;
- }
- elsif(length $new_password < 6)
- {
- $_ = "Length of New password less than 6 characters\!";
- return 0;
- }
- elsif(length $new_password > 10)
- {
- $_ = 'Length of New password greater than 10 characters!';
- return 0;
- }
- elsif($new_password ne $rep_password)
- {
- $_ = 'New password not equal to Repeated password!';
- return 0;
- }
- }
- elsif($#_)
- {
- local($new_password,$rep_password) = @_;
- if(($new_password eq "") or ($rep_password eq ""))
- {
- $_ = 'New/Repeated password not writen!';
- return 0;
- }
- elsif($new_password =~ /\W/g)
- {
- $_ = 'New password with invalid character!';
- return 0;
- }
- elsif(length $new_password < 6)
- {
- $_ = "Length of New password less than 6 characters\!";
- return 0;
- }
- elsif(length $new_password > 10)
- {
- $_ = 'Length of New password greater than 10 characters!';
- return 0;
- }
- elsif($new_password ne $rep_password)
- {
- $_ = 'New password not equal to Repeated password!';
- return 0;
- }
- }
- elsif($#_==0)
- {
- local($current_password) = @_;
- if($current_password eq "")
- {
- $_ = 'Current password not writen!';
- return 0;
- }
- elsif($current_password =~ /\W/g)
- {
- $_ = 'Current password with invalid character!';
- return 0;
- }
- }
-
- return 1;
- }
- #---------------------------------------------------------------------------
- #Sintax: &email(email_to_be_parsed);
- sub email{
-
- local($in) = @_;
-
- #Most common mensage
- local($i) = "Invalid Email format!";
-
- #Fin point(.)
- if($in=~/\./)
- {
- # Find (.@), (@.),(.@.),(..), or (.) extremity
- if(($in=~/\.\@/g) or ($in=~/\.\./g) or ($in=~/\@\./g) or ($in=~/\.$/) or ($in=~/^\./))
- {
- $_ = "$i";
- return 0;
- }
- # If format OK, delete points
- else
- {
- $in=~s/\.//g;
- }
- }
-
- #Remove first @
- if($in=~/\@/)
- {
- #if ()@(xx(@)xx) or (xx(@)xx)@() or (xx(@)xx)@(xx(@)xx)
- if(($` eq "") or ($' eq "") or ($' =~/\@/g))
- {
- $_ = "$i";
- return 0;
- }
- # Find invalid character
- elsif(($` =~/\W/g) or ( $' =~/\W/g))
- {
- $_ = "Email with invalid character!";
- return 0;
- }
- }
- elsif($in)
- {
- $_ = "$i";
- return 0;
- }
- elsif(not $in)
- {
- $_ = "0:No Email to be parsed!";
- return 0;
- }
-
- return 1;
- }
- #---------------------------------------------------------------------------
- #Sintax: &browser[(1)- Return the complete borwser┤s name];
- sub browser{
-
- local($in,$versao,$nome,$_);
-
- $in = @_;
-
- ($nome,$_) = split(/\//,$ENV{'HTTP_USER_AGENT'},2);
-
- #Internet Explorer, Netscape Navigator or Opera
- if ($nome eq "Mozilla")
- {
- # version (Nestscape and Explorer)
- $ver = substr($_,0,4);
-
- # MSIE
- if(/MSIE/)
- {
- $result = $in ? "INTERNET EXPLORER $ver" : "MSIE $ver";
- }
- # Netscape
- elsif(/Win95/)
- {
- $result = $in ? "NETSCAPE NAVIGATOR $ver" : "MOZILLA $ver";
- }
- # Opera
- elsif(/Opera/)
- {
- # Opera┤s version
- ($in,$ver) = split(/\)/,$_,2);
- $result = "OPERA $ver";
- }
- }
- #If not knew borwser
- else
- {
- $result = "$nome";
- }
- return ($result);
- }
- #----------------------------------------------------------------------------
- return 1;
-