Remove admin webui, move options to CLI args

This commit is contained in:
Ethan O'Brien 2024-11-02 12:22:16 -05:00
parent 7aaf22c923
commit 8bc07a6419
10 changed files with 20 additions and 167 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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<String> {
@ -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.");

View file

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

View file

@ -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 (
<div id="home">
<h1>Admin</h1>
<div>
<input type="checkbox" id="import" name="import" checked={!!imp} onClick={(i)=>handleSubmit(i)} />
<label for="import">Allow account imports</label><br/><br/>
<input type="checkbox" id="exp" name="exp" checked={!!exp} onClick={(i)=>handleSubmit2(i)} />
<label for="exp">Allow account exports</label>
</div>
</div>
);
}
export default Admin;

View file

@ -71,7 +71,7 @@ function Bonus() {
/>
<button type="submit">Submit</button>
</form>
<p>You can find a list of available login bonus IDs <a href="https://github.com/ethanaobrien/ew/blob/main/src/router/databases/json/login_bonus.json">here</a>. You should input the <code>id</code> field</p>
<p>You can find a list of available login bonus IDs <a href="https://git.ethanthesleepy.one/ethanaobrien/ew/src/branch/main/src/router/databases/json/login_bonus.json">here</a>. You should input the <code>id</code> field</p>
</div>
);
}

View file

@ -45,11 +45,6 @@ function Login() {
e.preventDefault();
window.location.href = "/help/";
}
const adminPanel = (e) => {
e.preventDefault();
window.location.href = "/admin/";
}
return (
<div id="login-form">
@ -63,7 +58,6 @@ function Login() {
<div id="sub_div">
<button onClick={import_user}>Import User</button><br/><br/>
<button onClick={help}>Need help?</button><br/><br/>
<button hidden={!["127.0.0.1", "localhost"].includes(window.location.hostname)} onClick={adminPanel}>Admin panel</button>
{ error[0] ? <p>Error: { error[0] } </p> : <p></p> }
</div>
</form>

View file

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