Программирование > Perl
Что нужно добавить в скрипт
kkhk:
Господа на сайте http://discuss.km.ru/ стоит скрипт статистики посещений, показывает браузер и операционку, что добавить нужно, что бы он еще показывал и разрешение монитора посетителей, скрипт идет ниже. Я не программист поэтому если можно по подробнее.
--------------------------------------------------------------------------------
#!/usr/bin/perl
#wostat.cgi
########################################
# WOstat v1.1
#
########################################
# ***************** Variables *********************
my $filename="wostat.cgi";
my $brfile="brdata.txt";
my $sysfile="sysdata.txt";
my $system="UNIX";
my $mailprog=\'/usr/sbin/sendmail\';
my $to=\'cat321@mail.ru\';
my $from=\'wow@womail.net\';
my $uncout_time="24"; # В часах
# *************************************************
# ******************* Modules *********************
use CGI qw(param);
use CGI::Carp qw/fatalsToBrowser/;
use locale;
use strict;
# *************************************************
###################################################
my @browsers=("MSIE 5.01","Netscape6/6.0","Opera 5.0","MSIE 5.5","MSIE 4.01","MSIE 5.0","MSIE 6.0","Opera/5.12","MSIE 6.0b","Opera/5.01","Netscape6/6.01","Powermarks/3.5","rv:0.9.1","Netscape6/6.2","Netscape6/6.1","Explorer/4.40.426","MSIE 2.1","X11","MSIE 4.0","MSIE 5.12","Opera/6.0","MSIE 5.0b1","MSIE 3.01");
my @systems=("Windows NT 5.0","Windows 98","Windows NT 5.1","Windows 2000","Windows 95","Windows 9x","Windows NT","Win16","Win32","Win 9x","Mac_PowerPC","FreeBSD","Macintosh","Linux","WinNT4.0","Windows ME","BeOS","Unix","Windows XP","SunOS");
###################################################
my $user_agent=$ENV{\'HTTP_USER_AGENT\'};
my $ip=$ENV{\'REMOTE_ADDR\'};
my $i=0;
my $ii=0;
my $j=0;
my $jj=0;
my $bro;
my $sys;
my $host;
my $hit;
my $all;
if ($user_agent=~/\\bWin98\\b/)
{
$sys="Windows 98";
}
if ($user_agent=~/\\bWin95\\b/)
{
$sys="Windows 95";
}
if ($user_agent=~/\\bWinNT\\b/)
{
$sys="Windows NT";
}
# ***************************** Counter file *****************************
open(AF,"all.txt") or die ("Can\'t open all count file all.txt ", $!);
if ($system ne "NT")
{
flock(AFA, 2);
}
print AFA "$all";
close (AFA);
# ******************************** Time file *****************************
open(TF,"= 0)
{
open (TFN, ">time.txt") or die("Can not open time-file time.txt ", $!);
if ($system ne "NT")
{
flock(TFN, 2);
}
print TFN "$time";
close (TFN);
open (IPBFILE, ">ipb.txt");
close (IPBFILE);
open (IPSFILE, ">ips.txt");
close (IPSFILE);
open (HIT, ">hit.txt");
close (HIT);
open (HOST, ">host.txt");
close (HOST);
}
# ***********************************************************************
# ***************************** HIT count *******************************
open(HIF,"hit.txt") or die("Can\'t open hit file to write ", $!);
if ($system ne "NT")
{
flock(HIFA, 2);
}
print HIFA "$hit";
close (HIFA);
# +++++++++
open(HF,"ipb.txt") or die("Can\'t open IP file to write ipb.txt ",$!);
if ($system ne "NT")
{
flock(IPE, 2);
}
print IPE "$ip\\n";
close(IPE);
# ***************************** Host count *******************************
$host++;
open (HFA, ">host.txt") or die("Can\'t open host file to write ", $!);
if ($system ne "NT")
{
flock(HFA, 2);
}
print HFA "$host";
close (HFA);
# ***********************************************************************
kkhk:
Продолжение скрипта
----------------------------------------------------------------------------------
open (FILE, "$brfile") or die("Can\'t open browsers file to write $brfile ",$!);
if ($system ne "NT")
{
flock(BRFILE, 2);
}
foreach my $line(@lines)
{
my(@temp)=split(/\\|/,$line);
if ($browser eq $temp[0])
{
$i++;
$temp[1]++;
print BRFILE "$temp[0]|$temp[1]\\n";
}
else
{
print BRFILE "$line\\n";
}
}
close (BRFILE);
if ($i == 0)
{
open (APPFILE, ">>$brfile") or die("Can\'t open browsers file to append $brfile ",$!);
if ($system ne "NT")
{
flock(APPFILE, 2);
}
print APPFILE "$browser|1\\n";
close (APPFILE);
}
}
}
}
# ************************ browser end ***************************
# ***************************** System ***************************
foreach my $system(@systems)
{
if ($user_agent =~ /\\b$system\\b/)
{
$jj++;
$sys=$system;
open (IP,">ips.txt") or die("Can\'t open IP file to write ips.file ",$!);
if ($system ne "NT")
{
flock(IPE, 2);
}
print IPE "$ip\\n";
close(IPE);
open (FILE, "$sysfile") or die("Can\'t open system file to write $sysfile ",$!);
if ($system ne "NT")
{
flock(SYSFILE, 2);
}
foreach my $line(@lines)
{
my(@temp)=split(/\\|/,$line);
if ($system eq $temp[0])
{
$ii++;
$temp[1]++;
print SYSFILE "$temp[0]|$temp[1]\\n";
}
else
{
print SYSFILE "$line\\n";
}
}
close (SYSFILE);
if ($ii == 0)
{
open (APPFILE, ">>$sysfile") or die("Can\'t open systems file to append $sysfile ",$!);
if ($system ne "NT")
{
flock(APPFILE, 2);
}
print APPFILE "$system|1\\n";
close (APPFILE);
}
}
}
}
# *************************** system end ***************************
if ($j==0)
{
send_mail("$to","$from","Этого браузера нет в списке","$user_agent");
}
if ($jj==0)
{
send_mail("$to","$from","Этой Оп. системы нет в списке","$user_agent");
}
open (BFILE, "[1] $b->[1]}
map { [$_,(split /\\|/)[1] ] } @unsorted_bro;
my @sorted_sys = map { $_->[0] }
reverse sort {$a->[1] $b->[1]}
map { [$_,(split /\\|/)[1] ] } @unsorted_sys;
my $html_output;
my $html_output1;
my $k=0;
my $kk=0;
foreach (@sorted_bro)
{
$k++;
my($name,$num)=split(/\\|/, $_);
$html_output.=qq~
$k.
"$name"
$num
~ ;
}
foreach (@sorted_sys)
{
$kk++;
my($name,$num)=split(/\\|/, $_);
$html_output1.=qq~
$kk.
"$name"
$num
~ ;
}
print "Content-type: text/html\\n\\n";
print qq~
$html_output
$html_output1
~;
if ($bro eq "")
{
$bro="Не определен";
}
if ($sys eq "")
{
$sys="Не определена";
}
print "Ваш браузер - $bro
\\n";
print "Ваша система - $sys
\\n";
print "Ваш IP адрес - $ip
\\n";
print "Посетителей сегодня: $host
\\n";
print "Визитов сегодня: $hit
\\n";
print "Визитов всего: $all
\\n";
# ************************** CHECK FILE *******************************
sub exist_file
{
my($file)=@_;
unless (-e $file)
{
open(FILE,">$file") || die("Can\'t create data-file $file",$!);
close(FILE);
chmod(0777,$file);
}
}
# ****************************** SUB send_mail ************************
sub send_mail
{
my $to=$_[0];
my $from=$_[1];
my $subject=$_[2];
my $message=$_[3];
$message =~ tr/\\xFE\\xE0\\xE1\\xF6\\xE4\\xE5\\xF4\\xE3\\xF5\\xE8-\\xEF\\xFF\\xF0-\\xF3\\xE6\\xE2\\xFC\\xFB\\xE7\\xF8\\xFD\\xF9\\xF7\\xFA\\xDE\\xC0\\xC1\\xD6\\xC4\\xC5\\xD4\\xC3\\xD5\\xC8-\\xCF\\xDF\\xD0-\\xD3\\xC6\\xC2\\xDC\\xDB\\xC7\\xD8\\xDD\\xD9\\xD7\\xDA/\\xC0-\\xFF/;
open (SENDMAIL, "|$mailprog -t");
print SENDMAIL "To: $to\\n";
print SENDMAIL "From: $from\\n";
print SENDMAIL "Subject: $subject\\n\\n";
print SENDMAIL "$message\\n";
close (SENDMAIL);
}
lodevar:
Разрешение узнается, например, ява-скриптом.
screen.height
screen.width
kkhk:
мало узнавать, надо еще и запоминать, то есть вести статистику, скрипт в работе можно глянуть поссылке в верху, а вот как это сделать? я ведь не програмист, что нужно вставить и куда?
lodevar:
Не. Сначала запускается страничка с ява-скриптом. Потом он узнает что надо и запускает страничку с только что полученными параметрами.
типа
location.href="main.html?height="screen.height+"&width="+screen.width;
Навигация
Перейти к полной версии