#!/usr/local/bin/perl
#-----------------------
# ClickCount.cgi
# Ver. 1.1
# ----------------------
# Gustav Evertsson
# www.guzzzt.com
# me@guzzzt.com
#-----------------------
$dbfile = "./clickcount.db";
&parse_query;
if($ENV{'QUERY_STRING'} eq '') {
print "Content-type: text/html\n\n";
#Print the top of the admin page
print qq|
GuzZzt ClickCount: Admin
GuzZzt ClickCount
URL |
Clicks |
|;
# write all urls
open(DATA, "$dbfile");
@db = ;
close(DATA);
foreach (@db) {
($clicks, $url) = split /\|/;
$totclicks = $totclicks+$clicks;
print qq|
$url |
$clicks |
|;
}
#totalt clicks
print qq|
Total: |
$totclicks |
|;
#Write the bottom of the page
print qq|
Powered by GuzZzt ClickCount V. 1.1
Copyright 1999 Gustav Evertsson
From GuzZzt.com
|;
}
else{
if($query{'action'} eq 'jump') {
open(DATA, "$dbfile");
@db = ;
close(DATA);
foreach (@db) {
($click, $url) = split /\|/;
if($url eq $query{'URL'}){
$newclick = $click+1;
$dummy .= "$newclick|$url|\n";
$find = 'true';
}
else {
$dummy .= "$click|$url|\n";
}
}
if($find ne 'true') {
$dummy .= "1|$query{'URL'}|";
}
open(DB, "+>$dbfile");
print DB $dummy;
close(DB);
print "Location: $query{'URL'} \n\n";
}
else{
open(DATA, "$dbfile");
@db = ;
close(DATA);
foreach (@db) {
($click, $url) = split /\|/;
if($url eq $query{'URL'}){
$viewclick = $click;
}
}
if($viewclick eq '') {
$viewclick = 0;
}
print "Content-type: text/html\n\n";
print "$viewclick";
}
}
sub parse_query {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ s/~/=/g; #change ~ to = if double querystrings change all = to ~ in the second url.
$query{$name} = $value;
}
}