]>
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 topuser(void) |
25697a35 GS |
31 | { |
32 | ||
491b862f | 33 | FILE *fp_in = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL; |
25697a35 GS |
34 | long long int ttnbytes=0, ttnacc=0, tnacc=0; |
35 | long long int tnbytes=0, ttnelap=0, tnelap=0; | |
36 | long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0; | |
6e792ade FM |
37 | long long int nbytes; |
38 | long long int nacc; | |
39 | long long int elap, incac, oucac; | |
9f20cdae FM |
40 | double perc=0.00; |
41 | double perc2=0.00; | |
42 | double inperc=0.00, ouperc=0.00; | |
25697a35 | 43 | int posicao=0; |
fa6552b0 | 44 | char olduser[MAX_USER_LEN], csort[MAXLEN]; |
25697a35 | 45 | char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; |
2240dcea | 46 | char user[MAX_USER_LEN], tusr[MAXLEN]; |
25697a35 | 47 | char ipantes[MAXLEN], nameantes[MAXLEN]; |
f2ec8c75 | 48 | const char *sfield="-n -k 2,2"; |
49767767 FM |
49 | const char *order; |
50 | const char *sort_field; | |
51 | const char *sort_order; | |
c0ec9cc7 | 52 | char title[80]; |
ac422f9b | 53 | char *warea; |
25697a35 GS |
54 | int totuser=0; |
55 | int topcount=0; | |
456d78a5 | 56 | int cstatus; |
9c7c6346 | 57 | struct getwordstruct gwarea; |
afaa3b67 | 58 | longline line; |
2240dcea | 59 | struct generalitemstruct item; |
f2ec8c75 | 60 | const struct userinfostruct *uinfo; |
25697a35 GS |
61 | |
62 | ipantes[0]='\0'; | |
63 | nameantes[0]='\0'; | |
64 | ||
d6e703cc | 65 | ntopuser = 0; |
13a19c1a | 66 | snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname); |
25697a35 | 67 | if((fp_in=fopen(wger,"r"))==NULL) { |
fcdc0918 | 68 | debuga(_("(topuser) Cannot open file %s\n"),wger); |
06b39c87 | 69 | exit(EXIT_FAILURE); |
25697a35 GS |
70 | } |
71 | ||
13a19c1a | 72 | snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname); |
25697a35 | 73 | if((fp_top2=fopen(top2,"w"))==NULL) { |
fcdc0918 | 74 | debuga(_("(topuser) Cannot open file %s\n"),top2); |
06b39c87 | 75 | exit(EXIT_FAILURE); |
25697a35 GS |
76 | } |
77 | ||
fb7c5f27 FM |
78 | olduser[0]='\0'; |
79 | totuser=0; | |
25697a35 | 80 | |
afaa3b67 | 81 | if ((line=longline_create())==NULL) { |
10210234 | 82 | debuga(_("Not enough memory to read the file %s\n"),wger); |
06b39c87 | 83 | exit(EXIT_FAILURE); |
ac422f9b FM |
84 | } |
85 | ||
afaa3b67 | 86 | while((warea=longline_read(fp_in,line))!=NULL) { |
2240dcea FM |
87 | ger_read(warea,&item,wger); |
88 | if(item.total) continue; | |
89 | if(strcmp(olduser,item.user) != 0) { | |
fb7c5f27 FM |
90 | totuser++; |
91 | ||
92 | if (olduser[0] != '\0') { | |
f16ba15b FM |
93 | /* |
94 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
95 | to print a long long int unless it is exactly 64-bits long. | |
96 | */ | |
97 | fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache); | |
fb7c5f27 FM |
98 | |
99 | ttnbytes+=tnbytes; | |
100 | ttnacc+=tnacc; | |
101 | ttnelap+=tnelap; | |
102 | ttnincache+=tnincache; | |
103 | ttnoucache+=tnoucache; | |
104 | } | |
2240dcea | 105 | strcpy(olduser,item.user); |
25697a35 GS |
106 | tnbytes=0; |
107 | tnacc=0; | |
4157aa09 | 108 | tnelap=0; |
25697a35 GS |
109 | tnincache=0; |
110 | tnoucache=0; | |
111 | } | |
112 | ||
2240dcea FM |
113 | tnbytes+=item.nbytes; |
114 | tnacc+=item.nacc; | |
115 | tnelap+=item.nelap; | |
116 | tnincache+=item.incache; | |
117 | tnoucache+=item.oucache; | |
25697a35 | 118 | } |
9f20cdae | 119 | fclose(fp_in); |
afaa3b67 | 120 | longline_destroy(&line); |
25697a35 | 121 | |
fb7c5f27 | 122 | if (olduser[0] != '\0') { |
f16ba15b FM |
123 | /* |
124 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
125 | to print a long long int unless it is exactly 64-bits long. | |
126 | */ | |
127 | fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache); | |
fb7c5f27 FM |
128 | |
129 | ttnbytes+=tnbytes; | |
130 | ttnacc+=tnacc; | |
131 | ttnelap+=tnelap; | |
132 | ttnincache+=tnincache; | |
133 | ttnoucache+=tnoucache; | |
fb7c5f27 | 134 | } |
9f20cdae | 135 | fclose(fp_top2); |
25697a35 | 136 | |
49767767 | 137 | if((TopuserSort & TOPUSER_SORT_USER) != 0) { |
f2ec8c75 | 138 | sfield="-k 1,1"; |
49767767 FM |
139 | sort_field=_("user"); |
140 | } else if((TopuserSort & TOPUSER_SORT_CONNECT) != 0) { | |
f2ec8c75 | 141 | sfield="-n -k 3,3"; |
49767767 FM |
142 | sort_field=_("connect"); |
143 | } else if((TopuserSort & TOPUSER_SORT_TIME) != 0) { | |
f2ec8c75 | 144 | sfield="-n -k 4,4"; |
49767767 FM |
145 | sort_field=_("time"); |
146 | } else { | |
147 | sort_field=_("bytes"); | |
148 | } | |
25697a35 | 149 | |
49767767 | 150 | if((TopuserSort & TOPUSER_SORT_REVERSE) == 0) { |
f2ec8c75 | 151 | order=""; |
49767767 FM |
152 | sort_order=_("normal"); |
153 | } else { | |
154 | order="-r"; | |
155 | sort_order=_("reverse"); | |
156 | } | |
25697a35 | 157 | |
13a19c1a | 158 | snprintf(top1,sizeof(top1),"%s/top",outdirname); |
e7b4b9e5 | 159 | sprintf(csort,"sort -T \"%s\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2); |
456d78a5 FM |
160 | cstatus=system(csort); |
161 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
10210234 FM |
162 | debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); |
163 | debuga(_("sort command: %s\n"),csort); | |
06b39c87 | 164 | exit(EXIT_FAILURE); |
456d78a5 | 165 | } |
25697a35 | 166 | |
fb7c5f27 | 167 | if((fp_top1=fopen(top1,"r"))==NULL) { |
fcdc0918 | 168 | debuga(_("(topuser) Cannot open file %s\n"),top1); |
06b39c87 | 169 | exit(EXIT_FAILURE); |
fb7c5f27 FM |
170 | } |
171 | ||
9f20cdae FM |
172 | unlink(top2); |
173 | ||
13a19c1a | 174 | snprintf(top3,sizeof(top3),"%s/index.html",outdirname); |
fb7c5f27 | 175 | if((fp_top3=fopen(top3,"w"))==NULL) { |
fcdc0918 | 176 | debuga(_("(topuser) Cannot open file %s\n"),top3); |
06b39c87 | 177 | exit(EXIT_FAILURE); |
fb7c5f27 FM |
178 | } |
179 | ||
fa6552b0 | 180 | snprintf(title,sizeof(title),_("SARG report for %s"),period.text); |
c0ec9cc7 | 181 | write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title); |
fcdc0918 | 182 | fputs("<tr><td class=\"header_c\">",fp_top3); |
fd46f082 | 183 | fprintf(fp_top3,_("Period: %s"),period.html); |
fcdc0918 | 184 | fputs("</td></tr>\n",fp_top3); |
49767767 FM |
185 | fputs("<tr><td class=\"header_c\">",fp_top3); |
186 | fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order); | |
187 | fputs("</td></tr>\n",fp_top3); | |
fcdc0918 | 188 | fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users")); |
c0ec9cc7 | 189 | close_html_header(fp_top3); |
9f20cdae | 190 | |
c0ec9cc7 | 191 | fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3); |
25697a35 | 192 | |
fcdc0918 | 193 | if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"topsites.html\">%s</a></td></tr>\n",_("Top sites")); |
c36c7384 FM |
194 | if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"siteuser.html\">%s</a></td></tr>\n",_("Sites & Users")); |
195 | if(dansguardian_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"dansguardian.html\">%s</a></td></tr>\n",_("DansGuardian")); | |
987e8375 | 196 | if(squidguard_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",_("Redirector")); |
c36c7384 | 197 | if ((ReportType & REPORT_TYPE_DOWNLOADS) != 0 && download_count && !Privacy && ndownload) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"download.html\">%s</a></td></tr>\n",_("Downloads")); |
68c0b61b | 198 | if ((ReportType & REPORT_TYPE_DENIED) != 0 && denied_count && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",_("Denied accesses")); |
c36c7384 FM |
199 | if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0 && authfail_count && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",_("Authentication Failures")); |
200 | if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"smartfilter.html\">%s</a></td></tr>\n",_("SmartFilter")); | |
c0ec9cc7 | 201 | if(UserAgentLog[0] != '\0' && useragent_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"useragent.html\">%s</a></td></tr>\n",_("Useragent")); |
5a1b55b7 | 202 | fputs("<tr><td></td></tr>\n</table></div>\n",fp_top3); |
25697a35 | 203 | |
085c1e1f | 204 | if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { |
491b862f | 205 | fputs("</body>\n</html>\n",fp_top3); |
9f20cdae | 206 | fclose (fp_top3); |
491b862f GS |
207 | return; |
208 | } | |
fb7c5f27 | 209 | |
5a1b55b7 | 210 | fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3); |
9f20cdae FM |
211 | fputs("<tr>",fp_top3); |
212 | ||
213 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
c36c7384 | 214 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("NUM")); |
9f20cdae | 215 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) |
b18ce4a0 | 216 | fputs("<th class=\"header_l\"></th>",fp_top3); |
9f20cdae | 217 | if((TopUserFields & TOPUSERFIELDS_USERID) != 0) |
c36c7384 | 218 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("USERID")); |
9f20cdae | 219 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) |
c36c7384 | 220 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("CONNECT")); |
9f20cdae | 221 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) |
c36c7384 | 222 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("BYTES")); |
9f20cdae | 223 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) |
c36c7384 | 224 | fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",_("BYTES")); |
9f20cdae | 225 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) |
156404e9 | 226 | fprintf(fp_top3,"<th class=\"header_c\" colspan=\"2\">%s</th>",_("IN-CACHE-OUT")); |
9f20cdae | 227 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) |
c36c7384 | 228 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME")); |
9f20cdae | 229 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) |
156404e9 | 230 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("MILLISEC")); |
9f20cdae | 231 | if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) |
c36c7384 | 232 | fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",_("TIME")); |
9f20cdae FM |
233 | |
234 | fputs("</tr>\n",fp_top3); | |
25697a35 | 235 | |
d6e703cc | 236 | ntopuser = 0; |
25697a35 | 237 | |
afaa3b67 | 238 | if ((line=longline_create())==NULL) { |
10210234 | 239 | debuga(_("Not enough memory to read the downloaded files\n")); |
06b39c87 | 240 | exit(EXIT_FAILURE); |
ac422f9b FM |
241 | } |
242 | ||
afaa3b67 | 243 | while((warea=longline_read(fp_top1,line))!=NULL) { |
9c7c6346 FM |
244 | getword_start(&gwarea,warea); |
245 | if (getword(user,sizeof(user),&gwarea,'\t')<0) { | |
10210234 | 246 | debuga(_("There is a broken user in file %s\n"),top1); |
06b39c87 | 247 | exit(EXIT_FAILURE); |
05b90947 | 248 | } |
6e792ade | 249 | if (getword_atoll(&nbytes,&gwarea,'\t')<0) { |
10210234 | 250 | debuga(_("There is a broken number of bytes in file %s\n"),top1); |
06b39c87 | 251 | exit(EXIT_FAILURE); |
05b90947 | 252 | } |
6e792ade | 253 | if (getword_atoll(&nacc,&gwarea,'\t')<0) { |
10210234 | 254 | debuga(_("There is a broken number of access in file %s\n"),top1); |
06b39c87 | 255 | exit(EXIT_FAILURE); |
05b90947 | 256 | } |
6e792ade | 257 | if (getword_atoll(&elap,&gwarea,'\t')<0) { |
10210234 | 258 | debuga(_("There is a broken elpased time in file %s\n"),top1); |
06b39c87 | 259 | exit(EXIT_FAILURE); |
05b90947 | 260 | } |
6e792ade | 261 | if (getword_atoll(&incac,&gwarea,'\t')<0) { |
10210234 | 262 | debuga(_("There is a broken in-cache size in file %s\n"),top1); |
06b39c87 | 263 | exit(EXIT_FAILURE); |
05b90947 | 264 | } |
6e792ade | 265 | if (getword_atoll(&oucac,&gwarea,'\n')<0) { |
10210234 | 266 | debuga(_("There is a broken out-of-cache size in file %s\n"),top1); |
06b39c87 | 267 | exit(EXIT_FAILURE); |
05b90947 | 268 | } |
9f20cdae | 269 | if(nacc < 1) |
d6e703cc | 270 | continue; |
05b90947 | 271 | ntopuser = 1; |
c0ec9cc7 | 272 | if(TopUsersNum > 0 && topcount >= TopUsersNum) break; |
6e792ade | 273 | tnbytes=nbytes; |
6e792ade | 274 | tnelap=elap; |
25697a35 | 275 | |
f2ec8c75 FM |
276 | uinfo=userinfo_find_from_id(user); |
277 | if (!uinfo) { | |
10210234 | 278 | debuga(_("Unknown user ID %s in file %s\n"),user,top1); |
06b39c87 | 279 | exit(EXIT_FAILURE); |
25697a35 | 280 | } |
dfb337be | 281 | |
9f20cdae | 282 | fputs("<tr>",fp_top3); |
25697a35 | 283 | |
9f20cdae FM |
284 | posicao++; |
285 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
286 | fprintf(fp_top3,"<td class=\"data\">%d</td>",posicao); | |
25697a35 | 287 | |
9f20cdae | 288 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) { |
9f20cdae | 289 | fputs("<td class=\"data2\">",fp_top3); |
25697a35 | 290 | #ifdef HAVE_GD |
3becf85c | 291 | if(Graphs && GraphFont[0]!='\0') { |
7f2382f6 FM |
292 | //fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a> ",uinfo->filename,ImageFile,_("Graphic")); |
293 | fprintf(fp_top3,"<a href=\"%s/graph.html\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a> ",uinfo->filename,ImageFile,_("Graphic")); | |
9f20cdae | 294 | } |
25697a35 | 295 | #endif |
1b81f396 | 296 | fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->filename,uinfo->filename,ImageFile,_("date/time report")); |
9f20cdae | 297 | } else { |
d5d021c5 | 298 | sprintf(val1,"%s/d%s.html",outdirname,uinfo->filename); |
9f20cdae | 299 | unlink(val1); |
25697a35 | 300 | } |
9f20cdae FM |
301 | if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { |
302 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) | |
303 | fprintf(fp_top3,"<td class=\"data2\">%s</td>",name); | |
304 | else | |
f2ec8c75 | 305 | fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label); |
25697a35 | 306 | } |
9f20cdae FM |
307 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) |
308 | fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(nacc,1)); | |
309 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) | |
310 | fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(tnbytes,1)); | |
311 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) { | |
312 | perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.; | |
313 | fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc); | |
25697a35 | 314 | } |
9f20cdae FM |
315 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) { |
316 | inperc=(tnbytes) ? incac * 100. / tnbytes : 0.; | |
317 | ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.; | |
318 | fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc); | |
65b4ec2c FM |
319 | #ifdef ENABLE_DOUBLE_CHECK_DATA |
320 | if (fabs(inperc+ouperc-100.)>=0.01) { | |
04a01ed3 | 321 | debuga(_("The total of the in-cache and cache-miss is not 100%% at position %d of user %s\n"),posicao,uinfo->label); |
65b4ec2c FM |
322 | } |
323 | #endif | |
25697a35 | 324 | } |
9f20cdae FM |
325 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) |
326 | fprintf(fp_top3,"<td class=\"data\">%s</td>",buildtime(tnelap)); | |
327 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) | |
328 | fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum2(tnelap,1)); | |
329 | if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) { | |
330 | perc2=(ttnelap) ? elap * 100. / ttnelap : 0.; | |
331 | fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc2); | |
dfb337be | 332 | } |
25697a35 | 333 | |
9f20cdae | 334 | fputs("</tr>\n",fp_top3); |
25697a35 GS |
335 | |
336 | topcount++; | |
25697a35 | 337 | } |
c0ec9cc7 FM |
338 | fclose(fp_top1); |
339 | unlink(top1); | |
afaa3b67 | 340 | longline_destroy(&line); |
25697a35 | 341 | |
9f20cdae | 342 | if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) { |
9f20cdae FM |
343 | fputs("<tr>",fp_top3); |
344 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
345 | fputs("<td></td>",fp_top3); | |
346 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) | |
347 | fputs("<td></td>",fp_top3); | |
c36c7384 | 348 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL")); |
9f20cdae FM |
349 | |
350 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) | |
b18ce4a0 | 351 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc,1)); |
9f20cdae | 352 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) |
b18ce4a0 | 353 | fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(ttnbytes,1)); |
9f20cdae FM |
354 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) |
355 | fputs("<td></td>",fp_top3); | |
356 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) | |
357 | { | |
358 | inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.; | |
359 | ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.; | |
b18ce4a0 | 360 | fprintf(fp_top3,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc); |
65b4ec2c FM |
361 | #ifdef ENABLE_DOUBLE_CHECK_DATA |
362 | if (fabs(inperc+ouperc-100.)>=0.01) { | |
04a01ed3 | 363 | debuga(_("The total of the in-cache and cache-miss is not 100%% for user %s\n"),uinfo->label); |
65b4ec2c FM |
364 | } |
365 | #endif | |
9f20cdae FM |
366 | } |
367 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) | |
b18ce4a0 | 368 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap)); |
9f20cdae | 369 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) |
b18ce4a0 | 370 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap,1)); |
9f20cdae FM |
371 | |
372 | fputs("</tr>\n",fp_top3); | |
25697a35 GS |
373 | } |
374 | ||
9f20cdae FM |
375 | if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) { |
376 | fputs("<tr>",fp_top3); | |
377 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
378 | fputs("<td></td>",fp_top3); | |
379 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) | |
380 | fputs("<td></td>",fp_top3); | |
c36c7384 | 381 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE")); |
9f20cdae FM |
382 | |
383 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) | |
b18ce4a0 | 384 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/totuser,1)); |
9f20cdae FM |
385 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) { |
386 | tnbytes=(totuser) ? ttnbytes / totuser : 0; | |
b18ce4a0 | 387 | fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(tnbytes,1)); |
9f20cdae FM |
388 | } |
389 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) | |
390 | fputs("<td></td>",fp_top3); | |
391 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) | |
392 | fputs("<td></td><td></td>",fp_top3); | |
393 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) | |
b18ce4a0 | 394 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap/totuser)); |
9f20cdae | 395 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) |
b18ce4a0 | 396 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap/totuser,1)); |
9f20cdae | 397 | fputs("</tr>\n",fp_top3); |
25697a35 GS |
398 | } |
399 | ||
c0ec9cc7 | 400 | fputs("</table></div>\n",fp_top3); |
fa6552b0 FM |
401 | if (write_html_trailer(fp_top3)<0) |
402 | debuga(_("Write error in top user list %s\n"),top3); | |
403 | if (fclose(fp_top3)==EOF) | |
404 | debuga(_("Failed to close the top user list %s - %s\n"),top3,strerror(errno)); | |
25697a35 | 405 | |
13a19c1a | 406 | snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname); |
25697a35 | 407 | if((fp_ou=fopen(tusr,"w"))==NULL) { |
fcdc0918 | 408 | debuga(_("(topuser) Cannot open file %s\n"),tusr); |
06b39c87 | 409 | exit(EXIT_FAILURE); |
25697a35 | 410 | } |
d6e703cc | 411 | fprintf(fp_ou,"%d\n",totuser); |
13a19c1a FM |
412 | if (fclose(fp_ou)==EOF) |
413 | debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno)); | |
25697a35 GS |
414 | |
415 | return; | |
416 | } |