From: Timo Eissler Date: Tue, 7 Jun 2022 15:53:23 +0000 (+0200) Subject: openvpn-authenticator: Change event and environment handling X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=01721042905f574e4f4dba196208475193cbb386;p=people%2Fteissler%2Fipfire-2.x.git openvpn-authenticator: Change event and environment handling Move reading of environment in it's own function because not all events have a ENV block following and thus always reading the ENV will cause RuntimeError("Unexpected environment line ..."). --- diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator index 25d96ca34..67fb72085 100644 --- a/config/ovpn/openvpn-authenticator +++ b/config/ovpn/openvpn-authenticator @@ -138,6 +138,21 @@ class OpenVPNAuthenticator(object): environ = {} + if event == "CONNECT": + environ = self._read_env(environ) + self._client_connect(*arguments, environ=environ) + elif event == "DISCONNECT": + environ = self._read_env(environ) + self._client_disconnect(*arguments, environ=environ) + elif event == "REAUTH": + environ = self._read_env(environ) + self._client_reauth(*arguments, environ=environ) + elif event == "ESTABLISHED": + environ = self._read_env(environ) + else: + log.debug("Unhandled event: %s" % event) + + def _read_env(self, environ): # Read environment while True: line = self._read_line() @@ -156,14 +171,7 @@ class OpenVPNAuthenticator(object): key, delim, value = line.partition("=") environ[key] = value - if event == "CONNECT": - self._client_connect(*arguments, environ=environ) - elif event == "DISCONNECT": - self._client_disconnect(*arguments, environ=environ) - elif event == "REAUTH": - self._client_reauth(*arguments, environ=environ) - else: - log.debug("Unhandled event: %s" % event) + return environ def _client_connect(self, cid, kid, environ={}): log.debug("Received client connect (cid=%s, kid=%s)" % (cid, kid))