almost working with tilde
This commit is contained in:
parent
bf05149d93
commit
0e655841f5
@ -155,21 +155,17 @@ impl SbotStatus {
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
// TODO: maybe define as a Path type?
|
// TODO: maybe define as a Path type?
|
||||||
/// Directory path for the log and indexes.
|
/// Directory path for the log and indexes.
|
||||||
pub repo: String,
|
pub database_directory: String,
|
||||||
/// Directory path for writing debug output.
|
|
||||||
pub debugdir: String,
|
|
||||||
/// Secret-handshake app-key (aka. network key).
|
/// Secret-handshake app-key (aka. network key).
|
||||||
pub shscap: String,
|
pub shscap: String,
|
||||||
/// HMAC hash used to sign messages.
|
/// HMAC hash used to sign messages.
|
||||||
pub hmac: String,
|
pub hmac: String,
|
||||||
/// Replication hops (1: friends, 2: friends of friends).
|
/// Replication hops (1: friends, 2: friends of friends).
|
||||||
pub hops: u8,
|
pub replication_hops: u8,
|
||||||
|
/// Ip address of pub
|
||||||
|
pub ip: String,
|
||||||
/// Address to listen on.
|
/// Address to listen on.
|
||||||
pub lis: String,
|
pub ssb_port: String,
|
||||||
/// Address to listen on for WebSocket connections.
|
|
||||||
pub wslis: String,
|
|
||||||
/// Address to for metrics and pprof HTTP server.
|
|
||||||
pub debuglis: String,
|
|
||||||
/// Enable sending local UDP broadcasts.
|
/// Enable sending local UDP broadcasts.
|
||||||
pub localadv: bool,
|
pub localadv: bool,
|
||||||
/// Enable listening for UDP broadcasts and connecting.
|
/// Enable listening for UDP broadcasts and connecting.
|
||||||
@ -182,48 +178,41 @@ pub struct Config {
|
|||||||
pub promisc: bool,
|
pub promisc: bool,
|
||||||
/// Disable the UNIX socket RPC interface.
|
/// Disable the UNIX socket RPC interface.
|
||||||
pub nounixsock: bool,
|
pub nounixsock: bool,
|
||||||
/// Attempt to repair the filesystem before starting.
|
|
||||||
pub repair: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make this real
|
// TODO: make this real
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct SbotConfig {
|
pub struct SbotConfig {
|
||||||
pub repo: String,
|
pub database_directory: String,
|
||||||
pub debugdir: String,
|
|
||||||
pub shscap: String,
|
pub shscap: String,
|
||||||
pub hmac: String,
|
pub hmac: String,
|
||||||
pub hops: i8,
|
pub replication_hops: i8,
|
||||||
pub lis: String,
|
pub ip: String,
|
||||||
pub wslis: String,
|
pub ssb_port: String,
|
||||||
pub debuglis: String,
|
// TODO: below settings have not been configured with tilde
|
||||||
pub localadv: bool,
|
pub localadv: bool,
|
||||||
pub localdiscov: bool,
|
pub localdiscov: bool,
|
||||||
pub enable_ebt: bool,
|
pub enable_ebt: bool,
|
||||||
pub promisc: bool,
|
pub promisc: bool,
|
||||||
pub nounixsock: bool,
|
pub nounixsock: bool,
|
||||||
pub repair: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default configuration values for solar-sbot.
|
/// Default configuration values for solar-sbot.
|
||||||
impl Default for SbotConfig {
|
impl Default for SbotConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
repo: ".ssb-go".to_string(),
|
database_directory: "~/.local/share/tildefriends".to_string(),
|
||||||
debugdir: "".to_string(),
|
|
||||||
shscap: "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=".to_string(),
|
shscap: "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=".to_string(),
|
||||||
hmac: "".to_string(),
|
hmac: "".to_string(),
|
||||||
hops: 1,
|
replication_hops: 1,
|
||||||
lis: ":8008".to_string(),
|
ip: "".to_string(),
|
||||||
wslis: ":8989".to_string(),
|
ssb_port: "8008".to_string(),
|
||||||
debuglis: "localhost:6078".to_string(),
|
|
||||||
localadv: false,
|
localadv: false,
|
||||||
localdiscov: false,
|
localdiscov: false,
|
||||||
enable_ebt: false,
|
enable_ebt: false,
|
||||||
promisc: false,
|
promisc: false,
|
||||||
nounixsock: false,
|
nounixsock: false,
|
||||||
repair: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,7 +222,7 @@ impl SbotConfig {
|
|||||||
pub fn read() -> Result<Self, PeachError> {
|
pub fn read() -> Result<Self, PeachError> {
|
||||||
// determine path of user's solar-sbot config.toml
|
// determine path of user's solar-sbot config.toml
|
||||||
let config_path = format!(
|
let config_path = format!(
|
||||||
"{}/config.toml",
|
"{}/sbot-config.toml",
|
||||||
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -244,16 +233,16 @@ impl SbotConfig {
|
|||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write the given `SbotConfig` to the solar-sbot `config.toml` file.
|
/// Write the given `SbotConfig` to the tilde-sbot `sbot-config.toml` file.
|
||||||
pub fn write(config: SbotConfig) -> Result<(), PeachError> {
|
pub fn write(config: SbotConfig) -> Result<(), PeachError> {
|
||||||
let repo_comment = "# For details about solar-sbot configuration, please visit the repo: https://github.com/cryptoscope/ssb\n".to_string();
|
let repo_comment = "# For details about tilde-sbot configuration, please visit tilde friends documentation\n".to_string();
|
||||||
|
|
||||||
// convert the provided `SbotConfig` instance to a string
|
// convert the provided `SbotConfig` instance to a string
|
||||||
let config_string = toml::to_string(&config)?;
|
let config_string = toml::to_string(&config)?;
|
||||||
|
|
||||||
// determine path of user's solar-sbot config.toml
|
// determine path of user's solar-sbot config.toml
|
||||||
let config_path = format!(
|
let config_path = format!(
|
||||||
"{}/config.toml",
|
"{}/sbot-config.toml",
|
||||||
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -272,20 +261,17 @@ impl SbotConfig {
|
|||||||
|
|
||||||
/// Initialise an sbot client
|
/// Initialise an sbot client
|
||||||
pub async fn init_sbot() -> Result<TildeClient, PeachError> {
|
pub async fn init_sbot() -> Result<TildeClient, PeachError> {
|
||||||
// read sbot config from config.toml
|
|
||||||
let sbot_config = SbotConfig::read().ok();
|
// read sbot config
|
||||||
|
let sbot_config = match SbotConfig::read() {
|
||||||
|
Ok(config) => config,
|
||||||
|
// build default config if an error is returned from the read attempt
|
||||||
|
Err(_) => SbotConfig::default(),
|
||||||
|
};
|
||||||
|
|
||||||
debug!("Initialising an sbot client with configuration parameters");
|
debug!("Initialising an sbot client with configuration parameters");
|
||||||
// initialise sbot connection with ip:port and shscap from config file
|
|
||||||
let key_path = format!(
|
|
||||||
"{}/secret",
|
|
||||||
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
|
||||||
);
|
|
||||||
// TODO: read this from config
|
|
||||||
const SERVER_ADDR: &str = "http://127.0.0.1:3030";
|
|
||||||
let sbot_client = TildeClient {
|
let sbot_client = TildeClient {
|
||||||
name: "name".to_string(),
|
port: sbot_config.ssb_port,
|
||||||
port: "8009".to_string(),
|
|
||||||
binary_path: config_manager::get_config_value("TILDE_BINARY_PATH")?
|
binary_path: config_manager::get_config_value("TILDE_BINARY_PATH")?
|
||||||
};
|
};
|
||||||
Ok(sbot_client)
|
Ok(sbot_client)
|
||||||
|
@ -26,7 +26,7 @@ pub fn handle_route(request: &Request, session_data: &mut Option<SessionData>) -
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set the `.ssb-go` path in order to mount the blob fileserver
|
// set the `.ssb-go` path in order to mount the blob fileserver
|
||||||
let ssb_path = sbot::get_go_ssb_path().expect("define ssb-go dir path");
|
let ssb_path = sbot::get_tilde_ssb_path().expect("define ssb-go dir path");
|
||||||
let blobstore = format!("{}/blobs/sha256", ssb_path);
|
let blobstore = format!("{}/blobs/sha256", ssb_path);
|
||||||
|
|
||||||
// blobstore file server
|
// blobstore file server
|
||||||
|
@ -33,16 +33,8 @@ fn read_status_and_config() -> (String, SbotConfig, String, String) {
|
|||||||
Err(_) => SbotConfig::default(),
|
Err(_) => SbotConfig::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// split the listen address into ip and port
|
let ip = sbot_config.ip.clone();
|
||||||
let (ip, port) = match sbot_config.lis.find(':') {
|
let port = sbot_config.ssb_port.clone();
|
||||||
Some(index) => {
|
|
||||||
let (ip, port) = sbot_config.lis.split_at(index);
|
|
||||||
// remove the : from the port
|
|
||||||
(ip.to_string(), port.replace(':', ""))
|
|
||||||
}
|
|
||||||
// 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)
|
(run_on_startup, sbot_config, ip, port)
|
||||||
}
|
}
|
||||||
@ -52,7 +44,7 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
|||||||
// check for flash cookies; will be (None, None) if no flash cookies are found
|
// check for flash cookies; will be (None, None) if no flash cookies are found
|
||||||
let (flash_name, flash_msg) = request.retrieve_flash();
|
let (flash_name, flash_msg) = request.retrieve_flash();
|
||||||
|
|
||||||
let (run_on_startup, sbot_config, ip, port) = read_status_and_config();
|
let (run_on_startup, sbot_config, ip, ssb_port) = read_status_and_config();
|
||||||
|
|
||||||
let menu_template = html! {
|
let menu_template = html! {
|
||||||
(PreEscaped("<!-- SBOT CONFIGURATION FORM -->"))
|
(PreEscaped("<!-- SBOT CONFIGURATION FORM -->"))
|
||||||
@ -62,42 +54,42 @@ pub fn build_template(request: &Request) -> 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 sbot_config.hops == 0 {
|
@if sbot_config.replication_hops == 0 {
|
||||||
input type="radio" id="hops_0" name="hops" value="0" checked;
|
input type="radio" id="hops_0" name="replication_hops" value="0" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_0" name="hops" value="0";
|
input type="radio" id="hops_0" name="replication_hops" value="0";
|
||||||
}
|
}
|
||||||
label class="font-normal" for="hops_0" { "0" }
|
label class="font-normal" for="hops_0" { "0" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if sbot_config.hops == 1 {
|
@if sbot_config.replication_hops == 1 {
|
||||||
input type="radio" id="hops_1" name="hops" value="1" checked;
|
input type="radio" id="hops_1" name="replication_hops" value="1" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_1" name="hops" value="1";
|
input type="radio" id="hops_1" name="replication_hops" value="1";
|
||||||
}
|
}
|
||||||
label class="font-normal" for="hops_1" { "1" }
|
label class="font-normal" for="hops_1" { "1" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if sbot_config.hops == 2 {
|
@if sbot_config.replication_hops == 2 {
|
||||||
input type="radio" id="hops_2" name="hops" value="2" checked;
|
input type="radio" id="hops_2" name="replication_hops" value="2" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_2" name="hops" value="2";
|
input type="radio" id="hops_2" name="replication_hops" value="2";
|
||||||
}
|
}
|
||||||
label class="font-normal" for="hops_2" { "2" }
|
label class="font-normal" for="hops_2" { "2" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if sbot_config.hops == 3 {
|
@if sbot_config.replication_hops == 3 {
|
||||||
input type="radio" id="hops_3" name="hops" value="3" checked;
|
input type="radio" id="hops_3" name="replication_hops" value="3" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_3" name="hops" value="3";
|
input type="radio" id="hops_3" name="replication_hops" value="3";
|
||||||
}
|
}
|
||||||
label class="font-normal" for="hops_3" { "3" }
|
label class="font-normal" for="hops_3" { "3" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@if sbot_config.hops == 4 {
|
@if sbot_config.replication_hops == 4 {
|
||||||
input type="radio" id="hops_4" name="hops" value="4" checked;
|
input type="radio" id="hops_4" name="replication_hops" value="4" checked;
|
||||||
} @else {
|
} @else {
|
||||||
input type="radio" id="hops_4" name="hops" value="4";
|
input type="radio" id="hops_4" name="replication_hops" value="4";
|
||||||
}
|
}
|
||||||
label class="font-normal" for="hops_4" { "4" }
|
label class="font-normal" for="hops_4" { "4" }
|
||||||
}
|
}
|
||||||
@ -106,11 +98,11 @@ pub fn build_template(request: &Request) -> 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=(ip);
|
input type="text" id="ip" name="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=(port);
|
input type="text" id="port" name="ssb_port" value=(ssb_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" {
|
||||||
@ -119,34 +111,35 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
|||||||
}
|
}
|
||||||
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="database_directory" value=(sbot_config.database_directory);
|
||||||
}
|
}
|
||||||
|
// TODO: re-add these checkboxes, if tilde adds them
|
||||||
div class="center" {
|
div class="center" {
|
||||||
@if sbot_config.enable_ebt {
|
// @if sbot_config.enable_ebt {
|
||||||
input type="checkbox" id="ebtReplication" style="margin-bottom: 1rem;" name="enable_ebt" checked;
|
// input type="checkbox" id="ebtReplication" style="margin-bottom: 1rem;" name="enable_ebt" checked;
|
||||||
} @else {
|
// } @else {
|
||||||
input type="checkbox" id="ebtReplication" style="margin-bottom: 1rem;" name="enable_ebt";
|
// input type="checkbox" id="ebtReplication" style="margin-bottom: 1rem;" name="enable_ebt";
|
||||||
}
|
// }
|
||||||
label class="font-normal" for="ebtReplication" title="Enable Epidemic Broadcast Tree (EBT) replication instead of legacy replication" {
|
// label class="font-normal" for="ebtReplication" title="Enable Epidemic Broadcast Tree (EBT) replication instead of legacy replication" {
|
||||||
"Enable EBT Replication"
|
// "Enable EBT Replication"
|
||||||
}
|
// }
|
||||||
br;
|
// br;
|
||||||
@if sbot_config.localadv {
|
// @if sbot_config.localadv {
|
||||||
input type="checkbox" id="lanBroadcast" style="margin-bottom: 1rem;" name="localadv" checked;
|
// input type="checkbox" id="lanBroadcast" style="margin-bottom: 1rem;" name="localadv" checked;
|
||||||
} @else {
|
// } @else {
|
||||||
input type="checkbox" id="lanBroadcast" style="margin-bottom: 1rem;" name="localadv";
|
// 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" {
|
// 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"
|
// "Enable LAN Broadcasting"
|
||||||
}
|
// }
|
||||||
br;
|
// br;
|
||||||
@if sbot_config.localdiscov {
|
// @if sbot_config.localdiscov {
|
||||||
input type="checkbox" id="lanDiscovery" style="margin-bottom: 1rem;" name="localdiscov" checked;
|
// input type="checkbox" id="lanDiscovery" style="margin-bottom: 1rem;" name="localdiscov" checked;
|
||||||
} @else {
|
// } @else {
|
||||||
input type="checkbox" id="lanDiscovery" style="margin-bottom: 1rem;" name="localdiscov";
|
// 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" }
|
// label class="font-normal" for="lanDiscovery" title="Listen for the presence of local peers and attempt to connect if found" { "Enable LAN Discovery" }
|
||||||
br;
|
// br;
|
||||||
@if run_on_startup == "enabled" {
|
@if run_on_startup == "enabled" {
|
||||||
input type="checkbox" id="startup" style="margin-bottom: 1rem;" name="startup" checked;
|
input type="checkbox" id="startup" style="margin-bottom: 1rem;" name="startup" checked;
|
||||||
} @else {
|
} @else {
|
||||||
@ -154,18 +147,9 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
|||||||
}
|
}
|
||||||
label class="font-normal" for="startup" title="Run the pub automatically on system startup" { "Run pub when computer starts" }
|
label class="font-normal" for="startup" title="Run the pub automatically on system startup" { "Run pub when computer starts" }
|
||||||
br;
|
br;
|
||||||
@if sbot_config.repair {
|
|
||||||
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("<!-- hidden input elements for all other config variables -->"))
|
(PreEscaped("<!-- hidden input elements for all other config variables -->"))
|
||||||
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="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="promisc" name="promisc" value=(sbot_config.promisc);
|
input type="hidden" id="promisc" name="promisc" value=(sbot_config.promisc);
|
||||||
input type="hidden" id="nounixsock" name="nounixsock" value=(sbot_config.nounixsock);
|
input type="hidden" id="nounixsock" name="nounixsock" value=(sbot_config.nounixsock);
|
||||||
(PreEscaped("<!-- BUTTONS -->"))
|
(PreEscaped("<!-- BUTTONS -->"))
|
||||||
@ -196,61 +180,56 @@ pub fn build_template(request: &Request) -> PreEscaped<String> {
|
|||||||
templates::base::build_template(body, theme)
|
templates::base::build_template(body, theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use std::io::Read;
|
||||||
/// Parse the sbot configuration values and write to file.
|
/// Parse the sbot configuration values and write to file.
|
||||||
pub fn handle_form(request: &Request, restart: bool) -> Response {
|
pub fn handle_form(request: &Request, restart: bool) -> Response {
|
||||||
|
|
||||||
// query the request body for form data
|
// query the request body for form data
|
||||||
// return a 400 error if the admin_id field is missing
|
// return a 400 error if the admin_id field is missing
|
||||||
let data = try_or_400!(post_input!(request, {
|
let data = try_or_400!(post_input!(request, {
|
||||||
repo: String,
|
database_directory: String,
|
||||||
debugdir: String,
|
|
||||||
shscap: String,
|
shscap: String,
|
||||||
hmac: String,
|
hmac: String,
|
||||||
hops: i8,
|
replication_hops: i8,
|
||||||
lis_ip: String,
|
ip: String,
|
||||||
lis_port: String,
|
ssb_port: String,
|
||||||
wslis: String,
|
|
||||||
debuglis: String,
|
|
||||||
localadv: bool,
|
localadv: bool,
|
||||||
localdiscov: bool,
|
localdiscov: bool,
|
||||||
enable_ebt: bool,
|
enable_ebt: bool,
|
||||||
promisc: bool,
|
promisc: bool,
|
||||||
nounixsock: bool,
|
nounixsock: bool,
|
||||||
startup: bool,
|
startup: bool,
|
||||||
repair: bool,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// concat the ip and port for listen address
|
// concat the ip and port for listen address
|
||||||
let lis = format!("{}:{}", data.lis_ip, data.lis_port);
|
let lis = format!("{}:{}", data.ip, data.ssb_port);
|
||||||
|
|
||||||
// instantiate `SbotConfig` from form data
|
// instantiate `SbotConfig` from form data
|
||||||
let config = SbotConfig {
|
let config = SbotConfig {
|
||||||
lis,
|
ip: data.ip,
|
||||||
hops: data.hops,
|
ssb_port: data.ssb_port,
|
||||||
repo: data.repo,
|
replication_hops: data.replication_hops,
|
||||||
debugdir: data.debugdir,
|
database_directory: data.database_directory,
|
||||||
shscap: data.shscap,
|
shscap: data.shscap,
|
||||||
localadv: data.localadv,
|
localadv: data.localadv,
|
||||||
localdiscov: data.localdiscov,
|
localdiscov: data.localdiscov,
|
||||||
hmac: data.hmac,
|
hmac: data.hmac,
|
||||||
wslis: data.wslis,
|
|
||||||
debuglis: data.debuglis,
|
|
||||||
enable_ebt: data.enable_ebt,
|
enable_ebt: data.enable_ebt,
|
||||||
promisc: data.promisc,
|
promisc: data.promisc,
|
||||||
nounixsock: data.nounixsock,
|
nounixsock: data.nounixsock,
|
||||||
repair: data.repair,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match data.startup {
|
match data.startup {
|
||||||
true => {
|
true => {
|
||||||
debug!("Enabling go-sbot.service");
|
debug!("Enabling tilde-sbot.service");
|
||||||
if let Err(e) = sbot::systemctl_sbot_cmd("enable") {
|
if let Err(e) = sbot::systemctl_sbot_cmd("enable") {
|
||||||
warn!("Failed to enable go-sbot.service: {}", e)
|
warn!("Failed to enable tilde-sbot.service: {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
debug!("Disabling go-sbot.service");
|
debug!("Disabling tilde-sbot.service");
|
||||||
if let Err(e) = sbot::systemctl_sbot_cmd("disable") {
|
if let Err(e) = sbot::systemctl_sbot_cmd("disable") {
|
||||||
warn!("Failed to disable go-sbot.service: {}", e)
|
warn!("Failed to disable tilde-sbot.service: {}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -102,7 +102,7 @@ fn memory_element(memory: Option<u32>) -> Markup {
|
|||||||
fn hops_element() -> Markup {
|
fn hops_element() -> Markup {
|
||||||
// retrieve go-sbot systemd process status
|
// retrieve go-sbot systemd process status
|
||||||
let hops = match SbotConfig::read() {
|
let hops = match SbotConfig::read() {
|
||||||
Ok(conf) => conf.hops,
|
Ok(conf) => conf.replication_hops,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,11 +66,6 @@ pub fn restart_sbot_process() -> (String, String) {
|
|||||||
/// Initialise an sbot client with the given configuration parameters.
|
/// Initialise an sbot client with the given configuration parameters.
|
||||||
pub async fn init_sbot_client() -> Result<TildeClient, PeachWebError> {
|
pub async fn init_sbot_client() -> Result<TildeClient, PeachWebError> {
|
||||||
debug!("Initialising an sbot client with configuration parameters");
|
debug!("Initialising an sbot client with configuration parameters");
|
||||||
// initialise sbot connection with ip:port and shscap from config file
|
|
||||||
let key_path = format!(
|
|
||||||
"{}/secret.toml",
|
|
||||||
config_manager::get_config_value("TILDE_SBOT_DATADIR")?
|
|
||||||
);
|
|
||||||
let sbot_client = init_sbot().await?;
|
let sbot_client = init_sbot().await?;
|
||||||
Ok(sbot_client)
|
Ok(sbot_client)
|
||||||
}
|
}
|
||||||
@ -154,12 +149,11 @@ pub fn create_invite(uses: u16) -> Result<String, PeachWebError> {
|
|||||||
debug!("Generating Scuttlebutt invite code");
|
debug!("Generating Scuttlebutt invite code");
|
||||||
let mut invite_code = sbot_client.create_invite(uses as i32).await?;
|
let mut invite_code = sbot_client.create_invite(uses as i32).await?;
|
||||||
|
|
||||||
// // TODO: insert domain into invite if one is configured
|
let domain = config_manager::get_config_value("EXTERNAL_DOMAIN")?;
|
||||||
// let domain = config_manager::get_config_value("EXTERNAL_DOMAIN")?;
|
if !domain.is_empty() {
|
||||||
// if !domain.is_empty() {
|
invite_code = domain + &invite_code[4..];
|
||||||
// invite_code = domain + &invite_code[4..];
|
}
|
||||||
// }
|
|
||||||
//
|
|
||||||
Ok(invite_code)
|
Ok(invite_code)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -596,16 +590,16 @@ pub fn publish_private_msg(text: String, recipients: Vec<String>) -> Result<Stri
|
|||||||
|
|
||||||
// FILEPATH FUNCTIONS
|
// FILEPATH FUNCTIONS
|
||||||
|
|
||||||
/// Return the path of the ssb-go directory.
|
/// Return the path of the tilde-sbot directory.
|
||||||
pub fn get_go_ssb_path() -> Result<String, PeachWebError> {
|
pub fn get_tilde_ssb_path() -> Result<String, PeachWebError> {
|
||||||
let go_ssb_path = match SbotConfig::read() {
|
let tilde_ssb_path = match SbotConfig::read() {
|
||||||
Ok(conf) => conf.repo,
|
Ok(conf) => conf.database_directory,
|
||||||
// return the default path if unable to read `config.toml`
|
// return the default path if unable to read `config.toml`
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// determine the home directory
|
// determine the home directory
|
||||||
let mut home_path = dirs::home_dir().ok_or(PeachWebError::HomeDir)?;
|
let mut home_path = dirs::home_dir().ok_or(PeachWebError::HomeDir)?;
|
||||||
// add the go-ssb subdirectory
|
// add the .ssb-tilde subdirectory
|
||||||
home_path.push(".ssb-go");
|
home_path.push(".ssb-tilde");
|
||||||
// convert the PathBuf to a String
|
// convert the PathBuf to a String
|
||||||
home_path
|
home_path
|
||||||
.into_os_string()
|
.into_os_string()
|
||||||
@ -613,12 +607,12 @@ pub fn get_go_ssb_path() -> Result<String, PeachWebError> {
|
|||||||
.map_err(|_| PeachWebError::OsString)?
|
.map_err(|_| PeachWebError::OsString)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(go_ssb_path)
|
Ok(tilde_ssb_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether a blob is in the blobstore.
|
/// Check whether a blob is in the blobstore.
|
||||||
pub async fn blob_is_stored_locally(blob_path: &str) -> Result<bool, PeachWebError> {
|
pub async fn blob_is_stored_locally(blob_path: &str) -> Result<bool, PeachWebError> {
|
||||||
let go_ssb_path = get_go_ssb_path()?;
|
let go_ssb_path = get_tilde_ssb_path()?;
|
||||||
let complete_path = format!("{}/blobs/sha256/{}", go_ssb_path, blob_path);
|
let complete_path = format!("{}/blobs/sha256/{}", go_ssb_path, blob_path);
|
||||||
let blob_exists_locally = Path::new(&complete_path).exists();
|
let blob_exists_locally = Path::new(&complete_path).exists();
|
||||||
Ok(blob_exists_locally)
|
Ok(blob_exists_locally)
|
||||||
|
32
run-tilde-sbot.sh
Executable file
32
run-tilde-sbot.sh
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
CONFIG_FILE="/home/notplants/.local/share/tildefriends/sbot-config.toml"
|
||||||
|
|
||||||
|
# Extract network_key (if it exists)
|
||||||
|
NETWORK_KEY=$(grep -v '^\s*#' "$CONFIG_FILE" | grep -E '^\s*network_key\s*=' | sed -E 's/.*=\s*"?(.*?)"?\s*/\1/')
|
||||||
|
DATABASE_DIRECTORY=$(grep -v '^\s*#' "$CONFIG_FILE" \
|
||||||
|
| grep -E '^\s*database_directory\s*=' \
|
||||||
|
| sed -E 's/.*=\s*"([^"]*)"\s*/\1/')
|
||||||
|
|
||||||
|
# Extract all other key-value pairs except network_key
|
||||||
|
ARGS=$(grep -v '^\s*#' "$CONFIG_FILE" \
|
||||||
|
| grep -E '^\s*[a-zA-Z0-9_.-]+\s*=' \
|
||||||
|
| grep -v '^\s*network_key\s*=' \
|
||||||
|
| sed -E 's/\s*=\s*/=/' \
|
||||||
|
| tr -d '"' \
|
||||||
|
| paste -sd, -)
|
||||||
|
|
||||||
|
echo "ARGS: $ARGS"
|
||||||
|
[ -n "$NETWORK_KEY" ] && echo "NETWORK_KEY: $NETWORK_KEY"
|
||||||
|
[ -n "$DATABASE_DIRECTORY" ] && echo "DATABASE_DIRECTORY: $DATABASE_DIRECTORY"
|
||||||
|
|
||||||
|
CMD="/home/notplants/computer/projects/peachpub/tilde/tildefriends/out/release/tildefriends.standalone run"
|
||||||
|
[ -n "$ARGS" ] && CMD="$CMD -a \"$ARGS\""
|
||||||
|
[ -n "$NETWORK_KEY" ] && CMD="$CMD -k \"$NETWORK_KEY\""
|
||||||
|
[ -n "$DATABASE_DIRECTORY" ] && CMD="$CMD -d \"$DATABASE_DIRECTORY/db.sql\""
|
||||||
|
|
||||||
|
echo "Running command:"
|
||||||
|
echo "$CMD"
|
||||||
|
|
||||||
|
# Execute the command
|
||||||
|
eval $CMD
|
@ -9,7 +9,6 @@ use std::process::{Command, exit};
|
|||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
pub struct TildeClient {
|
pub struct TildeClient {
|
||||||
pub name: String,
|
|
||||||
pub port: String,
|
pub port: String,
|
||||||
pub binary_path: String,
|
pub binary_path: String,
|
||||||
}
|
}
|
||||||
@ -131,7 +130,6 @@ impl TildeClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_invite(&self, num_uses: i32) -> Result<String, TildeError> {
|
pub async fn create_invite(&self, num_uses: i32) -> Result<String, TildeError> {
|
||||||
// TODO: look up ip/domain from config
|
|
||||||
let key = self.whoami().await?;
|
let key = self.whoami().await?;
|
||||||
self.run_tilde_command(vec!["create_invite", "-u", &num_uses.to_string(), "-i", &key, "-p", &self.port, "-a", "127.0.0.1", "-e", "-1"])
|
self.run_tilde_command(vec!["create_invite", "-u", &num_uses.to_string(), "-i", &key, "-p", &self.port, "-a", "127.0.0.1", "-e", "-1"])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user