Remove admin webui, move options to CLI args
This commit is contained in:
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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.");
|
||||
|
Reference in New Issue
Block a user