Przeglądaj źródła

Fixed: counters incorectly shown in webadmin, contall/nocountall are not applied

z3APA3A 5 lat temu
rodzic
commit
935629e261
4 zmienionych plików z 63 dodań i 44 usunięć
  1. 15 11
      src/auth.c
  2. 1 1
      src/conf.c
  3. 4 25
      src/datatypes.c
  4. 43 7
      src/webadmin.c

+ 15 - 11
src/auth.c

@@ -606,17 +606,18 @@ void trafcountfunc(struct clientparam *param){
 	for(tc = conf.trafcounter; tc; tc = tc->next) {
 	for(tc = conf.trafcounter; tc; tc = tc->next) {
 		if(ACLmatches(tc->ace, param)){
 		if(ACLmatches(tc->ace, param)){
 			time_t t;
 			time_t t;
-			if(tc->ace->action == NOCOUNTIN || tc->ace->action == NOCOUNTALL) {
+
+			if(tc->ace->action == NOCOUNTIN) {
 				countout = 1;
 				countout = 1;
 				break;
 				break;
 			}
 			}
-			if(tc->ace->action != COUNTIN) {
+			if(tc->ace->action == NOCOUNTALL) break;
+			if(tc->ace->action != COUNTIN && tc->ace->action != COUNTALL) {
 				countout = 1;
 				countout = 1;
-				if(tc->ace->action != COUNTALL)continue;
+				continue;
 			}
 			}
 			tc->traf64 += param->statssrv64;
 			tc->traf64 += param->statssrv64;
-			time(&t);
-			tc->updated = t;
+			tc->updated = conf.time;
 		}
 		}
 	}
 	}
 	if(countout) for(tc = conf.trafcounter; tc; tc = tc->next) {
 	if(countout) for(tc = conf.trafcounter; tc; tc = tc->next) {
@@ -627,8 +628,7 @@ void trafcountfunc(struct clientparam *param){
 				continue;
 				continue;
 			}
 			}
 			tc->traf64 += param->statscli64;
 			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) {
 			for(tc = conf.trafcounter; tc; tc = tc->next) {
 				if(tc->disabled) continue;
 				if(tc->disabled) continue;
 				if(ACLmatches(tc->ace, param)){
 				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) {
 					if(tc->ace->action != COUNTIN) {
 						countout = 1;
 						countout = 1;
-						continue;
+						if(tc->ace->action != COUNTALL) continue;
 					}
 					}
 					if(tc->traflim64 <= tc->traf64) return 10;
 					if(tc->traflim64 <= tc->traf64) return 10;
 					param->trafcountfunc = conf.trafcountfunc;
 					param->trafcountfunc = conf.trafcountfunc;
@@ -668,8 +672,8 @@ int alwaysauth(struct clientparam * param){
 			if(countout)for(tc = conf.trafcounter; tc; tc = tc->next) {
 			if(countout)for(tc = conf.trafcounter; tc; tc = tc->next) {
 				if(tc->disabled) continue;
 				if(tc->disabled) continue;
 				if(ACLmatches(tc->ace, param)){
 				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;
 						continue;
 					}
 					}
 					if(tc->traflim64 <= tc->traf64) return 10;
 					if(tc->traflim64 <= tc->traf64) return 10;

+ 1 - 1
src/conf.c

@@ -308,7 +308,6 @@ static int h_archiver(int argc, char **argv){
 static int h_counter(int argc, char **argv){
 static int h_counter(int argc, char **argv){
 	struct counter_header ch1;
 	struct counter_header ch1;
 	if(conf.counterd >=0)close(conf.counterd);
 	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);
 	conf.counterd = open((char *)argv[1], O_BINARY|O_RDWR|O_CREAT, 0660);
 	if(conf.counterd<0){
 	if(conf.counterd<0){
 		fprintf(stderr, "Unable to open counter file %s, line %d\n", argv[1], linenum);
 		fprintf(stderr, "Unable to open counter file %s, line %d\n", argv[1], linenum);
@@ -1137,6 +1136,7 @@ static int h_ace(int argc, char **argv){
 	case NOCOUNTOUT:
 	case NOCOUNTOUT:
 	case COUNTALL:
 	case COUNTALL:
 	case NOCOUNTALL:
 	case NOCOUNTALL:
+		if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc;
 		tl = myalloc(sizeof(struct trafcount));
 		tl = myalloc(sizeof(struct trafcount));
 		if(!tl) {
 		if(!tl) {
 			return(21);
 			return(21);

+ 4 - 25
src/datatypes.c

@@ -365,32 +365,11 @@ static void * ef_ace_next(struct node * node){
 	return ((struct ace *)node->value) -> next;
 	return ((struct ace *)node->value) -> next;
 }
 }
 
 
+
+char * aceaction (int action);
+
 static void * ef_ace_type(struct node * node){
 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);
 }
 }
 
 
 
 

+ 43 - 7
src/webadmin.c

@@ -16,12 +16,43 @@ extern FILE *writable;
 FILE * confopen();
 FILE * confopen();
 extern void decodeurl(char *s, int filter);
 extern void decodeurl(char *s, int filter);
 
 
+
+
 struct printparam {
 struct printparam {
 	char buf[1024];
 	char buf[1024];
 	int inbuf;
 	int inbuf;
 	struct clientparam *cp;
 	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){
 static void stdpr(struct printparam* pp, char *buf, int inbuf){
 	if((pp->inbuf + inbuf > 1024) || !buf) {
 	if((pp->inbuf + inbuf > 1024) || !buf) {
 		socksend(pp->cp->clisock, (char *)pp->buf, pp->inbuf, conf.timeouts[STRING_S]);
 		socksend(pp->cp->clisock, (char *)pp->buf, pp->inbuf, conf.timeouts[STRING_S]);
@@ -260,11 +291,11 @@ char * admin_stringtable[]={
 
 
 	"<h3>Counters</h3>\r\n"
 	"<h3>Counters</h3>\r\n"
 	"<table border = \'1\'>\r\n"
 	"<table border = \'1\'>\r\n"
-	"<tr align=\'center\'><td>Description</td><td>Active</td>"
+	"<tr align=\'center\'><td>Action</td><td>#/Desc</td><td>Active</td>"
 	"<td>Users</td><td>Source Address</td><td>Destination Address</td>"
 	"<td>Users</td><td>Source Address</td><td>Destination Address</td>"
 	"<td>Port</td>"
 	"<td>Port</td>"
 	"<td>Limit</td><td>Units</td><td>Value</td>"
 	"<td>Limit</td><td>Units</td><td>Value</td>"
-	"<td>Reset</td><td>Updated</td><td>Num</td></tr>\r\n",
+	"<td>Reset</td><td>Updated</td><td>Position</td></tr>\r\n",
 
 
 	"</table>\r\n",
 	"</table>\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] == 'S' && atoi(req+2) == num) cp->disabled=0;
 			 if(req[1] == 'D' && atoi(req+2) == num) cp->disabled=1;
 			 if(req[1] == 'D' && atoi(req+2) == num) cp->disabled=1;
-			 inbuf += sprintf(buf,	"<tr>"
-						"<td>%s</td><td><A HREF=\'/C%c%d\'>%s</A></td><td>",
-						(cp->comment)?cp->comment:"&nbsp;",
+			 inbuf += sprintf(buf,	"<tr><td>%s</td><td>", cp->ace?aceaction(cp->ace->action):"-");
+			 if(cp->number || cp->comment)
+				inbuf += sprintf(buf+inbuf, "%d/%s</td>" , cp->number,
+						(cp->comment)?cp->comment:"&nbsp;");
+			else
+				inbuf += sprintf(buf+inbuf, " - </td>");
+
+			inbuf += sprintf(buf+inbuf, "<td><A HREF=\'/C%c%d\'>%s</A></td><td>",
 						(cp->disabled)?'S':'D',
 						(cp->disabled)?'S':'D',
 						num,
 						num,
 						(cp->disabled)?"NO":"YES"
 						(cp->disabled)?"NO":"YES"
@@ -467,7 +503,7 @@ void * adminchild(struct clientparam* param) {
 			 else {
 			 else {
 				inbuf += printportlist(buf+inbuf, LINESIZE-128, cp->ace->ports, ",<br />\r\n");
 				inbuf += printportlist(buf+inbuf, LINESIZE-128, cp->ace->ports, ",<br />\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,	
 			  inbuf += sprintf(buf+inbuf,	
 					"</td><td colspan=\'6\' align=\'center\'>exclude from limitation</td></tr>\r\n"
 					"</td><td colspan=\'6\' align=\'center\'>exclude from limitation</td></tr>\r\n"
 				 );
 				 );
@@ -542,7 +578,7 @@ void * adminchild(struct clientparam* param) {
 			if(!writable || !contentlen || fseek(writable, 0, 0)){
 			if(!writable || !contentlen || fseek(writable, 0, 0)){
 				error = 1;
 				error = 1;
 			}
 			}
-			while(l < contentlen && (i = sockgetlinebuf(param, CLIENT, (char *)buf, (contentlen - l) > LINESIZE - 1?LINESIZE - 1:contentlen - l, '+', conf.timeouts[STRING_S])) > 0){
+			while(l < contentlen && (i = sockgetlinebuf(param, CLIENT, buf, (contentlen - l) > LINESIZE - 1?LINESIZE - 1:contentlen - l, '+', conf.timeouts[STRING_S])) > 0){
 				if(((unsigned)i) > (contentlen - l)) i = (int)(contentlen - l);
 				if(((unsigned)i) > (contentlen - l)) i = (int)(contentlen - l);
 				if(!l){
 				if(!l){
 					if(i<9 || strncasecmp(buf, "conffile=", 9)) error = 1;
 					if(i<9 || strncasecmp(buf, "conffile=", 9)) error = 1;