Ejemplo n.º 1
0
 def print_raw(self, data):
     authors = []
     if data:
         for item in data:
             authors.append(Parser(self.args).get_authors(item))
     if authors:
         Helpers.print_success("All emails:\n")
         self.print_raw_authors(set(Helpers.flatten(authors)))
     else:
         Helpers.print_error("gitmails: No authors to print")
Ejemplo n.º 2
0
    def clone_repo_by_url(self, repo_url):
        try:
            clone_repository(repo_url,
                             self.get_repo_path_by_url(repo_url),
                             bare=True)
            return True

        except Exception as e:
            Helpers.print_error(e)
            return False
Ejemplo n.º 3
0
    def collect_organizations(self, organization, collectors):
        result = []
        for c in collectors:
            org = c.collect_organization(organization)
            if org:
                result.append(org)
                continue

            Helpers.print_error(
                "{}: Could not collect organization information".format(
                    c.collector_name))
        return result
Ejemplo n.º 4
0
    def collect_users(self, username, collectors):
        result = []
        for c in collectors:
            user = c.collect_user(username)
            if user:
                result.append(user)
                continue

            Helpers.print_error(
                "{}: Could not collect user information".format(
                    c.collector_name))
        return result
Ejemplo n.º 5
0
    def clone_repo(self, repo):
        try:
            if self.args.verbose:
                Helpers.print_success("Clonning {}".format(repo_url))
            clone_repository(repo.url, self.get_repo_path(repo), bare=True)
            return True

        except ValueError as e:
            return False

        except Exception as e:
            Helpers.print_error(e)
            return False
Ejemplo n.º 6
0
    def get_authors(self, repo_path):
        try:
            if self.args.verbose:
                Helpers.print_success(
                    "Collecting authors in ".format(repo_path))
            authors_set = set()
            repo = Repository(repo_path)
            for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
                authors_set.add(Author(commit.author.name,
                                       commit.author.email))
            return authors_set

        except Exception as e:
            Helpers.print_error(
                "{}: Could not collect authors".format(repo_path))
            return None
Ejemplo n.º 7
0
    def collect(self, collectors):
        collected = []
        if self.args.username:
            Helpers.print_success("Collecting information for {}".format(
                self.args.username))
            collected = self.collect_users(self.args.username, collectors)
        elif self.args.organization:
            Helpers.print_success("Collecting information for {}".format(
                self.args.organization))
            collected = self.collect_organizations(self.args.organization,
                                                   collectors)
        if not collected:
            Helpers.print_error("gitmails: Could not collect any information")
            return False

        return collected
Ejemplo n.º 8
0
    def check_email(self, email):
        try:
            url = "{}/{}?{}".format(self.base_url, email, self.url_parameters)
            r = requests.get(url)
            if r.status_code == 503:
                Helpers.print_error(
                    "hibp: IP got in DDoS protection by CloudFare")
            elif r.status_code == 429:
                Helpers.print_error("hibp: Throttled by HIBP API")
            elif r.text:
                r = r.json()
                print("\n{} leaks:".format(email))
                for leak in r:
                    print("\t- {}".format(leak["Name"]))
                return True

            return False

        except Exception as e:
            Helpers.print_error(e)
            return False
Ejemplo n.º 9
0
 def print_repos(self, repos, indentation=0):
     if not repos:
         Helpers.print_error(self.indent("No repositories", (indentation + 4)))
     for repo in repos:
         self.print_repo(repo, indentation=(indentation + 4))
         self.print_authors(repo.authors, indentation=(indentation + 8))