added prefix param to slugify_filename

This commit is contained in:
epi
2021-08-01 09:23:42 -05:00
parent f97d103fc6
commit c8a46b7e5a
3 changed files with 13 additions and 7 deletions

View File

@@ -79,10 +79,10 @@ impl TermInputHandler {
let filename = if !handles.config.target_url.is_empty() {
// target url populated
slugify_filename(&handles.config.target_url, "state")
slugify_filename(&handles.config.target_url, "ferox", "state")
} else {
// stdin used
slugify_filename("stdin", "state")
slugify_filename("stdin", "ferox", "state")
};
let warning = format!(

View File

@@ -273,7 +273,7 @@ async fn wrapped_main(config: Arc<Configuration>) -> Result<()> {
let out_dir = if !config.output.is_empty() {
// -o|--output was used, so we'll attempt to create a directory to store the files
let folder = slugify_filename(&handles.config.output, "logs");
let folder = slugify_filename(&handles.config.output, "", "logs");
// create the directory or fail silently, assuming the reason for failure is that
// the path exists already
@@ -299,7 +299,7 @@ async fn wrapped_main(config: Arc<Configuration>) -> Result<()> {
.position(|s| *s == "--output" || *s == "-o")
.unwrap();
let filename = slugify_filename(&target, "log");
let filename = slugify_filename(&target, "ferox", "log");
let full_path = Path::new(&out_dir)
.join(filename)

View File

@@ -390,17 +390,23 @@ pub fn should_deny_url(url: &Url, handles: Arc<Handles>) -> Result<bool> {
/// current unix timestamp and suffix
///
/// ex: ferox-http_telsa_com-1606947491.state
pub fn slugify_filename(url: &str, suffix: &str) -> String {
log::trace!("enter: slugify({:?}, {:?})", url, suffix);
pub fn slugify_filename(url: &str, prefix: &str, suffix: &str) -> String {
log::trace!("enter: slugify({:?}, {:?}, {:?})", url, prefix, suffix);
let ts = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|_| Duration::from_secs(0))
.as_secs();
let altered_prefix = if !prefix.is_empty() {
format!("{}-", prefix)
} else {
String::new()
};
let slug = url.replace("://", "_").replace("/", "_").replace(".", "_");
let filename = format!("ferox-{}-{}.{}", slug, ts, suffix);
let filename = format!("{}{}-{}.{}", altered_prefix, slug, ts, suffix);
log::trace!("exit: slugify -> {}", filename);
filename