-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for importing profile to the Config Manager
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
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|