From 1ab008b9af1556f1bcba85b2d262fa83b617f01e Mon Sep 17 00:00:00 2001 From: xchaos Date: Thu, 11 Oct 2012 21:29:38 +0000 Subject: [PATCH] more modularization git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@201 251d49ef-1d17-4917-a970-b30cf55b089b --- Makefile | 2 +- prometheus.c | 43 ++++++++++--------------------------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 7fcedc2..439c7ac 100644 --- 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 diff --git a/prometheus.c b/prometheus.c index beaffcb..814da9e 100644 --- a/prometheus.c +++ b/prometheus.c @@ -80,7 +80,7 @@ char *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */ char *classmap = "/var/lib/misc/prometheus.classes"; /* credit log file */ char *html = "/var/www/traffic.html"; /* hall of fame - html version */ char *preview = "/var/www/preview.html"; /* hall of fame preview - html version */ -char *json = "/var/www/logs/traffic.json"; /* hall of fame - json version */ +char *json_traffic = "/var/www/logs/traffic.json"; /* hall of fame - json version */ char *json_preview = "/var/www/logs/preview.json"; /* hall of fame preview - json version */ char *cmdlog = "/var/log/prometheuslog"; /* command log filename */ char *log_dir = "/var/www/logs/"; /* log directory pathname, ended with slash */ @@ -149,10 +149,13 @@ struct Group *groups = NULL, *group; struct Keyword *keyword, *defaultkeyword=NULL, *keywords=NULL; void parse_ip_log(int argc, char **argv); -/* implementid in parselog.c */ +/* implemented in parselog.c */ void parse_hosts(char *hosts); -/* implementid in parsehosts.c */ +/* implemented in parsehosts.c */ + +void write_json_traffic(char *json); +/* implemented in json.c */ const char *tr_odd_even(void) { @@ -278,7 +281,7 @@ void get_config(char *config_filename) ioption("hall-of-fame-enable",hall_of_fame); option("hall-of-fame-title",title); option("hall-of-fame-filename",html); - option("json-filename",json); + option("json-filename",json_traffic); option("hall-of-fame-preview",preview); option("json-preview",json_preview); option("log-filename",cmdlog); @@ -1086,41 +1089,15 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version); done; /* ugly macro end */ } html=preview; - json=json_preview; + json_traffic=json_preview; } if(!dry_run && !just_flush) { /*-----------------------------------------------------------------*/ - printf("Writing json overview %s ... ", json); + printf("Writing json traffic overview %s ... ", json_traffic); /*-----------------------------------------------------------------*/ - f=fopen(json, "w"); - if(f > 0) - { - int jsoncount=0; - fprintf(f, "{\n"); - for_each(ip, ips) - { - if( ip->lmsid > 0 - && (ip->traffic || ip->direct || ip->proxy || ip->upload)) - { - if(jsoncount) - { - fprintf(f, ",\n"); - } - fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d }", - ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload, ip->min, ip->desired, ip->max); - jsoncount++; - } - } - fprintf(f, "}\n"); - fclose(f); - puts("done."); - } - else - { - perror(json); - } + write_json_traffic(json_traffic); } f=fopen(html,"w"); -- 2.30.2