drobnosti
[svn/Prometheus-QoS/.git] / prometheus.c
index 89890d6acc77373fff99fb9504374ed44999ba7e..38bd53b8e3e2ffd2ed1f4917cf9157fd515a5b4e 100644 (file)
@@ -1,14 +1,14 @@
-\r
-/* ============================================================= */\r
-/* === Prometheus QoS - you can "steal fire" from your ISP   === */\r
-/* === "fair-per-IP" quality of service (QoS) utility        === */\r
-/* === requires Linux 2.4.x or 2.6.x with HTB support        === */\r
-/* === Copyright(C) 2005-2007 Michael Polak (xChaos)         === */\r
-/* === Credits: CZFree.Net, Martin Devera, Netdave, Aquarius === */\r
-/* ============================================================= */\r
-\r
-/* Modified: xChaos, 20070502\r
-             ludva, 20071227\r
+  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
+ /*     Prometheus QoS - you can "steal fire" from your ISP     */\r
+/*      "fair-per-IP" quality of service (QoS) utility          */\r
+/*      requires Linux 2.4.x or 2.6.x with HTB support          */\r
+/*      Copyright(C) 2005-2008 Michael Polak (xChaos)           */\r
+/*    iptables-restore support Copyright(C) 2007-2008 ludva     */\r
+/*  Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
+/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
+\r
+/* Modified: xChaos, 20080422\r
+             ludva, 20080415\r
 \r
    Prometheus QoS is free software; you can redistribute it and/or\r
    modify it under the terms of the GNU General Public License as \r
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
    General Public License for more details.\r
 \r
-   You should have received a copy of the GNU General Public License \r
-   along with the Linux kernel source code; if not, write to \r
-   Michael Polak, Svojsikova 7, 169 00 Praha 6 Czech Republic */\r
+   You should have received a copy of the GNU General Public License\r
+   along with Prometheus Qos; if not, write to the Free Software\r
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA \r
+   \r
+   GNU General Public License is located in file COPYING */\r
 \r
 #define STRLEN 256\r
 #define FIRSTGROUPID 1024\r
-#define MAX_GUARANTED_KBPS 2048\r
+#define FIRSTIPCLASS 2048\r
 #undef DEBUG\r
 \r
-#include "cll1.h"\r
+#include "cll1-0.6.h"\r
+\r
+const char *version="0.7.9.2"; /*0.7.9 will be last development, 0.8.0 first stable */\r
+\r
+/* ======= All path names are defined hear (for RPM patch) =======  */\r
+\r
+char *tc              = "/sbin/tc"; /* requires tc with HTB support */\r
+char *iptables        = "/sbin/iptables"; /* requires iptables utility */\r
+char *iptablessave    = "/sbin/iptables-save"; /* not yet required */\r
+char *iptablesrestore = "/sbin/iptables-restore";  /* requires iptables-restore */\r
+char *ls              = "/bin/ls"; /* this is not user configurable :-) */\r
+\r
+char *config          = "/etc/prometheus/prometheus.conf"; /* main configuration file */\r
+char *hosts           = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */\r
 \r
-const char *version="0.7.1";\r
+char *iptablesfile    = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/\r
+char *credit          = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
+char *html            = "/var/www/traffic.html"; /* hall of fame filename */\r
+char *preview         = "/var/www/preview.html"; /* hall of fame preview */\r
+char *cmdlog          = "/var/log/prometheuslog"; /* command log filename */\r
+char *log_dir         = "/var/www/logs/"; /* log directory pathname, ended with slash */\r
+char *log_url         = "logs/"; /* log directory relative URI prefix (partial URL) */\r
+char *html_log_dir    = "/var/www/logs/html/";\r
 \r
 /* ======= Help screen is hopefuly self-documenting part of code :-) ======= */\r
 \r
@@ -48,7 +70,13 @@ void help(void)
 -p            just generate preview of data transfer statistics and exit\n\\r
 -n            no delay (overrides qos-free-delay keyword)\n\\r
 -d            dry run (preview tc and iptables commands on stdout)\n\\r
