The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Export Awstats so that Clients can see?

Discussion in 'General Discussion' started by bumcheekcity, Apr 8, 2008.

  1. bumcheekcity

    bumcheekcity Registered

    Joined:
    Apr 8, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    To cut a long story short, I have a lot of clients that I DONT want to be able to access their own cPanel, but I do want to give them access to their stats. Preferably Awstats, as the topic says, because it's the best, but any of the stats programs would be a start I suppose. I didn't know if it would be possible to get some kind of CRON job to run or something, or if cPanel has this setting in it normally. I dont really mind exactly HOW they see their stats (like by going to http://mywebsite.com/awstats/ or something, and there's a page updated there), but I'd like it to be easy to remember.

    Thanks for any and all help :D
     
  2. verdon

    verdon Well-Known Member

    Joined:
    Nov 1, 2003
    Messages:
    836
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Northern Ontario, Canada
    cPanel Access Level:
    Root Administrator
    Here's what I do..

    1) In the client site, create a dir called stats. If you wish, you can protect this with a simple .htaccess file to keep bots and snoops out.

    2) In that dir I put this as an index.php file
    PHP:
    <?php 
    //original script from josheli.com 

    // path to file with login info
    include ("/path/to/somesafe/place/statscon.php");

    /* 
    NO NEED TO TOUCH ANYTHING BELOW HERE 
    */ 

    //retrieves the file, either .pl or .png 
    function getFile ($fileQuery ){ 
        global 
    $user ,$pass ,$domain ;
        return 
    file_get_contents ("http://$user:$pass@$domain:2082/" .$fileQuery ,'r' ); 
    }

    //it's a .png file... 
    if( strpos ($_SERVER ['QUERY_STRING' ], '.png' )!== false ) { 
        
    $fileQuery =$_SERVER ['QUERY_STRING' ]; 
    }
    //probably first time to access page... 
    elseif(empty( $_SERVER ['QUERY_STRING' ])){ 
        
    $fileQuery ="awstats.pl?config=$domain;
    }
    //otherwise, all other accesses 
    else { 
        
    $fileQuery ='awstats.pl?' .$_SERVER ['QUERY_STRING' ]; 
    }

    //now get the file 
    $file =getFile ($fileQuery ); 

    //check again to see if it was a .png file 
    //if it's not, replace the links 
    if( strpos ($_SERVER ['QUERY_STRING' ], '.png' )=== false ) { 
        
    $file =str_replace ('awstats.pl' ,basename ($_SERVER ['PHP_SELF' ]), $file ); 
        
    $file =str_replace ('="/images' ,'="' .basename ($_SERVER ['PHP_SELF' ]). '?images' ,$file ); 
    }
    //if it is a png, output appropriate header 
    else { 
        
    header ("Content-type: image/png" ); 
    }

    //output the file 
    echo $file ;
    ?> 
    3) and create the file '/path/to/somesafe/place/statscon.php' with the following info..
    PHP:
    <?php

    $user 
    'username' ;//the cpanel username 
    $pass 'password' ;//the cpanel password 
    $domain 'domain.com' ;//do not include 'http://' or 'www.' 

    ?>
     
  3. rligg

    rligg Well-Known Member

    Joined:
    Sep 16, 2003
    Messages:
    277
    Likes Received:
    0
    Trophy Points:
    16
    This works great but I do not have any images for the graphs. They are just white.Any ideas? This also creates a error_log in the stats folder.

    error: [06-Nov-2008 11:44:52] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/$user/statscon.php:8) in in /home/$user/public_html/stats/index.php on line 41
     
    #3 rligg, Nov 6, 2008
    Last edited: Nov 6, 2008
  4. rligg

    rligg Well-Known Member

    Joined:
    Sep 16, 2003
    Messages:
    277
    Likes Received:
    0
    Trophy Points:
    16
    <?php

    $user = 'username' ;//the cpanel username
    $pass = 'password' ;//the cpanel password
    $domain = 'domain.com' ;//do not include 'http://' or 'www.'

    ?>

    The closing "?>" is what was causing errors for me. Removed it and everything works great! Thanks.
     
  5. jmcole

    jmcole Active Member

    Joined:
    Aug 17, 2004
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    1
    you could create a symlink within the public_html folder to /home/username/tmp/awstats and then use cPanel to password protect this URL.

    login as root user
    cd /home/username/public_html
    su username
    ln -s ../tmp/awstats
    exit
    ls -al to make sure the symlink is there and check it quick via web browser
    login to cPanel for this user and go to Password Protect Directories, all set.
     
Loading...

Share This Page