]>
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"
32 struct dirent
*direntp
;
35 char arqou
[MAXLEN
], arqin
[MAXLEN
], wnome
[MAXLEN
], wnome2
[MAXLEN
];
36 char field1
[10]="2,2";
37 char field2
[10]="1,1";
38 char field3
[10]="3,3";
42 if(strstr(ReportType
,"users_sites") == 0) return;
48 while ((direntp
= readdir( dirp
)) != NULL
){
49 if(strstr(direntp
->d_name
,".utmp") == 0)
52 strcpy(wentp
,direntp
->d_name
);
56 if (getword(wnome2
,sizeof(wnome2
),wentp
,'.')<0) {
57 printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",tmp
);
62 if(strcmp(wentp
,"utmp") !=0) {
71 strcat(arqin
,direntp
->d_name
);
74 sprintf(msg
,"%s: %s",text
[54],arqou
);
79 strlow(UserSortOrder
);
81 if(strcmp(UserSortField
,"CONNECT") == 0) {
87 if(strcmp(UserSortField
,"SITE") == 0) {
93 if(strcmp(UserSortField
,"TIME") == 0) {
99 if(strcmp(UserSortOrder
,"normal") == 0)
102 strcat(arqou
,".txt");
103 sprintf(csort
,"sort -n -T %s %s -k %s -k %s -k %s -o '%s' '%s'",TempDir
,order
,field1
,field2
,field3
,arqou
,arqin
);
109 (void)rewinddir( dirp
);
110 (void)closedir( dirp
);
114 void sort_users_log(char *tmp
, int debug
)
118 struct dirent
*direntp
;
125 sprintf(msg
,"%s",text
[138]);
129 sprintf(wtmp
,"%s/sarg",tmp
);
131 dirp
= opendir(wtmp
);
132 while ( (direntp
= readdir( dirp
)) != NULL
){
133 if(strstr(direntp
->d_name
,".unsort") == 0)
135 if(strcmp(direntp
->d_name
,"denied.log") == 0 || strcmp(direntp
->d_name
,"authfail.log.unsort") == 0)
138 strcpy(wdname
,direntp
->d_name
);
142 if (getword(wname2
,sizeof(wname2
),wdname
,'.')<0) {
143 printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",wtmp
);
148 if(strcmp(wdname
,"unsort") !=0) {
153 if(strcmp(direntp
->d_name
,"download.unsort") == 0)
154 sprintf(csort
,"sort -T %s -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o '%s/%s.log' '%s/%s.unsort'",
155 tmp
, wtmp
, user
, wtmp
, user
);
157 sprintf(csort
,"sort -T %s -k 5,5 -k 1,1 -k 2,2 -o '%s/%s.log' '%s/%s.unsort'",
158 tmp
, wtmp
, user
, wtmp
, user
);
160 sprintf(wdname
,"%s/%s.unsort",wtmp
,user
);
165 (void)rewinddir( dirp
);
166 (void)closedir( dirp
);