Rename defines to WIREGUARD, get rid of old code

pull/1/head
Max Moser 2018-02-12 18:50:57 +01:00
parent 654ddec142
commit 619bd1a0f5
10 changed files with 92 additions and 380 deletions

View File

@ -490,8 +490,8 @@ main (int argc, char *argv[])
// the parameters are supplied via arguments // the parameters are supplied via arguments
printf("UUID: %s, Name: %s, Service: %s\n", vpn_uuid, vpn_name, vpn_service); printf("UUID: %s, Name: %s, Service: %s\n", vpn_uuid, vpn_name, vpn_service);
if (strcmp (vpn_service, NM_VPN_SERVICE_TYPE_OPENVPN) != 0) { if (strcmp (vpn_service, NM_VPN_SERVICE_TYPE_WIREGUARD) != 0) {
fprintf (stderr, "This dialog only works with the '%s' service\n", NM_VPN_SERVICE_TYPE_OPENVPN); fprintf (stderr, "This dialog only works with the '%s' service\n", NM_VPN_SERVICE_TYPE_WIREGUARD);
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -1,6 +1,6 @@
{ {
global: global:
nm_vpn_editor_factory_openvpn; nm_vpn_editor_factory_wireguard;
local: local:
*; *;
}; };

View File

@ -41,8 +41,8 @@
#include "import-export.h" #include "import-export.h"
#define OPENVPN_PLUGIN_NAME _("Wireguard") #define WIREGUARD_PLUGIN_NAME "Wireguard"
#define OPENVPN_PLUGIN_DESC _("Used to set up client-side Wireguard connections.") #define WIREGUARD_PLUGIN_DESC "Used to set up client-side Wireguard connections."
/*****************************************************************************/ /*****************************************************************************/
@ -53,11 +53,11 @@ enum {
PROP_SERVICE PROP_SERVICE
}; };
static void openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class); static void wireguard_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class);
G_DEFINE_TYPE_EXTENDED (OpenvpnEditorPlugin, openvpn_editor_plugin, G_TYPE_OBJECT, 0, G_DEFINE_TYPE_EXTENDED (WireguardEditorPlugin, wireguard_editor_plugin, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN, G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN,
openvpn_editor_plugin_interface_init)) wireguard_editor_plugin_interface_init))
/*****************************************************************************/ /*****************************************************************************/
@ -143,16 +143,16 @@ _call_editor_factory (gpointer factory,
static NMVpnEditor * static NMVpnEditor *
get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error) get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
{ {
g_return_val_if_fail (OPENVPN_IS_EDITOR_PLUGIN (iface), NULL); g_return_val_if_fail (WIREGUARD_IS_EDITOR_PLUGIN (iface), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (!error || !*error, NULL); g_return_val_if_fail (!error || !*error, NULL);
{ {
#ifdef NM_VPN_OLD #ifdef NM_VPN_OLD
return openvpn_editor_new (connection, error); return wireguard_editor_new (connection, error);
#else #else
return nm_vpn_plugin_utils_load_editor (NM_PLUGIN_DIR"/libnm-vpn-plugin-openvpn-editor.so", return nm_vpn_plugin_utils_load_editor (NM_PLUGIN_DIR"/libnm-vpn-plugin-wireguard-editor.so",
"nm_vpn_editor_factory_openvpn", "nm_vpn_editor_factory_wireguard",
_call_editor_factory, _call_editor_factory,
iface, iface,
connection, connection,
@ -170,13 +170,13 @@ get_property (GObject *object, guint prop_id,
{ {
switch (prop_id) { switch (prop_id) {
case PROP_NAME: case PROP_NAME:
g_value_set_string (value, OPENVPN_PLUGIN_NAME); g_value_set_string (value, WIREGUARD_PLUGIN_NAME);
break; break;
case PROP_DESC: case PROP_DESC:
g_value_set_string (value, OPENVPN_PLUGIN_DESC); g_value_set_string (value, WIREGUARD_PLUGIN_DESC);
break; break;
case PROP_SERVICE: case PROP_SERVICE:
g_value_set_string (value, NM_VPN_SERVICE_TYPE_OPENVPN); g_value_set_string (value, NM_VPN_SERVICE_TYPE_WIREGUARD);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -185,12 +185,12 @@ get_property (GObject *object, guint prop_id,
} }
static void static void
openvpn_editor_plugin_init (OpenvpnEditorPlugin *plugin) wireguard_editor_plugin_init (WireguardEditorPlugin *plugin)
{ {
} }
static void static void
openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class) wireguard_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class)
{ {
iface_class->get_editor = get_editor; iface_class->get_editor = get_editor;
iface_class->get_capabilities = get_capabilities; iface_class->get_capabilities = get_capabilities;
@ -200,7 +200,7 @@ openvpn_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_class)
} }
static void static void
openvpn_editor_plugin_class_init (OpenvpnEditorPluginClass *req_class) wireguard_editor_plugin_class_init (WireguardEditorPluginClass *req_class)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (req_class); GObjectClass *object_class = G_OBJECT_CLASS (req_class);
@ -229,6 +229,6 @@ nm_vpn_editor_plugin_factory (GError **error)
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
return g_object_new (OPENVPN_TYPE_EDITOR_PLUGIN, NULL); return g_object_new (WIREGUARD_TYPE_EDITOR_PLUGIN, NULL);
} }

View File

@ -20,37 +20,37 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef __NM_OPENVPN_EDITOR_PLUGIN_H__ #ifndef __NM_WIREGUARD_EDITOR_PLUGIN_H__
#define __NM_OPENVPN_EDITOR_PLUGIN_H__ #define __NM_WIREGUARD_EDITOR_PLUGIN_H__
#define OPENVPN_TYPE_EDITOR_PLUGIN (openvpn_editor_plugin_get_type ()) #define WIREGUARD_TYPE_EDITOR_PLUGIN (wireguard_editor_plugin_get_type ())
#define OPENVPN_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OPENVPN_TYPE_EDITOR_PLUGIN, OpenvpnEditorPlugin)) #define WIREGUARD_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIREGUARD_TYPE_EDITOR_PLUGIN, WireguardEditorPlugin))
#define OPENVPN_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OPENVPN_TYPE_EDITOR_PLUGIN, OpenvpnEditorPluginClass)) #define WIREGUARD_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIREGUARD_TYPE_EDITOR_PLUGIN, WireguardEditorPluginClass))
#define OPENVPN_IS_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OPENVPN_TYPE_EDITOR_PLUGIN)) #define WIREGUARD_IS_EDITOR_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIREGUARD_TYPE_EDITOR_PLUGIN))
#define OPENVPN_IS_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OPENVPN_TYPE_EDITOR_PLUGIN)) #define WIREGUARD_IS_EDITOR_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIREGUARD_TYPE_EDITOR_PLUGIN))
#define OPENVPN_EDITOR_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OPENVPN_TYPE_EDITOR_PLUGIN, OpenvpnEditorPluginClass)) #define WIREGUARD_EDITOR_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIREGUARD_TYPE_EDITOR_PLUGIN, WireguardEditorPluginClass))
typedef struct _OpenvpnEditorPlugin OpenvpnEditorPlugin; typedef struct _WireguardEditorPlugin WireguardEditorPlugin;
typedef struct _OpenvpnEditorPluginClass OpenvpnEditorPluginClass; typedef struct _WireguardEditorPluginClass WireguardEditorPluginClass;
struct _OpenvpnEditorPlugin { struct _WireguardEditorPlugin {
GObject parent; GObject parent;
}; };
struct _OpenvpnEditorPluginClass { struct _WireguardEditorPluginClass {
GObjectClass parent; GObjectClass parent;
}; };
GType openvpn_editor_plugin_get_type (void); GType wireguard_editor_plugin_get_type (void);
typedef NMVpnEditor *(*NMVpnEditorFactory) (NMVpnEditorPlugin *editor_plugin, typedef NMVpnEditor *(*NMVpnEditorFactory) (NMVpnEditorPlugin *editor_plugin,
NMConnection *connection, NMConnection *connection,
GError **error); GError **error);
NMVpnEditor * NMVpnEditor *
nm_vpn_editor_factory_openvpn (NMVpnEditorPlugin *editor_plugin, nm_vpn_editor_factory_wireguard (NMVpnEditorPlugin *editor_plugin,
NMConnection *connection, NMConnection *connection,
GError **error); GError **error);
#endif /* __NM_OPENVPN_EDITOR_PLUGIN_H__ */ #endif /* __NM_WIREGUARD_EDITOR_PLUGIN_H__ */

View File

@ -41,23 +41,21 @@
/*****************************************************************************/ /*****************************************************************************/
static void openvpn_editor_plugin_widget_interface_init (NMVpnEditorInterface *iface_class); static void wireguard_editor_plugin_widget_interface_init (NMVpnEditorInterface *iface_class);
G_DEFINE_TYPE_EXTENDED (OpenvpnEditor, openvpn_editor_plugin_widget, G_TYPE_OBJECT, 0, G_DEFINE_TYPE_EXTENDED (WireguardEditor, wireguard_editor_plugin_widget, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR, G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR,
openvpn_editor_plugin_widget_interface_init)) wireguard_editor_plugin_widget_interface_init))
#define OPENVPN_EDITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OPENVPN_TYPE_EDITOR, OpenvpnEditorPrivate)) #define WIREGUARD_EDITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), WIREGUARD_TYPE_EDITOR, WireguardEditorPrivate))
typedef struct { typedef struct {
GtkBuilder *builder; GtkBuilder *builder;
GtkWidget *widget; GtkWidget *widget;
GtkWindowGroup *window_group; GtkWindowGroup *window_group;
gboolean window_added; gboolean window_added;
GHashTable *advanced;
gboolean new_connection; gboolean new_connection;
GtkWidget *tls_user_cert_chooser; } WireguardEditorPrivate;
} OpenvpnEditorPrivate;
/*****************************************************************************/ /*****************************************************************************/
@ -98,10 +96,10 @@ check_interface_dns_entry(const char *str)
if(is_empty(str)){ if(is_empty(str)){
return TRUE; return TRUE;
} }
else if(is_ip4(str)){ else if(is_ip4((char *)str)){
return TRUE; return TRUE;
} }
else if(is_ip6(str)){ else if(is_ip6((char *)str)){
return TRUE; return TRUE;
} }
@ -128,7 +126,7 @@ check_interface_private_key(const char *str)
return FALSE; return FALSE;
} }
// TODO // TODO maybe check length, base64 encoding, ...?
return TRUE; return TRUE;
} }
@ -186,7 +184,7 @@ typedef gboolean (*CheckFunc)(const char *str);
// helper function to reduce boilerplate code in 'check_validity()' // helper function to reduce boilerplate code in 'check_validity()'
static gboolean static gboolean
check (OpenvpnEditorPrivate *priv, check (WireguardEditorPrivate *priv,
char *widget_name, char *widget_name,
CheckFunc chk, const char *key, CheckFunc chk, const char *key,
gboolean set_error, gboolean set_error,
@ -214,7 +212,7 @@ check (OpenvpnEditorPrivate *priv,
} }
static void static void
set_error_class(OpenvpnEditorPrivate *priv, char *widget_name, gboolean error) set_error_class(WireguardEditorPrivate *priv, char *widget_name, gboolean error)
{ {
GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget_name)); GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget_name));
if(error){ if(error){
@ -226,7 +224,7 @@ set_error_class(OpenvpnEditorPrivate *priv, char *widget_name, gboolean error)
} }
static gboolean static gboolean
is_filled_out(OpenvpnEditorPrivate *priv, char *widget_name) is_filled_out(WireguardEditorPrivate *priv, char *widget_name)
{ {
const char *str; const char *str;
GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget_name)); GtkWidget *widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, widget_name));
@ -236,13 +234,9 @@ is_filled_out(OpenvpnEditorPrivate *priv, char *widget_name)
} }
static gboolean static gboolean
check_validity (OpenvpnEditor *self, GError **error) check_validity (WireguardEditor *self, GError **error)
{ {
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (self); WireguardEditorPrivate *priv = WIREGUARD_EDITOR_GET_PRIVATE (self);
const char *str;
GtkTreeModel *model;
GtkTreeIter iter;
const char *contype = NULL;
gboolean success = TRUE; gboolean success = TRUE;
gboolean ip4_ok = TRUE; gboolean ip4_ok = TRUE;
gboolean ip6_ok = TRUE; gboolean ip6_ok = TRUE;
@ -311,132 +305,22 @@ check_validity (OpenvpnEditor *self, GError **error)
} }
} }
/*
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "auth_combo"));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
g_return_val_if_fail (model, FALSE);
success = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
g_return_val_if_fail (success == TRUE, FALSE);
gtk_tree_model_get (model, &iter, COL_AUTH_TYPE, &contype, -1);
if (!auth_widget_check_validity (priv->builder, contype, error))
return FALSE;
*/
return success; return success;
} }
static void static void
stuff_changed_cb (GtkWidget *widget, gpointer user_data) stuff_changed_cb (GtkWidget *widget, gpointer user_data)
{ {
g_signal_emit_by_name (OPENVPN_EDITOR (user_data), "changed"); g_signal_emit_by_name (WIREGUARD_EDITOR (user_data), "changed");
}
static void
auth_combo_changed_cb (GtkWidget *combo, gpointer user_data)
{
OpenvpnEditor *self = OPENVPN_EDITOR (user_data);
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (self);
GtkWidget *auth_notebook;
GtkTreeModel *model;
GtkTreeIter iter;
gint new_page = 0;
auth_notebook = GTK_WIDGET (gtk_builder_get_object (priv->builder, "auth_notebook"));
g_assert (auth_notebook);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
g_assert (model);
g_assert (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter));
gtk_tree_model_get (model, &iter, COL_AUTH_PAGE, &new_page, -1);
gtk_notebook_set_current_page (GTK_NOTEBOOK (auth_notebook), new_page);
stuff_changed_cb (combo, self);
}
static void
advanced_dialog_close_cb (GtkWidget *dialog, gpointer user_data)
{
gtk_widget_hide (dialog);
/* gtk_widget_destroy() will remove the window from the window group */
gtk_widget_destroy (dialog);
}
static void
advanced_dialog_response_cb (GtkWidget *dialog, gint response, gpointer user_data)
{
OpenvpnEditor *self = OPENVPN_EDITOR (user_data);
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (self);
GError *error = NULL;
if (response != GTK_RESPONSE_OK) {
advanced_dialog_close_cb (dialog, self);
return;
}
if (priv->advanced)
g_hash_table_destroy (priv->advanced);
priv->advanced = advanced_dialog_new_hash_from_dialog (dialog, &error);
if (!priv->advanced) {
g_message ("%s: error reading advanced settings: %s", __func__, error->message);
g_error_free (error);
}
advanced_dialog_close_cb (dialog, self);
stuff_changed_cb (NULL, self);
}
static void
advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
{
OpenvpnEditor *self = OPENVPN_EDITOR (user_data);
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (self);
GtkWidget *dialog, *toplevel, *widget;
GtkTreeModel *model;
GtkTreeIter iter;
const char *contype = NULL;
gboolean success;
toplevel = gtk_widget_get_toplevel (priv->widget);
g_return_if_fail (gtk_widget_is_toplevel (toplevel));
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "auth_combo"));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
success = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
g_return_if_fail (success == TRUE);
gtk_tree_model_get (model, &iter, COL_AUTH_TYPE, &contype, -1);
dialog = advanced_dialog_new (priv->advanced, contype);
if (!dialog) {
g_warning ("%s: failed to create the Advanced dialog!", __func__);
return;
}
gtk_window_group_add_window (priv->window_group, GTK_WINDOW (dialog));
if (!priv->window_added) {
gtk_window_group_add_window (priv->window_group, GTK_WINDOW (toplevel));
priv->window_added = TRUE;
}
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (advanced_dialog_response_cb), self);
g_signal_connect (G_OBJECT (dialog), "close", G_CALLBACK (advanced_dialog_close_cb), self);
gtk_widget_show_all (dialog);
} }
static gboolean static gboolean
init_editor_plugin (OpenvpnEditor *self, NMConnection *connection, GError **error) init_editor_plugin (WireguardEditor *self, NMConnection *connection, GError **error)
{ {
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (self); WireguardEditorPrivate *priv = WIREGUARD_EDITOR_GET_PRIVATE (self);
NMSettingVpn *s_vpn; NMSettingVpn *s_vpn;
GtkWidget *widget; GtkWidget *widget;
GtkListStore *store;
GtkTreeIter iter;
int active = -1;
const char *value; const char *value;
const char *contype = NM_OPENVPN_CONTYPE_TLS;
s_vpn = nm_connection_get_setting_vpn (connection); s_vpn = nm_connection_get_setting_vpn (connection);
@ -581,149 +465,27 @@ init_editor_plugin (OpenvpnEditor *self, NMConnection *connection, GError **erro
} }
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self); g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
/*
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "auth_combo"));
g_return_val_if_fail (widget != NULL, FALSE);
store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
*/
/*
if (s_vpn) {
contype = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
if (contype) {
if ( strcmp (contype, NM_OPENVPN_CONTYPE_TLS)
&& strcmp (contype, NM_OPENVPN_CONTYPE_STATIC_KEY)
&& strcmp (contype, NM_OPENVPN_CONTYPE_PASSWORD)
&& strcmp (contype, NM_OPENVPN_CONTYPE_PASSWORD_TLS))
contype = NM_OPENVPN_CONTYPE_TLS;
} else
contype = NM_OPENVPN_CONTYPE_TLS;
}
*/
/* TLS auth widget */
/*
tls_pw_init_auth_widget (priv->builder, s_vpn,
NM_OPENVPN_CONTYPE_TLS, "tls",
stuff_changed_cb, self);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_AUTH_NAME, _("Certificates (TLS)"),
COL_AUTH_PAGE, 0,
COL_AUTH_TYPE, NM_OPENVPN_CONTYPE_TLS,
-1);
*/
/* Password auth widget */
/*
tls_pw_init_auth_widget (priv->builder, s_vpn,
NM_OPENVPN_CONTYPE_PASSWORD, "pw",
stuff_changed_cb, self);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_AUTH_NAME, _("Password"),
COL_AUTH_PAGE, 1,
COL_AUTH_TYPE, NM_OPENVPN_CONTYPE_PASSWORD,
-1);
if ((active < 0) && !strcmp (contype, NM_OPENVPN_CONTYPE_PASSWORD))
active = 1;
*/
/* Password+TLS auth widget */
/*
tls_pw_init_auth_widget (priv->builder, s_vpn,
NM_OPENVPN_CONTYPE_PASSWORD_TLS, "pw_tls",
stuff_changed_cb, self);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_AUTH_NAME, _("Password with Certificates (TLS)"),
COL_AUTH_PAGE, 2,
COL_AUTH_TYPE, NM_OPENVPN_CONTYPE_PASSWORD_TLS,
-1);
if ((active < 0) && !strcmp (contype, NM_OPENVPN_CONTYPE_PASSWORD_TLS))
active = 2;
*/
/* Static key auth widget */
/*
sk_init_auth_widget (priv->builder, s_vpn, stuff_changed_cb, self);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_AUTH_NAME, _("Static Key"),
COL_AUTH_PAGE, 3,
COL_AUTH_TYPE, NM_OPENVPN_CONTYPE_STATIC_KEY,
-1);
if ((active < 0) && !strcmp (contype, NM_OPENVPN_CONTYPE_STATIC_KEY))
active = 3;
gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
g_object_unref (store);
g_signal_connect (widget, "changed", G_CALLBACK (auth_combo_changed_cb), self);
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? 0 : active);
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "advanced_button"));
g_signal_connect (G_OBJECT (widget), "clicked", G_CALLBACK (advanced_button_clicked_cb), self);
*/
return TRUE; return TRUE;
} }
static GObject * static GObject *
get_widget (NMVpnEditor *iface) get_widget (NMVpnEditor *iface)
{ {
OpenvpnEditor *self = OPENVPN_EDITOR (iface); WireguardEditor *self = WIREGUARD_EDITOR (iface);
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (self); WireguardEditorPrivate *priv = WIREGUARD_EDITOR_GET_PRIVATE (self);
return G_OBJECT (priv->widget); return G_OBJECT (priv->widget);
} }
static void
hash_copy_advanced (gpointer key, gpointer data, gpointer user_data)
{
NMSettingVpn *s_vpn = NM_SETTING_VPN (user_data);
const char *value = (const char *) data;
g_return_if_fail (value && strlen (value));
/* HTTP Proxy password is a secret, not a data item */
if (!strcmp (key, NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD))
nm_setting_vpn_add_secret (s_vpn, (const char *) key, value);
else
nm_setting_vpn_add_data_item (s_vpn, (const char *) key, value);
}
static char *
get_auth_type (GtkBuilder *builder)
{
GtkComboBox *combo;
GtkTreeModel *model;
GtkTreeIter iter;
char *auth_type = NULL;
gboolean success;
combo = GTK_COMBO_BOX (GTK_WIDGET (gtk_builder_get_object (builder, "auth_combo")));
model = gtk_combo_box_get_model (combo);
success = gtk_combo_box_get_active_iter (combo, &iter);
g_return_val_if_fail (success == TRUE, NULL);
gtk_tree_model_get (model, &iter, COL_AUTH_TYPE, &auth_type, -1);
return auth_type;
}
static gboolean static gboolean
update_connection (NMVpnEditor *iface, update_connection (NMVpnEditor *iface,
NMConnection *connection, NMConnection *connection,
GError **error) GError **error)
{ {
OpenvpnEditor *self = OPENVPN_EDITOR (iface); WireguardEditor *self = WIREGUARD_EDITOR (iface);
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (self); WireguardEditorPrivate *priv = WIREGUARD_EDITOR_GET_PRIVATE (self);
NMSettingVpn *s_vpn; NMSettingVpn *s_vpn;
GtkWidget *widget; GtkWidget *widget;
char *auth_type;
const char *str; const char *str;
gboolean valid = FALSE; gboolean valid = FALSE;
@ -731,7 +493,7 @@ update_connection (NMVpnEditor *iface,
return FALSE; return FALSE;
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_VPN_SERVICE_TYPE_OPENVPN, NULL); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_VPN_SERVICE_TYPE_WIREGUARD, NULL);
// local ip4 // local ip4
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "interface_ip4_entry")); widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "interface_ip4_entry"));
@ -817,46 +579,6 @@ update_connection (NMVpnEditor *iface,
if (str && str[0]) if (str && str[0])
nm_setting_vpn_add_data_item (s_vpn, NM_WG_KEY_ENDPOINT, str); nm_setting_vpn_add_data_item (s_vpn, NM_WG_KEY_ENDPOINT, str);
/*
auth_type = get_auth_type (priv->builder);
if (auth_type) {
nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE, auth_type);
auth_widget_update_connection (priv->builder, auth_type, s_vpn);
g_free (auth_type);
}
*/
/*
if (priv->advanced)
g_hash_table_foreach (priv->advanced, hash_copy_advanced, s_vpn);
*/
/* Default to agent-owned secrets for new connections */
/*
if (priv->new_connection) {
if (nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD)) {
nm_setting_set_secret_flags (NM_SETTING (s_vpn),
NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD,
NM_SETTING_SECRET_FLAG_AGENT_OWNED,
NULL);
}
if (nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_PASSWORD)) {
nm_setting_set_secret_flags (NM_SETTING (s_vpn),
NM_OPENVPN_KEY_PASSWORD,
NM_SETTING_SECRET_FLAG_AGENT_OWNED,
NULL);
}
if (nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_CERTPASS)) {
nm_setting_set_secret_flags (NM_SETTING (s_vpn),
NM_OPENVPN_KEY_CERTPASS,
NM_SETTING_SECRET_FLAG_AGENT_OWNED,
NULL);
}
}
*/
nm_connection_add_setting (connection, NM_SETTING (s_vpn)); nm_connection_add_setting (connection, NM_SETTING (s_vpn));
valid = TRUE; valid = TRUE;
@ -875,28 +597,28 @@ is_new_func (const char *key, const char *value, gpointer user_data)
/*****************************************************************************/ /*****************************************************************************/
static void static void
openvpn_editor_plugin_widget_init (OpenvpnEditor *plugin) wireguard_editor_plugin_widget_init (WireguardEditor *plugin)
{ {
} }
NMVpnEditor * NMVpnEditor *
openvpn_editor_new (NMConnection *connection, GError **error) wireguard_editor_new (NMConnection *connection, GError **error)
{ {
NMVpnEditor *object; NMVpnEditor *object;
OpenvpnEditorPrivate *priv; WireguardEditorPrivate *priv;
gboolean new = TRUE; gboolean new = TRUE;
NMSettingVpn *s_vpn; NMSettingVpn *s_vpn;
if (error) if (error)
g_return_val_if_fail (*error == NULL, NULL); g_return_val_if_fail (*error == NULL, NULL);
object = g_object_new (OPENVPN_TYPE_EDITOR, NULL); object = g_object_new (WIREGUARD_TYPE_EDITOR, NULL);
if (!object) { if (!object) {
g_set_error_literal (error, NMV_EDITOR_PLUGIN_ERROR, 0, _("could not create openvpn object")); g_set_error_literal (error, NMV_EDITOR_PLUGIN_ERROR, 0, "Could not create wireguard object");
return NULL; return NULL;
} }
priv = OPENVPN_EDITOR_GET_PRIVATE (object); priv = WIREGUARD_EDITOR_GET_PRIVATE (object);
priv->builder = gtk_builder_new (); priv->builder = gtk_builder_new ();
@ -923,27 +645,19 @@ openvpn_editor_new (NMConnection *connection, GError **error)
nm_setting_vpn_foreach_data_item (s_vpn, is_new_func, &new); nm_setting_vpn_foreach_data_item (s_vpn, is_new_func, &new);
priv->new_connection = new; priv->new_connection = new;
if (!init_editor_plugin (OPENVPN_EDITOR (object), connection, error)) { if (!init_editor_plugin (WIREGUARD_EDITOR (object), connection, error)) {
g_object_unref (object); g_object_unref (object);
return NULL; return NULL;
} }
/*
priv->advanced = advanced_dialog_new_hash_from_connection (connection, error);
if (!priv->advanced) {
g_object_unref (object);
return NULL;
}
*/
return object; return object;
} }
static void static void
dispose (GObject *object) dispose (GObject *object)
{ {
OpenvpnEditor *plugin = OPENVPN_EDITOR (object); WireguardEditor *plugin = WIREGUARD_EDITOR (object);
OpenvpnEditorPrivate *priv = OPENVPN_EDITOR_GET_PRIVATE (plugin); WireguardEditorPrivate *priv = WIREGUARD_EDITOR_GET_PRIVATE (plugin);
g_clear_object (&priv->window_group); g_clear_object (&priv->window_group);
@ -951,13 +665,11 @@ dispose (GObject *object)
g_clear_object (&priv->builder); g_clear_object (&priv->builder);
g_clear_pointer (&priv->advanced, g_hash_table_destroy); G_OBJECT_CLASS (wireguard_editor_plugin_widget_parent_class)->dispose (object);
G_OBJECT_CLASS (openvpn_editor_plugin_widget_parent_class)->dispose (object);
} }
static void static void
openvpn_editor_plugin_widget_interface_init (NMVpnEditorInterface *iface_class) wireguard_editor_plugin_widget_interface_init (NMVpnEditorInterface *iface_class)
{ {
/* interface implementation */ /* interface implementation */
iface_class->get_widget = get_widget; iface_class->get_widget = get_widget;
@ -965,11 +677,11 @@ openvpn_editor_plugin_widget_interface_init (NMVpnEditorInterface *iface_class)
} }
static void static void
openvpn_editor_plugin_widget_class_init (OpenvpnEditorClass *req_class) wireguard_editor_plugin_widget_class_init (WireguardEditorClass *req_class)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (req_class); GObjectClass *object_class = G_OBJECT_CLASS (req_class);
g_type_class_add_private (req_class, sizeof (OpenvpnEditorPrivate)); g_type_class_add_private (req_class, sizeof (WireguardEditorPrivate));
object_class->dispose = dispose; object_class->dispose = dispose;
} }
@ -981,13 +693,13 @@ openvpn_editor_plugin_widget_class_init (OpenvpnEditorClass *req_class)
#include "nm-wireguard-editor-plugin.h" #include "nm-wireguard-editor-plugin.h"
G_MODULE_EXPORT NMVpnEditor * G_MODULE_EXPORT NMVpnEditor *
nm_vpn_editor_factory_openvpn (NMVpnEditorPlugin *editor_plugin, nm_vpn_editor_factory_wireguard (NMVpnEditorPlugin *editor_plugin,
NMConnection *connection, NMConnection *connection,
GError **error) GError **error)
{ {
g_return_val_if_fail (!error || !*error, NULL); g_return_val_if_fail (!error || !*error, NULL);
return openvpn_editor_new (connection, error); return wireguard_editor_new (connection, error);
} }
#endif #endif

