more modularization
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 11 Oct 2012 21:29:38 +0000 (21:29 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 11 Oct 2012 21:29:38 +0000 (21:29 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@201 251d49ef-1d17-4917-a970-b30cf55b089b

Makefile
prometheus.c

index 7fcedc2e2de32a464160e6aa0ccfbd8dd03b4c05..439c7ac6972384cefb3a57ee38da9978bf5a5249 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ prefix=/usr
 mandir=$(prefix)/share/man
 sbindir=$(prefix)/sbin
 sysconfdir=/etc
-OBJECTS=parsehosts.o parselogs.o ipv4subnets.o prometheus.o
+OBJECTS=parsehosts.o parselogs.o ipv4subnets.o json.o prometheus.o
 HEADERS=cll1-0.6.2.h ipstruct.h
 
 main: prometheus
index beaffcb78b2b4266e82ff7a14dbce57b312a0b8e..814da9e4cb0fe9de6527fb98ad4e216d357961ba 100644 (file)
@@ -80,7 +80,7 @@ char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */
 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 - html version */\r
-char            *json = "/var/www/logs/traffic.json"; /* hall of fame - json version */\r
+char    *json_traffic = "/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
@@ -149,10 +149,13 @@ struct Group *groups = NULL, *group;
 struct Keyword *keyword, *defaultkeyword=NULL, *keywords=NULL;\r
 \r
 void parse_ip_log(int argc, char **argv);\r
-/* implementid in parselog.c */\r
+/* implemented in parselog.c */\r
 \r
 void parse_hosts(char *hosts);\r
-/* implementid in parsehosts.c */\r
+/* implemented in parsehosts.c */\r
+\r
+void write_json_traffic(char *json);\r
+/* implemented in json.c */\r
 \r
 const char *tr_odd_even(void)\r
 {\r
@@ -278,7 +281,7 @@ void get_config(char *config_filename)
   ioption("hall-of-fame-enable",hall_of_fame);\r
   option("hall-of-fame-title",title);\r
   option("hall-of-fame-filename",html);\r
-  option("json-filename",json);\r
+  option("json-filename",json_traffic);\r
   option("hall-of-fame-preview",preview);\r
   option("json-preview",json_preview);\r
   option("log-filename",cmdlog);\r
@@ -1086,41 +1089,15 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    done; /* ugly macro end */\r
   }\r
   html=preview;\r
-  json=json_preview;\r
+  json_traffic=json_preview;\r
  }\r
 \r
  if(!dry_run && !just_flush)\r
  {\r
   /*-----------------------------------------------------------------*/\r
-  printf("Writing json overview  %s ... ", json);\r
+  printf("Writing json traffic overview  %s ... ", json_traffic);\r
   /*-----------------------------------------------------------------*/\r
-  f=fopen(json, "w");\r
-  if(f > 0)\r
-  {\r
-   int jsoncount=0;\r
-   fprintf(f, "{\n");\r
-   for_each(ip, ips)\r
-   {\r
-    if(     ip->lmsid > 0 \r
-        && (ip->traffic || ip->direct || ip->proxy || ip->upload))\r
-    {\r
-     if(jsoncount)\r
-     {\r
-      fprintf(f, ",\n");\r
-     }\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
-   fprintf(f, "}\n");\r
-   fclose(f);\r
-   puts("done.");\r
-  }\r
-  else\r
-  {\r
-   perror(json);\r
-  }\r
+  write_json_traffic(json_traffic);\r
  }\r
 \r
  f=fopen(html,"w");\r
This page took 0.245696 seconds and 4 git commands to generate.