diff --git a/Caddyfile b/Caddyfile index f6ecd60..804b279 100644 --- a/Caddyfile +++ b/Caddyfile @@ -6,6 +6,10 @@ admin.ffxiv.local:80 { reverse_proxy :5800 } +ffxiv.local:80 { + reverse_proxy :5801 +} + frontier.ffxiv.local:80 { reverse_proxy :5857 } diff --git a/Cargo.toml b/Cargo.toml index 90d3e3b..57c0f69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,9 @@ name = "kawari-login" [[bin]] name = "kawari-patch" +[[bin]] +name = "kawari-web" + [profile.release] lto = true strip = true diff --git a/README.md b/README.md index 3d1e992..0c81e93 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ A substitute for a few official servers such as “ffxiv.com” and “square-en ## Components +* Web + * A simple website used for account management and other misc features. * Admin * The admin panel for configuring the multitude of servers. * [Frontier](https://docs.xiv.zone/server/frontier/) @@ -28,6 +30,7 @@ You will need some kind of reverse proxy because simply editing the `hosts` file First you need to edit your `hosts` file. Assuming you're using the default ports for each server, add the following: ``` +127.0.0.1 ffxiv.local 127.0.0.1 admin.ffxiv.local 127.0.0.1 frontier.ffxiv.local 127.0.0.1 patch-bootver.ffxiv.local diff --git a/src/bin/kawari-web.rs b/src/bin/kawari-web.rs new file mode 100644 index 0000000..e4d308f --- /dev/null +++ b/src/bin/kawari-web.rs @@ -0,0 +1,70 @@ +use std::net::SocketAddr; + +use axum::{ + Json, + Router, routing::get, + extract::Form +}; +use serde::{Deserialize, Serialize}; +use axum::response::{Html, Redirect}; +use axum::routing::post; +use kawari::config::{Config, get_config}; +use minijinja::{Environment, context}; +use kawari::setup_default_environment; + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct GateStatus { + status: i32, +} + +async fn root() -> Html { + tracing::info!("Requesting gate status..."); + + let config = get_config(); + + let environment = setup_default_environment(); + let template = environment.get_template("web.html").unwrap(); + Html(template.render(context! { gate_open => config.gate_open }).unwrap()) +} + +#[derive(Deserialize, Debug)] +#[allow(dead_code)] +struct Input { + gate_open: Option, +} + +async fn apply(Form(input): Form) -> Redirect { + tracing::info!("Apply config changes..."); + + let mut config = get_config(); + + if let Some(gate_open) = input.gate_open { + config.gate_open = gate_open == "on"; + } else { + config.gate_open = false; + } + + serde_json::to_writer( + &std::fs::File::create("config.json").unwrap(), + &config, + ) + .expect("TODO: panic message"); + + Redirect::to("/") +} + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + + let app = Router::new() + .route("/", get(root)) + .route("/apply", post(apply)); + + let addr = SocketAddr::from(([127, 0, 0, 1], 5801)); + tracing::info!("Web server started on {}", addr); + axum::Server::bind(&addr) + .serve(app.into_make_service()) + .await + .unwrap(); +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 31e3e8d..32ebb2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ pub fn generate_sid() -> String { pub fn setup_default_environment() -> Environment<'static> { let mut env = Environment::new(); env.add_template("admin.html", include_str!("../templates/admin.html")).unwrap(); + env.add_template("web.html", include_str!("../templates/web.html")).unwrap(); env } \ No newline at end of file diff --git a/templates/web.html b/templates/web.html new file mode 100644 index 0000000..173b2e4 --- /dev/null +++ b/templates/web.html @@ -0,0 +1,12 @@ + + + + + FFXIV + + + +

Welcome to Final Fantasy XIV!

+ + + \ No newline at end of file