minor bugfixes (#ifdef MONITORINGTRHU)
[svn/Prometheus-QoS/.git] / prometheus.c
index a8ec705f0ebbdaf7d0ed33f3af5449b6fba8eee9..4cc02a02543b8c2c23c1070fcb09a3b6807362da 100644 (file)
@@ -2,12 +2,12 @@
 /* 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-2019 Michael Polak, Arachne Aerospace     */\r
+/* Copyright(C) 2005-2020 Michael Polak, Arachne Aerospace     */\r
 /* iptables-restore support Copyright(C) 2007-2008 ludva       */\r
 /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 \r
-/* Modified by: xChaos, 20190912\r
+/* Modified by: xChaos, 20200107\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -29,7 +29,7 @@
 #include "cll1-0.6.2.h"\r
 #include "ipstruct.h"\r
 \r
-const char *version = "0.9.0-c";\r
+const char *version = "1.0.0-a";\r
 \r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 /* Versions: 0.9.0 is development release, 1.0 will be "stable"    */\r
@@ -40,7 +40,7 @@ const char *version = "0.9.0-c";
 /* Warning: unofficial Github mirror is not supported by author!  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 \r
-const char *stats_html_signature = "<span class=\"small\">Statistics generated by Prometheus QoS version %s<br />GPL+Copyright(C)2005-2017 Michael Polak, <a target=\"_blank\" 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-2020 Michael Polak, <a target=\"_blank\" href=\"http://www.arachne.cz/\">Arachne Labs</a></span>\n";\r
 \r
 #define STRLEN 512\r
 #undef DEBUG\r
@@ -63,6 +63,7 @@ char    *upstreamfile = "/etc/prometheus/upstream.interfaces"; /* list of interf
 char  *downstreamfile = "/etc/prometheus/downstream.interfaces"; /* list of interfaces to manage */\r
 char     *qosfreefile = "/etc/prometheus/qosfree.interfaces"; /* list of interfaces to manage */\r
 char    *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/\r
+char    *iptablesdump = "/var/spool/prometheus.iptables-dump"; /* temporary file for iptables -L -v -x -n -t mangle */\r
 char   *ip6tablesfile = "/var/spool/prometheus.ip6tables"; /* temporary file for ip6tables-restore*/\r
 char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
 char        *classmap = "/var/lib/misc/prometheus.classes"; /* credit log file */\r
@@ -290,6 +291,7 @@ void get_config(char *config_filename)
   option("ip6tables-save",ip6tablessave);\r
   option("ip6tables-restore",ip6tablesrestore);\r
   option("iptables-in-filename",iptablesfile);\r
+  option("iptables-dump-filename",iptablesdump);\r
   option("ip6tables-in-filename",ip6tablesfile);\r
   option("hosts",hosts);\r
   option("downstream-interfaces-list-filename",downstreamfile);\r
@@ -640,14 +642,34 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  printf("Parsing class defintion file %s ...\n", hosts);\r
  /*-----------------------------------------------------------------*/\r
  parse_hosts(hosts);\r
-/*\r
- //this was pretty dumb idea anyway...\r
- if(just_networks)\r
+\r
+#ifdef MONITORINGTRHU_CTU\r
+//special hack only to generate certain required CSV statistics for www.ctu.cz (regulation body)\r
+//not required for everyday use, requires special syntax sugar in hosts file, see parsehosts.c\r
+ for_each(technology, technologies)\r
  {\r
-  analyse_topology("/usr/sbin/traceroute -n -m 10 -w 2 %s.%d");\r
-  exit(-1); \r
- }\r
-*/\r
+  char *filename;\r
+  FILE *f;\r
+  string(filename, strlen(log_dir) + strlen(technology->filename) + 5);\r
+  strcpy(filename, log_dir);\r
+  strcat(filename, technology->filename); \r
+  strcat(filename, ".csv");\r
+  /*-----------------------------------------------------------------*/\r
+  printf("Writing report file %s ...\n", filename);\r
+  /*-----------------------------------------------------------------*/\r
+  f = fopen(filename, "w");\r
+  if(f)\r
+  {\r
+   for_each(ip, ips) if(eq(technology->filename, ip->technology_str))\r
+   {\r
+    fprintf(f,"%d,%s,%d\n", ip->lmsid, ip->ruian_id_str, ip->max);\r
+   }\r
+   fclose(f);\r
+  }\r
+  else\r
+   perror(filename); \r
+ } \r
+#endif\r
 \r
  /*-----------------------------------------------------------------*/\r
  puts("Resolving shared connections ...");\r
@@ -772,7 +794,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   {\r
    for_each(interface, interfaces)\r
    {\r
-    sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, (interface->is_upstream?"dst":"src"), qos_free_dst_ipset, interface->name);\r
+    sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, qos_free_dst_ipset, (interface->is_upstream?"dst":"src"), interface->name);\r
     iptables_save_line(str, IPv4);\r
    }\r
   }\r
@@ -781,7 +803,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   {\r
    for_each(interface, interfaces)\r
    {\r
-    sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, (interface->is_upstream?"src":"dst"), qos_free_src_ipset, interface->name);\r
+    sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, qos_free_src_ipset, (interface->is_upstream?"src":"dst"), interface->name);\r
     iptables_save_line(str, IPv4);\r
    }\r
   }\r
@@ -1220,6 +1242,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   printf("Writing statistics into HTML page %s ...\n", html);\r
   /*-----------------------------------------------------------------*/\r
   write_htmlandlogs(html, d, total, just_preview);\r
+  printf("\n");\r
  }\r
 \r
  if(just_preview)\r
This page took 0.12892 seconds and 4 git commands to generate.