basic ipset support for qos-free-zone
[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
139fc8a0 25extern int traffic_detected;\r
9a56ab25 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
0995c4ad 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
9a56ab25 43 if(f > 0)\r
44 {\r
0995c4ad 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
9a56ab25 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
0db8e993 60 FILE *f=fopen(html, "w");\r
9a56ab25 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
9a56ab25 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
ca6f7e80 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
9a56ab25 97 } \r
98 i += group->desired; \r
99 total += group->count;\r
100 count++; \r
101 }\r
102#ifdef DEBUG\r
9f552e96 103 printf("Total groups: %d Total bandwidth requested: %d kb/s\n",\r
104 count, i, i);\r
9a56ab25 105#endif\r
106 fprintf(f,"</tr></tbody>\n\\r
107<thead><tr>\n\\r
9f552e96 108<th colspan=\"2\" style=\"text-align: left\"></td>");\r
9a56ab25 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
9f552e96 115 fprintf(f,"</tr><tr><th colspan=\"4\"></th>\n");\r
9a56ab25 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
b1a5c883 128 unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0;\r
8e7aa995 129 unsigned long long total_pktup = 0, total_pktdown = 0;\r
b1a5c883 130 int active_classes = 0;\r
8e7aa995 131// int colspan = 14;\r
b1a5c883 132 struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL;\r
bf59a20b 133 int agreg_count = 0, limit_count = 0, prio_count = 0;\r
b1a5c883 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
8e7aa995 138 int mpkts;\r
b1a5c883 139 double perc6;\r
9a56ab25 140\r
8e7aa995 141/*\r
9a56ab25 142 if(qos_proxy)\r
143 {\r
144 colspan++;\r
145 }\r
8e7aa995 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
9a56ab25 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
8e7aa995 162 fputs("<th style=\"text-align: right\">cred.</th>\n\\r
9a56ab25 163<th style=\"text-align: right\">FUP</th>\n\\r
164<th style=\"text-align: right\">total</th>\n\\r
8e7aa995 165<th style=\"text-align: center\" colspan=\"2\">upload</th>\n",f);\r
166/*\r
9a56ab25 167 if(qos_proxy)\r
168 {\r
169 fputs("<th style=\"text-align: right\">proxy</th>\n",f);\r
170 }\r
8e7aa995 171*/\r
172 fputs("<th style=\"text-align: center\" colspan=\"2\">download</th>\n\\r
9a56ab25 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
8e7aa995 185<th style=\"text-align: right\">pkt</th>\n\\r
9a56ab25 186<th style=\"text-align: right\">MB</th>\n\\r
8e7aa995 187<th style=\"text-align: right\">pkt</th>\n\\r
9a56ab25 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
8e7aa995 191<th>!</th>\n\\r
9a56ab25 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
bf59a20b 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
ca6f7e80 207 {\r
208 f1 = "<span style=\"color:red\">";\r
9a56ab25 209 f2 = "</span>"; \r
210 limit_count++; \r
ca6f7e80 211 }\r
212 else if(ip->prio > highest_priority+1)\r
213 {\r
214 f1 = "<span style=\"color:brown\">";\r
215 f2 = "</span>";\r
9a56ab25 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
8e7aa995 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
9a56ab25 225 tr_odd_even(), ip->name, i, log_url, ip->name, ip->name);\r
226\r
227 if(use_jquery_popups)\r
228 {\r
ca6f7e80 229 fprintf(f, "<span id=\"sharing_%d\" style=\"display:none\">",i);\r
9a56ab25 230 popup_button=0;\r
ca6f7e80 231\r
0b9c3c19 232 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
9a56ab25 233 {\r
ca6f7e80 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
9a56ab25 236 popup_button++;\r
237 }\r
ca6f7e80 238\r
0b9c3c19 239 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
f64d5431 240 {\r
64b2d125 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
f64d5431 243 popup_button++;\r
244 }\r
ca6f7e80 245\r
9a56ab25 246 fputs("</span>\n",f);\r
247 if(popup_button)\r
248 {\r
8e7aa995 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
9a56ab25 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
8e7aa995 263 fprintf(f, "<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n",\r
264 lms_url, ip->lmsid, ip->lmsid);\r
9a56ab25 265 }\r
266 else if(ip->lmsid == 0)\r
267 {\r
3856be6a 268 fputs("------",f);\r
9a56ab25 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
e48d46c9 274 ip->keyword->html_color, ip->realquota);\r
8e7aa995 275 fprintf(f,"<td style=\"text-align: right\">%s%Lu%s</td>", f1, ip->traffic, f2);\r
9a56ab25 276\r
8e7aa995 277 /* upload --------------------------------------- */\r
278 fprintf(f,"<td style=\"text-align: right\">%Lu", ip->upload);\r
9a56ab25 279 if(use_jquery_popups)\r
280 {\r
8e7aa995 281 fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">", i);\r
0b9c3c19 282 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
f64d5431 283 {\r
8e7aa995 284 fprintf(f,"<br />%Lu", sharedip->upload);\r
f64d5431 285 }\r
0b9c3c19 286 for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
9a56ab25 287 {\r
8e7aa995 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
9a56ab25 322 }\r
323 fputs("</span>\n",f);\r
324 }\r
325 fputs("</td>\n",f);\r
9a56ab25 326\r
8e7aa995 327/*\r
9a56ab25 328 if(qos_proxy)\r
329 {\r
330 fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->proxy);\r
331 }\r
8e7aa995 332*/\r
333 /* download ---------------------------------------- */\r
334 fprintf(f,"<td style=\"text-align: right\">%Lu", ip->direct);\r
9a56ab25 335 if(use_jquery_popups)\r
336 {\r
8e7aa995 337 fprintf(f,"<span id=\"download_%d\" style=\"display:none\">", i);\r
0b9c3c19 338 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
f64d5431 339 {\r
8e7aa995 340 fprintf(f,"<br />%Lu", sharedip->direct);\r
f64d5431 341 }\r
0b9c3c19 342 for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
9a56ab25 343 {\r
8e7aa995 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
9a56ab25 378 }\r
379 fputs("</span>\n",f);\r
380 }\r
381 fputs("</td>\n",f);\r
382 /* ----------------------------------------------- */\r
383\r
b1a5c883 384 fprintf(f, "<td style=\"text-align: right\">%d</td>\n\\r
9a56ab25 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
b1a5c883 388 ip->min, ip->desired, \r
389 f1, ip->max, f2, \r
390 f1, ip->prio, f2);\r
9a56ab25 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
139fc8a0 406 if(!just_preview && traffic_detected)\r
9a56ab25 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
c5a58cd4 414 else\r
415 {\r
416 printf(".");\r
417 }\r
9a56ab25 418 }\r
8e7aa995 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
9a56ab25 425 if(qos_proxy)\r
426 {\r
b1a5c883 427 fprintf(f," <th style=\"text-align: right\">%Lu</th>\n", total_proxy);\r
9a56ab25 428 }\r
8e7aa995 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
bf59a20b 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
9a56ab25 437\r
ca6f7e80 438 if(ip6prefix)\r
c2237b8a 439 { \r
ca6f7e80 440 for_each(ip, ips)\r
441 { \r
442 if(ip->v6)\r
443 {\r
c2237b8a 444 bytes6 += ip->upload + ip->direct;\r
445 pkts6 += ip->pktsdown + ip->pktsup;\r
b1a5c883 446 count6++;\r
ca6f7e80 447 }\r
448 else\r
449 {\r
c2237b8a 450 bytes4 += ip->upload + ip->direct;\r
451 pkts4 += ip->pktsdown + ip->pktsup;\r
b1a5c883 452 count4++;\r
ca6f7e80 453 }\r
454 }\r
455\r
c2237b8a 456 perc6=(double)(bytes6)/(bytes4+bytes6)*100;\r
ca6f7e80 457 fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f);\r
62b118c2 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
c2237b8a 459 tr_odd_even(), count4, bytes4, (double)(bytes4)/(bytes4+bytes6)*100, pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r
62b118c2 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
b1a5c883 461 tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r
462 fputs("</table></p>\n", f);\r
ca6f7e80 463 }\r
464\r
9a56ab25 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
b1a5c883 479 if_exists(sum,sums,sum->l >= total_traffic/4)\r
9a56ab25 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
b1a5c883 489 if_exists(sum,sums,sum->i == 10)\r
9a56ab25 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
b1a5c883 499 if_exists(sum,sums,sum->l >= total_traffic/2)\r
9a56ab25 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
b1a5c883 509 if_exists(sum,sums,sum->l >= 4*total_traffic/5)\r
9a56ab25 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
b1a5c883 519 if_exists(sum,sums,sum->i >= (active_classes+1)/5)\r
9a56ab25 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
b1a5c883 533 if_exists(sum,sums,sum->i >= (active_classes+1)/4)\r
9a56ab25 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
b1a5c883 553 if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5)\r
9a56ab25 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
b1a5c883 568 fputs("</thead></table></p>\n", f);\r
9a56ab25 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
62b118c2 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
b1a5c883 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
9a56ab25 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.668977 seconds and 4 git commands to generate.