Compare commits

...
3 Commits
Author SHA1 Message Date
dietrich e4dff0429c cleanup and typos 2024-02-06 16:18:58 +01:00
dietrich bf4dbc5ba7 Update dependencies and fix imports 2024-02-02 20:25:33 +01:00
dietrich bd637cb97d Sliding details 2024-01-21 22:26:03 +01:00
10 changed files with 96 additions and 234 deletions
+6 -3
View File
@@ -3,7 +3,7 @@ name = "sieverman"
version = "0.1.0" version = "0.1.0"
authors = ["Franz Dietrich<dietrich@teilgedanken.de>"] authors = ["Franz Dietrich<dietrich@teilgedanken.de>"]
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" licenses = ["MIT", "Apache-2.0"]
description = "Connect to a Managesieve-Server" description = "Connect to a Managesieve-Server"
documentation = "https://docs.rs/bitflags" documentation = "https://docs.rs/bitflags"
readme = "README.md" readme = "README.md"
@@ -20,7 +20,7 @@ pki-types = { package = "rustls-pki-types", version = "1.0", features = [
"alloc", "alloc",
] } ] }
tokio-rustls = { version = "0.25" } tokio-rustls = { version = "0.25" }
env_logger = "0.10.1" env_logger = "0.11"
log = "0.4.20" log = "0.4.20"
tokio = { version = "1.34.0", features = ["full", "tracing"] } tokio = { version = "1.34.0", features = ["full", "tracing"] }
webpki-roots = "0.26.0" webpki-roots = "0.26.0"
@@ -28,7 +28,10 @@ nom = "7.1.3"
managesieve = { path = "../managesieve" } managesieve = { path = "../managesieve" }
anyhow = "1.0" anyhow = "1.0"
thiserror = "1.0" thiserror = "1.0"
gtk4 = { version = "0.7", features = ["gnome_45", "blueprint"] } gtk = { version = "0.7", package = "gtk4", features = [
"gnome_45",
"blueprint",
] }
serde = { version = "1.0.193", features = ["derive"] } serde = { version = "1.0.193", features = ["derive"] }
libadwaita = { version = "0.5.3", features = ["gtk_v4_10", "v1_4"] } libadwaita = { version = "0.5.3", features = ["gtk_v4_10", "v1_4"] }
gtk-blueprint = "0.2" gtk-blueprint = "0.2"
+62 -38
View File
@@ -2,53 +2,77 @@ using Gtk 4.0;
using Adw 1; using Adw 1;
Adw.ApplicationWindow window { Adw.ApplicationWindow window {
default-width: 900; default-width: 900;
default-height: 500; default-height: 500;
content: Gtk.Box { content: Gtk.Box {
orientation: vertical; orientation: vertical;
Adw.HeaderBar{ Adw.HeaderBar {
title-widget: Adw.WindowTitle { title-widget: Adw.WindowTitle {
title: "Sieverman"; title: "Sieverman";
}; };
Gtk.Button { label: "Neu";} [start]
} Gtk.Button {
Gtk.Box { label: "Neu";
orientation: horizontal; }
vexpand: true; [end]
halign: fill; Gtk.ToggleButton settings_button {
icon-name: "open-menu-symbolic";
active: true;
}
}
Gtk.Label{ Gtk.Box {
label: "Log information"; orientation: horizontal;
hexpand: true; vexpand: true;
halign: fill;
Gtk.Label {
label: "Log information";
hexpand: true;
}
Gtk.Revealer settings_pane {
reveal-child: bind settings_button.active bidirectional;
transition-type: slide_left;
Gtk.ScrolledWindow server_info {
width-request: 100;
Adw.PreferencesPage {
Adw.PreferencesGroup server_settings {
vexpand: true;
valign: center;
title: "Server Information";
description: "The information the server published on connection";
} }
Gtk.ScrolledWindow server_info {
width-request: 100;
Adw.PreferencesPage {
Adw.PreferencesGroup server_settings{
vexpand: true;
valign: center;
title: "Server Information";
description: "The information the server published on connection";
}
Adw.PreferencesGroup credentials {
vexpand: true;
valign: center;
title: "Login Information";
description: "The credentials that will be used to log in.";
Adw.EntryRow{title: "Username:";}
Adw.PasswordEntryRow{title: "Password:";}
}} Adw.PreferencesGroup credentials {
vexpand: true;
valign: center;
title: "Login Information";
description: "The credentials that will be used to log in.";
Adw.EntryRow {
title: "Username:";
}
Adw.PasswordEntryRow {
title: "Password:";
}
} }
}
} }
Gtk.Statusbar{Gtk.Label{ }
label: "Status"; }
}}
}; Gtk.Statusbar {
Gtk.Label {
label: "Status";
}
}
};
} }
+1 -2
View File
@@ -13,8 +13,7 @@ pub(crate) async fn run(
info!("connecting…"); info!("connecting…");
let future_info = info.connect(); let future_info = info.connect();
info!("waiting for the connection to be established"); info!("waiting for the connection to be established");
let mut connected = future_info.await.context("Something went wrong")?; let connected = future_info.await.context("Something went wrong")?;
info!("Fully read the introduction:"); info!("Fully read the introduction:");
to_frontend_tx to_frontend_tx
.send(BackToFront::ServerConnected( .send(BackToFront::ServerConnected(
+13 -15
View File
@@ -1,8 +1,7 @@
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use crate::__COMPILED_BLUEPRINT_MAP__; use crate::__COMPILED_BLUEPRINT_MAP__;
use gtk4::{ use gtk::{
glib,
prelude::{ApplicationExt, GtkWindowExt}, prelude::{ApplicationExt, GtkWindowExt},
Application, Application,
}; };
@@ -18,54 +17,53 @@ pub(crate) fn get_app(
let app = Application::builder() let app = Application::builder()
.application_id("de.teilgedanken.sieverman") .application_id("de.teilgedanken.sieverman")
.build(); .build();
app.connect_activate(move |app| build_ui(app, from_backend_rx.clone())); app.connect_activate(move |app| build_ui(app, from_backend_rx.clone()));
app app
} }
fn build_ui( fn build_ui(
app: &gtk4::Application, app: &gtk::Application,
from_backend_rx: Rc<RefCell<Option<tokio::sync::mpsc::Receiver<BackToFront>>>>, from_backend_rx: Rc<RefCell<Option<tokio::sync::mpsc::Receiver<BackToFront>>>>,
) { ) {
let builder = gtk4::Builder::new(); let builder = gtk::Builder::new();
builder builder
.add_from_string(get_blp!("gui/main_window.blp")) .add_from_string(get_blp!("gui/main_window.blp"))
.expect("Failed to parse blueprint"); .expect("Failed to parse blueprint");
let main_window = builder let main_window = builder
.object::<libadwaita::ApplicationWindow>("window") .object::<libadwaita::ApplicationWindow>("window")
.unwrap(); .unwrap();
let prefrences_group = builder
let preferences_group = builder
.object::<libadwaita::PreferencesGroup>("server_settings") .object::<libadwaita::PreferencesGroup>("server_settings")
.unwrap(); .unwrap();
main_window.set_application(Some(app)); main_window.set_application(Some(app));
let future = { let future = {
let mut data_event_receiver = from_backend_rx.take().expect("data_event_reciver"); let mut data_event_receiver = from_backend_rx.take().expect("data_event_receiver");
async move { async move {
while let Some(event) = data_event_receiver.recv().await { while let Some(event) = data_event_receiver.recv().await {
match event { match event {
BackToFront::ServerConnected(caps) => { BackToFront::ServerConnected(caps) => {
prefrences_group.add(&row_in_settings("Greeting", &caps.implementation)); preferences_group.add(&row_in_settings("Greeting", &caps.implementation));
prefrences_group preferences_group
.add(&row_in_settings("Authentication", &caps.sasl.join(","))); .add(&row_in_settings("Authentication", &caps.sasl.join(",")));
prefrences_group preferences_group
.add(&row_in_settings("Starttls", &caps.starttls.to_string())); .add(&row_in_settings("Starttls", &caps.starttls.to_string()));
prefrences_group.add(&row_in_settings("Version", &caps.version)); preferences_group.add(&row_in_settings("Version", &caps.version));
} }
} }
} }
} }
}; };
let c = glib::MainContext::default(); let c = gtk::glib::MainContext::default();
c.spawn_local(future); c.spawn_local(future);
main_window.present(); main_window.present();
trace!("Window is visible"); trace!("Window is visible");
} }
fn row_in_settings(name: &str, value: &str) -> libadwaita::ActionRow { fn row_in_settings(name: &str, value: &str) -> libadwaita::ActionRow {
let builder = gtk4::Builder::new(); let builder = gtk::Builder::new();
builder builder
.add_from_string(get_blp!("gui/server_info_row.blp")) .add_from_string(get_blp!("gui/server_info_row.blp"))
.expect("Failed to parse blueprint"); .expect("Failed to parse blueprint");
@@ -75,7 +73,7 @@ fn row_in_settings(name: &str, value: &str) -> libadwaita::ActionRow {
.unwrap(); .unwrap();
row.set_title(name); row.set_title(name);
let label = builder let label = builder
.object::<gtk4::Label>("server_info_row_value") .object::<gtk::Label>("server_info_row_value")
.unwrap(); .unwrap();
label.set_label(value); label.set_label(value);
row row
+6 -4
View File
@@ -3,7 +3,7 @@ mod gui;
pub mod protocol; pub mod protocol;
use std::{cell::RefCell, rc::Rc, thread, time::Duration}; use std::{cell::RefCell, rc::Rc, thread, time::Duration};
use gtk4::{glib, prelude::ApplicationExtManual as _}; use gtk::{glib, prelude::ApplicationExtManual as _};
use tracing::{info, trace}; use tracing::{info, trace};
gtk_blueprint::gen_blp_map!("gui"); gtk_blueprint::gen_blp_map!("gui");
@@ -16,10 +16,10 @@ fn main() -> glib::ExitCode {
.server_addr(([127, 0, 0, 1], 6669)) .server_addr(([127, 0, 0, 1], 6669))
.init(); .init();
gtk4::init().expect("Failed to initialize GTK"); gtk::init().expect("Failed to initialize GTK");
libadwaita::init().expect("Adwaita initialization failed"); libadwaita::init().expect("Adwaita initialization failed");
let (to_frontent_tx, from_backend_rx) = tokio::sync::mpsc::channel(5); let (to_frontend_tx, from_backend_rx) = tokio::sync::mpsc::channel(5);
let _handle = thread::spawn(move || { let _handle = thread::spawn(move || {
info!("Running Backend"); info!("Running Backend");
tokio::runtime::Builder::new_current_thread() tokio::runtime::Builder::new_current_thread()
@@ -27,12 +27,14 @@ fn main() -> glib::ExitCode {
.enable_time() .enable_time()
.build() .build()
.unwrap() .unwrap()
.block_on(backend::run::run(to_frontent_tx)) .block_on(backend::run::run(to_frontend_tx))
.expect("Failed to run or interrupted"); .expect("Failed to run or interrupted");
}); });
let app = gui::main_window::get_app(Rc::new(RefCell::new(Some(from_backend_rx)))); let app = gui::main_window::get_app(Rc::new(RefCell::new(Some(from_backend_rx))));
gtk::Window::set_default_icon_name("scanner");
let res = app.run(); let res = app.run();
trace!("End"); trace!("End");
+5 -8
View File
@@ -15,8 +15,6 @@ use tokio_rustls::{
}; };
use tracing::{error, info, trace}; use tracing::{error, info, trace};
pub mod parser;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ConnectionInfo { pub struct ConnectionInfo {
domain: String, domain: String,
@@ -39,7 +37,6 @@ impl ConnectionInfo {
.with_root_certificates(root_store) .with_root_certificates(root_store)
.with_no_client_auth(); .with_no_client_auth();
// Allow using SSLKEYLOGFILE.
config.key_log = Arc::new(KeyLogFile::new()); config.key_log = Arc::new(KeyLogFile::new());
trace!("Creating connector"); trace!("Creating connector");
let connector = TlsConnector::from(Arc::new(config)); let connector = TlsConnector::from(Arc::new(config));
@@ -129,7 +126,7 @@ impl ConnectionConnected {
info!("Buffer is: \n{}", self.buffer.lock().await) info!("Buffer is: \n{}", self.buffer.lock().await)
} }
pub async fn log_server_settings(&self) { pub async fn log_server_settings(&self) {
info!("Serversettings:\n{:?}", self.server_settings) info!("Server settings:\n{:?}", self.server_settings)
} }
pub async fn list_scripts(self) -> anyhow::Result<(Vec<(String, bool)>, Self)> { pub async fn list_scripts(self) -> anyhow::Result<(Vec<(String, bool)>, Self)> {
@@ -147,16 +144,16 @@ impl ConnectionConnected {
.await .await
.context("Failed to write LISTSCRIPTS command")?; .context("Failed to write LISTSCRIPTS command")?;
let scriptslist = loop { let scripts_list = loop {
let mut buf = buffer.lock().await; let mut buf = buffer.lock().await;
trace!("reading new input:\n{}", buf); trace!("reading new input:\n{}", buf);
match managesieve::response_listscripts(&buf.to_string()) { match managesieve::response_listscripts(&buf.to_string()) {
Ok((rest, scriptslist, resp)) => match resp.tag { Ok((rest, scripts_list, resp)) => match resp.tag {
managesieve::OkNoBye::Ok => { managesieve::OkNoBye::Ok => {
buf.clear(); buf.clear();
buf.push_str(rest); buf.push_str(rest);
info!("Read the introduction"); info!("Read the introduction");
break scriptslist; break scripts_list;
} }
managesieve::OkNoBye::No | managesieve::OkNoBye::Bye => { managesieve::OkNoBye::No | managesieve::OkNoBye::Bye => {
trace!("Connection closed!"); trace!("Connection closed!");
@@ -168,7 +165,7 @@ impl ConnectionConnected {
tokio::time::sleep(Duration::from_millis(50)).await; tokio::time::sleep(Duration::from_millis(50)).await;
}; };
Ok(( Ok((
scriptslist, scripts_list,
Self { Self {
writer, writer,
buffer, buffer,
-54
View File
@@ -1,54 +0,0 @@
use std::sync::Arc;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
async fn connect(addr: &str) -> Result<TlsStream<TcpStream>, Box<dyn std::error::Error>> {
let mut root_cert_store = RootCertStore::empty();
for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs") {
root_cert_store.add(cert)
}
let roots = webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.subject_public_key_info,
ta.name_constraints,
)
});
root_cert_store.add_trust_anchors(roots);
let config = ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_cert_store)
.with_no_client_auth();
let connector = TlsConnector::from(Arc::new(config));
let dnsname = ServerName::try_from("www.rust-lang.org").unwrap();
let stream = TcpStream::connect(&addr).await?;
let mut stream = connector.connect(dnsname, stream).await?;
Ok(tls_stream)
}
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let tls_stream = connect("127.0.0.1:8080").await?;
// Send a request to the server
let request = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n";
tls_stream.write_all(request)?;
// Read the response from the server
let mut buf = [0; 1024];
let n = tls_stream.read(&mut buf)?;
println!("{}", String::from_utf8_lossy(&buf[..n]));
Ok(())
}
fn main() {
tokio::runtime::Builder::new()
.threaded_scheduler()
.build()
.unwrap()
.block_on(run());
}
-4
View File
@@ -1,4 +0,0 @@
mod server_config;
mod utils;
pub use server_config::parse_server_config;
-84
View File
@@ -1,84 +0,0 @@
use nom::{
branch::alt,
bytes::complete::is_not,
bytes::complete::tag,
character::{
self,
complete::{alpha1, multispace1},
},
multi::many_m_n,
sequence::preceded,
IResult,
};
use tracing::trace;
use crate::{parser::utils::key_value, Methods, ServerSettings};
fn parse_version(input: &str) -> IResult<&str, Vec<i32>> {
many_m_n(
1,
5,
alt((
character::complete::i32,
preceded(character::complete::char('.'), character::complete::i32),
)),
)(input)
}
fn parse_methods(input: &str) -> IResult<&str, Vec<Methods>> {
let (rem, res) = many_m_n(1, 10, alt((alpha1, preceded(multispace1, alpha1))))(input)?;
let methods = res
.into_iter()
.map(|m| match m {
"PLAIN" => Methods::Plain,
"OAUTHBEARER" => Methods::OAuthbearer,
any => todo!("That method is not yet implemented: {}", any),
})
.collect();
Ok((rem, methods))
}
fn parse_extensions(input: &str) -> IResult<&str, Vec<String>> {
let space_then_word = preceded(tag(" "), is_not(" "));
let word = is_not(" ");
let (rem, res) = many_m_n(1, 200, alt((word, space_then_word)))(input)?;
let extensions = res.into_iter().map(|m| m.to_string()).collect();
Ok((rem, extensions))
}
pub fn parse_server_config(input: &str) -> IResult<&str, ServerSettings> {
let (remain, (_key, implementation)) = key_value(input)?;
trace!("Implementation:# {}", implementation);
let (remain, (_key, version)) = key_value(remain)?;
trace!("{}", version);
let (_, version) = parse_version(version)?;
trace!("Version:# {:?}", version);
let (remain, (_key, sasl)) = key_value(remain)?;
trace!("{}", sasl);
let (_, sasl) = parse_methods(sasl)?;
trace!("SASL:# {:?}", sasl);
let (remain, (_key, capabilities)) = key_value(remain)?;
trace!("{}", capabilities);
let (_, capabilities) = parse_extensions(capabilities)?;
trace!("Extensions:# {:?}", &capabilities);
let (remain, (_key, notify)) = key_value(remain)?;
trace!("{}", notify);
let (_, notify) = parse_extensions(remain)?;
trace!("Notify:# {:?}", &notify);
let (remain, (_key, max_redirects)) = key_value(remain)?;
trace!("{}", max_redirects);
let (_, max_redirects) = character::complete::u32(max_redirects)?;
trace!("Max Redirects:# {}", max_redirects);
IResult::Ok((
remain,
ServerSettings {
implementation: implementation.to_string(),
version,
sasl,
capabilities,
notify,
max_redirects,
},
))
}
-19
View File
@@ -1,19 +0,0 @@
use nom::{
bytes::complete::is_not,
bytes::complete::tag,
character::complete::{multispace0, multispace1},
sequence::{delimited, preceded, separated_pair},
IResult,
};
pub(crate) fn quoted(input: &str) -> IResult<&str, &str> {
preceded(multispace0, delimited(tag("\""), is_not("\n\""), tag("\"")))(input)
}
pub(crate) fn key_value(input: &str) -> IResult<&str, (&str, &str)> {
// note that this is really creating a function, the parser for abc
// vvvvv
// which is then called here, returning an IResult<&str, &str>
// vvvvv
preceded(multispace0, separated_pair(quoted, multispace1, quoted))(input)
}