json bug fix :-)
[svn/Prometheus-QoS/.git] / prometheus.c
index 494ce50..8c70bb0 100644 (file)
@@ -40,7 +40,7 @@ const char *version = "0.8.3-d";
 /* C source code development versions ("beta"): 0.7.9-a, 0.8.1-b, etc. */\r
 /* C source code release versions: 0.8.0, 0.8.2, 0.8.4, etc. */\r
 \r
-const char *stats_html_signature = "<span class=\"small\">Statistics generated by Prometheus QoS version %s<br />GPL+Copyright(C)2005-2012 Michael Polak, <a href=\"http://www.arachne.cz/\">Arachne Labs</a></span>\n";\r
+const char *stats_html_signature = "<span class=\"small\">Statistics generated by Prometheus QoS version %s<br />GPL+Copyright(C)2005-2012 Michael Polak, <a target=\"_blank\" href=\"http://www.arachne.cz/\">Arachne Labs</a></span>\n";\r
 \r
 /* ======= All path names are defined here (for RPM patch) =======  */\r
 \r
@@ -610,7 +610,7 @@ void get_traffic_statistics(void)
      {\r
       printf("(upload) ");\r
      }\r
-     printf("IP %s: %Lu M (%ld pkts)\n", ipaddr, traffic, pkts);\r
+     printf("IP %s: %Lu MB (%ld pkts)\n", ipaddr, traffic, pkts);\r
 \r
      if_exists(ip,ips,eq(ip->addr,ipaddr)); \r
      else \r
@@ -917,13 +917,13 @@ void parse_ip_log(int argc, char **argv)
    if(iplog->traffic)\r
    {\r
     fprintf(f, "%s<td style=\"text-align: right\">%d</td>\n\\r
-<td style=\"text-align: left\"><a class=\"blue\" href=\"%s%s.log\">%s</td>\n\\r
+<td style=\"text-align: left\"><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</td>\n\\r
 <td style=\"text-align: right\">", \r
                tr_odd_even(), i++, log_url, iplog->name, iplog->name);  \r
     if(iplog->lmsid > 0)\r
     {\r
      /*base URL will be configurable soon ... */\r
-     fprintf(f, "<a  class=\"blue\"  href=\"%s%d\">%04d</a>\n", lms_url, iplog->lmsid, iplog->lmsid);\r
+     fprintf(f, "<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n", lms_url, iplog->lmsid, iplog->lmsid);\r
     }\r
     else if(iplog->lmsid == 0)\r
     {\r
@@ -939,9 +939,9 @@ void parse_ip_log(int argc, char **argv)
    }\r
   }\r
   fprintf(f,"</tbody><thead><tr>\\r
-  <td colspan=\"4\" style=\"text-align: left\">Total:</td>\\r
-  <td style=\"text-align: right\"><strong>%ld&nbsp;GB</strong></td>\\r
-  <td style=\"text-align: right\"><strong>%Ld&nbsp;kb/s</strong></td></tr>\n", total, line);\r
+  <th colspan=\"3\" style=\"text-align: left\">Total:</th>\\r
+  <th colspan=\"2\" style=\"text-align: right\"><strong>%ld&nbsp;GB</strong></th>\\r
+  <th style=\"text-align: right\"><strong>%Ld&nbsp;kb/s</strong></th></tr>\n", total, line);\r
   fputs("</thead></table>\n", f);\r
 \r
   row_odd_even = 0;\r
@@ -958,7 +958,11 @@ void parse_ip_log(int argc, char **argv)
    if_exists(iplog,iplogs,iplog->l>=total/4)\r
    {\r
     fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r
-    fprintf(f,"<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d %%</td><td style=\"text-align: right\">%ld G</td><td style=\"text-align: right\">%d %%</td></tr>\n",iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
+    fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
+<td style=\"text-align: right\">%d %%</td>\n\\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
+<td style=\"text-align: right\">%d %%</td></tr>\n",\r
+              iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
    }\r
    \r
    if_exists(iplog,iplogs,iplog->i==10)\r
@@ -966,9 +970,9 @@ void parse_ip_log(int argc, char **argv)
     fprintf(f,"%s<td>Top 10 downloaders</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\"><strong>10</strong></td>\n\\r
 <td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld G</td>\n\\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
 <td style=\"text-align: right\">%d %%</td></tr>\n",\r
-               (100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
+               (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
    }\r
 \r
    if_exists(iplog,iplogs,iplog->l>=total/2)\r
@@ -976,7 +980,7 @@ void parse_ip_log(int argc, char **argv)
     fprintf(f,"%s<td>Top 50%% of traffic</td>\n", tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
 <td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld G</td>\n\\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
 <td style=\"text-align: right\"><strong>%d %%</strong></td></tr>\n",\r
               iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
    }\r
@@ -986,9 +990,9 @@ void parse_ip_log(int argc, char **argv)
     fprintf(f,"%s<td>Top 80%% of traffic</td>\n",tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
 <td style=\"text-align: right\">%d %%</td>\n\\r
-<td style=\"text-align: right\">%ld G</td>\n\\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
 <td style=\"text-align: right\"><strong>%d %%</strong></td></tr>\n",\r
-              iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
+              iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
    }\r
 \r
    if_exists (iplog,iplogs,iplog->i>=i/5)\r
@@ -996,15 +1000,19 @@ void parse_ip_log(int argc, char **argv)
     fprintf(f,"%s<td>Top 20%% downloaders</td>\n",tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
-<td style=\"text-align: right\">%ld G</td>\n\\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
 <td style=\"text-align: right\">%d %%</td></tr>\n",\r
-              iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
+              iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
    }\r
 \r
    if_exists(iplog,iplogs,iplog->i>=i/4)\r
    {\r
     fprintf(f,"%s<td>Top 25%% downloaders</td>\n", tr_odd_even());\r
-    fprintf(f,"<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d %%</td><td style=\"text-align: right\">%ld G</td><td style=\"text-align: right\">%d %%</td></tr>\n",iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
+    fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
+<td style=\"text-align: right\">%d %%</td>\n\\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
+<td style=\"text-align: right\">%d %%</td></tr>\n",\r
+               iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
    }\r
 \r
    if_exists(iplog,iplogs,iplog->i>=i/2)\r
@@ -1012,20 +1020,25 @@ void parse_ip_log(int argc, char **argv)
     fprintf(f,"%s<td>Top 50%% downloaders</td>\n",tr_odd_even());\r
     fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
 <td style=\"text-align: right\"><strong>%d %%</strong></td>\n\\r
-<td style=\"text-align: right\">%ld G</td><td style=\"text-align: right\">%d %%</td></tr>\n",iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
+<td style=\"text-align: right\">%d %%</td></tr>\n",\r
+              iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
    }\r
 \r
    if_exists(iplog,iplogs,iplog->i>=4*i/5)\r
    {\r
     fprintf(f,"%s<td>Top 80%% downloaders</td>\n",tr_odd_even());\r
-    fprintf(f,"<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d %%</td><td style=\"text-align: right\">%ld G</td><td style=\"text-align: right\">%d %%</td></tr>\n",iplog->i,(100*iplog->i+50)/i,iplog->l,(int)((100*iplog->l+50)/total));\r
+    fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
+<td style=\"text-align: right\">%d %%</td>\n\\r
+<td style=\"text-align: right\">%ld GB</td>\n\\r
+<td style=\"text-align: right\">%d %%</td></tr>\n",\r
+              iplog->i, (100*iplog->i+50)/i, iplog->l, (int)((100*iplog->l+50)/total));\r
    }\r
 \r
-   fprintf(f,"</tbody><thead><tr>\n\\r
-<th>All users, all traffic</th>\n\\r
-<th style=\"text-align: right\">%d</th>\n\\r
+   fprintf(f,"</tbody><thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r
+   fprintf(f,"<th style=\"text-align: right\">%d</th>\n\\r
 <th style=\"text-align: right\">100 %%</th>\n\\r
-<th style=\"text-align: right\">%ld G</th>\n\\r
+<th style=\"text-align: right\">%ld GB</th>\n\\r
 <th style=\"text-align: right\">100 %%</th></tr>\n",i-1,total);\r
    fputs("</thead></table>\n", f);\r
   }\r
@@ -1640,7 +1653,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     {\r
      fprintf(f, ",\n");\r
     }\r
-    if(ip->traffic || ip->direct || ip->proxy || ip->upload)\r
+    if(     ip->lmsid > 0 \r
+        && (ip->traffic || ip->direct || ip->proxy || ip->upload))\r
     {\r
      fprintf(f, " %d:{ \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu }",\r
                 ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload);\r
@@ -1794,7 +1808,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    printf("%03d. %-22s %10Lu (%d/%d)\n",i ,ip->name, ip->traffic, ip->min, ip->max); \r
 #endif\r
    /* hostnames -------------------------------------- */\r
-   fprintf(f,"%s<td style=\"text-align: right\"><a name=\"%s\"></a>%d</td><td><a class=\"blue\" href=\"%s%s.log\">%s</a>\n", \r
+   fprintf(f,"%s<td style=\"text-align: right\"><a name=\"%s\"></a>%d</td><td><a class=\"blue\" target=\"_blank\" href=\"%s%s.log\">%s</a>\n", \r
               tr_odd_even(), ip->name, i, log_url, ip->name, ip->name);\r
 \r
    if(use_jquery_popups)\r
@@ -1803,7 +1817,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      popup_button=0;\r
      for_each(sharedip, ips) if(eq(ip->name, sharedip->sharing))\r
      {\r
-      fprintf(f,"<br /><a class=\"blue\" 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</a>\n", log_url, sharedip->name, sharedip->name);\r
       popup_button++;\r
      }\r
      fputs("</span>\n",f);\r
@@ -1821,7 +1835,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     fputs("<td style=\"text-align: right\">",f);\r
     if(ip->lmsid > 0)\r
     {\r
-     fprintf(f,"<a class=\"blue\" href=\"%s%d\">%04d</a>\n", lms_url, ip->lmsid, ip->lmsid);\r
+     fprintf(f,"<a class=\"blue\" target=\"_blank\" href=\"%s%d\">%04d</a>\n", lms_url, ip->lmsid, ip->lmsid);\r
     }\r
     else if(ip->lmsid == 0)\r
     {\r
@@ -1925,7 +1939,11 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    if_exists(sum,sums,sum->l>=total_traffic/4)\r
    {\r
     fprintf(f,"%s<td>Top 25%% of traffic</td>\n", tr_odd_even());\r
-    fprintf(f,"<td style=\"text-align: right\">%d</td><td style=\"text-align: right\">%d %%</td><td style=\"text-align: right\">%Lu M</td><td style=\"text-align: right\">%Ld %%</td></tr>\n",sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
+    fprintf(f,"<td style=\"text-align: right\">%d</td>\n\\r
+<td style=\"text-align: right\">%d %%</td>\n\\r
+<td style=\"text-align: right\">%Lu MB</td>\n\\r
+<td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
+              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
@@ -1935,7 +1953,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 <td style=\"text-align: right\">%d %%</td>\n\\r
 <td style=\"text-align: right\">%Lu MB</td>\n\\r
 <td style=\"text-align: right\">%Ld %%</td></tr>\n",\r
-              (100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
+              (100*sum->i+50)/active_classes, sum->l, (100*sum->l+50)/total_traffic);\r
    }\r
 \r
    if_exists(sum,sums,sum->l>=total_traffic/2)\r
@@ -2002,10 +2020,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
               sum->i,(100*sum->i+50)/active_classes,sum->l,(100*sum->l+50)/total_traffic);\r
    }\r
 \r
-   fprintf(f,"<tr><thead><th><a class=\"blue\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r
+   fprintf(f,"<thead><tr><th><a class=\"blue\" target=\"_blank\" href=\"%sERP.log\">All users, all traffic</a></th>\n", log_url);\r
    fprintf(f,"<th style=\"text-align: right\">%d</th>\n\\r
 <th style=\"text-align: right\">100 %%</th>\n\\r
-<th style=\"text-align: right\">%Lu M</th>\n\\r
+<th style=\"text-align: right\">%Lu MB</th>\n\\r
 <th style=\"text-align: right\">100 %%</th></tr>\n",active_classes,total_traffic);\r
    fputs("</thead></table>\n", f);\r
 \r
@@ -2166,7 +2184,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   \r
    if(f)\r
    {\r
-     fprintf(f, "%s %d", ip->addr, ip->mark);\r
+     fprintf(f, "%s %d\n", ip->addr, ip->mark);\r
    }\r
   }\r
   else\r
This page took 0.180868 seconds and 4 git commands to generate.