View Single Post
  #27  
Old 29th May 2009, 12:52
djtremors djtremors is offline
Senior Member
 
Join Date: Apr 2006
Location: Sydney
Posts: 278
Thanks: 0
Thanked 12 Times in 10 Posts
Default

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 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');
                
$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
?>
__________________
www.emperor-it.com for ISPConfig mods/hacks

Last edited by djtremors; 31st May 2009 at 12:28.
Reply With Quote