-");\r
+-l Mmm YYYY   generate HTML summary of traffic logs (Mmm=Jan-Dec or Year, YYYY=year)\n\\r
+-m            generate HTML summary of traffic logs for yesterday's month\n\\r
+-y            generate HTML summary of traffic logs for yesterday's year\n");\r
+/* not yet implemented:\r
+-s            start shaping! (keep data transfer statistics - but apply shaping)\n\\r
+-r            just reload configuration (...and keep data transfer statistics)\n\\r
+*/\r
 }\r
 \r
 /* === Configuraration file values defaults - stored in global variables ==== */\r
@@ -57,23 +85,10 @@ int filter_type=1;                      /*1 mark, 2 classify*/
 char *mark="MARK";\r
 char *mark_iptables="MARK --set-mark ";\r
 int dry_run=0;                         /* preview - use puts() instead of system() */\r
-char *config="/etc/prometheus.conf";   /* main configuration file */\r
-char *hosts="/etc/hosts";              /* line bandwidth definition file */\r
-char *tc="/sbin/tc";                   /* requires tc with HTB support */\r
-char *iptables="/usr/sbin/iptables";       /* requires iptables utility */\r
-char *iptablessave="/usr/sbin/iptables-save"; /* new */\r
-char *iptablesrestore="/usr/sbin/iptables-restore";  /* new */\r
-char *iptablesfile="/var/spool/prometheus.iptables";  /* new; file for iptables-restore*/\r
 char *iptablespreamble="*mangle\n:PREROUTING ACCEPT [0:0]\n:POSTROUTING ACCEPT [0:0]\n:INPUT ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]";\r
 FILE *iptables_file=NULL;\r
-char *html="/var/www/traffic.html";    /* hall of fame filename */\r
-char *preview="/var/www/preview.html"; /* hall of fame preview */\r
-char *cmdlog="/var/log/prometheus";    /* command log filename */\r
-char *credit="/var/run/prometheus.credit";  /* credit log file */\r
 int enable_credit=1;                   /* enable credit file */\r
 int use_credit=0;                      /* use credit file (if enabled)*/\r
-char *log_dir="/var/www/html/logs/";   /* log directory pathname */\r
-char *log_url="logs/";                 /* log directory URL prefix */\r
 char *title="Hall of Fame - Greatest Suckers"; /* hall of fame title */\r
 int hall_of_fame=1;                           /* enable hall of fame */\r
 char *lan="eth0";                /* LAN interface */\r
@@ -86,8 +101,8 @@ int qos_proxy=1;              /* include proxy port to QoS */
 int include_upload=1;           /* upload+download=total traffic */\r
 char *proxy_ip="192.168.1.1/32"; /* our IP with proxy port */\r
 int proxy_port=3128;     /* proxy port number */\r
-long long int line=1024;            /* WAN/ISP download in kbps */\r
-long long int up=1024;              /* WAN/ISP upload in kbps */\r
+long long int line=1024;  /* WAN/ISP download in kbps */\r
+long long int up=1024;    /* WAN/ISP upload in kbps */\r
 int free_min=32;          /* minimum guaranted bandwidth for all undefined hosts */\r
 int free_max=64;          /* maximum allowed bandwidth for all undefined hosts */\r
 int qos_free_delay=0;    /* seconds to sleep before applying new QoS rules */\r
@@ -109,16 +124,10 @@ FILE *log_file=NULL;
 \r
 char *kwd="via-prometheus";           /* /etc/hosts comment, eg. #qos-64-128 */\r
 \r
-const idxtable_treshold1=24;         /* this is no longer configurable */\r
-const idxtable_treshold2=12;         /* this is no longer configurable */\r
-const idxtable_bitmask1=3;           /* this is no longer configurable */\r
-const idxtable_bitmask2=3;           /* this is no longer configurable */\r
-\r
-\r
-/* not yet implemented:\r
--s            start shaping! (keep data transfer statistics - but apply shaping)\n\\r
--r            just reload configuration (...and keep data transfer statistics)\n\\r
-*/\r
+const int idxtable_treshold1=24;      /* this is no longer configurable */\r
+const int idxtable_treshold2=12;      /* this is no longer configurable */\r
+const int idxtable_bitmask1=3;        /* this is no longer configurable */\r
+const int idxtable_bitmask2=3;        /* this is no longer configurable */\r
 \r
 /* ==== This is C<<1 stuff - learn C<<1 first! http://cll1.arachne.cz ==== */\r
 \r
