From 8bc07a6419bbfa34490ba6527bb55939c29ca020 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Sat, 2 Nov 2024 12:22:16 -0500 Subject: [PATCH] Remove admin webui, move options to CLI args --- docker/docker-compose.yml | 2 ++ docker/start.sh | 6 +++- src/main.rs | 8 ++++- src/router.rs | 2 -- src/router/webui.rs | 68 +++------------------------------------ webui/src/admin/Admin.css | 36 --------------------- webui/src/admin/Admin.jsx | 53 ------------------------------ webui/src/home/Home.jsx | 2 +- webui/src/login/Login.jsx | 6 ---- webui/src/main.jsx | 4 --- 10 files changed, 20 insertions(+), 167 deletions(-) delete mode 100644 webui/src/admin/Admin.css delete mode 100644 webui/src/admin/Admin.jsx diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index bae49d5..3c3a0d2 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -12,6 +12,8 @@ services: NPPS4_ADDRESS: "http://127.0.0.1:51376" MAXTIME: 1717045200 # A day before global EOS HIDDEN: false # Will disable the webui + DISABLE_IMPORTS: false # Will disable account imports + DISABLE_EXPORTS: false # Will disable account exports # Everything below is for the "Help" page #ANDROID_GLOBAL: "link.to/patched/android/global.apk" diff --git a/docker/start.sh b/docker/start.sh index 7a938e1..72b2f26 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -13,4 +13,8 @@ maxTime="${MAXTIME:-0}" purge=$([ "$PURGE" = "true" ] && echo "--purge" || echo "") -/root/ew/ew --path $directory --port $port --npps4 $npps4 $purge $hidden $https --global-android "$ANDROID_GLOBAL" --japan-android "$ANDROID_JAPAN" --global-ios "$IOS_GLOBAL" --japan-ios "$IOS_JAPAN" --assets-url "$ASSET_URL" --max-time $maxTime +imports=$([ "$DISABLE_IMPORTS" = "true" ] && echo "--disable-imports" || echo "") + +exports=$([ "$DISABLE_EXPORTS" = "true" ] && echo "--disable-exports" || echo "") + +/root/ew/ew --path $directory --port $port --npps4 $npps4 $exports $imports $purge $hidden $https --global-android "$ANDROID_GLOBAL" --japan-android "$ANDROID_JAPAN" --global-ios "$IOS_GLOBAL" --japan-ios "$IOS_JAPAN" --assets-url "$ASSET_URL" --max-time $maxTime diff --git a/src/main.rs b/src/main.rs index 3902836..35178fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,13 @@ pub struct Args { hidden: bool, #[arg(long, default_value_t = false, help = "Purge dead user accounts on startup")] - purge: bool + purge: bool, + + #[arg(long, default_value_t = false, help = "Disable user account imports")] + disable_imports: bool, + + #[arg(long, default_value_t = false, help = "Disable user account exports")] + disable_exports: bool } #[actix_web::main] diff --git a/src/router.rs b/src/router.rs index c017a7e..4897290 100644 --- a/src/router.rs +++ b/src/router.rs @@ -199,7 +199,6 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse { "/api/webui/startLoginbonus" => webui::start_loginbonus(req, body), "/api/webui/import" => webui::import(req, body), "/api/webui/set_time" => webui::set_time(req, body), - "/api/webui/admin" => webui::admin_post(req, body), _ => api_req(req, body).await } } else { @@ -214,7 +213,6 @@ pub async fn request(req: HttpRequest, body: String) -> HttpResponse { "/web/announcement" => web::announcement(req), "/api/webui/userInfo" => webui::user(req), "/webui/logout" => webui::logout(req), - "/api/webui/admin" => webui::admin(req), "/api/webui/export" => webui::export(req), "/api/webui/serverInfo" => webui::server_info(req), _ => api_req(req, body).await diff --git a/src/router/webui.rs b/src/router/webui.rs index a734898..e955c9c 100644 --- a/src/router/webui.rs +++ b/src/router/webui.rs @@ -5,35 +5,16 @@ use actix_web::{ http::header::ContentType }; use json::{JsonValue, object}; -use std::fs; -use std::fs::File; -use std::io::Write; use crate::include_file; use crate::router::{userdata, items}; fn get_config() -> JsonValue { - let def = object!{ - import: true, - export: true - }; - let contents = fs::read_to_string(crate::get_data_path("config.json")).unwrap_or(String::from("aaaaaaaaaaaaaaaaa")); - let mut rv = json::parse(&contents).unwrap_or(def.clone()); - for val in def.entries() { - if rv[val.0] == JsonValue::Null { - rv[val.0] = val.1.clone(); - } + let args = crate::get_args(); + object!{ + import: !args.disable_imports, + export: !args.disable_exports } - rv -} -fn save_config(val: String) { - let mut current = get_config(); - let new = json::parse(&val).unwrap(); - for vall in new.entries() { - current[vall.0] = vall.1.clone(); - } - let mut f = File::create(crate::get_data_path("config.json")).unwrap(); - f.write_all(json::stringify(current).as_bytes()).unwrap(); } fn get_login_token(req: &HttpRequest) -> Option { @@ -172,7 +153,7 @@ pub fn main(req: HttpRequest) -> HttpResponse { } } } - if req.path() != "/" && req.path() != "/home/" && req.path() != "/import/" && req.path() != "/admin/" && req.path() != "/help/" { + if req.path() != "/" && req.path() != "/home/" && req.path() != "/import/" && req.path() != "/help/" { return HttpResponse::Found() .insert_header(("Location", "/")) .body(""); @@ -182,45 +163,6 @@ pub fn main(req: HttpRequest) -> HttpResponse { .body(include_file!("webui/dist/index.html")) } - -macro_rules! check_admin { - ( $s:expr ) => { - { - if $s.peer_addr().unwrap().ip().to_string() != "127.0.0.1" { - let resp = object!{ - result: "ERR", - message: "Must be on localhost address to access admin panel." - }; - return HttpResponse::Ok() - .insert_header(ContentType::json()) - .body(json::stringify(resp)) - } - } - }; -} - -pub fn admin(req: HttpRequest) -> HttpResponse { - check_admin!(req); - let resp = object!{ - result: "OK", - data: get_config() - }; - HttpResponse::Ok() - .insert_header(ContentType::json()) - .body(json::stringify(resp)) -} - -pub fn admin_post(req: HttpRequest, body: String) -> HttpResponse { - check_admin!(req); - save_config(body); - let resp = object!{ - result: "OK" - }; - HttpResponse::Ok() - .insert_header(ContentType::json()) - .body(json::stringify(resp)) -} - pub fn export(req: HttpRequest) -> HttpResponse { if !get_config()["export"].as_bool().unwrap() { return error("Exporting accounts is disabled on this server."); diff --git a/webui/src/admin/Admin.css b/webui/src/admin/Admin.css deleted file mode 100644 index 87822a0..0000000 --- a/webui/src/admin/Admin.css +++ /dev/null @@ -1,36 +0,0 @@ -body { - background-color: #616161; -} - -#home { - width: 90%; - margin: 50px auto; - background-color: #43A047; - border-radius: 10px; - box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1); - font-family: "Poppins", sans-serif; - padding: 20px 10px; -} - -#logout { - border: none; - text-align: center; - text-decoration: underline; - display: inline-block; - font-size: 16px; - transition-duration: 0.4s; - float: right; - background-color: yellow; - border-radius: 30px; - padding: 5px 20px; - cursor: pointer; -} - -#logout:hover { - background-color: red; -} - -#error p { - color: orange; - grid-template-columns: auto auto auto; -} diff --git a/webui/src/admin/Admin.jsx b/webui/src/admin/Admin.jsx deleted file mode 100644 index d61a793..0000000 --- a/webui/src/admin/Admin.jsx +++ /dev/null @@ -1,53 +0,0 @@ -import { useState, useParams, useEffect } from 'react' -import './Admin.css' -import Request from '../Request.jsx' - -function Admin() { - const [imp, setimp] = useState(); - const [exp, setexp] = useState(); - - const handleSubmit = async (event) => { - await Request( - "/api/webui/admin", - { - import: !imp - } - ); - setimp(!imp); - }; - const handleSubmit2 = async (event) => { - await Request( - "/api/webui/admin", - { - export: !exp - } - ); - setexp(!exp); - }; - - if (imp === undefined) { - (async () => { - let resp = await Request("/api/webui/admin"); - if (resp.result !== "OK") { - window.location.href = "/?message=" + encodeURIComponent(resp.message); - return; - } - setimp(resp.data.import); - setexp(resp.data.export); - })(); - } - - return ( -
-

