X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=htmlandlogs.c;h=431d044bf3d36fb53ada3ae48340152c5744c613;hp=f16580adbb597adf97499255bc9280316255ce89;hb=HEAD;hpb=ca6f7e80f4ce05259df01ec965beb7a4907b8540 diff --git a/htmlandlogs.c b/htmlandlogs.c index f16580a..431d044 100644 --- a/htmlandlogs.c +++ b/htmlandlogs.c @@ -1,3 +1,5 @@ +/* Modified by: xChaos, 20131119 */ + #include "cll1-0.6.2.h" #include "ipstruct.h" #define STRLEN 512 @@ -12,15 +14,15 @@ extern const char *version; extern const char *stats_html_signature; extern char *jquery_url; extern int keywordcount; -extern long long int line; extern int dry_run; extern int qos_proxy; extern char *title; extern char *log_url; -extern int found_lmsid; +extern int found_code; extern char *lms_url; extern char *log_dir; extern char *ip6prefix; +extern int traffic_detected; const char *tr_odd_even(void); /* implemented in prometheus.c, shared with parselogs.c */ @@ -40,9 +42,9 @@ void append_log(struct IP *self) /*using global variables*/ f = fopen(str, "a"); if(f > 0) { - fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s", + fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%s\t%s", time(NULL), self->name, self->traffic, self->direct, self->proxy, - self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/ + self->upload, self->min, self->max, self->desired, self->code, d); /* d = date*/ fclose(f); } else @@ -98,19 +100,19 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) count++; } #ifdef DEBUG - printf("Total groups: %d Total bandwidth requested: %d kb/s\nAGGREGATION: 1/%d\n", - count, i, i/line); + printf("Total groups: %d Total bandwidth requested: %d kb/s\n", + count, i, i); #endif fprintf(f,"\n\ \n\ -Line %Ld kb/s",line); +"); fprintf(f,"%d%d kb/s",total,i); for_each(keyword, keywords) if(keyword->ip_count) { fprintf(f,"%d IPs",keyword->ip_count); } - fprintf(f,"Aggregation 1/%d\n", (int)(0.5+i/line)); + fprintf(f,"\n"); fprintf(f,"%d traffic classes\n", keywordcount, total); fputs("\n",f); @@ -123,30 +125,51 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) i=0; if(f > 0) { - unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0; - int active_classes=0; - int colspan=12; - struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums=NULL; - int limit_count=0, prio_count=0; - int popup_button=0; - + unsigned long long total_traffic = 1 /* prevent divide by zero */ , total_direct=0, total_proxy=0, total_upload=0, tmp_sum = 0; + unsigned long long total_pktup = 0, total_pktdown = 0; + int active_classes = 0; +// int colspan = 14; + struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums = NULL; + int agreg_count = 0, limit_count = 0, prio_count = 0; + int popup_button = 0; + /* IPv6 vs. IPv4 stats */ + unsigned long long pkts4 = 1, pkts6 = 1 /*prevent divide by zero */, bytes4 = 0, bytes6 = 0; + int count4 = 0, count6 = 0; + int mpkts; + double perc6; + +/* if(qos_proxy) { colspan++; } - +*/ + if(use_jquery_popups) + { + fprintf(f,""); + } + fprintf(f,"

