ip protocol usage statistics and more
[svn/Prometheus-QoS/.git] / htmlandlogs.c
index f624a48442c56c3d508c1b01f149de98f8b9d061..f16580adbb597adf97499255bc9280316255ce89 100644 (file)
@@ -20,6 +20,7 @@ extern char *log_url;
 extern int found_lmsid;\r
 extern char *lms_url;\r
 extern char *log_dir;\r
+extern char *ip6prefix;\r
 \r
 const char *tr_odd_even(void);\r
 /* implemented in prometheus.c, shared with parselogs.c */\r
@@ -30,14 +31,18 @@ void append_log(struct IP *self) /*using global variables*/
  FILE *f; \r
 \r
  date(d); /* this is typical cll1.h macro - prints current date */ \r
- string(str,STRLEN); \r
- sprintf(str,"%s/%s.log", log_dir, self->name);\r
- f=fopen(str,"a");\r
+ string(str, STRLEN); \r
+ sprintf(str, "%s/%s.log", log_dir, self->name);\r
+\r
+ /*-----------------------------------------------------------------*/\r
+ printf("Writing traffic log %s ...\n", str);\r
+ /*-----------------------------------------------------------------*/\r
+ f = fopen(str, "a");\r
  if(f > 0)\r
  {\r
-  fprintf(f,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
-            time(NULL), self->name, self->traffic, self->direct, self->proxy,\r
-            self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/\r
+  fprintf(f, "%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
+             time(NULL), self->name, self->traffic, self->direct, self->proxy,\r
+             self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/\r
   fclose(f);\r
  }\r
  else\r
@@ -50,7 +55,7 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
 {\r
  int i;\r
  char *str;\r
- FILE *f=fopen(html,"w");\r
+ FILE *f=fopen(html, "w");\r
 \r
  string(str,STRLEN); \r
  if(f > 0)\r
@@ -58,10 +63,6 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
   int count=1;\r
   i=0;\r
 \r
-  /*-----------------------------------------------------------------*/\r
-  printf("Writing statistics summary into HTML page %s ...\n", html);\r
-  /*-----------------------------------------------------------------*/\r
-\r
   if(use_jquery_popups)\r
   {\r
    fprintf(f,"<script type=\"text/javascript\" src=\"%s\"></script>\n", jquery_url);\r
@@ -89,8 +90,8 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
 \r
    for_each(keyword, keywords) if(keyword->ip_count)\r
    {\r
-    fprintf(f,"<td style=\"text-align: right\"><span style=\"color:#%s\">%d&nbsp;MB</span></td>",\r
-              keyword->html_color, group->min*keyword->data_limit);\r
+    fprintf(f, "<td style=\"text-align: right\"><span style=\"color:#%s\">%d&nbsp;MB</span></td>",\r
+               keyword->html_color, group->min*keyword->data_limit);\r
    }   \r
    i += group->desired; \r
    total += group->count;\r
@@ -172,15 +173,15 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
    i++;\r
 \r
    if(ip->max < ip->desired) \r
-   { \r
-    f1 = "<span style=\"color:red\">"; \r
+   {\r
+    f1 = "<span style=\"color:red\">";\r
     f2 = "</span>"; \r
     limit_count++; \r
-   } \r
-   else if(ip->prio > highest_priority+1) \r
-   { \r
-    f1 = "<span style=\"color:brown\">"; \r
-    f2 = "</span>"; \r
+   }\r
+   else if(ip->prio > highest_priority+1)\r
+   {\r
+    f1 = "<span style=\"color:brown\">";\r
+    f2 = "</span>";\r
     prio_count++; \r
    }       \r
 \r
@@ -193,18 +194,28 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
 \r
    if(use_jquery_popups)\r
    {\r
-     fprintf(f,"<span id=\"sharing_%d\" style=\"display:none\">",i);\r
+     fprintf(f, "<span id=\"sharing_%d\" style=\"display:none\">",i);\r
      popup_button=0;\r
-     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))\r
+\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
+     {\r
+      fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r
+                 log_url, sharedip->name, sharedip->name);\r
+      popup_button++;\r
+     }\r
+\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
      {\r
-      fprintf(f,"<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", log_url, sharedip->name, sharedip->name);\r
+      fprintf(f, "<br /><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s/64</a>\n", \r
+                 log_url, sharedip->addr, sharedip->addr);\r
       popup_button++;\r
      }\r
+\r
      fputs("</span>\n",f);\r
      if(popup_button)\r
      {\r
-      fprintf(f,"<span>[<a class=\"blue\" href=\"#\" onClick=\"$(this).parent().hide();$(\'#sharing_%d\').show();$(\'#download_%d\').show();$(\'#upload_%d\').show();return(false);\" style=\"cursor: pointer;\">+%d</a>]</span>",\r
-                i, i, i, popup_button);\r
+      fprintf(f, "<span>[<a class=\"blue\" href=\"#\" onClick=\"$(this).parent().hide();$(\'#sharing_%d\').show();$(\'#download_%d\').show();$(\'#upload_%d\').show();return(false);\" style=\"cursor: pointer;\">+%d</a>]</span>",\r
+                 i, i, i, popup_button);\r
      }\r
    }\r
    fputs("</td>\n",f);\r
@@ -225,16 +236,19 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
    }\r
    fprintf(f,"<td style=\"text-align: right\">%Lu</td>\n", ip->credit);\r
    fprintf(f,"<td style=\"text-align: right\"><span style=\"color:#%s\">%Lu</span></td>",\r
-             ip->keyword->html_color,\r
-             ip->credit+(ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)));\r
+             ip->keyword->html_color, ip->realquota);\r
    fprintf(f,"<td style=\"text-align: right\">%s%Lu%s", f1, ip->traffic, f2);\r
 \r
    /* download --------------------------------------- */\r
    fprintf(f,"</td><td style=\"text-align: right\">%Lu", ip->direct);\r
    if(use_jquery_popups)\r
    {\r
-     fprintf(f,"<span id=\"download_%d\" style=\"display:none\">",i);\r
-     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))\r
+     fprintf(f,"<span id=\"download_%d\" style=\"display:none\">", i);\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
+     {\r
+      fprintf(f,"<br />%Lu", sharedip->direct);\r
+     }\r
+     for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
      {\r
       fprintf(f,"<br />%Lu", sharedip->direct);\r
      }\r
@@ -251,8 +265,12 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
    fprintf(f,"<td style=\"text-align: right\">%Lu", ip->upload);\r
    if(use_jquery_popups)\r
    {\r
-     fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">",i);\r
-     for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))\r
+     fprintf(f,"<span id=\"upload_%d\" style=\"display:none\">", i);\r
+     for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && !sharedip->v6) /* IPv4 only */\r
+     {\r
+      fprintf(f,"<br />%Lu", sharedip->upload);\r
+     }\r
+     for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing) && sharedip->v6) /* IPv6 only */\r
      {\r
       fprintf(f,"<br />%Lu", sharedip->upload);\r
      }\r
@@ -302,6 +320,31 @@ void write_htmlandlogs(char *html, char *d, int total, int just_preview)
   fprintf(f,"<th style=\"text-align: right\">%Lu</th>", total_upload);\r
   fprintf(f,"<th colspan=\"4\"><span style=\"color:red\">LIMIT %dx</span> <span style=\"color:brown\">LOW-PRIO %dx</span></th></tr>\n</thead></table>\n",limit_count,prio_count);\r
 \r
+  if(ip6prefix)\r
+  {\r
+   unsigned long long pkts4 =0, pkts6 = 0, bytes4 = 0, bytes6 = 0;\r
+   for_each(ip, ips)\r
+   { \r
+    if(ip->v6)\r
+    {\r
+     bytes6 += ip->traffic;\r
+     pkts6 += ip->pktsdown+ip->pktsup;\r
+    }\r
+    else\r
+    {\r
+     bytes4 += ip->traffic;\r
+     pkts4 += ip->pktsdown+ip->pktsup;\r
+    }\r
+   }\r
+\r
+   fputs("<p><table class=\"decorated last\"><caption>IP protocols usage</caption>\n",f);\r
+   fprintf(f, "%s<td>Total IPv4</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%d %%)</td></tr>\n",\r
+              tr_odd_even(), bytes4, (float)(100*bytes4)/(bytes4+bytes6), pkts4, (float)(100*pkts4)/(pkts4+pkts6));\r
+   fprintf(f, "%s<td>Total IPv6</td><td style=\"text-align: right\">%Lu MB (%.2f %%)</td><td style=\"text-align: right\">%Lu packets (%d %%)</td></tr>\n",\r
+              tr_odd_even(), bytes6, (float)(100*bytes6)/(bytes4+bytes6), pkts6, (float)(100*pkts6)/(pkts4+pkts6));\r
+   fputs("</table>\n", f);\r
+  }\r
+\r
   row_odd_even = 0;\r
   if(active_classes>10)\r
   {\r
This page took 0.170105 seconds and 4 git commands to generate.