Ejemplo n.º 1
0
 def __init__(self, file):
     self.name = path.basename(file)
     self.pname = file
     self.fdl = []
     # try except ... for "stat"
     self.len = stat(file).st_size
     self.md5 = md5(file)
     self.sha256 = sha256(file)
Ejemplo n.º 2
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")