1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[USEFUL] Making awstats public without giving full access.

Discussion in 'Traffic Analysis' started by proxywhereabouts, Jun 26, 2008.

  1. #1
    For those of you who has sites for sale and was tired grabbing a screenie of your awstats, here is a simple PHP code to make your awstats public.

    So, now you can show your site's awstats to your buyers or advertisers without having to give out cpanel info or the hassle of grabbing a screenshot.

    I hope you do find this code useful. The code was taken from other forum

    How to
    • paste the code found below into a new text file and save, give it an original name
    • Edit the variables that are bold, with the corresponding details for your account
    • upload and you're done
    
    awpublicstats.php
    
    
    <?php
    /*
    dv at josheli.com
    
    Proxy for viewing Awstats outside of cpanel. I assume no liability.
    
    
    
    */
    
    $user = 'username';//your cpanel username
    $pass = 'password';//your cpanel password
    $domain = 'mydomain.com';//do not include 'http://' or 'www.'
    
    /*
    Domain of the stats you wish to view, e.g. a subdomain like "cvs.mydomain.com".
    If left blank, defaults to the "domain" above
    Another option is to set the "config" parameter in the url of your browser, e.g.:
    http://www.domain.com/awstats.php?config=sub.domain.com
    */
    $config_domain = '';
    
    /*
    If you don't know what you're doing, set $dynamic_images equal
    to TRUE, and don't worry about the $image_directory variable.
    Otherwise,
        - Normally, this script will load images by proxy, i.e. awstats.php
          is called for each <img> tag and will send the correct
          image to the browser. This is not the way the web is designed
          to work. So, if you wish to improve performance and lower
          bandwidth, you can:
          1. Set $dynamic_images to FALSE
          2. Create an image directory in your webroot
          3. Copy all of awstats image sub-directories to this new directory
          4. Point the $image_directory variable to your new directory     
        You will get all the benefits of cached, static images.
        In order to get the Awstats images and their directories, you will
        probably need to download an awstats distribution from
        awstats.sourceforge.net. The final layout will probably look like this:
    
          awstats_imagedir/
                        browser/
                        clock/
                        cpu/
                        flags/
                        mime/
                        os/
                        other/
    
        Under each of those sub-directories will be dozens of .png files.
    */
    
    $dynamic_images = true;
    $image_directory = './awstats_images/';
    
    //lame attempt to combat referrer spam
    $spam_words = array('mortgage', 'sex', 'porn', 'cock', 'slut', 'facial', 'loving', 'gay', '.ro');
    
    
    /***********
    NO NEED TO TOUCH ANYTHING BELOW HERE
    ************/
    
    //retrieves the file, either .pl or .png
    function get_file($fileQuery)
    {
      global $user, $pass, $domain;
      return file_get_contents("http://$user:$pass@$domain:2082/".$fileQuery);
    }
    
    $requesting_image = (strpos($_SERVER['QUERY_STRING'],'.png')===false)?false:true;
    
    if($requesting_image) //it's a .png file...
    {
      if(!$dynamic_images && !is_dir($image_directory))
      {
        exit;
      }
      $fileQuery = $_SERVER['QUERY_STRING'];
    }
    elseif(empty($_SERVER['QUERY_STRING']))//probably first time to access page...
    {
        if(empty($config_domain))
        {
            $config_domain = $domain;
        }
      $fileQuery = "awstats.pl?config=$config_domain";
    }
    else //otherwise, all other accesses
    {
      $fileQuery = 'awstats.pl?'.$_SERVER['QUERY_STRING'];
    }
    
    $file = get_file($fileQuery);
    
    //check again to see if it was a .png file
    //if it's not, replace the links
    if(!$requesting_image)
    {
      $file = str_replace('awstats.pl', basename($_SERVER['PHP_SELF']), $file);
      
      if($dynamic_images)
      {
        $imgsrc_search = '="/images';
        $imgsrc_replace = '="'.basename($_SERVER['PHP_SELF']).'?images';
      }
      else
      {
        $imgsrc_search = 'src="/images/awstats/';
        $imgsrc_replace = 'src="'.$image_directory;
      }
    
      $file = str_replace($imgsrc_search, $imgsrc_replace, $file);
      $file = str_replace($spam_words, 'SPAM', $file);
    }
    else //if it is a png, output appropriate header
    {
      header("Content-type: image/png");
    }
    
    //output the file
    echo $file;
    ?> 
    PHP:

    See it in action:
     
    proxywhereabouts, Jun 26, 2008 IP
  2. Whitey

    Whitey Active Member

    Messages:
    1,386
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Awesome idea, would make people selling sites that much more legit :)
     
    Whitey, Jun 27, 2008 IP
  3. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #3
    That is the whole idea..
    So, rather than asking seller to prove traffic stats, you can just ask him to upload the code and can view the stats yourself..live!

    I use this method when selling my sites. Saves my time from taking screenshot.
     
    proxywhereabouts, Jun 27, 2008 IP
  4. CashinX

    CashinX Active Member

    Messages:
    840
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    75
    #4
    Great idea and put into action well, I love it and will definetly be using it :D

    And @ Whitey: Not neccessarily, people could still copy the web page & put any numbers they want in it.
     
    CashinX, Jun 27, 2008 IP
  5. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #5
    what do you mean by "put any numbers they want in it?"
    Put what number?
     
    proxywhereabouts, Jun 27, 2008 IP
  6. CashinX

    CashinX Active Member

    Messages:
    840
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    75
    #6
    Sent you a PM as some things dont need to be said publically.
     
    CashinX, Jun 27, 2008 IP
  7. Mailman55

    Mailman55 Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Awesome script for awstats viewing. I recommend you sell this tool in the SitePoint marketplace where this tool would be very useful.
     
    Mailman55, Jun 27, 2008 IP
  8. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #8
    Nah..it would be unethical for me to sell this script/code as it was not originally coded by me.
     
    proxywhereabouts, Jun 27, 2008 IP
  9. gostats

    gostats Peon

    Messages:
    325
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    On top of providing awstats, it would be a good idea to also have a secondary third party tracker to back up the traffic claims.
     
    gostats, Jun 28, 2008 IP
  10. abercrombie

    abercrombie Peon

    Messages:
    654
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #10
    this is a pretty cool script, and even though you're typing in your UN/PW, seems relatively secure. someone correct me if i'm wrong.
     
    abercrombie, Jul 8, 2008 IP
  11. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #11
    Yes, you are required to write your UN/PW into the script, however, it won't be shown to anyone even he/she look on your code. try look at my demo up there.

    also, if you want to be safe, use the web based encrypter to encrypt the file thus making it much more safer.
     
    proxywhereabouts, Jul 8, 2008 IP
  12. Dr.

    Dr. Banned

    Messages:
    154
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Very USEFUL scripts,
    butthats is secure?
     
    Dr., Dec 5, 2008 IP
  13. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #13
    I believe it is secure as so far there is now way that you can peek on the source code to see the details.
    Furthermore, you can encode your source into base64 or blowfish before making it live.
     
    proxywhereabouts, Dec 5, 2008 IP
  14. kamnitnoom

    kamnitnoom Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    wow! I get knowlage
     
    kamnitnoom, Dec 6, 2008 IP