@@ -171,7 +180,7 @@ struct Keyword
  int asymetry_ratio;        /* ratio for ADSL-like upload */\r
  int asymetry_fixed;        /* fixed treshold for ADSL-like upload */\r
  int data_limit;            /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */\r
- int prio_limit;            /* soft shaping (qos): reduce HTB prio if max*prio_limit MB exceeded */\r
+ int data_prio;            /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */\r
  long fixed_limit;          /* fixed data limit for setting lower HTB ceil */\r
  long fixed_prio;           /* fixed data lmit for setting lower HTB prio */\r
  int reserve_min;          /* bonus for nominal HTB rate bandwidth (in kbps) */\r
@@ -203,7 +212,7 @@ void TheIP(void)
  push(ip,ips);\r
 }\r
 \r
-/* ====== Iptables indexes are used to reduce complexity to log8(N) ===== */\r
+/* ====== iptables indexes are used to reduce complexity to log8(N) ===== */\r
 \r
 char *very_ugly_ipv4_code(char *inip,int bitmask,int format_as_chainname)\r
 {\r
@@ -300,7 +309,7 @@ void get_config(char *config_filename)
    keyword->asymetry_ratio=1;          /* ratio for ADSL-like upload */\r
    keyword->asymetry_fixed=0;          /* fixed treshold for ADSL-like upload */\r
    keyword->data_limit=8;              /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */\r
-   keyword->prio_limit=4;              /* soft shaping (qos): reduce HTB prio if max*prio_limit MB exceeded */\r
+   keyword->data_prio=4;              /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */\r
    keyword->fixed_limit=0;             /* fixed data limit for setting lower HTB ceil */\r
    keyword->fixed_prio=0;              /* fixed data limit for setting lower HTB prio */\r
    keyword->reserve_min=8;            /* bonus for nominal HTB rate bandwidth (in kbps) */\r
@@ -332,7 +341,7 @@ void get_config(char *config_filename)
     ioption("asymetry-ratio",keyword->asymetry_ratio);\r
     ioption("asymetry-treshold",keyword->asymetry_fixed);\r
     ioption("magic-relative-limit",keyword->data_limit);\r
-    ioption("magic-relative-prio",keyword->prio_limit);\r
+    ioption("magic-relative-prio",keyword->data_prio);\r
     loption("magic-fixed-limit",keyword->fixed_limit);\r
     loption("magic-fixed-prio",keyword->fixed_prio);\r
     ioption("htb-default-prio",keyword->default_prio);\r
@@ -347,10 +356,8 @@ void get_config(char *config_filename)
     _=tmptr;\r
     \r
     if(keyword->data_limit || keyword->fixed_limit || \r
-       keyword->prio_limit || keyword->fixed_prio)\r
-        use_credit=1;\r
-        \r
-\r
+       keyword->data_prio || keyword->fixed_prio)\r
+        use_credit=1;        \r
    }\r
   }\r
 \r
@@ -374,6 +381,7 @@ void get_config(char *config_filename)
   option("credit-filename",credit);\r
   ioption("credit-enable",enable_credit);\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("qos-free-zone",qos_free_zone);\r
   ioption("qos-free-delay",qos_free_delay);\r
@@ -390,8 +398,7 @@ void get_config(char *config_filename)
   ioption("htb-r2q",htb_r2q);\r
   ioption("magic-include-upload",include_upload);\r
   ioption("magic-priorities",magic_priorities);\r
