cleanup paths and add whitespace
This commit is contained in:
		@ -7,16 +7,12 @@ use rocket::{
 | 
			
		||||
};
 | 
			
		||||
use rocket_dyn_templates::Template;
 | 
			
		||||
 | 
			
		||||
use peach_lib::config_manager;
 | 
			
		||||
use peach_lib::config_manager::load_peach_config;
 | 
			
		||||
use peach_lib::dyndns_client;
 | 
			
		||||
use peach_lib::dyndns_client::{
 | 
			
		||||
    check_is_new_dyndns_domain, get_dyndns_subdomain, get_full_dynamic_domain,
 | 
			
		||||
    is_dns_updater_online,
 | 
			
		||||
use peach_lib::{
 | 
			
		||||
    config_manager, dyndns_client,
 | 
			
		||||
    error::PeachError,
 | 
			
		||||
    jsonrpc_client_core::{Error, ErrorKind},
 | 
			
		||||
    jsonrpc_core::types::error::ErrorCode,
 | 
			
		||||
};
 | 
			
		||||
use peach_lib::error::PeachError;
 | 
			
		||||
use peach_lib::jsonrpc_client_core::{Error, ErrorKind};
 | 
			
		||||
use peach_lib::jsonrpc_core::types::error::ErrorCode;
 | 
			
		||||
 | 
			
		||||
use crate::error::PeachWebError;
 | 
			
		||||
use crate::routes::authentication::Authenticated;
 | 
			
		||||
@ -32,11 +28,12 @@ pub fn save_dns_configuration(dns_form: DnsForm) -> Result<(), PeachWebError> {
 | 
			
		||||
    // first save local configurations
 | 
			
		||||
    config_manager::set_external_domain(&dns_form.external_domain)?;
 | 
			
		||||
    config_manager::set_dyndns_enabled_value(dns_form.enable_dyndns)?;
 | 
			
		||||
 | 
			
		||||
    // if dynamic dns is enabled and this is a new domain name, then register it
 | 
			
		||||
    if dns_form.enable_dyndns {
 | 
			
		||||
        let full_dynamic_domain = get_full_dynamic_domain(&dns_form.dynamic_domain);
 | 
			
		||||
        let full_dynamic_domain = dyndns_client::get_full_dynamic_domain(&dns_form.dynamic_domain);
 | 
			
		||||
        // check if this is a new domain or if its already registered
 | 
			
		||||
        let is_new_domain = check_is_new_dyndns_domain(&full_dynamic_domain)?;
 | 
			
		||||
        let is_new_domain = dyndns_client::check_is_new_dyndns_domain(&full_dynamic_domain)?;
 | 
			
		||||
        if is_new_domain {
 | 
			
		||||
            match dyndns_client::register_domain(&full_dynamic_domain) {
 | 
			
		||||
                Ok(_) => {
 | 
			
		||||
@ -48,19 +45,17 @@ pub fn save_dns_configuration(dns_form: DnsForm) -> Result<(), PeachWebError> {
 | 
			
		||||
                    info!("Failed to register dyndns domain: {:?}", err);
 | 
			
		||||
                    // json response for failed update
 | 
			
		||||
                    let msg: String = match err {
 | 
			
		||||
                        PeachError::JsonRpcClientCore(source) => {
 | 
			
		||||
                            match source {
 | 
			
		||||
                                Error(ErrorKind::JsonRpcError(err), _state) => match err.code {
 | 
			
		||||
                                    ErrorCode::ServerError(-32030) => {
 | 
			
		||||
                                        format!("Error registering domain: {} was previously registered", full_dynamic_domain)
 | 
			
		||||
                                    }
 | 
			
		||||
                                    _ => {
 | 
			
		||||
                                        format!("Failed to register dyndns domain {:?}", err)
 | 
			
		||||
                                    }
 | 
			
		||||
                                },
 | 
			
		||||
                                _ => {
 | 
			
		||||
                                    format!("Failed to register dyndns domain: {:?}", source)
 | 
			
		||||
                                }
 | 
			
		||||
                        PeachError::JsonRpcClientCore(Error(
 | 
			
		||||
                            ErrorKind::JsonRpcError(err),
 | 
			
		||||
                            _state,
 | 
			
		||||
                        )) => {
 | 
			
		||||
                            if let ErrorCode::ServerError(-32030) = err.code {
 | 
			
		||||
                                format!(
 | 
			
		||||
                                    "Error registering domain: {} was previously registered",
 | 
			
		||||
                                    full_dynamic_domain
 | 
			
		||||
                                )
 | 
			
		||||
                            } else {
 | 
			
		||||
                                "Failed to register dyndns domain".to_string()
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        _ => "Failed to register dyndns domain".to_string(),
 | 
			
		||||
@ -92,11 +87,13 @@ pub struct ConfigureDNSContext {
 | 
			
		||||
 | 
			
		||||
impl ConfigureDNSContext {
 | 
			
		||||
    pub fn build() -> ConfigureDNSContext {
 | 
			
		||||
        let peach_config = load_peach_config().unwrap();
 | 
			
		||||
        // TODO: replace `unwrap` with resilient error handling
 | 
			
		||||
        let peach_config = config_manager::load_peach_config().unwrap();
 | 
			
		||||
        let dyndns_fulldomain = peach_config.dyn_domain;
 | 
			
		||||
        let is_dyndns_online = is_dns_updater_online().unwrap();
 | 
			
		||||
        let is_dyndns_online = dyndns_client::is_dns_updater_online().unwrap();
 | 
			
		||||
        let dyndns_subdomain =
 | 
			
		||||
            get_dyndns_subdomain(&dyndns_fulldomain).unwrap_or(dyndns_fulldomain);
 | 
			
		||||
            dyndns_client::get_dyndns_subdomain(&dyndns_fulldomain).unwrap_or(dyndns_fulldomain);
 | 
			
		||||
 | 
			
		||||
        ConfigureDNSContext {
 | 
			
		||||
            external_domain: peach_config.external_domain,
 | 
			
		||||
            dyndns_subdomain,
 | 
			
		||||
@ -113,15 +110,18 @@ impl ConfigureDNSContext {
 | 
			
		||||
#[get("/dns")]
 | 
			
		||||
pub fn configure_dns(flash: Option<FlashMessage>, _auth: Authenticated) -> Template {
 | 
			
		||||
    let mut context = ConfigureDNSContext::build();
 | 
			
		||||
 | 
			
		||||
    // set back icon link to network route
 | 
			
		||||
    context.back = Some("/settings/network".to_string());
 | 
			
		||||
    context.title = Some("Configure DNS".to_string());
 | 
			
		||||
 | 
			
		||||
    // check to see if there is a flash message to display
 | 
			
		||||
    if let Some(flash) = flash {
 | 
			
		||||
        // add flash message contents to the context object
 | 
			
		||||
        context.flash_name = Some(flash.kind().to_string());
 | 
			
		||||
        context.flash_msg = Some(flash.message().to_string());
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    Template::render("settings/network/configure_dns", &context)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -131,20 +131,24 @@ pub fn configure_dns_post(dns: Form<DnsForm>, _auth: Authenticated) -> Template
 | 
			
		||||
    match result {
 | 
			
		||||
        Ok(_) => {
 | 
			
		||||
            let mut context = ConfigureDNSContext::build();
 | 
			
		||||
 | 
			
		||||
            // set back icon link to network route
 | 
			
		||||
            context.back = Some("/settings/network".to_string());
 | 
			
		||||
            context.title = Some("Configure DNS".to_string());
 | 
			
		||||
            context.flash_name = Some("success".to_string());
 | 
			
		||||
            context.flash_msg = Some("New dynamic dns configuration is now enabled".to_string());
 | 
			
		||||
 | 
			
		||||
            Template::render("settings/network/configure_dns", &context)
 | 
			
		||||
        }
 | 
			
		||||
        Err(err) => {
 | 
			
		||||
            let mut context = ConfigureDNSContext::build();
 | 
			
		||||
 | 
			
		||||
            // set back icon link to network route
 | 
			
		||||
            context.back = Some("/settings/network".to_string());
 | 
			
		||||
            context.title = Some("Configure DNS".to_string());
 | 
			
		||||
            context.flash_name = Some("error".to_string());
 | 
			
		||||
            context.flash_msg = Some(format!("Failed to save dns configurations: {}", err));
 | 
			
		||||
 | 
			
		||||
            Template::render("settings/network/configure_dns", &context)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user