minor bugfixes (#ifdef MONITORINGTRHU)
[svn/Prometheus-QoS/.git] / htmlandlogs.c
... / ...
CommitLineData
1/* Modified by: xChaos, 20131119 */\r
2\r
3#include "cll1-0.6.2.h"\r
4#include "ipstruct.h"\r
5#define STRLEN 512\r
6\r
7extern int row_odd_even;\r
8extern int use_jquery_popups;\r
9extern struct IP *ips, *ip, *sharedip;\r
10extern struct Group *groups, *group;\r
11extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
12extern const int highest_priority;\r
13extern const char *version;\r
14extern const char *stats_html_signature;\r
15extern char *jquery_url;\r
16extern int keywordcount;\r
17extern int dry_run;\r
18extern int qos_proxy;\r
19extern char *title;\r
20extern char *log_url;\r
21extern int found_lmsid;\r
22extern char *lms_url;\r
23extern char *log_dir;\r
24extern char *ip6prefix;\r
25extern int traffic_detected;\r
26\r
27const char *tr_odd_even(void);\r
28/* implemented in prometheus.c, shared with parselogs.c */\r
29\r
30void append_log(struct IP *self) /*using global variables*/\r
31{\r
32 char *d, *str;\r
33 FILE *f; \r
34\r
35 date(d); /* this is typical cll1.h macro - prints current date */ \r
36 string(str, STRLEN); \r
37 sprintf(str, "%s/%s.log", log_dir, self->name);\r
38\r
39 /*-----------------------------------------------------------------*/\r
40 printf("Writing traffic log %s ...\n", str);\r
41 /*-----------------------------------------------------------------*/\r
42 f = fopen(str, "a");\r
43 if(f > 0)\r
44 {\r
45 fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
46 time(NULL), self->name, self->traffic, self->direct, self->proxy,\r
47 self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/\r
48 fclose(f);\r
49 }\r
50 else\r
51 {\r
52 perror(str);\r
53 }\r
54}\r
55\r
56void write_htmlandlogs(char *html, char *d, int total, int just_preview)\r
57{\r
58 int i;\r
59 char *str;\r
60 FILE *f=fopen(html, "w");\r
61\r
62 string(str,STRLEN); \r
63 if(f > 0)\r
64 {\r
65 int count=1;\r
66 i=0;\r
67\r
68 if(use_jquery_popups)\r
69 {\r
70 fprintf(f,"<script type=\"text/javascript\" src=\"%s\"></script>\n", jquery_url);\r
71 }\r
72 fputs("<table class=\"decorated last\">\n\\r
73<caption>Bandwidth classes</caption>\n\\r
74<thead><tr>\n\\r
75<th style=\"text-align: right\">#</th>\n\\r
76<th style=\"text-align: right\">group</th>\n\\r
77<th style=\"text-align: right\">IPs</th>\n\\r
78<th style=\"text-align: right\">requested</th>\n",f);\r
79 fprintf(f,"<th colspan=\"%d\">data limits</th>\n", keywordcount);\r
80 fputs("</tr></thead><tbody>\n",f);\r
81\r
82 row_odd_even = 0;\r
83 for_each(group, groups) \r
84 { \r
85#ifdef DEBUG\r
86 printf("%d kb/s group: %d bandwidth requested: %d kb/s\n",group->min,group->count,group->desired);\r
87#endif\r
88 fprintf(f, "%s<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d&nbsp;kb/s</td>",\r
89 tr_odd_even(), count, group->min);\r
90 fprintf(f, "<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d&nbsp;kb/s</td>",\r
91 group->count, group->desired);\r
92\r
93 for_each(keyword, keywords) if(keyword->ip_count)\r
94 {\r
95 fprintf(f, "<td style=\"text-align: right\"><span style=\"color:#%s\">%d&nbsp;MB</span></td>",\r
96 keyword->html_color, group->min*keyword->data_limit);\r
97 } \r
98 i += group->desired; \r
99 total += group->count;\r
100 count++; \r
101 }\r
102#ifdef DEBUG\r
103 printf("Total groups: %d Total bandwidth requested: %d kb/s\n",\r
104 count, i, i);\r
105#endif\r
106 fprintf(f,"</tr></tbody>\n\\r
107<thead><tr>\n\\r
108<th colspan=\"2\" style=\"text-align: left\"></td>");\r
109 fprintf(f,"<th style=\"text-align: right\">%d</td><th style=\"text-align: right\">%d kb/s</td>",total,i);\r
110\r
111 for_each(keyword, keywords) if(keyword->ip_count)\r
112 {\r
113 fprintf(f,"<th style=\"text-align: right\">%d IPs</th>",keyword->ip_count);\r
114 }\r
115 fprintf(f,"</tr><tr><th colspan=\"4\"></th>\n");\r
116 fprintf(f,"<th colspan=\"%d\">%d traffic classes</th></tr>\n", keywordcount, total);\r
117\r
118 fputs("</thead></table>\n",f);\r
119 }\r
120 else\r
121 {\r
122 perror(html);\r
123 }\r
124\r
125 i=0;\r
126 if(f > 0)\r
127 {\r
128 unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0;\r
129 unsigned long long total_pktup = 0, total_pktdown = 0;\r
130 int active_classes = 0;\r
131// int colspan = 14;\r
132 struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL;\r
133 int agreg_count = 0, limit_count = 0, prio_count = 0;\r
134 int popup_button = 0;\r
135 /* IPv6 vs. IPv4 stats */\r
136 unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0;\r
137 int count4 = 0, count6 = 0;\r
138 int mpkts;\r
139 double perc6;\r
140\r
141/*\r
142 if(qos_proxy)\r
143 {\r
144 colspan++;\r
145 }\r
146*/ \r
147 if(use_jquery_popups)\r
148 {\r
149 fprintf(f,"<script type=\"text/javascript\">\\r
150function show_section(n) {\\r
151$(\'#sharing_\'+n).show();\\r
152$(\'#download_'+n).show();\\r
153$(\'#pktsdown_\'+n).show();\\r
154$(\'#upload_'+n).show();\\r
155$(\'#pktsup_\'+n).show();\\r
156} </script>");\r
157 }\r
158\r
159 fprintf(f,"<p><table class=\"decorated last\">\n<caption>%s",title);\r
160 fprintf(f," (%s)</caption>\n", d);\r
161 fputs("<thead><tr>\n<th colspan=\"3\">&nbsp;</th>\n",f);\r
162 fputs("<th style=\"text-align: right\">cred.</th>\n\\r
163<th style=\"text-align: right\">FUP</th>\n\\r
164<th style=\"text-align: right\">total</th>\n\\r
165<th style=\"text-align: center\" colspan=\"2\">upload</th>\n",f);\r
166/*\r
167 if(qos_proxy)\r
168 {\r
169 fputs("<th style=\"text-align: right\">proxy</th>\n",f);\r
170 }\r
171*/\r
172 fputs("<th style=\"text-align: center\" colspan=\"2\">download</th>\n\\r
173<th style=\"text-align: right\">min</th>\n\\r
174<th style=\"text-align: right\">max</th>\n\\r
175<th style=\"text-align: right\">limit</th>\n\\r
176<th>&nbsp;</th>\n\\r
177</tr><tr>\n\\r
178<th style=\"text-align: right\">#</th>\n\\r
179<th>hostname [+sharing]</th>\n\\r
180<th style=\"text-align: right\">LMS</th>\n\\r
181<th style=\"text-align: right\">MB</th>\n\\r
182<th style=\"text-align: right\">MB</th>\n\\r
183<th style=\"text-align: right\">MB</th>\n\\r
184<th style=\"text-align: right\">MB</th>\n\\r
185<th style=\"text-align: right\">pkt</th>\n\\r
186<th style=\"text-align: right\">MB</th>\n\\r
187<th style=\"text-align: right\">pkt</th>\n\\r
188<th style=\"text-align: right\">kb/s</th>\n\\r
189<th style=\"text-align: right\">kb/s</th>\n\\r
190<th style=\"text-align: right\">kb/s</th>\n\\r
191<th>!</th>\n\\r
192</tr></thead><tbody>\n",f); \r
193\r
194 row_odd_even = 0;\r
195 for_each(ip,ips) if(!use_jquery_popups || !ip->sharing)\r
196 {\r
197 char *f1="", *f2="";\r
198 i++;\r
199\r
200 if(ip->aggregated > 1)\r
201 {\r
202 f1 = "<span style=\"color:green\">";\r
203 f2 = "</span>"; \r
204 agreg_count++;\r
205 }\r
206 else if(ip->max < ip->desired) \r
207 {\r
208 f1 = "<span style=\"color:red\">";\r
209 f2 = "</span>"; \r
210 limit_count++; \r
211 }\r
212 else if(ip->prio > highest_priority+1)\r
213 {\r
214 f1 = "<span style=\"color:brown\">";\r
215 f2 = "</span>";\r
216 prio_count++; \r
217 } \r
218\r
219#ifdef DEBUG\r
220 printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r
221#endif\r
222 /* hostnames -------------------------------------- */\r
223 fprintf(f,"%s<td style=\"text-align: right\"><a name=\"%s\"></a>%d</td>\\r
224<td><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r
225 tr_odd_even(), ip->name, i, log_url, ip->name, ip->name);\r
226\r
227 if(use_jquery_popups)\r
228 {\r
229 fprintf(f, "<span id=\"sharing_%d\" style=\"display:none\">",i);\r
230 popup_button=0;\r
231\r
232 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
233 {\r
234 fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r
235 log_url, sharedip->name, sharedip->name);\r
236 popup_button++;\r
237 }\r
238\r
239 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
240 {\r
241 fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/%d</a>\n", \r
242 log_url, sharedip->addr, sharedip->addr, sharedip->mask);\r
243 popup_button++;\r
244 }\r
245\r
246 fputs("</span>\n",f);\r
247 if(popup_button)\r
248 {\r
249 fprintf(f, "<span>[<a class=\"blue\" href=\"#\" \\r
250onClick=\"$(this).parent().hide();show_section(\'%d\');return(false);\" \\r
251style=\"cursor: pointer;\">+%d</a>]</span>",\r
252 i, popup_button);\r
253 }\r
254 }\r
255 fputs("</td>\n",f);\r
256 /* ----------------------------------------------- */\r
257\r
258 if(found_lmsid)\r
259 {\r
260 fputs("<td style=\"text-align: right\">",f);\r
261 if(ip->lmsid > 0)\r
262 {\r
263 fprintf(f, "<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n",\r
264 lms_url, ip->lmsid, ip->lmsid);\r
265 }\r
266 else if(ip->lmsid == 0)\r
267 {\r
268 fputs("------",f);\r
269 }\r
270 fputs("</td>\n",f);\r
271 }\r
272 fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->credit);\r
273 fprintf(f,"<td style=\"text-align: right\"><span style=\"color:#%s\">%Lu</span></td>",\r
274 ip->keyword->html_color, ip->realquota);\r
275 fprintf(f,"<td style=\"text-align: right\">%s%Lu%s</td>", f1, ip->traffic, f2);\r
276\r
277 /* upload --------------------------------------- */\r
278 fprintf(f,"<td style=\"text-align: right\">%Lu", ip->upload);\r
279 if(use_jquery_popups)\r
280 {\r
281 fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">", i);\r
282 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
283 {\r
284 fprintf(f,"<br />%Lu", sharedip->upload);\r
285 }\r
286 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
287 {\r
288 fprintf(f,"<br />%Lu", sharedip->upload);\r
289 }\r
290 fputs("</span>\n",f);\r
291 }\r
292 fputs("</td>\n",f);\r
293\r
294 /* pkts up ----------------------------------- */\r
295 mpkts = ip->pktsup>>20;\r
296 total_pktup += mpkts;\r
297 if(mpkts == 0)\r
298 {\r
299 mpkts = 1; /* prevent divide by zero*/\r
300 }\r
301 fprintf(f,"<td style=\"text-align: right\"><span style=\"color: gray\">%d</span>", ip->upload/mpkts);\r
302 if(use_jquery_popups)\r
303 {\r
304 fprintf(f,"<span id=\"pktsup_%d\" style=\"display:none\">", i);\r
305 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
306 {\r
307 mpkts = sharedip->pktsup>>20;\r
308 if(mpkts == 0)\r
309 {\r
310 mpkts = 1; /* prevent divide by zero*/\r
311 } \r
312 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->upload/mpkts);\r
313 }\r
314 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
315 {\r
316 mpkts = sharedip->pktsup>>20;\r
317 if(mpkts == 0)\r
318 {\r
319 mpkts = 1; /* prevent divide by zero*/\r
320 } \r
321 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->upload/mpkts);\r
322 }\r
323 fputs("</span>\n",f);\r
324 }\r
325 fputs("</td>\n",f);\r
326\r
327/*\r
328 if(qos_proxy)\r
329 {\r
330 fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->proxy);\r
331 }\r
332*/\r
333 /* download ---------------------------------------- */\r
334 fprintf(f,"<td style=\"text-align: right\">%Lu", ip->direct);\r
335 if(use_jquery_popups)\r
336 {\r
337 fprintf(f,"<span id=\"download_%d\" style=\"display:none\">", i);\r
338 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
339 {\r
340 fprintf(f,"<br />%Lu", sharedip->direct);\r
341 }\r
342 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
343 {\r
344 fprintf(f,"<br />%Lu", sharedip->direct);\r
345 }\r
346 fputs("</span>\n",f);\r
347 }\r
348 fputs("</td>\n",f);\r
349\r
350 /* pkts down ---------------------------------------- */\r
351 mpkts = ip->pktsdown>>20;\r
352 total_pktdown += mpkts;\r
353 if(mpkts == 0)\r
354 {\r
355 mpkts = 1; /* prevent divide by zero*/\r
356 }\r
357 fprintf(f,"<td style=\"text-align: right\"><span style=\"color: gray\">%d</span>", ip->direct/mpkts);\r
358 if(use_jquery_popups)\r
359 {\r
360 fprintf(f,"<span id=\"pktsdown_%d\" style=\"display:none\">", i);\r
361 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
362 {\r
363 mpkts = sharedip->pktsdown>>20;\r
364 if(mpkts == 0)\r
365 {\r
366 mpkts = 1; /* prevent divide by zero*/\r
367 } \r
368 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->direct/mpkts);\r
369 }\r
370 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
371 {\r
372 mpkts = sharedip->pktsdown>>20;\r
373 if(mpkts == 0)\r
374 {\r
375 mpkts = 1; /* prevent divide by zero*/\r
376 } \r
377 fprintf(f,"<br /><span style=\"color: gray\">%d</span>", sharedip->direct/mpkts);\r
378 }\r
379 fputs("</span>\n",f);\r
380 }\r
381 fputs("</td>\n",f);\r
382 /* ----------------------------------------------- */\r
383\r
384 fprintf(f, "<td style=\"text-align: right\">%d</td>\n\\r
385<td style=\"text-align: right\">%d</td>\n\\r
386<td style=\"text-align: right\">%s%d%s</td>\n\\r
387<td>%s%d%s</td></tr>\n",\r
388 ip->min, ip->desired, \r
389 f1, ip->max, f2, \r
390 f1, ip->prio, f2);\r
391\r
392 total_traffic+=ip->traffic;\r
393 total_direct+=ip->direct;\r
394 total_proxy+=ip->proxy;\r
395 total_upload+=ip->upload;\r
396 if(ip->traffic>0)\r
397 {\r
398 active_classes++;\r
399 tmp_sum+=ip->traffic;\r
400 create(sum,Sum);\r
401 sum->l=tmp_sum;\r
402 sum->i=active_classes;\r
403 insert(sum,sums,order_by,i);\r
404 }\r
405\r
406 if(!just_preview && traffic_detected)\r
407 {\r
408 append_log(ip);\r
409 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))\r
410 {\r
411 append_log(sharedip);\r
412 }\r
413 }\r
414 else\r
415 {\r
416 printf(".");\r
417 }\r
418 }\r
419 fprintf(f, "</tbody><thead><tr>\n\\r
420<th colspan=\"5\" style=\"text-align: left\">%d CLASSES</th>", i);\r
421 fprintf(f, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\\r
422<th style=\"text-align: right\">%d</th>\n",\r
423 total_traffic, total_upload, total_pktup/i);\r
424/*\r
425 if(qos_proxy)\r
426 {\r
427 fprintf(f," <th style=\"text-align: right\">%Lu</th>\n", total_proxy);\r
428 }\r
429*/\r
430 fprintf(f, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%d</th>",\r
431 total_direct, total_pktdown/i);\r
432 fprintf(f, "<th colspan=\"6\">\\r
433<span style=\"color:green\">AGR %dx</span> \\r
434<span style=\"color:red\">FUP %dx</span> \\r
435<span style=\"color:brown\">PRIO %dx</span></th></tr>\n</thead></table>\n",\r
436 agreg_count, limit_count, prio_count);\r
437\r
438 if(ip6prefix)\r
439 { \r
440 for_each(ip, ips)\r
441 { \r
442 if(ip->v6)\r
443 {\r
444 bytes6 += ip->upload + ip->direct;\r
445 pkts6 += ip->pktsdown + ip->pktsup;\r
446 count6++;\r
447 }\r
448 else\r
449 {\r
450 bytes4 += ip->upload + ip->direct;\r
451 pkts4 += ip->pktsdown + ip->pktsup;\r
452 count4++;\r
453 }\r
454 }\r
455\r
456 perc6=(double)(bytes6)/(bytes4+bytes6)*100;\r
457 fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f);\r
458 fprintf(f, "%s<td>Total %d IPv4 addreses</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%.2f %%)</td></tr>\n",\r
459 tr_odd_even(), count4, bytes4, (double)(bytes4)/(bytes4+bytes6)*100, pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r
460 fprintf(f, "%s<td>Total %d IPv6 /64 ranges</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%.2f %%)</td></tr>\n",\r
461 tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r
462 fputs("</table></p>\n", f);\r
463 }\r
464\r
465 row_odd_even = 0;\r
466 if(active_classes>10)\r
467 {\r
468 int top20_count=0,top20_perc1=0;\r
469 long long top20_perc2=0;\r
470 unsigned long long top20_sum=0l;\r
471 \r
472 fputs("<a name=\"erp\"></a><p><table class=\"decorated last\"><caption>Enterprise Resource Planning (ERP)</caption>\n",f);\r
473 fputs("<thead><tr>\n\\r
474<th>Analytic category</th>\n\\r
475<th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\\r
476<th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\\r
477</tr></thead><tbody>\n",f);\r
478\r
479 if_exists(sum,sums,sum->l >= total_traffic/4)\r
480 {\r
481 fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r
482 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
483<td style=\"text-align: right\">%d %%</td>\n\\r
484<td style=\"text-align: right\">%Lu MB</td>\n\\r
485<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
486 sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r
487 }\r
488 \r
489 if_exists(sum,sums,sum->i == 10)\r
490 {\r
491 fprintf(f,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());\r
492 fprintf(f,"<td style=\"text-align: right\"><strong>10</strong></td>\n\\r
493<td style=\"text-align: right\">%d %%</td>\n\\r
494<td style=\"text-align: right\">%Lu MB</td>\n\\r
495<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
496 (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r
497 }\r
498\r
499 if_exists(sum,sums,sum->l >= total_traffic/2)\r
500 {\r
501 fprintf(f,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());\r
502 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
503<td style=\"text-align: right\">%d %%</td>\n\\r
504<td style=\"text-align: right\">%Lu MB</td>\n\\r
505<td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r
506 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
507 }\r
508\r
509 if_exists(sum,sums,sum->l >= 4*total_traffic/5)\r
510 {\r
511 fprintf(f,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());\r
512 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
513<td style=\"text-align: right\">%d %%</td>\n\\r
514<td style=\"text-align: right\">%Lu MB</td>\n\\r
515<td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",\r
516 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
517 }\r
518\r
519 if_exists(sum,sums,sum->i >= (active_classes+1)/5)\r
520 {\r
521 fprintf(f,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());\r
522 top20_count=sum->i;\r
523 top20_perc1=(100*sum->i+50)/active_classes;\r
524 top20_sum=sum->l;\r
525 top20_perc2=(100*sum->l+50)/total_traffic;\r
526 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
527<td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
528<td style=\"text-align: right\">%Lu MB</td>\n\\r
529<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
530 top20_count,top20_perc1,top20_sum,top20_perc2);\r
531 }\r
532\r
533 if_exists(sum,sums,sum->i >= (active_classes+1)/4)\r
534 {\r
535 fprintf(f,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());\r
536 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
537<td style=\"text-align: right\">%d %%</td>\n\\r
538<td style=\"text-align: right\">%Lu MB</td>\n\\r
539<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
540 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
541 }\r
542\r
543 if_exists(sum,sums,sum->i>=(active_classes+1)/2)\r
544 {\r
545 fprintf(f,"%s<td>Top 50%% downloaders</td>\n", tr_odd_even());\r
546 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
547<td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
548<td style=\"text-align: right\">%Lu MB</td>\n\\r
549<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
550 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
551 }\r
552\r
553 if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5)\r
554 {\r
555 fprintf(f,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());\r
556 fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
557<td style=\"text-align: right\">%d %%</td>\n\\r
558<td style=\"text-align: right\">%Lu MB</td>\n\\r
559<td style=\"text-align: right\">%Ld %%</td></tr></tbody>\n",\r
560 sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
561 }\r
562\r
563 fprintf(f,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r
564 fprintf(f,"<th style=\"text-align: right\">%d</th>\n\\r
565<th style=\"text-align: right\">100 %%</th>\n\\r
566<th style=\"text-align: right\">%Lu MB</th>\n\\r
567<th style=\"text-align: right\">100 %%</th></tr>\n",active_classes,total_traffic);\r
568 fputs("</thead></table></p>\n", f);\r
569\r
570 /* write basic ERP data to log directory */\r
571 if(!just_preview)\r
572 {\r
573 FILE *iplog;\r
574 sprintf(str,"%s/ERP.log",log_dir);\r
575 iplog=fopen(str,"a");\r
576 if(iplog)\r
577 {\r
578 fprintf(iplog, "%ld\t%d\t%d %%\t%Lu M\t%Ld %%\tACTIVE %d\tTRAFFIC %Lu M\tCLASSES %d\tFUP-LIMIT %d\tLOW-PRIO %d\tIPv6 %Lu M\t%.2f %%\t%s",\r
579 time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, \r
580 active_classes, total_traffic, i, limit_count, prio_count,\r
581 bytes6, perc6, d); /* d = date*/\r
582 fclose(iplog);\r
583 }\r
584 else\r
585 {\r
586 perror(str);\r
587 }\r
588 }\r
589 }\r
590\r
591 fprintf(f, stats_html_signature, version);\r
592 fclose(f);\r
593 }\r
594}
This page took 0.236124 seconds and 5 git commands to generate.