#include "cll1-0.6.2.h" #include "ipstruct.h" #define STRLEN 512 extern int row_odd_even; extern int use_jquery_popups; extern struct IP *ips, *ip, *sharedip; extern struct Group *groups, *group; extern struct Keyword *keyword, *defaultkeyword, *keywords; extern const int highest_priority; 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 char *lms_url; extern char *log_dir; const char *tr_odd_even(void); /* implemented in prometheus.c, shared with parselogs.c */ void append_log(struct IP *self) /*using global variables*/ { char *d, *str; FILE *f; date(d); /* this is typical cll1.h macro - prints current date */ string(str,STRLEN); sprintf(str,"%s/%s.log", log_dir, self->name); 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", time(NULL), self->name, self->traffic, self->direct, self->proxy, self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/ fclose(f); } else { perror(str); } } void write_htmlandlogs(char *html, char *d, int total, int just_preview) { int i; char *str; FILE *f=fopen(html, "w"); string(str,STRLEN); if(f > 0) { int count=1; i=0; if(use_jquery_popups) { fprintf(f,"\n", jquery_url); } fputs("\n\ \n\ \n\ \n\ \n\ \n\ \n",f); fprintf(f,"\n", keywordcount); fputs("\n",f); row_odd_even = 0; for_each(group, groups) { #ifdef DEBUG printf("%d kb/s group: %d bandwidth requested: %d kb/s\n",group->min,group->count,group->desired); #endif fprintf(f, "%s", tr_odd_even(), count, group->min); fprintf(f, "", group->count, group->desired); for_each(keyword, keywords) if(keyword->ip_count) { fprintf(f,"", keyword->html_color, group->min*keyword->data_limit); } i += group->desired; total += group->count; count++; } #ifdef DEBUG printf("Total groups: %d Total bandwidth requested: %d kb/s\nAGGREGATION: 1/%d\n", count, i, i/line); #endif fprintf(f,"\n\ \n\ ",keyword->ip_count); } fprintf(f,"\n", (int)(0.5+i/line)); fprintf(f,"\n", keywordcount, total); fputs("
Bandwidth classes
#groupIPsrequesteddata limits
%d%d kb/s%d%d kb/s%d MB
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
Aggregation 1/%d%d traffic classes
\n",f); } else { perror(html); } 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; if(qos_proxy) { colspan++; } fprintf(f,"

\n\n", d); fputs("\n\n",f); fputs("\n\ \n\ \n\ \n",f); if(qos_proxy) { fputs("\n",f); } fputs("\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n",f); row_odd_even = 0; for_each(ip,ips) if(!use_jquery_popups || !ip->sharing) { char *f1="", *f2=""; i++; if(ip->max < ip->desired) { f1 = ""; f2 = ""; limit_count++; } else if(ip->prio > highest_priority+1) { f1 = ""; f2 = ""; prio_count++; } #ifdef DEBUG 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) { fputs("\n",f); } fprintf(f,"\n", ip->credit); fprintf(f,"", ip->keyword->html_color, ip->realquota); fprintf(f,"\n",f); /* ----------------------------------------------- */ if(qos_proxy) { fprintf(f,"\n", ip->proxy); } /* upload ---------------------------------------- */ fprintf(f,"\n",f); /* ----------------------------------------------- */ fprintf(f,"\n\ \n\ \n\ \n", ip->min, ip->desired, f1, ip->max, f2, f1, ip->prio, f2); total_traffic+=ip->traffic; total_direct+=ip->direct; total_proxy+=ip->proxy; total_upload+=ip->upload; if(ip->traffic>0) { active_classes++; tmp_sum+=ip->traffic; create(sum,Sum); sum->l=tmp_sum; sum->i=active_classes; insert(sum,sums,order_by,i); } if(!just_preview) { append_log(ip); for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing)) { append_log(sharedip); } } } fprintf(f,"\n\ ", colspan-7, i); fprintf(f,"\n", total_traffic, total_direct); if(qos_proxy) { fprintf(f,"\n", total_proxy); } fprintf(f,"", total_upload); fprintf(f,"\n
%s",title); fprintf(f," (%s)
 creditFUPtotaldownproxyupminmaxlimit 
