コード例 #1
0
##
# @file  ovpncli.py
#
# @brief  Simple test program for the openvpn3 Python module
#         This test program will basically work similar to the openvpn2
#         front-end, but not as robust.

import sys
import dbus
import time
import openvpn3
from getpass import getpass

# Parse the command line arguments
cmdparser = openvpn3.ConfigParser(sys.argv, 'OpenVPN 3 module test program')
cmdparser.SanityCheck()

# Get a configuration name, if avialable
cfgname = cmdparser.GetConfigName() and cmdparser.GetConfigName(
) or '(unknown)'

# Get connected to the D-Bus system bus
bus = dbus.SystemBus()

# Get a connection to the openvpn3-service-configmgr service
# and import the configuration
cm = openvpn3.ConfigurationManager(bus)
cfg = cm.Import(cfgname, cmdparser.GenerateConfig(), False, False)
print("Configuration D-Bus path: " + cfg.GetPath())
コード例 #2
0
if __name__ == '__main__':
    argp = argparse.ArgumentParser(
        description='Generate openvpn2 bash-completion helper')
    argp.add_argument('--python-source-dir', action='store', required=True)
    args = argp.parse_args()

    if None == args.python_source_dir:
        print("The --python-source-dir option is required")
        sys.exit(2)

    # Configure a dummy OpenVPN 3 ConfigParser, so the
    # supported options and arguments can be extracted
    sys.path.insert(0, args.python_source_dir)
    import openvpn3
    cfgparser = openvpn3.ConfigParser([
        sys.argv[0],
    ], argp.description)
    completion_data = cfgparser.RetrieveShellCompletionData()

    # Generate the bash-completion script
    valid_args = {}
    for opt, values in completion_data['argvalues'].items():
        if len(values) > 1:
            valid_args[opt] = '{' + ','.join(['"%s"' % v
                                              for v in values]) + '}'
        else:
            valid_args[opt] = '%s' % values[0]

    option_list = '{' + ','.join(
        ['"%s"' % o for o in completion_data['options']]) + '}'
コード例 #3
0
#  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/>.
#

##
# @file  genconfig.py
#
# @brief  Simple test program which uses the openvpn3 python module
#         to generate a proper configuration with external files embedded.
#         It uses the same configuration parser as the openvpn2 front-end to
#         openvpn3, and should support most the same set of options as the
#         classic OpenVPN 2.x client related options.

import sys
import openvpn3

cfgpars = openvpn3.ConfigParser(
    sys.argv,
    "Generate an OpenVPN configuration profile from the command line")
print(cfgpars.GenerateConfig())