Exemplo n.º 1
0
def exec(anserv, fn, kwarg):
    anserv.setfn(fn)
    fn = [s for s in anserv if not s.fnhasattr(base.UNSUPPORTED)]
    # fn = {n: getattr(s(), fn) for n, s in anserv.items() if
    #    not hasattr(getattr(s, fn), base.UNSUPPORTED)}
    # kwarg = {n: {"apikey": s.get_apikey()} for n, s in anserv.items()}

    summ = {s.name: color.grayb("unsupported") for s in anserv}

    if fn:
        with ThreadPoolExecutor(__maxt) as tp:
            # fut = {tp.submit(f, **kwarg[n], **kwargs): n for n, f in fn.items()}
            fut = {tp.submit(s.fn, **kwarg): s for s in fn}
            # timeout=60 (sec) # does not work like this
            for f in as_completed(fut, timeout=None):
                try:
                    data = f.result()
                except base.UnsupportedAttr:
                    pass
                except Exception as e:
                    summ[fut[f].name] = color.redb("unsuccessful")
                    out.warn(f"\"{fut[f].name}\" -- \"{fut[f].fnname}\" "
                             f"error: {e}\n{color.red(format_exc())}")
                else:
                    summ[fut[f].name] = color.greenb("successful")
                    out.info(f"\"{fut[f].name}\" -- \"{fut[f].fnname}\" "
                             f"completed:\n{data}")

    return [summ[s.name] for s in anserv]
Exemplo n.º 2
0
    def inarg():
        global ina, pause
        try:
            pause = int(arg["--pause"])
            if int(pause) < 0:
                pause = 0
        except ValueError:
            out.warn(f"invalid pause interval integer value \"{pause}\", "
                     f"defaulting to zero")

        if arg["--test"]:
            ina = base.Service.get_apifn()
        elif arg["--find"]:
            ina = arg["<input>"]
        elif arg["--quota"]:
            ina = __NOINPUT
        else:
            # domain
            if arg["--domain"]:
                ina = web.parse_domainl(*arg["<input>"])
                if not ina:
                    out.error("all input domain names are invalid")
            # ipaddr
            elif arg["--ipaddr"]:
                ina = web.parse_ipaddrl(*arg["<input>"])
                if not ina:
                    out.error("all input IP addresses are invalid")
            # url
            elif arg["--url"]:
                ina = web.parse_fullurll(*arg["<input>"])
                if not ina:
                    out.error("all input URLs are invalid")
            # file, hash
            else:
                if arg["--submit"]:
                    ina = file.new(*arg["<input>"])
                elif arg["--report"]:
                    # ina = arg["<input>"]
                    ina = crypto.parse_hashl(*arg["<input>"])
                else:  # arg["--download"]
                    if arg["<input>"]:
                        ina = crypto.parse_hashl(*arg["<input>"])
                    else:
                        ina = __NOINPUT
        out.debug("ina", obj=ina)

        if ina != __NOINPUT and not arg["--test"] and len(ina) != len(
                arg["<input>"]):
            rw.yn("one or more input arguments are invalid")
Exemplo n.º 3
0
def parse_fullurl(url):
    if regex.isfullurl(url):
        return url.lower()
    else:
        out.warn(f"malformed full URL \"{url}\"")
Exemplo n.º 4
0
    def inarg():
        if (arg["--ipaddr"] or arg["--domain"] or arg["--appl"] or arg["--url"]) \
                and not (arg["--download"] or arg["--find"] or arg["--find"]
                         or arg["--report"] or arg["--submit"]):
            print(usage)
            exit(0)

        global iarg, pause
        try:
            pause = int(arg["--pause"])
            if int(pause) < 0:
                raise ValueError
        except ValueError:
            out.warn(f"invalid pause interval integer value \"{pause}\", "
                     f"defaulting to zero")
            pause = 0

        if arg["--test"]:
            iarg = base.Service.get_apifn()
        elif arg["--find"]:
            iarg = arg["<input>"]
        elif arg["--quota"]:
            iarg = __NOINPUT
        else:
            # domain
            if arg["--domain"]:
                iarg = web.parse_domainl(*arg["<input>"])
                if not iarg:
                    out.error("all input domain names are invalid")
            # ipaddr
            elif arg["--ipaddr"]:
                iarg = web.parse_ipaddrl(*arg["<input>"])
                if not iarg:
                    out.error("all input IP addresses are invalid")
            # url
            elif arg["--url"]:
                iarg = web.parse_fullurll(*arg["<input>"])
                if not iarg:
                    out.error("all input URLs are invalid")
            # file, hash
            else:
                from glob import glob
                from os.path import isdir, isfile, normpath

                if arg["--recursive"]:
                    tmp = [f for f in arg["<input>"] if isfile(f)]
                    for f in [normpath(f) for f in arg["<input>"] if isdir(f)]:
                        tmp += [f for f in
                                glob(f + meta.SEP + "**", recursive=True) if
                                isfile(f)]
                    tmp += [h for h in arg["<input>"] if
                            not isfile(h) and not isdir(h)]
                    arg["<input>"] = tmp

                if arg["--submit"]:
                    iarg = file.new(*arg["<input>"])
                elif arg["--report"]:  # file, hash
                    iarg = [f for f in arg["<input>"] if not isfile(f)]
                    tmp = [f for f in arg["<input>"] if isfile(f)]
                    if rw.validff(tmp):  # file
                        iarg += [crypto.sha256(f) for f in tmp]
                    iarg = crypto.parse_hashl(*iarg)  # hash
                else:  # arg["--download"]
                    if arg["<input>"]:
                        iarg = crypto.parse_hashl(*arg["<input>"])
                    else:
                        iarg = __NOINPUT
        out.debug("iarg", obj=iarg)

        if iarg != __NOINPUT and \
                not arg["--test"] and len(iarg) != len(arg["<input>"]):
            rw.yn("one or more input arguments are invalid")