Merge #1141: installer: add a warning if remote adress is not loopback

3d55616b66e8a0995e2ef9e4ad6d294bf23fe6a7 installer: add a warning if remote adress is not loopback (pythcoiner)

Pull request description:

  This PR is a variant of #1137, it add a warning under text input field if user try to connect to a non-loopback address & use RPCAuth:

  ![image](https://github.com/wizardsardine/liana/assets/124568858/f925f9e1-d212-4b1e-9e58-d40f7633f026)

  It also add a check on address + RPC user/password/cookie:
  Check connection button is greyed out until address is valid + user and password are filled (if RPCAuth selected)

  Closes https://github.com/wizardsardine/liana/issues/1059

ACKs for top commit:
  jp1ac4:
    Tested ACK 3d55616b66.

Tree-SHA512: a48efe85ee178a4bf216a9cc60b03cbb705c6337b1ce21a49bd031a032e2e81e70428fa4cd76c5ee297b428912dc64f51ffc8ce8dfa928b000dcff412ca530db
This commit is contained in:
edouardparis 2024-06-27 09:40:58 +02:00
commit 4f41276fbb
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F
2 changed files with 51 additions and 8 deletions

View File

@ -1,6 +1,6 @@
#[cfg(target_os = "windows")]
use std::io::{self, Cursor};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, TcpListener};
use std::path::PathBuf;
use std::str::FromStr;
@ -415,8 +415,15 @@ impl Step for DefineBitcoind {
message::DefineBitcoind::ConfigFieldEdited(field, value) => match field {
ConfigField::Address => {
self.is_running = None;
self.address.value = value;
self.address.valid = true;
self.address.value.clone_from(&value);
self.address.valid = false;
if let Some((ip, port)) = value.rsplit_once(':') {
let port = u16::from_str(port);
let (ipv4, ipv6) = (Ipv4Addr::from_str(ip), Ipv6Addr::from_str(ip));
if port.is_ok() && (ipv4.is_ok() || ipv6.is_ok()) {
self.address.valid = true;
}
}
}
ConfigField::CookieFilePath => {
self.is_running = None;

View File

@ -1,12 +1,13 @@
use async_hwi::utils::extract_keys_and_template;
use iced::widget::{
checkbox, container, pick_list, radio, scrollable, scrollable::Properties, slider, Space,
TextInput,
checkbox, container, pick_list, radio, scrollable, scrollable::Properties, slider, Button,
Space, TextInput,
};
use iced::{alignment, widget::progress_bar, Alignment, Length};
use async_hwi::DeviceKind;
use liana_ui::component::text;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::path::PathBuf;
use std::{collections::HashSet, str::FromStr};
@ -839,6 +840,17 @@ pub fn define_bitcoin<'a>(
selected_auth_type: &RpcAuthType,
is_running: Option<&Result<(), Error>>,
) -> Element<'a, Message> {
let is_loopback = if let Some((ip, _port)) = address.value.clone().rsplit_once(':') {
let (ipv4, ipv6) = (Ipv4Addr::from_str(ip), Ipv6Addr::from_str(ip));
match (ipv4, ipv6) {
(_, Ok(ip)) => ip.is_loopback(),
(Ok(ip), _) => ip.is_loopback(),
_ => false,
}
} else {
false
};
let col_address = Column::new()
.push(text("Address:").bold())
.push(
@ -852,6 +864,19 @@ pub fn define_bitcoin<'a>(
.size(text::P1_SIZE)
.padding(10),
)
.push_maybe(if !is_loopback && address.valid {
Some(
iced::widget::Text::new(
"Connection to a remote Bitcoin node \
is not supported. Insert an IP address bound to the same machine \
running Liana (ignore this warning if that's already the case)",
)
.style(color::ORANGE)
.size(text::CAPTION_SIZE),
)
} else {
None
})
.spacing(10);
let col_auth = Column::new()
@ -917,6 +942,13 @@ pub fn define_bitcoin<'a>(
})
.spacing(10);
let check_connect_enable = if let RpcAuthType::UserPass = selected_auth_type {
address.valid
&& !rpc_auth_vals.password.value.is_empty()
&& !rpc_auth_vals.user.value.is_empty()
} else {
address.valid && !rpc_auth_vals.cookie_path.value.is_empty()
};
layout(
progress,
"Set up connection to the Bitcoin full node",
@ -951,9 +983,13 @@ pub fn define_bitcoin<'a>(
.spacing(10)
.push(Container::new(
button::secondary(None, "Check connection")
.on_press(Message::DefineBitcoind(
message::DefineBitcoind::PingBitcoind,
))
.on_press_maybe(if check_connect_enable {
Some(Message::DefineBitcoind(
message::DefineBitcoind::PingBitcoind,
))
} else {
None
})
.width(Length::Fixed(200.0)),
))
.push(if is_running.map(|res| res.is_ok()).unwrap_or(false) {