From 4d06eb167f8586781cba953e57636854b1073d38 Mon Sep 17 00:00:00 2001 From: glyph Date: Sat, 12 Mar 2022 10:36:40 +0200 Subject: [PATCH] incomplete sbot config route --- Cargo.lock | 1 + peach-web/rouille_refactor | 17 +- .../settings/scuttlebutt/configure_sbot.rs | 156 ++++++++++++++++++ .../src/routes/settings/scuttlebutt/mod.rs | 1 + 4 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 peach-web/src/routes/settings/scuttlebutt/configure_sbot.rs diff --git a/Cargo.lock b/Cargo.lock index 6b02ada..6320894 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1774,6 +1774,7 @@ dependencies = [ [[package]] name = "kuska-ssb" version = "0.4.0" +source = "git+https://github.com/mycognosist/ssb.git?branch=private_messages#4ae3e9ea24b828b9f11cb3af6866e8656924b9d0" dependencies = [ "async-std", "async-stream 0.2.1", diff --git a/peach-web/rouille_refactor b/peach-web/rouille_refactor index 3f651c4..e120b0c 100644 --- a/peach-web/rouille_refactor +++ b/peach-web/rouille_refactor @@ -12,8 +12,15 @@ we do not need to be super fast or feature-rich. [ tasks ] - - write the nav and base templates - - get the homepage loading properly - - route handler - - template - - file loading (static assets) + - write the settings route(s) + x menu + x scuttlebutt menu + - configure_sbot + x template + - sbot_config data + + x write the nav and base templates + x get the homepage loading properly + x route handler + x template + x file loading (static assets) diff --git a/peach-web/src/routes/settings/scuttlebutt/configure_sbot.rs b/peach-web/src/routes/settings/scuttlebutt/configure_sbot.rs new file mode 100644 index 0000000..6a5dd17 --- /dev/null +++ b/peach-web/src/routes/settings/scuttlebutt/configure_sbot.rs @@ -0,0 +1,156 @@ +use maud::{html, PreEscaped}; +use peach_lib::sbot::SbotStatus; + +use crate::templates; + +// TODO: flash message implementation for rouille +// + +/* +{# ASSIGN VARIABLES #} + {# ---------------- #} + {%- if sbot_config.hops -%} + {% set hops = sbot_config.hops -%} + {%- else -%} + {% set hops = "X" -%} + {%- endif -%} + {%- if sbot_config.lis -%} + {%- set listen_addr = sbot_config.lis | split(pat=":") -%} + {%- else -%} + {%- set listen_addr = ["", ""] -%} + {%- endif -%} +*/ + +// TODO: read the sbot config and assign variables accordingly +// pass those variables into the template builder + +/// Scuttlebutt settings menu template builder. +pub fn build() -> PreEscaped { + let menu_template = html! { + (PreEscaped("")) + div class="card center" { + form id="sbotConfig" class="center" action="/settings/scuttlebutt/configure" method="post" { + div class="center" style="display: flex; flex-direction: column; margin-bottom: 2rem;" title="Number of hops to replicate" { + label for="hops" class="label-small font-gray" { "HOPS" } + div id="hops" style="display: flex; justify-content: space-evenly;" { + div { + @if hops == 0 { + input type="radio" id="hops_0" name="hops" value="0" checked; + } @else { + input type="radio" id="hops_0" name="hops" value="0"; + } + label class="font-normal" for="hops_0" { "0" } + } + div { + @if hops == 1 { + input type="radio" id="hops_1" name="hops" value="1" checked; + } @else { + input type="radio" id="hops_1" name="hops" value="1"; + } + label class="font-normal" for="hops_1" { "1" } + } + div { + @if hops == 2 { + input type="radio" id="hops_2" name="hops" value="2" checked; + } @else { + input type="radio" id="hops_2" name="hops" value="2"; + } + label class="font-normal" for="hops_2" { "2" } + } + div { + @if hops == 3 { + input type="radio" id="hops_3" name="hops" value="3" checked; + } @else { + input type="radio" id="hops_3" name="hops" value="3"; + } + label class="font-normal" for="hops_3" { "3" } + } + div { + @if hops == 4 { + input type="radio" id="hops_4" name="hops" value="4" checked; + } @else { + input type="radio" id="hops_4" name="hops" value="4"; + } + label class="font-normal" for="hops_4" { "4" } + } + } + } + div class="center" style="display: flex; justify-content: space-between;" { + div style="display: flex; flex-direction: column; width: 60%; margin-bottom: 2rem;" title="IP address on which the sbot runs" { + label for="ip" class="label-small font-gray" { "IP ADDRESS" } + input type="text" id="ip" name="lis_ip" value="{{ listen_addr.0 }}"; + } + div style="display: flex; flex-direction: column; width: 20%; margin-bottom: 2rem;" title="Port on which the sbot runs" { + label for="port" class="label-small font-gray" { "PORT" } + input type="text" id="port" name="lis_port" value="{{ listen_addr.1 }}"; + } + } + div class="center" style="display: flex; flex-direction: column; margin-bottom: 2rem;" title="Network key (aka 'caps key') to define the Scuttleverse in which the sbot operates in" { + label for="network_key" class="label-small font-gray" { "NETWORK KEY" } + input type="text" id="network_key" name="shscap" value="{{ sbot_config.shscap }}"; + } + div class="center" style="display: flex; flex-direction: column; margin-bottom: 2rem;" title="Directory in which the sbot database is saved" { + label for="database_dir" class="label-small font-gray" { "DATABASE DIRECTORY" } + input type="text" id="database_dir" name="repo" value="{{ sbot_config.repo }}"; + } + div class="center" { + @if sbot_config.localadv == true { + input type="checkbox" id="lanBroadcast" style="margin-bottom: 1rem;" name="localadv" checked; + } @else { + input type="checkbox" id="lanBroadcast" style="margin-bottom: 1rem;" name="localadv"; + } + label class="font-normal" for="lanBroadcast" title="Broadcast the IP and port of this sbot instance so that local peers can discovery it and attempt to connect" { + "Enable LAN Broadcasting" + } + br; + @if sbot_config.localdiscov == true { + input type="checkbox" id="lanDiscovery" style="margin-bottom: 1rem;" name="localdiscov" checked; + } @else { + input type="checkbox" id="lanDiscovery" style="margin-bottom: 1rem;" name="localdiscov"; + } + label class="font-normal" for="lanDiscovery" title="Listen for the presence of local peers and attempt to connect if found" { "Enable LAN Discovery" } + br; + @if run_on_startup == "enabled" { + input type="checkbox" id="startup" style="margin-bottom: 1rem;" name="startup" checked; + } @else { + input type="checkbox" id="startup" style="margin-bottom: 1rem;" name="startup"; + } + label class="font-normal" for="startup" title="Run the pub automatically on system startup" { "Run pub when computer starts" } + br; + @if sbot_config.repair == true { + input type="checkbox" id="repair" name="repair" checked; + } @else { + input type="checkbox" id="repair" name="repair"; + } + label class="font-normal" for="repair" title="Attempt to repair the filesystem when starting the pub" { "Attempt filesystem repair when pub starts" } + } + (PreEscaped("")) + input type="hidden" id="debugdir" name="debugdir" value=(sbot_config.debugdir); + input type="hidden" id="hmac" name="hmac" value=(sbot_config.hmac); + input type="hidden" id="wslis" name="wslis" value=(sbot_config.wslis); + input type="hidden" id="debuglis" name="debuglis" value=(sbot_config.debuglis); + input type="hidden" id="enable_ebt" name="enable_ebt" value=(sbot_config.enable_ebt); + input type="hidden" id="promisc" name="promisc" value=(sbot_config.promisc); + input type="hidden" id="nounixsock" name="nounixsock" value=(sbot_config.nounixsock); + (PreEscaped("")) + input id="saveConfig" class="button button-primary center" style="margin-top: 2rem;" type="submit" title="Save configuration parameters to file" value="Save"; + input id="saveRestartConfig" class="button button-primary center" type="submit" title="Save configuration parameters to file and then (re)start the pub" value="Save & Restart" formaction="/settings/scuttlebutt/configure?restart=true"; + a id="restoreDefaults" class="button button-warning center" href="/settings/scuttlebutt/configure/default" title="Restore default configuration parameters and save them to file" { "Restore Defaults" } + } + (PreEscaped("")) + // TODO: flash message + } + }; + + // wrap the nav bars around the settings menu template content + // parameters are template, title and back url + let body = templates::nav::build(menu_template, "Scuttlebutt Settings", Some("/settings")); + + // render the base template with the provided body + templates::base::build(body) +} + +/* +{%- extends "nav" -%} +{%- block card %} + */ diff --git a/peach-web/src/routes/settings/scuttlebutt/mod.rs b/peach-web/src/routes/settings/scuttlebutt/mod.rs index b9a0e3e..a87cc1a 100644 --- a/peach-web/src/routes/settings/scuttlebutt/mod.rs +++ b/peach-web/src/routes/settings/scuttlebutt/mod.rs @@ -1 +1,2 @@ +pub mod configure_sbot; pub mod menu;