View File

@ -20,30 +20,30 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef __NM_OPENVPN_EDITOR_H__ #ifndef __NM_WIREGUARD_EDITOR_H__
#define __NM_OPENVPN_EDITOR_H__ #define __NM_WIREGUARD_EDITOR_H__
#define OPENVPN_TYPE_EDITOR (openvpn_editor_plugin_widget_get_type ()) #define WIREGUARD_TYPE_EDITOR (wireguard_editor_plugin_widget_get_type ())
#define OPENVPN_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OPENVPN_TYPE_EDITOR, OpenvpnEditor)) #define WIREGUARD_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIREGUARD_TYPE_EDITOR, WireguardEditor))
#define OPENVPN_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OPENVPN_TYPE_EDITOR, OpenvpnEditorClass)) #define WIREGUARD_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIREGUARD_TYPE_EDITOR, WireguardEditorClass))
#define OPENVPN_IS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OPENVPN_TYPE_EDITOR)) #define WIREGUARD_IS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIREGUARD_TYPE_EDITOR))
#define OPENVPN_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OPENVPN_TYPE_EDITOR)) #define WIREGUARD_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIREGUARD_TYPE_EDITOR))
#define OPENVPN_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OPENVPN_TYPE_EDITOR, OpenvpnEditorClass)) #define WIREGUARD_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIREGUARD_TYPE_EDITOR, WireguardEditorClass))
typedef struct _OpenvpnEditor OpenvpnEditor; typedef struct _WireguardEditor WireguardEditor;
typedef struct _OpenvpnEditorClass OpenvpnEditorClass; typedef struct _WireguardEditorClass WireguardEditorClass;
struct _OpenvpnEditor { struct _WireguardEditor {
GObject parent; GObject parent;
}; };
struct _OpenvpnEditorClass { struct _WireguardEditorClass {
GObjectClass parent; GObjectClass parent;
}; };
GType openvpn_editor_plugin_widget_get_type (void); GType wireguard_editor_plugin_widget_get_type (void);
NMVpnEditor *openvpn_editor_new (NMConnection *connection, GError **error); NMVpnEditor *wireguard_editor_new (NMConnection *connection, GError **error);
#endif /* __NM_OPENVPN_EDITOR_H__ */ #endif /* __NM_WIREGUARD_EDITOR_H__ */