-  ioption("magic-treshold",magic_treshold);\r
-  \r
+  ioption("magic-treshold",magic_treshold);  \r
   option("filter-type", cnf);\r
   \r
 /* not yet implemented:\r
@@ -486,7 +493,7 @@ void get_traffic_statistics(void)
            else\r
             sscanf(ptr,"%Lu",&traffic); traffic+=(1<<19); traffic>>=20;\r
            break;\r
-   case 3: if(strncmp(ptr,"post_",5) && strncmp(ptr,"forw_",5) || commonflag)\r
+   case 3: if((strncmp(ptr,"post_",5) && strncmp(ptr,"forw_",5)) || commonflag)\r
             accept=eq(ptr,mark);\r
             /*if (filter_type==1) accept=eq(ptr,"MARK"); else accept=eq(ptr,"CLASSIFY");*/\r
            break;\r
@@ -561,20 +568,24 @@ void run_restore(void)
 {\r
  char *restor, *str;\r
  string(restor,STRLEN);\r
+\r
+ /*-----------------------------------------------------------------*/\r
+ printf("Running %s <%s ...\n",iptablesrestore,iptablesfile);\r
+ /*-----------------------------------------------------------------*/\r
  \r
  save_line("COMMIT");\r
  fclose(iptables_file);\r
- if(dry_run) {\r
+ if(dry_run) \r
+ {\r
     parse(iptablesfile)\r
     {\r
         str=_;\r
         printf("%s\n", str);\r
     }done;\r
- }else{\r
-    //sprintf(restor,"cat %s",iptablesfile); else \r
-    sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
-    system(restor);\r
- };\r
+ }\r
+\r
+ sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
+ safe_run(restor);\r
  \r
  free(restor);\r
 }\r
@@ -617,6 +628,119 @@ char *parse_datafile_line(char *str)
   return NULL;\r
 }\r
 \r
+struct IpLog\r
+{\r
+ char *name;\r
+ long traffic;\r
+ list(IpLog);\r
+} *iplog,*iplogs;\r
+\r
+void parse_ip_log(int argc, char **argv) \r
+{\r
+ char *month,*year,*str,*name,*ptr,*ptr2;\r
+ long traffic,traffic_month,total=0;\r
+ int col,col2,y_ok,m_ok,accept_month,i=1,any_month=0;\r
+ char mstr[4],ystr[5];\r
+ FILE *f;\r
\r
+ string(str,STRLEN);\r
+\r
+ if(argv[1][1]=='l') /* -l */\r
+ {\r
+   if(argc<4)\r
+   {\r
+    puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)");\r
+    exit(-1);\r
+   }\r
+   else\r
+   {\r
+    month=argv[2];\r
+    if(eq(month,"Year")) any_month=1;\r
+    year=argv[3];\r
+   }\r
+ }\r
+ else\r
+ { \r
+   time_t t = time(NULL) - 3600*24 ; /* yesterday's timestamp*/\r
+   struct tm *timep = localtime(&t);                                           \r
\r
+   if(argv[1][1]=='m') /* -m yestarday - month */\r
+   {\r
+    strftime(mstr, 4, "%b", timep);\r
+    month=mstr;\r
+    strftime(ystr, 5, "%Y", timep);\r
+    year=ystr; \r
+   }\r
+   else /* -y yesterday - year */\r
+   {\r
+    month="Year";\r
+    any_month=1;\r
+    strftime(ystr, 5, "%Y", timep);\r
+    year=ystr;\r
+   }\r
+ }\r
+ printf("Analysing traffic for %s %s ...\n",month,year);\r
+\r
+ sprintf(str,"%s %s/*.log",ls,log_dir);\r
+ shell(str);\r
+ input(str,STRLEN)\r
+ {\r
+  ptr=strrchr(str,'\n');\r
+  if(ptr) *ptr='\0';\r
+  printf("Parsing %s ...",str);\r
+  accept_month=0;\r
+  traffic_month=0;\r
+  parse(str)\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
+    case 7: 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
+   if(y_ok && m_ok) \r
+   {\r
+    traffic_month+=traffic;\r
+    accept_month=1;\r
+   }\r
+  }\r
+  done;\r
+  if(accept_month)\r
+  {\r
+   create(iplog,IpLog);\r
+   iplog->name=name;\r
+   iplog->traffic=traffic_month;\r
+   insert(iplog,iplogs,desc_order_by,traffic);\r
+   printf(" %ld MB\n",iplog->traffic);\r
+  }\r
+  else\r
+   puts(" no records.");\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)\r
+ {\r
+  fprintf(f,"<table border><tr><th colspan=\"4\">Data transfers - %s %s</th></tr>\n ",month,year);\r
+  every(iplog,iplogs)\r
+   if(iplog->traffic)\r
+   {\r
+    fprintf(f,"<tr><td align=\"right\">%d</td><th>%s</td><td align=\"right\">%ld MB</td><th align=\"right\">%ld GB</th></tr>\n",i++,iplog->name,iplog->traffic,iplog->traffic>>10);\r
+    total+=iplog->traffic>>10;\r
+   }\r
+  fprintf(f,"<tr><th colspan=\"3\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th></tr>\n",total);\r
+  fputs("</table>\n",f);\r
+  fclose(f);\r
+  puts(" done.");\r
+ }\r
+}\r
+\r
+\r
 /*-----------------------------------------------------------------*/\r
 /* Are you looking for int main (int argc, char **argv) ? :-))     */\r
 /*-----------------------------------------------------------------*/\r
