char *log_url = "logs/"; /* log directory relative URI prefix (partial URL) */\r
char *html_log_dir = "/var/www/logs/html/";\r
\r
+char *jquery_url = "http://code.jquery.com/jquery-latest.js";\r
+char *lms_url = "/lms/?m=customerinfo&id=";\r
+int use_jquery_popups = 1;\r
+\r
/* ======= Help screen is hopefuly self-documenting part of code :-) ======= */\r
\r
void help(void)\r
option("log-traffic-directory",log_dir);\r
option("log-traffic-html-directory",html_log_dir);\r
option("log-traffic-url-path",log_url);\r
+ option("jquery-url",jquery_url);\r
+ option("lms-url",lms_url);\r
+ ioption("use-jquery-popups",use_jquery_popups);\r
option("qos-free-zone",qos_free_zone);\r
ioption("qos-free-delay",qos_free_delay);\r
ioption("qos-proxy-enable",qos_proxy);\r
f=fopen(str,"w");\r
if(f)\r
{\r
- fprintf(f,"<table border><tr><th colspan=\"2\">%s %s</th><th align=\"right\">lms</th><th colspan=\"2\">Data transfers</th><th align=\"right\">Min.speed</th></tr>\n ",month,year);\r
+ fprintf(f, "<table border><tr><th colspan=\"2\">%s %s</th><th align=\"right\">lms</th><th colspan=\"2\">Data transfers</th><th align=\"right\">Min.speed</th></tr>\n ",\r
+ month, year);\r
\r
- for_each(iplog,iplogs)\r
+ for_each(iplog, iplogs)\r
{\r
if(iplog->traffic)\r
{\r
- fprintf(f,"<tr><td align=\"right\">%d</td><th align=\"left\">%s</td><td align=\"right\">", i++, iplog->name); \r
+ fprintf(f, "<tr><td align=\"right\">%d</td><th align=\"left\">%s</td><td align=\"right\">", \r
+ i++, iplog->name); \r
if(iplog->lmsid > 0)\r
{\r
/*base URL will be configurable soon ... */\r
- fprintf(f,"<a href=\"https://hermes.spoje.net/?m=customerinfo&id=%d\">%04d</a>\n", iplog->lmsid, iplog->lmsid);\r
+ fprintf(f, "<a href=\"%s%d\">%04d</a>\n", lms_url, iplog->lmsid, iplog->lmsid);\r
}\r
else if(iplog->lmsid == 0)\r
{\r
fputs("-------",f);\r
} \r
- fprintf(f,"<td align=\"right\">%ld M</td><th align=\"right\">%ld G</th><td align=\"right\">%ld kbps</th></tr>\n",\r
- iplog->traffic, iplog->traffic>>10, iplog->guaranted);\r
+ fprintf(f, "<td align=\"right\">%ld M</td><th align=\"right\">%ld G</th><td align=\"right\">%ld kbps</th></tr>\n",\r
+ iplog->traffic, iplog->traffic>>10, iplog->guaranted);\r
total+=iplog->traffic>>10;\r
iplog->i=i;\r
iplog->l=total;\r
/*-----------------------------------------------------------------*/\r
puts("Resolving shared connections ...");\r
/*-----------------------------------------------------------------*/\r
- for_selected(ip,ips,ip->sharing)\r
+ for_each(ip,ips) if(ip->sharing)\r
{\r
- for_selected(sharedip,ips,eq(sharedip->name,ip->sharing))\r
+ for_each(sharedip,ips) if(eq(sharedip->name,ip->sharing))\r
{\r
sharedip->traffic+=ip->traffic;\r
ip->traffic=0;\r
save_line(":post_common - [0:0]");\r
save_line(":forw_common - [0:0]");\r
\r
- for_selected(ip,ips,ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0"))\r
+ for_each(ip,ips) if (ip->addr && *(ip->addr) && !eq(ip->addr,"0.0.0.0/0"))\r
{\r
buf=hash_id(ip->addr,bitmask);\r
if_exists(idx,idxs,eq(idx->id,buf))\r
bitmask-=idxtable_bitmask2;\r
idxcount=0;\r
\r
- for_selected(idx,idxs,idx->parent==NULL)\r
+ for_each(idx,idxs) if(idx->parent == NULL)\r
{\r
buf=hash_id(idx->addr,bitmask);\r
if_exists(metaindex,idxs,eq(metaindex->id,buf))\r
sleep(qos_free_delay);\r
}\r
\r
- sprintf(str,"%s qdisc add dev %s root handle 1: htb r2q %d default 1",tc,lan,htb_r2q);\r
+ sprintf(str,"%s qdisc add dev %s root handle 1: htb r2q %d default 1",\r
+ tc,lan,htb_r2q);\r
safe_run(str);\r
\r
sprintf(str, "%s class add dev %s parent 1: classid 1:2 htb rate %s ceil %s burst %dk prio %d",\r
/*-----------------------------------------------------------------*/\r
/* sub-scope - local variables */ \r
{\r
- long long int rate=line;\r
- long long int max=line;\r
- int group_count=0;\r
- FILE *credit_file=NULL;\r
+ long long int rate = line;\r
+ long long int max = line;\r
+ int group_count = 0;\r
+ FILE *credit_file = NULL;\r
\r
if(!just_preview && !dry_run && enable_credit)\r
{\r
- credit_file=fopen(credit,"w");\r
+ credit_file = fopen(credit,"w");\r
}\r
\r
for_each(group,groups)\r
safe_run(str);\r
}\r
\r
- if(group_count++<max_nesting)\r
+ if(group_count++ < max_nesting)\r
{\r
- parent=group->id;\r
+ parent = group->id;\r
}\r
\r
- rate-=digital_divide*group->min;\r
- if(rate<group->min)\r
+ rate -= digital_divide*group->min;\r
+ if(rate < group->min)\r
{\r
- rate=group->min;\r
+ rate = group->min;\r
}\r
\r
/*shaping of aggresive downloaders, with credit file support */\r
if(use_credit)\r
{\r
- int group_rate=group->min, priority_sequence=lowest_priority;\r
+ int group_rate = group->min, priority_sequence = lowest_priority;\r
\r
- for_selected(ip, ips, ip->min==group->min && ip->max>ip->min)\r
+ for_each(ip, ips) if(ip->min == group->min && ip->max > ip->min)\r
{\r
- if( ip->keyword->data_limit && !ip->fixedprio &&\r
- ip->traffic>ip->credit+\r
- (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)) )\r
+ if( ip->keyword->data_limit && !ip->fixedprio \r
+ && ( ip->traffic>ip->credit\r
+ + (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))) )\r
{\r
if(group_rate<ip->max)\r
{\r
}\r
else\r
{\r
- if( ip->keyword->data_prio && !ip->fixedprio &&\r
- ip->traffic>ip->credit+\r
- (ip->min*ip->keyword->data_prio+(ip->keyword->fixed_prio<<20)) )\r
+ if( ip->keyword->data_prio \r
+ && !ip->fixedprio \r
+ && ( ip->traffic>ip->credit\r
+ + (ip->min*ip->keyword->data_prio+(ip->keyword->fixed_prio<<20))) )\r
{\r
ip->prio=priority_sequence--;\r
if(ip->prio<highest_priority+1)\r
fprintf(credit_file,"%s %Lu\n",ip->addr,lcredit);\r
}\r
}\r
- }\r
- \r
+ } \r
}\r
}\r
if(credit_file)\r
f=fopen("/var/run/prometheus.previous","w");\r
if(f)\r
{\r
- for_selected(ip,ips,ip->traffic || ip->direct || ip->proxy ||ip->upload)\r
- fprintf(f,"%s %Lu %Lu %Lu %Lu\n",ip->addr,ip->traffic,ip->direct,ip->proxy,ip->upload);\r
+ for_each(ip,ips) if(ip->traffic || ip->direct || ip->proxy || ip->upload)\r
+ {\r
+ fprintf(f,"%s %Lu %Lu %Lu %Lu\n",\r
+ ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload);\r
+ }\r
fclose(f);\r
}\r
\r
\r
if(f)\r
{\r
-\r
int count=1;\r
i=0;\r
\r
/*-----------------------------------------------------------------*/\r
- printf("Sorting data and generating statistics page %s ...\n",ptr);\r
+ printf("Sorting data and generating statistics page %s ...\n", ptr);\r
/*-----------------------------------------------------------------*/\r
\r
- fputs("<script type=\"text/javascript\" src=\"/jquery.js\"></script>\n",f);\r
+ if(use_jquery_popups)\r
+ {\r
+ fprintf(f,"<script type=\"text/javascript\" src=\"%s\"></script>\n", jquery_url);\r
+ }\r
fputs("<table border>\n<tr><th align=\"right\">#</th><th align=\"right\">group</th><th align=\"right\">IPs</th><th align=\"right\">requested</th>\n",f);\r
- fprintf(f,"<th colspan=\"%d\">data limits</th>\n",keywordcount);\r
+ fprintf(f,"<th colspan=\"%d\">data limits</th>\n", keywordcount);\r
fputs("</tr>\n",f);\r
\r
- for_each(group,groups) \r
+ for_each(group, groups) \r
{ \r
#ifdef DEBUG\r
printf("%d k group: %d bandwidth requested: %d k\n",group->min,group->count,group->desired);\r
#endif\r
- fprintf(f,"<tr><td align=\"right\">%d</td><td align=\"right\">%d k</td>",count,group->min);\r
- fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d k</td>",group->count,group->desired);\r
+ fprintf(f,"<tr><td align=\"right\">%d</td><td align=\"right\">%d k</td>",\r
+ count, group->min);\r
+ fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d k</td>",\r
+ group->count, group->desired);\r
\r
- for_each(keyword,keywords)\r
+ for_each(keyword, keywords)\r
{\r
- fprintf(f,"<td align=\"right\"><span style=\"color:#%s\">%d M</span></td>",keyword->html_color,group->min*keyword->data_limit);\r
+ fprintf(f,"<td align=\"right\"><span style=\"color:#%s\">%d M</span></td>",\r
+ keyword->html_color, group->min*keyword->data_limit);\r
} \r
- i+=group->desired; \r
- total+=group->count;\r
+ i += group->desired; \r
+ total += group->count;\r
count++; \r
}\r
#ifdef DEBUG\r
- printf("Total groups: %d Total bandwidth requested: %d k\nAGGREGATION: 1/%d\n",count,i,i/line);\r
+ printf("Total groups: %d Total bandwidth requested: %d k\nAGGREGATION: 1/%d\n",\r
+ count, i, i/line);\r
#endif\r
fprintf(f,"<tr><th colspan=\"2\" align=\"left\">Line %Ld k</td>",line);\r
fprintf(f,"<th align=\"right\">%d</td><th align=\"right\">%d k</td>",total,i);\r
\r
- for_each(keyword,keywords)\r
+ for_each(keyword, keywords)\r
{\r
fprintf(f,"<th align=\"right\">%d IPs</th>",keyword->ip_count);\r
}\r
- fprintf(f,"</tr><tr><th colspan=\"4\">Aggregation 1/%d</th>\n",(int)(0.5+i/line));\r
- fprintf(f,"<th colspan=\"%d\">%d traffic classes</th></tr>\n",keywordcount,total);\r
+ fprintf(f,"</tr><tr><th colspan=\"4\">Aggregation 1/%d</th>\n", (int)(0.5+i/line));\r
+ fprintf(f,"<th colspan=\"%d\">%d traffic classes</th></tr>\n", keywordcount, total);\r
\r
fputs("</table>\n",f);\r
}\r
- else if(!dry_run && !just_flush) \r
+ else if(!dry_run && !just_flush)\r
+ {\r
perror(html);\r
+ }\r
\r
- i=1;\r
+ i=0;\r
if(f)\r
{\r
unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0;\r
<td align=\"right\">maximum</td>\\r
<td>prio</td></tr>\n",f); \r
\r
- for_each(ip,ips)\r
+ for_each(ip,ips) if(!use_jquery_popups || !ip->sharing)\r
{\r
char *f1="", *f2="";\r
- if(ip->max<ip->desired)\r
+ i++;\r
+ \r
+ if(ip->max < ip->desired)\r
{\r
f1="<span style=\"color:red\">";\r
f2="</span>";\r
limit_count++;\r
}\r
- else if(ip->prio>highest_priority+1)\r
+ else if(ip->prio > highest_priority+1)\r
{\r
f1="<span style=\"color:brown\">";\r
f2="</span>";\r
printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r
#endif\r
/* hostnames -------------------------------------- */\r
- fprintf(f,"<tr><td align=\"right\"><a name=\"%s\"></a>%d</td><td><a href=\"%s%s.log\">%s</a>\n", ip->name, i, log_url, ip->name, ip->name); \r
- fprintf(f,"<span id=\"sharing_%d\" style=\"display:none\">",i);\r
- popup_button=0;\r
- for_selected(sharedip,ips,eq(ip->name,sharedip->sharing))\r
- {\r
- fprintf(f,"<br /><a href=\"%s%s.log\">%s</a>\n", log_url, sharedip->name, sharedip->name);\r
- popup_button=1;\r
- }\r
- fputs("</span>\n",f);\r
- if(popup_button)\r
+ fprintf(f,"<tr><td align=\"right\"><a name=\"%s\"></a>%d</td><td><a href=\"%s%s.log\">%s</a>\n", ip->name, i, log_url, ip->name, ip->name);\r
+ if(use_jquery_popups)\r
{\r
- fprintf(f,"<span>[<a href=\"#\" onClick=\"$(this).parent().hide();$(\'#sharing_%d\').show();$(\'#download_%d\').show();$(\'#upload_%d\').show();return(false);\" style=\"cursor: pointer; text-decoration:none;\">+</a>]</span>",\r
- i, i, i);\r
+ fprintf(f,"<span id=\"sharing_%d\" style=\"display:none\">",i);\r
+ popup_button=0;\r
+ for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))\r
+ {\r
+ fprintf(f,"<br /><a href=\"%s%s.log\">%s</a>\n", log_url, sharedip->name, sharedip->name);\r
+ popup_button++;\r
+ }\r
+ fputs("</span>\n",f);\r
+ if(popup_button)\r
+ {\r
+ fprintf(f,"<span>[<a href=\"#\" onClick=\"$(this).parent().hide();$(\'#sharing_%d\').show();$(\'#download_%d\').show();$(\'#upload_%d\').show();return(false);\" style=\"cursor: pointer;\">+%d</a>]</span>",\r
+ i, i, i, popup_button);\r
+ }\r
}\r
fputs("</td>\n",f);\r
/* ----------------------------------------------- */\r
if(ip->lmsid > 0)\r
{\r
/*base URL will be configurable soon ... */\r
- fprintf(f,"<a href=\"https://hermes.spoje.net/?m=customerinfo&id=%d\">%04d</a>\n", ip->lmsid, ip->lmsid);\r
+ fprintf(f,"<a href=\"%s%d\">%04d</a>\n", lms_url, ip->lmsid, ip->lmsid);\r
}\r
else if(ip->lmsid == 0)\r
{\r
fprintf(f,"<td align=\"right\"><span style=\"color:#%s\">%Lu M</span></td>",\r
ip->keyword->html_color,\r
ip->credit+(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)));\r
- fprintf(f,"<td align=\"right\">%s%Lu M%s",f1, ip->traffic, f2);\r
+ fprintf(f,"<td align=\"right\">%s%Lu M%s", f1, ip->traffic, f2);\r
\r
/* download --------------------------------------- */\r
fprintf(f,"</td><td align=\"right\">%Lu M", ip->direct);\r
- fprintf(f,"<span id=\"download_%d\" style=\"display:none\">",i);\r
- for_selected(sharedip,ips,eq(ip->name,sharedip->sharing))\r
+ if(use_jquery_popups)\r
{\r
- fprintf(f,"<br />%Lu M", sharedip->direct);\r
+ fprintf(f,"<span id=\"download_%d\" style=\"display:none\">",i);\r
+ for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))\r
+ {\r
+ fprintf(f,"<br />%Lu M", sharedip->direct);\r
+ }\r
+ fputs("</span>\n",f);\r
}\r
- fputs("</span></td>\n",f);\r
+ fputs("</td>\n",f);\r
/* ----------------------------------------------- */\r
\r
if(qos_proxy)\r
}\r
/* upload ---------------------------------------- */\r
fprintf(f,"<td align=\"right\">%Lu M", ip->upload);\r
- fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">",i);\r
- for_selected(sharedip,ips,eq(ip->name,sharedip->sharing))\r
+ if(use_jquery_popups)\r
{\r
- fprintf(f,"<br />%Lu M", sharedip->upload);\r
+ fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">",i);\r
+ for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))\r
+ {\r
+ fprintf(f,"<br />%Lu M", sharedip->upload);\r
+ }\r
+ fputs("</span>\n",f);\r
}\r
- fputs("</span></td>\n",f);\r
+ fputs("</td>\n",f);\r
/* ----------------------------------------------- */\r
\r
fprintf(f,"<td align=\"right\">%d k</td><td align=\"right\">%d k</td><td align=\"right\">%s%d k%s</td><td>%s%d%s</td></tr>\n",\r
ip->min,ip->desired,f1,ip->max,f2,f1,ip->prio,f2);\r
+\r
total_traffic+=ip->traffic;\r
total_direct+=ip->direct;\r
total_proxy+=ip->proxy;\r
sum->i=active_classes;\r
insert(sum,sums,order_by,i);\r
}\r
- \r
- i++;\r
- \r
+\r
if(!just_preview)\r
{\r
sprintf(str,"%s/%s.log",log_dir,ip->name);\r
if(iplog)\r
{\r
fprintf(iplog,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
- time(NULL),ip->name,ip->traffic,ip->direct,ip->proxy,ip->upload,ip->min,ip->max,ip->desired,ip->lmsid,d); /* d = date*/\r
+ time(NULL), ip->name, ip->traffic, ip->direct, ip->proxy,\r
+ ip->upload, ip->min, ip->max, ip->desired, ip->lmsid, d); /* d = date*/\r
fclose(iplog);\r
}\r
}\r
}\r
- fprintf(f,"<tr><th colspan=\"%d\" align=\"left\">SUMMARY:</td>",colspan-7);\r
+ fprintf(f,"<tr><th colspan=\"%d\" align=\"left\">%d CLASSES</th>", colspan-7, i);\r
fprintf(f,"<th align=\"right\">%Lu M</th><th align=\"right\">%Lu M</th>\n", total_traffic, total_direct);\r
if(qos_proxy)\r
{\r
{\r
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",\r
time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, \r
- active_classes, total_traffic, total, limit_count, prio_count, d); /* d = date*/\r
+ active_classes, total_traffic, i, limit_count, prio_count, d); /* d = date*/\r
fclose(iplog);\r
}\r
}\r
i=0;\r
printf("%-22s %-15s mark\n","name","ip");\r
\r
- for_selected(ip,ips,ip->mark>0)\r
+ for_each(ip,ips) if(ip->mark>0)\r
{ \r
- \r
if(idxs)\r
{\r
char *buf;\r