struct userfilestruct *ufile1;
struct ReadLogStruct log_entry;
struct LogLineStruct log_line;
+ FILE *UseragentLog=NULL;
LogLine_Init(&log_line);
LogLine_File(&log_line,arq);
denied_write(&log_entry);
authfail_write(&log_entry);
if (download_flag) download_write(&log_entry,download_url);
+ if (log_entry.UserAgent)
+ {
+ if (!UseragentLog)
+ UseragentLog=UserAgent_Open();
+ UserAgent_Write(UseragentLog,log_entry.Ip,log_entry.User,log_entry.UserAgent);
+ }
if (log_line.current_format!=&ReadSargLog) {
if (period.start.tm_year==0 || idata<mindate || compare_date(&period.start,&log_entry.EntryTime)>0){
debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),arq,FileObject_GetLastCloseError());
exit(EXIT_FAILURE);
}
+ if (UseragentLog) fclose(UseragentLog);
if (ShowReadStatistics) {
if (ShowReadPercent)
printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs2, (float) 100 );
EXTCOL_Path,
EXTCOL_Query,
EXTCOL_Status,
+ EXTCOL_UserAgent,
EXTCOL_Last //last entry of the list !
};
if (strncasecmp(columns,"cs-uri-query",len)==0) col_id=EXTCOL_Query;
} else if (len==13) {
if (strncasecmp(columns,"cs-uri-scheme",len)==0) col_id=EXTCOL_Scheme;
+ } else if (len==14) {
+ if (strncasecmp(columns,"cs(User-Agent)",len)==0) col_id=EXTCOL_UserAgent;
}
if (col_id!=EXTCOL_Last) {
ExtCols[col_id]=col;
static char *ExtLog_GetString(char *Line,int col,char **End)
{
bool quote;
- bool dequote;
//skip opening double quote
quote=(*Line=='\"');
if (quote) ++Line;
- dequote=false;
while (*Line) {
if (quote) {
if (*Line=='\"') {
- if (Line[1]!='\"') {
- if (End) *End=(dequote) ? NULL : Line;
- Line++;//skip the closing quote
+ if (Line[1]=='\"') {
+ Line++;//skip the first quote here, the second is skipped by the other Line++
+ } else {
+ if (End) *End=Line;
+ Line++;//skip closing quote
quote=false;
break;
}
- dequote=true;
}
} else {
if (*Line==ExtColSep[col]) {
char *dest;
if (!string) return;//string not parsed
- if (end_ptr) { //end is known and no quotes are in the string
+ if (*string!='\"' && end_ptr) { //no quotes to remove from the string
*end_ptr='\0';
return;
}
- // remove the quotes and end at the first unremoveable quote
+
+ // remove first quote
dest=string;
+ if (string[1]!='\"') string++;
+
+ // remove the quotes and end at the first unremoveable quote
while (*string)
{
if (*string=='\"') {
char *UrlPort=NULL,*UrlPortEnd;
char *UrlPath=NULL,*UrlPathEnd;
char *UrlQuery=NULL,*UrlQueryEnd;
+ char *UserAgent=NULL,*UserAgentEnd;
// is it a directive
if (*Line=='#') {
Line=ExtLog_GetString(Line,col,&HttpCodeEnd);
if (!Line) return(RLRC_Unknown);
break;
+ case EXTCOL_UserAgent:
+ UserAgent=Line;
+ Line=ExtLog_GetString(Line,col,&UserAgentEnd);
+ if (!Line) return(RLRC_Unknown);
+ break;
case EXTCOL_Last://ignored column
Line=ExtLog_GetString(Line,col,NULL);
if (!Line) return(RLRC_Unknown);
ExtLog_FixString(UrlQuery,UrlQueryEnd);
Entry->Url=ExtLog_ConcatUrl(UrlScheme,UrlHost,UrlPort,UrlPath,UrlQuery);
}
+ ExtLog_FixString(UserAgent,UserAgentEnd);
+ Entry->UserAgent=ExtLog_FixEmptyString(UserAgent);
return(RLRC_NoError);
}
extern struct globalstatstruct globstat;
extern bool smartfilter;
-extern FileListObject UserAgentLog;
/*!
Save the total number of users. The number is written in sarg-users and set
if (is_denied()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",_("Denied accesses"));
if (is_authfail()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",_("Authentication Failures"));
if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"smartfilter.html\">%s</a></td></tr>\n",_("SmartFilter"));
- if (!FileList_IsEmpty(UserAgentLog) && useragent_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"useragent.html\">%s</a></td></tr>\n",_("Useragent"));
+ if (useragent_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"useragent.html\">%s</a></td></tr>\n",_("Useragent"));
fputs("<tr><td></td></tr>\n</table></div>\n",fp_top3);
}