]>
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 htmlrel(void) |
25697a35 GS |
31 | { |
32 | DIR *dirp; | |
32e71fa4 | 33 | FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr; |
25697a35 GS |
34 | |
35 | struct dirent *direntp; | |
36 | long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0; | |
37 | long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0; | |
9f20cdae | 38 | long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0; |
0a4e18e1 FM |
39 | long long int ltemp; |
40 | long long int ntotuser; | |
41 | long long int userbytes, userelap; | |
e5b2c6f0 | 42 | char *buf; |
25697a35 | 43 | char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN]; |
e5b2c6f0 | 44 | char *url, tmsg[50], csort[MAXLEN]; |
fa6552b0 | 45 | char user[MAXLEN], duser[MAXLEN]; |
e5b2c6f0 | 46 | char userhora[9], userdia[9]; |
0a4e18e1 | 47 | char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN]; |
f2ec8c75 | 48 | char denied_report[255]; |
25697a35 | 49 | char *str; |
32e71fa4 | 50 | char warea[MAXLEN]; |
0a4e18e1 | 51 | char totuser[8]; |
2240dcea | 52 | char tmp6[MAXLEN]; |
25697a35 | 53 | long long int tnacc=0, ttnacc=0, unacc=0; |
9f20cdae | 54 | double perc=0, perc2=0, ouperc=0, inperc=0; |
32e71fa4 | 55 | int count; |
456d78a5 | 56 | int cstatus; |
936c9905 FM |
57 | const char txtext[]=".txt"; |
58 | int dlen; | |
e5b2c6f0 | 59 | char siteind[MAX_TRUNCATED_URL]; |
9c7c6346 | 60 | struct getwordstruct gwarea; |
afaa3b67 | 61 | longline line,line1; |
2240dcea | 62 | struct generalitemstruct item; |
f2ec8c75 | 63 | const struct userinfostruct *uinfo; |
25697a35 | 64 | |
085c1e1f | 65 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 GS |
66 | |
67 | strcpy(tmp2,TempDir); | |
68 | strcat(tmp2,"/sargtmp.unsort"); | |
69 | ||
70 | strcpy(tmp3,TempDir); | |
71 | strcat(tmp3,"/sargtmp.log"); | |
72 | ||
d5d021c5 | 73 | snprintf(arqper,sizeof(arqper),"%s/sarg-general",outdirname); |
25697a35 | 74 | if ((fp_in = fopen(arqper, "r")) == 0){ |
9f70c14e | 75 | debuga(_("(html2) Cannot open file %s\n"),arqper); |
06b39c87 | 76 | exit(EXIT_FAILURE); |
25697a35 | 77 | } |
afaa3b67 | 78 | if ((line=longline_create())==NULL) { |
10210234 | 79 | debuga(_("Not enough memory to read file %s\n"),arqper); |
06b39c87 | 80 | exit(EXIT_FAILURE); |
e5b2c6f0 | 81 | } |
9f20cdae FM |
82 | ttnacc=0; |
83 | totbytes=0; | |
84 | totelap=0; | |
afaa3b67 | 85 | while((buf=longline_read(fp_in,line))!=NULL) { |
2240dcea FM |
86 | ger_read(buf,&item,arqper); |
87 | if(item.total) { | |
88 | ttnacc+=item.nacc; | |
89 | totbytes+=item.nbytes; | |
90 | totelap+=item.nelap; | |
25697a35 GS |
91 | } |
92 | } | |
9f20cdae | 93 | fclose(fp_in); |
afaa3b67 | 94 | longline_destroy(&line); |
25697a35 | 95 | |
d5d021c5 | 96 | snprintf(arqper,sizeof(arqper),"%s/sarg-users",outdirname); |
9f20cdae | 97 | if ((fp_in = fopen(arqper, "r")) == 0){ |
9f70c14e | 98 | debuga(_("(html11) Cannot open file %s\n"),arqper); |
06b39c87 | 99 | exit(EXIT_FAILURE); |
9f20cdae FM |
100 | } |
101 | if (!fgets(totuser,sizeof(totuser),fp_in)) { | |
d5d021c5 | 102 | debuga(_("(html11) read error in %s\n"),arqper); |
06b39c87 | 103 | exit(EXIT_FAILURE); |
9f20cdae | 104 | } |
25697a35 | 105 | fclose(fp_in); |
9f20cdae FM |
106 | ntotuser=my_atoll(totuser); |
107 | if (ntotuser<=0) ntotuser=1; | |
25697a35 | 108 | |
1f482a8d FM |
109 | greport_prepare(); |
110 | ||
e21b6c02 FM |
111 | if ((dirp = opendir(tmp)) == NULL) { |
112 | debuga(_("Failed to open directory %s - %s\n"),tmp,strerror(errno)); | |
113 | exit(EXIT_FAILURE); | |
114 | } | |
25697a35 | 115 | while ( (direntp = readdir( dirp )) != NULL ) { |
936c9905 FM |
116 | dlen=strlen(direntp->d_name)-(sizeof(txtext)-1); |
117 | if (dlen<0) continue; | |
118 | if(strcmp(direntp->d_name+dlen,txtext) != 0) | |
25697a35 GS |
119 | continue; |
120 | ||
121 | count=1; | |
936c9905 | 122 | if (dlen>0) { |
d25d4e6a FM |
123 | if (dlen>=sizeof(user)) continue; |
124 | strncpy(user,direntp->d_name,dlen); | |
125 | user[dlen]=0; | |
936c9905 | 126 | } else { |
d25d4e6a | 127 | user[0]=0; |
25697a35 | 128 | } |
f2ec8c75 | 129 | |
d25d4e6a | 130 | uinfo=userinfo_find_from_file(user); |
f2ec8c75 | 131 | if (!uinfo) { |
10210234 | 132 | debuga(_("Unknown user ID %s in directory %s\n"),user,tmp); |
06b39c87 | 133 | exit(EXIT_FAILURE); |
f2ec8c75 | 134 | } |
d25d4e6a | 135 | str=strrchr(user,'.'); |
936c9905 FM |
136 | if (str) |
137 | strcpy(denied_report,str+1); | |
138 | else | |
d25d4e6a | 139 | strcpy(denied_report,user); |
936c9905 | 140 | |
d5d021c5 FM |
141 | if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,user)>=sizeof(warea)) { |
142 | debuga(_("Destination directory too long: %s/%s\n"),outdirname,user); | |
06b39c87 | 143 | exit(EXIT_FAILURE); |
05b90947 | 144 | } |
25697a35 GS |
145 | mkdir(warea,0755); |
146 | ||
f2ec8c75 FM |
147 | report_day(uinfo); |
148 | greport_day(uinfo); | |
25697a35 | 149 | |
f2ec8c75 | 150 | if (snprintf(arqin,sizeof(arqin),"%s/%s",tmp,direntp->d_name)>=sizeof(arqin)) { |
10210234 | 151 | debuga(_("Input file name too long: %s/%s\n"),tmp,direntp->d_name); |
06b39c87 | 152 | exit(EXIT_FAILURE); |
f2ec8c75 | 153 | } |
d5d021c5 FM |
154 | if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) { |
155 | debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname,uinfo->filename,uinfo->filename); | |
06b39c87 | 156 | exit(EXIT_FAILURE); |
f2ec8c75 FM |
157 | } |
158 | if (snprintf(duser,sizeof(duser),"%s/%s/denied_%s.html",tmp,direntp->d_name,denied_report)>=sizeof(duser)) { | |
10210234 | 159 | debuga(_("File name too long: %s/%s/denied_%s.html\n"),tmp,direntp->d_name,denied_report); |
06b39c87 | 160 | exit(EXIT_FAILURE); |
25697a35 | 161 | } |
25697a35 GS |
162 | if(access(duser, R_OK) != 0) |
163 | denied_report[0]='\0'; | |
936c9905 | 164 | |
25697a35 | 165 | if ((fp_in = fopen(arqin, "r")) == 0){ |
9f70c14e | 166 | debuga(_("(html3) Cannot open file %s\n"),arqin); |
06b39c87 | 167 | exit(EXIT_FAILURE); |
25697a35 | 168 | } |
48864d28 | 169 | |
afaa3b67 | 170 | if ((line=longline_create())==NULL) { |
10210234 | 171 | debuga(_("Not enough memory to read file %s\n"),arqin); |
06b39c87 | 172 | exit(EXIT_FAILURE); |
ac422f9b FM |
173 | } |
174 | ||
9f20cdae FM |
175 | tnacc=0; |
176 | tnbytes=0; | |
177 | tnelap=0; | |
178 | tnincache=0; | |
179 | tnoucache=0; | |
afaa3b67 | 180 | while((buf=longline_read(fp_in,line))!=NULL) { |
e5b2c6f0 | 181 | getword_start(&gwarea,buf); |
0a4e18e1 | 182 | if (getword_atoll(<emp,&gwarea,'\t')<0) { |
10210234 | 183 | debuga(_("There is a broken number of access in file %s\n"),arqin); |
06b39c87 | 184 | exit(EXIT_FAILURE); |
4bcb77cf | 185 | } |
0a4e18e1 FM |
186 | tnacc+=ltemp; |
187 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
10210234 | 188 | debuga(_("There is a broken downloaded size in file %s\n"),arqin); |
06b39c87 | 189 | exit(EXIT_FAILURE); |
4bcb77cf | 190 | } |
0a4e18e1 | 191 | tnbytes+=ltemp; |
e5b2c6f0 | 192 | if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) { |
10210234 | 193 | debuga(_("There is a broken url in file %s\n"),arqin); |
06b39c87 | 194 | exit(EXIT_FAILURE); |
ac422f9b FM |
195 | } |
196 | if (getword_skip(MAXLEN,&gwarea,'\t')<0) { | |
10210234 | 197 | debuga(_("There is a broken access code in file %s\n"),arqin); |
06b39c87 | 198 | exit(EXIT_FAILURE); |
ac422f9b FM |
199 | } |
200 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
10210234 | 201 | debuga(_("There is a broken elapsed time in file %s\n"),arqin); |
06b39c87 | 202 | exit(EXIT_FAILURE); |
4bcb77cf | 203 | } |
0a4e18e1 FM |
204 | tnelap+=ltemp; |
205 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
10210234 | 206 | debuga(_("There is a broken in-cache volume in file %s\n"),arqin); |
06b39c87 | 207 | exit(EXIT_FAILURE); |
4bcb77cf | 208 | } |
0a4e18e1 FM |
209 | tnincache+=ltemp; |
210 | if (getword_atoll(<emp,&gwarea,'\n')<0) { | |
10210234 | 211 | debuga(_("There is a broken out-cache volume in file %s\n"),arqin); |
06b39c87 | 212 | exit(EXIT_FAILURE); |
4bcb77cf | 213 | } |
0a4e18e1 | 214 | tnoucache+=ltemp; |
25697a35 GS |
215 | } |
216 | ||
ec7b26a5 | 217 | rewind(fp_in); |
32d1c674 | 218 | |
25697a35 | 219 | if ((fp_ou = fopen(arqou, "w")) == 0){ |
9f70c14e | 220 | debuga(_("(html5) Cannot open file %s\n"),arqou); |
06b39c87 | 221 | exit(EXIT_FAILURE); |
25697a35 | 222 | } |
32d1c674 | 223 | |
c0ec9cc7 | 224 | write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report")); |
94558017 FM |
225 | fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period.html); |
226 | fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo->label); | |
227 | fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s, %s</td></tr>\n",_("Sort"),UserSortField,UserSortOrder); | |
228 | fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report")); | |
c0ec9cc7 | 229 | close_html_header(fp_ou); |
25697a35 | 230 | |
c0ec9cc7 | 231 | fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou); |
32d1c674 | 232 | |
4157aa09 | 233 | if(denied_report[0]!='\0') { |
c36c7384 | 234 | fprintf(fp_ou,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a> %s</td></tr>\n",denied_report,_("SmartFilter"),_("Report")); |
25697a35 | 235 | } |
32d1c674 | 236 | |
c36c7384 | 237 | fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("ACCESSED SITE")); |
594c9da4 FM |
238 | |
239 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) | |
c36c7384 | 240 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT")); |
594c9da4 | 241 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) |
c36c7384 | 242 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES")); |
594c9da4 | 243 | if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) |
c36c7384 | 244 | fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES")); |
594c9da4 | 245 | if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) |
156404e9 | 246 | fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</th>",_("IN-CACHE-OUT")); |
594c9da4 | 247 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) |
c36c7384 | 248 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME")); |
594c9da4 | 249 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) |
156404e9 | 250 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISEC")); |
594c9da4 | 251 | if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) |
c36c7384 | 252 | fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME")); |
594c9da4 FM |
253 | |
254 | fputs("</tr>\n",fp_ou); | |
32d1c674 | 255 | |
25697a35 | 256 | if(debug) { |
10210234 | 257 | debuga(_("Making report: %s\n"),uinfo->id); |
25697a35 GS |
258 | } |
259 | ||
afaa3b67 | 260 | while((buf=longline_read(fp_in,line))!=NULL) { |
e5b2c6f0 | 261 | getword_start(&gwarea,buf); |
0a4e18e1 | 262 | if (getword_atoll(&twork,&gwarea,'\t')<0) { |
94558017 | 263 | debuga(_("There is a broken number of access in file %s\n"),arqin); |
06b39c87 | 264 | exit(EXIT_FAILURE); |
4157aa09 | 265 | } |
0a4e18e1 | 266 | if (getword_atoll(&nnbytes,&gwarea,'\t')<0) { |
94558017 | 267 | debuga(_("There is a broken number of bytes in file %s\n"),arqin); |
06b39c87 | 268 | exit(EXIT_FAILURE); |
4157aa09 | 269 | } |
e5b2c6f0 | 270 | if (getword_ptr(buf,&url,&gwarea,'\t')<0) { |
94558017 | 271 | debuga(_("There is a broken url in file %s\n"),arqin); |
06b39c87 | 272 | exit(EXIT_FAILURE); |
4157aa09 | 273 | } |
9c7c6346 | 274 | if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) { |
94558017 | 275 | debuga(_("There is a broken access code in file %s\n"),arqin); |
06b39c87 | 276 | exit(EXIT_FAILURE); |
4157aa09 | 277 | } |
0a4e18e1 | 278 | if (getword_atoll(&nnelap,&gwarea,'\t')<0) { |
94558017 | 279 | debuga(_("There is a broken elapsed time in file %s\n"),arqin); |
06b39c87 | 280 | exit(EXIT_FAILURE); |
4157aa09 | 281 | } |
0a4e18e1 | 282 | if (getword_atoll(&incache,&gwarea,'\t')<0) { |
94558017 | 283 | debuga(_("There is a broken in cache column in file %s\n"),arqin); |
06b39c87 | 284 | exit(EXIT_FAILURE); |
4157aa09 | 285 | } |
0a4e18e1 | 286 | if (getword_atoll(&oucache,&gwarea,'\n')<0) { |
94558017 | 287 | debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin,__LINE__); |
06b39c87 | 288 | exit(EXIT_FAILURE); |
4157aa09 | 289 | } |
25697a35 | 290 | |
594c9da4 FM |
291 | if(UserReportLimit<=0 || count<=UserReportLimit) { |
292 | fputs("<tr>",fp_ou); | |
25697a35 | 293 | |
0349fa24 | 294 | if(IndexTree == INDEX_TREE_DATE) |
dfb337be FM |
295 | sprintf(tmp6,"../%s",ImageFile); |
296 | else | |
297 | strcpy(tmp6,"../../images"); | |
25697a35 | 298 | |
c0ec9cc7 | 299 | if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) { |
e5b2c6f0 | 300 | url_to_file(url,siteind,sizeof(siteind)); |
c05462b8 | 301 | fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->filename,siteind,tmp6,_("date/time report")); |
c0ec9cc7 FM |
302 | } else { |
303 | fprintf(fp_ou,"<td class=\"data\"></td>"); | |
304 | } | |
305 | ||
594c9da4 FM |
306 | if(Privacy) |
307 | fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString); | |
308 | else { | |
e5b2c6f0 | 309 | fputs("<td class=\"data2\">",fp_ou); |
594c9da4 | 310 | if(BlockIt[0]!='\0') { |
e5b2c6f0 FM |
311 | fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt); |
312 | output_html_url(fp_ou,url); | |
313 | fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6); | |
314 | } | |
315 | fputs("<a href=\"http://",fp_ou); | |
316 | output_html_url(fp_ou,url); | |
e6c0aebd | 317 | fputs("\">",fp_ou); |
e5b2c6f0 FM |
318 | output_html_string(fp_ou,url,100); |
319 | fputs("</a></td>",fp_ou); | |
594c9da4 | 320 | } |
4157aa09 | 321 | |
594c9da4 FM |
322 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) |
323 | fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(twork,1)); | |
324 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) | |
325 | fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(nnbytes,1)); | |
9f20cdae FM |
326 | if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) { |
327 | perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.; | |
328 | fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc); | |
329 | } | |
330 | if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) { | |
331 | inperc=(nnbytes) ? incache * 100. / nnbytes : 0.; | |
332 | ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.; | |
333 | fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc); | |
334 | } | |
594c9da4 FM |
335 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) |
336 | fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(nnelap)); | |
337 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) | |
338 | fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(nnelap,1)); | |
9f20cdae FM |
339 | if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) { |
340 | perc2=(tnelap) ? nnelap * 100. / tnelap : 0.; | |
341 | fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2); | |
342 | } | |
594c9da4 FM |
343 | |
344 | if(strncmp(tmsg,"OK",2) != 0) | |
c36c7384 | 345 | fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED")); |
594c9da4 FM |
346 | |
347 | fputs("</tr>\n",fp_ou); | |
354c1a68 FM |
348 | count++; |
349 | } | |
25697a35 GS |
350 | |
351 | if(iprel) { | |
d25d4e6a | 352 | if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) { |
10210234 | 353 | debuga(_("File name too long: %s/%s.ip\n"),tmp,uinfo->filename); |
06b39c87 | 354 | exit(EXIT_FAILURE); |
d25d4e6a | 355 | } |
936c9905 | 356 | |
25697a35 | 357 | if ((fp_ip = fopen(arqip, "r")) == 0){ |
9f70c14e | 358 | debuga(_("(html6) Cannot open file %s\n"),arqip); |
06b39c87 | 359 | exit(EXIT_FAILURE); |
25697a35 | 360 | } |
0dda06bf | 361 | |
936c9905 | 362 | if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){ |
9f70c14e | 363 | debuga(_("(html7) Cannot open file %s\n"),tmp2); |
06b39c87 | 364 | exit(EXIT_FAILURE); |
25697a35 | 365 | } |
936c9905 | 366 | |
afaa3b67 | 367 | if ((line1=longline_create())==NULL) { |
10210234 | 368 | debuga(_("Not enough memory to read file %s\n"),arqip); |
06b39c87 | 369 | exit(EXIT_FAILURE); |
e5b2c6f0 | 370 | } |
afaa3b67 | 371 | while((buf=longline_read(fp_ip,line1))!=NULL) { |
25697a35 GS |
372 | if(strstr(buf,url) != 0) |
373 | fputs(buf,fp_ip2); | |
374 | } | |
afaa3b67 | 375 | longline_destroy(&line1); |
936c9905 | 376 | |
25697a35 GS |
377 | fclose(fp_ip); |
378 | fclose(fp_ip2); | |
379 | ||
9a2efbd0 | 380 | sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",TempDir,tmp3,tmp2); |
456d78a5 FM |
381 | cstatus=system(csort); |
382 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
9f70c14e FM |
383 | debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); |
384 | debuga(_("sort command: %s\n"),csort); | |
06b39c87 | 385 | exit(EXIT_FAILURE); |
456d78a5 | 386 | } |
936c9905 FM |
387 | |
388 | if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) { | |
9f70c14e | 389 | debuga(_("(html8) Cannot open file %s\n"),tmp3); |
06b39c87 | 390 | exit(EXIT_FAILURE); |
25697a35 GS |
391 | } |
392 | ||
05b90947 | 393 | olduserip[0]='\0'; |
dfb337be | 394 | |
afaa3b67 | 395 | if ((line1=longline_create())==NULL) { |
10210234 | 396 | debuga(_("Not enough memory to read file %s\n"),arqip); |
06b39c87 | 397 | exit(EXIT_FAILURE); |
e5b2c6f0 | 398 | } |
afaa3b67 | 399 | while((buf=longline_read(fp_ip,line1))!=NULL) { |
9c7c6346 FM |
400 | getword_start(&gwarea,buf); |
401 | if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) { | |
9f70c14e | 402 | debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3); |
06b39c87 | 403 | exit(EXIT_FAILURE); |
05b90947 | 404 | } |
e5b2c6f0 | 405 | if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) { |
d574e592 | 406 | debuga(_("Maybe you have a broken url in your %s file\n"),tmp3); |
06b39c87 | 407 | exit(EXIT_FAILURE); |
05b90947 | 408 | } |
9c7c6346 | 409 | if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) { |
9f70c14e | 410 | debuga(_("Maybe you have a broken day in your %s file\n"),tmp3); |
06b39c87 | 411 | exit(EXIT_FAILURE); |
05b90947 | 412 | } |
9c7c6346 | 413 | if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) { |
9f70c14e | 414 | debuga(_("Maybe you have a broken time in your %s file\n"),tmp3); |
06b39c87 | 415 | exit(EXIT_FAILURE); |
05b90947 | 416 | } |
0a4e18e1 | 417 | if (getword_atoll(&userbytes,&gwarea,'\t')<0) { |
9f70c14e | 418 | debuga(_("Maybe you have a broken size in your %s file\n"),tmp3); |
06b39c87 | 419 | exit(EXIT_FAILURE); |
05b90947 | 420 | } |
0a4e18e1 | 421 | if (getword_atoll(&userelap,&gwarea,'\t')<0) { |
ad7f30fd | 422 | debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3); |
06b39c87 | 423 | exit(EXIT_FAILURE); |
05b90947 | 424 | } |
25697a35 | 425 | if(strcmp(user_ip,olduserip) != 0) { |
25697a35 | 426 | sprintf(wwork1,"%s",fixnum(unbytes,1)); |
f16ba15b FM |
427 | /* |
428 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
429 | to print a long long int unless it is exactly 64-bits long. | |
430 | */ | |
431 | fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%"PRIu64"</td></tr>\n",olduserip,wwork1,buildtime(unelap),(uint64_t)unelap); | |
dfb337be | 432 | |
25697a35 GS |
433 | strcpy(olduserip,user_ip); |
434 | unacc=0; | |
435 | unbytes=0; | |
436 | unelap=0; | |
437 | } | |
dfb337be | 438 | |
0a4e18e1 FM |
439 | unbytes=unbytes+userbytes; |
440 | unelap=unelap+userelap; | |
25697a35 GS |
441 | } |
442 | ||
443 | fclose(fp_ip); | |
afaa3b67 | 444 | longline_destroy(&line1); |
25697a35 GS |
445 | |
446 | unlink(tmp2); | |
447 | unlink(tmp3); | |
448 | ||
25697a35 | 449 | sprintf(wwork1,"%s",fixnum(unbytes,1)); |
f16ba15b FM |
450 | /* |
451 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
452 | to print a long long int unless it is exactly 64-bits long. | |
453 | */ | |
454 | fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%"PRIu64"</td></tr>\n",olduserip,wwork1,buildtime(unelap),(uint64_t)unelap); | |
25697a35 GS |
455 | } |
456 | ||
457 | unacc=0; | |
458 | unbytes=0; | |
459 | unelap=0; | |
25697a35 GS |
460 | } |
461 | ||
9f20cdae | 462 | fclose(fp_in); |
afaa3b67 | 463 | longline_destroy(&line); |
9f20cdae | 464 | |
25697a35 GS |
465 | if(iprel) |
466 | unlink(arqip); | |
467 | unlink(arqin); | |
468 | ||
085c1e1f | 469 | if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) { |
c36c7384 | 470 | fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL")); |
594c9da4 | 471 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) |
b18ce4a0 | 472 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1)); |
594c9da4 | 473 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) |
b18ce4a0 | 474 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1)); |
9f20cdae FM |
475 | if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) { |
476 | perc=(totbytes) ? tnbytes *100. / totbytes :0.; | |
b18ce4a0 | 477 | fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc); |
9f20cdae FM |
478 | } |
479 | if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) { | |
480 | inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.; | |
481 | ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.; | |
b18ce4a0 | 482 | fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc); |
9f20cdae | 483 | } |
594c9da4 | 484 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) |
b18ce4a0 | 485 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap)); |
594c9da4 | 486 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) |
b18ce4a0 | 487 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1)); |
9f20cdae FM |
488 | if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) { |
489 | perc2=(totelap) ? tnelap * 100. / totelap : 0.; | |
b18ce4a0 | 490 | fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2); |
9f20cdae | 491 | } |
594c9da4 | 492 | fputs("</tr>\n",fp_ou); |
25697a35 GS |
493 | } |
494 | ||
e6414a9d FM |
495 | if(PerUserLimit > 0) { |
496 | if(tnbytes > (PerUserLimit*1000000)) { | |
25697a35 GS |
497 | limit_flag=0; |
498 | if(access(PerUserLimitFile, R_OK) == 0) { | |
499 | if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) { | |
bc877ad2 | 500 | debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile); |
06b39c87 | 501 | exit(EXIT_FAILURE); |
25697a35 | 502 | } |
491b862f | 503 | while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) { |
9f20cdae | 504 | fixendofline(tmp6); |
f2ec8c75 | 505 | if(strcmp(tmp6,uinfo->label) == 0) { |
25697a35 GS |
506 | limit_flag=1; |
507 | break; | |
508 | } | |
509 | } | |
510 | fclose(fp_usr); | |
511 | } | |
936c9905 | 512 | |
25697a35 GS |
513 | if(!limit_flag) { |
514 | if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) { | |
9f70c14e | 515 | debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile); |
06b39c87 | 516 | exit(EXIT_FAILURE); |
25697a35 | 517 | } |
f2ec8c75 | 518 | fprintf(fp_usr,"%s\n",uinfo->label); |
25697a35 | 519 | fclose(fp_usr); |
936c9905 | 520 | |
d2fe0c32 | 521 | if(debug) |
10210234 | 522 | debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo->label,PerUserLimit,PerUserLimitFile); |
25697a35 GS |
523 | } |
524 | } | |
525 | } | |
526 | ||
d6e703cc FM |
527 | // if(indexonly) { |
528 | // unlink(arqou); | |
529 | // continue; | |
530 | // } | |
531 | ||
9f20cdae | 532 | if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) { |
0a4e18e1 FM |
533 | totbytes2=totbytes/ntotuser; |
534 | totelap2=totelap/ntotuser; | |
dfb337be | 535 | |
c36c7384 | 536 | fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE")); |
9f20cdae | 537 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) |
b18ce4a0 | 538 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1)); |
9f20cdae | 539 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) |
b18ce4a0 | 540 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1)); |
9f20cdae FM |
541 | fprintf(fp_ou,"<th></th><th></th><th></th>"); |
542 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) | |
b18ce4a0 | 543 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2)); |
9f20cdae | 544 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) |
b18ce4a0 | 545 | fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1)); |
9f20cdae FM |
546 | if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) { |
547 | perc2 = (totelap) ? totelap2 * 100. / totelap : 0.; | |
b18ce4a0 | 548 | fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2); |
936c9905 | 549 | } |
9f20cdae FM |
550 | fputs("</tr>\n",fp_ou); |
551 | } | |
25697a35 | 552 | |
dfb337be | 553 | fputs("</table></div>\n",fp_ou); |
fa6552b0 FM |
554 | if (write_html_trailer(fp_ou)<0) |
555 | debuga(_("Write error in file %s\n"),arqou); | |
556 | if (fclose(fp_ou)==EOF) | |
557 | debuga(_("Failed to close file %s - %s\n"),arqou,strerror(errno)); | |
25697a35 | 558 | |
d25d4e6a | 559 | htaccess(uinfo); |
25697a35 GS |
560 | } |
561 | ||
25697a35 | 562 | (void)closedir(dirp); |
c274f011 | 563 | greport_cleanup(); |
25697a35 GS |
564 | |
565 | return; | |
566 | } |