ještě ERP
[svn/Prometheus-QoS/.git] / prometheus.c
index 0c0d93b..5420588 100644 (file)
@@ -7,7 +7,7 @@
 /*  Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
 \r
-/* Modified by: xChaos, 20110221\r
+/* Modified by: xChaos, 20110428\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -85,6 +85,7 @@ void help(void)
 -s            start shaping! (keep data transfer statistics - but apply shaping)\n\\r
 */\r
 }\r
+\r
 /* === Configuraration file values defaults - stored in global variables ==== */\r
 \r
 int        filter_type = 1; /*1 mark, 2 classify*/\r
@@ -104,6 +105,7 @@ char       *wan_medium = "100Mbit"; /* 10Mbit/100Mbit ethernet */
 char         *qos_leaf = "sfq perturb 5"; /* leaf discipline */\r
 char    *qos_free_zone = NULL; /* QoS free zone */\r
 int          qos_proxy = 1; /* include proxy port to QoS */\r
+int        found_lmsid = 0; /* show links to users in LMS information system */\r
 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
@@ -134,7 +136,7 @@ const int idxtable_treshold2 = 12;      /* this is no longer configurable */
 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
+/* ==== This is C<<1 stuff - learn C<<1 first! https://dev.arachne.cz/svn/cll1h ==== */\r
 \r
 struct IP\r
 {\r
@@ -148,6 +150,7 @@ struct IP
  int prio;\r
  int fixedprio;\r
  int group;\r
+ int lmsid;\r
  unsigned long long direct;\r
  unsigned long long proxy;\r
  unsigned long long upload;\r
@@ -209,7 +212,8 @@ void TheIP(void)
  ip->addr        = "";\r
  ip->sharing     = NULL;\r
  ip->prio        = highest_priority+1;\r
- ip->fixedprio   = 0;\r
+ ip->lmsid       = -1;\r
+ ip->fixedprio   = \\r
  ip->mark        = \\r
  ip->min         = \\r
  ip->max         = \\r
@@ -237,10 +241,14 @@ char *very_ugly_ipv4_code(char *inip,int bitmask,int format_as_chainname)
  /* debug printf("(%s,%d) -> ",ip,bitmask); */\r
 \r
  if(ip && *ip && bitmask>=0 && bitmask<=32)\r
+ {\r
   string(outip,strlen(ip)+10); /*fuck unicode? assertion: 10>strlen("_%d_%d") */\r
+ }\r
  else \r
+ {\r
   /* should never exit here */\r
   return "undefined";\r
+ }\r
  outptr=outip;\r
  while(ip && *ip)\r
  {\r
@@ -249,9 +257,13 @@ char *very_ugly_ipv4_code(char *inip,int bitmask,int format_as_chainname)
    if(dot<(bitmask/8-1)) \r
    {\r
     if(format_as_chainname)\r
+    {\r
      *outptr='_';\r
+    }\r
     else\r
+    {\r
      *outptr='.';\r
+    }\r
     outptr++;\r
     dot++;\r
    }\r
@@ -292,10 +304,14 @@ char *very_ugly_ipv4_code(char *inip,int bitmask,int format_as_chainname)
 }\r
 \r
 char *hash_id(char *ip,int bitmask)\r
-{ return very_ugly_ipv4_code(ip,bitmask,1); }\r
+{ \r
+ return very_ugly_ipv4_code(ip,bitmask,1);\r
+}\r
 \r
 char *subnet_id(char *ip,int bitmask)\r
-{ return very_ugly_ipv4_code(ip,bitmask,0); }\r
+{\r
+ return very_ugly_ipv4_code(ip,bitmask,0);\r
+}\r
 \r
 /* ================= Let's parse configuration file here =================== */\r
 \r
@@ -327,9 +343,6 @@ void get_config(char *config_filename)
    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
    keyword->reserve_max=0;            /* malus for nominal HTB ceil (in kbps) */\r
-/* obsolete:\r
-   keyword->divide_max=0;             relative malus: new_ceil=rate+(old_ceil-rate)/divide_max\r
-   keyword->htb_ceil_bonus_divide=0;   relative bonus: new_ceil=old_ceil+old_ceil/htb_ceil_bonus_divide */\r
    keyword->default_prio=highest_priority+1;\r
    keyword->html_color="000000";\r
    keyword->ip_count=0;\r
@@ -347,7 +360,6 @@ void get_config(char *config_filename)
     {\r
      int l=strlen(keyword->key);\r
 \r
-\r
      if(!strncmp(keyword->key,_,l) && strlen(_)>l+2)\r
      {\r
       char *tmptr=_; /*  <---- l+1 ----> */\r
@@ -361,17 +373,15 @@ void get_config(char *config_filename)
       ioption("htb-default-prio",keyword->default_prio);\r
       ioption("htb-rate-bonus",keyword->reserve_min);\r
       ioption("htb-ceil-malus",keyword->reserve_max);\r
-  /* obsolete:\r
-      ioption("htb-ceil-divide",keyword->divide_max);\r
-      ioption("htb-ceil-bonus-divide",keyword->htb_ceil_bonus_divide);\r
-  */\r
       option("leaf-discipline",keyword->leaf_discipline);\r
       option("html-color",keyword->html_color);\r
       _=tmptr;\r
       \r
       if(keyword->data_limit || keyword->fixed_limit || \r
          keyword->data_prio || keyword->fixed_prio)\r
-          use_credit=1;        \r
+      {\r
+       use_credit=1;        \r
+      }\r
      }\r
     }\r
   }\r
