Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accounting data not read from openvpn-status.log (OpenVPN version 2.5). Added solution. #31

Open
Le-Inc opened this issue Sep 30, 2024 · 0 comments

Comments

@Le-Inc
Copy link

Le-Inc commented Sep 30, 2024

Because (current) OpenVPN 2.5 has different status log than the version used to compile radiusplugin no bytes sent/received is read from openvpn-status.log file. I changed in AcctScheduler.cpp file method parseStatusFile, so radiusplugin could parse file. Code:

void AcctScheduler::parseStatusFile(PluginContext *context, uint64_t *bytesin, uint64_t *bytesout, string key)
{
	char line[512], newline[512];
	memset(newline, 0, 512);
	string AddKey;
	char* RowVals[9];
	int i;
	
	//open the status file to read
	ifstream file(context->conf.getStatusFile().c_str(), ios::in);
	if (file.is_open())
	{
		if (DEBUG (context->getVerbosity()))
			 cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Scheduler: Read Statusfile.\n";
	  	
	  	//find the key, is delimited with a ',' from the informations
	  	
	  	//loop until the name is found, there is no delimiter, the string
	  	//"ROUTING TABLE" is found or EOF
		
        // Added CLIENT_LIST as OpenVPN status-log format has changed.
		AddKey = "CLIENT_LIST,"+key;
		i = 0;

		do
		{
			file.getline(line, 512);
			
		}
		while (line!=NULL && strncmp(line,AddKey.c_str(),AddKey.length())!=0 && strcmp(line,"HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t)")!=0 && file.eof()==false);
		
		if (line!=NULL && strncmp(line,AddKey.c_str(),AddKey.length())==0) {
		  memcpy(newline, line+AddKey.length(), strlen(line)-AddKey.length()+1);
		  char* res =  strtok(newline, ",");
		  while (res != NULL) {
		    RowVals[i] = res;
                    res = strtok(NULL, ",");
		    i = i + 1;
          }
		  *bytesin=strtoull(RowVals[1],NULL,10);
		  *bytesout=strtoull(RowVals[2],NULL,10);

		} else {
			cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: No accounting data was found for "<< key << " in file " << context->conf.getStatusFile() << endl;
		}

		file.close();
	}
	else
	{
		cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Statusfile "<< context->conf.getStatusFile() <<" could not opened.\n";
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant