From 129d26475e30ff1ea20c3501e5069ecbb48d1752 Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Wed, 2 Dec 2020 20:08:03 +0300 Subject: [PATCH] Fixed: counters incorectly shown in webadmin, contall/nocountall are not applied --- src/auth.c | 26 ++++++++++++++----------- src/conf.c | 2 +- src/datatypes.c | 29 ++++------------------------ src/webadmin.c | 50 ++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 63 insertions(+), 44 deletions(-) diff --git a/src/auth.c b/src/auth.c index 5e0072f..73211c0 100644 --- a/src/auth.c +++ b/src/auth.c @@ -606,17 +606,18 @@ void trafcountfunc(struct clientparam *param){ for(tc = conf.trafcounter; tc; tc = tc->next) { if(ACLmatches(tc->ace, param)){ time_t t; - if(tc->ace->action == NOCOUNTIN || tc->ace->action == NOCOUNTALL) { + + if(tc->ace->action == NOCOUNTIN) { countout = 1; break; } - if(tc->ace->action != COUNTIN) { + if(tc->ace->action == NOCOUNTALL) break; + if(tc->ace->action != COUNTIN && tc->ace->action != COUNTALL) { countout = 1; - if(tc->ace->action != COUNTALL)continue; + continue; } tc->traf64 += param->statssrv64; - time(&t); - tc->updated = t; + tc->updated = conf.time; } } if(countout) for(tc = conf.trafcounter; tc; tc = tc->next) { @@ -627,8 +628,7 @@ void trafcountfunc(struct clientparam *param){ continue; } tc->traf64 += param->statscli64; - time(&t); - tc->updated = t; + tc->updated = conf.time; } } @@ -655,10 +655,14 @@ int alwaysauth(struct clientparam * param){ for(tc = conf.trafcounter; tc; tc = tc->next) { if(tc->disabled) continue; if(ACLmatches(tc->ace, param)){ - if(tc->ace->action == NOCOUNTIN) break; + if(tc->ace->action == NOCOUNTIN) { + countout = 1; + break; + } + if(tc->ace->action == NOCOUNTALL) break; if(tc->ace->action != COUNTIN) { countout = 1; - continue; + if(tc->ace->action != COUNTALL) continue; } if(tc->traflim64 <= tc->traf64) return 10; param->trafcountfunc = conf.trafcountfunc; @@ -668,8 +672,8 @@ int alwaysauth(struct clientparam * param){ if(countout)for(tc = conf.trafcounter; tc; tc = tc->next) { if(tc->disabled) continue; if(ACLmatches(tc->ace, param)){ - if(tc->ace->action == NOCOUNTOUT) break; - if(tc->ace->action != COUNTOUT) { + if(tc->ace->action == NOCOUNTOUT || tc->ace->action == NOCOUNTALL) break; + if(tc->ace->action != COUNTOUT && tc->ace->action != COUNTALL) { continue; } if(tc->traflim64 <= tc->traf64) return 10; diff --git a/src/conf.c b/src/conf.c index e5d2065..4a0c04b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -404,7 +404,6 @@ static int h_archiver(int argc, unsigned char **argv){ static int h_counter(int argc, unsigned char **argv){ struct counter_header ch1; if(conf.counterd >=0)close(conf.counterd); - if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc; conf.counterd = open((char *)argv[1], O_BINARY|O_RDWR|O_CREAT, 0660); if(conf.counterd<0){ fprintf(stderr, "Unable to open counter file %s, line %d\n", argv[1], linenum); @@ -1239,6 +1238,7 @@ static int h_ace(int argc, unsigned char **argv){ case NOCOUNTOUT: case COUNTALL: case NOCOUNTALL: + if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc; tl = myalloc(sizeof(struct trafcount)); if(!tl) { return(21); diff --git a/src/datatypes.c b/src/datatypes.c index 6613299..fb304ed 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -365,32 +365,11 @@ static void * ef_ace_next(struct node * node){ return ((struct ace *)node->value) -> next; } + +char * aceaction (int action); + static void * ef_ace_type(struct node * node){ - switch (((struct ace *)node->value) -> action) { - case ALLOW: - case REDIRECT: - return "allow"; - case DENY: - return "deny"; - case BANDLIM: - return "bandlim"; - case NOBANDLIM: - return "nobandlim"; - case COUNTIN: - return "countin"; - case NOCOUNTIN: - return "nocountin"; - case COUNTOUT: - return "countout"; - case NOCOUNTOUT: - return "nocountout"; - case COUNTALL: - return "countall"; - case NOCOUNTALL: - return "nocountall"; - default: - return "unknown"; - } + return aceaction(((struct ace *)node->value) -> action); } diff --git a/src/webadmin.c b/src/webadmin.c index 8f29481..936ef2a 100644 --- a/src/webadmin.c +++ b/src/webadmin.c @@ -16,12 +16,43 @@ extern FILE *writable; FILE * confopen(); extern void decodeurl(unsigned char *s, int filter); + + struct printparam { char buf[1024]; int inbuf; struct clientparam *cp; }; +char * aceaction (int action){ + switch (action) { + case ALLOW: + case REDIRECT: + return "allow"; + case DENY: + return "deny"; + case BANDLIM: + return "bandlim"; + case NOBANDLIM: + return "nobandlim"; + case COUNTIN: + return "countin"; + case NOCOUNTIN: + return "nocountin"; + case COUNTOUT: + return "countout"; + case NOCOUNTOUT: + return "nocountout"; + case COUNTALL: + return "countall"; + case NOCOUNTALL: + return "nocountall"; + default: + return "unknown"; + } +} + + static void stdpr(struct printparam* pp, char *buf, int inbuf){ if((pp->inbuf + inbuf > 1024) || !buf) { socksend(pp->cp->clisock, (unsigned char *)pp->buf, pp->inbuf, conf.timeouts[STRING_S]); @@ -260,11 +291,11 @@ char * admin_stringtable[]={ "

Counters

\r\n" "\r\n" - "" + "" "" "" "" - "\r\n", + "\r\n", "
DescriptionActive
Action#/DescActiveUsersSource AddressDestination AddressPortLimitUnitsValueResetUpdatedNum
ResetUpdatedPosition
\r\n", @@ -433,9 +464,14 @@ void * adminchild(struct clientparam* param) { } if(req[1] == 'S' && atoi(req+2) == num) cp->disabled=0; if(req[1] == 'D' && atoi(req+2) == num) cp->disabled=1; - inbuf += sprintf(buf, "" - "%s%s", - (cp->comment)?cp->comment:" ", + inbuf += sprintf(buf, "%s", cp->ace?aceaction(cp->ace->action):"-"); + if(cp->number || cp->comment) + inbuf += sprintf(buf+inbuf, "%d/%s" , cp->number, + (cp->comment)?cp->comment:" "); + else + inbuf += sprintf(buf+inbuf, " - "); + + inbuf += sprintf(buf+inbuf, "%s", (cp->disabled)?'S':'D', num, (cp->disabled)?"NO":"YES" @@ -467,7 +503,7 @@ void * adminchild(struct clientparam* param) { else { inbuf += printportlist(buf+inbuf, LINESIZE-128, cp->ace->ports, ",
\r\n"); } - if(cp->type == NONE) { + if(cp->ace && (cp->ace->action == NOCOUNTIN || cp->ace->action == NOCOUNTOUT || cp->ace->action == NOCOUNTALL)) { inbuf += sprintf(buf+inbuf, "exclude from limitation\r\n" ); @@ -543,7 +579,7 @@ void * adminchild(struct clientparam* param) { error = 1; } while(l < contentlen && (i = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, (contentlen - l) > LINESIZE - 1?LINESIZE - 1:contentlen - l, '+', conf.timeouts[STRING_S])) > 0){ - if(i > (contentlen - l)) i = (contentlen - l); + if((unsigned)i > (contentlen - l)) i = (contentlen - l); if(!l){ if(i<9 || strncasecmp(buf, "conffile=", 9)) error = 1; }