====== Update script in Perl ====== This writes out a new runningtotal.shtml file. With hindsight, a cgi include could just read a value in from a file as part of the include file. ===== cgi-bin/updatetotal.pl ===== [host1] $ ~/cgi-bin/updatetotal.pl #!/usr/bin/perl #written Andrew Stringer 27/08/2008 #to process update to total cash raised. use strict; use warnings; use CGI; my $password="handel"; my $inputpassword=' '; my $target="150000"; my $query = new CGI; $inputpassword = $query->param("password"); my $total = $query->param("total"); if ($inputpassword eq $password) { #check if input amount is numeric (\D is any digit except a decimal digit) if ($total =~ m/\D,/) { print "Content-type: text/html\n\n"; print < Error Total raised (£$total) must be numbers only.
ENDTEXT4 exit (1); } #check if input ammount is greater than the target if ($total > $target ) { print "Content-type: text/html\n\n"; print < Error Total raised (£$total) must be less than the target amount (£$target).
ENDTEXT5 exit (1); } #write to file open RUNNINGTOTAL, ">../http/runningtotal.shtml" or die "Cannot open file runningtotal.shtml for output." ; print RUNNINGTOTAL <

Raised &
Pledged so far:-

£ $total

Target £150,000

ENDTEXT1 close RUNNINGTOTAL ; #start output of html page print "Content-type: text/html\n\n"; print < Total Updated Total updated and is now £$total

Return to main page
ENDTEXT2 } else { #start output of general error page print "Content-type: text/html\n\n"; print < Error An error has occured.
ENDTEXT3 } exit (0);
===== Form to submit values ===== Update running total
Update Running Total
Password:-
Running Total:- £
===== Counting ipaddresses ===== # more andrew/counter2.pl #!/usr/bin/perl #Program to count in ipaddresses #written Andrew Stringer 16/08/2005 sub IP2DENARY { #get ipaddress passed to subroutine my $ipaddress = shift; #split into array on "." my @octet = split /\./ , $ipaddress; #convert each octet to hex, pad to 2 digits my $hexip1= sprintf"%02x", $octet[0]; my $hexip2= sprintf"%02x", $octet[1]; my $hexip3= sprintf"%02x", $octet[2]; my $hexip4= sprintf"%02x", $octet[3]; #concatenate to one number my $hexipaddress=$hexip1.$hexip2.$hexip3.$hexip4; #convert to denary equivalent my $denipaddress=hex($hexipaddress); return $hexipaddress, $denipaddress; } sub DENARY2IP { #get denary equivalent of ipaddress passed to subroutine my $denipaddress = shift; #convert to hex and pad to 8 digits my $hexip= sprintf"%08x", $denipaddress; #use substr to split into octets my $hexoctet1= substr($hexip, 0, 2); my $hexoctet2= substr($hexip, 2, 2); my $hexoctet3= substr($hexip, 4, 2); my $hexoctet4= substr($hexip, 6, 2); my $denoctet1= hex($hexoctet1); my $denoctet2= hex($hexoctet2); my $denoctet3= hex($hexoctet3); my $denoctet4= hex($hexoctet4); my $ipaddress="$denoctet1.$denoctet2.$denoctet3.$denoctet4" ; return $ipaddress; } MAIN: #start of body of program { #set starting ipaddress & no. of hosts to count through. my $ip="192.168.1.0"; my $blocksize="1024"; print "start ipaddress is $ip, block size is $blocksize. \n"; my @ipaddress = &IP2DENARY($ip); my $denipaddress=$ipaddress[1]; for ($count=$denipaddress; $count<($denipaddress+$blocksize); $count++) { my $ipaddress2=DENARY2IP($count); print "ipaddress is $ipaddress2 \n"; } #my @ipaddress = &IP2DENARY($ip); #my $hexipaddress=$ipaddress[0]; #my $denipaddress=$ipaddress[1]; #my $ipaddress2=DENARY2IP($denipaddress); } exit (0);