feat(network): support for eap peap networks
This commit is contained in:
parent
4f1ef57fe2
commit
31afd3fa8b
4 changed files with 265 additions and 129 deletions
|
|
@ -34,11 +34,14 @@ use zbus::Connection;
|
|||
use crate::{
|
||||
config, fl,
|
||||
network_manager::{
|
||||
active_conns::active_conns_subscription, available_wifi::AccessPoint,
|
||||
current_networks::ActiveConnectionInfo, devices::devices_subscription,
|
||||
hw_address::HwAddress, network_manager_subscription,
|
||||
wireless_enabled::wireless_enabled_subscription, NetworkManagerEvent,
|
||||
NetworkManagerRequest, NetworkManagerState,
|
||||
active_conns::active_conns_subscription,
|
||||
available_wifi::{AccessPoint, NetworkType},
|
||||
current_networks::ActiveConnectionInfo,
|
||||
devices::devices_subscription,
|
||||
hw_address::HwAddress,
|
||||
network_manager_subscription,
|
||||
wireless_enabled::wireless_enabled_subscription,
|
||||
NetworkManagerEvent, NetworkManagerRequest, NetworkManagerState,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -50,6 +53,7 @@ pub fn run() -> cosmic::iced::Result {
|
|||
enum NewConnectionState {
|
||||
EnterPassword {
|
||||
access_point: AccessPoint,
|
||||
identity: String,
|
||||
password: String,
|
||||
password_hidden: bool,
|
||||
},
|
||||
|
|
@ -235,6 +239,7 @@ pub(crate) enum Message {
|
|||
SelectWirelessAccessPoint(AccessPoint),
|
||||
CancelNewConnection,
|
||||
Password(String),
|
||||
Identity(String),
|
||||
SubmitPassword,
|
||||
Frame(Instant),
|
||||
Token(TokenUpdate),
|
||||
|
|
@ -331,41 +336,57 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
success,
|
||||
req,
|
||||
} => {
|
||||
if let NetworkManagerRequest::SelectAccessPoint(ssid, hw_address) = &req {
|
||||
let conn_match = self
|
||||
.new_connection
|
||||
.as_ref()
|
||||
.map(|c| c.ssid() == ssid && c.hw_address() == *hw_address)
|
||||
.unwrap_or_default();
|
||||
if conn_match && success {
|
||||
if let Some(s) =
|
||||
state.active_conns.iter_mut().find(|ap| &ap.name() == ssid && ap.hw_address() == *hw_address)
|
||||
{
|
||||
match s {
|
||||
ActiveConnectionInfo::WiFi { state, .. } => {
|
||||
*state = ActiveConnectionState::Activated;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
if let NetworkManagerRequest::SelectAccessPoint(
|
||||
ssid,
|
||||
hw_address,
|
||||
_network_type,
|
||||
) = &req
|
||||
{
|
||||
let conn_match = self
|
||||
.new_connection
|
||||
.as_ref()
|
||||
.map(|c| c.ssid() == ssid && c.hw_address() == *hw_address)
|
||||
.unwrap_or_default();
|
||||
|
||||
if conn_match && success {
|
||||
if let Some(s) = state
|
||||
.active_conns
|
||||
.iter_mut()
|
||||
.find(|ap| &ap.name() == ssid && ap.hw_address() == *hw_address)
|
||||
{
|
||||
match s {
|
||||
ActiveConnectionInfo::WiFi { state, .. } => {
|
||||
*state = ActiveConnectionState::Activated;
|
||||
}
|
||||
self.failed_known_ssids.remove(ssid);
|
||||
self.new_connection = None;
|
||||
self.show_visible_networks = false;
|
||||
} else if !matches!(
|
||||
&self.new_connection,
|
||||
Some(NewConnectionState::EnterPassword { .. })
|
||||
)
|
||||
{
|
||||
self.failed_known_ssids.insert(ssid.clone());
|
||||
}
|
||||
} else if let NetworkManagerRequest::Password(ssid, _, hw_address) = &req {
|
||||
if let Some(NewConnectionState::Waiting(access_point)) =
|
||||
self.new_connection.clone()
|
||||
{
|
||||
if !success && ssid == &access_point.ssid && *hw_address == access_point.hw_address {
|
||||
self.new_connection =
|
||||
Some(NewConnectionState::Failure(access_point.clone()));
|
||||
} else {
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
self.failed_known_ssids.remove(ssid);
|
||||
self.new_connection = None;
|
||||
self.show_visible_networks = false;
|
||||
} else if !matches!(
|
||||
&self.new_connection,
|
||||
Some(NewConnectionState::EnterPassword { .. })
|
||||
) {
|
||||
self.failed_known_ssids.insert(ssid.clone());
|
||||
}
|
||||
} else if let NetworkManagerRequest::Authenticate {
|
||||
ssid,
|
||||
identity: _,
|
||||
password: _,
|
||||
hw_address,
|
||||
} = &req
|
||||
{
|
||||
if let Some(NewConnectionState::Waiting(access_point)) =
|
||||
self.new_connection.clone()
|
||||
{
|
||||
if !success
|
||||
&& ssid == &access_point.ssid
|
||||
&& *hw_address == access_point.hw_address
|
||||
{
|
||||
self.new_connection =
|
||||
Some(NewConnectionState::Failure(access_point.clone()));
|
||||
} else {
|
||||
self.new_connection = None;
|
||||
self.show_visible_networks = false;
|
||||
}
|
||||
|
|
@ -412,13 +433,19 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint(
|
||||
access_point.ssid.clone(),
|
||||
access_point.hw_address,
|
||||
access_point.network_type,
|
||||
));
|
||||
|
||||
self.new_connection = Some(NewConnectionState::EnterPassword {
|
||||
access_point,
|
||||
password: String::new(),
|
||||
password_hidden: true,
|
||||
});
|
||||
if matches!(access_point.network_type, NetworkType::Open) {
|
||||
self.new_connection = Some(NewConnectionState::Waiting(access_point));
|
||||
} else {
|
||||
self.new_connection = Some(NewConnectionState::EnterPassword {
|
||||
access_point,
|
||||
identity: String::new(),
|
||||
password: String::new(),
|
||||
password_hidden: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
Message::ToggleVisibleNetworks => {
|
||||
self.new_connection = None;
|
||||
|
|
@ -450,19 +477,24 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
if let Some(NewConnectionState::EnterPassword {
|
||||
password,
|
||||
access_point,
|
||||
identity,
|
||||
..
|
||||
}) = self.new_connection.take()
|
||||
{
|
||||
let _ = tx.unbounded_send(NetworkManagerRequest::Password(
|
||||
access_point.ssid.clone(),
|
||||
password,
|
||||
access_point.hw_address,
|
||||
));
|
||||
let is_enterprise: bool = matches!(access_point.network_type, NetworkType::EAP);
|
||||
|
||||
let _ = tx.unbounded_send(NetworkManagerRequest::Authenticate {
|
||||
ssid: access_point.ssid.clone(),
|
||||
identity: is_enterprise.then(|| identity.clone()),
|
||||
password: password,
|
||||
hw_address: access_point.hw_address,
|
||||
});
|
||||
self.new_connection
|
||||
.replace(NewConnectionState::Waiting(access_point));
|
||||
};
|
||||
}
|
||||
Message::ActivateKnownWifi(ssid, hw_address) => {
|
||||
let mut network_type = NetworkType::Open;
|
||||
let tx = if let Some(tx) = self.nm_sender.as_ref() {
|
||||
if let Some(ap) = self
|
||||
.nm_state
|
||||
|
|
@ -470,14 +502,18 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.iter_mut()
|
||||
.find(|c| c.ssid == ssid && c.hw_address == hw_address)
|
||||
{
|
||||
network_type = ap.network_type;
|
||||
ap.working = true;
|
||||
}
|
||||
tx
|
||||
} else {
|
||||
return Task::none();
|
||||
};
|
||||
let _ =
|
||||
tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint(ssid, hw_address));
|
||||
let _ = tx.unbounded_send(NetworkManagerRequest::SelectAccessPoint(
|
||||
ssid,
|
||||
hw_address,
|
||||
network_type,
|
||||
));
|
||||
}
|
||||
Message::CancelNewConnection => {
|
||||
self.new_connection = None;
|
||||
|
|
@ -570,6 +606,13 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
cosmic::app::Action::Surface(a),
|
||||
));
|
||||
}
|
||||
Message::Identity(new_identity) => {
|
||||
if let Some(NewConnectionState::EnterPassword { identity, .. }) =
|
||||
&mut self.new_connection
|
||||
{
|
||||
*identity = new_identity;
|
||||
}
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -964,6 +1007,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
match new_conn_state {
|
||||
NewConnectionState::EnterPassword {
|
||||
access_point,
|
||||
identity,
|
||||
password,
|
||||
password_hidden,
|
||||
} => {
|
||||
|
|
@ -978,30 +1022,38 @@ impl cosmic::Application for CosmicNetworkApplet {
|
|||
.spacing(12),
|
||||
);
|
||||
content = content.push(id);
|
||||
let enter_password_col = column![
|
||||
text::body(fl!("enter-password")),
|
||||
text_input::secure_input(
|
||||
"",
|
||||
password,
|
||||
Some(Message::TogglePasswordVisibility),
|
||||
*password_hidden,
|
||||
|
||||
let is_enterprise = matches!(access_point.network_type, NetworkType::EAP);
|
||||
let enter_password_col = column![]
|
||||
.push_maybe(is_enterprise.then(|| text::body(fl!("identity"))))
|
||||
.push_maybe(is_enterprise.then(|| {
|
||||
text_input::text_input("", identity).on_input(Message::Identity)
|
||||
}))
|
||||
.push(text::body(fl!("enter-password")))
|
||||
.push(
|
||||
text_input::secure_input(
|
||||
"",
|
||||
password,
|
||||
Some(Message::TogglePasswordVisibility),
|
||||
*password_hidden,
|
||||
)
|
||||
.on_input(Message::Password)
|
||||
.on_paste(Message::Password)
|
||||
.on_submit(|_| Message::SubmitPassword),
|
||||
)
|
||||
.on_input(Message::Password)
|
||||
.on_paste(Message::Password)
|
||||
.on_submit(|_| Message::SubmitPassword)
|
||||
]
|
||||
.push_maybe(
|
||||
access_point
|
||||
.wps_push
|
||||
.then(|| container(text::body(fl!("router-wps-button"))).padding(8)),
|
||||
)
|
||||
.push(
|
||||
row![
|
||||
button::standard(fl!("cancel")).on_press(Message::CancelNewConnection),
|
||||
button::suggested(fl!("connect")).on_press(Message::SubmitPassword)
|
||||
]
|
||||
.spacing(24),
|
||||
);
|
||||
.push_maybe(
|
||||
access_point.wps_push.then(|| {
|
||||
container(text::body(fl!("router-wps-button"))).padding(8)
|
||||
}),
|
||||
)
|
||||
.push(
|
||||
row![
|
||||
button::standard(fl!("cancel"))
|
||||
.on_press(Message::CancelNewConnection),
|
||||
button::suggested(fl!("connect")).on_press(Message::SubmitPassword)
|
||||
]
|
||||
.spacing(24),
|
||||
);
|
||||
let col =
|
||||
padded_control(enter_password_col.spacing(8).align_x(Alignment::Center))
|
||||
.align_x(Alignment::Center);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue