View Single Post
  #1  
Old 29th March 2009, 23:16
Mouton Mouton is offline
Junior Member
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 4 Times in 1 Post
Default ISPconfig 3 - awstats

I quickly wrote this small plugin to create awstats config file automatically (base on the ISPconfig 2 plugin)
It really needs improvement and automation but that's a start for whoever has time to write more about it...
Do not hesitate to improve or fix it....

PS: congrats for the 3.0.1 version !


Just paste the following code in a awstats_plugin.inc.php file in the plugins-available directory.


Code:
<?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');
        }


        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 by Mouton; 29th March 2009 at 23:19.
Reply With Quote
Sponsored Links