more refucktoring (into multiple modules)
[svn/Prometheus-QoS/.git] / prometheus.c
index 17c77af29484607eaf802b5a1a07a8b5956fba12..717971410549b1ce35de9bc6eadc77ce1ae55fe3 100644 (file)
@@ -7,7 +7,7 @@
 /*  Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */\r
 \r
-/* Modified by: xChaos, 20120610\r
+/* Modified by: xChaos, 20121007\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
    \r
    GNU General Public License is located in file COPYING */\r
 \r
-#define STRLEN 256\r
-#define FIRSTGROUPID 1024\r
-#define FIRSTIPCLASS 2048\r
+#define STRLEN 512\r
 #undef DEBUG\r
 \r
 #include "cll1-0.6.2.h"\r
+#include "ipstruct.h"\r
 \r
-const char *version = "0.8.3-f";\r
+const char *version = "0.8.3-g";\r
 \r
 /* Version numbers: 0.8.3 is development releases ("beta"), 0.8.4 will be "stable" */\r
 /* Debian(RPM) package versions/patchlevels: 0.7.9-2, 0.8.0-1, 0.8.0-2, etc. */\r
@@ -57,8 +56,9 @@ char    *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for
 char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
 char        *classmap = "/var/lib/misc/prometheus.classes"; /* credit log file */\r
 char            *html = "/var/www/traffic.html"; /* hall of fame - html version */\r
-char         *preview = "/var/www/preview.html"; /* hall of fame preview */\r
+char         *preview = "/var/www/preview.html"; /* hall of fame preview - html version */\r
 char            *json = "/var/www/logs/traffic.json"; /* hall of fame - json version */\r
+char    *json_preview = "/var/www/logs/preview.json"; /* hall of fame preview - json version */\r
 char          *cmdlog = "/var/log/prometheuslog"; /* command log filename */\r
 char         *log_dir = "/var/www/logs/"; /* log directory pathname, ended with slash */\r
 char         *log_url = "/logs/"; /* log directory relative URI prefix (partial URL) */\r
@@ -70,6 +70,12 @@ int use_jquery_popups = 1;
 int      row_odd_even = 0; /*<tr class="odd/even"> */\r
 \r
 \r
