]>
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" | |
27 | ||
28 | void saverecs(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache); | |
29 | void grava_SmartFilter(char *dirname, char *user, char *ip, char *data, char *hora, char *url, char *smart); | |
30 | ||
31 | void data_file(char *tmp) | |
32 | { | |
33 | ||
34 | FILE *fp_in; | |
35 | ||
36 | char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10]; | |
37 | char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN]; | |
38 | char dirname[MAXLEN], wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN]; | |
39 | char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50]; | |
40 | char ipantes[MAXLEN], nameantes[MAXLEN]; | |
41 | char accsmart[MAXLEN]; | |
42 | char Msg[MAXLEN]; | |
43 | int smartfilter=0; | |
44 | char wcrc[50]; | |
45 | char crc2[50]; | |
46 | char wdname[MAXLEN]; | |
47 | char wname2[MAXLEN]; | |
48 | DIR *dirp; | |
49 | struct dirent *direntp; | |
50 | long long int nbytes=0; | |
51 | long long int nelap=0; | |
52 | long long int nacc=0; | |
53 | long long int rtotal=0; | |
54 | long long int incache=0; | |
55 | long long int oucache=0; | |
56 | char *s; | |
57 | ||
58 | ipantes[0]='\0'; | |
59 | nameantes[0]='\0'; | |
60 | ||
61 | olduser[0]='\0'; | |
62 | strncat(tmp,"/sarg",5); | |
63 | ||
64 | dirp = opendir(tmp); | |
65 | while ( (direntp = readdir( dirp )) != NULL ) { | |
66 | if(strstr(direntp->d_name,".log") == 0) | |
67 | continue; | |
68 | sprintf(tmp3,"%s/%s",tmp,direntp->d_name); | |
69 | ||
70 | if((fp_in=fopen(tmp3,"r"))==NULL){ | |
71 | fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],tmp); | |
72 | exit(1); | |
73 | } | |
74 | strcpy(wdname,direntp->d_name); | |
75 | strip_prefix: | |
76 | getword(wname2,wdname,'.'); | |
77 | strcat(user,wname2); | |
78 | ||
79 | ttopen=0; | |
80 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
81 | getword(accdia,buf,' '); | |
82 | getword(acchora,buf,' '); | |
83 | getword(accuser,buf,' '); | |
84 | getword(accip,buf,' '); | |
85 | getword(accurl,buf,' '); | |
86 | getword(accbytes,buf,' '); | |
87 | getword(acccode,buf,' '); | |
88 | getword(accelap,buf,' '); | |
89 | getword(accsmart,buf,' '); | |
90 | getword(accsmart,buf,'"'); | |
91 | ||
92 | if(strcmp(Ip2Name,"yes") == 0) { | |
93 | if(strcmp(accip,ipantes) != 0) { | |
94 | strcpy(ipantes,accip); | |
95 | ip2name(accip); | |
96 | strcpy(nameantes,accip); | |
97 | } else strcpy(accip,nameantes); | |
98 | } | |
99 | ||
100 | if(!rtotal){ | |
101 | strcpy(oldurl,accurl); | |
102 | strcpy(oldacccode,acccode); | |
103 | strcpy(oldaccelap,accelap); | |
104 | strcpy(oldaccuser,accuser); | |
105 | strcpy(oldaccip,accip); | |
106 | strcpy(oldaccdia,accdia); | |
107 | strcpy(oldacchora,acchora); | |
108 | rtotal++; | |
109 | } | |
110 | ||
111 | if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){ | |
112 | strcpy(oldmsg,"OK"); | |
113 | if(strstr(oldacccode,"DENIED") != 0) | |
114 | sprintf(oldmsg,"%s",text[46]); | |
115 | strcpy(wdirname,dirname); | |
116 | gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); | |
117 | strcpy(wdirname,dirname); | |
14c2eac6 | 118 | saverecs(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); |
25697a35 GS |
119 | nacc=0; |
120 | nbytes=0; | |
121 | nelap=0; | |
122 | incache=0; | |
123 | oucache=0; | |
124 | if(strcmp(oldaccuser,accuser) != 0) | |
125 | ind2=0; | |
126 | } | |
127 | ||
128 | nacc++; | |
129 | nbytes+=my_atoll(accbytes); | |
130 | nelap+=my_atoll(accelap); | |
131 | ||
132 | strcpy(wcrc,acccode); | |
133 | getword(crc2,wcrc,'/'); | |
134 | ||
135 | if(strstr(crc2,"MISS") != 0) | |
136 | oucache+=my_atoll(accbytes); | |
137 | else incache+=my_atoll(accbytes); | |
138 | ||
139 | strcpy(oldurl,accurl); | |
140 | strcpy(oldaccuser,accuser); | |
141 | strcpy(oldacccode,acccode); | |
142 | strcpy(oldaccelap,accelap); | |
143 | strcpy(oldaccip,accip); | |
144 | strcpy(oldaccdia,accdia); | |
145 | strcpy(oldacchora,acchora); | |
146 | } | |
147 | ||
148 | fclose(fp_in); | |
149 | } | |
150 | ||
151 | (void)closedir( dirp ); | |
152 | if(debug) { | |
153 | sprintf(Msg,"Datafile %s successfully",DataFile); | |
154 | debuga(Msg); | |
155 | } | |
156 | return; | |
157 | } | |
158 | ||
14c2eac6 | 159 | void saverecs(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache) |
25697a35 GS |
160 | { |
161 | ||
162 | FILE *fp_ou; | |
163 | char reg[MAXLEN]; | |
164 | ||
165 | if((fp_ou=fopen(DataFile,"a"))==NULL){ | |
166 | fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],DataFile); | |
167 | exit(1); | |
168 | } | |
169 | ||
170 | my_lltoa(nacc,val1,0); | |
171 | my_lltoa(nbytes,val2,0); | |
172 | my_lltoa(nelap,val3,0); | |
173 | my_lltoa(incache,val4,0); | |
174 | my_lltoa(oucache,val5,0); | |
175 | ||
176 | if(strstr(DataFileFields,"user") != 0) { | |
177 | strcpy(reg,user); | |
178 | strncat(reg,DataFileDelimiter,1); | |
179 | } | |
180 | if(strstr(DataFileFields,"date") != 0) { | |
181 | strncat(reg,dia,strlen(dia)); | |
182 | strncat(reg,DataFileDelimiter,1); | |
183 | } | |
184 | if(strstr(DataFileFields,"time") != 0) { | |
185 | strncat(reg,hora,strlen(hora)); | |
186 | strncat(reg,DataFileDelimiter,1); | |
187 | } | |
188 | if(strstr(DataFileFields,"url") != 0) { | |
189 | strcpy(name,url); | |
491b862f GS |
190 | if (strcmp(DataFileUrl,"ip") == 0) |
191 | name2ip(name); | |
25697a35 GS |
192 | strncat(reg,name,strlen(name)); |
193 | strncat(reg,DataFileDelimiter,1); | |
194 | } | |
195 | if(strstr(DataFileFields,"connect") != 0) { | |
196 | strncat(reg,val1,strlen(val1)); | |
197 | strncat(reg,DataFileDelimiter,1); | |
198 | } | |
199 | if(strstr(DataFileFields,"bytes") != 0) { | |
200 | strncat(reg,val2,strlen(val2)); | |
201 | strncat(reg,DataFileDelimiter,1); | |
202 | } | |
203 | if(strstr(DataFileFields,"in_cache") != 0) { | |
204 | strncat(reg,val4,strlen(val4)); | |
205 | strncat(reg,DataFileDelimiter,1); | |
206 | } | |
207 | if(strstr(DataFileFields,"out_cache") != 0) { | |
208 | strncat(reg,val5,strlen(val5)); | |
209 | strncat(reg,DataFileDelimiter,1); | |
210 | } | |
211 | if(strstr(DataFileFields,"elapsed") != 0) { | |
212 | strncat(reg,val3,strlen(val3)); | |
213 | strncat(reg,DataFileDelimiter,1); | |
214 | } | |
215 | ||
216 | reg[strlen(reg)-1]='\n'; | |
217 | fputs(reg,fp_ou); | |
218 | ||
219 | fclose(fp_ou); | |
220 | ||
221 | return; | |
222 | ||
223 | } |