mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-17 18:31:29 +03:00
load authorized keys from config
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::env::{self, VarError};
|
use std::env::{self, VarError};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@@ -23,12 +24,12 @@ pub struct ConfigToml {
|
|||||||
pub port: Option<u16>,
|
pub port: Option<u16>,
|
||||||
pub frontend: Option<Frontend>,
|
pub frontend: Option<Frontend>,
|
||||||
pub release_bind: Option<Vec<scancode::Linux>>,
|
pub release_bind: Option<Vec<scancode::Linux>>,
|
||||||
pub pk_path: Option<PathBuf>,
|
pub cert_path: Option<PathBuf>,
|
||||||
pub sk_path: Option<PathBuf>,
|
|
||||||
pub left: Option<TomlClient>,
|
pub left: Option<TomlClient>,
|
||||||
pub right: Option<TomlClient>,
|
pub right: Option<TomlClient>,
|
||||||
pub top: Option<TomlClient>,
|
pub top: Option<TomlClient>,
|
||||||
pub bottom: Option<TomlClient>,
|
pub bottom: Option<TomlClient>,
|
||||||
|
pub authorized_fingerprints: Option<HashMap<String, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
@@ -231,6 +232,7 @@ impl Default for Frontend {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
pub authorized_fingerprints: HashMap<String, String>,
|
||||||
pub capture_backend: Option<CaptureBackend>,
|
pub capture_backend: Option<CaptureBackend>,
|
||||||
pub emulation_backend: Option<EmulationBackend>,
|
pub emulation_backend: Option<EmulationBackend>,
|
||||||
pub frontend: Frontend,
|
pub frontend: Frontend,
|
||||||
@@ -291,7 +293,7 @@ impl Config {
|
|||||||
// --config <file> overrules default location
|
// --config <file> overrules default location
|
||||||
let config_file = args.config.map(PathBuf::from).unwrap_or(config_file);
|
let config_file = args.config.map(PathBuf::from).unwrap_or(config_file);
|
||||||
|
|
||||||
let config_toml = match ConfigToml::new(&config_file) {
|
let mut config_toml = match ConfigToml::new(&config_file) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("{config_file:?}: {e}");
|
log::warn!("{config_file:?}: {e}");
|
||||||
log::warn!("Continuing without config file ...");
|
log::warn!("Continuing without config file ...");
|
||||||
@@ -325,9 +327,15 @@ impl Config {
|
|||||||
|
|
||||||
let cert_path = args
|
let cert_path = args
|
||||||
.cert_path
|
.cert_path
|
||||||
.or(config_toml.as_ref().and_then(|c| c.pk_path.clone()))
|
.or(config_toml.as_ref().and_then(|c| c.cert_path.clone()))
|
||||||
.unwrap_or(config_path.join(CERT_FILE_NAME));
|
.unwrap_or(config_path.join(CERT_FILE_NAME));
|
||||||
|
|
||||||
|
let authorized_fingerprints = config_toml
|
||||||
|
.as_mut()
|
||||||
|
.map(|c| std::mem::take(&mut c.authorized_fingerprints))
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut clients: Vec<(TomlClient, Position)> = vec![];
|
let mut clients: Vec<(TomlClient, Position)> = vec![];
|
||||||
|
|
||||||
if let Some(config_toml) = config_toml {
|
if let Some(config_toml) = config_toml {
|
||||||
@@ -350,6 +358,7 @@ impl Config {
|
|||||||
let test_emulation = args.test_emulation;
|
let test_emulation = args.test_emulation;
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
|
authorized_fingerprints,
|
||||||
capture_backend,
|
capture_backend,
|
||||||
emulation_backend,
|
emulation_backend,
|
||||||
daemon,
|
daemon,
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ impl Service {
|
|||||||
|
|
||||||
let service = Self {
|
let service = Self {
|
||||||
active: Rc::new(Cell::new(None)),
|
active: Rc::new(Cell::new(None)),
|
||||||
authorized_keys: Default::default(),
|
authorized_keys: Arc::new(RwLock::new(config.authorized_fingerprints.clone())),
|
||||||
cert,
|
cert,
|
||||||
public_key_fingerprint,
|
public_key_fingerprint,
|
||||||
config,
|
config,
|
||||||
|
|||||||
Reference in New Issue
Block a user