]>
git.ipfire.org Git - thirdparty/sarg.git/blob - sort.c
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
26 #include "include/conf.h"
27 #include "include/defs.h"
33 struct dirent
*direntp
;
35 const char tmpext
[]=".utmp";
39 char arqou
[MAXLEN
], arqin
[MAXLEN
], wnome
[MAXLEN
];
40 char field1
[10]="2,2";
41 char field2
[10]="1,1";
42 char field3
[10]="3,3";
46 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
49 if(strcmp(UserSortField
,"CONNECT") == 0) {
53 } else if(strcmp(UserSortField
,"SITE") == 0) {
57 } else if(strcmp(UserSortField
,"TIME") == 0) {
63 strlow(UserSortOrder
);
64 if(strcmp(UserSortOrder
,"normal") == 0)
68 while ((direntp
= readdir( dirp
)) != NULL
){
69 dlen
=strlen(direntp
->d_name
)-(sizeof(tmpext
)-1);
71 if(strcmp(direntp
->d_name
+dlen
,tmpext
) != 0)
75 if (dlen
>=sizeof(wnome
)) continue;
76 strncpy(wnome
,direntp
->d_name
,dlen
);
86 strcat(arqin
,direntp
->d_name
);
89 debuga("%s: %s",text
[54],arqou
);
93 sprintf(csort
,"sort -n -T \"%s\" %s -k %s -k %s -k %s -o \"%s\" \"%s\"",TempDir
,order
,field1
,field2
,field3
,arqou
,arqin
);
94 cstatus
=system(csort
);
95 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
96 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
97 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
104 (void)closedir( dirp
);
108 void sort_users_log(const char *tmp
, int debug
)
111 struct dirent
*direntp
;
117 const char unsortext
[]=".unsort";
121 debuga("%s",text
[138]);
124 sprintf(wtmp
,"%s/sarg",tmp
);
126 dirp
= opendir(wtmp
);
127 while ( (direntp
= readdir( dirp
)) != NULL
){
128 dlen
=strlen(direntp
->d_name
)-(sizeof(unsortext
)-1);
129 if (dlen
<0) continue;
130 if(strcmp(direntp
->d_name
+dlen
,unsortext
) != 0)
132 if(strcmp(direntp
->d_name
,"authfail.log.unsort") == 0)
136 if (dlen
>=sizeof(user
)) continue;
137 strncpy(user
,direntp
->d_name
,dlen
);
143 if(strcmp(direntp
->d_name
,"download.unsort") == 0)
144 sprintf(csort
,"sort -T \"%s\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"",
145 tmp
, wtmp
, user
, wtmp
, user
);
147 sprintf(csort
,"sort -T \"%s\" -k 5,5 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
148 tmp
, wtmp
, user
, wtmp
, user
);
149 cstatus
=system(csort
);
150 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
151 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
152 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
155 if (snprintf(wdname
,sizeof(wdname
),"%s/%s.unsort",wtmp
,user
)>=sizeof(wdname
)) {
156 fprintf(stderr
, "SARG: user name too long for: %s/%s.unsort\n",wtmp
,user
);
163 (void)closedir( dirp
);