#hostname [+sharing]LMSMBMBMBMBMBkb/skb/skb/sprio
%d%s\n", tr_odd_even(), ip->name, i, log_url, ip->name, ip->name); if(use_jquery_popups) { fprintf(f,"",i); popup_button=0; for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */ { fprintf(f,"
%s\n", log_url, sharedip->name, sharedip->name); popup_button++; } for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */ { fprintf(f,"
%s\n", log_url, sharedip->name, sharedip->addr); popup_button++; } fputs("
\n",f); if(popup_button) { fprintf(f,"[+%d]", i, i, i, popup_button); } } fputs("
",f); if(ip->lmsid > 0) { fprintf(f,"%04d\n", lms_url, ip->lmsid, ip->lmsid); } else if(ip->lmsid == 0) { fputs("-------",f); } fputs("%Lu%Lu%s%Lu%s", f1, ip->traffic, f2); /* download --------------------------------------- */ fprintf(f,"%Lu", ip->direct); if(use_jquery_popups) { fprintf(f,"",i); for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */ { fprintf(f,"
%Lu", sharedip->direct); } for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */ { fprintf(f,"
%Lu", sharedip->direct); } fputs("
\n",f); } fputs("
%Lu%Lu", ip->upload); if(use_jquery_popups) { fprintf(f,"",i); for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,':')) /* IPv4 only */ { fprintf(f,"
%Lu", sharedip->upload); } for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !strchr(sharedip->addr,'.')) /* IPv6 only */ { fprintf(f,"
%Lu", sharedip->upload); } fputs("
\n",f); } fputs("
%d%d%s%d%s%s%d%s
%d CLASSES%Lu%Lu%Lu%LuLIMIT %dx LOW-PRIO %dx
\n",limit_count,prio_count); row_odd_even = 0; if(active_classes>10) { int top20_count=0,top20_perc1=0; long long top20_perc2=0; unsigned long long top20_sum=0l; fputs("

\n",f); fputs("\n\ \n\ \n\ \n\ \n",f); if_exists(sum,sums,sum->l>=total_traffic/4) { fprintf(f,"%s\n", tr_odd_even()); fprintf(f,"\n\ \n\ \n\ \n", sum->i, (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic); } if_exists(sum,sums,sum->i==10) { fprintf(f,"%s\n", tr_odd_even()); fprintf(f,"\n\ \n\ \n\ \n", (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic); } if_exists(sum,sums,sum->l>=total_traffic/2) { fprintf(f,"%s\n", tr_odd_even()); fprintf(f,"\n\ \n\ \n\ \n", 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) { fprintf(f,"%s\n", tr_odd_even()); fprintf(f,"\n\ \n\ \n\ \n", 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) { fprintf(f,"%s\n", tr_odd_even()); top20_count=sum->i; top20_perc1=(100*sum->i+50)/active_classes; top20_sum=sum->l; top20_perc2=(100*sum->l+50)/total_traffic; fprintf(f,"\n\ \n\ \n\ \n", top20_count,top20_perc1,top20_sum,top20_perc2); } if_exists(sum,sums,sum->i>=(active_classes+1)/4) { fprintf(f,"%s\n", tr_odd_even()); fprintf(f,"\n\ \n\ \n\ \n", 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)/2) { fprintf(f,"%s\n", tr_odd_even()); fprintf(f,"\n\ \n\ \n\ \n", 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) { fprintf(f,"%s\n", tr_odd_even()); fprintf(f,"\n\ \n\ \n\ \n", sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic); } fprintf(f,"\n", log_url); fprintf(f,"\n\ \n\ \n\ \n",active_classes,total_traffic); fputs("
Enterprise Resource Planning (ERP)
Analytic categoryActive ClassesData transfers
Top 25%% of traffic%d%d %%%Lu MB%Ld %%
Top 10 downloaders10%d %%%Lu MB%Ld %%
Top 50%% of traffic%d%d %%%Lu MB%Ld %%
Top 80%% of traffic%d%d %%%Lu MB%Ld %%
Top 20%% downloaders%d%d %%%Lu MB%Ld %%
Top 25%% downloaders%d%d %%%Lu MB%Ld %%
Top 50%% downloaders%d%d %%%Lu MB%Ld %%
Top 80%% downloaders%d%d %%%Lu MB%Ld %%
All users, all traffic%d100 %%%Lu MB100 %%
\n", f); /* write basic ERP data to log directory */ if(!just_preview) { FILE *iplog; sprintf(str,"%s/ERP.log",log_dir); 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*/ fclose(iplog); } else { perror(str); } } } fprintf(f, stats_html_signature, version); fclose(f); } }