1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-25 08:27:44 +00:00

Begin adding a user accessible web server

This commit is contained in:
Joshua Goins 2024-05-11 14:02:55 -04:00
parent 3278452ac3
commit f37840d44f
6 changed files with 93 additions and 0 deletions

View file

@ -6,6 +6,10 @@ admin.ffxiv.local:80 {
reverse_proxy :5800
}
ffxiv.local:80 {
reverse_proxy :5801
}
frontier.ffxiv.local:80 {
reverse_proxy :5857
}

View file

@ -15,6 +15,9 @@ name = "kawari-login"
[[bin]]
name = "kawari-patch"
[[bin]]
name = "kawari-web"
[profile.release]
lto = true
strip = true

View file

@ -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

70
src/bin/kawari-web.rs Normal file
View file

@ -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<String> {
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<String>,
}
async fn apply(Form(input): Form<Input>) -> 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();
}

View file

@ -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
}

12
templates/web.html Normal file
View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FFXIV</title>
</head>
<body>
<p>Welcome to Final Fantasy XIV!</p>
</body>
</html>