Commit 5ec5a932 authored by Mohammed Sadiq's avatar Mohammed Sadiq

Add network agent

Network agent is responsible for requesting credentials
when connecting to networks that requires credentials

Fixes #180
parent 27294516
......@@ -115,6 +115,7 @@ libgvc = subproject('gvc',
libgvc_dep = libgvc.get_variable('libgvc_dep')
libnm_dep = dependency('libnm', version: '>= 1.14')
libpolkit_agent_dep = dependency('polkit-agent-1', version: '>= 0.105')
network_agent_dep = dependency('libsecret-1')
subdir('data')
subdir('po')
......
......@@ -57,6 +57,8 @@ phosh_sources = [
'background.h',
'batteryinfo.c',
'batteryinfo.h',
'contrib/shell-network-agent.c',
'contrib/shell-network-agent.h',
'fader.c',
'fader.h',
'home.c',
......@@ -74,6 +76,8 @@ phosh_sources = [
'main.c',
'monitor-manager.c',
'monitor-manager.h',
'network-auth-prompt.c',
'network-auth-prompt.h',
'notification.c',
'notification.h',
'notify-manager.c',
......@@ -134,6 +138,7 @@ phosh_deps = [
libgvc_dep,
libnm_dep,
libpolkit_agent_dep,
network_agent_dep,
cc.find_library('pam', required: true),
cc.find_library('m', required: false),
cc.find_library('rt', required: false),
......
This diff is collapsed.
/*
* Copyright (C) 2019 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#pragma once
#include <gtk/gtk.h>
#include <NetworkManager.h>
#include "layersurface.h"
#define PHOSH_TYPE_NETWORK_AUTH_PROMPT (phosh_network_auth_prompt_get_type())
G_DECLARE_FINAL_TYPE (PhoshNetworkAuthPrompt, phosh_network_auth_prompt, PHOSH, NETWORK_AUTH_PROMPT, PhoshLayerSurface);
GtkWidget *phosh_network_auth_prompt_new (ShellNetworkAgent *agent,
NMClient *nm_client,
gpointer layer_shell,
gpointer wl_output);
void phosh_network_auth_prompt_set_request (PhoshNetworkAuthPrompt *self,
gchar *request_id,
NMConnection *connection,
gchar *setting_name,
gchar **hints,
NMSecretAgentGetSecretsFlags flags);
......@@ -9,6 +9,7 @@
<file preprocess="xml-stripblanks">ui/lockscreen.ui</file>
<file preprocess="xml-stripblanks">ui/notification.ui</file>
<file preprocess="xml-stripblanks">ui/polkit-auth-prompt.ui</file>
<file preprocess="xml-stripblanks">ui/network-auth-prompt.ui</file>
<file preprocess="xml-stripblanks">ui/settings-menu.ui</file>
<file preprocess="xml-stripblanks">ui/system-prompt.ui</file>
<file preprocess="xml-stripblanks">ui/top-panel.ui</file>
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="PhoshNetworkAuthPrompt" parent="PhoshLayerSurface">
<property name="app-paintable">1</property>
<signal name="draw" handler="network_prompt_draw_cb" />
<signal name="key-press-event" handler="network_prompt_key_press_event_cb"/>
<child>
<object class="GtkBox">
<property name="visible">1</property>
<property name="valign">center</property>
<property name="halign">center</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="margin-bottom">32</property>
<property name="orientation">vertical</property>
<style>
<class name="phosh-system-modal-dialog"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="halign">start</property>
<property name="icon_name">dialog-password-symbolic</property>
<property name="icon_size">6</property>
</object>
</child>
<!-- Message Label -->
<child>
<object class="GtkLabel" id="message_label">
<property name="visible">1</property>
<property name="margin-bottom">12</property>
<property name="halign">start</property>
<property name="hexpand">1</property>
<property name="wrap">1</property>
<attributes>
<attribute name="scale" value="1.2"/>
</attributes>
</object>
</child>
<child>
<object class="GtkBox" id="main_box">
<property name="visible">1</property>
<property name="margin-bottom">12</property>
</object>
</child>
<child>
<object class="GtkGrid" id="system_prompt_grid">
<property name="visible">1</property>
<property name="margin-left">20</property>
<property name="margin-right">20</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLabel" id="lbl_info">
<property name="visible">True</property>
<property name="margin_top">12</property>
<property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">1</property>
<property name="margin-top">12</property>
<!-- Cancel button -->
<child>
<object class="GtkButton" id="cancel_button">
<property name="visible">1</property>
<property name="receives-default">0</property>
<property name="hexpand">1</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="use-underline">1</property>
<property name="label" translatable="yes">_Cancel</property>
<signal name="clicked" handler="network_prompt_cancel_clicked_cb" swapped="yes"/>
</object>
</child>
<!-- Connect button -->
<child>
<object class="GtkButton" id="connect_button">
<property name="visible">1</property>
<property name="sensitive">0</property>
<property name="can-default">1</property>
<property name="has-default">1</property>
<property name="receives-default">1</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="use-underline">1</property>
<property name="label" translatable="yes">C_onnect</property>
<signal name="clicked" handler="network_prompt_connect_clicked_cb" swapped="yes"/>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
<!-- Grid to be shown for WEP/WPA passwords -->
<object class="GtkGrid" id="wpa_grid">
<property name="visible">1</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Password:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="wpa_password_entry">
<property name="visible">1</property>
<property name="has-focus">1</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="visibility">0</property>
<property name="invisible-char"></property>
<property name="activates-default">1</property>
<property name="input-purpose">password</property>
<property name="buffer">password_buffer</property>
<signal name="changed" handler="network_prompt_wpa_password_changed_cb" swapped="yes"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<object class="GcrSecureEntryBuffer" id="username_buffer"/>
<object class="GcrSecureEntryBuffer" id="password_buffer"/>
</interface>
......@@ -10,14 +10,23 @@
#include "config.h"
#include "contrib/shell-network-agent.h"
#include "network-auth-prompt.h"
#include "wifimanager.h"
#include "shell.h"
#include "phosh-wayland.h"
#include <NetworkManager.h>
/**
* SECTION:phosh-wifi-manager
* @short_description: Tracks the Wifi status
* @short_description: Tracks the Wifi status and handle wifi credentials entry
* @Title: PhoshWifiManager
*
* Wi-Fi credentials are handled with #ShellNetworkAgent which implements
* #NMSecretAgentOld. When a credential for some wi-fi network is requested,
* A new #PhoshNetworkAuthPrompt is created, which asks the user various
* credentials required depending on the Access point security method.
*/
enum {
......@@ -46,7 +55,8 @@ struct _PhoshWifiManager
NMActiveConnection *active;
/* The wifi device used in the active connection */
NMDeviceWifi *dev;
ShellNetworkAgent *network_agent;
PhoshNetworkAuthPrompt *network_prompt;
};
G_DEFINE_TYPE (PhoshWifiManager, phosh_wifi_manager, G_TYPE_OBJECT);
......@@ -302,6 +312,118 @@ on_nmclient_devices_changed (PhoshWifiManager *self, GParamSpec *pspec, NMClient
}
static void
network_prompt_done_cb (PhoshWifiManager *self)
{
g_return_if_fail (PHOSH_IS_WIFI_MANAGER (self));
if (self->network_prompt)
gtk_widget_hide (GTK_WIDGET (self->network_prompt));
g_clear_pointer ((GtkWidget **)&self->network_prompt, gtk_widget_destroy);
}
static void
network_agent_setup_prompt (PhoshWifiManager *self)
{
PhoshMonitor *primary_monitor;
PhoshWayland *wl = phosh_wayland_get_default ();
PhoshShell *shell = phosh_shell_get_default ();
GtkWidget *network_prompt;
g_return_if_fail (PHOSH_IS_WIFI_MANAGER (self));
if (self->network_prompt)
return;
primary_monitor = phosh_shell_get_primary_monitor (shell);
network_prompt = phosh_network_auth_prompt_new (self->network_agent,
self->nmclient,
phosh_wayland_get_zwlr_layer_shell_v1(wl),
primary_monitor->wl_output);
self->network_prompt = PHOSH_NETWORK_AUTH_PROMPT (network_prompt);
g_signal_connect_object (self->network_prompt, "done",
G_CALLBACK (network_prompt_done_cb),
self, G_CONNECT_SWAPPED);
}
static void
secret_request_new_cb (PhoshWifiManager *self,
gchar *request_id,
NMConnection *connection,
gchar *setting_name,
gchar **hints,
NMSecretAgentGetSecretsFlags flags,
ShellNetworkAgent *agent)
{
g_return_if_fail (PHOSH_IS_WIFI_MANAGER (self));
if (!self->network_prompt)
network_agent_setup_prompt (self);
phosh_network_auth_prompt_set_request (self->network_prompt,
request_id, connection, setting_name,
hints, flags);
gtk_widget_show (GTK_WIDGET (self->network_prompt));
}
static void
secret_request_cancelled_cb (PhoshWifiManager *self,
gchar *request_id,
ShellNetworkAgent *agent)
{
g_return_if_fail (PHOSH_IS_WIFI_MANAGER (self));
g_return_if_fail (SHELL_IS_NETWORK_AGENT (agent));
network_prompt_done_cb (self);
}
static void
secret_agent_register_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
PhoshWifiManager *self = user_data;
NMSecretAgentOld *agent = NM_SECRET_AGENT_OLD (object);
g_autoptr(GError) error = NULL;
g_return_if_fail (PHOSH_IS_WIFI_MANAGER (self));
if (!nm_secret_agent_old_register_finish (agent, result, &error)) {
g_warning ("Error registering network agent: %s", error->message);
return;
}
g_signal_connect_object (self->network_agent, "new-request",
G_CALLBACK (secret_request_new_cb),
self, G_CONNECT_SWAPPED);
g_signal_connect_object (self->network_agent, "cancel-request",
G_CALLBACK (secret_request_cancelled_cb),
self, G_CONNECT_SWAPPED);
}
static void
setup_network_agent (PhoshWifiManager *self)
{
g_autoptr(GError) error = NULL;
g_return_if_fail (PHOSH_IS_WIFI_MANAGER (self));
self->network_agent = g_initable_new (SHELL_TYPE_NETWORK_AGENT, NULL, &error,
"identifier", "sm.puri.phosh.NetworkAgent",
"auto-register", FALSE, NULL);
if (error) {
g_warning ("Error: %s", error->message);
return;
}
nm_secret_agent_old_register_async (NM_SECRET_AGENT_OLD (self->network_agent), NULL,
secret_agent_register_cb, self);
}
static void
on_nm_client_ready (GObject *obj, GAsyncResult *res, gpointer data)
{
......@@ -319,6 +441,7 @@ on_nm_client_ready (GObject *obj, GAsyncResult *res, gpointer data)
g_return_if_fail (NM_IS_CLIENT (self->nmclient));
setup_network_agent (self);
g_signal_connect_swapped (self->nmclient, "notify::wireless-enabled",
G_CALLBACK (on_nmclient_wireless_enabled_changed), self);
g_signal_connect_swapped (self->nmclient, "notify::active-connections",
......@@ -350,6 +473,7 @@ phosh_wifi_manager_finalize (GObject *object)
{
PhoshWifiManager *self = PHOSH_WIFI_MANAGER(object);
g_clear_object (&self->network_agent);
g_clear_object (&self->nmclient);
if (self->ap) {
......
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