+void parse_ip_log(int argc, char **argv);\r
+/* implementid in parselog.c */\r
+\r
+void parse_hosts(char *hosts);\r
+/* implementid in parsehosts.c */\r
+\r
 const char *tr_odd_even(void)\r
 {\r
  row_odd_even = 1 - row_odd_even;\r
@@ -142,6 +148,8 @@ int         burst_main = 64;
 int        burst_group = 32;\r
 int     magic_treshold = 8; /* reduce ceil by X*magic_treshhold kbps (hard shaping) */\r
 int       keywordcount = 0;\r
+int class_count        = 0;\r
+int ip_count           = 0;\r
 /* not yet implemented:\r
 int      fixed_packets = 0; maximum number of pps per IP address (not class!) \r
 int       packet_limit = 5; maximum number of pps to htn CEIL, not rate !!! \r
@@ -156,40 +164,11 @@ const int idxtable_treshold2 = 12;      /* this is no longer configurable */
 const int idxtable_bitmask1  = 3;        /* this is no longer configurable */\r
 const int idxtable_bitmask2  = 3;        /* this is no longer configurable */\r
 \r
-/* ==== This is C<<1 stuff - learn C<<1 first! https://dev.arachne.cz/svn/cll1h ==== */\r
+struct IP *ips = NULL, *ip, *sharedip;\r
+struct Group *groups = NULL, *group;\r
+struct Keyword *keyword, *defaultkeyword=NULL, *keywords=NULL;\r
 \r
-struct IP\r
-{\r
- char *addr;\r
- char *name;\r
- char *sharing;\r
- int min;\r
- int desired;\r
- int max;\r
- int mark;\r
- int prio;\r
- int fixedprio;\r
- int group;\r
- int lmsid;\r
- unsigned long long direct;\r
- unsigned long long proxy;\r
- unsigned long long upload;\r
- unsigned long long traffic;\r
- unsigned long long credit;\r
- unsigned long pktsup;\r
- unsigned long pktsdown;\r
- struct Keyword *keyword;\r
- list(IP);\r
-} *ips=NULL, *ip, *sharedip;\r
-\r
-struct Group\r
-{\r
- int min;\r
- int count;\r
- int desired;\r
- int id;\r
- list(Group);\r
-} *groups=NULL, *group;\r
+/* ==== This is C<<1 stuff - learn C<<1 first! https://dev.arachne.cz/svn/cll1h ==== */\r
 \r
 struct Index\r
 {\r
@@ -201,53 +180,10 @@ struct Index
  list(Index);\r
 } *idxs=NULL, *idx, *metaindex;\r
 \r
-struct Keyword\r
-{\r
- char *key;\r
\r
- int asymetry_ratio;        /* ratio for ADSL-like upload */\r
- int asymetry_fixed;        /* fixed treshold for ADSL-like upload */\r
- int data_limit;            /* hard shaping: apply magic_treshold if max*data_limit MB exceeded */\r
- int data_prio;             /* soft shaping (qos): reduce HTB prio if max*data_prio MB exceeded */\r
- long fixed_limit;          /* fixed data limit for setting lower HTB ceil */\r
- long fixed_prio;           /* fixed data lmit for setting lower HTB prio */\r
- int reserve_min;          /* bonus for nominal HTB rate bandwidth (in kbps) */\r
- int reserve_max;          /* malus for nominal HTB ceil (in kbps) */\r
-// int divide_max;         /* relative malus: new_ceil=rate+(old_ceil-rate)/divide_max */\r
-// int htb_ceil_bonus_divide; /* relative bonus: new_ceil=old_ceil+old_ceil/htb_ceil_bonus_divide */\r
- int default_prio;         /* default HTB priority for this keyword */\r
- char *html_color;\r
- int ip_count;\r
- char *leaf_discipline;\r
\r
- list(Keyword);\r
-} *keyword,*defaultkeyword=NULL,*keywords=NULL;\r
 \r
-/* Damned, this must be object oriented! This looks almost like constructor ;-) */\r
 \r
-void TheIP(void)\r
-{\r
- create(ip,IP);\r
- ip->name        = "";\r
- ip->addr        = "";\r
- ip->sharing     = NULL;\r
- ip->prio        = highest_priority+1;\r
- ip->lmsid       = -1;\r
- ip->fixedprio   = \\r
- ip->mark        = \\r
- ip->min         = \\r
- ip->max         = \\r
- ip->desired     = \\r
- ip->credit      = \\r
- ip->upload      = \\r
- ip->proxy       = \\r
- ip->direct      = \\r
- ip->traffic     = \\r
- ip->pktsup      = \\r
- ip->pktsdown    = 0;\r
- ip->keyword     = keywords;\r
- push(ip,ips);\r
-}\r
+void TheIP(void);\r
+/* function implemented in parsehosts.c */\r
 \r
 /* ====== iptables indexes are used to reduce complexity to log8(N) ===== */\r
 \r
@@ -439,6 +375,7 @@ void get_config(char *config_filename)
   option("hall-of-fame-filename",html);\r
   option("json-filename",json);\r
   option("hall-of-fame-preview",preview);\r
+  option("json-preview",json_preview);\r
   option("log-filename",cmdlog);\r
   option("credit-filename",credit);\r
   option("classmap-filename",classmap);\r
@@ -707,57 +644,6 @@ void run_restore(void)
  free(restor);\r
 }\r
 \r
-/* == This function strips extra characters after IP address and stores it = */\r
-\r
-void parse_ip(char *str)\r
-{\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
-  {\r
-   ptr++;\r
-  }\r
-  *ptr=0;\r
- }\r
\r
- ptr=str;\r
- while(*ptr && *ptr!=' ' && *ptr!=9)\r
- {\r
-  ptr++;\r
- }\r
\r
- *ptr=0;\r
- ipaddr=str;\r
- ptr++;\r
- while(*ptr && (*ptr==' ' || *ptr==9))\r
- {\r
-  ptr++;\r
- }\r
- ipname=ptr; \r
- while(*ptr && *ptr!=' ' && *ptr!=9)\r
- {\r
-  ptr++;\r
- }\r
- *ptr=0;\r
-\r
- if_exists(ip,ips,eq(ip->addr,ipaddr));\r
- else\r
- {\r
-  TheIP();\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
  char *ptr=strchr(str,' ');\r
@@ -774,284 +660,6 @@ char *parse_datafile_line(char *str)
  }\r
 }\r
 \r
-struct IpLog\r
-{\r
- char *name;\r
- long traffic;\r
- long guaranted;\r
- int i;\r
- int lmsid;\r
- long l;\r
- list(IpLog);\r
-} *iplog,*iplogs;\r
-\r
-void parse_ip_log(int argc, char **argv) \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, lmsid;\r
- char mstr[4], ystr[5];\r
- FILE *f; \r
- string(str,STRLEN);\r
- string(filename,STRLEN);\r
-\r
- if(argv[1][1]=='l') /* -l */\r
- {\r
-  if(argc<4)\r
-  {\r
-   puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)");\r
-   exit(-1);\r
-  }\r
-  else\r
-  {\r
-   month=argv[2];\r
-   if(eq(month,"Year")) any_month=1;\r
-   year=argv[3];\r
-  }\r
- }\r
- else\r
- { \r
-  time_t t = time(NULL) - 3600*24 ; /* yesterday's timestamp*/\r
-  struct tm *timep = localtime(&t);                                           \r
-\r
-  if(argv[1][1]=='m') /* -m yestarday - month */\r
-  {\r
-   strftime(mstr, 4, "%b", timep);\r
-   month=mstr;\r
-   strftime(ystr, 5, "%Y", timep);\r
-   year=ystr; \r
-  }\r
-  else /* -y yesterday - year */\r
-  {\r
-   month="Year";\r
-   any_month=1;\r
-   strftime(ystr, 5, "%Y", timep);\r
-   year=ystr;\r
-  }\r
- }\r
- printf("Analysing traffic for %s %s ...\n",month,year);\r
-\r
- /* sorry... next release of C<<1 header file will include for_path_files(name,path) {  } macro */\r
- sprintf(str,"%s %s/",ls,log_dir);\r
- shell(str);\r
- input(str,STRLEN) \r
- {\r
-  if(strstr(str,".log"))\r
-  {\r
-    ptr=strrchr(str,'\n');\r
-    if(ptr) *ptr='\0';\r
-    sprintf(filename,"%s/%s",log_dir,str);\r
-    printf("Parsing %s ...",filename);\r
-    accept_month=0;\r
-    traffic_month=0;\r
-    guaranted=0;\r
-    lmsid=-1;\r
-    parse(filename)\r
-    {\r
-     y_ok=m_ok=0;  \r
-     valid_columns(ptr,_,'\t',col) switch(col)\r
-     {\r
-      case 2: name = ptr;break;\r
-      case 3: traffic = atol(ptr);break;\r
-      /* column number   - was 7, now 11...*/\r
-      case 7:\r
-      case 8:\r
-      case 9:\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
-                 case 2: if(any_month || eq(ptr2,month)) m_ok = 1; break;\r
-                 case 5: if(eq(ptr2,year)) y_ok = 1; break;\r
-                }\r
-               }\r
-               else\r
-               {\r
-                 if(col == 7) guaranted = atol(ptr);\r
-                 if(col == 10) lmsid = atoi(ptr);\r
-               }\r
-     }\r
-     \r
-     if(y_ok && m_ok) \r
-     {\r
-      traffic_month += traffic;\r
-      accept_month = 1;\r
-     }\r
-    }\r
-    done; /* ugly macro end */ \r
-\r
-    if(accept_month)\r
-    {\r
-     create(iplog,IpLog);\r
-     iplog->name = name;\r
-     iplog->guaranted = guaranted;\r
-     iplog->traffic = traffic_month;\r
-     iplog->lmsid = lmsid;\r
-     insert(iplog,iplogs,desc_order_by,traffic);\r
-     printf(" %ld MB\n",iplog->traffic);\r
-    }\r
-    else\r
-    {\r
-     puts(" no records.");\r
-    }\r
-  }\r
- }\r
- sprintf(str,"%s/%s-%s.html",html_log_dir,year,month);\r
- printf("Writing %s ... ",str);\r
- f=fopen(str,"w");\r
- if(f > 0)\r
- {\r
-  fprintf(f, "<table class=\"decorated last\"><thead>\n\\r
-<tr><th colspan=\"2\">%s %s</th>\n\\r
-<th style=\"text-align: right\">lms</th>\n\\r
-<th colspan=\"2\">Data transfers</th>\n\\r
-<th style=\"text-align: right\">Min.speed</th>\n\\r
-</tr></thead><tbody>\n ",\r
-             month, year);\r
-\r
-  row_odd_even = 0;\r
-  for_each(iplog, iplogs)\r
-  {\r
-   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\" 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\" target=\"_blank\" href=\"%s%d\">%04d</a>\n", lms_url, iplog->lmsid, iplog->lmsid);\r
-    }\r
-    else if(iplog->lmsid == 0)\r
-    {\r
-     fputs("-------",f);\r
-    }    \r
-    fprintf(f, "<td style=\"text-align: right\">%ld&nbsp;MB</td>\n\\r
-    <td style=\"text-align: right\"><strong>%ld&nbsp;GB</strong></td>\n\\r
-    <td style=\"text-align: right\">%ld&nbsp;kb/s</th></tr>\n",\r
-               iplog->traffic, iplog->traffic>>10, iplog->guaranted);\r
-    total+=iplog->traffic>>10;\r
-    iplog->i=i;\r
-    iplog->l=total;\r
-   }\r
-  }\r
-  fprintf(f,"</tbody><thead><tr>\\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
-  if(i>10)\r
-  {\r
-   fputs("<a name=\"erp\"></a><p><table class=\"decorated last\">\n\\r
-<caption>Enterprise Resource Planning (ERP)</caption>\n\\r
-<thead><tr>\n\\r
-<th>Analytic category</th>\n\\r
-<th colspan=\"2\" style=\"text-align: center\">Active Classes</th>\n\\r
-<th colspan=\"2\" style=\"text-align: center\">Data transfers</th>\n\\r
-</tr></thead><tbody>\n",f);\r
-\r
-   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>\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
-   {\r
-    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 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
-   }\r
-\r
-   if_exists(iplog,iplogs,iplog->l>=total/2)\r
-   {\r
-    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 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
-\r
-   if_exists(iplog,iplogs,iplog->l>=4*total/5)\r
-   {\r
-    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 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
-\r
-   if_exists (iplog,iplogs,iplog->i>=i/5)\r
-   {\r
-    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 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/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>\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
-   {\r
-    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 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>\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><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 GB</th>\n\\r
-<th style=\"text-align: right\">100 %%</th></tr>\n",i-1,total);\r
-   fputs("</thead></table>\n", f);\r
-  }\r
-\r
-  fprintf(f, stats_html_signature, version);\r
-  fclose(f);\r
-  puts("done.");\r
- }\r
- else\r
- {\r
-  perror(str);\r
- }\r
-}\r
-\r
 void append_log(struct IP *self) /*using global variables*/\r
 {\r
  char *d, *str;\r
@@ -1074,7 +682,6 @@ void append_log(struct IP *self) /*using global variables*/
  }\r
 }\r
 \r
-\r
 /*-----------------------------------------------------------------*/\r
 /* Are you looking for int main(int argc, char **argv) ? :-))      */\r
 /*-----------------------------------------------------------------*/\r
@@ -1085,7 +692,7 @@ program
  FILE *f=NULL;               /* everything is just stream of bytes... */\r
  char *str, *ptr, *d;        /* LET A$=B$ :-) */\r
  char *substring;\r
- int class_count=0,ip_count=0;\r
+\r
  int parent=1;\r
  int just_flush=FALSE;       /* deactivates all previous actions */\r
  int nodelay=FALSE;\r
@@ -1164,107 +771,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  /*-----------------------------------------------------------------*/\r
  printf("Parsing class defintion file %s ...\n", hosts);\r
  /*-----------------------------------------------------------------*/\r
- int groupidx = FIRSTGROUPID;\r
- parse(hosts)\r
- {\r
-  str=_;\r
-\r
-  if(*str<'0' || *str>'9')\r
-  {\r
-   /* any line starting with non-number is comment ...*/\r
-   continue;\r
-  }\r
-  \r
-  //Does this IP share QoS class with some other ?\r
-  substring=strstr(str,"sharing-");\r
-  if(substring)\r
-  { \r
-   substring+=8; //"sharing-"\r
-   parse_ip(str);\r
-   ip_count++;\r
-   ip->sharing=substring;\r
-   ip->keyword=defaultkeyword; /* settings for default keyword */\r
-   while(*substring && *substring!='\n')\r
-   {\r
-    substring++;\r
-   }\r
-   *substring=0; \r
-  }\r
-  else\r
-  {\r
-   //Do we have to create new QoS class for this IP ?\r
-\r
-   if_exists(keyword,keywords,(substring=strstr(str,keyword->key)))\r
-   {\r
-    parse_ip(str);\r
-    ip_count++;\r
-    ip->keyword=keyword;\r
-    keyword->ip_count++;\r
-    ip->prio=keyword->default_prio;\r
-    substring+=strlen(keyword->key)+1;\r
-    ptr=substring;\r
-    while(*ptr && *ptr!='-')\r
-    {\r
-     ptr++;\r
-    }\r
-    if(*ptr=='-')\r
-    {\r
-     *ptr=0;\r
-     ip->max = ip->desired=atoi(ptr+1);\r
-    }\r
-    ip->min = atoi(substring);\r
-    if(ip->min <= 0)\r
-    {\r
-     printf(" %s: Illegal value of minimum bandwidth 0 kbps, using %d kb/s\n",\r
-            str, free_min);\r
-     ip->min = free_min;\r
-    }\r
-    if(ip->max <= ip->min)\r
-    {\r
-     ip->fixedprio = 1;\r
-     ip->max = ip->min+ip->keyword->reserve_min;\r
-    }\r
-    else \r
-    {\r
-     ip->max -= ip->keyword->reserve_max;\r
-     if(ip->max<ip->min)\r
-     {\r
-      ip->max=ip->min;\r
-     }\r
-    }\r
-    ip->mark=FIRSTIPCLASS+1+class_count++;\r
-\r
-    if_exists(group,groups,group->min==ip->min) \r
-    { \r
-     group->count++;      \r
-     group->desired += ip->min;\r
-     ip->group = group->id;   \r
-    }\r
-    else\r
-    {\r
-     create(group,Group);\r
-     group->min = ip->min;\r
-     group->id = groupidx++;\r
-     ip->group = group->id;\r
-\r
-     if(group->min<8) group->min=8;\r
-     /* Warning - this is maybe because of primitive tc namespace, can be fixed */\r
-     /* it is because class IDs are derived from min. bandwidth. - xCh */\r
-     //if(group->min>MAX_GUARANTED_KBPS) group->min=MAX_GUARANTED_KBPS;\r
-     \r
-     group->count=1;\r
-     group->desired=ip->min;   \r
-     insert(group,groups,desc_order_by,min);\r
-    }\r
-   }//endif keyword-\r
-  }//endif sharing-\r
- }\r
- fail\r
- {\r
-  perror(hosts);\r
-  exit(-1);\r
- }\r
- done; /* ugly macro end */\r
+ parse_hosts(hosts);\r
 \r
  /*-----------------------------------------------------------------*/\r
  /* cll1.h - let's allocate brand new character buffer...           */\r
@@ -1284,7 +791,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    ip->lmsid=sharedip->lmsid;\r
    break;\r
   }\r
-  if(!sharedip)\r
+  if(not sharedip)\r
   {\r
    printf("Unresolved shared connection: %s %s sharing-%s\n",\r
           ip->addr, ip->name, ip->sharing);\r
@@ -1352,11 +859,11 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    if(qos_proxy)\r
    {\r
     save_line(":post_noproxy - [0:0]");\r
-    sprintf(str,"-A POSTROUTING -p ! tcp -o %s -j post_noproxy", lan);\r
+    sprintf(str,"-A POSTROUTING ! -p tcp -o %s -j post_noproxy", lan);\r
     save_line(str);   \r
-    sprintf(str,"-A POSTROUTING -s ! %s -o %s -j post_noproxy", proxy_ip, lan);\r
+    sprintf(str,"-A POSTROUTING ! -s %s -o %s -j post_noproxy", proxy_ip, lan);\r
     save_line(str);   \r
-    sprintf(str,"-A POSTROUTING -s %s -p tcp --sport ! %d -o %s -j post_noproxy", proxy_ip, proxy_port, lan);\r
+    sprintf(str,"-A POSTROUTING -s %s -p tcp ! --sport %d -o %s -j post_noproxy", proxy_ip, proxy_port, lan);\r
     save_line(str);   \r
 \r
     chain="post_noproxy";    \r
@@ -1673,13 +1180,14 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    }\r
    done; /* ugly macro end */\r
   }\r
-  f=fopen(preview,"w");\r
-  ptr=preview; \r
+  html=preview;\r
+  json=json_preview;\r
  }\r
- else if(!dry_run && !just_flush)\r
+\r
+ if(!dry_run && !just_flush)\r
  {\r
   /*-----------------------------------------------------------------*/\r
-  printf("Writing daily statistics  %s ... ", json);\r
+  printf("Writing json overview  %s ... ", json);\r
   /*-----------------------------------------------------------------*/\r
   f=fopen(json, "w");\r
   if(f > 0)\r
@@ -1695,8 +1203,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      {\r
       fprintf(f, ",\n");\r
      }\r
-     fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu }",\r
-                ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload);\r
+     fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d }",\r
+                ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload, ip->min, ip->desired, ip->max);\r
      jsoncount++;\r
     }\r
    }\r
@@ -1708,17 +1216,16 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   {\r
    perror(json);\r
   }\r
-  f=fopen(html,"w");\r
-  ptr=html;\r
  }\r
 \r
- if(f)\r
+ f=fopen(html,"w");\r
+ if(f > 0)\r
  {\r
   int count=1;\r
   i=0;\r
 \r
   /*-----------------------------------------------------------------*/\r
-  printf("Sorting data and generating statistics page %s ...\n", ptr);\r
+  printf("Sorting data and generating statistics page %s ...\n", html);\r
   /*-----------------------------------------------------------------*/\r
 \r
   if(use_jquery_popups)\r
@@ -1779,7 +1286,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  }\r
 \r
  i=0;\r
- if(f)\r
+ if(f > 0)\r
  {\r
   unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0;\r
   int active_classes=0;\r
@@ -2226,7 +1733,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      safe_run(str);\r
    }\r
   \r
-   if(f)\r
+   if(f > 0)\r
    {\r
      fprintf(f, "%s %d\n", ip->addr, ip->mark);\r
    }\r
@@ -2239,7 +1746,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   }\r
   i++;\r
  }\r
- if(f)\r
+ if(f > 0)\r
  {\r
   puts("done.");\r
   fclose(f);\r
This page took 0.372831 seconds and 4 git commands to generate.