|
Packit Service |
d328f3 |
// SPDX-License-Identifier: GPL-2.0+
|
|
Packit Service |
d328f3 |
/* NetworkManager Connection editor -- Connection editor for NetworkManager
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* Rodrigo Moya <rodrigo@gnome-db.org>
|
|
Packit Service |
d328f3 |
*
|
|
Packit Service |
d328f3 |
* Copyright 2004 - 2018 Red Hat, Inc.
|
|
Packit Service |
d328f3 |
*/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#include "nm-default.h"
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#include <string.h>
|
|
Packit Service |
d328f3 |
#include <stdlib.h>
|
|
Packit Service |
d328f3 |
#include <signal.h>
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#include <glib-unix.h>
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#include "nm-connection-list.h"
|
|
Packit Service |
d328f3 |
#include "nm-connection-editor.h"
|
|
Packit Service |
d328f3 |
#include "connection-helpers.h"
|
|
Packit Service |
d328f3 |
#include "vpn-helpers.h"
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
#define CONNECTION_LIST_TAG "nm-connection-list"
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gboolean nm_ce_keep_above;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/*************************************************/
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static void
|
|
Packit Service |
d328f3 |
editor_created (NMConnectionList *list, gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
g_application_release (G_APPLICATION (user_data));
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static gboolean
|
|
Packit Service |
d328f3 |
handle_arguments (GApplication *application,
|
|
Packit Service |
d328f3 |
const char *type,
|
|
Packit Service |
d328f3 |
gboolean create,
|
|
Packit Service |
d328f3 |
gboolean show,
|
|
Packit Service |
d328f3 |
const char *edit_uuid,
|
|
Packit Service |
d328f3 |
const char *import)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
NMConnectionList *list = g_object_get_data (G_OBJECT (application), CONNECTION_LIST_TAG);
|
|
Packit Service |
d328f3 |
gboolean show_list = TRUE;
|
|
Packit Service |
d328f3 |
GType ctype = 0;
|
|
Packit Service |
d328f3 |
gs_free char *type_tmp = NULL;
|
|
Packit Service |
d328f3 |
const char *p, *detail = NULL;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
if (type) {
|
|
Packit Service |
d328f3 |
p = strchr (type, ':');
|
|
Packit Service |
d328f3 |
if (p) {
|
|
Packit Service |
d328f3 |
type = type_tmp = g_strndup (type, p - type);
|
|
Packit Service |
d328f3 |
detail = p + 1;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
ctype = nm_setting_lookup_type (type);
|
|
Packit Service |
d328f3 |
if (ctype == 0 && !p) {
|
|
Packit Service |
d328f3 |
gs_free char *service_type = NULL;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/* allow using the VPN name directly, without "vpn:" prefix. */
|
|
Packit Service |
d328f3 |
service_type = nm_vpn_plugin_info_list_find_service_type (vpn_get_plugin_infos (), type);
|
|
Packit Service |
d328f3 |
if (service_type) {
|
|
Packit Service |
d328f3 |
ctype = NM_TYPE_SETTING_VPN;
|
|
Packit Service |
d328f3 |
detail = type;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
if (ctype == 0) {
|
|
Packit Service |
d328f3 |
g_warning ("Unknown connection type '%s'", type);
|
|
Packit Service |
d328f3 |
return TRUE;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
if (show) {
|
|
Packit Service |
d328f3 |
/* Just show the given connection type page */
|
|
Packit Service |
d328f3 |
nm_connection_list_set_type (list, ctype);
|
|
Packit Service |
d328f3 |
} else if (create) {
|
|
Packit Service |
d328f3 |
g_application_hold (application);
|
|
Packit Service |
d328f3 |
if (!ctype)
|
|
Packit Service |
d328f3 |
nm_connection_list_add (list, editor_created, application);
|
|
Packit Service |
d328f3 |
else
|
|
Packit Service |
d328f3 |
nm_connection_list_create (list, ctype, detail, NULL,
|
|
Packit Service |
d328f3 |
editor_created, application);
|
|
Packit Service |
d328f3 |
show_list = FALSE;
|
|
Packit Service |
d328f3 |
} else if (import) {
|
|
Packit Service |
d328f3 |
/* import */
|
|
Packit Service |
d328f3 |
g_application_hold (application);
|
|
Packit Service |
d328f3 |
nm_connection_list_create (list, ctype, detail, import,
|
|
Packit Service |
d328f3 |
editor_created, application);
|
|
Packit Service |
d328f3 |
show_list = FALSE;
|
|
Packit Service |
d328f3 |
} else if (edit_uuid) {
|
|
Packit Service |
d328f3 |
/* Show the edit dialog for the given UUID */
|
|
Packit Service |
d328f3 |
nm_connection_list_edit (list, edit_uuid);
|
|
Packit Service |
d328f3 |
show_list = FALSE;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
return show_list;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static gboolean
|
|
Packit Service |
d328f3 |
signal_handler (gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
GApplication *application = G_APPLICATION (user_data);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
g_message ("Caught signal shutting down...");
|
|
Packit Service |
d328f3 |
g_application_quit (application);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
return G_SOURCE_REMOVE;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static void
|
|
Packit Service |
d328f3 |
create_activated (GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
GApplication *application = G_APPLICATION (user_data);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
handle_arguments (application, NULL, TRUE, FALSE, NULL, NULL);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static void
|
|
Packit Service |
d328f3 |
quit_activated (GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
GApplication *application = G_APPLICATION (user_data);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
g_application_quit (application);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static GActionEntry app_entries[] =
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
{ "create", create_activated, NULL, NULL, NULL },
|
|
Packit Service |
d328f3 |
{ "quit", quit_activated, NULL, NULL, NULL },
|
|
Packit Service |
d328f3 |
};
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static void
|
|
Packit Service |
d328f3 |
new_editor_cb (NMConnectionList *list, NMConnectionEditor *new_editor, gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
GtkApplication *app = GTK_APPLICATION (user_data);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
gtk_application_add_window (app, nm_connection_editor_get_window (new_editor));
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static void
|
|
Packit Service |
d328f3 |
list_visible_cb (NMConnectionList *list, GParamSpec *pspec, gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
GtkApplication *app = GTK_APPLICATION (user_data);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
if (gtk_widget_get_visible (GTK_WIDGET (list)))
|
|
Packit Service |
d328f3 |
gtk_application_add_window (app, GTK_WINDOW (list));
|
|
Packit Service |
d328f3 |
else
|
|
Packit Service |
d328f3 |
gtk_application_remove_window (app, GTK_WINDOW (list));
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static void
|
|
Packit Service |
d328f3 |
editor_startup (GApplication *application, gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
GtkApplication *app = GTK_APPLICATION (application);
|
|
Packit Service |
d328f3 |
NMConnectionList *list;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries,
|
|
Packit Service |
d328f3 |
G_N_ELEMENTS (app_entries), app);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
list = nm_connection_list_new ();
|
|
Packit Service |
d328f3 |
if (!list) {
|
|
Packit Service |
d328f3 |
g_warning ("Failed to initialize the UI, exiting...");
|
|
Packit Service |
d328f3 |
g_application_quit (application);
|
|
Packit Service |
d328f3 |
return;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
g_object_set_data_full (G_OBJECT (application), CONNECTION_LIST_TAG, g_object_ref (list), g_object_unref);
|
|
Packit Service |
d328f3 |
g_signal_connect_object (list, NM_CONNECTION_LIST_NEW_EDITOR, G_CALLBACK (new_editor_cb), application, 0);
|
|
Packit Service |
d328f3 |
g_signal_connect_object (list, "notify::visible", G_CALLBACK (list_visible_cb), application, 0);
|
|
Packit Service |
d328f3 |
g_signal_connect (list, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static void
|
|
Packit Service |
d328f3 |
editor_activate (GApplication *application, gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
NMConnectionList *list = g_object_get_data (G_OBJECT (application), CONNECTION_LIST_TAG);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
nm_connection_list_present (list);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
static gint
|
|
Packit Service |
d328f3 |
editor_command_line (GApplication *application,
|
|
Packit Service |
d328f3 |
GApplicationCommandLine *command_line,
|
|
Packit Service |
d328f3 |
gpointer user_data)
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
gchar **argv;
|
|
Packit Service |
d328f3 |
gint argc;
|
|
Packit Service |
d328f3 |
GOptionContext *opt_ctx = NULL;
|
|
Packit Service |
d328f3 |
GError *error = NULL;
|
|
Packit Service |
d328f3 |
gs_free char *type = NULL, *uuid = NULL, *import = NULL;
|
|
Packit Service |
d328f3 |
gboolean create = FALSE, show = FALSE;
|
|
Packit Service |
d328f3 |
int ret = 1;
|
|
Packit Service |
d328f3 |
GOptionEntry entries[] = {
|
|
Packit Service |
d328f3 |
{ "type", 't', 0, G_OPTION_ARG_STRING, &type, "Type of connection to show or create", NM_SETTING_WIRED_SETTING_NAME },
|
|
Packit Service |
d328f3 |
{ "create", 'c', 0, G_OPTION_ARG_NONE, &create, "Create a new connection", NULL },
|
|
Packit Service |
d328f3 |
{ "show", 's', 0, G_OPTION_ARG_NONE, &show, "Show a given connection type page", NULL },
|
|
Packit Service |
d328f3 |
{ "edit", 'e', 0, G_OPTION_ARG_STRING, &uuid, "Edit an existing connection with a given UUID", "UUID" },
|
|
Packit Service |
d328f3 |
{ "import", 'i', 0, G_OPTION_ARG_STRING, &import, "Import a VPN connection from given file", NULL },
|
|
Packit Service |
d328f3 |
{ NULL }
|
|
Packit Service |
d328f3 |
};
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
argv = g_application_command_line_get_arguments (command_line, &argc);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
opt_ctx = g_option_context_new (NULL);
|
|
Packit Service |
d328f3 |
g_option_context_set_summary (opt_ctx, "Allows users to view and edit network connection settings");
|
|
Packit Service |
d328f3 |
g_option_context_add_main_entries (opt_ctx, entries, NULL);
|
|
Packit Service |
d328f3 |
if (!g_option_context_parse (opt_ctx, &argc, &argv, &error)) {
|
|
Packit Service |
d328f3 |
g_application_command_line_printerr (command_line, "Failed to parse options: %s\n", error->message);
|
|
Packit Service |
d328f3 |
g_error_free (error);
|
|
Packit Service |
d328f3 |
goto out;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
/* Just one page for both CDMA & GSM, handle that here */
|
|
Packit Service |
d328f3 |
if (g_strcmp0 (type, NM_SETTING_CDMA_SETTING_NAME) == 0) {
|
|
Packit Service |
d328f3 |
g_free (type);
|
|
Packit Service |
d328f3 |
type = g_strdup (NM_SETTING_GSM_SETTING_NAME);
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
if (handle_arguments (application, type, create, show, uuid, import))
|
|
Packit Service |
d328f3 |
g_application_activate (application);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
ret = 0;
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
out:
|
|
Packit Service |
d328f3 |
g_option_context_free (opt_ctx);
|
|
Packit Service |
d328f3 |
return ret;
|
|
Packit Service |
d328f3 |
}
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
int
|
|
Packit Service |
d328f3 |
main (int argc, char *argv[])
|
|
Packit Service |
d328f3 |
{
|
|
Packit Service |
d328f3 |
gs_unref_object GtkApplication *app = NULL;
|
|
Packit Service |
d328f3 |
GOptionContext *opt_ctx;
|
|
Packit Service |
d328f3 |
GOptionEntry entries[] = {
|
|
Packit Service |
d328f3 |
/* This is not passed over D-Bus. */
|
|
Packit Service |
d328f3 |
{ "keep-above", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &nm_ce_keep_above, NULL, NULL },
|
|
Packit Service |
d328f3 |
{ NULL }
|
|
Packit Service |
d328f3 |
};
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
bindtextdomain (GETTEXT_PACKAGE, NMALOCALEDIR);
|
|
Packit Service |
d328f3 |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
Packit Service |
d328f3 |
textdomain (GETTEXT_PACKAGE);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
app = gtk_application_new ("org.gnome.nm_connection_editor",
|
|
Packit Service |
d328f3 |
G_APPLICATION_HANDLES_COMMAND_LINE);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
opt_ctx = g_option_context_new (NULL);
|
|
Packit Service |
d328f3 |
g_option_context_add_main_entries (opt_ctx, entries, NULL);
|
|
Packit Service |
d328f3 |
g_option_context_set_help_enabled (opt_ctx, FALSE);
|
|
Packit Service |
d328f3 |
g_option_context_set_ignore_unknown_options (opt_ctx, TRUE);
|
|
Packit Service |
d328f3 |
g_option_context_parse (opt_ctx, &argc, &argv, NULL);
|
|
Packit Service |
d328f3 |
g_option_context_free (opt_ctx);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
g_signal_connect (app, "startup", G_CALLBACK (editor_startup), NULL);
|
|
Packit Service |
d328f3 |
g_signal_connect (app, "activate", G_CALLBACK (editor_activate), NULL);
|
|
Packit Service |
d328f3 |
g_signal_connect (app, "command-line", G_CALLBACK (editor_command_line), NULL);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
g_unix_signal_add (SIGTERM, signal_handler, app);
|
|
Packit Service |
d328f3 |
g_unix_signal_add (SIGINT, signal_handler, app);
|
|
Packit Service |
d328f3 |
|
|
Packit Service |
d328f3 |
return g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit Service |
d328f3 |
}
|