On Fri, 2014-05-23 at 22:29 +0800, Lei Xue wrote: > Hi All, > > I have an OpenVPN configuration file, and I can import it via Network > Manager GUI to create a VPN connection. > > Now, I would like to write a script to create the VPN connection based on > configuration file. I found that I can use Network Manager DBUS to do that, > but I just got the examples on how to activate the exist connection. I > found them from this thread: > https://mail.gnome.org/archives/networkmanager-list/2009-February/msg00075.html > . > > And there is not enough information on how to do the VPN type connection, > it will be very appreciated if you can provide any tips or suggestion. > > I would like to use Perl script to do that, but any other language will be > all right to learn about.
THere are some examples about adding a non-VPN connection here: http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/dbus http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/gi/add_connection.py http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/ruby/add-connection.rb which should give you an idea of how to do it in some different languages dynamically. What's obviously different are the specific key/value pairs that you need to send, and those are dependent on each VPN plugin. There isn't formal documentation on those, but it's centrally located in the code: https://git.gnome.org/browse/network-manager-openvpn/tree/src/nm-openvpn-service.c#n99 If you'd like to see what the NM-openvpn import/export code looks like that's at: https://git.gnome.org/browse/network-manager-openvpn/tree/properties/import-export.c but in general, the conversion is pretty straight-forward and the key names are the same as the openvpn config equivalents. There's another option: just create the NM config file and drop that into /etc/NetworkManager/system-connections, and since you'll be giving it a known UUID, you can then call Settings.GetConnectionByUuid() via D-Bus and then use the returned object path to start the VPN connection. You can see the config file NM writes by going through the import process in nm-connection-editor and the saving the resulting connection, and it'll show up in /etc/NetworkManager/system-connections. Hopefully that's enough to get you started, let us know if you have any more questions! Dan _______________________________________________ networkmanager-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/networkmanager-list
