コード例 #1
0
 def __init__(self, query, username, password, directory, proxy):
     """Initialize class and set variables."""
     c = conf.Configure()
     self.user = username
     self.pw = password
     self.query = query
     self.dir = directory
     self.pxy = proxy
コード例 #2
0
ファイル: directory_search.py プロジェクト: yut0u/GitMAD
 def iterate_thru_repos(self):
     """Driver for this class, to put other functions together, search, and generate results.
     
     In addition, this will email results (if enabled) as well as insert them into the database.
     """
     dbc = database.DbOps(self.db_user, self.db_pw, self.db_host,
                          self.db_database)
     total_added = 0
     total_list = []
     for key in self.in_dict:
         if 'cloned' in self.in_dict[key]:
             repo_id = self.in_dict[key][7]
             db_repo_id = dbc.get_recent_hash(repo_id)
             repo = self.in_dict[key][0]
             gen_file_list = self.generate_file_list(repo)
             gen_item_info_list, f_recent_commit = self.search_file_list(
                 repo, gen_file_list, db_repo_id)
             dbc.update_repo_info(self.in_dict[key], f_recent_commit)
             num_added, added_list = dbc.update_repo_search_results(
                 self.in_dict[key], gen_item_info_list, self.search_type)
             total_added += num_added
             total_list.extend(added_list)
         elif 'not_cloned' in self.in_dict[key]:
             dbc.update_repo_info(self.in_dict[key], 'n/a')
     print("Length of added list - a list of dicts")
     print(len(total_list))
     if total_list != []:
         if self.do_email == 1:
             num_results = len(total_list)
             email_body = []
             for item in range(0, len(total_list)):
                 if total_list[item]["Type"] == "Query Match":
                     email_body.append(total_list[item])
             zip_path = self.write_files(total_list)
             c = conf.Configure()
             e_conf_file, e_file_check = c.check_for_file(c.e_filename)
             e_from, e_to, e_domain, e_port, e_pw = c.populate_email_credentials(
                 e_conf_file, e_file_check)
             e_alert = ea.EmailAction(e_from, e_to, e_domain, e_port, e_pw)
             e_alert.send_alert(zip_path, num_results, email_body)
     print("Items added to repo_search_results:")
     print(total_added)
コード例 #3
0
ファイル: main.py プロジェクト: yut0u/GitMAD
    def __init__(self,
                 query,
                 email,
                 logging,
                 res_per_pull,
                 max_repo_size,
                 ent,
                 entropy_amt=4):
        """Initialize class, set variables, and populate config files."""
        c = conf.Configure()
        conf_file, file_check = c.check_for_file(c.c_filename)
        pxy, db_u, db_p, db_h, db_db, g_u, g_p, d = c.populate_credentials(
            conf_file, file_check)
        if email == 1:
            e_conf_file, e_file_check = c.check_for_file(c.e_filename)
            e_from, e_to, e_domain, e_port, e_pw = c.populate_email_credentials(
                e_conf_file, e_file_check)

        if logging == 1:
            # configure logging
            print("placeholder")
        self.proxy = pxy
        self.directory = d
        self.user = g_u
        self.pw = g_p
        self.db_user = db_u
        self.db_pw = db_p
        self.db_host = db_h
        self.db_db = db_db
        self.query = query
        self.do_email = email
        self.do_logs = logging
        self.rpp = res_per_pull
        self.max_size = int(max_repo_size)
        self.ent_size = int(entropy_amt)
        if int(ent) == 1:
            self.do_ent = 'entropy'
        else:
            self.do_ent = 'no entropy'
コード例 #4
0
ファイル: web_home.py プロジェクト: silvrwolfboy/GitMAD
#!/usr/bin/python3

from flask import Flask, render_template, url_for, request, Response
import db_ops as db
import conf
import regex_matches
import json
import datetime
import decimal

c = conf.Configure()
conf_file, file_check = c.check_for_file(c.c_filename)
pxy, db_u, db_p, db_h, db_db, g_u, g_p, d = c.populate_credentials(
    conf_file, file_check)
db_user = db_u
db_pw = db_p
db_host = db_h
db_db = db_db

app = Flask(__name__)


class DecimalEncoder(json.JSONEncoder):
    ### subclassing json to handle a decimal return (match item entropy) from DB ###
    def _iterencode(self, o, markers=None):
        if isinstance(o, decimal.Decimal):
            # wanted a simple yield str(o) in the next line,
            # but that would mean a yield on the line with super(...),
            # which wouldn't work (see my comment below), so...
            return (str(o) for o in [o])
        return super(DecimalEncoder, self)._iterencode(o, markers)