]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
1164c474 | 3 | * 1998, 2010 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
9 | * --------------------------------------------------------------------- |
10 | * | |
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. | |
15 | * | |
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. | |
20 | * | |
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. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "include/conf.h" | |
5f3cfd1d | 28 | #include "include/defs.h" |
25697a35 | 29 | |
32e71fa4 | 30 | void tmpsort(void) |
25697a35 GS |
31 | { |
32 | ||
33 | DIR *dirp; | |
34 | struct dirent *direntp; | |
456d78a5 | 35 | int cstatus; |
32e71fa4 FM |
36 | const char tmpext[]=".utmp"; |
37 | int dlen; | |
25697a35 GS |
38 | |
39 | char csort[MAXLEN]; | |
32e71fa4 | 40 | char arqou[MAXLEN], arqin[MAXLEN], wnome[MAXLEN]; |
25697a35 GS |
41 | char field1[10]="2,2"; |
42 | char field2[10]="1,1"; | |
43 | char field3[10]="3,3"; | |
44 | char order[4]="-r"; | |
45 | ||
46 | if(indexonly) return; | |
085c1e1f | 47 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 48 | |
32e71fa4 FM |
49 | strup(UserSortField); |
50 | if(strcmp(UserSortField,"CONNECT") == 0) { | |
51 | strcpy(field1,"1,1"); | |
52 | strcpy(field2,"2,2"); | |
53 | strcpy(field3,"3,3"); | |
54 | } else if(strcmp(UserSortField,"SITE") == 0) { | |
55 | strcpy(field1,"3,3"); | |
56 | strcpy(field2,"2,2"); | |
57 | strcpy(field3,"1,1"); | |
58 | } else if(strcmp(UserSortField,"TIME") == 0) { | |
59 | strcpy(field1,"5,5"); | |
60 | strcpy(field2,"2,2"); | |
61 | strcpy(field3,"1,1"); | |
62 | } | |
63 | ||
64 | strlow(UserSortOrder); | |
65 | if(strcmp(UserSortOrder,"normal") == 0) | |
66 | order[0]='\0'; | |
25697a35 GS |
67 | |
68 | dirp = opendir(tmp); | |
69 | while ((direntp = readdir( dirp )) != NULL ){ | |
32e71fa4 FM |
70 | dlen=strlen(direntp->d_name)-(sizeof(tmpext)-1); |
71 | if (dlen<0) continue; | |
72 | if(strcmp(direntp->d_name+dlen,tmpext) != 0) | |
25697a35 GS |
73 | continue; |
74 | ||
32e71fa4 FM |
75 | if (dlen>0) { |
76 | if (dlen>=sizeof(wnome)) continue; | |
77 | strncpy(wnome,direntp->d_name,dlen); | |
0a4e18e1 | 78 | wnome[dlen]='\0'; |
32e71fa4 FM |
79 | } else { |
80 | wnome[0]='\0'; | |
25697a35 | 81 | } |
5542cb59 | 82 | |
25697a35 GS |
83 | strcpy(arqou,tmp); |
84 | strcat(arqou,"/"); | |
85 | strcpy(arqin,arqou); | |
86 | strcat(arqou,wnome); | |
87 | strcat(arqin,direntp->d_name); | |
88 | ||
89 | if(debug) { | |
d2fe0c32 | 90 | debuga("%s: %s",text[54],arqou); |
25697a35 GS |
91 | } |
92 | ||
25697a35 | 93 | strcat(arqou,".txt"); |
9a2efbd0 | 94 | sprintf(csort,"sort -n -T \"%s\" %s -k %s -k %s -k %s -o \"%s\" \"%s\"",TempDir,order,field1,field2,field3,arqou,arqin); |
456d78a5 FM |
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); | |
99 | exit(1); | |
100 | } | |
25697a35 GS |
101 | unlink(arqin); |
102 | ||
103 | } | |
104 | ||
25697a35 GS |
105 | (void)closedir( dirp ); |
106 | return; | |
107 | } | |
108 | ||
32e71fa4 | 109 | void sort_users_log(const char *tmp, int debug) |
25697a35 | 110 | { |
25697a35 GS |
111 | DIR *dirp; |
112 | struct dirent *direntp; | |
113 | char csort[MAXLEN]; | |
114 | char wtmp[MAXLEN]; | |
32e71fa4 | 115 | char user[MAXLEN]; |
25697a35 | 116 | char wdname[MAXLEN]; |
456d78a5 | 117 | int cstatus; |
32e71fa4 FM |
118 | const char unsortext[]=".unsort"; |
119 | int dlen; | |
25697a35 | 120 | |
d6e703cc | 121 | if(debug) { |
d2fe0c32 | 122 | debuga("%s",text[138]); |
d6e703cc FM |
123 | } |
124 | ||
25697a35 GS |
125 | sprintf(wtmp,"%s/sarg",tmp); |
126 | ||
127 | dirp = opendir(wtmp); | |
128 | while ( (direntp = readdir( dirp )) != NULL ){ | |
32e71fa4 FM |
129 | dlen=strlen(direntp->d_name)-(sizeof(unsortext)-1); |
130 | if (dlen<0) continue; | |
131 | if(strcmp(direntp->d_name+dlen,unsortext) != 0) | |
25697a35 | 132 | continue; |
32e71fa4 | 133 | if(strcmp(direntp->d_name,"authfail.log.unsort") == 0) |
491b862f GS |
134 | continue; |
135 | ||
32e71fa4 FM |
136 | if (dlen>0) { |
137 | if (dlen>=sizeof(user)) continue; | |
138 | strncpy(user,direntp->d_name,dlen); | |
139 | user[dlen]=0; | |
140 | } else { | |
141 | bzero(user, MAXLEN); | |
25697a35 GS |
142 | } |
143 | ||
144 | if(strcmp(direntp->d_name,"download.unsort") == 0) | |
9a2efbd0 | 145 | sprintf(csort,"sort -T \"%s\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"", |
5542cb59 | 146 | tmp, wtmp, user, wtmp, user); |
25697a35 | 147 | else |
9a2efbd0 | 148 | sprintf(csort,"sort -T \"%s\" -k 5,5 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"", |
5542cb59 | 149 | tmp, wtmp, user, wtmp, user); |
456d78a5 FM |
150 | cstatus=system(csort); |
151 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
152 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
153 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
154 | exit(1); | |
155 | } | |
32e71fa4 FM |
156 | if (snprintf(wdname,sizeof(wdname),"%s/%s.unsort",wtmp,user)>=sizeof(wdname)) { |
157 | fprintf(stderr, "SARG: user name too long for: %s/%s.unsort\n",wtmp,user); | |
158 | exit(1); | |
159 | } | |
25697a35 GS |
160 | unlink(wdname); |
161 | bzero(user, MAXLEN); | |
162 | ||
163 | } | |
25697a35 GS |
164 | (void)closedir( dirp ); |
165 | ||
166 | return; | |
167 | } |