Git Product home page Git Product logo

Comments (1)

Russell-Jones-OxPhys avatar Russell-Jones-OxPhys commented on August 12, 2024

OK, I figured it out using

import dbus
from pprint import pprint

bus = dbus.SystemBus()

ssn = "org.freedesktop.NetworkManager"

sysproxy = bus.get_object(ssn, "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(sysproxy, ssn + ".Settings")
c = settings.ListConnections()[0]
#pprint(settings.ListConnections())

for conn in settings.ListConnections():
    connproxy = bus.get_object(ssn, conn)
    conn = dbus.Interface(connproxy, ssn+'.Settings.Connection')
    pprint(conn.GetSettings())
    print()

The connection object has a different form for VPN connections from WiFi connections. So I had to do

import dbus
import uuid
import os

bus = dbus.SystemBus()

ssn = "org.freedesktop.NetworkManager"

sysproxy = bus.get_object(ssn, "/org/freedesktop/NetworkManager/Settings")

settings = dbus.Interface(sysproxy, ssn + ".Settings")

s_vpn = dbus.Dictionary({
            'ca-cert' : '/usr/local/share/ca-certificates/my-cert-chain.pem', 
            'user' : 'usernmae', 
            'refuse-eap': 'yes', 
            'refuse-chap': 'yes', 
            'gateway' : 'vpn.example.com', 
            'domain' : 'EXAMPLE', 
            'refuse-pap' : 'yes', 
            'password-flags' : '0', 
            'proxy-password-flags' : '0', 
        })

s_secs = dbus.Dictionary({
             'password' : 'password',
        })


s_con = dbus.Dictionary({
    'id': 'Example SSTP',
    'type': 'vpn',
    'uuid': str(uuid.uuid4()),
    'permissions': ['user:'+os.environ['USER']],
    'autoconnect' : False,
})

s_ip4 = dbus.Dictionary({'method' : 'auto'})

s_ip6 = dbus.Dictionary({
    'method' : 'ignore',
    'ip6-privacy' : False,
    'addr-gen-mode' : 1, # 'stable-privacy' ?
})

con = dbus.Dictionary({
    'connection': s_con,
    'vpn': dbus.Dictionary({ 
                'data': s_vpn,
                'service-type' : ('org.freedesktop.'
                                  'NetworkManager.sstp'),
                'secrets' : s_secs,
                }),
    'ipv4': s_ip4,
    'ipv6': s_ip6,
})

settings.AddConnection(con)

from network-manager-sstp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.