#!/usr/bin/perl #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # Mamak Click Count Version 1.0 # # Create Date: 19-Sep-2001 Last Modified: 20-Sep-2001 # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# # Author: Tan Kian Khoon Email: tan@mamakstall.com # # Website: http://www.mamakstall.com/scripts/ # # Copyright 2001 MamakStall.com All Rights Reserved. # #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-# $filename = "click.dat"; $password = "genesis"; ############################################################################### # DON'T MODIFY LINE BELOW ############################################################################### &ReadParse(*input); #$link = lc($input{'link'}); $link = $input{'link'}; $pass = $input{'view'}; open (DAT, "$filename") || print "can't open $filename"; @records = ; close(DAT); if ($pass) { &view; } else { &process; } ############################################################################### # SUB View Data ############################################################################### sub view { print "Content-type: text/html\n\n"; if ($pass eq $password) { print qq~ Admin Page ~; foreach $record (@records) { ($url, $clickcount) = split(/\|/, $record); print ""; } print qq~
Click Count Statistics
URL Click
$url$clickcount
~; } else { print "Password incorrect"; } } ############################################################################### # SUB Process ############################################################################### sub process { $found = 0; open (WDAT, ">$filename") || print "can't open $filename"; foreach $record (@records) { chop($record); ($url, $clickcount) = split(/\|/, $record); if ($link eq $url) { $found = 1; $clickcount++; print WDAT "$link|$clickcount\n"; } else { print WDAT "$record\n"; } } if ($found ne 1) { print WDAT "$link|1\n"; } close(WDAT); print "Location: http://$link\n\n"; } ############################################################################### # SUB ReadParse ############################################################################### 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; } }