Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
indexds committed Feb 2, 2025
1 parent 38da3f2 commit 9b05f7d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
17 changes: 9 additions & 8 deletions sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ CONFIG_LWIP_IP_FORWARD=y
# CONFIG_LWIP_IPV4_NAPT is not set
# CONFIG_LWIP_STATS is not set
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID=y
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
Expand Down Expand Up @@ -1265,14 +1265,14 @@ CONFIG_LWIP_MAX_LISTENING_TCP=16
CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION=y
CONFIG_LWIP_TCP_MAXRTX=12
CONFIG_LWIP_TCP_SYNMAXRTX=12
CONFIG_LWIP_TCP_MSS=1440
CONFIG_LWIP_TCP_TMR_INTERVAL=250
CONFIG_LWIP_TCP_MSS=1460
CONFIG_LWIP_TCP_TMR_INTERVAL=200
CONFIG_LWIP_TCP_MSL=60000
CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT=20000
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5760
CONFIG_LWIP_TCP_WND_DEFAULT=5760
CONFIG_LWIP_TCP_RECVMBOX_SIZE=16
CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE=16
CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE=8
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
CONFIG_LWIP_TCP_OOSEQ_TIMEOUT=6
CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=4
Expand Down Expand Up @@ -1369,8 +1369,9 @@ CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_NONE=y
CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y
# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=512
# CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096
# CONFIG_MBEDTLS_DYNAMIC_BUFFER is not set
# CONFIG_MBEDTLS_DEBUG is not set

Expand Down Expand Up @@ -1848,10 +1849,10 @@ CONFIG_TIMER_QUEUE_LENGTH=10
# CONFIG_HAL_ASSERTION_SILIENT is not set
CONFIG_L2_TO_L3_COPY=y
# CONFIG_ESP_GRATUITOUS_ARP is not set
CONFIG_TCPIP_RECVMBOX_SIZE=32
CONFIG_TCPIP_RECVMBOX_SIZE=64
CONFIG_TCP_MAXRTX=12
CONFIG_TCP_SYNMAXRTX=12
CONFIG_TCP_MSS=1440
CONFIG_TCP_MSS=1460
CONFIG_TCP_MSL=60000
CONFIG_TCP_SND_BUF_DEFAULT=5760
CONFIG_TCP_WND_DEFAULT=5760
Expand Down
13 changes: 10 additions & 3 deletions src/http/index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use base64::prelude::BASE64_STANDARD;
use base64::Engine;

Expand All @@ -10,7 +9,11 @@ use crate::utils::nvs::WgConfig;
const FAVICON_DATA: &[u8] = include_bytes!("./static/assets/favicon.ico");

fn get_value<'a, const N: usize>(remember_me: &'a HeaplessString<8>, value: &'a HeaplessString<N>) -> &'a str {
if remember_me.0.parse::<bool>().unwrap_or(false) { value.as_str() } else { "" }
if remember_me.0.parse::<bool>().unwrap_or(false) {
value.as_str()
} else {
""
}
}

/// Gives the html for the "/" handler, with respect to the current wireguard
Expand Down Expand Up @@ -92,6 +95,10 @@ pub fn index_html(wg_config: &WgConfig) -> anyhow::Result<String> {
port = get_value(&wg_config.remember_me, &wg_config.port),
privkey = get_value(&wg_config.remember_me, &wg_config.client_private_key),
pubkey = get_value(&wg_config.remember_me, &wg_config.server_public_key),
checkstate = if wg_config.remember_me.0.parse::<bool>().unwrap_or(false) { "checked" } else { "" },
checkstate = if wg_config.remember_me.0.parse::<bool>().unwrap_or(false) {
"checked"
} else {
""
},
))
}
14 changes: 7 additions & 7 deletions src/utils/nvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ impl WgConfig {
const DEFAULT_ADDR: &str = "";
const DEFAULT_CLIENT_PRIV: &str = "";
const DEFAULT_PORT: &str = "51820";
const DEFAULT_REMEMBER_ME: &'static str = "false";
const DEFAULT_SERVER_PUB: &str = "";
const PORT: &'static str = "PORT";
const SERVER_PUB: &'static str = "PUBKEY";
const REMEMBER_ME: &'static str = "REMBER";
const DEFAULT_REMEMBER_ME: &'static str = "false";
const SERVER_PUB: &'static str = "PUBKEY";

/// Retrieves and sanitizes a key from nvs.
fn get_key<const N: usize>(nvs: &MutexGuard<'_, EspNvs<NvsDefault>>, key: &str) -> anyhow::Result<String<N>> {
Expand Down Expand Up @@ -63,8 +63,7 @@ impl WgConfig {

if config.remember_me.as_str() == "on" {
nvs.set_str(Self::REMEMBER_ME, "true")?;
}
else {
} else {
nvs.set_str(Self::REMEMBER_ME, "false")?;
}

Expand Down Expand Up @@ -99,11 +98,12 @@ impl WgConfig {
.unwrap_or_else(|_| Self::DEFAULT_SERVER_PUB.try_into().unwrap()),
)
.clean_string(),

remember_me: HeaplessString(WgConfig::get_key::<8>(&nvs, Self::REMEMBER_ME)

remember_me: HeaplessString(
WgConfig::get_key::<8>(&nvs, Self::REMEMBER_ME)
.unwrap_or_else(|_| Self::DEFAULT_REMEMBER_ME.try_into().unwrap()),
)
.clean_string()
.clean_string(),
})
}
}
Expand Down

0 comments on commit 9b05f7d

Please sign in to comment.