@@ -437,14 +447,17 @@ void get_config(char *config_filename)
     }\r
  }\r
 \r
- if (strcmpi(cnf, "mark")){\r
-    filter_type = 2;\r
-    mark = "CLASSIFY";\r
-    mark_iptables = "CLASSIFY --set-class 1:";\r
- }else{\r
-    filter_type = 1;\r
-    mark = "MARK";\r
-    mark_iptables = "MARK --set-mark ";\r
+ if (strcmpi(cnf, "mark"))\r
+ {\r
+  filter_type = 2;\r
+  mark = "CLASSIFY";\r
+  mark_iptables = "CLASSIFY --set-class 1:";\r
+ }\r
+ else\r
+ {\r
+  filter_type = 1;\r
+  mark = "MARK";\r
+  mark_iptables = "MARK --set-mark ";\r
  }\r
 \r
  /* are supplied values meaningful ?*/\r
@@ -524,8 +537,14 @@ void get_traffic_statistics(void)
   \r
     if(accept && traffic>0 && ipaddr)\r
     {\r
-     if(proxyflag)printf("(proxy) ");\r
-     else if(!downloadflag) printf("(upload) ");\r
+     if(proxyflag)\r
+     {\r
+      printf("(proxy) ");\r
+     }\r
+     else if(!downloadflag)\r
+     {\r
+      printf("(upload) ");\r
+     }\r
      printf("IP %s: %Lu M (%ld pkts)\n", ipaddr, traffic, pkts);\r
 \r
      if_exists(ip,ips,eq(ip->addr,ipaddr)); \r
@@ -544,9 +563,13 @@ void get_traffic_statistics(void)
      if(downloadflag)\r
      {\r
       if(proxyflag)\r
+      {\r
        ip->proxy=traffic;\r
+      }\r
       else\r
+      {\r
        ip->traffic+=traffic;\r
+      }\r
       ip->direct=ip->traffic-ip->upload-ip->proxy;\r
       ip->pktsdown=pkts;\r
      }\r
@@ -555,10 +578,16 @@ void get_traffic_statistics(void)
       ip->upload=traffic;\r
       ip->pktsup=pkts;\r
       if(include_upload)\r
+      {\r
        ip->traffic+=traffic;\r
+      }\r
       else \r
+      {\r
        if(traffic>ip->traffic)\r
+       {\r
         ip->traffic=traffic;     \r
+       }\r
+      }\r
      }\r
     }  \r
   }\r
@@ -570,8 +599,18 @@ void get_traffic_statistics(void)
 \r
 void safe_run(char *cmd)\r
 {\r
- if(dry_run) printf("\n=>%s\n",cmd); else system(cmd);\r
- if(log_file) fprintf(log_file,"%s\n",cmd);\r
+ if(dry_run)\r
+ {\r
+  printf("\n=>%s\n",cmd);\r
+ }\r
+ else\r
+ {\r
+  system(cmd);\r
+ }\r
+ if(log_file)\r
+ {\r
+  fprintf(log_file,"%s\n",cmd);\r
+ }\r
 }\r
 \r
 void save_line(char *line)\r
