add sbot settings config route
This commit is contained in:
@ -1,31 +1,49 @@
|
|||||||
use maud::{html, PreEscaped};
|
use maud::{html, PreEscaped};
|
||||||
use peach_lib::sbot::SbotStatus;
|
use peach_lib::sbot::{SbotConfig, SbotStatus};
|
||||||
|
|
||||||
use crate::templates;
|
use crate::templates;
|
||||||
|
|
||||||
// TODO: flash message implementation for rouille
|
// TODO: flash message implementation for rouille
|
||||||
//
|
|
||||||
|
|
||||||
/*
|
/// Read the status and configuration of the sbot.
|
||||||
{# ASSIGN VARIABLES #}
|
/// Define fallback values if an error is returned from either read function.
|
||||||
{# ---------------- #}
|
fn read_status_and_config() -> (String, SbotConfig, String, String) {
|
||||||
{%- if sbot_config.hops -%}
|
// retrieve go-sbot systemd process status
|
||||||
{% set hops = sbot_config.hops -%}
|
let run_on_startup = if let Ok(status) = SbotStatus::read() {
|
||||||
{%- else -%}
|
// if the read is ok, return the value or "disabled" if no value is set
|
||||||
{% set hops = "X" -%}
|
match status.boot_state {
|
||||||
{%- endif -%}
|
Some(state) => state,
|
||||||
{%- if sbot_config.lis -%}
|
None => "disabled".to_string(),
|
||||||
{%- set listen_addr = sbot_config.lis | split(pat=":") -%}
|
}
|
||||||
{%- else -%}
|
} else {
|
||||||
{%- set listen_addr = ["", ""] -%}
|
// if the read returns an error, set the value to "disabled"
|
||||||
{%- endif -%}
|
"disabled".to_string()
|
||||||
*/
|
};
|
||||||
|
|
||||||
// TODO: read the sbot config and assign variables accordingly
|
// retrieve sbot config parameters
|
||||||
// pass those variables into the template builder
|
let sbot_config = match SbotConfig::read() {
|
||||||
|
Ok(config) => config,
|
||||||
|
// build default config if an error is returned from the read attempt
|
||||||
|
Err(_) => SbotConfig::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// split the listen address into ip and port
|
||||||
|
let (ip, port) = match sbot_config.lis.find(':') {
|
||||||
|
Some(index) => {
|
||||||
|
let (ip, port) = sbot_config.lis.split_at(index);
|
||||||
|
(ip.to_string(), port.to_string())
|
||||||
|
}
|
||||||
|
// if no ':' separator is found, assume an ip has been configured (without port)
|
||||||
|
None => (sbot_config.lis.to_string(), String::new()),
|
||||||
|
};
|
||||||
|
|
||||||
|
(run_on_startup, sbot_config, ip, port)
|
||||||
|
}
|
||||||
|
|
||||||
/// Scuttlebutt settings menu template builder.
|
/// Scuttlebutt settings menu template builder.
|
||||||
pub fn build() -> PreEscaped<String> {
|
pub fn build() -> PreEscaped<String> {
|
||||||
|
let (run_on_startup, sbot_config, ip, port) = read_status_and_config();
|
||||||
|
|
||||||
let menu_template = html! {
|
let menu_template = html! {
|
||||||
(PreEscaped("<!-- SBOT CONFIGURATION FORM -->"))
|
(PreEscaped("<!-- SBOT CONFIGURATION FORM -->"))
|
||||||
div class="card center" {
|
div class="card center" {
|
||||||
@ -34,7 +52,7 @@ pub fn build() -> PreEscaped<String> {
|
|||||||
label for="hops" class="label-small font-gray" { "HOPS" }
|
label for="hops" class="label-small font-gray" { "HOPS" }
|
||||||
div id="hops" style="display: flex; justify-content: space-evenly;" {
|
div id="hops" style="display: flex; justify-content: space-evenly;" {
|
||||||
div {
|
div {
|
||||||
@if hops == 0 {
|
@if sbot_config.hops == 0 {
|
||||||
input type="radio" id="hops_0" name="hops" value="0" checked;
|
input type="radio" id="hops_0" name="hops" value="0" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_0" name="hops" value="0";
|
input type="radio" id="hops_0" name="hops" value="0";
|
||||||
@ -42,7 +60,7 @@ pub fn build() -> PreEscaped<String> {
|
|||||||
label class="font-normal" for="hops_0" { "0" }
|
label class="font-normal" for="hops_0" { "0" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if hops == 1 {
|
@if sbot_config.hops == 1 {
|
||||||
input type="radio" id="hops_1" name="hops" value="1" checked;
|
input type="radio" id="hops_1" name="hops" value="1" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_1" name="hops" value="1";
|
input type="radio" id="hops_1" name="hops" value="1";
|
||||||
@ -50,7 +68,7 @@ pub fn build() -> PreEscaped<String> {
|
|||||||
label class="font-normal" for="hops_1" { "1" }
|
label class="font-normal" for="hops_1" { "1" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if hops == 2 {
|
@if sbot_config.hops == 2 {
|
||||||
input type="radio" id="hops_2" name="hops" value="2" checked;
|
input type="radio" id="hops_2" name="hops" value="2" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_2" name="hops" value="2";
|
input type="radio" id="hops_2" name="hops" value="2";
|
||||||
@ -58,7 +76,7 @@ pub fn build() -> PreEscaped<String> {
|
|||||||
label class="font-normal" for="hops_2" { "2" }
|
label class="font-normal" for="hops_2" { "2" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if hops == 3 {
|
@if sbot_config.hops == 3 {
|
||||||
input type="radio" id="hops_3" name="hops" value="3" checked;
|
input type="radio" id="hops_3" name="hops" value="3" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_3" name="hops" value="3";
|
input type="radio" id="hops_3" name="hops" value="3";
|
||||||
@ -66,7 +84,7 @@ pub fn build() -> PreEscaped<String> {
|
|||||||
label class="font-normal" for="hops_3" { "3" }
|
label class="font-normal" for="hops_3" { "3" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if hops == 4 {
|
@if sbot_config.hops == 4 {
|
||||||
input type="radio" id="hops_4" name="hops" value="4" checked;
|
input type="radio" id="hops_4" name="hops" value="4" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_4" name="hops" value="4";
|
input type="radio" id="hops_4" name="hops" value="4";
|
||||||
@ -78,20 +96,20 @@ pub fn build() -> PreEscaped<String> {
|
|||||||
div class="center" style="display: flex; justify-content: space-between;" {
|
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" {
|
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" }
|
label for="ip" class="label-small font-gray" { "IP ADDRESS" }
|
||||||
input type="text" id="ip" name="lis_ip" value="{{ listen_addr.0 }}";
|
input type="text" id="ip" name="lis_ip" value=(ip);
|
||||||
}
|
}
|
||||||
div style="display: flex; flex-direction: column; width: 20%; margin-bottom: 2rem;" title="Port on which the sbot runs" {
|
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" }
|
label for="port" class="label-small font-gray" { "PORT" }
|
||||||
input type="text" id="port" name="lis_port" value="{{ listen_addr.1 }}";
|
input type="text" id="port" name="lis_port" value=(port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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" {
|
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" }
|
label for="network_key" class="label-small font-gray" { "NETWORK KEY" }
|
||||||
input type="text" id="network_key" name="shscap" value="{{ sbot_config.shscap }}";
|
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" {
|
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" }
|
label for="database_dir" class="label-small font-gray" { "DATABASE DIRECTORY" }
|
||||||
input type="text" id="database_dir" name="repo" value="{{ sbot_config.repo }}";
|
input type="text" id="database_dir" name="repo" value=(sbot_config.repo);
|
||||||
}
|
}
|
||||||
div class="center" {
|
div class="center" {
|
||||||
@if sbot_config.localadv == true {
|
@if sbot_config.localadv == true {
|
||||||
@ -149,8 +167,3 @@ pub fn build() -> PreEscaped<String> {
|
|||||||
// render the base template with the provided body
|
// render the base template with the provided body
|
||||||
templates::base::build(body)
|
templates::base::build(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
{%- extends "nav" -%}
|
|
||||||
{%- block card %}
|
|
||||||
*/
|
|
Reference in New Issue
Block a user