From bc7b456e00064a6e9fa7ba10cfea0891cbefc2ca Mon Sep 17 00:00:00 2001 From: Kremilly Date: Sun, 15 Dec 2024 13:56:58 -0300 Subject: [PATCH] refactor: migrate URL constants to a new Urls module and update references --- src/constants/global.rs | 6 ------ src/constants/mod.rs | 1 + src/constants/urls.rs | 11 +++++++++++ src/dump_sync.rs | 8 ++++++-- src/helpers/configs.rs | 7 +++++-- src/plugins/pastebin.rs | 8 ++++++-- src/plugins/reports_xss.rs | 8 ++++++-- src/plugins/scan_xss.rs | 4 ++-- src/ui/share_alerts.rs | 4 ++-- 9 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 src/constants/urls.rs diff --git a/src/constants/global.rs b/src/constants/global.rs index 37c4ad4..0f6e282 100644 --- a/src/constants/global.rs +++ b/src/constants/global.rs @@ -7,15 +7,9 @@ impl Global { pub const APP_VERSION: &'static str = env!("CARGO_PKG_VERSION"); pub const APP_LICENSE: &'static str = env!("CARGO_PKG_LICENSE"); pub const APP_HOMEPAGE: &'static str = env!("CARGO_PKG_HOMEPAGE"); - - pub const APP_CONFIGS: &'static str = "https://raw.githubusercontent.com/Kremilly/DumpSync/refs/heads/main/dumpsync.yml"; - pub const XSS_DETECT_REGEX: &'static str = "https://raw.githubusercontent.com/Kremilly/DumpSync/refs/heads/main/patterns.txt"; pub const APP_ICON: &'static str = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAYAAABxLuKEAAAACXBIWXMAAC4jAAAuIwF4pT92AAADSklEQVR4nO2aP07jQBSHf95si0QQQgihIBJRUAfJgtocAY4ARwhHIFfIEcgRNjXVuqFBCGEkhBBCKC5ow5stHENY/Gb8Z5zYu++Tpkk8+jlfZuyZZztKKQjf+bHoE6gqIoZBxDCIGAYRwyBiGEQMg4hhEDEMIoZBxDCIGAYRwyBiGEQMg4hhSCPGA6AstTGAXwB6Gc+zCeB82jdv7gWAk7SBjqmCp5TypidkGx/AoeM4oSG/O81vWsodOo5zbDrIKOb9/b0sMQDgNxqNPU12G8Bv2JMS0280Gme6A4xTSSlVZutOJhN2eCulekqpZgm5vclk0tb97p8mMURkOqQoXU22V2KuB2DAfVkFMew/R0Taf7Ug2ulZBTGVzDaKSfncaQBgmPB5E9FtMhcpsgMAp7ZzAXsjJlhaWholffH29pb1nLJkl5ILzGEqFem/qL6AvalUSv+CfbXrFEQLTJa6j5jmeDxurqysfFs9Ly8v93MHo/5iugDGr6+vQ0QjYLi6uhrkDpyh7mJijqbt/OXlJQAwitva2pp2L8ZRdTEhsu+T2oh20ScA8Pz8/CFpfX1de12ZpepiRohGQhG8acPT01MA4GxjYyNpzfUF4yaSiFK1Iv01fftEFKY9hxStTUQXj4+P57UWs7m56RPRIREFFuWAiHoPDw/aDaq1skOR/jparZbfarU6SqlTpdRQKRVaKj1oxVT6GjPL1tbWANMywf39fXzd8KApWxjQ9quNmFm2t7fjOw3u7u7a+BR0BEvVvlqKmaXT6QT4LDid3t7exoKyFty/UHsxf7Ozs+MD8G9ubv5dMdfX16Yi/HB3dzexPFn67nrBCzxTzTexFlM0F6i+mIX0BezVY7yrq6ukzwvdIVJkH5WRC9gbMR/7EZukLDvkXcdokacEDFUQw5YCiCiA5rlTWbnAHGq+KWDvLEqpAaK3HOaaCyx+xAxc19XdcgeIVrG2ryPaXMBi2SFH67uum/Sw7APXdUMiOiYif565QLqpFMIw7DIQIprbo4ODg1Rlxv39/QDA3uXlZTxy8oyezLnG92P+V+QdPAYRwyBiGEQMg4hhEDEMIoZBxDCIGAYRwyBiGEQMg4hhEDEMIoZBxDCIGAYRw/AHZ4ENamm/WDkAAAAASUVORK5CYII="; - pub const PASTEBIN_API_URI: &'static str = "https://pastebin.com/api/api_post.php"; - pub const CDN_BOOTSTRAP: &'static str = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"; - pub fn app_config() -> String { format!("{}.yml", Self::APP_NAME) } diff --git a/src/constants/mod.rs b/src/constants/mod.rs index 7d05e2e..9b6b302 100644 --- a/src/constants/mod.rs +++ b/src/constants/mod.rs @@ -1,2 +1,3 @@ +pub mod urls; pub mod global; pub mod regexp; \ No newline at end of file diff --git a/src/constants/urls.rs b/src/constants/urls.rs new file mode 100644 index 0000000..152ce9c --- /dev/null +++ b/src/constants/urls.rs @@ -0,0 +1,11 @@ +pub struct Urls; + +impl Urls { + + pub const APP_CONFIGS: &'static str = "https://raw.githubusercontent.com/Kremilly/DumpSync/refs/heads/main/dumpsync.yml"; + pub const XSS_DETECT_REGEX: &'static str = "https://raw.githubusercontent.com/Kremilly/DumpSync/refs/heads/main/patterns.txt"; + + pub const PASTEBIN_API_URI: &'static str = "https://pastebin.com/api/api_post.php"; + pub const CDN_BOOTSTRAP: &'static str = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"; + +} diff --git a/src/dump_sync.rs b/src/dump_sync.rs index c1c9376..2ea6d38 100644 --- a/src/dump_sync.rs +++ b/src/dump_sync.rs @@ -17,9 +17,13 @@ use crate::{ ui::ui_base::UI, core::dump::Dump, helpers::env::Env, - constants::global::Global, ui::success_alerts::SuccessAlerts, + constants::{ + urls::Urls, + global::Global, + }, + plugins::{ schema::Schema, scan_xss::ScanXSS, @@ -47,7 +51,7 @@ impl DumpSync { } async fn initialize(&self) -> Result<(), Box> { - let response = reqwest::get(Global::APP_CONFIGS).await?; + let response = reqwest::get(Urls::APP_CONFIGS).await?; let content = response.bytes().await?; let mut file = File::create(Global::app_config()).await?; diff --git a/src/helpers/configs.rs b/src/helpers/configs.rs index 7b2c839..d355a16 100644 --- a/src/helpers/configs.rs +++ b/src/helpers/configs.rs @@ -11,14 +11,17 @@ use std::{ }, }; -use crate::constants::global::Global; +use crate::constants::{ + urls::Urls, + global::Global, +}; pub struct Configs; impl Configs { fn default_config(&self) -> Result> { - let response = blocking::get(Global::APP_CONFIGS)?.text()?; + let response = blocking::get(Urls::APP_CONFIGS)?.text()?; let config: Value = serde_yaml::from_str(&response)?; Ok(config) } diff --git a/src/plugins/pastebin.rs b/src/plugins/pastebin.rs index 01dab35..ad20201 100644 --- a/src/plugins/pastebin.rs +++ b/src/plugins/pastebin.rs @@ -7,8 +7,12 @@ use std::{ use crate::{ utils::file::FileUtils, - constants::global::Global, ui::share_alerts::ShareAlerts, + + constants::{ + urls::Urls, + global::Global, + }, }; pub struct Pastebin { @@ -64,7 +68,7 @@ impl Pastebin { params.insert("api_paste_format", &ext); let response = Client::new() - .post(Global::PASTEBIN_API_URI) + .post(Urls::PASTEBIN_API_URI) .form(¶ms) .send() .await?; diff --git a/src/plugins/reports_xss.rs b/src/plugins/reports_xss.rs index b6c147d..f2db12b 100644 --- a/src/plugins/reports_xss.rs +++ b/src/plugins/reports_xss.rs @@ -10,9 +10,13 @@ use std::{ use crate::{ utils::file::FileUtils, - constants::global::Global, ui::report_alerts::ReportAlerts, handlers::reports_handlers::ReportsHandlers, + + constants::{ + urls::Urls, + global::Global, + } }; #[derive(Serialize)] @@ -85,7 +89,7 @@ impl ReportsXSS { pub fn html(&self, detections: Vec<(String, usize, String, String)>, output_path: &str) -> Result<(), Box> { let mut file = File::create(output_path)?; file.write_all(format!("{}: XSS Reports", Global::APP_NAME).as_bytes())?; - file.write_all(format!("", Global::CDN_BOOTSTRAP).as_bytes())?; + file.write_all(format!("", Urls::CDN_BOOTSTRAP).as_bytes())?; file.write_all(format!( "", diff --git a/src/plugins/scan_xss.rs b/src/plugins/scan_xss.rs index 464fafd..f1f53af 100644 --- a/src/plugins/scan_xss.rs +++ b/src/plugins/scan_xss.rs @@ -9,7 +9,7 @@ use mysql::{ }; use crate::{ - constants::global::Global, + constants::urls::Urls, ui::scan_alerts::ScanAlerts, core::connection::Connection, plugins::reports_xss::ReportsXSS, @@ -84,7 +84,7 @@ impl ScanXSS { } None => { - ScanHandlers.load_patterns_from_url(Global::XSS_DETECT_REGEX).await? + ScanHandlers.load_patterns_from_url(Urls::XSS_DETECT_REGEX).await? } }; diff --git a/src/ui/share_alerts.rs b/src/ui/share_alerts.rs index aa1b232..10c433d 100644 --- a/src/ui/share_alerts.rs +++ b/src/ui/share_alerts.rs @@ -2,7 +2,7 @@ extern crate colored; use colored::*; -use crate::constants::global::Global; +use crate::constants::urls::Urls; pub struct ShareAlerts; @@ -22,7 +22,7 @@ impl ShareAlerts { } pub fn api_key_missing() { - let api_link = Global::PASTEBIN_API_URI; + let api_link = Urls::PASTEBIN_API_URI; let message = "Please provide a valid API key. Click this link to get one"; Self::error("API key is missing or empty");