@@ -581,7 +620,7 @@ void save_line(char *line)
 \r
 void run_restore(void)\r
 {\r
- char *restor, *str;\r
+ char *restor;\r
  string(restor,STRLEN);\r
 \r
  /*-----------------------------------------------------------------*/\r
@@ -592,11 +631,11 @@ void run_restore(void)
  fclose(iptables_file);\r
  if(dry_run) \r
  {\r
-    parse(iptablesfile)\r
-    {\r
-        str=_;\r
-        printf("%s\n", str);\r
-    }done;\r
+  parse(iptablesfile)\r
+  {\r
+   printf("%s\n",_);\r
+  }\r
+  done;\r
  }\r
 \r
  sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
@@ -609,19 +648,37 @@ void run_restore(void)
 \r
 void parse_ip(char *str)\r
 {\r
- char *ptr=str,*ipaddr=NULL,*ipname=NULL;;\r
+ char *ptr,*ipaddr=NULL,*ipname=NULL,*lmsid=NULL;\r
+\r
+ ptr=strchr(str,'{');\r
+ if(ptr)\r
+ {\r
+  lmsid=++ptr;\r
+  while(*ptr && *ptr!='}')\r
+  {\r
+   ptr++;\r
+  }\r
+  *ptr=0;\r
+ }\r
  \r
+ ptr=str;\r
  while(*ptr && *ptr!=' ' && *ptr!=9)\r
+ {\r
   ptr++;\r
+ }\r
  \r
  *ptr=0;\r
  ipaddr=str;\r
  ptr++;\r
  while(*ptr && (*ptr==' ' || *ptr==9))\r
+ {\r
   ptr++;\r
+ }\r
  ipname=ptr; \r
  while(*ptr && *ptr!=' ' && *ptr!=9)\r
+ {\r
   ptr++;\r
+ }\r
  *ptr=0;\r
 \r
  if_exists(ip,ips,eq(ip->addr,ipaddr));\r
@@ -631,6 +688,11 @@ void parse_ip(char *str)
  }\r
  ip->addr=ipaddr;\r
  ip->name=ipname;\r
+ if(lmsid)\r
+ {\r
+  ip->lmsid=atoi(lmsid);\r
+  found_lmsid=1;\r
+ }\r
 }\r
 \r
 char *parse_datafile_line(char *str)\r
@@ -644,7 +706,9 @@ char *parse_datafile_line(char *str)
   return ptr;\r
  } \r
  else \r
+ {\r
   return NULL;\r
+ }\r
 }\r
 \r
 struct IpLog\r
@@ -653,6 +717,7 @@ struct IpLog
  long traffic;\r
  long guaranted;\r
  int i;\r
+ int lmsid;\r
  long l;\r
  list(IpLog);\r
 } *iplog,*iplogs;\r
