File analog-php.php of Package Analog
<?php
include "../include/datum.inc";
$ANALOG_DIR="/usr/share/analog/html";
$HTTP_HOST=$_SERVER["HTTP_HOST"];
if ( isset($_REQUEST["show"])) {
$show=$_REQUEST["show"];
};
$log_dir="/var/log/apache2/$HTTP_HOST";
$log_file="$log_dir/access_log";
$stats_dir="$ANALOG_DIR/stats/$HTTP_HOST";
$charts_dir="$ANALOG_DIR/charts/$HTTP_HOST";
if ( isset($show)) {
$index="$stats_dir/$show/index.html";
};
$title="Statistika za $HTTP_HOST";
include "../include/header.inc";
if ( ! is_dir( "$stats_dir" )) {
mkdir ( "$stats_dir", 0755 );
}
if ( ! is_dir( "$stats_dir/current" )) {
mkdir ( "$stats_dir/current", 0755 );
}
if ( ! is_dir( "$charts_dir" )) {
mkdir ( "$charts_dir", 0755 );
}
if ( ! is_dir( "$charts_dir/current" )) {
mkdir ( "$charts_dir/current", 0755 );
}
if ( is_dir($stats_dir) ) {
$DIR=opendir("$stats_dir");
if ( ! isset($show)) {
print ("<A HREF=\"" . $_SERVER['PHP_SELF'] . "?show=generate_current_step1\">Generiraj trenutno statistiko...</A>");
print ("<HR>");
while ($file = readdir($DIR)) {
if ( is_dir("$stats_dir/$file") && ( $file != "." ) && ( $file != ".." )) {
$mesec = preg_split( "/-/", $file );
if ( $file == "current" ) {
print ("<A HREF=\"" . $_SERVER['PHP_SELF'] . "?show=$file\">");
print ("Trenutna statistika<BR>");
} else {
print ("<A HREF=\"" . $_SERVER['PHP_SELF'] . "?show=$file\">");
print (ime_meseca($mesec[1]));
print (" $mesec[0]</A>");
print ("<BR>");
}
}
}
} elseif ( $show == "generate_current_step1" ) {
print ("<HR>Ko bo statistika izdelana, vas bo brskalnik avtomatsko preusmeril...");
print ("<BR>");
print ("<meta http-equiv=\"Refresh\" content=\"0;url=http://$HTTP_HOST/stats/?show=generate_current_step2\">");
} elseif ( $show == "generate_current_step2" ) {
$cmd="/usr/bin/analog +C'DNS WRITE' +C'HOSTNAME $HTTP_HOST' +C'HOSTURL http://$HTTP_HOST' +C'REFREPEXCLUDE http://$HTTP_HOST/*' +C'REFSITEEXCLUDE http://$HTTP_HOST/' +C'DIREXCLUDE /stats' +C'CHARTDIR charts/$HTTP_HOST/current/' +C'LOCALCHARTDIR $charts_dir/current/' +C'OUTFILE $stats_dir/current/index.html' $log_file";
system($cmd, $err);
print ("<meta http-equiv=\"Refresh\" content=\"2;url=http://$HTTP_HOST/stats/?show=current\">");
print ("<HR>Statistika je izdelana. Ce vas brskalnik v 5 sekundah ne bo avtomatsko preusmeril na statistiko, kliknite ");
print ("<A HREF=\"http://$HTTP_HOST/stats/?show=current\">tukaj.</A>");
print ("<HR>");
} else {
if ( is_file($index)) {
readfile ( "$index" );
} else {
print "<HR><I>Napaka! Statistika ni na voljo!</I></BR>";
}
}
closedir($DIR);
} else {
print ("<HR><I>Napaka! Log datoteka za ta host ni na voljo!</I></BR>");
}
include "../include/footer.inc";
?>