\n\n", d); fputs("\n\n",f); - fputs("\n\ + fputs("\n\ \n\ \n\ -\n",f); +\n",f); +/* if(qos_proxy) { fputs("\n",f); } - fputs("\n\ +*/ + fputs("\n\ \n\ \n\ \n\ @@ -159,11 +182,13 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) \n\ \n\ \n\ +\n\ \n\ +\n\ \n\ \n\ \n\ -\n\ +\n\ \n",f); row_odd_even = 0; @@ -172,7 +197,13 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) char *f1="", *f2=""; i++; - if(ip->max < ip->desired) + if(ip->aggregated > 1) + { + f1 = ""; + f2 = ""; + agreg_count++; + } + else if(ip->max < ip->desired) { f1 = ""; f2 = ""; @@ -189,7 +220,8 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); #endif /* hostnames -------------------------------------- */ - fprintf(f,"%s\ +\n",f); /* ----------------------------------------------- */ - if(found_lmsid) + if(found_code) { fputs("\n",f); } fprintf(f,"\n", ip->credit); fprintf(f,"", ip->keyword->html_color, ip->realquota); - fprintf(f,"", f1, ip->traffic, f2); - /* download --------------------------------------- */ - fprintf(f,"\n",f); - /* ----------------------------------------------- */ + /* pkts up ----------------------------------- */ + mpkts = ip->pktsup>>20; + total_pktup += mpkts; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"\n",f); + +/* if(qos_proxy) { fprintf(f,"\n", ip->proxy); } - /* upload ---------------------------------------- */ - fprintf(f,"\n",f); + + /* pkts down ---------------------------------------- */ + mpkts = ip->pktsdown>>20; + total_pktdown += mpkts; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"\n",f); /* ----------------------------------------------- */ - fprintf(f,"\n\ + fprintf(f, "\n\ \n\ \n\ \n", - ip->min, ip->desired, - f1, ip->max, f2, - f1, ip->prio, f2); + ip->min, ip->desired, + f1, ip->max, f2, + f1, ip->prio, f2); total_traffic+=ip->traffic; total_direct+=ip->direct; @@ -301,7 +403,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) insert(sum,sums,order_by,i); } - if(!just_preview) + if(!just_preview && traffic_detected) { append_log(ip); for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing)) @@ -309,40 +411,55 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) append_log(sharedip); } } + else + { + printf("."); + } } - fprintf(f,"\n\ -", colspan-7, i); - fprintf(f,"\n", total_traffic, total_direct); + fprintf(f, "\n\ +", i); + fprintf(f, "\ +\n", + total_traffic, total_upload, total_pktup/i); +/* if(qos_proxy) { - fprintf(f,"\n", total_proxy); + fprintf(f," \n", total_proxy); } - fprintf(f,"", total_upload); - fprintf(f,"\n
%s",title); fprintf(f," (%s)
 creditcred.FUPtotaldownuploadproxyupdownloadminmaxlimitMBMBMBpktMBpktkb/skb/skb/sprio!
%d%s\n", + fprintf(f,"%s%d%s\n", tr_odd_even(), ip->name, i, log_url, ip->name, ip->name); if(use_jquery_popups) @@ -206,86 +238,156 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ { - fprintf(f, "
%s/64\n", - log_url, sharedip->addr, sharedip->addr); + fprintf(f, "
%s/%d\n", + log_url, sharedip->addr, sharedip->addr, sharedip->mask); popup_button++; } fputs("\n",f); if(popup_button) { - fprintf(f, "[+%d]", - i, i, i, popup_button); + fprintf(f, "[+%d]", + i, popup_button); } } fputs("
",f); - if(ip->lmsid > 0) + if(ip->code[0]) { - fprintf(f,"%04d\n", lms_url, ip->lmsid, ip->lmsid); + fprintf(f, "%s\n", + lms_url, ip->code, ip->code); } - else if(ip->lmsid == 0) + else if(ip->code[0] == 0) { - fputs("-------",f); + fputs("------",f); } fputs("%Lu%Lu%s%Lu%s", f1, ip->traffic, f2); + fprintf(f,"%s%Lu%s%Lu", ip->direct); + /* upload --------------------------------------- */ + fprintf(f,"%Lu", ip->upload); if(use_jquery_popups) { - fprintf(f,"", i); + fprintf(f,"", i); for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ { - fprintf(f,"
%Lu", sharedip->direct); + fprintf(f,"
%Lu", sharedip->upload); } for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ { - fprintf(f,"
%Lu", sharedip->direct); + fprintf(f,"
%Lu", sharedip->upload); } fputs("
\n",f); } fputs("
%d", ip->upload/mpkts); + if(use_jquery_popups) + { + fprintf(f,"", i); + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ + { + mpkts = sharedip->pktsup>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->upload/mpkts); + } + for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ + { + mpkts = sharedip->pktsup>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->upload/mpkts); + } + fputs("
\n",f); + } + fputs("
%Lu%Lu", ip->upload); +*/ + /* download ---------------------------------------- */ + fprintf(f,"%Lu", ip->direct); if(use_jquery_popups) { - fprintf(f,"", i); + fprintf(f,"", i); for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ { - fprintf(f,"
%Lu", sharedip->upload); + fprintf(f,"
%Lu", sharedip->direct); } for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ { - fprintf(f,"
%Lu", sharedip->upload); + fprintf(f,"
%Lu", sharedip->direct); + } + fputs("
\n",f); + } + fputs("
%d", ip->direct/mpkts); + if(use_jquery_popups) + { + fprintf(f,"", i); + for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */ + { + mpkts = sharedip->pktsdown>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->direct/mpkts); + } + for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */ + { + mpkts = sharedip->pktsdown>>20; + if(mpkts == 0) + { + mpkts = 1; /* prevent divide by zero*/ + } + fprintf(f,"
%d", sharedip->direct/mpkts); } fputs("
\n",f); } fputs("
%d%d%d%s%d%s%s%d%s
%d CLASSES%Lu%Lu
%d CLASSES%Lu%Lu%d%Lu%Lu%LuLIMIT %dx LOW-PRIO %dx
\n",limit_count,prio_count); +*/ + fprintf(f, "%Lu%d", + total_direct, total_pktdown/i); + fprintf(f, "\ +AGR %dx \ +FUP %dx \ +PRIO %dx\n\n", + agreg_count, limit_count, prio_count); if(ip6prefix) - { - unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0; + { for_each(ip, ips) { if(ip->v6) { - bytes6 += ip->traffic; - pkts6 += ip->pktsdown+ip->pktsup; + bytes6 += ip->upload + ip->direct; + pkts6 += ip->pktsdown + ip->pktsup; + count6++; } else { - bytes4 += ip->traffic; - pkts4 += ip->pktsdown+ip->pktsup; + bytes4 += ip->upload + ip->direct; + pkts4 += ip->pktsdown + ip->pktsup; + count4++; } } + perc6=(double)(bytes6)/(bytes4+bytes6)*100; fputs("

