Managed to load server configuration from WebUI

This commit is contained in:
2024-04-29 22:14:16 +02:00
parent 955067ad9c
commit 46648db093
15 changed files with 2159 additions and 13 deletions

View File

@ -10,7 +10,7 @@ pub struct AppConfig {
pub listen_address: String,
/// Website main origin
#[clap(short, long, env, default_value = "http://localhost:3000")]
#[clap(short, long, env, default_value = "http://localhost:5173")]
pub website_origin: String,
/// Proxy IP, might end with a star "*"

View File

@ -6,6 +6,7 @@ use std::fmt::{Display, Formatter};
use std::io::ErrorKind;
pub mod auth_controller;
pub mod server_controller;
/// Custom error to ease controller writing
#[derive(Debug)]

View File

@ -0,0 +1,17 @@
use crate::app_config::AppConfig;
use crate::controllers::HttpResult;
use crate::extractors::auth_extractor::AuthExtractor;
use actix_web::HttpResponse;
#[derive(serde::Serialize)]
struct ServerConfig {
authenticated: bool,
disable_auth: bool,
}
pub async fn config(auth: AuthExtractor) -> HttpResult {
Ok(HttpResponse::Ok().json(ServerConfig {
authenticated: auth.is_authenticated(),
disable_auth: AppConfig::get().unsecure_disable_login,
}))
}

View File

@ -1,3 +1,4 @@
use actix_cors::Cors;
use actix_identity::config::LogoutBehaviour;
use actix_identity::IdentityMiddleware;
use actix_remote_ip::RemoteIPConfig;
@ -9,9 +10,9 @@ use actix_web::web::Data;
use actix_web::{web, App, HttpServer};
use light_openid::basic_state_manager::BasicStateManager;
use remote_backend::app_config::AppConfig;
use remote_backend::controllers::auth_controller;
use remote_backend::constants;
use remote_backend::controllers::{auth_controller, server_controller};
use remote_backend::middlewares::auth_middleware::AuthChecker;
use remote_backend::{constants, virtweb_client};
use std::time::Duration;
#[actix_web::main]
@ -40,15 +41,28 @@ async fn main() -> std::io::Result<()> {
.login_deadline(Some(Duration::from_secs(constants::MAX_SESSION_DURATION)))
.build();
let cors = Cors::default()
.allowed_origin(&AppConfig::get().website_origin)
.allowed_methods(vec!["GET", "POST", "PUT", "PATCH", "DELETE"])
.allowed_header("X-Auth-Token")
.allow_any_header()
.supports_credentials()
.max_age(3600);
App::new()
.wrap(Logger::default())
.wrap(AuthChecker)
.wrap(identity_middleware)
.wrap(session_mw)
.wrap(cors)
.app_data(state_manager.clone())
.app_data(Data::new(RemoteIPConfig {
proxy: AppConfig::get().proxy_ip.clone(),
}))
.route(
"/api/server/config",
web::get().to(server_controller::config),
)
.route(
"/api/auth/start_oidc",
web::get().to(auth_controller::start_oidc),