From c9012978d51f85e4209bc0c7fc5ef78df5c3b38e Mon Sep 17 00:00:00 2001 From: ludvik Date: Tue, 15 Apr 2008 15:50:51 +0000 Subject: [PATCH] oprava - statistiky -l -m -y, nebyl zpracovan config pri jejich spusteni oprava - je spravne logovan provoz free-zone (0.0.0.0/0) git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@75 251d49ef-1d17-4917-a970-b30cf55b089b --- prometheus.c | 308 ++++++++++++++++++++++++++------------------------- 1 file changed, 157 insertions(+), 151 deletions(-) diff --git a/prometheus.c b/prometheus.c index 9e658fe..8e74a44 100644 --- a/prometheus.c +++ b/prometheus.c @@ -20,11 +20,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with Prometheus Qos; if not, write to the Free Software + You should have received a copy of the GNU General Public License + along with Prometheus Qos; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - GNU General Public License is located in file COPYING */ + GNU General Public License is located in file COPYING */ #define STRLEN 256 #define FIRSTGROUPID 1024 @@ -628,35 +628,35 @@ char *parse_datafile_line(char *str) return NULL; } -struct IpLog -{ - char *name; - long traffic; - list(IpLog); -} *iplog,*iplogs; - -void parse_ip_log(int argc, char **argv) -{ - char *month,*year,*str,*name,*ptr,*ptr2; - long traffic,traffic_month,total=0; +struct IpLog +{ + char *name; + long traffic; + list(IpLog); +} *iplog,*iplogs; + +void parse_ip_log(int argc, char **argv) +{ + char *month,*year,*str,*name,*ptr,*ptr2; + long traffic,traffic_month,total=0; int col,col2,y_ok,m_ok,accept_month,i=1,any_month=0; - char mstr[4],ystr[5]; - FILE *f; - - string(str,STRLEN); - + char mstr[4],ystr[5]; + FILE *f; + + string(str,STRLEN); + if(argv[1][1]=='l') /* -l */ { - if(argc<4) - { - puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)"); - exit(-1); - } - else - { - month=argv[2]; - if(eq(month,"Year")) any_month=1; - year=argv[3]; + if(argc<4) + { + puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)"); + exit(-1); + } + else + { + month=argv[2]; + if(eq(month,"Year")) any_month=1; + year=argv[3]; } } else @@ -680,65 +680,65 @@ void parse_ip_log(int argc, char **argv) } } printf("Analysing traffic for %s %s ...\n",month,year); - - sprintf(str,"%s %s/*.log",ls,log_dir); - shell(str); - input(str,STRLEN) - { - ptr=strrchr(str,'\n'); - if(ptr) *ptr='\0'; - printf("Parsing %s ...",str); - accept_month=0; - traffic_month=0; - parse(str) - { - y_ok=m_ok=0; - valid_columns(ptr,_,'\t',col) switch(col) - { - case 2: name=ptr;break; - case 3: traffic=atol(ptr);break; - case 7: valid_columns(ptr2,ptr,' ',col2) switch(col2) - { - case 2: if(any_month || eq(ptr2,month)) m_ok=1; break; - case 5: if(eq(ptr2,year)) y_ok=1; break; - } - } - if(y_ok && m_ok) - { - traffic_month+=traffic; - accept_month=1; - } - } - done; - if(accept_month) - { - create(iplog,IpLog); - iplog->name=name; - iplog->traffic=traffic_month; - insert(iplog,iplogs,desc_order_by,traffic); - printf(" %ld MB\n",iplog->traffic); - } - else - puts(" no records."); - } - sprintf(str,"%s/%s-%s.html",html_log_dir,year,month); - printf("Writing %s ...",str); - f=fopen(str,"w"); - if(f) - { - fprintf(f,"\n ",month,year); - every(iplog,iplogs) - if(iplog->traffic) - { - fprintf(f,"\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10); - total+=iplog->traffic>>10; - } - fprintf(f,"\n",total); - fputs("
Data transfers - %s %s
%d%s%ld MB%ld GB
Total:%ld GB
\n",f); - fclose(f); - puts(" done."); - } -} + + sprintf(str,"%s %s/*.log",ls,log_dir); + shell(str); + input(str,STRLEN) + { + ptr=strrchr(str,'\n'); + if(ptr) *ptr='\0'; + printf("Parsing %s ...",str); + accept_month=0; + traffic_month=0; + parse(str) + { + y_ok=m_ok=0; + valid_columns(ptr,_,'\t',col) switch(col) + { + case 2: name=ptr;break; + case 3: traffic=atol(ptr);break; + case 7: valid_columns(ptr2,ptr,' ',col2) switch(col2) + { + case 2: if(any_month || eq(ptr2,month)) m_ok=1; break; + case 5: if(eq(ptr2,year)) y_ok=1; break; + } + } + if(y_ok && m_ok) + { + traffic_month+=traffic; + accept_month=1; + } + } + done; + if(accept_month) + { + create(iplog,IpLog); + iplog->name=name; + iplog->traffic=traffic_month; + insert(iplog,iplogs,desc_order_by,traffic); + printf(" %ld MB\n",iplog->traffic); + } + else + puts(" no records."); + } + sprintf(str,"%s/%s-%s.html",html_log_dir,year,month); + printf("Writing %s ...",str); + f=fopen(str,"w"); + if(f) + { + fprintf(f,"\n ",month,year); + every(iplog,iplogs) + if(iplog->traffic) + { + fprintf(f,"\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10); + total+=iplog->traffic>>10; + } + fprintf(f,"\n",total); + fputs("
Data transfers - %s %s
%d%s%ld MB%ld GB
Total:%ld GB
\n",f); + fclose(f); + puts(" done."); + } +} /*-----------------------------------------------------------------*/ @@ -776,9 +776,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); argument("-9") { just_flush=9; } argument("-p") { just_preview=1; } argument("-n") { nodelay=1; } - argument("-l") { parse_ip_log(argc,argv); exit(0); } - argument("-m") { parse_ip_log(argc,argv); exit(0); } - argument("-y") { parse_ip_log(argc,argv); exit(0); } + argument("-l") { just_preview=666; } + argument("-m") { just_preview=666; } + argument("-y") { just_preview=666; } argument("-?") { help(); exit(0); } argument("--help") { help(); exit(0); } argument("-v") { exit(0); } @@ -794,6 +794,12 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); printf("Parsing configuration file %s ...\n", config); /*-----------------------------------------------------------------*/ get_config(config); + + if(just_preview == 666) + { + parse_ip_log(argc,argv); + exit(0); + } if(althosts) hosts=althosts; @@ -1383,63 +1389,63 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); fputs("\n\n",f); if(active_classes>10) - { - fputs("

\n",f); - fputs("\n",f); - fputs("\n",f); - - find(sum,sums,sum->l>=total/4) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i==10) - { - fprintf(f,"\n"); - fprintf(f,"\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->l>=total/2) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->l>=4*total/5) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find (sum,sums,sum->i>=(active_classes+1)/5) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i>=(active_classes+1)/4) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i>=(active_classes+1)/2) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - find(sum,sums,sum->i>=4*(active_classes+1)/5) - { - fprintf(f,"\n"); - fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); - } - - fprintf(f,"\n"); - fprintf(f,"\n",active_classes,total); - fputs("
Enterprise Research and Planning (ERP)
Analytic categoryActive ClassesData transfers
Top 25%% of traffic%d%d %%%Lu M%Ld %%
Top 10 downloaders10%d %%%Lu M%Ld %%
Top 50%% of traffic%d%d %%%Lu M%Ld %%
Top 80%% of traffic%d%d %%%Lu M%Ld %%
Top 20%% downloaders%d%d %%%Lu M%Ld %%
Top 25%% downloaders%d%d %%%Lu M%Ld %%
Top 50%% downloaders%d%d %%%Lu M%Ld %%
Top 80%% downloaders%d%d %%%Lu M%Ld %%
All users, all traffic%d100 %%%Lu M100 %%
\n",f); - } + { + fputs("

\n",f); + fputs("\n",f); + fputs("\n",f); + + find(sum,sums,sum->l>=total/4) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i==10) + { + fprintf(f,"\n"); + fprintf(f,"\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->l>=total/2) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->l>=4*total/5) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find (sum,sums,sum->i>=(active_classes+1)/5) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i>=(active_classes+1)/4) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i>=(active_classes+1)/2) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + find(sum,sums,sum->i>=4*(active_classes+1)/5) + { + fprintf(f,"\n"); + fprintf(f,"\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total); + } + + fprintf(f,"\n"); + fprintf(f,"\n",active_classes,total); + fputs("
Enterprise Research and Planning (ERP)
Analytic categoryActive ClassesData transfers
Top 25%% of traffic%d%d %%%Lu M%Ld %%
Top 10 downloaders10%d %%%Lu M%Ld %%
Top 50%% of traffic%d%d %%%Lu M%Ld %%
Top 80%% of traffic%d%d %%%Lu M%Ld %%
Top 20%% downloaders%d%d %%%Lu M%Ld %%
Top 25%% downloaders%d%d %%%Lu M%Ld %%
Top 50%% downloaders%d%d %%%Lu M%Ld %%
Top 80%% downloaders%d%d %%%Lu M%Ld %%
All users, all traffic%d100 %%%Lu M100 %%
\n",f); + } fprintf(f,"Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2008 Michael Polak, Arachne Labs
\n",version); fclose(f); } @@ -1567,18 +1573,18 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); if(qos_proxy) { - sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j MARK --set-mark 3",chain_postrouting,proxy_ip,proxy_port,lan); + sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j %s%d",chain_postrouting,proxy_ip,proxy_port,lan,mark_iptables,3); save_line(str); sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j ACCEPT",chain_postrouting,proxy_ip,proxy_port,lan); save_line(str); } - sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_postrouting,lan); + sprintf(str,"-A %s -o %s -j %s%d",chain_postrouting,lan,mark_iptables,3); save_line(str); sprintf(str,"-A %s -o %s -j ACCEPT",chain_postrouting,lan); save_line(str); /* -------------------------------------------------------- mark upload */ - sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_forward,wan); + sprintf(str,"-A %s -o %s -j %s%d",chain_forward,wan,mark_iptables,3); save_line(str); sprintf(str,"-A %s -o %s -j ACCEPT",chain_forward,wan); save_line(str); -- 2.30.2