Skip to content

Commit

Permalink
refactor: migrate URL constants to a new Urls module and update refer…
Browse files Browse the repository at this point in the history
…ences
  • Loading branch information
Kremilly committed Dec 15, 2024
1 parent 05a65a6 commit bc7b456
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
6 changes: 0 additions & 6 deletions src/constants/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod urls;
pub mod global;
pub mod regexp;
11 changes: 11 additions & 0 deletions src/constants/urls.rs
Original file line number Diff line number Diff line change
@@ -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";

}
8 changes: 6 additions & 2 deletions src/dump_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -47,7 +51,7 @@ impl DumpSync {
}

async fn initialize(&self) -> Result<(), Box<dyn Error>> {
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?;
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value, Box<dyn Error>> {
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)
}
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/pastebin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(&params)
.send()
.await?;
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/reports_xss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -85,7 +89,7 @@ impl ReportsXSS {
pub fn html(&self, detections: Vec<(String, usize, String, String)>, output_path: &str) -> Result<(), Box<dyn Error>> {
let mut file = File::create(output_path)?;
file.write_all(format!("<html><head><title>{}: XSS Reports</title>", Global::APP_NAME).as_bytes())?;
file.write_all(format!("<link href='{}' rel='stylesheet'></head><body>", Global::CDN_BOOTSTRAP).as_bytes())?;
file.write_all(format!("<link href='{}' rel='stylesheet'></head><body>", Urls::CDN_BOOTSTRAP).as_bytes())?;

file.write_all(format!(
"<nav class='navbar navbar-dark navbar-expand-lg bg-dark'><div class='container-fluid'><img src='{}' height='36'/><a class='navbar-brand'>XSS Scan Results</a></div></nav>",
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/scan_xss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/ui/share_alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate colored;

use colored::*;

use crate::constants::global::Global;
use crate::constants::urls::Urls;

pub struct ShareAlerts;

Expand All @@ -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");
Expand Down

0 comments on commit bc7b456

Please sign in to comment.