View File

@ -116,7 +116,7 @@ _create_plugin (void)
plugin = nm_vpn_editor_plugin_factory (&error); plugin = nm_vpn_editor_plugin_factory (&error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (OPENVPN_IS_EDITOR_PLUGIN (plugin)); g_assert (WIREGUARD_IS_EDITOR_PLUGIN (plugin));
return plugin; return plugin;
} }
#define _CREATE_PLUGIN(plugin) \ #define _CREATE_PLUGIN(plugin) \

View File

@ -763,7 +763,7 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
nm_connection_add_setting (connection, NM_SETTING (s_ip4)); nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ()); s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_VPN_SERVICE_TYPE_OPENVPN, NULL); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_VPN_SERVICE_TYPE_WIREGUARD, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_vpn)); nm_connection_add_setting (connection, NM_SETTING (s_vpn));
/* Get the default path for ca, cert, key file, these files maybe /* Get the default path for ca, cert, key file, these files maybe

View File

@ -22,11 +22,11 @@
#ifndef __NM_SERVICE_DEFINES_H__ #ifndef __NM_SERVICE_DEFINES_H__
#define __NM_SERVICE_DEFINES_H__ #define __NM_SERVICE_DEFINES_H__
#define NM_VPN_SERVICE_TYPE_OPENVPN "org.freedesktop.NetworkManager.wireguard" #define NM_VPN_SERVICE_TYPE_WIREGUARD "org.freedesktop.NetworkManager.wireguard"
#define NM_DBUS_SERVICE_OPENVPN "org.freedesktop.NetworkManager.wireguard" #define NM_DBUS_SERVICE_WIREGUARD "org.freedesktop.NetworkManager.wireguard"
#define NM_DBUS_INTERFACE_OPENVPN "org.freedesktop.NetworkManager.wireguard" #define NM_DBUS_INTERFACE_WIREGUARD "org.freedesktop.NetworkManager.wireguard"
#define NM_DBUS_PATH_OPENVPN "/org/freedesktop/NetworkManager/wireguard" #define NM_DBUS_PATH_WIREGUARD "/org/freedesktop/NetworkManager/wireguard"
#define NM_WG_KEY_ADDR_IP4 "local-ip4" #define NM_WG_KEY_ADDR_IP4 "local-ip4"
#define NM_WG_KEY_ADDR_IP6 "local-ip6" #define NM_WG_KEY_ADDR_IP6 "local-ip6"

View File

@ -609,7 +609,7 @@ main (int argc, char *argv[])
NMWireguardPlugin *plugin; NMWireguardPlugin *plugin;
gboolean persist = FALSE; gboolean persist = FALSE;
GOptionContext *opt_ctx = NULL; GOptionContext *opt_ctx = NULL;
gchar *bus_name = NM_DBUS_SERVICE_OPENVPN; gchar *bus_name = NM_DBUS_SERVICE_WIREGUARD;
GError *error = NULL; GError *error = NULL;
GMainLoop *loop; GMainLoop *loop;