mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 17:15:43 +00:00
system: add get; rename
This commit is contained in:
@@ -6,7 +6,7 @@ use std::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{OSConfig, SystemConfigurator};
|
use super::{SystemConfig, SystemConfigurator};
|
||||||
|
|
||||||
const MAC_RESOLVER_FILE_HEADER: &str = "# Added by easytier\n";
|
const MAC_RESOLVER_FILE_HEADER: &str = "# Added by easytier\n";
|
||||||
const ETC_RESOLVER: &str = "/etc/resolver";
|
const ETC_RESOLVER: &str = "/etc/resolver";
|
||||||
@@ -27,7 +27,7 @@ impl DarwinConfigurator {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do_set_dns(&self, cfg: &OSConfig) -> io::Result<()> {
|
pub fn do_set_dns(&self, cfg: &SystemConfig) -> io::Result<()> {
|
||||||
fs::create_dir_all(ETC_RESOLVER)?;
|
fs::create_dir_all(ETC_RESOLVER)?;
|
||||||
let mut keep = HashSet::new();
|
let mut keep = HashSet::new();
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ impl DarwinConfigurator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SystemConfigurator for DarwinConfigurator {
|
impl SystemConfigurator for DarwinConfigurator {
|
||||||
fn set_dns(&self, cfg: &OSConfig) -> io::Result<()> {
|
fn set_dns(&self, cfg: &SystemConfig) -> io::Result<()> {
|
||||||
self.do_set_dns(cfg)
|
self.do_set_dns(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::utils::BoxExt;
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub mod linux;
|
pub mod linux;
|
||||||
|
|
||||||
@@ -5,16 +7,36 @@ pub mod linux;
|
|||||||
pub mod windows;
|
pub mod windows;
|
||||||
|
|
||||||
#[cfg(all(target_os = "macos", not(feature = "macos-ne")))]
|
#[cfg(all(target_os = "macos", not(feature = "macos-ne")))]
|
||||||
pub mod darwin;
|
pub mod macos;
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct OSConfig {
|
pub struct SystemConfig {
|
||||||
pub nameservers: Vec<String>,
|
pub nameservers: Vec<String>,
|
||||||
pub search_domains: Vec<String>,
|
pub search_domains: Vec<String>,
|
||||||
pub match_domains: Vec<String>,
|
pub match_domains: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SystemConfigurator: Send + Sync + Clone {
|
pub trait SystemConfigurator: Send + Sync {
|
||||||
fn set_dns(&self, cfg: &OSConfig) -> std::io::Result<()>;
|
fn set_dns(&self, cfg: &SystemConfig) -> std::io::Result<()>;
|
||||||
fn clean(&self) -> std::io::Result<()>;
|
fn clean(&self) -> std::io::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move this to nic mod
|
||||||
|
fn get(
|
||||||
|
#[allow(unused_variables)] interface: &str,
|
||||||
|
) -> Result<Option<Box<dyn SystemConfigurator>>, anyhow::Error> {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
use crate::dns::system::windows::WindowsDNSManager;
|
||||||
|
return Ok(Some(WindowsDNSManager::new(interface)?.boxed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(target_os = "macos", not(feature = "macos-ne")))]
|
||||||
|
{
|
||||||
|
use crate::dns::system_config::darwin::DarwinConfigurator;
|
||||||
|
return Ok(Some(DarwinConfigurator::new().boxed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use winreg::RegKey;
|
|||||||
|
|
||||||
use crate::common::ifcfg::RegistryManager;
|
use crate::common::ifcfg::RegistryManager;
|
||||||
|
|
||||||
use super::{OSConfig, SystemConfigurator};
|
use super::{SystemConfig, SystemConfigurator};
|
||||||
|
|
||||||
pub fn is_windows_10_or_better() -> io::Result<bool> {
|
pub fn is_windows_10_or_better() -> io::Result<bool> {
|
||||||
let hklm = winreg::enums::HKEY_LOCAL_MACHINE;
|
let hklm = winreg::enums::HKEY_LOCAL_MACHINE;
|
||||||
@@ -149,7 +149,7 @@ impl WindowsDNSManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SystemConfigurator for WindowsDNSManager {
|
impl SystemConfigurator for WindowsDNSManager {
|
||||||
fn set_dns(&self, cfg: &OSConfig) -> io::Result<()> {
|
fn set_dns(&self, cfg: &SystemConfig) -> io::Result<()> {
|
||||||
self.set_primary_dns(
|
self.set_primary_dns(
|
||||||
&cfg.nameservers
|
&cfg.nameservers
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use super::{
|
|||||||
server::Server,
|
server::Server,
|
||||||
MAGIC_DNS_INSTANCE_ADDR,
|
MAGIC_DNS_INSTANCE_ADDR,
|
||||||
};
|
};
|
||||||
use crate::dns::system::{OSConfig, SystemConfigurator};
|
use crate::dns::system::{SystemConfig, SystemConfigurator};
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{
|
common::{
|
||||||
ifcfg::{IfConfiger, IfConfiguerTrait},
|
ifcfg::{IfConfiger, IfConfiguerTrait},
|
||||||
@@ -155,7 +155,7 @@ impl MagicDnsServerInstanceData {
|
|||||||
|
|
||||||
fn do_system_config(&self, zone: &str) -> Result<(), anyhow::Error> {
|
fn do_system_config(&self, zone: &str) -> Result<(), anyhow::Error> {
|
||||||
if let Some(c) = &self.system_config {
|
if let Some(c) = &self.system_config {
|
||||||
c.set_dns(&OSConfig {
|
c.set_dns(&SystemConfig {
|
||||||
nameservers: vec![self.fake_ip.to_string()],
|
nameservers: vec![self.fake_ip.to_string()],
|
||||||
search_domains: vec![zone.to_string()],
|
search_domains: vec![zone.to_string()],
|
||||||
match_domains: vec![zone.to_string()],
|
match_domains: vec![zone.to_string()],
|
||||||
|
|||||||
Reference in New Issue
Block a user