HOWTO: Awstats + Confixx

Bash, Shell, PHP, Python, Perl, CGI
cos
Posts: 29
Joined: 2007-04-20 19:56
 

Re: HOWTO: Awstats + Confixx

Post by cos »

Sorry, wenn ich den Thread nochmal aufrolle. Ich habe alles nach der Anleitung von MONK installiert.

Ich hab zum Test erstmal eine conf Datei für eine meiner Domains manuell angelegt. Wenn ich nun versuche den Befehl auszuführen:
/usr/share/awstats/tools/awstats_updateall.pl now -awstatsprog=/var/www/web1/html/cgi-bin/awstats/awstats.pl

krieg ich vom Script folgende Meldung:

Code: Select all

/var/www/web1/log$ /usr/share/awstats/tools/awstats_updateall.pl now -awstatsprog=/var/www/web1/html/cgi-bin/awstats/awstats.pl 
Running '"/var/www/web1/html/cgi-bin/awstats/awstats.pl" -update -config=domain1.com -configdir="/etc/awstats"' to update config domain1.com
Create/Update database for config "/etc/awstats/awstats.domain1.com.conf" by AWStats version 6.6 (build 1.887)
From data in log file "/var/www/web1/log/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
AWStats did not find any valid log lines that match your LogFormat parameter, in the 50th first non commented lines read of your log.
Your log file /var/www/web1/log/access_log must have a bad format or LogFormat parameter setup does not match this format.
Your AWStats LogFormat parameter is:
%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %virtualname
This means each line in your web server log file need to have the following personalized log format:
%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %virtualname
And this is an example of records AWStats found in your log file (the record number 50 in your log):
84.175.58.73 - - [19/Apr/2007:09:25:09 +0200] "GET /logo/home.gif HTTP/1.1" 200 337 "http://www.domain1.com/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"www.domain1.com
Setup ('/etc/awstats/awstats.domain1.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
In jeder Zeile im Log steht das aber in diesem Format:
77.0.105.122 - - [23/Apr/2007:11:02:59 +0200] "GET /3.gif HTTP/1.1" 200 1100 "http://www.domain1.com/seite1.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; FunWebProducts; SIMBAR={C44AF36E-B351-4964-9139-66B767DD52AC}; .NET CLR 1.1.4322)" http://www.domain1.com

Was kann das sein? Den Eintrag in die httpd.conf zwecks Logformat hab ich vorgenommen!

Warum sind auch immer 2 Bindestriche nach der IP (host) im Log?

P.S.: Ich habe meine domain für diesen Post hier überall in domain1.com geändert, weil das nicht meine Domain ist und ich keinen ärger will...
cos
Posts: 29
Joined: 2007-04-20 19:56
 

Re: HOWTO: Awstats + Confixx

Post by cos »

Habs schon gefunden - Da hat ein Freizeichen vorm VHost gefehlt (im folgenden Beispiel nach Firefox/2.0.0.3"):

Code: Select all

84.175.58.73 - - [19/Apr/2007:09:25:09 +0200] "GET /logo/home.gif HTTP/1.1" 200 337 "http://www.domain1.com/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3" www.domain1.com
Frage:
Wie lege ich den CronJob an? Einfach in die Shell eintippen? Wie kann ich den CronJob abschalten/löschen, wenn ich was falsch mache, oder irgendwas nicht funzt?
Anonymous
 

Confixx und Awstats auf xvserver und SuSE bei S4Y

Post by Anonymous »

Ich habe es dank dem How-To geschaft das ganze innerhalb von ein paar stunden ans laufen zu bekommen. Allerdings gabe es ein paar Fehler. Da bestimmt auch andere meine Probleme hatten oder haben werden poste ich drum hier meine scripts.

Um die logs im richtigen Format für AWSTATS zu erzeugen und um zu verhindern das Änderungen über schrieben werden erst die

pipelog.pl unter /usr/local/confixx ändern:

Code: Select all

#!/usr/bin/perl
###### Confixx-Apache-PipeLog
## zum Loggen der Webzugriffe pro User
########## erstellt am Fri Oct 12 12:42:52 2007 ###
$logDir = "/var/log/apache2/confixx/domains/access";
$stdLog = "/var/log/apache2/confixx/stdlog_access";
while(<STDIN>){
  ($domain, $log) = split(/:#:/, $_);
  $domain = lc($domain);
  if(-l "$logDir/$domain"){
    open(LOG, ">>$logDir/$domain") or next;
    $log =~ s/n|r//g;
    $log = "$log $domainn";
    print LOG $log;
    close(LOG);
   }else{
    open(LOG, ">>$stdLog") or next;
    print LOG "$domain :: $log";
    close(LOG);
  }
}
Jetzt alle Logs in den Userverzeichnissen löschen (web1 - webxx)

Meine index.html unter /srv/www/confixx/html/awstats

Code: Select all

<html>
<head>
<title>AWStats-Zugriffsstatistiken</title>
</head>
<body>
<center>
<h1>Geben Sie Ihren Benutzernamen oder Domain-Namen (domain.tld) ein:</h1>
<form action="http://vs163247.vserver.de/cgi-bin/awstats/awstats.pl"
method="GET" />
<input type="text" name="config" /><br />
<br />
<input type="submit" value="Einloggen" />
</form></body></html>
Meine .htaccess unter /srv/www/confixx/html/cgi-bin/awstats

Code: Select all

AuthName "awstats"
AuthType Basic
AuthUserFile /srv/www/confixx/html/cgi-bin/awstats/.htpasswd
require valid-user
Meine crontab für das die Statistic Updates in /etc

Code: Select all

SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
#
# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
#
-*/36 * * * *   root  test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1

*/1 * * * * root  /usr/local/confixx/confixx_counterscript.pl
*/30    *       *       *       *       root    /usr/local/awstats/awstats.sh >/dev/null 2>/dev/null
Und nun zu awstats unter /usr/local/awstats

Mein shellscript awstats.sh

Code: Select all

#!/bin/sh
perl /usr/local/awstats/awmakeconf.pl
/usr/local/awstats/awstats_updateall.pl now -awstatsprog=/srv/www/confixx/html/cgi-bin/awstats/awstats.pl
Da ich es meinen Benutzern ermöglicht habe Statistiken als domain.tld oder unter dem user web.. muste ich das perl script etwas auf boren und erweitern, ferner habe ich noch 2 kleine Fehler korrigiert.

Meine awmakeconf.pl

Code: Select all

#!/usr/bin/perl

#########################################################################
#                                                                       #
#               AWStats Configuration - Maker for Confixx               #
#               Copyright 2003 by Michael Mangold                       #
#               Contact: info@michael-mangold.net                       #
#                                                                       #
#               Modifizierungen (c) 2004 by Anton Dollmaier             #
#               Contact: info@aditsystems.de                            #
#                                                                       #
#########################################################################

$conf_path = '/etc/awstats';   # Pfad in dem die AWStats Konfigurationen liegen
$user_path = '/srv/www/';        # Pfad in dem Confixx die webs anlegt

$pwfile = "/srv/www/confixx/html/cgi-bin/awstats/.htpasswd"; # Passwort-Datei für die .htaccess-Abfrage

&loadConfFile;
use DBI;
$dbh = DBI->connect($db_address, $dbUser, $dbPw)
  or die( &ltext('db_connect', '#2001', "$DBI::errstr") );

$cmd = 'rm '.$conf_path.'/awstats.*';

system($cmd);

$sql = "SELECT kunde, anbieter
        FROM kunden
        WHERE kunde != 'web0'
        ORDER BY kunde ASC";

my $sth = $dbh->prepare($sql);
$sth->execute;
while( @data = $sth->fetchrow_array )
     {
     $domains = '';
     $kunde = $data[0];
     $anbieter = $data[1];
     $logfile = $user_path.$kunde."/log/access_log";

     $sql = "SELECT domain FROM domains WHERE kunde = '".$kunde."' AND richtigedomain='1' ORDER BY domain ASC";
     my $res1 = $dbh->prepare($sql);
     $res1->execute;
     while ( @row = $res1->fetchrow_array )
           {

           my $subdomains = $row[0];
           my $Domainname = $subdomains;
           $subdomains =~ s/./\./g;
           $domains = "REGEX[^.*".$subdomains."$] ";
           $config = "LogFile="$logfile"nSiteDomain="$Domainname"nHostAliases="$domains"nAllowAccessFromWebToFollowingAuthenticatedUsers="$kunde Administrator $anbieter"nInclude "/etc/awstats/muster.conf"nn";

           system ("echo '$config' > $conf_path/awstats.$Domainname.conf");

           }
     $res1->finish();


     $sql = "SELECT domain FROM domains WHERE kunde = '".$kunde."' AND richtigedomain='1' ORDER BY domain ASC";
     my $res1 = $dbh->prepare($sql);
     $res1->execute;
     while ( @row = $res1->fetchrow_array )
           {
           my $subdomains = $row[0];
           $subdomains =~ s/./\./g;
           $domains .= "REGEX[^.*".$subdomains."$] ";
           }
     $res1->finish();

     $domain = $data[0];

     $config = "LogFile="$logfile"nSiteDomain="$domain"nHostAliases="$domains $kunde.vs163247.vserver.de"nAllowAccessFromWebToFollowingAuthenticatedUsers="$kunde Administrator $anbieter"nInclude "/etc/awstats/muster.conf"nn";

     system ("echo '$config' > $conf_path/awstats.$kunde.conf");

    }
$sth->finish();

system('cp /usr/local/awstats/muster.conf '.$conf_path);

#
# Generate Password-File for Statistics
#

# First, lets get Admin- and Reseller-Data

$sql = "SELECT anbieter,longpw FROM anbieter";

my $res = $dbh->prepare($sql);
$res->execute;

while ( @data = $res->fetchrow_array )
{
        $users .= $data[0].":".$data[1]."n";
}
$res->finish();

my $sql = "SELECT longpw FROM admin WHERE login='Administrator'";

my $sth = $dbh->prepare($sql);
$sth->execute;

while (@data = $sth->fetchrow_array)
      {
      $users .= "Administrator:".$data[0]."n";
      }

$sth->finish();

my $sql = "SELECT kunde, statistiklongpw
          FROM kunden
          WHERE statistik='1' AND kunde!='web0';";

my $sth = $dbh->prepare($sql);
$sth->execute;

while( @data = $sth->fetchrow_array )
    {
    $users .= $data[0].":".$data[1]."n";
    }
system('rm '.$pwfile);
system ("echo '".$users."' > ".$pwfile);

$sth->finish();
$dbh->disconnect;

sub loadConfFile{
my ($file, $base);
if(-T "/usr/local/confixx/confixx_main.conf"){
      $file = "/usr/local/confixx/confixx_main.conf";
       }
   else{
      $0 = $^X unless ($^X =~ m%(^|[/\])(perl)|(perl.exe)$%i);
      ($base) = $0 =~ m%^(.*)[/\]%;
      $base ||= ".";
      $file = "$base/confixx_main.conf";
      unless(-T $file){
         die("Couldn't find confixx_main.conf");
         }
      }
    do $file;
}
Das Script legt die Konfigdateien unter /etc/awstats für alle domains und alle webs in der Form awstats.domain.tld.conf und awstats.web1.conf etc an.

Zuletzt noch meine muster.conf für awstats

Code: Select all

# AWSTATS CONFIGURE FILE 6.6
#-----------------------------------------------------------------------------
# Copy this file into awstats.www.mydomain.conf and edit this new config file
# to setup AWStats (See documentation in docs/ directory).
# The config file must be in /etc/awstats, /usr/local/etc/awstats or /etc (for
# Unix/Linux) or same directory than awstats.pl (Windows, Mac, Unix/Linux...)
# To include an environment variable in any parameter (AWStats will replace
# it with its value when reading it), follow the example:
# Parameter="__ENVNAME__"
# Note that environment variable AWSTATS_CURRENT_CONFIG is always defined with
# the config value in an AWStats running session and can be used like others.
#-----------------------------------------------------------------------------
# $Revision: 1.327 $ - $Author: eldy $ - $Date: 2006/04/21 22:28:49 $

LogType=W
LogFormat = "%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %virtualname"

LogSeparator=" "
DNSLookup=1
DirData="/var/cache/awstats"
DirCgi="/cgi-bin/awstats"
DirIcons="/icon"
AllowToUpdateStatsFromBrowser=0
AllowFullYearView=3
AllowAccessFromWebToAuthenticatedUsersOnly=1

Ich hoffe das ich nichts vergessen habe und es euch weiter hilft.

Gruß
Oliver
Post Reply