]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br |
25697a35 | 3 | * 1998, 2005 |
94ff9470 | 4 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
25697a35 GS |
5 | * |
6 | * SARG donations: | |
7 | * please look at http://sarg.sourceforge.net/donations.php | |
8 | * --------------------------------------------------------------------- | |
9 | * | |
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. | |
14 | * | |
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. | |
19 | * | |
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. | |
23 | * | |
24 | */ | |
25 | ||
26 | #include "include/conf.h" | |
27 | ||
28 | void tmpsort() | |
29 | { | |
30 | ||
31 | DIR *dirp; | |
32 | struct dirent *direntp; | |
33 | ||
34 | char csort[MAXLEN]; | |
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"; | |
39 | char order[4]="-r"; | |
40 | ||
41 | if(indexonly) return; | |
42 | if(strstr(ReportType,"users_sites") == 0) return; | |
43 | ||
44 | wnome[0]='\0'; | |
45 | wnome2[0]='\0'; | |
46 | ||
47 | dirp = opendir(tmp); | |
48 | while ((direntp = readdir( dirp )) != NULL ){ | |
49 | if(strstr(direntp->d_name,".utmp") == 0) | |
50 | continue; | |
51 | ||
52 | strcpy(wentp,direntp->d_name); | |
53 | ||
54 | wnome[0]='\0'; | |
55 | striptmp: | |
56 | getword(wnome2,wentp,'.'); | |
57 | strcat(wnome,wnome2); | |
58 | ||
59 | if(strcmp(wentp,"utmp") !=0) { | |
60 | strcat(wnome,"."); | |
61 | goto striptmp; | |
62 | } | |
63 | ||
64 | strcpy(arqou,tmp); | |
65 | strcat(arqou,"/"); | |
66 | strcpy(arqin,arqou); | |
67 | strcat(arqou,wnome); | |
68 | strcat(arqin,direntp->d_name); | |
69 | ||
70 | if(debug) { | |
71 | sprintf(msg,"%s: %s",text[54],arqou); | |
72 | debuga(msg); | |
73 | } | |
74 | ||
75 | strup(UserSortField); | |
76 | strlow(UserSortOrder); | |
77 | ||
78 | if(strcmp(UserSortField,"CONNECT") == 0) { | |
79 | strcpy(field1,"1,1"); | |
80 | strcpy(field2,"2,2"); | |
81 | strcpy(field3,"3,3"); | |
82 | } | |
83 | ||
84 | if(strcmp(UserSortField,"SITE") == 0) { | |
85 | strcpy(field1,"3,3"); | |
86 | strcpy(field2,"2,2"); | |
87 | strcpy(field3,"1,1"); | |
88 | } | |
89 | ||
90 | if(strcmp(UserSortField,"TIME") == 0) { | |
91 | strcpy(field1,"5,5"); | |
92 | strcpy(field2,"2,2"); | |
93 | strcpy(field3,"1,1"); | |
94 | } | |
95 | ||
96 | if(strcmp(UserSortOrder,"normal") == 0) | |
97 | order[0]='\0'; | |
98 | ||
99 | strcat(arqou,".txt"); | |
94ff9470 | 100 | sprintf(csort,"sort -n -T %s %s -k %s -k %s -k %s -o '%s' '%s'",TempDir,order,field1,field2,field3,arqou,arqin); |
25697a35 GS |
101 | system(csort); |
102 | unlink(arqin); | |
103 | ||
104 | } | |
105 | ||
106 | (void)rewinddir( dirp ); | |
107 | (void)closedir( dirp ); | |
108 | return; | |
109 | } | |
110 | ||
111 | void sort_users_log(char *tmp, int debug) | |
112 | { | |
113 | ||
114 | DIR *dirp; | |
115 | struct dirent *direntp; | |
116 | char csort[MAXLEN]; | |
117 | char wtmp[MAXLEN]; | |
118 | char wname2[MAXLEN]; | |
119 | char wdname[MAXLEN]; | |
120 | ||
121 | sprintf(wtmp,"%s/sarg",tmp); | |
122 | ||
123 | dirp = opendir(wtmp); | |
124 | while ( (direntp = readdir( dirp )) != NULL ){ | |
125 | if(strstr(direntp->d_name,".unsort") == 0) | |
126 | continue; | |
127 | strcpy(wdname,direntp->d_name); | |
128 | ||
129 | bzero(user, MAXLEN); | |
130 | strip_unsort: | |
131 | getword(wname2,wdname,'.'); | |
132 | strcat(user,wname2); | |
133 | ||
134 | if(strcmp(wdname,"unsort") !=0) { | |
135 | strcat(user,"."); | |
136 | goto strip_unsort; | |
137 | } | |
138 | ||
139 | if(strcmp(direntp->d_name,"download.unsort") == 0) | |
94ff9470 | 140 | sprintf(csort,"sort -T %s -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o '%s/%s.log' '%s/%s.unsort'", |
25697a35 GS |
141 | tmp, wtmp, user, wtmp, user); |
142 | else | |
94ff9470 | 143 | sprintf(csort,"sort -T %s -k 5,5 -k 1,1 -k 2,2 -o '%s/%s.log' '%s/%s.unsort'", |
25697a35 GS |
144 | tmp, wtmp, user, wtmp, user); |
145 | system(csort); | |
146 | sprintf(wdname,"%s/%s.unsort",wtmp,user); | |
147 | unlink(wdname); | |
148 | bzero(user, MAXLEN); | |
149 | ||
150 | } | |
151 | (void)rewinddir( dirp ); | |
152 | (void)closedir( dirp ); | |
153 | ||
154 | return; | |
155 | } |