Skip to content

Commit

Permalink
Add support for importing profile to the Config Manager
Browse files Browse the repository at this point in the history
This adds a new ConfigImport class which imports the downloaded profile
into the configuration manager, where it sets a couple of reasonable
defaults on the configuration profile.

Signed-off-by: David Sommerseth <[email protected]>
  • Loading branch information
dsommers committed Jan 11, 2022
1 parent 3666624 commit a73b0bd
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions openvpn/connector/configmgr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# OpenVPN Connector Setup
# - Configure OpenVPN 3 Linux for OpenVPN Cloud
#
# Copyright (C) 2022 OpenVPN Inc. <[email protected]>
# Copyright (C) 2022 David Sommerseth <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3 of the
# License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import os
import dbus
from openvpn3 import ConfigurationManager

class ConfigImport(object):
def __init__(self, systembus, cfgname):
self.__system_bus = systembus
self.__cfgmgr = ConfigurationManager(self.__system_bus)
self.__config_name = cfgname.replace(' ', '')
self._cfgobj = None


def GetConfigName(self):
return self.__config_name


def Import(self, profile):
print('Importing VPN configuration profile "%s" ... ' % self.__config_name,
end='', flush=True)
self._cfgobj = self.__cfgmgr.Import(self.__config_name,
profile.GetProfile(),
False, True)
self._cfgobj.SetProperty('locked_down', True)
self._cfgobj.SetOverride('persist-tun', True)
self._cfgobj.SetOverride('log-level', '5')
print('Done')
if 'OPENVPN_CLOUD_DEBUG' in os.environ:
print('Configuration path: %s' % self._cfgobj.GetPath())


def EnableOwnershipTransfer(self):
print('Granting root user access to profile ... ', end='', flush=True)
self._cfgobj.SetProperty('transfer_owner_session', True)
self._cfgobj.AccessGrant(0)
print('Done')

0 comments on commit a73b0bd

Please sign in to comment.