@@ -661,7 +726,7 @@ void parse_ip_log(int argc, char **argv)
 {\r
  char *month, *year, *str, *name="(undefined)", *ptr, *ptr2, *filename;\r
  long traffic=0l, traffic_month, total=0, guaranted;\r
- int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0;\r
+ int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0, lmsid;\r
  char mstr[4], ystr[5];\r
  FILE *f; \r
  string(str,STRLEN);\r
@@ -716,7 +781,8 @@ void parse_ip_log(int argc, char **argv)
     printf("Parsing %s ...",filename);\r
     accept_month=0;\r
     traffic_month=0;\r
-    guaranted = 0;\r
+    guaranted=0;\r
+    lmsid=-1;\r
     parse(filename)\r
     {\r
      y_ok=m_ok=0;  \r
@@ -724,11 +790,12 @@ void parse_ip_log(int argc, char **argv)
      {\r
       case 2: name = ptr;break;\r
       case 3: traffic = atol(ptr);break;\r
-      /* column number   - was 7, now 10...*/\r
+      /* column number   - was 7, now 11...*/\r
       case 7:\r
       case 8:\r
       case 9:\r
-      case 10: if (isalpha(*ptr)) /* character, not numeric string = date, just one*/\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
@@ -739,6 +806,7 @@ void parse_ip_log(int argc, char **argv)
                else\r
                {\r
                  if(col == 7) guaranted = atol(ptr);\r
+                 if(col == 10) lmsid = atoi(ptr);\r
                }\r
      }\r
      \r
@@ -756,6 +824,7 @@ void parse_ip_log(int argc, char **argv)
      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
@@ -770,25 +839,35 @@ void parse_ip_log(int argc, char **argv)
  f=fopen(str,"w");\r
  if(f)\r
  {\r
-  fprintf(f,"<table border><tr><th colspan=\"2\">%s %s</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 ",month,year);\r
 \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\">%ld M</td><th align=\"right\">%ld G</th><td align=\"right\">%ld kbps</th></tr>\n",\r
-              i++, iplog->name, iplog->traffic, iplog->traffic>>10, iplog->guaranted);\r
+    fprintf(f,"<tr><td align=\"right\">%d</td><th align=\"left\">%s</td><td align=\"right\">", 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&amp;id=%d\">%04d</a>\n", 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
     total+=iplog->traffic>>10;\r
     iplog->i=i;\r
     iplog->l=total;\r
    }\r
   }\r
-  fprintf(f,"<tr><th colspan=\"3\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th><th align=\"right\">%Ld kbps</th></tr>\n", total, line);\r
+  fprintf(f,"<tr><th colspan=\"4\" align=\"left\">Total:</th><th align=\"right\">%ld GB</th><th align=\"right\">%Ld kbps</th></tr>\n", total, line);\r
   fputs("</table>\n", f);\r
 \r
   if(i>10)\r
   {\r
-   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Research and Planning (ERP)</th></tr>\n",f);\r
+   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Resource 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
@@ -868,13 +947,14 @@ program
  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-2008 Michael Polak (xChaos)\n\\r
+Version %s - Copyright (C)2005-2011 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
@@ -944,7 +1024,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   str=_;\r
 \r
   if(*str<'0' || *str>'9')\r
+  {\r
+   /* any line starting with non-number is comment ...*/\r
    continue;\r
+  }\r
   \r
   //Does this IP share QoS class with some other ?\r
   substring=strstr(str,"sharing-");\r
@@ -956,7 +1039,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    ip->sharing=substring;\r
    ip->keyword=defaultkeyword; /* settings for default keyword */\r
    while(*substring && *substring!='\n')\r
+   {\r
     substring++;\r
+   }\r
    *substring=0; \r
   }\r
   else\r
@@ -973,7 +1058,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     substring+=strlen(keyword->key)+1;\r
     ptr=substring;\r
     while(*ptr && *ptr!='-')\r
+    {\r
      ptr++;\r
+    }\r
     if(*ptr=='-')\r
     {\r
      *ptr=0;\r
@@ -993,15 +1080,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     else \r
     {\r
      ip->max-=ip->keyword->reserve_max;\r
-\r
-/*\r
-     if(ip->keyword->divide_max>1)\r
-      ip->max=ip->min+(ip->max-ip->min)/ip->keyword->divide_max;\r
-     if(ip->keyword->htb_ceil_bonus_divide>0)\r
-      ip->max+=ip->max/ip->keyword->htb_ceil_bonus_divide;\r
-*/\r
      if(ip->max<ip->min)\r
+     {\r
       ip->max=ip->min;\r
+     }\r
     }\r
     ip->mark=FIRSTIPCLASS+1+class_count++;\r
 \r
@@ -1052,10 +1134,13 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    sharedip->traffic+=ip->traffic;\r
    ip->traffic=0;\r
    ip->mark=sharedip->mark; \r
+   ip->lmsid=sharedip->lmsid;\r
    break;\r
   }\r
   if(!sharedip)\r
+  {\r
    printf("Unresolved shared connection: %s %s sharing-%s\n",ip->addr,ip->name,ip->sharing);\r
+  }\r
  }\r
 \r
  if(enable_credit && just_flush<9)\r
@@ -1084,13 +1169,15 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   /*-----------------------------------------------------------------*/\r
   \r
   iptables_file=fopen(iptablesfile,"w");\r
