]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed FM |
2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
3 | * 1998, 2008 | |
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" | |
5f3cfd1d | 27 | #include "include/defs.h" |
25697a35 | 28 | |
32e71fa4 | 29 | void tmpsort(void) |
25697a35 GS |
30 | { |
31 | ||
32 | DIR *dirp; | |
33 | struct dirent *direntp; | |
456d78a5 | 34 | int cstatus; |
32e71fa4 FM |
35 | const char tmpext[]=".utmp"; |
36 | int dlen; | |
25697a35 GS |
37 | |
38 | char csort[MAXLEN]; | |
32e71fa4 | 39 | char arqou[MAXLEN], arqin[MAXLEN], wnome[MAXLEN]; |
25697a35 GS |
40 | char field1[10]="2,2"; |
41 | char field2[10]="1,1"; | |
42 | char field3[10]="3,3"; | |
43 | char order[4]="-r"; | |
44 | ||
45 | if(indexonly) return; | |
46 | if(strstr(ReportType,"users_sites") == 0) return; | |
47 | ||
32e71fa4 FM |
48 | strup(UserSortField); |
49 | if(strcmp(UserSortField,"CONNECT") == 0) { | |
50 | strcpy(field1,"1,1"); | |
51 | strcpy(field2,"2,2"); | |
52 | strcpy(field3,"3,3"); | |
53 | } else if(strcmp(UserSortField,"SITE") == 0) { | |
54 | strcpy(field1,"3,3"); | |
55 | strcpy(field2,"2,2"); | |
56 | strcpy(field3,"1,1"); | |
57 | } else if(strcmp(UserSortField,"TIME") == 0) { | |
58 | strcpy(field1,"5,5"); | |
59 | strcpy(field2,"2,2"); | |
60 | strcpy(field3,"1,1"); | |
61 | } | |
62 | ||
63 | strlow(UserSortOrder); | |
64 | if(strcmp(UserSortOrder,"normal") == 0) | |
65 | order[0]='\0'; | |
25697a35 GS |
66 | |
67 | dirp = opendir(tmp); | |
68 | while ((direntp = readdir( dirp )) != NULL ){ | |
32e71fa4 FM |
69 | dlen=strlen(direntp->d_name)-(sizeof(tmpext)-1); |
70 | if (dlen<0) continue; | |
71 | if(strcmp(direntp->d_name+dlen,tmpext) != 0) | |
25697a35 GS |
72 | continue; |
73 | ||
32e71fa4 FM |
74 | if (dlen>0) { |
75 | if (dlen>=sizeof(wnome)) continue; | |
76 | strncpy(wnome,direntp->d_name,dlen); | |
77 | wnome[dlen]=0; | |
78 | } else { | |
79 | wnome[0]='\0'; | |
25697a35 | 80 | } |
32e71fa4 | 81 | |
25697a35 GS |
82 | strcpy(arqou,tmp); |
83 | strcat(arqou,"/"); | |
84 | strcpy(arqin,arqou); | |
85 | strcat(arqou,wnome); | |
86 | strcat(arqin,direntp->d_name); | |
87 | ||
88 | if(debug) { | |
d2fe0c32 | 89 | debuga("%s: %s",text[54],arqou); |
25697a35 GS |
90 | } |
91 | ||
25697a35 | 92 | strcat(arqou,".txt"); |
94ff9470 | 93 | 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 |
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); | |
98 | exit(1); | |
99 | } | |
25697a35 GS |
100 | unlink(arqin); |
101 | ||
102 | } | |
103 | ||
25697a35 GS |
104 | (void)closedir( dirp ); |
105 | return; | |
106 | } | |
107 | ||
32e71fa4 | 108 | void sort_users_log(const char *tmp, int debug) |
25697a35 | 109 | { |
25697a35 GS |
110 | DIR *dirp; |
111 | struct dirent *direntp; | |
112 | char csort[MAXLEN]; | |
113 | char wtmp[MAXLEN]; | |
32e71fa4 | 114 | char user[MAXLEN]; |
25697a35 | 115 | char wdname[MAXLEN]; |
456d78a5 | 116 | int cstatus; |
32e71fa4 FM |
117 | const char unsortext[]=".unsort"; |
118 | int dlen; | |
25697a35 | 119 | |
d6e703cc | 120 | if(debug) { |
d2fe0c32 | 121 | debuga("%s",text[138]); |
d6e703cc FM |
122 | } |
123 | ||
25697a35 GS |
124 | sprintf(wtmp,"%s/sarg",tmp); |
125 | ||
126 | dirp = opendir(wtmp); | |
127 | while ( (direntp = readdir( dirp )) != NULL ){ | |
32e71fa4 FM |
128 | dlen=strlen(direntp->d_name)-(sizeof(unsortext)-1); |
129 | if (dlen<0) continue; | |
130 | if(strcmp(direntp->d_name+dlen,unsortext) != 0) | |
25697a35 | 131 | continue; |
32e71fa4 | 132 | if(strcmp(direntp->d_name,"authfail.log.unsort") == 0) |
491b862f GS |
133 | continue; |
134 | ||
32e71fa4 FM |
135 | if (dlen>0) { |
136 | if (dlen>=sizeof(user)) continue; | |
137 | strncpy(user,direntp->d_name,dlen); | |
138 | user[dlen]=0; | |
139 | } else { | |
140 | bzero(user, MAXLEN); | |
25697a35 GS |
141 | } |
142 | ||
143 | if(strcmp(direntp->d_name,"download.unsort") == 0) | |
94ff9470 | 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'", |
25697a35 GS |
145 | tmp, wtmp, user, wtmp, user); |
146 | else | |
94ff9470 | 147 | sprintf(csort,"sort -T %s -k 5,5 -k 1,1 -k 2,2 -o '%s/%s.log' '%s/%s.unsort'", |
25697a35 | 148 | tmp, wtmp, user, wtmp, user); |
456d78a5 FM |
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); | |
153 | exit(1); | |
154 | } | |
32e71fa4 FM |
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); | |
157 | exit(1); | |
158 | } | |
25697a35 GS |
159 | unlink(wdname); |
160 | bzero(user, MAXLEN); | |
161 | ||
162 | } | |
25697a35 GS |
163 | (void)closedir( dirp ); |
164 | ||
165 | return; | |
166 | } |