[GH-ISSUE #29] Status fields mapping - simple fix #26

Open
opened 2026-02-25 20:30:18 +03:00 by kerem · 2 comments
Owner

Originally created by @bugsyb on GitHub (Nov 12, 2020).
Original GitHub issue: https://github.com/adamwalach/openvpn-web-ui/issues/29

Hi Adam,

Would you be able please kindly to fix the little problem with mapping fields?
[https://imgur.com/a/c9GBERj]

The KB received shows 0, the KB Sent shows value, in fact received in KBytes, Connected Since shows Sent but in B not KB, and Username shows connected since but in timestamp, not date.

Belief is that it is down to parse.go section (below is what I thought would fix it - but something is wrong with this - not sure why field[4] gets 0, hence moved on to next field.

		case c == "CLIENT_LIST":
			bytesR, _ := strconv.ParseUint(fields[5], 10, 64)
			bytesS, _ := strconv.ParseUint(fields[6], 10, 64)
//			ConnectedSinceD := time.Unix(fields[7])
			item := &OVClient{
				CommonName:      fields[1],
				RealAddress:     fields[2],
				VirtualAddress:  fields[3],
				BytesReceived:   bytesR,
				BytesSent:       bytesS,
				ConnectedSince:  fields[7],
				ConnectedSinceT: fields[8],
//				Username:        fields[9],

github.com/adamwalach/openvpn-web-ui@075614837f/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go (L91)

Hope this is a 1 minute issue for you to fix.

Thank you in advance.

Originally created by @bugsyb on GitHub (Nov 12, 2020). Original GitHub issue: https://github.com/adamwalach/openvpn-web-ui/issues/29 Hi Adam, Would you be able please kindly to fix the little problem with mapping fields? [https://imgur.com/a/c9GBERj] The KB received shows 0, the KB Sent shows value, in fact received in KBytes, Connected Since shows Sent but in B not KB, and Username shows connected since but in timestamp, not date. Belief is that it is down to parse.go section (below is what I thought would fix it - but something is wrong with this - not sure why field[4] gets 0, hence moved on to next field. ``` case c == "CLIENT_LIST": bytesR, _ := strconv.ParseUint(fields[5], 10, 64) bytesS, _ := strconv.ParseUint(fields[6], 10, 64) // ConnectedSinceD := time.Unix(fields[7]) item := &OVClient{ CommonName: fields[1], RealAddress: fields[2], VirtualAddress: fields[3], BytesReceived: bytesR, BytesSent: bytesS, ConnectedSince: fields[7], ConnectedSinceT: fields[8], // Username: fields[9], ``` https://github.com/adamwalach/openvpn-web-ui/blob/075614837fd082481d3c29bf61aded7079b9f1e4/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go#L91 Hope this is a 1 minute issue for you to fix. Thank you in advance.
Author
Owner

@bugsyb commented on GitHub (Nov 12, 2020):

Root cause is that currently there is IPv6 address included on status output, hence need to skip it (or map to new table field - skipping it in my case:

diff -Naur openvpn-web-ui-orig/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go openvpn-web-ui-override/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go
--- openvpn-web-ui-orig/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go	2020-03-22 14:02:56.000000000 +0100
+++ openvpn-web-ui-override/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go	2020-11-12 23:37:01.000000000 +0100
@@ -88,17 +88,17 @@
 			}
 			s.RoutingTable = append(s.RoutingTable, item)
 		case c == "CLIENT_LIST":
-			bytesR, _ := strconv.ParseUint(fields[4], 10, 64)
-			bytesS, _ := strconv.ParseUint(fields[5], 10, 64)
+			bytesR, _ := strconv.ParseUint(fields[5], 10, 64)
+			bytesS, _ := strconv.ParseUint(fields[6], 10, 64)
 			item := &OVClient{
 				CommonName:      fields[1],
 				RealAddress:     fields[2],
 				VirtualAddress:  fields[3],
 				BytesReceived:   bytesR,
 				BytesSent:       bytesS,
-				ConnectedSince:  fields[6],
-				ConnectedSinceT: fields[7],
-				Username:        fields[8],
+				ConnectedSince:  fields[7],
+				ConnectedSinceT: fields[8],
+				Username:        fields[9],
 			}
 			s.ClientList = append(s.ClientList, item)
 		}

Output:

status 2
TITLE,OpenVPN 2.4.9 aarch64-alpine-linux-musl [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] built on Apr 20 2020
TIME,Thu Nov 12 22:06:53 2020,1605218813
HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Virtual IPv6 Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username,Client ID,Peer ID
<!-- gh-comment-id:726385183 --> @bugsyb commented on GitHub (Nov 12, 2020): Root cause is that currently there is IPv6 address included on status output, hence need to skip it (or map to new table field - skipping it in my case: ``` diff -Naur openvpn-web-ui-orig/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go openvpn-web-ui-override/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go --- openvpn-web-ui-orig/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go 2020-03-22 14:02:56.000000000 +0100 +++ openvpn-web-ui-override/vendor/github.com/adamwalach/go-openvpn/server/mi/parse.go 2020-11-12 23:37:01.000000000 +0100 @@ -88,17 +88,17 @@ } s.RoutingTable = append(s.RoutingTable, item) case c == "CLIENT_LIST": - bytesR, _ := strconv.ParseUint(fields[4], 10, 64) - bytesS, _ := strconv.ParseUint(fields[5], 10, 64) + bytesR, _ := strconv.ParseUint(fields[5], 10, 64) + bytesS, _ := strconv.ParseUint(fields[6], 10, 64) item := &OVClient{ CommonName: fields[1], RealAddress: fields[2], VirtualAddress: fields[3], BytesReceived: bytesR, BytesSent: bytesS, - ConnectedSince: fields[6], - ConnectedSinceT: fields[7], - Username: fields[8], + ConnectedSince: fields[7], + ConnectedSinceT: fields[8], + Username: fields[9], } s.ClientList = append(s.ClientList, item) } ``` Output: ``` status 2 TITLE,OpenVPN 2.4.9 aarch64-alpine-linux-musl [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] built on Apr 20 2020 TIME,Thu Nov 12 22:06:53 2020,1605218813 HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Virtual IPv6 Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username,Client ID,Peer ID ```
Author
Owner

@bugsyb commented on GitHub (Nov 12, 2020):

Pending fix to be applied, pls.

<!-- gh-comment-id:726385876 --> @bugsyb commented on GitHub (Nov 12, 2020): Pending fix to be applied, pls.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/openvpn-web-ui#26
No description provided.