-  if (iptables_file == NULL) {\r
+  if (iptables_file == NULL)\r
+  {\r
     puts("Cannot open iptablesfile!");\r
     exit(-1);\r
   }\r
   \r
   log_file=fopen(cmdlog,"w");\r
-  if (log_file == NULL) {\r
+  if (log_file == NULL) \r
+  {\r
     puts("Cannot open logfile!");\r
     exit(-1);\r
   }\r
@@ -1127,7 +1214,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     chain="post_noproxy";    \r
    }\r
    else\r
+   {\r
     chain="POSTROUTING";\r
+   }\r
     \r
    sprintf(str,"-A %s -s %s -o %s -j ACCEPT", chain, qos_free_zone, lan);\r
    save_line(str);\r
@@ -1197,7 +1286,6 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    sort(idx,idxs,order_by,bitmask);\r
 \r
    i=0;\r
-\r
    for_each(idx,idxs)\r
    {\r
     subnet=subnet_id(idx->addr,idx->bitmask);\r
@@ -1215,7 +1303,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      sprintf(buf,"post_%s",idx->parent->id);\r
     }\r
     else\r
+    {\r
      buf="POSTROUTING";\r
+    }\r
 \r
     sprintf(str,"-A %s -d %s/%d -o %s -j post_%s", buf, subnet, idx->bitmask, lan, idx->id);\r
     save_line(str);\r
@@ -1229,7 +1319,9 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      sprintf(buf,"forw_%s",idx->parent->id);\r
     }\r
     else\r
+    {\r
      buf="FORWARD";\r
+    }\r
 \r
     sprintf(str,"-A %s -s %s/%d -o %s -j forw_%s", buf, subnet, idx->bitmask, wan, idx->id);\r
     save_line(str);\r
@@ -1290,8 +1382,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  /*-----------------------------------------------------------------*/\r
  puts("Locating heavy downloaders and generating root classes ...");\r
  /*-----------------------------------------------------------------*/\r
- sort(ip,ips,desc_order_by,traffic);\r
\r
+ sort(ip,ips,desc_order_by,traffic); \r
 \r
  /*-----------------------------------------------------------------*/\r
  /* sub-scope - local variables */  \r
@@ -1301,7 +1392,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   int group_count=0;\r
   FILE *credit_file=NULL;\r
   \r
-  if(!just_preview && !dry_run && enable_credit) credit_file=fopen(credit,"w");\r
+  if(!just_preview && !dry_run && enable_credit)\r
+  {\r
+   credit_file=fopen(credit,"w");\r
+  }\r
     \r
   for_each(group,groups)\r
   {\r
@@ -1318,10 +1412,16 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     safe_run(str);\r
    }\r
    \r
-   if(group_count++<max_nesting) parent=group->id;\r
+   if(group_count++<max_nesting)\r
+   {\r
+    parent=group->id;\r
+   }\r
    \r
    rate-=digital_divide*group->min;\r
-   if(rate<group->min)rate=group->min;\r
+   if(rate<group->min)\r
+   {\r
+    rate=group->min;\r
+   }\r
     \r
    /*shaping of aggresive downloaders, with credit file support */\r
    if(use_credit)\r
@@ -1334,10 +1434,16 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
          ip->traffic>ip->credit+\r
          (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)) )\r
      {\r
-      if(group_rate<ip->max) ip->max=group_rate;\r
+      if(group_rate<ip->max)\r
+      {\r
+       ip->max=group_rate;\r
+      }\r
       group_rate+=magic_treshold;\r
       ip->prio=lowest_priority;\r
-      if(ip->prio<highest_priority+2) ip->prio=highest_priority+2;\r
+      if(ip->prio<highest_priority+2)\r
+      {\r
+       ip->prio=highest_priority+2;\r
+      }\r
      }\r
      else\r
      {\r
@@ -1346,15 +1452,20 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
            (ip->min*ip->keyword->data_prio+(ip->keyword->fixed_prio<<20)) )\r
       {\r
        ip->prio=priority_sequence--;\r
-       if(ip->prio<highest_priority+1) ip->prio=highest_priority+1;\r
+       if(ip->prio<highest_priority+1)\r
+       {\r
+        ip->prio=highest_priority+1;\r
+       }\r
       }\r
      \r
       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
+       if((ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))>ip->traffic)\r
+       {\r
         lcredit=(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20))-ip->traffic;\r
+       }\r
        fprintf(credit_file,"%s %Lu\n",ip->addr,lcredit);\r
       }\r
      }\r
@@ -1362,7 +1473,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
         \r
    }\r
   }\r
