see also http://hplyot.obspm.fr/~dl/wwwtools.html diff -urN httpd_1.4.1/README.more_log httpd_1.4.1_dl/README.more_log --- httpd_1.4.1/README.more_log Thu Jan 1 01:00:00 1970 +++ httpd_1.4.1_dl/README.more_log Mon May 29 03:40:20 1995 @@ -0,0 +1,25 @@ + + Hi, This patch originally allowed to add to the NCSA httpd 1.3 log file + the "Referer" and/or "User-Agent" fields. (This allow you to track + down user agent statistics and where your pages are refered (and to + send correction in case of errors,...)). + + These features have been added to regular 1.4, but using separate + unsynched files, so i ported my previous 1.3 patch to keep the same + features for 1.4 + + This patches now applies to v1.4.1 (apache version might come + if ppl are interested). Latest version and infos on + http://hplyot.obspm.fr/~dl/wwwtools.html + + Regards, + May 29th 1995 - dl + + Note : using -DLOG_USER_AGENT and -DLOG_REFERER *replace* the ncsa 1.4 + logging by mine. (ie no more separate log files) + + Ps : mail me (dl@hplyot.obspm.fr) for comments, suggestions,... + also If you make scripts to exploit these new data. + +-- + Laurent Demailly diff -urN httpd_1.4.1/cgi-bin/test-cgi.tcl httpd_1.4.1_dl/cgi-bin/test-cgi.tcl --- httpd_1.4.1/cgi-bin/test-cgi.tcl Thu May 18 06:00:14 1995 +++ httpd_1.4.1_dl/cgi-bin/test-cgi.tcl Mon May 29 03:25:15 1995 @@ -3,7 +3,9 @@ # robert.bagwill@nist.gov, no warranty, no rights reserved # print out command line args, stdin, and environment variables # -# some fixes by dl@hplyot.obspm.fr - v1.1 - Apr 11 1995 +# some fixes by dl@hplyot.obspm.fr - v1.2 - May 20 1995 +# +# better get test-cgi2.tcl from http://hplyot.obspm.fr/~dl/wwwtools.html # set envvars {SERVER_SOFTWARE SERVER_NAME GATEWAY_INTERFACE SERVER_PROTOCOL SERVER_PORT REQUEST_METHOD PATH_INFO PATH_TRANSLATED SCRIPT_NAME QUERY_STRING REMOTE_HOST REMOTE_ADDR REMOTE_USER AUTH_TYPE CONTENT_TYPE CONTENT_LENGTH HTTP_ACCEPT HTTP_REFERER HTTP_USER_AGENT} @@ -42,7 +44,6 @@ foreach var $envvars { if {[info exists env($var)]} { puts "
$var
$env($var)" - } } } puts "" diff -urN httpd_1.4.1/src/Makefile httpd_1.4.1_dl/src/Makefile --- httpd_1.4.1/src/Makefile Thu May 18 06:31:59 1995 +++ httpd_1.4.1_dl/src/Makefile Mon May 29 03:54:13 1995 @@ -19,7 +19,13 @@ # If you want to ensure that CGI scripts can't mess with the log files, # use -DSECURE_LOGS # -CFLAGS= -O2 -g -DNO_PASS + +# To add referer and/or user_agent infos to the main log, use : +# -DLOG_REFERER -DLOG_USER_AGENT +# ( instead of separated log file -- dl@hplyot.obspm.fr ) +CFLAGS= -O2 -DLOG_REFERER -DLOG_USER_AGENT + +#CFLAGS= -O2 -g -DNO_PASS #CFLAGS= -g -Wall -ansi -pedantic # Place here any extra libraries you may need to link to. You @@ -44,9 +50,9 @@ # AUX_CFLAGS= -DIRIX # EXTRA_LIBS= -lsun # For HP-UX -# AUX_CFLAGS= -DHPUX +AUX_CFLAGS= -DHPUX # For AIX - AUX_CFLAGS= -DAIX -U__STR__ +# AUX_CFLAGS= -DAIX -U__STR__ # For Ultrix # AUX_CFLAGS= -DULTRIX # For DEC OSF/1 diff -urN httpd_1.4.1/src/http_config.c httpd_1.4.1_dl/src/http_config.c --- httpd_1.4.1/src/http_config.c Thu May 18 06:11:34 1995 +++ httpd_1.4.1_dl/src/http_config.c Sun May 28 23:34:22 1995 @@ -30,8 +30,12 @@ char server_root[MAX_STRING_LEN]; char error_fname[MAX_STRING_LEN]; char xfer_fname[MAX_STRING_LEN]; +#ifndef LOG_USER_AGENT char agent_fname[MAX_STRING_LEN]; +#endif +#ifndef LOG_REFERER char referer_fname[MAX_STRING_LEN]; +#endif char referer_ignore[MAX_STRING_LEN]; char pid_fname[MAX_STRING_LEN]; char server_admin[MAX_STRING_LEN]; @@ -68,8 +72,12 @@ /* ServerRoot set in httpd.c */ make_full_path(server_root,DEFAULT_ERRORLOG,error_fname); make_full_path(server_root,DEFAULT_XFERLOG,xfer_fname); +#ifndef LOG_USER_AGENT make_full_path(server_root,DEFAULT_AGENTLOG,agent_fname); +#endif +#ifndef LOG_REFERER make_full_path(server_root,DEFAULT_REFERERLOG,referer_fname); +#endif make_full_path(server_root,DEFAULT_PIDLOG,pid_fname); strcpy(referer_ignore,DEFAULT_REFERERIGNORE); strcpy(server_admin,DEFAULT_ADMIN); @@ -143,8 +151,12 @@ strcpy(server_root,w); make_full_path(server_root,DEFAULT_ERRORLOG,error_fname); make_full_path(server_root,DEFAULT_XFERLOG,xfer_fname); +#ifndef LOG_USER_AGENT make_full_path(server_root,DEFAULT_AGENTLOG,agent_fname); +#endif +#ifndef LOG_REFERER make_full_path(server_root,DEFAULT_REFERERLOG,referer_fname); +#endif make_full_path(server_root,DEFAULT_PIDLOG,pid_fname); make_full_path(server_root,RESOURCE_CONFIG_FILE,srm_confname); make_full_path(server_root,ACCESS_CONFIG_FILE,access_confname); @@ -165,15 +177,19 @@ } else if(!strcasecmp(w,"AgentLog")) { cfg_getword(w,l); +#ifndef LOG_USER_AGENT if(w[0] != '/') make_full_path(server_root,w,agent_fname); else strcpy(agent_fname,w); +#endif } else if(!strcasecmp(w,"RefererLog")) { cfg_getword(w,l); +#ifndef LOG_REFERER if(w[0] != '/') make_full_path(server_root,w,referer_fname); else strcpy(referer_fname,w); +#endif } else if(!strcasecmp(w,"RefererIgnore")) { cfg_getword(w,l); diff -urN httpd_1.4.1/src/http_log.c httpd_1.4.1_dl/src/http_log.c --- httpd_1.4.1/src/http_log.c Thu May 18 06:00:22 1995 +++ httpd_1.4.1_dl/src/http_log.c Sun May 28 23:34:22 1995 @@ -51,13 +51,18 @@ static int xfer_log; static int xfer_flags = ( O_WRONLY | O_APPEND | O_CREAT ); static mode_t xfer_mode = ( S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); +#ifndef LOG_USER_AGENT FILE *agent_log; +#endif +#ifdef LOG_REFERER +extern char referer_ignore[MAX_STRING_LEN]; +#else FILE *referer_log; +#endif int ErrorStat=0; ErrorMessage Errors[NUM_ERRORS]; int numErrorsDefined=0; extern int servernum; -extern char referer[]; extern char *save_name; void open_logs() { @@ -74,41 +79,50 @@ perror("open"); exit(1); } +#ifndef LOG_USER_AGENT if(!(agent_log = fopen(agent_fname,"a"))) { fprintf(stderr,"httpd: could not open agent log file %s.\n", agent_fname); perror("fopen"); exit(1); } +#endif +#ifndef LOG_REFERER if(!(referer_log = fopen(referer_fname,"a"))) { fprintf(stderr,"httpd: could not open referer log file %s.\n", referer_fname); perror("fopen"); exit(1); } +#endif #ifdef SECURE_LOGS /* set close-on-exec flag so CGI's cannot get to logs */ flags = fcntl(xfer_log, F_GETFD); flags |= FD_CLOEXEC; fcntl(xfer_log, F_SETFD, flags); +#ifndef LOG_USER_AGENT flags = fcntl(fileno(agent_log), F_GETFD); flags |= FD_CLOEXEC; fcntl(fileno(agent_log), F_SETFD, flags); +#endif +#ifndef LOG_REFERER flags = fcntl(fileno(referer_log), F_GETFD); flags |= FD_CLOEXEC; fcntl(fileno(referer_log), F_SETFD, flags); +#endif #endif /* SECURE_LOGS */ } void close_logs() { - fflush(error_log); - fflush(agent_log); - fflush(referer_log); close(xfer_log); fclose(error_log); +#ifndef LOG_USER_AGENT fclose(agent_log); +#endif +#ifndef LOG_REFERER fclose(referer_log); +#endif } void error_log2stderr() { @@ -162,9 +176,31 @@ strcat(str,"- "); if(bytes_sent != -1) - sprintf(str,"%s%d\n",str,bytes_sent); + sprintf(str,"%s%d",str,bytes_sent); else - strcat(str,"-\n"); + strcat(str,"-"); + +/* Add referer and/or user_agent infos to the main log -- dl */ +#ifdef LOG_REFERER + if (referer[0] && + ( (referer_ignore[0]=='\0') || (!strstr(referer,referer_ignore)) ) ) + sprintf(str,"%s \"%s\"",str,referer); + else + strcat(str," \"\""); +#endif + +#ifdef LOG_USER_AGENT +#ifndef LOG_REFERER + strcat(str," \"\""); /* user_agent is always +2 (+1 for referer) */ +#endif + if (user_agent[0]) + sprintf(str,"%s \"%s\"\n",str,user_agent); + else + strcat(str," \"\"\n"); +#else + strcat(str,"\n"); +#endif + /* sprintf(str,"%s SN:%d",str,servernum); fprintf(xfer_log,"%s\n",str); fflush(xfer_log); */ diff -urN httpd_1.4.1/src/http_mime.c httpd_1.4.1_dl/src/http_mime.c --- httpd_1.4.1/src/http_mime.c Thu May 18 06:00:23 1995 +++ httpd_1.4.1_dl/src/http_mime.c Sun May 28 23:34:23 1995 @@ -53,10 +53,21 @@ char *status_line = NULL; char ims[MAX_STRING_LEN]; /* If-modified-since */ +#ifndef LOG_USER_AGENT extern FILE *agent_log; +#endif +#ifndef LOG_REFERER extern FILE *referer_log; +#endif extern char referer_ignore[MAX_STRING_LEN]; -char referer[HUGE_STRING_LEN]; + +/* MAX_ is enough for Referer */ +char referer[MAX_STRING_LEN]; +/* if we use my logging method : -- dl */ +#ifdef LOG_USER_AGENT +char user_agent[MAX_STRING_LEN]; +#endif + void hash_insert(struct mime_ext *me) { register int i = hash(me->ext[0]); @@ -407,6 +418,10 @@ void init_header_vars() { +/* To add user_agent infos to the log, we need : -- dl */ +#ifdef LOG_USER_AGENT + user_agent[0] = '\0' ; +#endif referer[0] = '\0'; content_type[0] = '\0'; last_modified[0] = '\0'; @@ -483,15 +498,26 @@ continue; } if(!strcasecmp(w,"User-agent")) { - fprintf(agent_log, "%s\n", l); - fflush(agent_log); +#ifdef LOG_USER_AGENT + /* lets copy the user-agent (my method) */ + strcpy(user_agent,l); +#else + /* NCSA's method : */ + fprintf(agent_log, "%s\n", l); + fflush(agent_log); +#endif } if(!strcasecmp(w,"Referer")) { - strcpy(referer,l); - if ((!strlen(referer_ignore)) || (!strstr(l,referer_ignore))){ - fprintf(referer_log, "%s -> %s\n", l, url); - fflush(referer_log); - } + strcpy(referer,l); +/* if not dl's method : */ +#ifndef LOG_REFERER + /* NCSA's method : */ +/* in my method :(the referer_ignore test is done when logging (http_log.c)*/ + if ((!strlen(referer_ignore)) || (!strstr(l,referer_ignore))){ + fprintf(referer_log, "%s -> %s\n", l, url); + fflush(referer_log); + } +#endif } if(!strcasecmp(w,"If-modified-since")) strcpy(ims,l); diff -urN httpd_1.4.1/src/http_request.c httpd_1.4.1_dl/src/http_request.c --- httpd_1.4.1/src/http_request.c Thu May 18 06:12:08 1995 +++ httpd_1.4.1_dl/src/http_request.c Mon May 29 04:23:35 1995 @@ -65,7 +65,7 @@ /* if (remote_ip) free(remote_ip); */ if (remote_name) { free(remote_name); - remote_host = NULL; + remote_name = NULL; /* fix From: Eric Mumpower (nocturne@mit.edu) */ } #if defined(NeXT) || defined(__mc68000__) longjmp(jmpbuffer,1); diff -urN httpd_1.4.1/src/httpd.h httpd_1.4.1_dl/src/httpd.h --- httpd_1.4.1/src/httpd.h Thu May 18 06:55:31 1995 +++ httpd_1.4.1_dl/src/httpd.h Mon May 29 03:32:02 1995 @@ -425,7 +425,7 @@ /* ------------------------------ error types ------------------------------ */ -#define SERVER_VERSION "NCSA/1.4.1" +#define SERVER_VERSION "NCSA/1.4.1+dl" #define SERVER_PROTOCOL "HTTP/1.0" #define SERVER_SUPPORT "httpd@void.ncsa.uiuc.edu" @@ -566,8 +566,12 @@ extern char annotation_server[MAX_STRING_LEN]; /* SSG 4/4/95 */ extern char error_fname[MAX_STRING_LEN]; extern char xfer_fname[MAX_STRING_LEN]; +#ifndef LOG_USER_AGENT extern char agent_fname[MAX_STRING_LEN]; +#endif +#ifndef LOG_REFERER extern char referer_fname[MAX_STRING_LEN]; +#endif extern char pid_fname[MAX_STRING_LEN]; extern char server_admin[MAX_STRING_LEN]; extern char *server_hostname; @@ -619,6 +623,11 @@ /* MIME */ extern char auth_line[MAX_STRING_LEN]; +/* To add referer and/or user_agent infos to the log, we need : -- dl */ +extern char referer[MAX_STRING_LEN]; +#ifdef LOG_USER_AGENT +extern char user_agent[MAX_STRING_LEN]; +#endif extern int content_length; extern char content_type[MAX_STRING_LEN]; extern char content_encoding[MAX_STRING_LEN];