Show stealth status in pkg list

This commit is contained in:
kpcyrd
2020-09-13 22:19:01 +02:00
parent 21c70aaf58
commit 152dd82848
7 changed files with 60 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
-- Description: Send a request to a hidden service
-- Version: 0.1.0
-- Stealth: passive
-- License: GPL-3.0
function run()

View File

@@ -1,5 +1,6 @@
-- Description: basic selftest
-- Version: 0.1.0
-- Stealth: offline
-- License: GPL-3.0
function run()

View File

@@ -1,5 +1,6 @@
-- Description: Read from stdin
-- Version: 0.1.0
-- Stealth: offline
-- License: GPL-3.0
function run()

View File

@@ -1,6 +1,7 @@
-- Description: jaVasCript:/*-/*`/*\`/*'/*"/**/(/* */oNcliCk=alert() )//%0D%0A%0d%0a//</stYle/</titLe/</teXtarEa/</scRipt/--!>\x3csVg/<sVg/oNloAd=alert()//>\x3e
-- Version: 0.1.0
-- License: GPL-3.0
-- Stealth: loud
-- Source: domains
function run()

View File

@@ -110,11 +110,11 @@ impl FromStr for Source {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum Stealth {
Loud,
Normal,
Silent,
Passive,
Offline,
}
@@ -126,7 +126,7 @@ impl FromStr for Stealth {
"loud" => Ok(Stealth::Loud),
// This is also the default level if none is provided
"normal" => Ok(Stealth::Normal),
"silent" => Ok(Stealth::Silent),
"passive" => Ok(Stealth::Passive),
"offline" => Ok(Stealth::Offline),
x => bail!("Unknown stealth: {:?}", x),
}
@@ -291,7 +291,7 @@ mod tests {
let metadata = Metadata::from_str(r#"-- Description: Hello world, this is my description
-- Version: 1.0.0
-- Source: domains
-- Stealth: silent
-- Stealth: passive
-- Author: kpcyrd <git at rxv dot cc>
-- Author: kpcyrd's cat
-- Repository: https://github.com/kpcyrd/sn0int
@@ -303,7 +303,7 @@ mod tests {
version: "1.0.0".to_string(),
license: License::WTFPL,
source: Some(Source::Domains),
stealth: Stealth::Silent,
stealth: Stealth::Passive,
authors: vec![
"kpcyrd <git at rxv dot cc>".to_string(),
"kpcyrd's cat".to_string(),

View File

@@ -5,13 +5,14 @@ use crate::api::Client;
use crate::args;
use crate::config::Config;
use crate::cmd::{Cmd, LiteCmd};
use crate::engine::Library;
use crate::engine::{Library, Module};
use crate::registry::{self, InstallTask, UpdateTask, Updater};
use crate::shell::Shell;
use crate::update::AutoUpdater;
use crate::worker;
use colored::Colorize;
use colored::{Color, Colorize};
use sn0int_common::ModuleID;
use sn0int_common::metadata::Stealth;
use std::collections::HashSet;
use std::fmt::Write;
use std::sync::Arc;
@@ -71,7 +72,7 @@ pub struct List {
pub source: Option<String>,
/// List outdated modules
#[structopt(long="outdated")]
pub outdated: bool,
pub outdated_only: bool,
/// Filter by pattern
#[structopt(default_value="*")]
pub pattern: String,
@@ -96,6 +97,34 @@ enum ModuleReload {
No,
}
#[inline]
fn write_tag(out: &mut String, color: Color, txt: &str) -> Result<()> {
write!(out, " [{}]", txt.color(color))?;
Ok(())
}
fn print_module(module: &Module, is_outdated: bool) -> Result<()> {
let mut out = String::new();
write!(&mut out, "{}/{} {}", module.author().purple(),
module.name(),
module.version().blue())?;
match module.stealth() {
Stealth::Loud => write_tag(&mut out, Color::Yellow, "LOUD")?,
Stealth::Normal => (),
Stealth::Passive => write_tag(&mut out, Color::Green, "passive")?,
Stealth::Offline => write_tag(&mut out, Color::Green, "offline")?,
};
if is_outdated {
write_tag(&mut out, Color::Red, "outdated")?;
}
println!("{}", out.bold());
println!(" {}", module.description());
Ok(())
}
fn run_subcommand(subcommand: SubCommand, library: &Library, config: &Config) -> Result<ModuleReload> {
match subcommand {
SubCommand::List(list) => {
@@ -115,16 +144,12 @@ fn run_subcommand(subcommand: SubCommand, library: &Library, config: &Config) ->
continue;
}
let mut out = String::new();
write!(&mut out, "{} ({})", canonical.green(),
module.version().yellow())?;
if autoupdate.is_outdated(&canonical) {
write!(&mut out, " {}", "[outdated]".red())?;
} else if list.outdated {
let is_outdated = autoupdate.is_outdated(&canonical);
if list.outdated_only && !is_outdated {
continue;
}
println!("{}", out);
println!("\t{}", module.description());
print_module(module, is_outdated)?;
}
Ok(ModuleReload::No)
},

View File

@@ -14,7 +14,7 @@ use std::sync::{Arc, Mutex};
use crate::engine::ctx::Script;
use crate::ipc::child::IpcChild;
use sn0int_common::ModuleID;
use sn0int_common::metadata::{Metadata, Source};
use sn0int_common::metadata::{Metadata, Source, Stealth};
use chrootable_https::dns::Resolver;
use crate::psl::PslReader;
use crate::paths;
@@ -226,6 +226,8 @@ pub struct Module {
version: String,
source: Option<Source>,
keyring_access: Vec<String>,
stealth: Stealth,
private_module: bool,
script: Script,
}
@@ -248,11 +250,18 @@ impl Module {
version: metadata.version,
source: metadata.source,
keyring_access: metadata.keyring_access,
stealth: metadata.stealth,
private_module,
script,
})
}
#[inline]
pub fn author(&self) -> &str {
&self.author
}
#[inline]
pub fn name(&self) -> &str {
&self.name
@@ -290,6 +299,11 @@ impl Module {
&self.keyring_access
}
#[inline]
pub fn stealth(&self) -> &Stealth {
&self.stealth
}
#[inline]
pub fn is_private(&self) -> bool {
self.private_module