-  if(credit_file)fclose(credit_file);\r
+  if(credit_file)\r
+  {\r
+   fclose(credit_file);\r
+  }\r
  }\r
 \r
  if(just_preview)\r
@@ -1389,7 +1503,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
  if(f)\r
  {\r
-  int total=0;\r
+\r
   int count=1;\r
   i=0;\r
 \r
@@ -1438,31 +1552,42 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  i=1;\r
  if(f)\r
  {\r
-  unsigned long long total=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0;\r
+  unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0;\r
   int active_classes=0;\r
   int colspan;\r
   FILE *iplog;\r
   struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums=NULL;\r
 \r
+  colspan=11;\r
   if(qos_proxy)\r
-   colspan=12;\r
-  else \r
-   colspan=11;\r
+  {\r
+   colspan++;\r
+  }\r
+  if(found_lmsid)\r
+  {\r
+   colspan++;\r
+  }\r
   \r
   fprintf(f,"<p><table border>\n<tr><th colspan=\"%d\">%s",colspan,title);\r
   fprintf(f," (%s)</th></tr>\n", d);\r
-  fputs("<tr><td align=\"right\">#</td><td>hostname</td>\\r
-  <td align=\"right\">credit</td>\\r
-  <td align=\"right\">limit</td>\\r
-  <td align=\"right\">total</td>\\r
-  <td align=\"right\">direct</td>\n",f);\r
+  fputs("<tr><td align=\"right\">#</td><td>hostname</td>",f);\r
+  if(found_lmsid)\r
+  {\r
+   fputs("<td align=\"right\">lms</td>\n",f);\r
+  }\r
+  fputs("<td align=\"right\">credit</td>\\r
+<td align=\"right\">limit</td>\\r
+<td align=\"right\">total</td>\\r
+<td align=\"right\">direct</td>\n",f);\r
   if(qos_proxy)\r
+  {\r
    fputs("<td align=\"right\">proxy</td>\n",f);\r
+  }\r
   fputs("<td align=\"right\">upload</td>\\r
-  <td align=\"right\">minimum</td>\\r
-  <td align=\"right\">desired</td>\\r
-  <td align=\"right\">maximum</td>\\r
-  <td>prio</td></tr>\n",f);    \r
+<td align=\"right\">minimum</td>\\r
+<td align=\"right\">desired</td>\\r
+<td align=\"right\">maximum</td>\\r
+<td>prio</td></tr>\n",f);      \r
 \r
   for_each(ip,ips)\r
   {\r
@@ -1481,15 +1606,33 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 #ifdef DEBUG\r
    printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r
 #endif\r
-   fprintf(f,"<tr><td align=\"right\"><a name=\"%s\"></a>%d</td><td><a href=\"%s%s.log\">%s</a></td><td align=\"right\">%Lu M</td>\n",\r
-              ip->name, i, log_url, ip->name, ip->name, ip->credit);\r
-   fprintf(f,"<td align=\"right\"><font color=\"#%s\">%Lu M</font></td>",ip->keyword->html_color,ip->credit+(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)));\r
+   fprintf(f,"<tr><td align=\"right\"><a name=\"%s\"></a>%d</td><td><a href=\"%s%s.log\">%s</a></td>\n", ip->name, i, log_url, ip->name, ip->name);\r
+   if(found_lmsid)\r
+   {\r
+    fputs("<td align=\"right\">",f);\r
+    if(ip->lmsid > 0)\r
+    {\r
+     /*base URL will be configurable soon ... */\r
+     fprintf(f,"<a href=\"https://hermes.spoje.net/?m=customerinfo&amp;id=%d\">%04d</a>\n", ip->lmsid, ip->lmsid);\r
+    }\r
+    else if(ip->lmsid == 0)\r
+    {\r
+     fputs("-------",f);\r
+    }\r
+    fputs("</td>\n",f);    \r
+   }\r
+   fprintf(f,"<td align=\"right\">%Lu M</td>\n", ip->credit);\r
+   fprintf(f,"<td align=\"right\"><font color=\"#%s\">%Lu M</font></td>",\r
+             ip->keyword->html_color, ip->credit+(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)));\r
    fprintf(f,"<td align=\"right\">%s%Lu M%s</td><td align=\"right\">%Lu M</td>\n", f1, ip->traffic, f2, ip->direct);\r
    if(qos_proxy)\r
+   {\r
     fprintf(f,"<td align=\"right\">%Lu M</td>\n", ip->proxy);\r
+   }\r
    fprintf(f,"<td align=\"right\">%Lu M</td>\n", ip->upload);\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",ip->min,ip->desired,f1,ip->max,f2,f1,ip->prio,f2);\r
-   total+=ip->traffic;\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
+   total_traffic+=ip->traffic;\r
    total_direct+=ip->direct;\r
    total_proxy+=ip->proxy;\r
    total_upload+=ip->upload;\r
@@ -1511,79 +1654,102 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     iplog=fopen(str,"a");\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%s",\r
-                    time(NULL),ip->name,ip->traffic,ip->direct,ip->proxy,ip->upload,ip->min,ip->max,ip->desired,d); /* d = date*/\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
      fclose(iplog);\r
     }\r
    }\r