Admin

-
- handleSubmit(i)} /> -

- handleSubmit2(i)} /> - -
-
- ); -} - -export default Admin; diff --git a/webui/src/home/Home.jsx b/webui/src/home/Home.jsx index da3153d..23d024b 100644 --- a/webui/src/home/Home.jsx +++ b/webui/src/home/Home.jsx @@ -71,7 +71,7 @@ function Bonus() { /> -

You can find a list of available login bonus IDs here. You should input the id field

+

You can find a list of available login bonus IDs here. You should input the id field

); } diff --git a/webui/src/login/Login.jsx b/webui/src/login/Login.jsx index e2dfaf4..41041d1 100644 --- a/webui/src/login/Login.jsx +++ b/webui/src/login/Login.jsx @@ -45,11 +45,6 @@ function Login() { e.preventDefault(); window.location.href = "/help/"; } - - const adminPanel = (e) => { - e.preventDefault(); - window.location.href = "/admin/"; - } return (
@@ -63,7 +58,6 @@ function Login() {




- { error[0] ?

Error: { error[0] }

:

}
diff --git a/webui/src/main.jsx b/webui/src/main.jsx index eeea5fc..725fe75 100644 --- a/webui/src/main.jsx +++ b/webui/src/main.jsx @@ -3,7 +3,6 @@ import ReactDOM from 'react-dom/client' import Login from './login/Login.jsx' import Home from './home/Home.jsx' import Import from './import/Import.jsx' -import Admin from './admin/Admin.jsx' import Help from './help/Help.jsx' let Elem; @@ -17,9 +16,6 @@ switch (window.location.pathname) { case "/import/": Elem = Import; break; - case "/admin/": - Elem = Admin; - break; case "/help/": Elem = Help; break;