View Single Post
Old 02-03-2016, 10:29 AM   #1169
mariosipad
Guru
mariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watchmariosipad is clearly one to watch
 
Posts: 726
Karma: 10738
Join Date: Nov 2012
Device: iPad & iPhone with Marvin 2 + 3 & Kobo Glo HD
Hi TC,

This turned out to be a nice little project!

Quote:
I'd be interested in how you're writing to access.log.
I don't, apache does out of the box (Linux Mint & Debian)
What to write to access.log is defined in /etc/apache2/apache2.conf and when to write is defined
in /etc/apache2/sites-enabled/000-default.conf.

The file without comments. See line -> Customlog:
Code:
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
Quote:
The beauty of my solution is that I don't need to modify any of the application scripts other than to enable the log file. Plus you can run it manually whenever you want.
I agree! However in my "Solution" I just add 1 line (plus comments) to one of the scripts. I don't even modify .htaccess!

Now for my "solution" ;-)
It's most certainly not "the best", but it just works (for me).

1 - I installed COPS files in: /var/www/html/cops
Calibre Databases can be installed where you/I want.

2 - I created the file /etc/apache2/auth.cops
Code:
### /etc/apache2/auth.cops ###

	### Add password for /var/www/html/cops/* ###

        <Directory /var/www/html/cops>
        	AuthType Basic
        	AuthName "Restricted Content"
        	AuthUserFile /etc/apache2/.htpasswd
        	Require valid-user
	</Directory>

        # Select only the "/cops/" dir to log
	SetEnvIf Request_URI "/cops/$" logit
	
	### Define new LogFormat & CustomLog
	 	
	LogFormat "%u %t %h %>s" simple

        CustomLog ${APACHE_LOG_DIR}/user.log simple env=logit

### end ###
a - you can put the lines needed for authentication either in .htaccess, ../cops/config_local.php or here. If you put them in .htaccess just delete them from this file.
b - edit where you put the .htpasswd file
c - with SetEnVif I set which log-line to put in the new log (not getJSON but /cops/ )
d - define what to put in the new log (LogFormat)
e - write the line to the log user.log [user time IP etc.]

3 - I edited /etc/apache2/sites-enabled/000-default.conf and added the line
Code:
		Include /etc/apache2/auth.*
which executes the auth.cops script when needed

/etc/apache2/sites-enabled/000-default.conf now looks like:
Code:
<VirtualHost *:80>

		ServerAdmin webmaster@localhost
		DocumentRoot /var/www/html

		ErrorLog ${APACHE_LOG_DIR}/error.log
		CustomLog ${APACHE_LOG_DIR}/access.log combined


		### Include (COPS) authorization code(s) ### 

		Include /etc/apache2/auth.*

		### End Include ###

	</VirtualHost>
4 - restart apache

5 - login and you see a new log file in /var/log/apache2/user.log
Strangely enough the content of this file in MInt is not 100% the same as in Debian. Debian adds a line with '-' as user. But it's no real problem.

With a cron job you could mail this log-file to yourself every day/week/month/etc

6 - todo: rotate the user log every month or so, depending on number of lines in the log.

Update: The OS (Linux Mint / Debian) uses some logrotate scripts and cronjobs that rotate the *.log files in /var/log/apache2/ . My new log file 'user.log' is in this map/directory so it will be included in the scheduled log rotation. Nothing to do here!



Greetz
Mario

Last edited by mariosipad; 02-03-2016 at 05:34 PM. Reason: Added an update for log rotate
mariosipad is offline   Reply With Quote