* Copyright (C) 2009,2010 Florian octo Forster
* Copyright (C) 2009 Marco Chiappero
* Copyright (C) 2009 Fabian Schuh
+ * Copyright (C) 2017-2020 Pavel Rochnyak
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
#define TITLE_SINGLE "OpenVPN STATISTICS\n"
#define TITLE_V1 "OpenVPN CLIENT LIST\n"
-#define TITLE_V2 "TITLE"
+#define TITLE_V2 "TITLE,"
+#define TITLE_V3 "TITLE\t"
#define V1HEADER \
"Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since\n"
* status file is generated by openvpn/multi.c:multi_print_status()
* http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
*/
-static int multi2_read(const char *name, FILE *fh) {
+static int multi2_read(const char *name, FILE *fh, const char *delim) {
char buffer[1024];
/* OpenVPN-2.4 has 11 fields of data + 2 fields for "HEADER" and "CLIENT_LIST"
* So, set array size to 20 elements, to support future extensions.
int columns = 0;
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
- int fields_num = openvpn_strsplit(buffer, fields, max_fields);
+ int fields_num = 0;
+
+ char *field = fields[fields_num++] = buffer;
+
+ while ((field = strstr(field, delim)) != NULL) {
+ *field = '\0';
+ fields[fields_num++] = ++field;
+ if (fields_num >= max_fields)
+ break;
+ }
/* Try to find section header */
if (found_header == false) {
} else if (strcmp(buffer, TITLE_V1) == 0) { // OpenVPN CLIENT LIST
DEBUG("openvpn plugin: found status file MULTI version 1");
read = multi1_read(st->name, fh);
- } else if (strncmp(buffer, TITLE_V2, strlen(TITLE_V2)) == 0) { // TITLE
- DEBUG("openvpn plugin: found status file MULTI version 2/3");
- read = multi2_read(st->name, fh);
+ } else if (strncmp(buffer, TITLE_V2, strlen(TITLE_V2)) == 0) { // TITLE,
+ DEBUG("openvpn plugin: found status file MULTI version 2");
+ read = multi2_read(st->name, fh, ",");
+ } else if (strncmp(buffer, TITLE_V3, strlen(TITLE_V3)) == 0) { // TITLE\t
+ DEBUG("openvpn plugin: found status file MULTI version 3");
+ read = multi2_read(st->name, fh, "\t");
} else {
NOTICE("openvpn plugin: %s: Unknown file format, please "
"report this as bug. Make sure to include "