-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76cae08
commit f9f3481
Showing
8 changed files
with
275 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use normalize_path::NormalizePath; | ||
use random_string::generate_rng; | ||
use std::fs; | ||
use std::fs::File; | ||
use std::io::{Error, Write}; | ||
use std::path::PathBuf; | ||
use std::sync::Mutex; | ||
use actix_web::{post, HttpResponse, web}; | ||
use actix_web::web::Data; | ||
use serde::Deserialize; | ||
use crate::logger::logger; | ||
use crate::structs::PluginMeta; | ||
|
||
#[derive(Deserialize)] | ||
struct DashAPIData { | ||
passkey: String, | ||
command: String, | ||
subcommand: String, | ||
params: String, | ||
} | ||
#[post("/dashapi/")] | ||
pub(crate) async fn dashserver(data: web::Form<DashAPIData>, _pluginsmex: Data<Mutex<Vec<PluginMeta>>>) -> HttpResponse { | ||
if data.passkey != (passkey().unwrap_or(String::from(""))) { | ||
logger(15, String::from("An unauthorized external entity just tried performing an action on this instance.")); | ||
return HttpResponse::Forbidden().body(String::from("Wrong passkey entered. A report has been sent to the server owner.")); | ||
} | ||
|
||
match data.command.as_str() { | ||
"log" => { | ||
logger(data.subcommand.parse().unwrap_or(1), format!("{{CynthiaDash}} {}",data.params.clone())); | ||
} | ||
_ => { | ||
return HttpResponse::BadRequest().body(String::from("Invalid command.")); | ||
} | ||
} | ||
|
||
HttpResponse::Ok().body(String::from("OK!")) | ||
|
||
} | ||
|
||
pub fn passkey() -> Result<String, Error> { | ||
let fl = PathBuf::from("./.cynthiaTemp/dashpasskeys/"); | ||
fs::create_dir_all(&fl).unwrap(); | ||
let filepath = fl.join(format!("{}.TXT", std::process::id())).normalize(); | ||
if filepath.exists() { | ||
let pk = fs::read_to_string(filepath)?; | ||
Ok(pk) | ||
} else { | ||
let pk: String = generate_rng(15..70, random_string::charsets::ALPHANUMERIC); | ||
let mut fi: File = File::create(filepath.clone())?; | ||
write!(fi, "{}", pk)?; | ||
Ok(pk) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.