#!/usr/bin/perl
use strict;
use CGI;
use GD;
use GD::Text;
use CGI::Carp qw(fatalsToBrowser);
use Fcntl ':flock';
use CGI::Cookie;
my %cookies = fetch CGI::Cookie;
# Get cookies for a more personalised image ;)
# $id = $cookies{'ID'}->value;
if ($ENV{'HTTP_REFERER'} =~ /flop/ || /kyle/) {
ownage();
}
my $query = new CGI;
print $query->header("image/gif");
my $views = get_view();
my $len = length($views);
my $ua = $ENV{HTTP_USER_AGENT};
sub ua_check
{
SWITCH: for ($ua)
{
/[Ww]indows/&& do {return 'You are using Windows';};
/[Ll]inux/ && do {return 'You are using Linux';};
/[Mm]ac/ && do {return 'You are using Mac';};
/[Rr]ed/ && do {return "You are shaine";};
return 'Unknown OS :(';
}
}
sub cl_check
{
SWITCH: for ($ua)
{
/[Ff]irefox/&& do {return "and Firefox";};
/MISE/ && do {return "and IE";};
/[Oo]pra/ && do {return "and Opra";};
/[Ww]get/ && do {return 'and using WGET wtf';};
return 'Unknown Browser :(';
}
}
my $os = ua_check();
my $client = cl_check();
my $x = 144;
my $y = 66;
my $d = 1;
$x += ip_len();
my $im = new GD::Image($x,$y);
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my @rand; $rand[$_] = $im->colorAllocate(rand_color(),rand_color(),rand_color()) for 0 .. 5;
my $blue = $im->colorAllocate(0,0,255);
my $red = $im->colorAllocate(255,0,0);
my $green = $im->colorAllocate(0,102,0);
my $purple = $im->colorAllocate(102,0,153);
# my $gd_text->set_font('uni.ttf', 10);
my $gd_text = GD::Text->new();
$gd_text->set_font('uni.ttf', 10);
$gd_text->set_text("$ua");
#my $string = GD::Text->new(text => $txt, font => gdSmallFont);
#my ($width, $height) = $string->get('width', 'height');
#$gd->string(gdSmallFont, (38 - $width)/2, (34 - $height)/2, $txt, $black);
$im->filledRectangle(0,0,($x - 1),($y - 1),$black);
$im->interlaced('true');
$im->rectangle(0,0,($x - 1),($y - 1),$white);
$im->string(gdSmallFont,5,0,$views. " views",$rand[0]);
$im->string(gdSmallFont,5,10,"$ENV{REMOTE_ADDR}",$rand[1]);
#$im->string(gdSmallFont,5,20,"$ENV{HTTP_USER_AGENT}",$rand2);
$im->string(gdSmallFont,5,20,"$os $client",$rand[2]);
$im->string(gdSmallFont,5,31,scalar(localtime),$rand[3]);
$im->string(gdSmallFont,5,41,"SquareOwnz.org",$rand[4]);
$im->string(gdSmallFont,5,51,"Napsig",$rand[5]);
print $im->gif;
inc_views();
sub get_view {
open (count, "<", "gif.txt");
my $locvar = <count>;
close (count);
return $locvar;
}
sub inc_views {
my $exclusive_lock = 2;
my $unlock_lock = 8;
my $views = get_view();
open (file, ">","gif.txt");
flock(file,$exclusive_lock);
my $new = $views + 1;
print file $new;
flock(file,$unlock_lock);
close(file);
return 1;
}
sub ip_len {
my $x = length($ENV{REMOTE_ADDR});
return ($x * 5.5 - 4);
}
sub rand_color {
return int(rand(126) + 100);
}
sub ownage
{
print 'gay';
exit;
}
1;