- /* sorry... next release of C<<1 header file will include for_path_files(name,path) { } macro */\r
- sprintf(str,"%s %s/",ls,log_dir);\r
- shell(str);\r
- input(str,STRLEN) \r
- {\r
- if(strstr(str,".log"))\r
- {\r
- ptr=strrchr(str,'\n');\r
- if(ptr) *ptr='\0';\r
- sprintf(filename,"%s/%s",log_dir,str);\r
- printf("Parsing %s ...",filename);\r
- accept_month=0;\r
- traffic_month=0;\r
- guaranted=0;\r
- lmsid=-1;\r
- parse(filename)\r
- {\r
- y_ok=m_ok=0; \r
- valid_columns(ptr,_,'\t',col) switch(col)\r
- {\r
- case 2: name = ptr;break;\r
- case 3: traffic = atol(ptr);break;\r
- /* column number - was 7, now 11...*/\r
- case 7:\r
- case 8:\r
- case 9:\r
- case 10:\r
- case 11: if(isalpha(*ptr)) /* character, not numeric string = date, just one*/\r
- {\r
- valid_columns(ptr2,ptr,' ',col2) switch(col2)\r
- {\r
- case 2: if(any_month || eq(ptr2,month)) m_ok = 1; break;\r
- case 5: if(eq(ptr2,year)) y_ok = 1; break;\r
- }\r
- }\r
- else\r
- {\r
- if(col == 7) guaranted = atol(ptr);\r
- if(col == 10) lmsid = atoi(ptr);\r
- }\r
- }\r
- \r
- if(y_ok && m_ok) \r
- {\r
- traffic_month += traffic;\r
- accept_month = 1;\r
- }\r
- }\r
- done;\r
-\r
- if(accept_month)\r
- {\r
- create(iplog,IpLog);\r
- iplog->name = name;\r
- iplog->guaranted = guaranted;\r
- iplog->traffic = traffic_month;\r
- iplog->lmsid = lmsid;\r
- insert(iplog,iplogs,desc_order_by,traffic);\r
- printf(" %ld MB\n",iplog->traffic);\r
- }\r
- else\r
- {\r
- puts(" no records.");\r
- }\r
- }\r
- }\r
- sprintf(str,"%s/%s-%s.html",html_log_dir,year,month);\r
- printf("Writing %s ... ",str);\r
- f=fopen(str,"w");\r
- if(f > 0)\r
- {\r
- fprintf(f, "<table class=\"decorated last\"><thead>\n\\r
-<tr><th colspan=\"2\">%s %s</th>\n\\r
-<th style=\"text-align: right\">lms</th>\n\\r
-<th colspan=\"2\">Data transfers</th>\n\\r
-<th style=\"text-align: right\">Min.speed</th>\n\\r
-</tr></thead><tbody>\n ",\r
- month, year);\r
-\r
- row_odd_even = 0;\r
- for_each(iplog, iplogs)\r
- {\r
- if(iplog->traffic)\r
- {\r
- fprintf(f, "%s<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: left\"><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</td>\n\\r
-<td style=\"text-align: right\">", \r
- tr_odd_even(), i++, log_url, iplog->name, iplog->name); \r
- if(iplog->lmsid > 0)\r
- {\r
- /*base URL will be configurable soon ... */\r
- fprintf(f, "<a class=\"blue\" target=\"_blank\" 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 style=\"text-align: right\">%ld MB</td>\n\\r
- <td style=\"text-align: right\"><strong>%ld GB</strong></td>\n\\r
- <td style=\"text-align: right\">%ld kb/s</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
- }\r
- fprintf(f,"</tbody><thead><tr>\\r
- <th colspan=\"3\" style=\"text-align: left\">Total:</th>\\r
- <th colspan=\"2\" style=\"text-align: right\"><strong>%ld GB</strong></th>\\r
- <th style=\"text-align: right\"><strong>%Ld kb/s</strong></th></tr>\n", total, line);\r
- fputs("</thead></table>\n", f);\r
-\r
- row_odd_even = 0;\r
- if(i>10)\r
- {\r
- fputs("<a name=\"erp\"></a><p><table class=\"decorated last\">\n\\r
-<caption>Enterprise Resource Planning (ERP)</caption>\n\\r
-<thead><tr>\n\\r
-<th>Analytic category</th>\n\\r
-<th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\\r
-<th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\\r
-</tr></thead><tbody>\n",f);\r
-\r
- if_exists(iplog,iplogs,iplog->l>=total/4)\r
- {\r
- fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\">%d %%</td></tr>\n",\r
- iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
- }\r
- \r
- if_exists(iplog,iplogs,iplog->i==10)\r
- {\r
- fprintf(f,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\"><strong>10</strong></td>\n\\r
-<td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\">%d %%</td></tr>\n",\r
- (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
- }\r
-\r
- if_exists(iplog,iplogs,iplog->l>=total/2)\r
- {\r
- fprintf(f,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\"><strong>%d %%</strong></td></tr>\n",\r
- iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
- }\r
-\r
- if_exists(iplog,iplogs,iplog->l>=4*total/5)\r
- {\r
- fprintf(f,"%s<td>Top 80%% of traffic</td>\n",tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\"><strong>%d %%</strong></td></tr>\n",\r
- iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
- }\r
-\r
- if_exists (iplog,iplogs,iplog->i>=i/5)\r
- {\r
- fprintf(f,"%s<td>Top 20%% downloaders</td>\n",tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\">%d %%</td></tr>\n",\r
- iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
- }\r
-\r
- if_exists(iplog,iplogs,iplog->i>=i/4)\r
- {\r
- fprintf(f,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\">%d %%</td></tr>\n",\r
- iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
- }\r
-\r
- if_exists(iplog,iplogs,iplog->i>=i/2)\r
- {\r
- fprintf(f,"%s<td>Top 50%% downloaders</td>\n",tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\">%d %%</td></tr>\n",\r
- iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
- }\r
-\r
- if_exists(iplog,iplogs,iplog->i>=4*i/5)\r
- {\r
- fprintf(f,"%s<td>Top 80%% downloaders</td>\n",tr_odd_even());\r
- fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld GB</td>\n\\r
-<td style=\"text-align: right\">%d %%</td></tr>\n",\r
- iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
- }\r
-\r
- fprintf(f,"</tbody><thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r
- fprintf(f,"<th style=\"text-align: right\">%d</th>\n\\r
-<th style=\"text-align: right\">100 %%</th>\n\\r
-<th style=\"text-align: right\">%ld GB</th>\n\\r
-<th style=\"text-align: right\">100 %%</th></tr>\n",i-1,total);\r
- fputs("</thead></table>\n", f);\r
- }\r
-\r
- fprintf(f, stats_html_signature, version);\r
- fclose(f);\r
- puts("done.");\r
- }\r
- else\r
- {\r
- perror(str);\r
- }\r
-}\r
-\r
-void append_log(struct IP *self) /*using global variables*/\r
-{\r
- char *d, *str;\r
- FILE *f; \r
-\r
- date(d); /* this is typical cll1.h macro - prints current date */ \r
- string(str,STRLEN); \r
- sprintf(str,"%s/%s.log", log_dir, self->name);\r
- f=fopen(str,"a");\r
- if(f > 0)\r
- {\r
- fprintf(f,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
- time(NULL), self->name, self->traffic, self->direct, self->proxy,\r
- self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/\r
- fclose(f);\r
- }\r
- else\r
- {\r
- perror(str);\r
- }\r
-}\r
-\r
-\r
-/*-----------------------------------------------------------------*/\r
-/* Are you looking for int main(int argc, char **argv) ? :-)) */\r
-/*-----------------------------------------------------------------*/\r
-\r
-program\r
-{\r
- int i=0;\r
- FILE *f=NULL;\r
- char *str, *ptr, *d;\r
- char *substring;\r
- int class_count=0,ip_count=0;\r
- int parent=1;\r
- int just_flush=FALSE;\r
- int nodelay=FALSE;\r
- int just_preview=FALSE; /* preview - generate just stats */\r
- int just_logs=FALSE; /* just parse logs */\r
- int run=FALSE;\r
- int total=0;\r
- \r
- char *chain_forward, *chain_postrouting;\r
- char *althosts=NULL;\r
- \r
- printf("\n\\r
-Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\\r
-Version %s - Copyright (C)2005-2012 Michael Polak (xChaos)\n\\r
-iptables-restore & burst tunning & classify modification by Ludva\n\\r
-Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);\r
-\r
- /*----- Boring... we have to check command line options first: ----*/\r
- \r
- arguments\r
- {\r
- argument("-c") { nextargument(config); }\r
- argument("-h") { nextargument(althosts);}\r
- argument("-d") { run=TRUE; dry_run=TRUE; }\r
- argument("-f") { run=TRUE; just_flush=TRUE; }\r
- argument("-9") { run=TRUE; just_flush=9; }\r
- argument("-p") { run=TRUE; just_preview=TRUE; }\r
- argument("-r") { run=TRUE; }\r
- argument("-n") { run=TRUE; nodelay=TRUE; }\r
- argument("-l") { just_logs=TRUE; }\r
- argument("-m") { just_logs=TRUE; }\r
- argument("-y") { just_logs=TRUE; }\r
- argument("-?") { help(); exit(0); }\r
- argument("--help") { help(); exit(0); }\r
- argument("-v") { exit(0); } \r
- argument("--version") { exit(0); } \r
- }\r
- \r
- if(dry_run)\r
- {\r
- puts("*** THIS IS JUST DRY RUN ! ***\n");\r
- }\r