]>
git.ipfire.org Git - thirdparty/sarg.git/blob - sort.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 #include "include/conf.h"
28 #include "include/defs.h"
34 struct dirent
*direntp
;
36 const char tmpext
[]=".utmp";
40 char arqou
[MAXLEN
], arqin
[MAXLEN
], wnome
[MAXLEN
];
41 const char *field1
="2,2";
42 const char *field2
="1,1";
43 const char *field3
="3,3";
44 const char *order
="-r";
47 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
50 if(strcmp(UserSortField
,"CONNECT") == 0) {
54 } else if(strcmp(UserSortField
,"SITE") == 0) {
58 } else if(strcmp(UserSortField
,"TIME") == 0) {
64 strlow(UserSortOrder
);
65 if(strcmp(UserSortOrder
,"normal") == 0)
69 while ((direntp
= readdir( dirp
)) != NULL
){
70 dlen
=strlen(direntp
->d_name
)-(sizeof(tmpext
)-1);
72 if(strcmp(direntp
->d_name
+dlen
,tmpext
) != 0)
76 if (dlen
>=sizeof(wnome
)) continue;
77 strncpy(wnome
,direntp
->d_name
,dlen
);
87 strcat(arqin
,direntp
->d_name
);
90 debuga("%s: %s",text
[54],arqou
);
94 sprintf(csort
,"sort -n -T \"%s\" %s -k %s -k %s -k %s -o \"%s\" \"%s\"",TempDir
,order
,field1
,field2
,field3
,arqou
,arqin
);
95 cstatus
=system(csort
);
96 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
97 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
98 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
105 (void)closedir( dirp
);
109 void sort_users_log(const char *tmp
, int debug
)
112 struct dirent
*direntp
;
120 const char unsortext
[]=".unsort";
123 debuga("%s",text
[138]);
126 sprintf(wtmp
,"%s/sarg",tmp
);
128 dirp
= opendir(wtmp
);
129 while ( (direntp
= readdir( dirp
)) != NULL
){
130 dlen
=strlen(direntp
->d_name
)-(sizeof(unsortext
)-1);
131 if (dlen
<0) continue;
132 if(strcmp(direntp
->d_name
+dlen
,unsortext
) != 0)
134 if(strcmp(direntp
->d_name
,"authfail.log.unsort") == 0)
138 if (dlen
>=sizeof(user
)) continue;
139 strncpy(user
,direntp
->d_name
,dlen
);
145 if(strcmp(direntp
->d_name
,"download.unsort") == 0)
146 clen
=snprintf(csort
,sizeof(csort
),"sort -T \"%s\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"",
147 tmp
, wtmp
, user
, wtmp
, user
);
149 clen
=snprintf(csort
,sizeof(csort
),"sort -T \"%s\" -k 5,5 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
150 tmp
, wtmp
, user
, wtmp
, user
);
151 if (clen
>=sizeof(csort
)) {
152 fprintf(stderr
, "SARG: user name too long to sort %s\n",csort
);
155 cstatus
=system(csort
);
156 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
157 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
158 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
161 if (snprintf(wdname
,sizeof(wdname
),"%s/%s.unsort",wtmp
,user
)>=sizeof(wdname
)) {
162 fprintf(stderr
, "SARG: user name too long for: %s/%s.unsort\n",wtmp
,user
);
167 (void)closedir( dirp
);