\n",f); - fprintf(f, "%s\n", - tr_odd_even(), bytes4, (float)(100*bytes4)/(bytes4+bytes6), pkts4, (float)(100*pkts4)/(pkts4+pkts6)); - fprintf(f, "%s\n", - tr_odd_even(), bytes6, (float)(100*bytes6)/(bytes4+bytes6), pkts6, (float)(100*pkts6)/(pkts4+pkts6)); - fputs("
IP protocols usage
Total IPv4%Lu MB (%.2f %%)%Lu packets (%d %%)
Total IPv6%Lu MB (%.2f %%)%Lu packets (%d %%)
\n", f); + fprintf(f, "%sTotal %d IPv4 addreses%Lu MB (%.2f %%)%Lu packets (%.2f %%)\n", + tr_odd_even(), count4, bytes4, (double)(bytes4)/(bytes4+bytes6)*100, pkts4, (float)(100*pkts4)/(pkts4+pkts6)); + fprintf(f, "%sTotal %d IPv6 /64 ranges%Lu MB (%.2f %%)%Lu packets (%.2f %%)\n", + tr_odd_even(), count6, bytes6, perc6, pkts6, (float)(100*pkts6)/(pkts4+pkts6)); + fputs("

\n", f); } row_odd_even = 0; @@ -359,7 +476,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) Data transfers\n\ \n",f); - if_exists(sum,sums,sum->l>=total_traffic/4) + if_exists(sum,sums,sum->l >= total_traffic/4) { fprintf(f,"%sTop 25%% of traffic\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -369,7 +486,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->i==10) + if_exists(sum,sums,sum->i == 10) { fprintf(f,"%sTop 10 downloaders\n", tr_odd_even()); fprintf(f,"10\n\ @@ -379,7 +496,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->l>=total_traffic/2) + if_exists(sum,sums,sum->l >= total_traffic/2) { fprintf(f,"%sTop 50%% of traffic\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -389,7 +506,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->l>=4*total_traffic/5) + if_exists(sum,sums,sum->l >= 4*total_traffic/5) { fprintf(f,"%sTop 80%% of traffic\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -399,7 +516,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->i>=(active_classes+1)/5) + if_exists(sum,sums,sum->i >= (active_classes+1)/5) { fprintf(f,"%sTop 20%% downloaders\n", tr_odd_even()); top20_count=sum->i; @@ -413,7 +530,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) top20_count,top20_perc1,top20_sum,top20_perc2); } - if_exists(sum,sums,sum->i>=(active_classes+1)/4) + if_exists(sum,sums,sum->i >= (active_classes+1)/4) { fprintf(f,"%sTop 25%% downloaders\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -433,7 +550,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } - if_exists(sum,sums,sum->i>=4*(active_classes+1)/5) + if_exists(sum,sums,sum->i >= 4*(active_classes+1)/5) { fprintf(f,"%sTop 80%% downloaders\n", tr_odd_even()); fprintf(f,"%d\n\ @@ -448,7 +565,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) 100 %%\n\ %Lu MB\n\ 100 %%\n",active_classes,total_traffic); - fputs("\n", f); + fputs("

\n", f); /* write basic ERP data to log directory */ if(!just_preview) @@ -458,9 +575,10 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview) iplog=fopen(str,"a"); if(iplog) { - 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\t%s", - time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, - active_classes, total_traffic, i, limit_count, prio_count, d); /* d = date*/ + 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", + time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, + active_classes, total_traffic, i, limit_count, prio_count, + bytes6, perc6, d); /* d = date*/ fclose(iplog); } else