Thursday, December 27, 2007

SARG - Squid Analysis Report Generator

SARG - Squid Analysis Report Generator is a tool that allow you to view "where" your users are going to on the Internet.

Its very useful tool which generates graphical and tabular report from your access.log file in a web browser.







You can get sarg from http://sarg.sourceforge.net/sarg.php
Extract it to your src folder, configure it and install it.

The configuration file is sarg.conf. You really don't need to change that file as most of the option can be passed through command line parameters. One thing you must make sure is that the output directory is your web accessible directory. The configuration file is pretty simple. Also make sure that it gets your right access.log file.

Tuesday, December 25, 2007

Google Analytics for you blog

Google Analytics can help you track uses of your site and plan for the future. You must already be knowing about this. I am posting this because adding this to your blog can be a little tricky.

Many users are trying to add the Google analytics code the classical way which works only on classic templates. If you try it for new template you will get the following error.

We were unable to save your template
Please correct the error below, and submit your template again.
Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: The content of elements must consist of well-formed character data or markup

So to successfully set up try the following way.
Click Template
Click Page Elements
Click Add
Click HTML/JavaScript
Put your code their.
Do not write anything more not even the title. If you do so, it will appear on the homepage.
Check you Google analytics account

Friday, December 21, 2007

Your wife's future


If you are a computer guy then one day you sure will find your wife like in the picture below

Password protect a web page

Password protect your web pages in apache server in a very simple way. This is however not that secure and is not recommended. Just use this for simple thing and when other authentication cant be used.

First create a file which holds username and password.
For this you can use htpasswd program.

/usr/local/httpd/bin/htpasswd -c /usr/local/httpd/passwordfile username

The -c option here creates new file. So if the file already exists or you are just modifying or adding a new user omit -c option. Not doing that will make a new file resulting in loss of old username and password.

The file must be somewhere your webserver can find but not other place. Though the password is encrypted its better to keep it off from human eye.

Now edit you httpd.conf file to include the follwoing line in whichever websites that you require authentication


AuthType Basic
AuthName "By Invitation Only"
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen sungo


Restart apache and you're done.

Additional reading: http://httpd.apache.org/docs/1.3/howto/auth.html#basic

Sunday, December 16, 2007

MRTG for SQUID

MRTG for SQUID gives you a detail idea of what is happening behind the scene. In this tutorial I'll make sure that you will successfully set up one like below.


First thing is to make sure that you have given --enable-snmp option while compiling your squid. If you have not done so then its time to do so. Compile your squid with --enable-snmp and then 'make clean', 'make', and 'make install'

Edit you squid.conf file so that
snmp_port 3401
acl snmppublic snmp_community public
snmp_access allow snmppublic localhost
snmp_access deny all

The first line defines the port SNMP is listening on squid.
Second line defines public as the community string or lets say password.
Third line defines that from localhost snmp query can be made to squid.
Fourth line denies query from all.(except localhost)

Now you need a web server to serve the graphs.

Download apache from http://www.reverse.net/pub/apache/httpd/httpd-2.2.6.tar.bz2
mv ./httpd-2.2.6.tar.bz2 /usr/local/src
cd /usr/local/src
bunzip2 -c /usr/local/src/httpd-2.2.6.tar.bz2 | tar xvf -
rm httpd-2.2.6.tar.bz2
mv httpd-* httpd
cd httpd
./configure --enable-prefix=/usr/local/httpd
make
make install

Now you need to configure apache. Lets just host it in a simple way.

mkdir -p /usr/local/www/mrtg
vi /us/local/httpd/conf/httpd.conf
Change DocumentRoot to "/usr/local/www/mrtg"
save and exit
run /usr/local/httpd/bin/apachectl -k start


Now its time for setting MRTG server. Download the following programs:

http://www.gzip.org/zlib (gzip
http://www.libpng.org/pub/png/libpng.html (libpng)
http://www.libgd.org/ (gd)
http://oss.oetiker.ch/mrtg/pub (mrtg)


Copy zlib to /usr/local/src
gunzip -c zlib-*.tar.gz | tar xvf -
rm zlib-*.tar.gz
mv zlib-* zlib
cd zlib
./configure
make
cd ..


Copy libppng to /usr/local/src
gunzip -c libpng-*.tar.gz |tar xvf -
rm libpng-*.tar.gz
mv libpng-* libpng
cd libpng
make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib
rm *.so.* *.so
cd ..


The \ in the following line means that they are same line.

Copy gd to /usr/local/src
gunzip -c gd-2.0.11.tar.gz |tar xf -
mv gd-2.0.11 gd
cd gd
env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" \
./configure --disable-shared --without-freetype --without-jpeg
make
cp .libs/* .
cd ..


Copy mrtg to /usr/local/src
gunzip -c mrtg-2.15.2.tar.gz | tar xvf -
cd mrtg-2.15.2
./configure --prefix=/usr/local/mrtg-2 \
--with-gd=/usr/local/src/gd \
--with-z=/usr/local/src/zlib \
--with-png=/usr/local/src/libpng
make
make install
mkdir -p /usr/localmrtg-2/cfg

Now lets make graph for squid.

Download the following two files

mrtg-squid.cfg
squid.mib

Copy them to /usr/local/mrtg-2/cfg/
edit mrtg-squid.cfg and do as the file says. Put working dir as /var/www/mrtg

Lets make graph
/usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/cfg/mrtg-squid.cfg
Run this for three times. Its OK for now to see few errors.

Lets make index page
/usr/locl/mrtg-2/bin/indexmaker --title="OSR" --show=day --section=title --output=/var/www/mrtg/index.html /usr/local/mrtg-2/cfg/mrtg-squid.cfg

Fire your browser and you should see the graph

For continous monitoring
crontab -e
*/5 * * * *
/usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/cfg/mrtg-squid.cfg --logging=/var/log/mrtg.log

Additional reading: http://wiki.squid-cache.org/SquidFaq/SquidSnmp