X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=prometheus.c;h=5b90528c7bad21025eb4c6bd12c08ae29f9ff623;hb=2d1141371d8f714276b8b17ff3d55a5dfc91b900;hp=38bd53b8e3e2ffd2ed1f4917cf9157fd515a5b4e;hpb=33ec95ab4c8797bc37e0ccc97411f7c67bd08f80;p=svn%2FPrometheus-QoS%2F.git diff --git a/prometheus.c b/prometheus.c index 38bd53b..5b90528 100644 --- a/prometheus.c +++ b/prometheus.c @@ -33,27 +33,34 @@ #include "cll1-0.6.h" -const char *version="0.7.9.2"; /*0.7.9 will be last development, 0.8.0 first stable */ +const char *version = "0.7.9-c"; -/* ======= All path names are defined hear (for RPM patch) ======= */ +/* Version numbers: 0.7.9 will be last development ("beta"), 0.8.0 first stable */ +/* Debian(RPM) package versions/patchlevels: 0.7.9-2, 0.8.0-1, 0.8.0-2, etc. */ +/* C source code development versions ("beta"): 0.7.9-a, 0.8.1-b, etc. */ +/* C source code release versions: 0.8.0, 0.8.2, 0.8.4, etc. */ -char *tc = "/sbin/tc"; /* requires tc with HTB support */ -char *iptables = "/sbin/iptables"; /* requires iptables utility */ -char *iptablessave = "/sbin/iptables-save"; /* not yet required */ +const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2008 Michael Polak, Arachne Labs
\n"; + +/* ======= All path names are defined here (for RPM patch) ======= */ + +char *tc = "/sbin/tc"; /* requires tc with HTB support */ +char *iptables = "/sbin/iptables"; /* requires iptables utility */ +char *iptablessave = "/sbin/iptables-save"; /* not yet required */ char *iptablesrestore = "/sbin/iptables-restore"; /* requires iptables-restore */ -char *ls = "/bin/ls"; /* this is not user configurable :-) */ +char *ls = "/bin/ls"; /* this is not user configurable :-) */ -char *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */ -char *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */ +char *config = "/etc/prometheus/prometheus.conf"; /* main configuration file */ +char *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */ -char *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/ -char *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */ -char *html = "/var/www/traffic.html"; /* hall of fame filename */ -char *preview = "/var/www/preview.html"; /* hall of fame preview */ -char *cmdlog = "/var/log/prometheuslog"; /* command log filename */ -char *log_dir = "/var/www/logs/"; /* log directory pathname, ended with slash */ -char *log_url = "logs/"; /* log directory relative URI prefix (partial URL) */ -char *html_log_dir = "/var/www/logs/html/"; +char *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/ +char *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */ +char *html = "/var/www/traffic.html"; /* hall of fame filename */ +char *preview = "/var/www/preview.html"; /* hall of fame preview */ +char *cmdlog = "/var/log/prometheuslog"; /* command log filename */ +char *log_dir = "/var/www/logs/"; /* log directory pathname, ended with slash */ +char *log_url = "logs/"; /* log directory relative URI prefix (partial URL) */ +char *html_log_dir = "/var/www/logs/html/"; /* ======= Help screen is hopefuly self-documenting part of code :-) ======= */ @@ -435,7 +442,7 @@ void get_config(char *config_filename) /* are supplied values meaningful ?*/ if(line<=0 || up<=0) { - puts("Illegal value of wan bandwidth: 0 kbps."); + puts("Illegal value of LAN or WAN bandwidth: 0 kbps."); reject_config_and_exit(config_filename); } } @@ -547,7 +554,6 @@ void get_traffic_statistics(void) } } - free(cmd); } @@ -632,17 +638,17 @@ struct IpLog { char *name; long traffic; + long guaranted; 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; - + char *month, *year, *str, *name, *ptr, *ptr2; + long traffic, traffic_month, total=0, guaranted; + int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0; + char mstr[4], ystr[5]; + FILE *f; string(str,STRLEN); if(argv[1][1]=='l') /* -l */ @@ -683,6 +689,7 @@ void parse_ip_log(int argc, char **argv) sprintf(str,"%s %s/*.log",ls,log_dir); shell(str); + input(str,STRLEN) { ptr=strrchr(str,'\n'); @@ -690,31 +697,46 @@ void parse_ip_log(int argc, char **argv) printf("Parsing %s ...",str); accept_month=0; traffic_month=0; + guaranted = 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; - } + case 2: name = ptr;break; + case 3: traffic = atol(ptr);break; + /* column number - was 7, now 10...*/ + case 7: + case 8: + case 9: + case 10: if (isalpha(*ptr)) /* character, not numeric string = date, just one*/ + { + 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; + } + } + else + { + if(col == 7) guaranted = atol(ptr); + } } + if(y_ok && m_ok) { - traffic_month+=traffic; - accept_month=1; + traffic_month += traffic; + accept_month = 1; } } done; + if(accept_month) { create(iplog,IpLog); - iplog->name=name; - iplog->traffic=traffic_month; + iplog->name = name; + iplog->guaranted = guaranted; + iplog->traffic = traffic_month; insert(iplog,iplogs,desc_order_by,traffic); printf(" %ld MB\n",iplog->traffic); } @@ -726,15 +748,17 @@ void parse_ip_log(int argc, char **argv) f=fopen(str,"w"); if(f) { - fprintf(f,"\n ",month,year); + fprintf(f,"
Data transfers - %s %s
\n ",month,year); every(iplog,iplogs) if(iplog->traffic) { - fprintf(f,"\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10); + fprintf(f,"\n", + i++, iplog->name, iplog->traffic, iplog->traffic>>10, iplog->guaranted); total+=iplog->traffic>>10; } - fprintf(f,"\n",total); - fputs("
Data transfers - %s %sMin.speed
%d%s%ld MB%ld GB
%d%s%ld MB%ld GB%ld kbps
Total:%ld GB
\n",f); + fprintf(f,"Total:%ld GB%Ld kbps\n", total, line); + fputs("\n", f); + fprintf(f, stats_html_signature, version); fclose(f); puts(" done."); } @@ -1446,9 +1470,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); fprintf(f,"All users, all traffic\n"); fprintf(f,"%d100 %%%Lu M100 %%\n",active_classes,total); - fputs("\n",f); + fputs("\n", f); } - fprintf(f,"Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2008 Michael Polak, Arachne Labs
\n",version); + fprintf(f, stats_html_signature, version); fclose(f); }