1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use crate::errors::*;

use crate::db;
use structopt::StructOpt;


#[derive(Debug, StructOpt)]
pub enum Target {
    /// On domains
    #[structopt(name="domains")]
    Domains(Filter),
    /// On subdomains
    #[structopt(name="subdomains")]
    Subdomains(Filter),
    /// On ipaddrs
    #[structopt(name="ipaddrs")]
    IpAddrs(Filter),
    /// On urls
    #[structopt(name="urls")]
    Urls(Filter),
    /// On emails
    #[structopt(name="emails")]
    Emails(Filter),
    /// On phone numbers
    #[structopt(name="phonenumbers")]
    PhoneNumbers(Filter),
    /// On devices
    #[structopt(name="devices")]
    Devices(Filter),
    /// On networks
    #[structopt(name="networks")]
    Networks(Filter),
    /// On accounts
    #[structopt(name="accounts")]
    Accounts(Filter),
    /// On breaches
    #[structopt(name="breaches")]
    Breaches(Filter),
    /// On images
    #[structopt(name="images")]
    Images(Filter),
    /// On ports
    #[structopt(name="ports")]
    Ports(Filter),
    /// On ipnets
    #[structopt(name="netblocks")]
    Netblocks(Filter),
    /// On crypto currency addresses
    #[structopt(name="cryptoaddrs")]
    CryptoAddrs(Filter),
}

impl Target {
    pub fn domains(&self) -> Option<&Filter> {
        if let Target::Domains(f) = self {
            Some(f)
        } else {
            None
        }
    }

    pub fn subdomains(&self) -> Option<&Filter> {
        if let Target::Subdomains(f) = self {
            Some(f)
        } else {
            None
        }
    }

    pub fn ipaddrs(&self) -> Option<&Filter> {
        if let Target::IpAddrs(f) = self {
            Some(f)
        } else {
            None
        }
    }

    pub fn urls(&self) -> Option<&Filter> {
        if let Target::Urls(f) = self {
            Some(f)
        } else {
            None
        }
    }

    pub fn ports(&self) -> Option<&Filter> {
        if let Target::Ports(f) = self {
            Some(f)
        } else {
            None
        }
    }

    pub fn netblocks(&self) -> Option<&Filter> {
        if let Target::Netblocks(f) = self {
            Some(f)
        } else {
            None
        }
    }
}

#[derive(Debug, StructOpt)]
pub struct Filter {
    args: Vec<String>,
}

impl Filter {
    #[inline]
    pub fn any() -> db::Filter {
        db::Filter::any()
    }

    pub fn parse_optional(&self) -> Result<db::Filter> {
        db::Filter::parse_optional(&self.args)
    }

    pub fn parse(&self) -> Result<db::Filter> {
        db::Filter::parse(&self.args)
    }
}