Commit 4e9aa035 authored by Jiří Klimeš's avatar Jiří Klimeš

merge: implement nmcli con import/export for VPN connections (rh #1034105)

https://bugzilla.redhat.com/show_bug.cgi?id=1034105
parents ce238a70 3892b839
......@@ -40,6 +40,8 @@ nmcli_SOURCES = \
\
$(srcdir)/../common/nm-secret-agent-simple.c \
$(srcdir)/../common/nm-secret-agent-simple.h \
$(srcdir)/../common/nm-vpn-helpers.c \
$(srcdir)/../common/nm-vpn-helpers.h \
$(NULL)
nmcli_LDADD = \
......
This diff is collapsed.
......@@ -282,6 +282,7 @@ _nmcli_compl_OPTIONS()
# expects several options with parameters. This function can parse them and remove them from the words array.
_nmcli_compl_ARGS()
{
local aliases=${@}
local OPTIONS_ALL N_REMOVE_WORDS REMOVE_OPTIONS OPTIONS_HAS_MANDATORY i
OPTIONS_ALL=("${OPTIONS[@]}")
OPTIONS_UNKNOWN_OPTION=
......@@ -317,7 +318,17 @@ _nmcli_compl_ARGS()
N_REMOVE_WORDS=2
REMOVE_OPTIONS=("${words[0]}")
case "${words[0]}" in
# change option name to alias
WORD0="${words[0]}"
for alias in "${aliases[@]}" ; do
if [[ "${WORD0}" == ${alias%%:*} ]]; then
WORD0=${alias#*:}
break
fi
done
case "${WORD0}" in
level)
if [[ "${#words[@]}" -eq 2 ]]; then
_nmcli_list "OFF ERR WARN INFO DEBUG TRACE"
......@@ -560,7 +571,8 @@ _nmcli_compl_ARGS()
username| \
service| \
password| \
passwd-file)
passwd-file| \
file)
if [[ "${#words[@]}" -eq 2 ]]; then
return 0
fi
......@@ -870,7 +882,7 @@ _nmcli()
;;
c|co|con|conn|conne|connec|connect|connecti|connectio|connection)
if [[ ${#words[@]} -eq 2 ]]; then
_nmcli_compl_COMMAND "$command" show up down add modify clone edit delete monitor reload load
_nmcli_compl_COMMAND "$command" show up down add modify clone edit delete monitor reload load import export
elif [[ ${#words[@]} -gt 2 ]]; then
case "$command" in
s|sh|sho|show)
......@@ -1315,6 +1327,61 @@ _nmcli()
COMPREPLY=()
fi
;;
i|im|imp|impo|impor|import)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND "${words[2]}" type file --temporary
elif [[ ${#words[@]} -gt 3 ]]; then
_nmcli_array_delete_at words 0 1
LONG_OPTIONS=(help temporary)
HELP_ONLY_AS_FIRST=1
_nmcli_compl_OPTIONS
case $? in
0)
return 0
;;
1)
if [[ "$HELP_ONLY_AS_FIRST" == 1 ]]; then
_nmcli_compl_COMMAND "${words[2]}" type file
fi
return 0
;;
esac
OPTIONS=(type file)
OPTIONS_MANDATORY=(type file)
ALIASES=("type:vpn-type")
_nmcli_compl_ARGS ${ALIASES[@]}
return 0
fi
;;
e|ex|exp|expo|expor|export)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_show NAME)")"
elif [[ ${#words[@]} -gt 3 ]]; then
_nmcli_array_delete_at words 0 1
LONG_OPTIONS=(help)
HELP_ONLY_AS_FIRST=1
_nmcli_compl_OPTIONS
case $? in
0)
return 0
;;
1)
if [[ "$HELP_ONLY_AS_FIRST" == 1 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\n%s" "$(_nmcli_con_show NAME)")" "${LONG_OPTIONS[@]}"
fi
return 0
;;
esac
OPTIONS=(id uuid path)
_nmcli_compl_ARGS_CONNECTION && return 0
return 0
fi
;;
esac
fi
;;
......
......@@ -37,22 +37,30 @@ static gboolean plugins_loaded;
static GSList *plugins = NULL;
NMVpnEditorPlugin *
nm_vpn_get_plugin_by_service (const char *service)
nm_vpn_get_plugin_by_service (const char *service, GError **error)
{
NMVpnEditorPlugin *plugin = NULL;
NMVpnPluginInfo *plugin_info;
char *type = NULL;
g_return_val_if_fail (service != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (G_UNLIKELY (!plugins_loaded))
nm_vpn_get_plugins ();
if (!g_str_has_prefix (service, NM_DBUS_INTERFACE))
service = type = g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, service);
plugin_info = nm_vpn_plugin_info_list_find_by_service (plugins, service);
if (plugin_info) {
plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info);
if (!plugin)
plugin = nm_vpn_plugin_info_load_editor_plugin (plugin_info, NULL);
}
plugin = nm_vpn_plugin_info_load_editor_plugin (plugin_info, error);
} else
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_FAILED,
_("could not get VPN plugin info"));
g_free (type);
return plugin;
}
......@@ -80,7 +88,7 @@ nm_vpn_supports_ipv6 (NMConnection *connection)
service_type = nm_setting_vpn_get_service_type (s_vpn);
g_return_val_if_fail (service_type != NULL, FALSE);
plugin = nm_vpn_get_plugin_by_service (service_type);
plugin = nm_vpn_get_plugin_by_service (service_type, NULL);
g_return_val_if_fail (plugin != NULL, FALSE);
capabilities = nm_vpn_editor_plugin_get_capabilities (plugin);
......
......@@ -25,7 +25,7 @@
GSList *nm_vpn_get_plugins (void);
NMVpnEditorPlugin *nm_vpn_get_plugin_by_service (const char *service);
NMVpnEditorPlugin *nm_vpn_get_plugin_by_service (const char *service, GError **error);
gboolean nm_vpn_supports_ipv6 (NMConnection *connection);
......
......@@ -816,6 +816,29 @@ then \fINetworkManager\fP will reload connection files any time they change
Load/reload one or more connection files from disk. Use this after manually
editing a connection file to ensure that \fBNetworkManager\fP is aware
of its latest state.
.TP
.B import [--temporary] type <type> file <file to import>
.br
Import an external/foreign configuration as a NetworkManager connection profile.
The type of the input file is specified by \fItype\fP option.
.br
Only VPN configurations are supported at the moment. The configuration
is imported by NetworkManager VPN plugins. \fItype\fP values are the same as for
\fIvpn-type\fP option in \fBnmcli connection add\fP. VPN configurations are
imported by VPN plugins. Therefore the proper VPN plugin has to be installed
so that nmcli could import the data.
.br
The imported connection profile will be saved as persistent unless \fI--temporary\fP
option is specified, in which case the new profile won't exist after NetworkManager
restart.
.TP
.B export [ id | uuid | path ] <ID> [<output file>]
.br
Export a connection.
.br
Only VPN connections are supported at the moment. A proper VPN plugin has to be
installed so that nmcli could export a connection. If no \fI<output file>\fP is
provided, the VPN configuration data will be printed to standard output.
.RE
.TP
......@@ -1187,6 +1210,14 @@ appends a Google public DNS server to DNS servers in ABC profile.
.IP
removes the specified IP address from (static) profile ABC.
.IP "\fB\f(CWnmcli con import type openvpn file ~/Downloads/frootvpn.ovpn\fP\fP"
.IP
imports an OpenVPN configuration to NetworkManager.
.IP "\fB\f(CWnmcli con export corp-vpnc /home/joe/corpvpn.conf\fP\fP"
.IP
exports NetworkManager VPN profile corp-vpnc as standard Cisco (vpnc) configuration.
.SH NOTES
\fInmcli\fP accepts abbreviations, as long as they are a unique prefix in the set
of possible options. As new options get added, these abbreviations are not guaranteed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment