Awstats mod - uses dynamic pages (non static)

Discussion in 'Tips/Tricks/Mods' started by djtremors, Nov 8, 2006.

  1. djtremors

    djtremors New Member

    This is my version of the awstats page. It uses dynamic generating awstats.pl code and uses HTTP basic authentication to access the pages.

    http://www.djtremors.com/index.php?option=com_content&task=view&id=25&Itemid=139

    The stats page is viewed under the domain you are checking and with a /stats on the end.
    ie. www.domain.com/stats

    Hopefully I got the installer.sh working enough to work on any Linux distro but it's been biased towards Fedora/Redhat/Centos.

    Hopefully I've ironed out the installer and so on. I'm still currently working on it a bit. But it's pretty much all there.

    NOTE: It's not compatible with the other awstats version released by one of the other contributors which creates static HTML pages. So make sure you pick one or the other.
     
  2. domino

    domino New Member

    Thanks for this. If all works well, I think this would be a great ISPConfig Add-on :cool:
     
  3. djtremors

    djtremors New Member

    yeah I uploaded it to my friends Fedora box to test first time deployment which was were I realised some small missed files, mistakes and required changes to my scripts and then modified my local copies and so on.

    So I hope I haven't missed anything or left something out. my mates machine is now working so should be fine.

    Basically the way it works on the front side is like this:

    1. Browse points to http://www.____.com/stats
    2. The .htaccess file (created by the crontab/awstats.php file) authenticates the user and redirects to the /ispc.awstats/awstats.pl?config=www____.com page.
    3. the crontab/awstats.php file creates all the .htaccess/.htpasswd files as well as creates all /etc/awstats/awstats.{domain}.conf files

    All awstats data is stored in /home/admispconfig/ispconfig/web/ispc.awstats.data/, outside of the /ispc.awstats page.

    Authentication files are stored together in /home/admispconfig/ispconfig/web/ispc.awstats/.htpasswd as well as the websites home directory. ONLY the domains allowed users can access their own sites so there's no cross site security issues there.

    So hopefully everything is right to go first go for you all. Otherwise just msg me the hiccups and the configuration you got (ie. where's apaches confs are and crontab if not /var/spool/cron/root etc.etc.etc.)

    thx ;)
     
  4. djtremors

    djtremors New Member

    Updated

    Fixed a small bug which didn't create/update the awstats archive & db logs due to an incorrect DataDir setting in the /etc/awstats/awstats.model.conf file.
    Full path corrects the problem.

    Anyone with this bug can easily change the line in /etc/awstats/awstats.model.conf

    and put instead
    PHP:
    DirData="/home/admispconfig/ispconfig/web/ispc.awstats.data"
     
  5. falko

    falko Super Moderator Howtoforge Staff

  6. djtremors

    djtremors New Member

    yes, I ran an update script which auto creates the tgz and puts it on the site but forgot to at least create a changelog or even version file but yeah, if you see me mention an update then it's live on the download already.
     
  7. falko

    falko Super Moderator Howtoforge Staff

    That's good! :)
     
  8. martinfst

    martinfst Member Moderator

    Installed this mod on Ubuntu 6.10 (Edgy Eft) and made it work

    I just installed this mod on Ubuntu 6.10, but I have to assume some of the mods below are also essential for other deployments ;)

    I've found the following problems with this install on Ubuntu 6.10 (Edge Eft) and Apache2.
    In the install.sh script, which is found in the installation directory ~/ispc.awstats-install:
    1. The quotes around the the variables are not needed and escaping is done too much, so the variables are not set. Change the lines reading:
      Code:
      HTTPPATH="`httpd -V |grep HTTPD_ROOT | cut -f 2 -d \\"`"
      CONFFILE="`httpd -V |grep SERVER_CONFIG_FILE | cut -f 2 -d \\"`"
      to
      Code:
      HTTPPATH=`httpd -V |grep HTTPD_ROOT | cut -f 2 -d \"`
      CONFFILE=`httpd -V |grep SERVER_CONFIG_FILE | cut -f 2 -d \"`
    2. Next in the same install.sh script, the wrong variable names are used for updating the apache configuration, thus it's never updated. You also need to restart apache to make the changes effective.
      Change:
      Code:
      .......
      elif [ -f "$SERVER_CONFIG_FILE" ]; then
       echo " Found: full path conf file"
       cat "$SERVER_CONFIG_FILE" >/tmp/httpd.conf.$$ && \
       cat /home/admispconfig/ispconfig/web/ispc.awstats/httpd.patch >> /tmp/httpd.conf.$$ && \
       mv "$SERVER_CONFIG_FILE" "$SERVER_CONFIG_FILE.$$" && \
       mv /tmp/httpd.conf.$$ "$SERVER_CONFIG_FILE"
       [ "$?" != 0 ] && ( echo "ERROR: failed to copy httpd configuration"; exit 1 )
      elif [ -f "$HTTPPATH/$SERVER_CONFIG_FILE" ]; then
       echo " Found: httpd+conf full path conf file"
       cat "$HTTPPATH/$SERVER_CONFIG_FILE" >/tmp/httpd.conf.$$ && \
       cat /home/admispconfig/ispconfig/web/ispc.awstats/httpd.patch >> /tmp/httpd.conf.$$ && \
       mv "$HTTPPATH/$SERVER_CONFIG_FILE"
      "$HTTPPATH/$SERVER_CONFIG_FILE.$$" && \
              mv /tmp/httpd.conf.$$ "$HTTPPATH/$SERVER_CONFIG_FILE"   
              [ "$?" != 0 ] && ( echo "ERROR: failed to copy httpd configuration"; exit 1 )
      fi
      to
      Code:
      .......
      elif [ -f "$CONFFILE" ]; then
              echo " Found: full path conf file"
              cat "$CONFFILE" >/tmp/httpd.conf.$$ && \
              cat /home/admispconfig/ispconfig/web/ispc.awstats/httpd.patch >> /tmp/httpd.conf.$$ && \
              mv "$CONFFILE" "$CONFFILE.$$" && \
              mv /tmp/httpd.conf.$$ "$CONFFILE"
              [ "$?" != 0 ] && ( echo "ERROR: failed to copy httpd configuration"; exit 1 )
      elif [ -f "$HTTPPATH/$CONFFILE" ]; then
              echo " Found: httpd+conf full path conf file"
              cat "$HTTPPATH/$CONFFILE" >/tmp/httpd.conf.$$ && \
              cat /home/admispconfig/ispconfig/web/ispc.awstats/httpd.patch >> /tmp/httpd.conf.$$ && \
              mv "$HTTPPATH/$CONFFILE" "$HTTPPATH/$CONFFILE.$$" && \
              mv /tmp/httpd.conf.$$ "$HTTPPATH/$CONFFILE"     
              [ "$?" != 0 ] && ( echo "ERROR: failed to copy httpd configuration"; exit 1 )
      fi
      
      And restart apache with
      Code:
       /etc/init.d/apache2 force-reload
    3. The cron script also contains an error by referencing the wrong alias. So Update line 103 of /root/ispconfig/scripts/shell/awstats.php from
      Code:
      fwrite($fp, "\nRedirect 301 /stats http://".$web_real_name."/ispc.awstats/awstats.pl?config=".$web_real_name."\n");
      
      to
      Code:
      fwrite($fp, "\nRedirect 301 /stats http://".$web_real_name."/ispcstats/awstats.pl?config=".$web_real_name."\n");

    Happy AWStats :D statistics by accessing <siteURL>/stats.
     
  9. djtremors

    djtremors New Member

    Holly crap... that bad. thanks for that.

    The extra escaping didn't cause issues in fedora/redhat and removing them as you have didn't complain either so I've removed these to suit more distros now.

    Fixed VAR name (Ouch, how the hell did that go wrong).

    The Redirect /ispc.awstats/ has been corrected.

    Added your instructions to restart apache at the end of the script and a thankyou note to you for the fixes.

    PLEASE NOTE: The original link on first post contains the changes martinfst has supplied.


    Hopefully this is alot better now, bit hard to test on a live system hence the errors.
     
  10. b00gz

    b00gz New Member

    How can I enable full year view by default for all of the pages? I appreciate the help!
     
  11. djtremors

    djtremors New Member

    Sorry for the lateness, my server was down for a while and couldn't check it to see what you meant.

    I'm not sure what you mean by "full year view".
     
  12. b00gz

    b00gz New Member

    I figured it out I was referring to AllowFullYearView=3 in the awstats.model.conf
     
  13. martinfst

    martinfst Member Moderator

    AWstats and mod_perl / mod_perl2

    I'll post here, as this is an issue with AWstats with dynamic pages and mod_perl. As probably most people using AWstats Dynamic with the ISPConfig panel will end up in this thread, it'll go here.

    I had very inconsistent performance of awstats, most of the time identified by awstats reporting I had not used a valid user, but couple of refresh pages later I suddenly did get a page. And after clicking a submenu item, that pointed to a new page, I suddenly found myself not being a valid user anymore. Initially I though this was a bug of Firefox 2 not being able to hold credentials, but as it looks now it has to do everything with the way AWstats is running in mod_perl.
    Code:
    IT DOES NOT SEND THE CORRECT HEADERS!
    Sorry for the capitalization, but I believe this is a serious problem of awstats and it's in there for years. I fixed the code months (years) ago on my systems , but moving to a new server and a new version pointed me again to this.

    If you have mod_perl2 and Apache2 running, there's no need to mess around with the code, as there's a mod_perl directive, which can solve this issue. You need to edit the .htaccess file where awstats.pl resides. If you use the install of this thread, you'll find it at
    Code:
    /home/admispconfig/ispconfig/web/ispc.awstats/.htaccess
    Add the following lines at the end:
    Code:
    <Files ~ (\.pl$)>
            PerlSendHeader On
    </Files>
    
    Presto. Now Awstats runs as expected, without throwing you out as an non-authenticated user, but yet your were.
     
  14. Petr WhiskI

    Petr WhiskI New Member

    Cross site security issues

    Try this:
    Log in stats of your site and change url in browser:
    http://www.yoursite.tld/ispcstats/awstats.pl?config=www.another_site_on_the_same_isp.tld

    So what do you thing about crossite security now? ;)
     
  15. martinfst

    martinfst Member Moderator

    Did this (before you even posted) and the result in your browser is:
    Code:
    Error: User 'web1_xxxxxxxx' is not allowed to access statistics of this domain/config.
    
    Setup ('/etc/awstats/awstats.www.anothersideatisp.tld.conf' file, web server or permissions) may be wrong.
    Check config file, permissions and AWStats documentation (in 'docs' directory).
    So, now it's awstats rejecting, but even so, you don't have access. :)
     
  16. Petr WhiskI

    Petr WhiskI New Member

    AllowAccessFromWebToAuthenticatedUsersOnly=0

    Thanks, I found it.
    In /etc/awstats/awstats.model.conf
    have to set
    AllowAccessFromWebToAuthenticatedUsersOnly=1

    - it was AllowAccessFromWebToAuthenticatedUsersOnly=0 !! after fresh install of your package :(
    Strange thing - look at /home/admispconfig/ispconfig/web/ispc.awstats/awstats.model.conf
    there is AllowAccessFromWebToAuthenticatedUsersOnly=0 too...

    Thank you for fast reply and hope ;)
     
  17. Petr WhiskI

    Petr WhiskI New Member

    Webalizer must be present with this package

    BTW - test at line 45 in /root/ispconfig/scripts/shell/awstats.php

    exec("which webalizer", $webalizer_location, $verify);

    is needed for awstats? I think not...

    I removed Webalizer package (useless with this suprtupr awstats ;) ) and awstats updates stops working...
    half an hour of finding around (I'm 5 months new in linux) :(
     
  18. falko

    falko Super Moderator Howtoforge Staff

    I think you can remove that line from the script.
     
  19. Ovidiu

    Ovidiu Active Member

    hello,

    I would love to use this plugin but I am not sure if those fixes martinfst mentioned found their way into the zip file available for download on the coders page - if it is uptodate I guess it will work on a Debian system too, as martifst got it working on a Ubuntu system.

    can anyone confirm this is working on a debian based system?
     
  20. Petr WhiskI

    Petr WhiskI New Member

    Me - on Debian Sarge
    with some cosmetic issues mentioned above ;)
     

Share This Page