@@ -631,15 +755,17 @@ program
  int parent=1;\r
  int just_flush=0;\r
  int nodelay=0;\r
- int just_preview=0;                   /* preview - generate just stats */\r
+ int just_preview=0;                /* preview - generate just stats */\r
+ int just_logs=0;                   /* just parse logs */\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-2007 Michael Polak (xChaos)\n\\r
+Version %s - Copyright (C)2005-2008 Michael Polak (xChaos)\n\\r
 iptables-restore & burst tunning & classify modification 0.7d by Ludva\n\\r
-Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);\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
@@ -652,6 +778,9 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
   argument("-9") { just_flush=9; }\r
   argument("-p") { just_preview=1; }\r
   argument("-n") { nodelay=1; }\r
+  argument("-l") { just_logs=1; }\r
+  argument("-m") { just_logs=1; }\r
+  argument("-y") { just_logs=1; }\r
   argument("-?") { help(); exit(0); }\r
   argument("--help") { help(); exit(0); }\r
   argument("-v") { exit(0); } \r
@@ -667,6 +796,12 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
  printf("Parsing configuration file %s ...\n", config);\r
  /*-----------------------------------------------------------------*/\r
  get_config(config);\r
\r
+ if(just_logs)\r
+ {\r
+    parse_ip_log(argc,argv);\r
+    exit(0);\r
+ }\r
 \r
  if(althosts) hosts=althosts;\r
 \r
@@ -725,8 +860,8 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
     ip->min=atoi(substring);\r
     if(ip->min<=0)\r
     {\r
-     puts("Illegal value of minimum bandwidth: 0 kbps.");\r
-     reject_config_and_exit(hosts);\r
+     printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kbps\n",str,free_min);\r
+     ip->min=free_min;\r
     }\r
     if(ip->max<=ip->min)\r
     {\r
@@ -746,7 +881,7 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
      if(ip->max<ip->min)\r
       ip->max=ip->min;\r
     }\r
