In both cases, the sorted files are written in files with the extension \c log and the name of the unsorted
file without the \c unsort extension. The unsorted file is deleted just after the sorting.
*/
+
+
+
+
+
+/*! \fn void sort_labels(const char **label,const char **order)
+Get the internationalized text to display when reporting the sort criterion and order
+of a user list.
+
+\param label A pointer to set to the string of the sort criterion name.
+\param order A pointer to set to the string of the sort order name
+*/
unsigned long int exclude;
};
+struct sort_list
+{
+ //! The name of the value of the parameter.
+ const char *name;
+ //! The bit to set if the value is found.
+ unsigned long int value;
+};
+
static struct param_list report_type_values[]=
{
{"users_sites",REPORT_TYPE_USERS_SITES,0},
{"ignore",REALTIME_UNAUTH_REC_IGNORE,~REALTIME_UNAUTH_REC_IGNORE},
};
+struct sort_list topuser_sort[]=
+{
+ {"BYTES",TOPUSER_SORT_BYTES},
+ {"USER",TOPUSER_SORT_USER},
+ {"CONNECT",TOPUSER_SORT_CONNECT},
+ {"TIME",TOPUSER_SORT_TIME},
+};
+
+struct sort_list topsite_sort[]=
+{
+ {"BYTES",TOPSITE_SORT_BYTES},
+ {"CONNECT",TOPSITE_SORT_CONNECT},
+};
+
+struct sort_list user_sort[]=
+{
+ {"BYTES",USER_SORT_BYTES},
+ {"SITE",USER_SORT_SITE},
+ {"CONNECT",USER_SORT_CONNECT},
+ {"TIME",USER_SORT_TIME},
+};
+
static int is_param(const char *param,const char *buf)
{
int plen;
return(1);
}
+static int getparam_sort(const char *param,struct sort_list *options,int noptions,char *buf,unsigned long int *value)
+{
+ int plen;
+ char *str, *order;
+ int i;
+
+ plen=strlen(param);
+ if (strncmp(buf,param,plen) != 0) return(0);
+ buf+=plen;
+ if ((unsigned char)*buf>' ') return(0);
+ while (*buf && (unsigned char)*buf<=' ') buf++;
+
+ str=buf;
+ order=NULL;
+ while (*str && (unsigned char)*str>' ') str++;
+ if (*str) {
+ *str++='\0';
+ while (*str && (unsigned char)*str<=' ') str++;
+ order=str;
+ }
+ for (i=0 ; i<noptions && strcasecmp(buf,options[i].name) ; i++);
+ if (i>=noptions) {
+ debuga(_("Unknown sort criterion \"%s\" for parameter \"%s\"\n"),buf,param);
+ exit(EXIT_FAILURE);
+ }
+ *value|=options[i].value;
+
+ if (order) {
+ str=order;
+ while (*str && (unsigned char)*str>' ') str++;
+ if (*str) {
+ *str++='\0';
+ while (*str && (unsigned char)*str<=' ') str++;
+ }
+ if (strcasecmp(order,"reverse")==0 || strcasecmp(order,"D")==0) {
+ *value|=SORT_REVERSE;
+ } else if (strcasecmp(order,"normal")!=0 && strcasecmp(order,"A")!=0) {
+ debuga(_("Unknown sort order \"%s\" for parameter \"%s\"\n"),order,param);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ buf=str;
+ return(1);
+}
+
static void parmtest(char *buf)
{
char wbuf[2048];
return;
}
- if (getparam_2words("topuser_sort_field",buf,TopuserSortField,sizeof(TopuserSortField),TopuserSortOrder,sizeof(TopuserSortOrder))>0) return;
+ if (getparam_sort("topuser_sort_field",SET_LIST(topuser_sort),buf,&TopuserSort)>0) return;
- if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
+ if (getparam_sort("user_sort_field",SET_LIST(user_sort),buf,&UserSort)>0) return;
if (is_param("access_log",buf)>0) {
if (AccessLogFromCmdLine==0) {
if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return;
- if (getparam_2words("topsites_sort_order",buf,TopsitesSortField,sizeof(TopsitesSortField),TopsitesSortType,sizeof(TopsitesSortType))>0) return;
+ if (getparam_sort("topsites_sort_order",SET_LIST(topsite_sort),buf,&TopsitesSort)>0) return;
if (getparam_bool("long_url",buf,&LongUrl)>0) return;
int count;
int cstatus;
const char txtext[]=".txt";
+ const char *sort_field;
+ const char *sort_order;
int dlen;
char siteind[MAX_TRUNCATED_URL];
struct getwordstruct gwarea;
greport_prepare();
+ sort_labels(&sort_field,&sort_order);
+
if ((dirp = opendir(tmp)) == NULL) {
debuga(_("Failed to open directory %s - %s\n"),tmp,strerror(errno));
exit(EXIT_FAILURE);
write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"));
fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period.html);
fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo->label);
- fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s, %s</td></tr>\n",_("Sort"),UserSortField,UserSortOrder);
+ fputs("<tr><td class=\"header_c\">",fp_ou);
+ fprintf(fp_ou,_("Sort: %s, %s"),sort_field,sort_order);
+ fputs("</td></tr>\n",fp_ou);
fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
close_html_header(fp_ou);
#define REALTIME_UNAUTH_REC_SHOW 0x0001UL
#define REALTIME_UNAUTH_REC_IGNORE 0x0002UL
+#define SORT_REVERSE 0x0001
+
+#define TOPUSER_SORT_REVERSE SORT_REVERSE
+#define TOPUSER_SORT_BYTES 0x0002UL
+#define TOPUSER_SORT_USER 0x0004UL
+#define TOPUSER_SORT_CONNECT 0x0008UL
+#define TOPUSER_SORT_TIME 0x0010UL
+
+#define TOPSITE_SORT_REVERSE SORT_REVERSE
+#define TOPSITE_SORT_BYTES 0x0002UL
+#define TOPSITE_SORT_CONNECT 0x0004UL
+
+#define USER_SORT_REVERSE SORT_REVERSE
+#define USER_SORT_BYTES 0x0002UL
+#define USER_SORT_SITE 0x0004UL
+#define USER_SORT_CONNECT 0x0008UL
+#define USER_SORT_TIME 0x0010UL
+
struct periodstruct
{
//! The first date of the period.
int TopSitesNum;
int TopUsersNum;
char ExcludeCodes[256];
-char TopsitesSortField[15];
-char TopsitesSortType[20];
+unsigned long int TopsitesSort;
unsigned long int ReportType;
char UserTabFile[255];
char warea[MAXLEN];
char TempDir[MAXLEN];
char OutputDir[MAXLEN];
char OutputEmail[MAXLEN];
-char TopuserSortField[30];
-char UserSortField[30];
-char TopuserSortOrder[10];
-char UserSortOrder[10];
+unsigned long int TopuserSort;
+unsigned long int UserSort;
char UserAgentLog[255];
char module[255];
char ExcludeHosts[255];
// sort.c
void sort_users_log(const char *tmp, int debug);
void tmpsort(void);
+void sort_labels(const char **label,const char **order);
// splitlog.c
void splitlog(const char *arq, char *df, int dfrom, int duntil, int convert);
TopSitesNum=100;
TopUsersNum=0;
UserIp=0;
- strcpy(TopuserSortField,"BYTES");
- strcpy(UserSortField,"BYTES");
- strcpy(TopuserSortOrder,"reverse");
- strcpy(UserSortOrder,"reverse");
- strcpy(TopsitesSortField,"CONNECT");
- strcpy(TopsitesSortType,"D");
+ TopuserSort=TOPUSER_SORT_BYTES | TOPUSER_SORT_REVERSE;
+ UserSort=USER_SORT_BYTES | USER_SORT_REVERSE;
+ TopsitesSort=TOPSITE_SORT_CONNECT | TOPSITE_SORT_REVERSE;
LongUrl=0;
strcpy(FontFace,"Verdana,Tahoma,Arial");
datetimeby=DATETIME_BYTE;
DIR *dirp;
struct dirent *direntp;
const char logext[]=".log";
+ const char *sort_field;
+ const char *sort_order;
int dlen;
int url_len;
int ourl_size=0;
maketmp(user,tmp,debug,indexonly);
maketmp_hour(user,tmp,indexonly);
+ sort_labels(&sort_field,&sort_order);
ttopen=0;
oldurltt=NULL;
write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report"));
fprintf(fp_tt,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period.html);
fprintf(fp_tt,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo->label);
- fprintf(fp_tt,"<tr><td class=\"header_c\">%s: %s, %s</td></tr>\n",_("Sort"),UserSortField,UserSortOrder);
+ fputs("<tr><td class=\"header_c\">",fp_tt);
+ fprintf(fp_tt,_("Sort: %s, %s"),sort_field,sort_order);
+ fputs("</td></tr>\n",fp_tt);
fprintf(fp_tt,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User"));
close_html_header(fp_tt);
const char *field1="2,2";
const char *field2="1,1";
const char *field3="3,3";
- const char *order="-r";
+ const char *order;
if(indexonly) return;
if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
- strup(UserSortField);
- if(strcmp(UserSortField,"CONNECT") == 0) {
+ if((UserSort & USER_SORT_CONNECT) != 0) {
field1="1,1";
field2="2,2";
field3="3,3";
- } else if(strcmp(UserSortField,"SITE") == 0) {
+ } else if((UserSort & USER_SORT_SITE) != 0) {
field1="3,3";
field2="2,2";
field3="1,1";
- } else if(strcmp(UserSortField,"TIME") == 0) {
+ } else if((UserSort & USER_SORT_TIME) != 0) {
field1="5,5";
field2="2,2";
field3="1,1";
}
- strlow(UserSortOrder);
- if(strcmp(UserSortOrder,"normal") == 0)
+ if((UserSort & USER_SORT_REVERSE) == 0)
order="";
+ else
+ order="-r";
if ((dirp = opendir(tmp)) == NULL) {
debuga(_("Failed to open directory %s - %s\n"),tmp,strerror(errno));
return;
}
+
+void sort_labels(const char **label,const char **order)
+{
+ if((UserSort & USER_SORT_CONNECT) != 0) {
+ *label=_("connect");
+ } else if((UserSort & USER_SORT_SITE) != 0) {
+ *label=_("site");
+ } else if((UserSort & USER_SORT_TIME) != 0) {
+ *label=_("time");
+ } else {
+ *label=_("bytes");
+ }
+
+ if((UserSort & USER_SORT_REVERSE) == 0)
+ *order=_("normal");
+ else
+ *order=_("reverse");
+}
fclose(fp_ou);
- strlow(TopsitesSortField);
- strlow(TopsitesSortType);
-
- if(strcmp(TopsitesSortField,"connect") == 0)
+ if((TopsitesSort & TOPSITE_SORT_CONNECT) != 0) {
sortf="-k 1,1 -k 2,2";
- else if(strcmp(TopsitesSortField,"bytes") == 0)
+ } else {
sortf="-k 2,2 -k 1,1";
- else
- sortf="";
- if(strcmp(TopsitesSortType,"a") == 0)
- sortt="";
- else if(strcmp(TopsitesSortType,"d") == 0)
+ }
+ if((TopsitesSort & TOPSITE_SORT_REVERSE) != 0) {
sortt="-r";
- else
+ } else {
sortt="";
+ }
sprintf(csort,"sort %s -n %s -o \"%s\" \"%s\"",sortt,sortf,sites,general3);
cstatus=system(csort);
char user[MAX_USER_LEN], tusr[MAXLEN];
char ipantes[MAXLEN], nameantes[MAXLEN];
const char *sfield="-n -k 2,2";
- const char *order="-r";
+ const char *order;
+ const char *sort_field;
+ const char *sort_order;
char title[80];
char *warea;
int totuser=0;
}
fclose(fp_top2);
- strup(TopuserSortField);
- strlow(TopuserSortOrder);
-
- if(strcmp(TopuserSortField,"USER") == 0)
+ if((TopuserSort & TOPUSER_SORT_USER) != 0) {
sfield="-k 1,1";
-
- if(strcmp(TopuserSortField,"CONNECT") == 0)
+ sort_field=_("user");
+ } else if((TopuserSort & TOPUSER_SORT_CONNECT) != 0) {
sfield="-n -k 3,3";
-
- if(strcmp(TopuserSortField,"TIME") == 0)
+ sort_field=_("connect");
+ } else if((TopuserSort & TOPUSER_SORT_TIME) != 0) {
sfield="-n -k 4,4";
+ sort_field=_("time");
+ } else {
+ sort_field=_("bytes");
+ }
- if(strcmp(TopuserSortOrder,"normal") == 0)
+ if((TopuserSort & TOPUSER_SORT_REVERSE) == 0) {
order="";
+ sort_order=_("normal");
+ } else {
+ order="-r";
+ sort_order=_("reverse");
+ }
snprintf(top1,sizeof(top1),"%s/top",outdirname);
sprintf(csort,"sort -T \"%s\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2);
fputs("<tr><td class=\"header_c\">",fp_top3);
fprintf(fp_top3,_("Period: %s"),period.html);
fputs("</td></tr>\n",fp_top3);
- fprintf(fp_top3,"<tr><td class=\"header_c\">%s: %s, %s</td></tr>\n",_("Sort"),TopuserSortField,TopuserSortOrder);
+ fputs("<tr><td class=\"header_c\">",fp_top3);
+ fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order);
+ fputs("</td></tr>\n",fp_top3);
fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users"));
close_html_header(fp_top3);