1 /* Modified by: xChaos, 20131119 */
3 #include "cll1-0.6.2.h"
7 extern int row_odd_even
;
8 extern int use_jquery_popups
;
9 extern struct IP
*ips
, *ip
, *sharedip
;
10 extern struct Group
*groups
, *group
;
11 extern struct Keyword
*keyword
, *defaultkeyword
, *keywords
;
12 extern const int highest_priority
;
13 extern const char *version
;
14 extern const char *stats_html_signature
;
15 extern char *jquery_url
;
16 extern int keywordcount
;
17 extern long long int line
;
22 extern int found_lmsid
;
25 extern char *ip6prefix
;
27 const char *tr_odd_even(void);
28 /* implemented in prometheus.c, shared with parselogs.c */
30 void append_log(struct IP
*self
) /*using global variables*/
35 date(d
); /* this is typical cll1.h macro - prints current date */
37 sprintf(str
, "%s/%s.log", log_dir
, self
->name
);
39 /*-----------------------------------------------------------------*/
40 printf("Writing traffic log %s ...\n", str
);
41 /*-----------------------------------------------------------------*/
45 fprintf(f
, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",
46 time(NULL
), self
->name
, self
->traffic
, self
->direct
, self
->proxy
,
47 self
->upload
, self
->min
, self
->max
, self
->desired
, self
->lmsid
, d
); /* d = date*/
56 void write_htmlandlogs(char *html
, char *d
, int total
, int just_preview
)
60 FILE *f
=fopen(html
, "w");
70 fprintf(f
,"<script type=\"text/javascript\" src=\"%s\"></script>\n", jquery_url
);
72 fputs("<table class=\"decorated last\">\n\
73 <caption>Bandwidth classes</caption>\n\
75 <th style=\"text-align: right\">#</th>\n\
76 <th style=\"text-align: right\">group</th>\n\
77 <th style=\"text-align: right\">IPs</th>\n\
78 <th style=\"text-align: right\">requested</th>\n",f
);
79 fprintf(f
,"<th colspan=\"%d\">data limits</th>\n", keywordcount
);
80 fputs("</tr></thead><tbody>\n",f
);
83 for_each(group
, groups
)
86 printf("%d kb/s group: %d bandwidth requested: %d kb/s\n",group
->min
,group
->count
,group
->desired
);
88 fprintf(f
, "%s<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d kb/s</td>",
89 tr_odd_even(), count
, group
->min
);
90 fprintf(f
, "<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d kb/s</td>",
91 group
->count
, group
->desired
);
93 for_each(keyword
, keywords
) if(keyword
->ip_count
)
95 fprintf(f
, "<td style=\"text-align: right\"><span style=\"color:#%s\">%d MB</span></td>",
96 keyword
->html_color
, group
->min
*keyword
->data_limit
);
99 total
+= group
->count
;
103 printf("Total groups: %d Total bandwidth requested: %d kb/s\nAGGREGATION: 1/%d\n",
106 fprintf(f
,"</tr></tbody>\n\
108 <th colspan=\"2\" style=\"text-align: left\">Line %Ld kb/s</td>",line
);
109 fprintf(f
,"<th style=\"text-align: right\">%d</td><th style=\"text-align: right\">%d kb/s</td>",total
,i
);
111 for_each(keyword
, keywords
) if(keyword
->ip_count
)
113 fprintf(f
,"<th style=\"text-align: right\">%d IPs</th>",keyword
->ip_count
);
115 fprintf(f
,"</tr><tr><th colspan=\"4\">Aggregation 1/%d</th>\n", (int)(0.5+i
/line
));
116 fprintf(f
,"<th colspan=\"%d\">%d traffic classes</th></tr>\n", keywordcount
, total
);
118 fputs("</thead></table>\n",f
);
128 unsigned long long total_traffic
=0, total_direct
=0, total_proxy
=0, total_upload
=0, tmp_sum
= 0;
129 unsigned long long total_pktup
= 0, total_pktdown
= 0;
130 int active_classes
= 0;
132 struct Sum
{unsigned long long l
; int i
; list(Sum
);} *sum
,*sums
= NULL
;
133 int limit_count
= 0, prio_count
= 0;
134 int popup_button
= 0;
135 /* IPv6 vs. IPv4 stats */
136 unsigned long long pkts4
=0, pkts6
= 0, bytes4
= 0, bytes6
= 0;
137 int count4
= 0, count6
= 0;
147 if(use_jquery_popups
)
149 fprintf(f
,"<script type=\"text/javascript\">\
150 function show_section(n) {\
151 $(\'#sharing_\'+n).show();\
152 $(\'#download_'+n).show();\
153 $(\'#pktsdown_\'+n).show();\
154 $(\'#upload_'+n).show();\
155 $(\'#pktsup_\'+n).show();\
159 fprintf(f
,"<p><table class=\"decorated last\">\n<caption>%s",title
);
160 fprintf(f
," (%s)</caption>\n", d
);
161 fputs("<thead><tr>\n<th colspan=\"3\"> </th>\n",f
);
162 fputs("<th style=\"text-align: right\">cred.</th>\n\
163 <th style=\"text-align: right\">FUP</th>\n\
164 <th style=\"text-align: right\">total</th>\n\
165 <th style=\"text-align: center\" colspan=\"2\">upload</th>\n",f
);
169 fputs("<th style=\"text-align: right\">proxy</th>\n",f);
172 fputs("<th style=\"text-align: center\" colspan=\"2\">download</th>\n\
173 <th style=\"text-align: right\">min</th>\n\
174 <th style=\"text-align: right\">max</th>\n\
175 <th style=\"text-align: right\">limit</th>\n\
178 <th style=\"text-align: right\">#</th>\n\
179 <th>hostname [+sharing]</th>\n\
180 <th style=\"text-align: right\">LMS</th>\n\
181 <th style=\"text-align: right\">MB</th>\n\
182 <th style=\"text-align: right\">MB</th>\n\
183 <th style=\"text-align: right\">MB</th>\n\
184 <th style=\"text-align: right\">MB</th>\n\
185 <th style=\"text-align: right\">pkt</th>\n\
186 <th style=\"text-align: right\">MB</th>\n\
187 <th style=\"text-align: right\">pkt</th>\n\
188 <th style=\"text-align: right\">kb/s</th>\n\
189 <th style=\"text-align: right\">kb/s</th>\n\
190 <th style=\"text-align: right\">kb/s</th>\n\
192 </tr></thead><tbody>\n",f
);
195 for_each(ip
,ips
) if(!use_jquery_popups
|| !ip
->sharing
)
200 if(ip
->max
< ip
->desired
)
202 f1
= "<span style=\"color:red\">";
206 else if(ip
->prio
> highest_priority
+1)
208 f1
= "<span style=\"color:brown\">";
214 printf("%03d. %-22s %10Lu (%d/%d)\n",i
,ip
->name
, ip
->traffic
, ip
->min
, ip
->max
);
216 /* hostnames -------------------------------------- */
217 fprintf(f
,"%s<td style=\"text-align: right\"><a name=\"%s\"></a>%d</td>\
218 <td><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n",
219 tr_odd_even(), ip
->name
, i
, log_url
, ip
->name
, ip
->name
);
221 if(use_jquery_popups
)
223 fprintf(f
, "<span id=\"sharing_%d\" style=\"display:none\">",i
);
226 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
228 fprintf(f
, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n",
229 log_url
, sharedip
->name
, sharedip
->name
);
233 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
235 fprintf(f
, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/64</a>\n",
236 log_url
, sharedip
->addr
, sharedip
->addr
);
240 fputs("</span>\n",f
);
243 fprintf(f
, "<span>[<a class=\"blue\" href=\"#\" \
244 onClick=\"$(this).parent().hide();show_section(\'%d\');return(false);\" \
245 style=\"cursor: pointer;\">+%d</a>]</span>",
250 /* ----------------------------------------------- */
254 fputs("<td style=\"text-align: right\">",f
);
257 fprintf(f
, "<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n",
258 lms_url
, ip
->lmsid
, ip
->lmsid
);
260 else if(ip
->lmsid
== 0)
266 fprintf(f
,"<td style=\"text-align: right\">%Lu</td>\n", ip
->credit
);
267 fprintf(f
,"<td style=\"text-align: right\"><span style=\"color:#%s\">%Lu</span></td>",
268 ip
->keyword
->html_color
, ip
->realquota
);
269 fprintf(f
,"<td style=\"text-align: right\">%s%Lu%s</td>", f1
, ip
->traffic
, f2
);
271 /* upload --------------------------------------- */
272 fprintf(f
,"<td style=\"text-align: right\">%Lu", ip
->upload
);
273 if(use_jquery_popups
)
275 fprintf(f
,"<span id=\"upload_%d\" style=\"display:none\">", i
);
276 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
278 fprintf(f
,"<br />%Lu", sharedip
->upload
);
280 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
282 fprintf(f
,"<br />%Lu", sharedip
->upload
);
284 fputs("</span>\n",f
);
288 /* pkts up ----------------------------------- */
289 mpkts
= ip
->pktsup
>>20;
290 total_pktup
+= mpkts
;
293 mpkts
= 1; /* prevent divide by zero*/
295 fprintf(f
,"<td style=\"text-align: right\"><span style=\"color: gray\">%d</span>", ip
->upload
/mpkts
);
296 if(use_jquery_popups
)
298 fprintf(f
,"<span id=\"pktsup_%d\" style=\"display:none\">", i
);
299 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
301 mpkts
= sharedip
->pktsup
>>20;
304 mpkts
= 1; /* prevent divide by zero*/
306 fprintf(f
,"<br /><span style=\"color: gray\">%d</span>", sharedip
->upload
/mpkts
);
308 for_each(sharedip
, ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
310 mpkts
= sharedip
->pktsup
>>20;
313 mpkts
= 1; /* prevent divide by zero*/
315 fprintf(f
,"<br /><span style=\"color: gray\">%d</span>", sharedip
->upload
/mpkts
);
317 fputs("</span>\n",f
);
324 fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->proxy);
327 /* download ---------------------------------------- */
328 fprintf(f
,"<td style=\"text-align: right\">%Lu", ip
->direct
);
329 if(use_jquery_popups
)
331 fprintf(f
,"<span id=\"download_%d\" style=\"display:none\">", i
);
332 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
334 fprintf(f
,"<br />%Lu", sharedip
->direct
);
336 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
338 fprintf(f
,"<br />%Lu", sharedip
->direct
);
340 fputs("</span>\n",f
);
344 /* pkts down ---------------------------------------- */
345 mpkts
= ip
->pktsdown
>>20;
346 total_pktdown
+= mpkts
;
349 mpkts
= 1; /* prevent divide by zero*/
351 fprintf(f
,"<td style=\"text-align: right\"><span style=\"color: gray\">%d</span>", ip
->direct
/mpkts
);
352 if(use_jquery_popups
)
354 fprintf(f
,"<span id=\"pktsdown_%d\" style=\"display:none\">", i
);
355 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && !sharedip
->v6
) /* IPv4 only */
357 mpkts
= sharedip
->pktsdown
>>20;
360 mpkts
= 1; /* prevent divide by zero*/
362 fprintf(f
,"<br /><span style=\"color: gray\">%d</span>", sharedip
->direct
/mpkts
);
364 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
) && sharedip
->v6
) /* IPv6 only */
366 mpkts
= sharedip
->pktsdown
>>20;
369 mpkts
= 1; /* prevent divide by zero*/
371 fprintf(f
,"<br /><span style=\"color: gray\">%d</span>", sharedip
->direct
/mpkts
);
373 fputs("</span>\n",f
);
376 /* ----------------------------------------------- */
378 fprintf(f
, "<td style=\"text-align: right\">%d</td>\n\
379 <td style=\"text-align: right\">%d</td>\n\
380 <td style=\"text-align: right\">%s%d%s</td>\n\
381 <td>%s%d%s</td></tr>\n",
382 ip
->min
, ip
->desired
,
386 total_traffic
+=ip
->traffic
;
387 total_direct
+=ip
->direct
;
388 total_proxy
+=ip
->proxy
;
389 total_upload
+=ip
->upload
;
393 tmp_sum
+=ip
->traffic
;
396 sum
->i
=active_classes
;
397 insert(sum
,sums
,order_by
,i
);
403 for_each(sharedip
,ips
) if(eq(ip
->name
, sharedip
->sharing
))
405 append_log(sharedip
);
409 fprintf(f
, "</tbody><thead><tr>\n\
410 <th colspan=\"5\" style=\"text-align: left\">%d CLASSES</th>", i
);
411 fprintf(f
, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%Lu</th>\
412 <th style=\"text-align: right\">%d</th>\n",
413 total_traffic
, total_upload
, total_pktup
/i
);
417 fprintf(f," <th style=\"text-align: right\">%Lu</th>\n", total_proxy);
420 fprintf(f
, "<th style=\"text-align: right\">%Lu</th><th style=\"text-align: right\">%d</th>",
421 total_direct
, total_pktdown
/i
);
422 fprintf(f
, "<th colspan=\"6\"><span style=\"color:red\">LIMIT %dx</span> \
423 <span style=\"color:brown\">LOW-PRIO %dx</span></th></tr>\n</thead></table>\n",
424 limit_count
, prio_count
);
432 bytes6
+= ip
->upload
+ ip
->direct
;
433 pkts6
+= ip
->pktsdown
+ ip
->pktsup
;
438 bytes4
+= ip
->upload
+ ip
->direct
;
439 pkts4
+= ip
->pktsdown
+ ip
->pktsup
;
444 perc6
=(double)(bytes6
)/(bytes4
+bytes6
)*100;
445 fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f
);
446 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",
447 tr_odd_even(), count4
, bytes4
, (double)(bytes4
)/(bytes4
+bytes6
)*100, pkts4
, (float)(100*pkts4
)/(pkts4
+pkts6
));
448 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",
449 tr_odd_even(), count6
, bytes6
, perc6
, pkts6
, (float)(100*pkts6
)/(pkts4
+pkts6
));
450 fputs("</table></p>\n", f
);
454 if(active_classes
>10)
456 int top20_count
=0,top20_perc1
=0;
457 long long top20_perc2
=0;
458 unsigned long long top20_sum
=0l;
460 fputs("<a name=\"erp\"></a><p><table class=\"decorated last\"><caption>Enterprise Resource Planning (ERP)</caption>\n",f
);
461 fputs("<thead><tr>\n\
462 <th>Analytic category</th>\n\
463 <th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\
464 <th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\
465 </tr></thead><tbody>\n",f
);
467 if_exists(sum
,sums
,sum
->l
>= total_traffic
/4)
469 fprintf(f
,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());
470 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
471 <td style=\"text-align: right\">%d %%</td>\n\
472 <td style=\"text-align: right\">%Lu MB</td>\n\
473 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
474 sum
->i
, (100*sum
->i
+50)/active_classes
, sum
->l
, (100*sum
->l
+50)/total_traffic
);
477 if_exists(sum
,sums
,sum
->i
== 10)
479 fprintf(f
,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());
480 fprintf(f
,"<td style=\"text-align: right\"><strong>10</strong></td>\n\
481 <td style=\"text-align: right\">%d %%</td>\n\
482 <td style=\"text-align: right\">%Lu MB</td>\n\
483 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
484 (100*sum
->i
+50)/active_classes
, sum
->l
, (100*sum
->l
+50)/total_traffic
);
487 if_exists(sum
,sums
,sum
->l
>= total_traffic
/2)
489 fprintf(f
,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());
490 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
491 <td style=\"text-align: right\">%d %%</td>\n\
492 <td style=\"text-align: right\">%Lu MB</td>\n\
493 <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",
494 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
497 if_exists(sum
,sums
,sum
->l
>= 4*total_traffic
/5)
499 fprintf(f
,"%s<td>Top 80%% of traffic</td>\n", tr_odd_even());
500 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
501 <td style=\"text-align: right\">%d %%</td>\n\
502 <td style=\"text-align: right\">%Lu MB</td>\n\
503 <td style=\"text-align: right\"><strong>%Ld %%</strong></td></tr>\n",
504 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
507 if_exists(sum
,sums
,sum
->i
>= (active_classes
+1)/5)
509 fprintf(f
,"%s<td>Top 20%% downloaders</td>\n", tr_odd_even());
511 top20_perc1
=(100*sum
->i
+50)/active_classes
;
513 top20_perc2
=(100*sum
->l
+50)/total_traffic
;
514 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
515 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
516 <td style=\"text-align: right\">%Lu MB</td>\n\
517 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
518 top20_count
,top20_perc1
,top20_sum
,top20_perc2
);
521 if_exists(sum
,sums
,sum
->i
>= (active_classes
+1)/4)
523 fprintf(f
,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());
524 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
525 <td style=\"text-align: right\">%d %%</td>\n\
526 <td style=\"text-align: right\">%Lu MB</td>\n\
527 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
528 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
531 if_exists(sum
,sums
,sum
->i
>=(active_classes
+1)/2)
533 fprintf(f
,"%s<td>Top 50%% downloaders</td>\n", tr_odd_even());
534 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
535 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\
536 <td style=\"text-align: right\">%Lu MB</td>\n\
537 <td style=\"text-align: right\">%Ld %%</td></tr>\n",
538 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
541 if_exists(sum
,sums
,sum
->i
>= 4*(active_classes
+1)/5)
543 fprintf(f
,"%s<td>Top 80%% downloaders</td>\n", tr_odd_even());
544 fprintf(f
,"<td style=\"text-align: right\">%d</td>\n\
545 <td style=\"text-align: right\">%d %%</td>\n\
546 <td style=\"text-align: right\">%Lu MB</td>\n\
547 <td style=\"text-align: right\">%Ld %%</td></tr></tbody>\n",
548 sum
->i
,(100*sum
->i
+50)/active_classes
,sum
->l
,(100*sum
->l
+50)/total_traffic
);
551 fprintf(f
,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url
);
552 fprintf(f
,"<th style=\"text-align: right\">%d</th>\n\
553 <th style=\"text-align: right\">100 %%</th>\n\
554 <th style=\"text-align: right\">%Lu MB</th>\n\
555 <th style=\"text-align: right\">100 %%</th></tr>\n",active_classes
,total_traffic
);
556 fputs("</thead></table></p>\n", f
);
558 /* write basic ERP data to log directory */
562 sprintf(str
,"%s/ERP.log",log_dir
);
563 iplog
=fopen(str
,"a");
566 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",
567 time(NULL
), top20_count
, top20_perc1
, top20_sum
, top20_perc2
,
568 active_classes
, total_traffic
, i
, limit_count
, prio_count
,
569 bytes6
, perc6
, d
); /* d = date*/
579 fprintf(f
, stats_html_signature
, version
);
This page took 0.659825 seconds and 4 git commands to generate.