]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Create a user agent report if the input log provides the information
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 1 Nov 2015 15:23:30 +0000 (16:23 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 1 Nov 2015 15:23:30 +0000 (16:23 +0100)
An extended log can contain the user agent identification string. Sarg can
now use it to generate the user agent report.

The new user_agent type is added to report_type to generate a user agent
report. For compatibility with previous versions, that report type is
automatically selected if at least one file name is provided with the
useragent option.

getconf.c
include/conf.h
log.c
sarg.conf
useragent.c

index ee8bd0ecb0a020bcc5580e2db4185250e95bc9ea..8c3060a13e6d7392d43a878db219ca985a21664a 100644 (file)
--- a/getconf.c
+++ b/getconf.c
@@ -84,6 +84,7 @@ static struct param_list report_type_values[]=
        {"auth_failures",REPORT_TYPE_AUTH_FAILURES,0},
        {"site_user_time_date",REPORT_TYPE_SITE_USER_TIME_DATE,0},
        {"downloads",REPORT_TYPE_DOWNLOADS,0},
+       {"user_agent",REPORT_TYPE_USERAGENT,0},
 };
 
 static struct param_list data_field_values[]=
index 875804c2f75057bc40895357fd57df28abc6a152..c04196f3603c6489061c4adb11d62b1271b82a82 100644 (file)
@@ -197,6 +197,7 @@ Sarg will complain that there are too many days in the files if this limit is ov
 #define REPORT_TYPE_DENIED              0x0040UL
 #define REPORT_TYPE_AUTH_FAILURES       0x0080UL
 #define REPORT_TYPE_DOWNLOADS           0x0100UL
+#define REPORT_TYPE_USERAGENT           0x0200UL
 
 #define DATA_FIELD_USER      0x0001UL
 #define DATA_FIELD_DATE      0x0002UL
diff --git a/log.c b/log.c
index 9d4f11443480d015478d869293c667c7a9bf7f4c..d1170415c4b413370ff69e970bec987ae7f62e85 100644 (file)
--- a/log.c
+++ b/log.c
@@ -531,8 +531,11 @@ int main(int argc,char *argv[])
        if(ReportType == 0) {
                ReportType=REPORT_TYPE_TOPUSERS | REPORT_TYPE_TOPSITES | REPORT_TYPE_USERS_SITES |
                           REPORT_TYPE_SITES_USERS | REPORT_TYPE_DATE_TIME | REPORT_TYPE_DENIED |
-                          REPORT_TYPE_AUTH_FAILURES | REPORT_TYPE_SITE_USER_TIME_DATE | REPORT_TYPE_DOWNLOADS;
+                                  REPORT_TYPE_AUTH_FAILURES | REPORT_TYPE_SITE_USER_TIME_DATE |
+                                  REPORT_TYPE_DOWNLOADS | REPORT_TYPE_USERAGENT;
        }
+       if (!FileList_IsEmpty(UserAgentLog))
+               ReportType|=REPORT_TYPE_USERAGENT;
 
        if(access(ExcludeUsers, R_OK) == 0) {
                getuexclude(ExcludeUsers,debug);
index acb07345552556b39e35bec5196ce5249f85cacc..2c6b697667e431a04aaaf516e9fb8669dfdfd8bf 100644 (file)
--- a/sarg.conf
+++ b/sarg.conf
 #
 #       Wildcards are allowed (see access_log).
 #
+#       When this option is used the user_agent report is implicitly
+#       selected in report_type.
+#
 #useragent_log none
 
 # TAG:  date_format
 # TAG: report_type type
 #      What kind of reports to generate.
 #      topusers            - users, sites, times, bytes, connects, links to accessed sites, etc
-#      topsites                   - site, connect and bytes report
-#      sites_users        - users and sites report
-#      users_sites        - accessed sites by the user report
-#      date_time          - bytes used per day and hour report
-#      denied             - denied sites with full URL report
+#      topsites            - site, connect and bytes report
+#      sites_users         - users and sites report
+#      users_sites         - accessed sites by the user report
+#      date_time           - bytes used per day and hour report
+#      denied              - denied sites with full URL report
 #      auth_failures       - autentication failures report
 #      site_user_time_date - sites, dates, times and bytes report
 #      downloads           - downloads per user report
+#      user_agent          - user agent identification strings report (this report is always selected
+#                            if at least one file is provided with useragent option)
 #
 #      Eg.: report_type topsites denied
 #
-#report_type topusers topsites sites_users users_sites date_time denied auth_failures site_user_time_date downloads
+#report_type topusers topsites sites_users users_sites date_time denied auth_failures site_user_time_date downloads user_agent
 
 # TAG: usertab filename
 #      You can change the "userid" or the "ip address" to be a real user name on the reports.
index 53c5f4d275db335ffa81cbb9540d1ec8594f923f..11934204afd0a7d1a43a6cc4ff46df007a986067 100644 (file)
@@ -45,19 +45,21 @@ static struct tm UserAgentEndDate;
  */
 FILE *UserAgent_Open(void)
 {
-       FILE *fp_ou;
+       FILE *fp_ou=NULL;
 
        if (UserAgentTempLog[0]) {
                debuga(__FILE__,__LINE__,_("Useragent log already opened\n"));
                exit(EXIT_FAILURE);
        }
-       snprintf(UserAgentTempLog,sizeof(UserAgentTempLog),"%s/squagent.int_unsort",tmp);
-       if ((fp_ou=fopen(UserAgentTempLog,"w"))==NULL) {
-               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),UserAgentTempLog,strerror(errno));
-               exit(EXIT_FAILURE);
+       if ((ReportType & REPORT_TYPE_USERAGENT)!=0) {
+               snprintf(UserAgentTempLog,sizeof(UserAgentTempLog),"%s/squagent.int_unsort",tmp);
+               if ((fp_ou=fopen(UserAgentTempLog,"w"))==NULL) {
+                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),UserAgentTempLog,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+               memset(&UserAgentStartDate,0,sizeof(UserAgentStartDate));
+               memset(&UserAgentEndDate,0,sizeof(UserAgentEndDate));
        }
-       memset(&UserAgentStartDate,0,sizeof(UserAgentStartDate));
-       memset(&UserAgentEndDate,0,sizeof(UserAgentEndDate));
        return(fp_ou);
 }
 
@@ -71,8 +73,10 @@ FILE *UserAgent_Open(void)
  */
 void UserAgent_Write(FILE *fp,const char *Ip,const char *User,const char *Agent)
 {
-       fprintf(fp,"%s\t%s\t%s\n",Ip,Agent,User);
-       useragent_count++;
+       if (fp) {
+               fprintf(fp,"%s\t%s\t%s\n",Ip,Agent,User);
+               useragent_count++;
+       }
 }
 
 /*!
@@ -209,7 +213,7 @@ void UserAgent(void)
        double perc;
        struct getwordstruct gwarea;
 
-       if (!UserAgentTempLog[0]) return;
+       if (!UserAgentTempLog[0] || useragent_count==0) return;
 
        snprintf(tmp2,sizeof(tmp2),"%s/squagent.int_log",tmp);
        if (debug) {