Obtaining user logs! (Task 1)

Out of a lot of options that we had, we opted for OpenCart ( http://www.opencart.com/ ) for our front end e-commerce solution. So the first step was to download and configure open cart over a locally running LAMP server. The steps for setting up the OpenCart site on your Apache server can be found here : ” http://docs.opencart.com/display/opencart/Installation ” .

 

                      Image

 

Apache provides a mod_usertrack ( “http://httpd.apache.org/docs/2.0/mod/mod_usertrack.html ” ) module for logging the user activity by using cookies and generates a ‘clickstream’ log. An enhanced version of the same module can be found here by the name mod_cookietrack : ” https://github.com/piykumar/modified_mod_cookietrack ” . This module requires apache-dev to be installed and perl. After that you install it using the command ‘sudo ./build.pl’.

 

NOTE : If you have errors saying that apxs file is not found in /usr/sbin/apxs try to look for it in the folder /usr/bin/apxs and then copy it there!

 

Once that is done and the module has been successfully added to your Apache server, its time to provide the UUIDs for our logs. You see, the module has support for an external library to generate UUIDs. The function should be written in C and the prototype for the same being

void gen_uid(char *uid, char *timestamp, char *ip);

We have a basic function for it which generates UUIDs with the format “I….T…R…”, where the numbers after I are the IP address and those after T are the timestamp and three digits after R are random digits generated for uniqueness! 

Now that we have the function to generate the UUIDs, we add it to the module with the command, ‘ sudo ./build.pl –inc /where/uid/lives –lib uuid.c ‘.

The module has a many directives of which the CookieTracking directive has to be enabled for the tracking to begin. This can be done by adding the line ‘CookieTracking on’ in the server config file ie. either apache2.conf or httpd.conf. Some other useful directives are CookieExpires, CookieName, CookieNoteName etc. The details of all the directives are available in the documentation of mod_cookietrack.

                      Image

The CookieNoteName directive is used to refer to the UUID while generating custom logs. Here i have used the CookieNoteName uid for referring to the UUIDs. The name of the cookie here is ‘ocart’. Once done save the file and remember to restart the server with the command ‘ sudo service apache2 restart ‘.

Now you can go to your OpenCart site and check if the cookie is being created by the WebConsole( Ctrl+Shift+K ). Here is a what it should look like!

                     Image   

Notice that the cookie contains the name ‘ocart’ and the 64 bit UUID!

Finally we have to generate some custom logs. A really good place to learn more about generating server logs would be ” http://www.serverwatch.com/tutorials/article.php/1128861/Apache-Guide-Logging-Part-3–Custom-Logs.html “. First we have to define a log format and refer it by some name. And then define a directory for the custom logs to be stored.

                         Image

In line 211 i have defined a Log Format which displays just the UUID( ‘%{uid}n’ ) and the first line of the request( ‘%r’ ) and give it a referral name ‘client’ . Next in line 213 i have defined as to where these custom logs will be stored ie. /var/www/logs/c_logs. Once that is done remember to create the directory and touch the file in the appropriate directory. And ofcourse please do restart the server!

Go to your OpenCart site and start sending requests, you will then see the logs piling up in the c_logs file in /var/www/logs folder!

                    Image

So this is just the beginning! The first of the 5 tasks to continue! Cheers! 😀 \,,/

 

 

 

Advertisements

One thought on “Obtaining user logs! (Task 1)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s