-/* Modified by: xChaos, 20131029 */\r
+/* Modified by: xChaos, 20200104 */\r
+\r
+#define MONITORINGTRHU_CTU\r
\r
struct IP\r
{\r
unsigned long pktsup;\r
unsigned long pktsdown;\r
struct Keyword *keyword;\r
+#ifdef MONITORINGTRHU_CTU\r
+ char *technology_str;\r
+ char *ruian_id_str;\r
+#endif\r
int v6;\r
int mask;\r
struct IP *uplink;\r
\r
void TheIP(char *ipaddr, int is_network);\r
/* function implemented in parsehosts.c */\r
+\r
+#ifdef MONITORINGTRHU_CTU\r
+struct Technology\r
+{\r
+ char *filename;\r
+ list(Technology);\r
+};\r
+\r
+extern struct Technology *technologies, *technology;\r
+#endif\r
{\r
push(ip, ips); \r
}\r
+#ifdef MONITORINGTRHU_CTU\r
+ ip->technology_str = NULL;\r
+ ip->ruian_id_str = NULL;\r
+#endif\r
+\r
ip_count++;\r
}\r
\r
+#ifdef MONITORINGTRHU_CTU\r
+struct Technology *technologies = NULL, *technology = NULL;\r
+#endif\r
struct IP *lastIP6range, *lastIP6uplink;\r
\r
/* == This function strips extra characters after IPv4 address and stores it = */\r
else\r
{\r
substring = strstr(str, "#255.");\r
- if(substring and not strstr(str, "#255.255.255.255")) /* do not ping /32 uplinks */\r
+ if(substring and not strstr(str, "#255.255.255.255")) /* ignore /32 subnets */\r
{\r
/* netmask detected - save network*/\r
unsigned bit;\r
}\r
else\r
{\r
+ /* Main branch - most IP addresses go here */\r
/*Do we have to create new QoS class for this IP ? */\r
if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
{\r
+#ifdef MONITORINGTRHU_CTU\r
+//special hack only to generate certain required CSV statistics for www.ctu.cz (regulation body)\r
+ char *found_at = strchr(str, '@');\r
+ char *ruian_id_str = NULL;\r
+ technology = NULL;\r
+ if(found_at)\r
+ {\r
+ int len;\r
+ char *found_ruian_end = strchr(found_at, ' ');\r
+ char *found_tech_str = found_at;\r
+ while(found_tech_str-- > str && *found_tech_str != ' ' && *found_tech_str != '#');\r
+ if(found_tech_str > str)\r
+ {\r
+ len = found_at - found_tech_str - 1;\r
+ for_each(technology, technologies)\r
+ if(!strncmp(technology->filename, found_tech_str + 1, len))\r
+ break;\r
+ if(!technology)\r
+ {\r
+ create(technology,Technology);\r
+ string(technology->filename, len + 1);\r
+ strncpy(technology->filename, found_tech_str + 1, len);\r
+ technology->filename[len] = 0;\r
+ push(technology, technologies);\r
+ }\r
+ if(found_ruian_end)\r
+ {\r
+ len = found_ruian_end - found_at - 1;\r
+ string(ruian_id_str, len + 1);\r
+ strncpy(ruian_id_str, found_at + 1, len);\r
+ ruian_id_str[len] = 0;\r
+ }\r
+ }\r
+ }\r
+#endif\r
parse_and_append_ip(str, ips);\r
if(lastIP6range)\r
{\r
ip->mark = FIRSTIPCLASS+1+class_count++; \r
update_network(ip->addr, ip);\r
\r
+#ifdef MONITORINGTRHU_CTU\r
+ if(technology)\r
+ {\r
+ ip->technology_str = technology->filename;\r
+ ip->ruian_id_str = ruian_id_str;\r
+ /* debug printf("[%s,%d,%s,%d]\n", ip->technology_str,ip->lmsid, ip->ruian_id_str, ip->max); */\r
+ }\r
+#endif\r
+\r
if_exists(group,groups,(group->min == ip->min)) \r
{ \r
group->count++; \r
group->desired = ip->min; \r
insert(group, groups, desc_order_by,min);\r
}\r
- }//endif keyword-\r
+ }//endif keyword- \r
}//endif netmask\r
}//endif sharing-\r
}\r
// TheIP("0.0.0.0", TRUE);\r
// ip->name = "TOTAL";\r
// ip->mask = 0;\r
-}\r
+}
\ No newline at end of file
#include "cll1-0.6.2.h"\r
#include "ipstruct.h"\r
\r
-#define STRLEN 512\r
+#define STRLEN 256\r
\r
/* globals declared in prometheus.c */\r
extern struct IP *ips, *ip, *sharedip;\r
extern int include_upload;\r
\r
int traffic_detected = 0;\r
+extern char *iptablesdump;\r
\r
/* ===================== traffic analyser - uses iptables ================ */ \r
\r
{\r
char *str,*cmd;\r
int downloadflag = 0;\r
-\r
- textfile(Pipe,str) *line,*lines=NULL;\r
- string(str,STRLEN);\r
+ FILE *f;\r
string(cmd,STRLEN);\r
\r
- sprintf(cmd,"%s -L -v -x -n -t mangle", whichiptables);\r
- shell(cmd);\r
- input(str,STRLEN)\r
- {\r
- create(line,Pipe);\r
- line->str=str;\r
- string(str,STRLEN);\r
- append(line,lines);\r
- }\r
+ sprintf(cmd, "%s -L -v -x -n -t mangle>%s", whichiptables, iptablesdump);\r
+ /*-----------------------------------------------------------------*/\r
+ printf("Running %s ...\n", cmd);\r
+ /*-----------------------------------------------------------------*/\r
+ system(cmd);\r
+ /*-----------------------------------------------------------------*/\r
+ printf("Processing %s ...\n", iptablesdump);\r
+ /*-----------------------------------------------------------------*/\r
+ f = fopen(iptablesdump,"r");\r
+ if(!f)\r
+ perror(iptablesdump);\r
\r
- for_each(line,lines)\r
+ while(!feof(f))\r
{\r
int col, accept = 0, /*proxyflag = 0, */valid = 1, setchainname = 0, commonflag = 0; \r
unsigned long long traffic = 0;\r
unsigned long pkts = 0;\r
char *ipaddr = NULL,*ptr;\r
\r
- valid_columns(ptr, line->str, ' ', col)\r
+ string(str, STRLEN);\r
+ fgets(str, STRLEN, f);\r
+ valid_columns(ptr, str, ' ', col)\r
if(valid) switch(col)\r
{ \r
case 1: if(eq(ptr,"Chain"))\r
/* 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
#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
/* 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-2019 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
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
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
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, html_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
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