summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG16
-rw-r--r--INSTALL33
-rw-r--r--Makefile56
-rw-r--r--mod_log_sql.c15
4 files changed, 69 insertions, 51 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5479725..7d9fba0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,13 +1,27 @@
1$Id: CHANGELOG,v 1.4 2001/12/07 03:52:56 helios Exp $ 1$Id: CHANGELOG,v 1.5 2002/01/15 18:40:14 helios Exp $
2 2
3 3
4TODO: 4TODO:
5* Full commenting of the code. 5* Full commenting of the code.
6* Rethink documentation flow and rewrite? 6* Rethink documentation flow and rewrite?
7* Message queueing during server downtime?
7 8
8 9
9CHANGES: 10CHANGES:
10 11
121.13:
13
14* Now use ap_get_server_name() in extract_virtual_host() to fix the
15 instances where mass-virtual-hosting sites were getting the wrong
16 server-name written to the log.
17* Now use mysql_real_connect() instead of mysql_connect(). The
18 latter's use was deprecated and did not work in MySQL 4.
19* There is now a DEFINE for the socket name. This is used by the
20 mysql_real_connect() function and is relevant only if the db resides
21 on localhost. It is irrelevant if the db resides on a networked
22 machine and is ignored in that case (although it still must be defined
23 for the connect to work).
24
111.12: 251.12:
12 26
13* Added a mysql_close() call to get rid of those annoying MySQL 27* Added a mysql_close() call to get rid of those annoying MySQL
diff --git a/INSTALL b/INSTALL
index 86807a2..7f2e061 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,4 +1,4 @@
1$Id: INSTALL,v 1.3 2002/01/02 20:47:44 helios Exp $ 1$Id: INSTALL,v 1.4 2002/01/15 18:40:14 helios Exp $
2 2
3 3
4Requirements 4Requirements
@@ -31,10 +31,7 @@ Requirements
31Installation (as an Apache DSO) 31Installation (as an Apache DSO)
32=============================== 32===============================
33 33
34For folks interested in using this module as an Apache DSO, these 34For folks interested in using this module as an Apache DSO:
35instructions are currently UNTESTED but should work. (I would be
36grateful to hear back from a DSO user as to my accuracy with these
37instructions.)
38 35
390) Perform all the following steps as root so that you have install 360) Perform all the following steps as root so that you have install
40 privs, etc. 37 privs, etc.
@@ -44,7 +41,10 @@ instructions.)
44 # tar zxf mod_log_mysql.tar.gz -C /usr/local/src 41 # tar zxf mod_log_mysql.tar.gz -C /usr/local/src
45 # cd /usr/local/src/mod_log_mysql 42 # cd /usr/local/src/mod_log_mysql
46 43
472) Instruct apxs to compile and install the module as a DSO. You need 442) Edit Makefile and make any adjustments for your system. These are
45 fully explained in the Makefile.
46
473) Instruct apxs to compile and install the module as a DSO. You need
48 to know two things before you run apxs: 48 to know two things before you run apxs:
49 - The location of the apxs binary, find using 'locate apxs' 49 - The location of the apxs binary, find using 'locate apxs'
50 - The location of your MySQL libraries, find using 'locate libmysqlclient' 50 - The location of your MySQL libraries, find using 'locate libmysqlclient'
@@ -57,13 +57,14 @@ instructions.)
57 ld -Bshareable -o mod_log_mysql.so mod_log_mysql.o 57 ld -Bshareable -o mod_log_mysql.so mod_log_mysql.o
58 cp mod_log_mysql.so <your path to Apache libexec>/mod_log_mysql.so 58 cp mod_log_mysql.so <your path to Apache libexec>/mod_log_mysql.so
59 chmod 755 <your path to Apache libexec>/mod_log_mysql.so 59 chmod 755 <your path to Apache libexec>/mod_log_mysql.so
60 [activating module foo' in /path/to/apache/etc/httpd.conf] 60 [activating module blah in /path/to/apache/etc/httpd.conf]
61 61
623) Now go to step (9) in the instructions below to configure httpd.conf... 624) Now go to step (9) in the instructions below to configure httpd.conf...
63 63
64 64
65Installation (as a static module compiled into httpd) 65Installation (as a static module compiled into httpd)
66===================================================== 66=====================================================
67
67[This is what I do, FYI.] 68[This is what I do, FYI.]
68 69
690) Perform all the following steps as root so that you have install 700) Perform all the following steps as root so that you have install
@@ -74,10 +75,8 @@ Installation (as a static module compiled into httpd)
74 # tar zxf mod_log_mysql.tar.gz -C /usr/local/src 75 # tar zxf mod_log_mysql.tar.gz -C /usr/local/src
75 # cd /usr/local/src/mod_log_mysql 76 # cd /usr/local/src/mod_log_mysql
76 77
772) Edit Makefile and make any adjustments for your system: make sure 782) Edit Makefile and make any adjustments for your system. These are
78 that APACHEDIR points to the location of your Apache source code, 79 fully explained in the Makefile.
79 and that CFLAGS points to the location of your Apache installation
80 directory (where your httpd binary lives).
81 80
823) # make all 813) # make all
83 (You should receive NO warnings or errors of any kind. 82 (You should receive NO warnings or errors of any kind.
@@ -133,8 +132,8 @@ Installation (as a static module compiled into httpd)
133 # cp -f ./httpd /usr/local/Apache/bin/ 132 # cp -f ./httpd /usr/local/Apache/bin/
134 133
1359) Configure your apache daemon to log to your database. Here's a very 1349) Configure your apache daemon to log to your database. Here's a very
136 basic set of config lines to start you off. Full docs on them are 135 basic set of config lines to start you off. Full documentation is
137 included after this section. 136 available here: http://www.grubbybaby.com/mod_log_mysql/directives.html
138 137
139 EXAMPLE: Connect to the MySQL database called "apache" running 138 EXAMPLE: Connect to the MySQL database called "apache" running
140 on "dbmachine.foo.com". The module uses username "loguser" and 139 on "dbmachine.foo.com". The module uses username "loguser" and
@@ -157,7 +156,7 @@ Installation (as a static module compiled into httpd)
157 </VirtualHost> 156 </VirtualHost>
158 157
159 158
160 9a) For users who have a DSO-enabled httpd: 159 9a) Special step for users who have a DSO-enabled httpd:
161 160
162 If you you are building mod_log_mysql as a static module BUT 161 If you you are building mod_log_mysql as a static module BUT
163 your httpd is enabled for DSOs, add the following line to your 162 your httpd is enabled for DSOs, add the following line to your
@@ -186,9 +185,9 @@ Installation (as a static module compiled into httpd)
186 mysql> source access_log.sql 185 mysql> source access_log.sql
187 186
188 187
18911) Create a specific mysql userid that httpd will use to authenticate 18811) Create a specific MySQL userid that httpd will use to authenticate
190 and enter data. This userid need not be an actual Unix user. It 189 and enter data. This userid need not be an actual Unix user. It
191 is a userid specific to mysql with specific privileges. To create a 190 is a userid internal to MySQL with specific privileges. To create a
192 user called "loguser" with the password "l0gger" with only the 191 user called "loguser" with the password "l0gger" with only the
193 capability of INSERT to "access_log": 192 capability of INSERT to "access_log":
194 193
diff --git a/Makefile b/Makefile
index 5744be4..65e0cd5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,37 +1,47 @@
1# $Id: Makefile,v 1.4 2001/12/07 03:52:56 helios Exp $ 1# $Id: Makefile,v 1.5 2002/01/15 18:40:14 helios Exp $
2MLMVERS = 1.13
2 3
3# Verify that this points to the right place... 4# Where you unpacked your Apache tarball -- the source.
4APACHEDIR = /usr/local/src/apache_1.3.22 5APACHESOURCE = /usr/local/src/apache_1.3.22
5 6
6# Use the first one if you want mod_log_mysql to be able to log 7# Where Apache [got|will get] installed
7# SSL variables like keysize or cipher. Use the second one if 8APACHEINST = /usr/local/Apache
8# you don't use SSL or don't care to log it.
9DEFS = -DWANT_SSL_LOGGING
10#DEFS =
11 9
12# Use this one if you do WANT_SSL_LOGGING, and confirm the last three paths. 10# Use the first DEFS line if you want mod_log_mysql to be able to log SSL
13# Point "/usr/local/ssl/include" to where your openssl/*.h files are, 11# variables like keysize or cipher. Use the second one if you don't use SSL
14# Point "/usr/include/db1" to where ndbm.h can be found, 12# or don't care to log it.
15# Point "/usr/local/src/apache_1.3.22/src/modules/ssl" to where mod_ssl.h can be found.
16# 13#
17# How to find your directories: 14# If your MySQL db is running on the same machine as Apache, modify the
15# MYSQLSOCKET path to point to your MySQL socket. This define has no effect
16# if your MySQL machine is a networked (TCP/IP) machine.
17
18DEFS = -DMYSQLSOCKET="\"/var/lib/mysql/mysql.sock\"" -DWANT_SSL_LOGGING
19#DEFS = -DMYSQLSOCKET="\"/var/lib/mysql/mysql.sock\""
20
21# Use the first CFLAGS if you *do* WANT_SSL_LOGGING, and confirm the paths.
18# 22#
19# $ locate http_core.h 23# Modify "/usr/local/ssl/include" to where YOUR openssl/*.h files are,
20# /usr/local/Apache/include/http_core.h 24# Modify "/usr/include/db1" to where YOUR ndbm.h can be found,
25# Modify "/usr/local/src/apache_1.3.22/src/modules/ssl" to where YOUR mod_ssl.h can be found.
26#
27# How to find your directories:
21# 28#
22# $ locate x509.h 29# $ locate x509.h
23# /usr/local/ssl/include/openssl/x509.h 30# /usr/local/ssl/include/openssl/x509.h
31# ^^^^^^^^^^^^^^^^^^^^^^
24# 32#
25# $ locate ndbm.h 33# $ locate ndbm.h
26# /usr/include/db1/ndbm.h 34# /usr/include/db1/ndbm.h
35# ^^^^^^^^^^^^^^^^
27# 36#
28# $ locate mod_ssl.h 37# $ locate mod_ssl.h
29# /usr/local/src/apache_1.3.22/src/modules/ssl/mod_ssl.h 38# /usr/local/src/apache_1.3.22/src/modules/ssl/mod_ssl.h
39# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30 40
31CFLAGS = -fpic -O2 -Wall -I/usr/local/Apache/include -I/usr/local/ssl/include -I/usr/include/db1 -I/usr/local/src/apache_1.3.22/src/modules/ssl 41CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include -I/usr/local/ssl/include -I/usr/include/db1 -I${APACHESOURCE}/src/modules/ssl
32 42
33# Use this one if you don't WANT_SSL_LOGGING: 43# Use this CFLAGS if you don't WANT_SSL_LOGGING:
34#CFLAGS = -fpic -O2 -Wall -I/usr/local/Apache/include 44#CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include
35 45
36 46
37# --------------------------------------------------------- 47# ---------------------------------------------------------
@@ -46,13 +56,13 @@ mod_log_mysql.o: mod_log_mysql.c Makefile
46 $(CC) ${CFLAGS} ${DEFS} -c mod_log_mysql.c 56 $(CC) ${CFLAGS} ${DEFS} -c mod_log_mysql.c
47 57
48install: all 58install: all
49 $(INSTALL) mod_log_mysql.o ${APACHEDIR}/src/mod_log_mysql.o 59 $(INSTALL) mod_log_mysql.o ${APACHESOURCE}/src/mod_log_mysql.o
50 60
51distro: all 61distro: all
52 cp -f INSTALL /usr/local/Apache/html/mod_log_mysql/ 62 cp -f INSTALL ${APACHEINST}/html/mod_log_mysql/
53 cp -f README /usr/local/Apache/html/mod_log_mysql/ 63 cp -f README ${APACHEINST}/html/mod_log_mysql/
54 cp -f CHANGELOG /usr/local/Apache/html/mod_log_mysql/ 64 cp -f CHANGELOG ${APACHEINST}/html/mod_log_mysql/
55 cd ..; tar zcf mod_log_mysql.tar.gz --exclude mod_log_mysql/CVS mod_log_mysql/; $(INSTALL) mod_log_mysql.tar.gz /usr/local/Apache/html/mod_log_mysql/; rm -f mod_log_mysql.tar.gz 65 cd ..; tar zcf mod_log_mysql-${MLMVERS}.tar.gz --exclude mod_log_mysql/CVS mod_log_mysql/; $(INSTALL) mod_log_mysql-${MLMVERS}.tar.gz ${APACHEINST}/html/mod_log_mysql/; rm -f mod_log_mysql-${MLMVERS}.tar.gz
56 66
57clean: 67clean:
58 rm -f *.o *~ 68 rm -f *.o *~
diff --git a/mod_log_sql.c b/mod_log_sql.c
index efbf45c..6780b74 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -1,11 +1,11 @@
1/* $Id: mod_log_sql.c,v 1.4 2001/12/07 03:52:56 helios Exp $ */ 1/* $Id: mod_log_sql.c,v 1.5 2002/01/15 18:40:14 helios Exp $ */
2 2
3 3
4/* DEFINES */ 4/* DEFINES */
5#define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away") 5#define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away")
6#define ERRLEVEL APLOG_ERR|APLOG_NOERRNO 6#define ERRLEVEL APLOG_ERR|APLOG_NOERRNO
7#define DEBUGLEVEL APLOG_INFO|APLOG_NOERRNO 7#define DEBUGLEVEL APLOG_INFO|APLOG_NOERRNO
8/* (DEBUG and WANT_SSL_LOGGING are defined in the Makefile DEFS line.) */ 8/* (MYSQLSOCKET, DEBUG and WANT_SSL_LOGGING are defined in the Makefile DEFS line.) */
9 9
10 10
11 11
@@ -245,7 +245,7 @@ static const char *extract_request_duration(request_rec *r, char *a)
245 245
246static const char *extract_virtual_host(request_rec *r, char *a) 246static const char *extract_virtual_host(request_rec *r, char *a)
247{ 247{
248 return pstrdup(r->pool, r->server->server_hostname); 248 return ap_get_server_name(r);
249} 249}
250 250
251static const char *extract_server_port(request_rec *r, char *a) 251static const char *extract_server_port(request_rec *r, char *a)
@@ -469,13 +469,8 @@ void open_logdb_link()
469 return; 469 return;
470 } 470 }
471 if (db_name) { /* open an SQL link */ 471 if (db_name) { /* open an SQL link */
472 mysql_log = mysql_connect(&sql_server, db_host, db_user, db_pwd); 472 mysql_init(&sql_server);
473 if (mysql_log) { /* link opened */ 473 mysql_log = mysql_real_connect(&sql_server, db_host, db_user, db_pwd, db_name, 0, MYSQLSOCKET, 0);
474 if (mysql_select_db(mysql_log, db_name) != 0) { /* unable to select database */
475 mysql_close(mysql_log);
476 mysql_log = NULL;
477 }
478 }
479 } 474 }
480} 475}
481 476