diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | build.rs | 23 | ||||
-rw-r--r-- | src/config.rs | 57 | ||||
-rw-r--r-- | src/main.rs | 61 | ||||
-rw-r--r-- | static/style.css | 2 | ||||
-rw-r--r-- | templates/head.html | 31 | ||||
-rw-r--r-- | templates/incoming.html | 6 | ||||
-rw-r--r-- | templates/send.html | 6 | ||||
-rw-r--r-- | templates/settings.html | 6 |
10 files changed, 166 insertions, 28 deletions
@@ -270,7 +270,6 @@ dependencies = [ "axum", "log", "serde", - "serde_json", "simple_logger", "sqlx", "tokio", @@ -13,7 +13,6 @@ axum = "0.7" simple_logger = "4.3" log = "0.4" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" toml = "0.8" sqlx = { version = "0.7", features = [ "runtime-tokio-rustls", "sqlite"]} tokio = { version = "1", features = ["full"] } @@ -5,15 +5,20 @@ fn main() { let input = format!("{dir}/style.css"); let output = format!("{dir}/static/style.css"); - let result = std::process::Command::new("tailwindcss") + match std::process::Command::new("tailwindcss") .args(["-m", "--input", &input, "--output", &output]) .output() - .expect("Unable to generate css"); - - if !result.status.success() { - let error = String::from_utf8_lossy(&result.stderr); - println!("cargo:warning=tailwind returned {}", result.status); - println!("cargo:warning=Unable to build CSS !"); - println!("cargo:warning=Output: {error}"); - } + { + Ok(result) => { + if !result.status.success() { + let error = String::from_utf8_lossy(&result.stderr); + println!("cargo:warning=tailwindcss returned {}", result.status); + println!("cargo:warning=Unable to build CSS !"); + println!("cargo:warning=Output: {error}"); + } + }, + Err(e) => { + println!("cargo:warning=Could not run tailwindcss: {}", e); + }, + } } diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..51bf507 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,57 @@ +use std::fs; +use anyhow::Context; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone)] +pub struct FelinetConfig { + pub enabled: bool, + pub address: String, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct TunnelConfig { + pub enabled: bool, + pub local_ip: String, + pub netmask: String, +} + +type DurationSeconds = std::num::NonZeroU32; + +#[derive(Serialize, Deserialize, Clone)] +pub struct BeaconConfig { + pub period_seconds: Option<DurationSeconds>, + #[serde(default)] + pub max_hops: u8, + pub latitude: Option<f64>, + pub longitude: Option<f64>, + pub altitude: Option<f64>, + pub comment: Option<String>, + pub antenna_height: Option<u8>, + pub antenna_gain: Option<f32>, + pub tx_power: Option<f32>, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct Config { + pub callsign: String, + pub ssid: u8, + #[serde(default)] + pub icon: u16, + pub felinet: FelinetConfig, + pub beacon: BeaconConfig, + pub tunnel: Option<TunnelConfig>, +} + +const CONFIGFILE : &str = "node-config.toml"; + +impl Config { + pub fn load() -> anyhow::Result<Self> { + let file_contents = fs::read_to_string(CONFIGFILE)?; + toml::from_str(&file_contents).context("parsing config file") + } + + pub fn store(&self) -> anyhow::Result<()> { + fs::write(CONFIGFILE, toml::to_string_pretty(&self)?) + .context("writing config file") + } +} diff --git a/src/main.rs b/src/main.rs index 1850e66..cab477c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,8 @@ use axum::{ use sqlx::{Connection, SqliteConnection}; use tower_http::services::ServeDir; +mod config; + struct AppState { callsign : String, db : Mutex<SqliteConnection> @@ -20,6 +22,9 @@ type SharedState = Arc<AppState>; #[tokio::main] async fn main() -> std::io::Result<()> { + + // simple_logger:: + let mut conn = SqliteConnection::connect("sqlite:cats-radio-node.db").await.unwrap(); sqlx::migrate!() .run(&mut conn) @@ -35,6 +40,9 @@ async fn main() -> std::io::Result<()> { let app = Router::new() .route("/", get(dashboard)) + .route("/incoming", get(incoming)) + .route("/send", get(send)) + .route("/settings", get(settings)) .route("/form", get(show_form).post(accept_form)) .nest_service("/static", ServeDir::new("static")) /* requires tracing and tower, e.g. @@ -70,6 +78,7 @@ enum ActivePage { Dashboard, Incoming, Send, + Settings, } #[derive(Template)] @@ -80,9 +89,7 @@ struct DashboardTemplate<'a> { callsign: String, } -async fn dashboard( - State(state): State<SharedState>, - ) -> DashboardTemplate<'static> { +async fn dashboard(State(state): State<SharedState>) -> DashboardTemplate<'static> { DashboardTemplate { title: "Dashboard", callsign: state.callsign.clone(), @@ -90,6 +97,54 @@ async fn dashboard( } } +#[derive(Template)] +#[template(path = "incoming.html")] +struct IncomingTemplate<'a> { + title: &'a str, + page: ActivePage, + callsign: String, +} + +async fn incoming(State(state): State<SharedState>) -> IncomingTemplate<'static> { + IncomingTemplate { + title: "Incoming", + callsign: state.callsign.clone(), + page: ActivePage::Incoming, + } +} + +#[derive(Template)] +#[template(path = "send.html")] +struct SendTemplate<'a> { + title: &'a str, + page: ActivePage, + callsign: String, +} + +async fn send(State(state): State<SharedState>) -> SendTemplate<'static> { + SendTemplate { + title: "Send", + callsign: state.callsign.clone(), + page: ActivePage::Send, + } +} + +#[derive(Template)] +#[template(path = "settings.html")] +struct SettingsTemplate<'a> { + title: &'a str, + page: ActivePage, + callsign: String, +} + +async fn settings(State(state): State<SharedState>) -> SettingsTemplate<'static> { + SettingsTemplate { + title: "Settings", + callsign: state.callsign.clone(), + page: ActivePage::Settings, + } +} + async fn show_form() -> Html<&'static str> { Html( r#" diff --git a/static/style.css b/static/style.css index 0998844..5b5b8df 100644 --- a/static/style.css +++ b/static/style.css @@ -1 +1 @@ -/*! tailwindcss v3.3.5 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }html{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));font-family:sans-serif}.flex{display:flex}.h-full{height:100%}.min-h-screen{min-height:100vh}.w-60{width:15rem}.flex-auto{flex:1 1 auto}.flex-none{flex:none}.items-center{align-items:center}.space-x-3>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-right:calc(.75rem*var(--tw-space-x-reverse));margin-left:calc(.75rem*(1 - var(--tw-space-x-reverse)))}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.25rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem*var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.divide-gray-300>:not([hidden])~:not([hidden]){--tw-divide-opacity:1;border-color:rgb(209 213 219/var(--tw-divide-opacity))}.rounded-md{border-radius:.375rem}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}.p-2{padding:.5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.pb-4{padding-bottom:1rem}.pt-2{padding-top:.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.font-semibold{font-weight:600}.text-gray-800{--tw-text-opacity:1;color:rgb(31 41 55/var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}h1{font-size:1.125rem;line-height:1.75rem}h1,h2{font-weight:700}
\ No newline at end of file +/*! tailwindcss v3.3.5 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }html{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));font-family:sans-serif}.m-2{margin:.5rem}.flex{display:flex}.h-full{height:100%}.min-h-screen{min-height:100vh}.w-60{width:15rem}.w-8{width:2rem}.flex-auto{flex:1 1 auto}.flex-none{flex:none}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.25rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem*var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.divide-sky-300>:not([hidden])~:not([hidden]){--tw-divide-opacity:1;border-color:rgb(125 211 252/var(--tw-divide-opacity))}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.bg-sky-100{--tw-bg-opacity:1;background-color:rgb(224 242 254/var(--tw-bg-opacity))}.bg-sky-200{--tw-bg-opacity:1;background-color:rgb(186 230 253/var(--tw-bg-opacity))}.bg-sky-300{--tw-bg-opacity:1;background-color:rgb(125 211 252/var(--tw-bg-opacity))}.p-2{padding:.5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.pb-4{padding-bottom:1rem}.pt-2{padding-top:.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.font-semibold{font-weight:600}.text-sky-800{--tw-text-opacity:1;color:rgb(7 89 133/var(--tw-text-opacity))}.text-sky-900{--tw-text-opacity:1;color:rgb(12 74 110/var(--tw-text-opacity))}h1{font-size:1.125rem;line-height:1.75rem}h1,h2{font-weight:700}.hover\:bg-sky-300:hover{--tw-bg-opacity:1;background-color:rgb(125 211 252/var(--tw-bg-opacity))}
\ No newline at end of file diff --git a/templates/head.html b/templates/head.html index 0d7d2bc..f15487c 100644 --- a/templates/head.html +++ b/templates/head.html @@ -11,27 +11,32 @@ <body> <div class="flex"> <nav class="flex-none"> - <div class="h-full min-h-screen p-3 space-y-2 w-60 bg-gray-100 text-gray-800"> - <div class="p-3 space-y-2 bg-gray-100 text-gray-800"> + <div class="h-full min-h-screen p-3 space-y-2 w-60 bg-sky-100 text-sky-800"> + <div class="p-3 rounded-lg space-y-2 bg-sky-300 text-sky-900"> <p class="text-lg">CATS Radio Node</p> <p class="text-lg font-semibold">{{ callsign }}</p> </div> - <div class="divide-y divide-gray-300"> - <ul class="pt-2 pb-4 space-y-1 text-sm"> - <li class="{% if page == ActivePage::Dashboard %} bg-gray-200 text-gray-900 {% endif %}"> - <a href="/" class="flex items-center p-2 space-x-3 rounded-md"> - <i class="fa fa-home" aria-hidden="true"></i><span>Dashboard</span> + <div class="divide-y divide-sky-300"> + <ul class="pt-2 pb-4 space-y-1 text-lg"> + <li class="rounded-md p-3 {% if page == ActivePage::Dashboard %} bg-sky-200 text-sky-900 {% endif %} hover:bg-sky-300"> + <a href="/" class="p-2 m-2"> + <i class="w-8 fa fa-home" aria-hidden="true"></i><span>Dashboard</span> </a> </li> - <li class="{% if page == ActivePage::Incoming %} bg-gray-200 text-gray-900 {% endif %}"> - <a href="/incoming" class="flex items-center p-2 space-x-3 rounded-md"> - <i class="fa fa-inbox" aria-hidden="true"></i><span>Incoming</span> + <li class="rounded-md p-3 {% if page == ActivePage::Incoming %} bg-sky-200 text-sky-900 {% endif %}"> + <a href="/incoming" class="p-2 m-2"> + <i class="w-8 fa fa-inbox" aria-hidden="true"></i><span>Incoming</span> </a> </li> - <li class="{% if page == ActivePage::Send %} bg-gray-200 text-gray-900 {% endif %}"> - <a href="/send" class="flex items-center p-2 space-x-3 rounded-md"> - <i class="fa fa-paper-plane-o" aria-hidden="true"></i><span>Send</span> + <li class="rounded-md p-3 {% if page == ActivePage::Send %} bg-sky-200 text-sky-900 {% endif %}"> + <a href="/send" class="p-2 m-2"> + <i class="w-8 fa fa-paper-plane-o" aria-hidden="true"></i><span>Send</span> + </a> + </li> + <li class="rounded-md p-3 {% if page == ActivePage::Settings %} bg-sky-200 text-sky-900 {% endif %}"> + <a href="/settings" class="p-2 m-2"> + <i class="w-8 fa fa-cog" aria-hidden="true"></i><span>Settings</span> </a> </li> </ul> diff --git a/templates/incoming.html b/templates/incoming.html new file mode 100644 index 0000000..3de173d --- /dev/null +++ b/templates/incoming.html @@ -0,0 +1,6 @@ +{% include "head.html" %} +<div class=""> + Incoming! +</div> +{% include "foot.html" %} +{# vi:set et sw=2 ts=2: #} diff --git a/templates/send.html b/templates/send.html new file mode 100644 index 0000000..b47f6b0 --- /dev/null +++ b/templates/send.html @@ -0,0 +1,6 @@ +{% include "head.html" %} +<div class=""> + Send! +</div> +{% include "foot.html" %} +{# vi:set et sw=2 ts=2: #} diff --git a/templates/settings.html b/templates/settings.html new file mode 100644 index 0000000..221df88 --- /dev/null +++ b/templates/settings.html @@ -0,0 +1,6 @@ +{% include "head.html" %} +<div class=""> + Settings! +</div> +{% include "foot.html" %} +{# vi:set et sw=2 ts=2: #} |