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