aboutsummaryrefslogtreecommitdiff
path: root/src/routes
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-12 15:05:03 +0100
committerGitHub <[email protected]>2024-02-12 15:05:03 +0100
commitca395b81bcadb9dde9214098f2cab0c7a3561574 (patch)
tree055bae9ef4e65f53b826b240f0b8e3b15b73693e /src/routes
parente4832b4cf36ba0eaed298ee458498eddd7176590 (diff)
parente50a868f69b602cc0bc84d51e9940878924f49ef (diff)
downloadwebol-ca395b81bcadb9dde9214098f2cab0c7a3561574.tar
webol-ca395b81bcadb9dde9214098f2cab0c7a3561574.tar.gz
webol-ca395b81bcadb9dde9214098f2cab0c7a3561574.zip
Merge pull request #13 from FxQnLr/config
Config
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/device.rs6
-rw-r--r--src/routes/start.rs8
2 files changed, 6 insertions, 8 deletions
diff --git a/src/routes/device.rs b/src/routes/device.rs
index b80cb85..c85df1b 100644
--- a/src/routes/device.rs
+++ b/src/routes/device.rs
@@ -12,7 +12,7 @@ use crate::error::Error;
12pub async fn get(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<GetDevicePayload>) -> Result<Json<Value>, Error> { 12pub async fn get(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<GetDevicePayload>) -> Result<Json<Value>, Error> {
13 info!("add device {}", payload.id); 13 info!("add device {}", payload.id);
14 let secret = headers.get("authorization"); 14 let secret = headers.get("authorization");
15 if auth(secret).map_err(Error::Auth)? { 15 if auth(&state.config, secret).map_err(Error::Auth)? {
16 let device = sqlx::query_as!( 16 let device = sqlx::query_as!(
17 Device, 17 Device,
18 r#" 18 r#"
@@ -39,7 +39,7 @@ pub struct GetDevicePayload {
39pub async fn put(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PutDevicePayload>) -> Result<Json<Value>, Error> { 39pub async fn put(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PutDevicePayload>) -> Result<Json<Value>, Error> {
40 info!("add device {} ({}, {}, {})", payload.id, payload.mac, payload.broadcast_addr, payload.ip); 40 info!("add device {} ({}, {}, {})", payload.id, payload.mac, payload.broadcast_addr, payload.ip);
41 let secret = headers.get("authorization"); 41 let secret = headers.get("authorization");
42 if auth(secret).map_err(Error::Auth)? { 42 if auth(&state.config, secret).map_err(Error::Auth)? {
43 sqlx::query!( 43 sqlx::query!(
44 r#" 44 r#"
45 INSERT INTO devices (id, mac, broadcast_addr, ip) 45 INSERT INTO devices (id, mac, broadcast_addr, ip)
@@ -73,7 +73,7 @@ pub struct PutDeviceResponse {
73pub async fn post(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, Error> { 73pub async fn post(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, Error> {
74 info!("edit device {} ({}, {}, {})", payload.id, payload.mac, payload.broadcast_addr, payload.ip); 74 info!("edit device {} ({}, {}, {})", payload.id, payload.mac, payload.broadcast_addr, payload.ip);
75 let secret = headers.get("authorization"); 75 let secret = headers.get("authorization");
76 if auth(secret).map_err(Error::Auth)? { 76 if auth(&state.config, secret).map_err(Error::Auth)? {
77 let device = sqlx::query_as!( 77 let device = sqlx::query_as!(
78 Device, 78 Device,
79 r#" 79 r#"
diff --git a/src/routes/start.rs b/src/routes/start.rs
index 4264588..ce95bf3 100644
--- a/src/routes/start.rs
+++ b/src/routes/start.rs
@@ -1,5 +1,4 @@
1use crate::auth::auth; 1use crate::auth::auth;
2use crate::config::SETTINGS;
3use crate::db::Device; 2use crate::db::Device;
4use crate::error::Error; 3use crate::error::Error;
5use crate::services::ping::Value as PingValue; 4use crate::services::ping::Value as PingValue;
@@ -21,7 +20,7 @@ pub async fn start(
21) -> Result<Json<Value>, Error> { 20) -> Result<Json<Value>, Error> {
22 info!("POST request"); 21 info!("POST request");
23 let secret = headers.get("authorization"); 22 let secret = headers.get("authorization");
24 let authorized = auth(secret).map_err(Error::Auth)?; 23 let authorized = auth(&state.config, secret).map_err(Error::Auth)?;
25 if authorized { 24 if authorized {
26 let device = sqlx::query_as!( 25 let device = sqlx::query_as!(
27 Device, 26 Device,
@@ -38,9 +37,7 @@ pub async fn start(
38 37
39 info!("starting {}", device.id); 38 info!("starting {}", device.id);
40 39
41 let bind_addr = SETTINGS 40 let bind_addr = "0.0.0.0:0";
42 .get_string("bindaddr")
43 .unwrap_or("0.0.0.0:1111".to_string());
44 41
45 let _ = send_packet( 42 let _ = send_packet(
46 &bind_addr.parse().map_err(Error::IpParse)?, 43 &bind_addr.parse().map_err(Error::IpParse)?,
@@ -75,6 +72,7 @@ pub async fn start(
75 72
76 crate::services::ping::spawn( 73 crate::services::ping::spawn(
77 state.ping_send.clone(), 74 state.ping_send.clone(),
75 &state.config,
78 device, 76 device,
79 uuid_gen.clone(), 77 uuid_gen.clone(),
80 &state.ping_map, 78 &state.ping_map,