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