ISPconfig 3 - awstats

Discussion in 'Tips/Tricks/Mods' started by Mouton, Mar 29, 2009.

  1. grungy

    grungy HowtoForge Supporter

    awstats_updateall.pl on Debain is run as following:

    Code:
    /usr/share/doc/awstats/examples/awstats_updateall.pl now -awstatsprog=/usr/lib/cgi-bin/awstats.pl
    The awstats conf file should be more rich, for example:

    Code:
                            exec( "echo 'Include \"/etc/awstats/awstats.conf\"' > /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            exec( "echo 'LogFile=\"/var/log/ispconfig/httpd/".$data["new"]["domain"]."/access.log\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            exec( "echo 'SiteDomain=\"".$data["new"]["domain"]."\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf");
                            exec( "echo 'DNSLookup=\"1\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            exec( "echo 'DirData =\"/var/cache/awstats\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            exec( "echo 'AllowFullYearView=\"3\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
    
     
  2. admins

    admins Member

    To the simlink: From where to where must I create a symlink
    Code:
    ln -s ....
    Thanks
    admins
     
  3. djtremors

    djtremors ISPConfig Developer

    Oo this looks to be a good plugin hack. Might add my bit to take logins from mysql and create a .htaccess htpasswd file as i'm migrating my ispc2 accounts to my ispc3 server.

    long live the plugins!

    Is there a list what hooks are available for plugins? I have a DR design in mind and would like to use this opportunity to mirror when accounts are created and deleted with rsync ability etc.etc.
     
  4. till

    till Super Moderator

    There is no list yet. But if you look into the files in mods-available, you can easily find the definitions. Currently these are available:

    client_insert, client_update, client_delete
    database_insert, database_update, database_delete
    mail_domain_insert, mail_domain_update, mail_domain_delete
    mail_user_insert, mail_user_update, mail_user_delete
    mail_access_insert, mail_access_update, mail_access_delete
    mail_forwarding_insert, mail_forwarding_update, mail_forwarding_delete
    mail_transport_insert, mail_transport_update, mail_transport_delete
    mail_get_insert, mail_get_update, mail_get_delete
    mail_content_filter_insert, mail_content_filter_update, mail_content_filter_delete
    server_insert, server_update, server_delete
    server_ip_insert, server_ip_update, server_ip_delete
    firewall_insert, firewall_update, firewall_delete
    software_update_inst_insert, software_update_inst_update, software_update_inst_delete
    web_domain_insert, web_domain_update, web_domain_delete
    ftp_user_insert, ftp_user_update, ftp_user_delete
    shell_user_insert, shell_user_update, shell_user_delete

    The event names correspond with the database table names.
     
  5. BorderAmigos

    BorderAmigos New Member

    I did all of the above and still not working. I'll read it thru 5 or 10 more times to find what I'm missing.
     
  6. djtremors

    djtremors ISPConfig Developer

    @BorderAmigos : What does "still not working" mean. Did you make a vhost for it

    I had to change mine to work with debians apt-get version which was different.


    PHP:
                    if(!@is_file("/etc/awstats/awstats.".$data["new"]["domain"].".conf") || ($data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"])) {
                            if ( @
    is_file("/etc/awstats/awstats.".$data["old"]["domain"].".conf") )
                                     
    exec("rm -f /etc/awstats/awstats.".$data["old"]["domain"].".conf");

                            
    exec"echo 'Include \"/etc/awstats/awstats.conf\"' > /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            
    exec"echo 'LogFile=\"/var/log/ispconfig/httpd/".$data["new"]["domain"]."/access.log\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            
    exec"echo 'SiteDomain=\"".$data["new"]["domain"]."\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf");
                            
    // exec( "echo 'AllowAccessFromWebToFollowingAuthenticatedUsers=\"".$ht_user_list."\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf");
                    
    }
    my /etc/apache2/conf.d/awstats.conf looks like this (for now).
    PHP:
    Alias /awstatsclasses "/usr/share/awstats/classes/"
    Alias /awstatscss "/usr/share/awstats/css/"
    Alias /awstats-icon "/usr/share/awstats/icon/"
    ScriptAlias /stats"/usr/lib/cgi-bin/"
    #
    # This is to permit URL access to scripts/files in AWStats directory.
    #
    <Directory "/usr/share/awstats">
            
    Options None
            AllowOverride None
            Order allow
    ,deny
            Allow from all
    </Directory>
    what I did notice is that this only supports the domain and not the www. autodomains which I'll get around to adding along with authentication (been sick lately any contenders to SQL to get list, be my guest)...
     
  7. djtremors

    djtremors ISPConfig Developer

    Ok, got around to making a quick patch to allow my awstats to appear using the configuration method mentioned earlier and using a redirection from /stats to redirect to /ispcstats with the domain.

    This will create a .htaccess_stats file with the clients login/password from the database. Change as you please if you want email users to be able to use it instead etc. There is no super admin login atm but that's an easy addition by adding a admin:{hash} to the write routine.

    There may be other little tweaks needs in regards to getting awstats part working but this is only the ispc3 side.

    Code :
    PHP:
    Ok, got around to making a quick patch to allow my awstats to appear using the configuration method mentioned earlier and using a redirection from /stats to redirect to /ispcstats with the domain.

    This will create a .htaccess_stats file with the clients login/password from the database. Change as you please if you want email users to be able to use it instead etc. There is no super admin login atm but that's an easy addition by adding a admin:{hash} to the write routine.

    There may be other little tweaks needs in regards to getting awstats part working but this is only the ispc3 side.

    Code :
    [PHP]<?php

    class awstats_plugin {

            var 
    $plugin_name 'awstats_plugin';
            var 
    $class_name  'awstats_plugin';

            
    //* This function is called during ispconfig installation to determine
            //  if a symlink shall be created for this plugin.
            
    function onInstall() {
                    global 
    $conf;

                    if(@
    $conf['services']['awstats'] == true) {
                            return 
    true;
                    } else {
                            return 
    false;
                    }

            }


            
    /*
                    This function is called when the plugin is loaded
            */

            
    function onLoad() {
                    global 
    $app;

                    
    /*
                    Register for the events
                    */

                    //* Mail Domains
                    
    $app->plugins->registerEvent('web_domain_insert',$this->plugin_name,'domain_insert');
                    
    $app->plugins->registerEvent('web_domain_update',$this->plugin_name,'domain_update');
                    
    $app->plugins->registerEvent('web_domain_delete',$this->plugin_name,'domain_delete');
                    
    $app->plugins->registerEvent('client_insert',$this->plugin_name,'client_insert');
                    
    $app->plugins->registerEvent('client_update',$this->plugin_name,'client_update');
                    
    $app->plugins->registerEvent('client_delete',$this->plugin_name,'client_delete');
            }

            function 
    awstats_update($event_name,$data) {
                    global 
    $app$conf;
                    
    $result $app->db->queryAllRecords("SELECT * FROM web_domain wd,sys_group sg,client c where wd.sys_groupid = sg.groupid and sg.client_id = c.client_id");
                    
    $fp fopen($domroot."/.htpasswd_stats","w");
                    if (
    $fp)
                    {
                foreach(
    $result as $row)
                        {
                            
    $domain         $row['domain'];
                        
    $username       $row['username'];
                                
    $password       $row['password'];
                                
    $domroot        $row['document_root'];
                                echo 
    "Domain::$domain DomRoot::$domroot\n";

                                    
    fwrite($fp,$username.":".$password."\n");
                            }
                            
    fclose($fp);
            }
                    
    $fp fopen($domroot."/web/stats/.htaccess","w");
                    if (
    $fp)
                    {
                            
    $access='AuthType Basic
    AuthName "Site Client Access Only"
    AuthUserFile '
    .$domroot.'/.htpasswd_stats
    <limit GET PUT POST>
    require valid-user
    </limit>
    Redirect 301 /stats http://www.'
    .$domain.'/ispcstats/awstats.pl?config=www.'.$domain.'
    '
    ;

                            
    fwrite($fp,$access);
                            
    fclose($fp);
                    }
            }

            function 
    client_insert($event_name,$data) {
                    global 
    $app$conf;
                    
    $this->awstats_update();
            }

            function 
    client_update($event_name,$data) {
                    global 
    $app$conf;
                    
    $this->awstats_update();
            }

            function 
    client_delete($event_name,$data) {
                    global 
    $app$conf;
                    
    $this->awstats_update();
            }

            function 
    user_insert($event_name,$data) {
                    
    // TODO: handle users for awstats access
            
    }

            function 
    user_update($event_name,$data) {
                    
    // TODO: handle users for awstats access
            
    }

            function 
    user_delete($event_name,$data) {
                    
    // TODO: handle users for awstats access
            
    }

            function 
    domain_update($event_name,$data) {
                    global 
    $app$conf;

                    
    $this->domain_insert($event_name$data);
            }

            function 
    domain_insert($event_name,$data) {
                    global 
    $app$conf;

                    if(!@
    is_file("/etc/awstats/awstats.".$data["new"]["domain"].".conf") || ($data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"])) {
                            if ( @
    is_file("/etc/awstats/awstats.".$data["old"]["domain"].".conf") )
                                     
    exec("rm -f /etc/awstats/awstats.".$data["old"]["domain"].".conf");

                            
    exec"echo 'Include \"/etc/awstats/awstats.conf\"' > /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            
    exec"echo 'LogFile=\"/var/log/ispconfig/httpd/".$data["new"]["domain"]."/access.log\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf" );
                            
    exec"echo 'SiteDomain=\"".$data["new"]["domain"]."\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf");
                            
    // exec( "echo 'AllowAccessFromWebToFollowingAuthenticatedUsers=\"".$ht_user_list."\"' >> /etc/awstats/awstats.".$data["new"]["domain"].".conf");

                    
    }

            }

            function 
    domain_delete($event_name,$data) {
                    global 
    $app$conf;

                    if(
    $data["old"]["domain"] != '' ) {
                            if ( @
    is_file("/etc/awstats/awstats.".$data["old"]["domain"].".conf") )
                                     
    exec("rm -f /etc/awstats/awstats.".$data["old"]["domain"].".conf");
                    }
            }




    // end class
    ?>
     
    Last edited: May 31, 2009
  8. sirrus

    sirrus HowtoForge Supporter

    Thank you for this plugin.

    It is not creating awstat conf files in my case. A lot of people use secured php where exec is denied. I think it is at least one securtiy rights issue.

    I suggest to rewrite this code to use fwrite:

    Code:
    function domain_insert($event_name,$data) {
            global $app, $conf;
    
            $newfile = "/etc/awstats/awstats.".$data["new"]["domain"].".conf";
            $oldfile = "/etc/awstats/awstats.".$data["old"]["domain"].".conf";
    
            if(!@is_file($newfile) || ($oldfile != '' && $newfile != $oldfile)) {
                    if ( @is_file($oldfile) )
                            exec("rm -f ".$oldfile);
    
                    $fp = fopen($newfile,"w");
                    if ($fp) {
                            $awcon = "Include \"/etc/awstats/awstats.conf\"\n" .
                            "LogFile=\"/var/log/ispconfig/httpd/".$data["new"]["domain"]."/access.log\"\n" .
                            "SiteDomain=\"".$data["new"]["domain"]."\"\n" .
                            "DNSLookup=\"1\"\n" .
                            "DirData =\"/var/cache/awstats\"\n" .
                            "AllowFullYearView=\"3\"";
                            //$awcon .= "\nAllowAccessFromWebToFollowingAuthenticatedUsers=\"".$ht_user_list."\"";
                            fwrite($fp, $awcon);
                            fclose($fp);
                    }
            }
    }
     
    Last edited: Nov 23, 2009
  9. korbynn

    korbynn Member

    I am running on CentOS 4.3.

    I did all that was suggested in the last 2 posts (Thankyou) but awstats is still not processing the website stats or are the stats else where.
    My client really likes awstats as opposed to webalizer.

    I noticed that the /etc/awstats/awstats.conf did not exist so I
    cp awstats.model.conf awstats.conf
    hoping that this would make the config for awstats to work.

    Any thoughts or pointers to other info is appreciated.
    :confused:
     
  10. stefanr

    stefanr HowtoForge Supporter

    Hello,

    i have tried the following things

    1.)
    aptitute install awstats

    2.)
    vim /usr/local/ispconfig/server/plugins-available/awstats_plugin.inc.php and write the code from post #27 and post #28 into the file.

    3.)
    ln -s /usr/local/ispconfig/server/plugins-available/awstats_plugin.inc.php /usr/local/ispconfig/server/plugins-enabled/awstats_plugin.inc.php

    4.)
    vim /usr/local/ispconfig/server/lib/config.inc.php and insert the row $conf['services']['awstats'] = true;

    i think this is all what i must do on the ispconfig server. And now at all domains the www.domain.de/stats should be replaced by the awstats files and i must see it under www.domain.de/stats.

    It doesent works at the moment have anyone a idea?

    kind regards
    Stefan
     
  11. BorderAmigos

    BorderAmigos New Member

    It is working on my setup. For me it does not replace the webalizer stats in /stats but gives me additional in /awstats. Both packages are working.

    Pretty much as above except create directory in the web root called awstats and give it permissions 777.
     
  12. stefanr

    stefanr HowtoForge Supporter

    Hello BorderAmigos,

    thanks for your answer, you mean that it is all done and everything is fine.
    But i have no directory awstats in any domain. I create in one of the domains manually and chmod 777 the awstats. Now should the awstats plugin should work.

    Can i do manually an awstats update?

    kind regards

    STEFAN
     
  13. BorderAmigos

    BorderAmigos New Member

    Check to see that the config's were created (one for each site)...

    Code:
    /etc/awstats/awstats.example.com.conf
    I use a cron job that runs the below, again for every site...

    Code:
    /usr/lib/cgi-bin/awstats.pl -update -config=example.com -output=main > /var/www/example.com/web/awstats/index.html 
    There may have been other tweaks I don't remember at the moment.
     
  14. stefanr

    stefanr HowtoForge Supporter

    Hi,

    thanks i've done and now i got this error

    Error: SiteDomain parameter not defined in your config/domain file. You must edit it for using this version of AWStats.

    Setup ('/etc/awstats/awstats.conf' file, web server or permissions) may be wrong.
    Check config file, permissions and AWStats documentation (in 'docs' directory).

    when i go to domain.de/awstats

    cat /etc/awstats/awstats.domain.de.conf
    Include "/etc/awstats/awstats.conf"
    LogFile="/var/log/ispconfig/httpd/domain.de/access.log"
    SiteDomain="domain.de"

    shoud i give the webserver read//write rights to the awstats.conf file?

    what do i wrong?

    kind regards
    STEFAN
     
  15. BorderAmigos

    BorderAmigos New Member

    All I can do is say what my settings are.

    All of the conf files in /etc/awstats are owned by root and permissions of 644.

    In /etc/awstats/awstats.conf
    SiteDomain=""

    in /etc/awstats/awstats.example.com.conf
    SiteDomain="example.com"
     
  16. astewart

    astewart ISPConfig Developer

    Unable to exec awstats.pl from user cgi-bin directory

    So I have awstats installed and no problems creating static 'index.html' file in the following path for each domain:
    I have a seperate cron setup for each domain as follows:
    I copied the 'awstats.pl' file to each 'cgi-bin' directory for each domain that has 'cgi' enabled.
    Chmodded the script to 755 and changed the user and group to to the owner of that domain, eg (web2:client0).

    So there are no problems viewing the static page but anytime I click on one of the links from the main awstats page to see 'Full List' or any link for that matter that directly calls the 'awstats.pl', I get the 'Internal 500' error because of 'suexec'.
    When I disabale 'suexec' it works fine but I don't want to have to disable it.

    Obviously it has something to due with the settings in the 'awstats.conf' file, at least I think so.

    Here is what the suexec.log shows:
    Here is my awstats.conf file:
    And here is what is listed in one of my specified .vhost files for a domain: (Just the CGI Part)
    I've already done a lot of google searching but no luck.
    Does anyone have any ideas why this is not working with 'suexec' enabled?

    Thanks!
     
    Last edited: Feb 1, 2010
  17. BorderAmigos

    BorderAmigos New Member

    Not sure but check and make sure the directories involved have the correct owners, groups and permissions as well as the files. This messed me up at one point.
     
  18. astewart

    astewart ISPConfig Developer

    I've been playing around with permissions and user/groups for the last 3 -4 days but no luck.

    It has to be with the way I have the directive setup, but I think I tried everything (Well obviously not everything)


    BorderAmigos, would you be able to show me what you have in your
    /etc/apache2/conf.d/awstats.conf file?
     
  19. BorderAmigos

    BorderAmigos New Member

    "BorderAmigos, would you be able to show me what you have in your
    /etc/apache2/conf.d/awstats.conf file? "

    I don't have this file in this location. It is not part of the Apache configuration. Under /etc/awstats there are awstats.conf and another awstats.example.com.conf for each domain and subdomain (24 files in my case).

    Here is an example of one of the domain files...
    Code:
    Include "/etc/awstats/awstats.conf"
    LogFile="/var/log/ispconfig/httpd/chloetry.com/access.log"
    SiteDomain="chloetry.com"
    HostAliases="www.chloetry.com localhost 127.0.0.1"
    
    The awstats.conf is to big to post so I attached it.

    PS The "Include awstats.local.conf" file included at the end is just a copy of the "awstats.conf" file without the include. It's there in case an update overwrites the original file.
     

    Attached Files:

    Last edited: Feb 2, 2010
  20. astewart

    astewart ISPConfig Developer

    This is what i currently have in my '/etc/apache2/conf.d/awstats.conf '
    Here is an example of one of my domain files:
    I noticed that you attached the awstats.conf file from /etc/awstats, I was wondering what you have in your awstats.conf file in /etc/apache2/conf.d directory?
     

Share This Page