-    ip->mark=MAX_GUARANTED_KBPS+1+class_count++;\r
+    ip->mark=FIRSTIPCLASS+1+class_count++;\r
 \r
     find(group,groups,group->min==ip->min) \r
     { \r
@@ -877,7 +1012,7 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
   if(ip_count>idxtable_treshold1 && !just_flush)\r
   {\r
    int idxcount=0, bitmask=32-idxtable_bitmask1; /* default net mask: 255.255.255.240 */\r
-   char *subnet, *ptr, *buf;\r
+   char *subnet, *buf;\r
    /*-----------------------------------------------------------------*/\r
    printf("Detected %d addresses - indexing iptables rules to improve performance...\n",ip_count);\r
    /*-----------------------------------------------------------------*/\r
@@ -1062,10 +1197,9 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
     \r
     search(ip, ips, ip->min==group->min && ip->max>ip->min)\r
     {\r
-     if(ip->keyword->data_limit>0 &&\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
-        && !ip->fixedprio)\r
+         (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)) )\r
      {\r
       if(group_rate<ip->max) ip->max=group_rate;\r
       group_rate+=magic_treshold;\r
@@ -1074,9 +1208,9 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
      }\r
      else\r
      {\r
-      if(ip->traffic>ip->credit+\r
-          (ip->min*ip->keyword->prio_limit+(ip->keyword->fixed_prio<<20)) && \r
-         !ip->fixedprio)\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
       {\r
        ip->prio=priority_sequence--;\r
        if(ip->prio<2) ip->prio=2;\r
@@ -1085,6 +1219,7 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
       if(credit_file)\r
       {\r
        unsigned long long lcredit=0;\r
+       \r
        if((ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))>ip->traffic) \r
         lcredit=(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))-ip->traffic;\r
        fprintf(credit_file,"%s %Lu\n",ip->addr,lcredit);\r
@@ -1150,7 +1285,7 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
 #ifdef DEBUG\r
    printf("Total groups: %d Total bandwidth requested: %d k\nAGGREGATION: 1/%d\n",count,i,i/line);\r
 #endif\r
-   fprintf(f,"<tr><th colspan=\"2\" align=\"left\">Line %d k</td>",line);\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
    every(keyword,keywords)\r
@@ -1236,11 +1371,12 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
    \r
    if(!just_preview)\r
    {\r
-    sprintf(str,"%s%s.log",log_dir,ip->name);\r
+    sprintf(str,"%s/%s.log",log_dir,ip->name);\r
     iplog=fopen(str,"a");\r
     if(iplog)\r
     {\r
-     fprintf(iplog,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%s",time(NULL),ip->name,ip->traffic, ip->direct, ip->proxy, ip->upload,d);\r
+     fprintf(iplog,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\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,d); /* d = date*/\r
      fclose(iplog);\r
     }\r
    }\r
@@ -1256,22 +1392,63 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
 \r
   if(active_classes>10)\r
   {\r
-   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"4\">Enterprise Research and Planning (ERP)</th></tr>\n",f);\r
-   fputs("<tr><td colspan=\"2\">Active Classes</td><td colspan=\"2\">Data transfers</td></tr>\n",f);\r
-   find (sum,sums,sum->l>=total/4)\r
-    fprintf(f,"<tr><td>Top %d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%d %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
-   find (sum,sums,sum->i==10)\r
-    fprintf(f,"<tr><td>Top 10</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%d %%</td></tr>\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
-   find (sum,sums,sum->l>=total/2)\r
-    fprintf(f,"<tr><td>Top %d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%d %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
-   find (sum,sums,sum->i>=(active_classes+3)/4)\r
-    fprintf(f,"<tr><td>Top %d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%d %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
-   find (sum,sums,sum->i>=(active_classes+1)/2)\r
-    fprintf(f,"<tr><td>Top %d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%d %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
-   fprintf(f,"<tr><th align=\"left\">All %d</th><th align=\"right\">100 %%</th><th align=\"right\">%Lu M</th><th align=\"right\">100 %%</th></tr>\n",active_classes,total);\r
+   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Research and Planning (ERP)</th></tr>\n",f);\r
+   fputs("<tr><td>Analytic category</td>\n",f);\r
+   fputs("<td colspan=\"2\" align=\"center\">Active Classes</td><td colspan=\"2\" align=\"center\">Data transfers</td></tr>\n",f);\r
+\r
+   find(sum,sums,sum->l>=total/4)\r
+   {\r
+    fprintf(f,"<tr><td>Top 25%% of traffic</td>\n");\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+   \r
+   find(sum,sums,sum->i==10)\r
+   {\r
+    fprintf(f,"<tr><td>Top 10 downloaders</td>\n");\r
+    fprintf(f,"<th align=\"right\">10</th><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+\r
+   find(sum,sums,sum->l>=total/2)\r
+   {\r
+    fprintf(f,"<tr><td>Top 50%% of traffic</td>\n");\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+\r
+   find(sum,sums,sum->l>=4*total/5)\r
+   {\r
+    fprintf(f,"<tr><td>Top 80%% of traffic</td>\n");\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><th align=\"right\">%Ld %%</th></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+\r
+   find (sum,sums,sum->i>=(active_classes+1)/5)\r
+   {\r
+    fprintf(f,"<tr><td>Top 20%% downloaders</td>\n");\r
+    fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+\r
+   find(sum,sums,sum->i>=(active_classes+1)/4)\r
+   {\r
+    fprintf(f,"<tr><td>Top 25%% downloaders</td>\n");\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+\r
+   find(sum,sums,sum->i>=(active_classes+1)/2)\r
+   {\r
+    fprintf(f,"<tr><td>Top 50%% downloaders</td>\n");\r
+    fprintf(f,"<td align=\"right\">%d</td><th align=\"right\">%d %%</th><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+\r
+   find(sum,sums,sum->i>=4*(active_classes+1)/5)\r
+   {\r
+    fprintf(f,"<tr><td>Top 80%% downloaders</td>\n");\r
+    fprintf(f,"<td align=\"right\">%d</td><td align=\"right\">%d %%</td><td align=\"right\">%Lu M</td><td align=\"right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total);\r
+   }\r
+\r
+   fprintf(f,"<tr><td>All users, all traffic</td>\n");\r
+   fprintf(f,"<th align=\"right\">%d</th><th align=\"right\">100 %%</th><th align=\"right\">%Lu M</th><th align=\"right\">100 %%</th></tr>\n",active_classes,total);\r
    fputs("</table>\n",f);\r
   }\r
-  fprintf(f,"<small>Statistics generated by Prometheus QoS version %s<br>GPL+Copyright(C)2005 Michael Polak, <a href=\"http://www.arachne.cz/\">Arachne Labs</a></small>\n",version);\r
+  fprintf(f,"<small>Statistics generated by Prometheus QoS version %s<br>GPL+Copyright(C)2005-2008 Michael Polak, <a href=\"http://www.arachne.cz/\">Arachne Labs</a></small>\n",version);\r
   fclose(f);\r
  }\r
 \r
@@ -1398,24 +1575,28 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
 \r
  if(qos_proxy)\r
  {\r
-  sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j MARK --set-mark 3",chain_postrouting,proxy_ip,proxy_port,lan);\r
+  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);\r
   save_line(str);\r
   sprintf(str,"-A %s -s %s -p tcp --sport %d -o %s -j ACCEPT",chain_postrouting,proxy_ip,proxy_port,lan);\r
   save_line(str);\r
  }\r
- sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_postrouting,lan);\r
+ sprintf(str,"-A %s -o %s -j %s%d",chain_postrouting,lan,mark_iptables,3);\r
  save_line(str);\r
  sprintf(str,"-A %s -o %s -j ACCEPT",chain_postrouting,lan);\r
  save_line(str);\r
 \r
  /* --------------------------------------------------------  mark upload */\r
- sprintf(str,"-A %s -o %s -j MARK --set-mark 3",chain_forward,wan);\r
+ sprintf(str,"-A %s -o %s -j %s%d",chain_forward,wan,mark_iptables,3);\r
  save_line(str);\r
  sprintf(str,"-A %s -o %s -j ACCEPT",chain_forward,wan);\r
  save_line(str);\r
 \r
  printf("Total IP count: %d\n", i);\r
 \r
+ /*-----------------------------------------------------------------*/\r
+ puts("Generating free bandwith classes ...");\r
+ /*-----------------------------------------------------------------*/\r
+\r
  /* ---------------------------------------- tc - free bandwith shared class */\r
  sprintf(str,"%s class add dev %s parent 1:%d classid 1:3 htb rate %dkbit ceil %dkbit burst %dk prio 2",tc,lan,parent,free_min,free_max,burst);\r
  safe_run(str);\r
@@ -1438,7 +1619,7 @@ Credits: CZFree.Net, Martin Devera, Netdave, Aquarius\n\n",version);
 \r
  sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle 3 fw flowid 1:3",tc,wan);\r
  safe_run(str);\r
\r
+\r
  run_restore();\r
  \r
  if (log_file) fclose(log_file);\r
This page took 0.264264 seconds and 4 git commands to generate.