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