GNOME Bugzilla – Bug 744260
vpn: add scripts to import VPN configuration to NM
Last modified: 2015-05-19 07:31:26 UTC
NetworkManager has an VPN import functionality. However, it is bound to GUI and thus is not useful for command line or batch processing. Branch jk/vpn-import-scripts includes scripts (in Lua) for importing/converting OpenVPN, vpnc and OpenConnect configurations to NetworkManager.
I think there are basically two ways how we should import/export connections. 1) have a script using DBus (possibly libnm-gio-introspection) to create the connections using DBUS directly. $ ./create-connection args 2) write keyfiles. This goes together with nmcli being able to import/export connections in keyfile format. Then you would call $ ./create-connection args | nmcli connection import >> contrib/scripts: openvpn2nm.lua - script for converting OpenVPN configs to NM this supports 1) and 2). I would not support specifying an out-file, just print to stdout. If somebody wants to write it to file, he should redirect it: openvpn2nm/lua '<in>' | sudo tee /etc/NetworkManager/system-connections/vpn (any debug messages would go to stderr). Is two-spaces indent standard for lua? It's hard to read for me :) Also, could we get rid of the global variables (except vpn2nm)? IMO that is easier to understand. +function uuid() The function does not create RFC compliant uuids. Is there no library function for uuids? Also, NM now supports generating the UUID itself (both in keyfile and DBus Update()). So, you could just omit it entirely. For reference, nmcli should support regenerating the UUID too: ./create-connection args | nmcli connection import would keep the UUID (if set), otherwise generate one. This ./create-connection args | nmcli connection import --generate-uuid would always regenerate an UUID. How about naming the scripts differently? I would expect people to copy the script into their path. Just get rid for the .lua extension. And how about giving them a common prefix? Like: contrib/scripts/nm-import-[vpnc|openvpn|...]
I opened bug 744702 for import/export of connections in nmcli and bug 744699 to support keyfile in libnm. If that would be done, I think scripts should make use of that functionality. This way, the script only has to concern itself with reading the vpn-specific config and creating an NMConnection of them. All that is left is: print(connection.to_keyfile(with-secrets=TRUE))
Why lua? We're already using both perl and python in different places. Adding a third scripting language seems unnecessary.
(In reply to Thomas Haller from comment #1) > I think there are basically two ways how we should import/export connections. > > I would not support specifying an out-file, just > print to stdout. If somebody wants to write it to file, he should redirect > it: > Hmm, I think it's just a matter of taste. Anyway, users typically want to store the data to a file and then do something with it, like copying it to NM keyfile storage and adjust the permissions as suggested right away, or storing it for a later use. Or we could make the output file name optional. > > Is two-spaces indent standard for lua? It's hard to read for me :) > It is: http://lua-users.org/wiki/LuaStyleGuide (Formating) And it is readable for me. Anyway, I was always using two spaces indentation, even for C (before being forces to one Tab in NM :)) > Also, could we get rid of the global variables (except vpn2nm)? IMO that is > easier to understand. > There are not that many, just the VPN data storage and they are marked with g_ prefix. It is easier than passing them to all functions. > > +function uuid() > > The function does not create RFC compliant uuids. How so? The UUIDs look OK and passes e.g. http://guid.us/Test/GUID There might be some modules for UUID generation, but I'd rather not add a dependency. > > How about naming the scripts differently? I would expect people to copy the > script into their path. Just get rid for the .lua extension. > And how about giving them a common prefix? Like: > contrib/scripts/nm-import-[vpnc|openvpn|...] Done.
(In reply to Dan Winship from comment #3) > Why lua? We're already using both perl and python in different places. > Adding a third scripting language seems unnecessary. Why not :) My reasons are 1. The scripts are quite independent, so they can be in any language. 2. I wanted to learn Lua and I like it. 3. Lua is small, nice, fast, without much dependencies. 4. Contribute to Lua awareness and spreading.
Scripts have been merged to master: 9b11276 merge: add scripts for importing VPN configurations for NM (bgo #744260) 466515e contrib/scripts: fix importing 'remote' and 'remote-random' options for openvpn 29473f1 contrib/scripts: nm-import-openconnect - script for importing OpenConnect VPN configs to NM db0cf1e contrib/scripts: nm-import-vpnc - script for importing Cisco VPN configs to NM 1a2798d contrib/scripts: nm-import-openvpn - script for importing OpenVPN configs to NM