parsovani LMS id + LMS id do Hall of Fame (bude nutné dořešit...)
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 26 Apr 2011 23:24:00 +0000 (23:24 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 26 Apr 2011 23:24:00 +0000 (23:24 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@145 251d49ef-1d17-4917-a970-b30cf55b089b

prometheus.c

index 7ab712f737f15fa340c797d35e4656581e6c0273..9853a5a169de8b41c1fa80c928fe6e5e303a2abd 100644 (file)
@@ -7,7 +7,7 @@
 /*  Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
 \r
 /*  Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
 \r
-/* Modified by: xChaos, 20110221\r
+/* Modified by: xChaos, 20110427\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -104,6 +104,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
 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
 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
@@ -622,8 +623,18 @@ void run_restore(void)
 \r
 void parse_ip(char *str)\r
 {\r
 \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
+   ptr++;\r
+  *ptr=0;\r
+ }\r
  \r
  \r
+ ptr=str;\r
  while(*ptr && *ptr!=' ' && *ptr!=9)\r
   ptr++;\r
  \r
  while(*ptr && *ptr!=' ' && *ptr!=9)\r
   ptr++;\r
  \r
@@ -644,6 +655,11 @@ void parse_ip(char *str)
  }\r
  ip->addr=ipaddr;\r
  ip->name=ipname;\r
  }\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
 }\r
 \r
 char *parse_datafile_line(char *str)\r
@@ -657,7 +673,9 @@ char *parse_datafile_line(char *str)
   return ptr;\r
  } \r
  else \r
   return ptr;\r
  } \r
  else \r
+ {\r
   return NULL;\r
   return NULL;\r
+ }\r
 }\r
 \r
 struct IpLog\r
 }\r
 \r
 struct IpLog\r
@@ -674,7 +692,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
 {\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
  char mstr[4], ystr[5];\r
  FILE *f; \r
  string(str,STRLEN);\r
@@ -729,7 +747,8 @@ void parse_ip_log(int argc, char **argv)
     printf("Parsing %s ...",filename);\r
     accept_month=0;\r
     traffic_month=0;\r
     printf("Parsing %s ...",filename);\r
     accept_month=0;\r
     traffic_month=0;\r
-    guaranted = 0;\r
+    guaranted=0;\r
+    lmsid=0;\r
     parse(filename)\r
     {\r
      y_ok=m_ok=0;  \r
     parse(filename)\r
     {\r
      y_ok=m_ok=0;  \r
@@ -737,11 +756,12 @@ void parse_ip_log(int argc, char **argv)
      {\r
       case 2: name = ptr;break;\r
       case 3: traffic = atol(ptr);break;\r
      {\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 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
                {\r
                 valid_columns(ptr2,ptr,' ',col2) switch(col2)\r
                 {\r
@@ -752,6 +772,7 @@ void parse_ip_log(int argc, char **argv)
                else\r
                {\r
                  if(col == 7) guaranted = atol(ptr);\r
                else\r
                {\r
                  if(col == 7) guaranted = atol(ptr);\r
+                 if(col == 10) lmsid = atoi(ptr);\r
                }\r
      }\r
      \r
                }\r
      }\r
      \r
@@ -957,7 +978,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   str=_;\r
 \r
   if(*str<'0' || *str>'9')\r
   str=_;\r
 \r
   if(*str<'0' || *str>'9')\r
+  {\r
+   /* any line starting with non-number is comment ...*/\r
    continue;\r
    continue;\r
+  }\r
   \r
   //Does this IP share QoS class with some other ?\r
   substring=strstr(str,"sharing-");\r
   \r
   //Does this IP share QoS class with some other ?\r
   substring=strstr(str,"sharing-");\r
@@ -969,7 +993,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
    ip->sharing=substring;\r
    ip->keyword=defaultkeyword; /* settings for default keyword */\r
    while(*substring && *substring!='\n')\r
+   {\r
     substring++;\r
     substring++;\r
+   }\r
    *substring=0; \r
   }\r
   else\r
    *substring=0; \r
   }\r
   else\r
@@ -1319,7 +1345,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   int group_count=0;\r
   FILE *credit_file=NULL;\r
   \r
   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
     \r
   for_each(group,groups)\r
   {\r
@@ -1342,7 +1371,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    }\r
    \r
    rate-=digital_divide*group->min;\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
     \r
    /*shaping of aggresive downloaders, with credit file support */\r
    if(use_credit)\r
@@ -1355,10 +1387,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
          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
       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
      }\r
      else\r
      {\r
@@ -1367,15 +1405,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
            (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
       }\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
         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
        fprintf(credit_file,"%s %Lu\n",ip->addr,lcredit);\r
       }\r
      }\r
@@ -1383,7 +1426,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
         \r
    }\r
   }\r
         \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
  }\r
 \r
  if(just_preview)\r
@@ -1465,25 +1511,36 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   FILE *iplog;\r
   struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums=NULL;\r
 \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
   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
   \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
   if(qos_proxy)\r
+  {\r
    fputs("<td align=\"right\">proxy</td>\n",f);\r
    fputs("<td align=\"right\">proxy</td>\n",f);\r
+  }\r
   fputs("<td align=\"right\">upload</td>\\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
 \r
   for_each(ip,ips)\r
   {\r
@@ -1502,14 +1559,28 @@ 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
 #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)\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
+    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
    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
     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\">%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
+   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+=ip->traffic;\r
    total_direct+=ip->direct;\r
    total_proxy+=ip->proxy;\r
    total+=ip->traffic;\r
    total_direct+=ip->direct;\r
    total_proxy+=ip->proxy;\r
@@ -1532,18 +1603,20 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     iplog=fopen(str,"a");\r
     if(iplog)\r
     {\r
     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
      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
   if(qos_proxy)\r
   fprintf(f,"<th align=\"right\">%Lu M</th>\\r
   <th align=\"right\">%Lu M</th>\n", total, total_direct);\r
   if(qos_proxy)\r
+  {\r
    fprintf(f,"<th align=\"right\">%Lu M</th>\n", total_proxy);\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
   fprintf(f,"<th align=\"right\">%Lu M</th>", total_upload);\r
   fputs("<td colspan=\"4\"></td></th>\n</table>\n",f);\r
 \r
This page took 0.226691 seconds and 4 git commands to generate.