-\r
   }\r
-  fprintf(f,"<tr><th colspan=\"4 \"align=\"left\">SUMMARY:</td>");\r
+  fprintf(f,"<tr><th colspan=\"%d\" align=\"left\">SUMMARY:</td>",colspan-7);\r
   fprintf(f,"<th align=\"right\">%Lu M</th>\\r
-  <th align=\"right\">%Lu M</th>\n", total, total_direct);\r
+  <th align=\"right\">%Lu M</th>\n", total_traffic, total_direct);\r
   if(qos_proxy)\r
+  {\r
    fprintf(f,"<th align=\"right\">%Lu M</th>\n", total_proxy);\r
+  }\r
   fprintf(f,"<th align=\"right\">%Lu M</th>", total_upload);\r
   fputs("<td colspan=\"4\"></td></th>\n</table>\n",f);\r
 \r
   if(active_classes>10)\r
   {\r
-   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Research and Planning (ERP)</th></tr>\n",f);\r
+   int top20_count=0,top20_perc1=0;\r
+   long long top20_perc2=0;\r
+   unsigned long long top20_sum=0l;\r
+  \r
+   fputs("<a name=\"erp\"></a><p><table border><tr><th colspan=\"5\">Enterprise Resource 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
-   if_exists(sum,sums,sum->l>=total/4)\r
+   if_exists(sum,sums,sum->l>=total_traffic/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
+    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_traffic);\r
    }\r
    \r
    if_exists(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
+    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_traffic);\r
    }\r
 \r
-   if_exists(sum,sums,sum->l>=total/2)\r
+   if_exists(sum,sums,sum->l>=total_traffic/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
+    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_traffic);\r
    }\r
 \r
-   if_exists(sum,sums,sum->l>=4*total/5)\r
+   if_exists(sum,sums,sum->l>=4*total_traffic/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
+    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_traffic);\r
    }\r
 \r
-   if_exists (sum,sums,sum->i>=(active_classes+1)/5)\r
+   if_exists(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
+    top20_count=sum->i;\r
+    top20_perc1=(100*sum->i+50)/active_classes;\r
+    top20_sum=sum->l;\r
+    top20_perc2=(100*sum->l+50)/total_traffic;\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",top20_count,top20_perc1,top20_sum,top20_perc2);\r
    }\r
 \r
    if_exists(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
+    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_traffic);\r
    }\r
 \r
    if_exists(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
+    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_traffic);\r
    }\r
 \r
    if_exists(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
+    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_traffic);\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
+   fprintf(f,"<tr><td><a href=\"%sERP.log\">All users, all traffic</a></td>\n", log_url);\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_traffic);\r
    fputs("</table>\n", f);\r
+\r
+   /* write basic ERP data to log directory */\r
+   if(!just_preview)\r
+   {\r
+    sprintf(str,"%s/ERP.log",log_dir);\r
+    iplog=fopen(str,"a");\r
+    if(iplog)\r
+    {\r
+     fprintf(iplog,"%ld\t%d\t%d %%\t%Lu M\t%Ld %%\t%d\t%Lu M\t%d\t%s",\r
+                    time(NULL), top20_count, top20_perc1, top20_sum, top20_perc2, active_classes, total_traffic, total, d); /* d = date*/\r
+     fclose(iplog);\r
+    }\r
+   }\r
   }\r
+\r
   fprintf(f, stats_html_signature, version);\r
   fclose(f);\r
  }\r
This page took 0.46081 seconds and 4 git commands to generate.