Ejemplo n.º 1
0
def changeConfig(data):
    target = data.get('target', None)
    database = data.get('database', None)
    host = data.get('host', None)    
    user = data.get('user', None)    
    password = data.get('password', None)
    filename = data.get('filename', 'target')
    
    fp = "{}/conf/server.conf".format(base_dir)
    conf = json.loads(slurp(fp)) if os.path.isfile(fp) else {}    
    zargs= zip(['target','database','host','user','password'], 
               [target, database, host, user, password ])
    args_map = {x:y for x,y in filter(lambda o: o[1], zargs)}
    config = dict(conf, **args_map)
    out = json.dumps(config, sort_keys=True, indent=4, separators=(',', ': '))
    spit(fp, out, True)
    spit('{}/conf/{}.cfg'.format(base_dir, filename), 'EMAIL_TARGET="{}"\n'.format(config["target"]), True)
    tangelo.content_type("application/json")    
    return { 'target' : config["target"], 'config' : filename + ".cfg" }
Ejemplo n.º 2
0
def changeConfig(data):
    target = data.get('target', None)
    database = data.get('database', None)
    host = data.get('host', None)
    user = data.get('user', None)
    password = data.get('password', None)
    filename = data.get('filename', 'target')

    fp = "{}/conf/server.conf".format(base_dir)
    conf = json.loads(slurp(fp)) if os.path.isfile(fp) else {}
    zargs = zip(['target', 'database', 'host', 'user', 'password'],
                [target, database, host, user, password])
    args_map = {x: y for x, y in filter(lambda o: o[1], zargs)}
    config = dict(conf, **args_map)
    out = json.dumps(config, sort_keys=True, indent=4, separators=(',', ': '))
    spit(fp, out, True)
    spit('{}/conf/{}.cfg'.format(base_dir, filename),
         'EMAIL_TARGET="{}"\n'.format(config["target"]), True)
    tangelo.content_type("application/json")
    return {'target': config["target"], 'config': filename + ".cfg"}
Ejemplo n.º 3
0
def getIngestLog(*args):
    job_id = nth(args, 0)
    logfile = "{}/{}.tee.log".format(work_dir, job_id)
    sz = slurp(logfile)
    tangelo.content_type("application/json")
    return {'log': sz}
Ejemplo n.º 4
0
def getState(*args):
    email_addr = nth(args, 0)
    logfile = "{}/{}.log".format(work_dir, email_addr)
    sz = slurp(logfile)
    tangelo.content_type("application/json")
    return {'log': sz}
Ejemplo n.º 5
0
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=desc)
    parser.add_argument("-a","--header", action='store_true', help="add header to output")
    parser.add_argument("-s","--start", type=int, default=0, help="start at line #")
    parser.add_argument("-l", "--limit", type=int, default=0, help="end at line #")
    parser.add_argument("target_email", help="Target Email")
    parser.add_argument("out_dir", help="Output Directory")
    parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File")
    args = parser.parse_args()
    outfile = "{}/output.csv".format(args.out_dir)
    mkdirp("{}/emails".format(args.out_dir))
    if args.header:
        spit(outfile, email_extract.headerrow() + "\n")

    for i, line in enumerate(skip(args.infile, at_start=args.start)):
        if ((not args.limit == 0) and (i >= args.limit)):
            break;
        try:
            fp = line.strip()
            guid = email_extract.md5(fp)
            category = email_extract.categoryList(fp)
            buff = slurp(fp)

            row = email_extract.extract(guid, buff, args.out_dir, category, args.target_email)
            spit(outfile, row + "\n")
        except Exception as e:
            print "exception line: {} | {} ".format(i, e.message)

        if i % 100 == 0:
            prn("completed line: {}".format(i + args.start)) 
Ejemplo n.º 6
0
    cat input_file.tsv | ./printview.py
    '''
    parser = argparse.ArgumentParser(
        description="printview",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=desc)
    parser.add_argument("target", help="target email")
    parser.add_argument("tmpl", help="path to template file")
    parser.add_argument("infile",
                        nargs='?',
                        type=argparse.FileType('r'),
                        default=sys.stdin,
                        help="Input File")

    args = parser.parse_args()
    T = Template(slurp(args.tmpl))

    def split(x, c):
        a = x.split(c) if x else ''
        return a if a else []

    def formatName(n):
        a = n.split() if n else []
        return ' '.join(a[:5])

    def formatScore(s):
        x = float(s) * 100
        return "{:10.2f}%".format(x)

    def getTopics(_id):
        with newman_connector() as cnx:
Ejemplo n.º 7
0
    parser.add_argument("target_email", help="Target Email")
    parser.add_argument("out_dir", help="Output Directory")
    parser.add_argument("infile",
                        nargs='?',
                        type=argparse.FileType('r'),
                        default=sys.stdin,
                        help="Input File")
    args = parser.parse_args()
    outfile = "{}/output.csv".format(args.out_dir)
    mkdirp("{}/emails".format(args.out_dir))
    if args.header:
        spit(outfile, email_extract.headerrow() + "\n")

    for i, line in enumerate(skip(args.infile, at_start=args.start)):
        if ((not args.limit == 0) and (i >= args.limit)):
            break
        try:
            fp = line.strip()
            guid = email_extract.md5(fp)
            category = email_extract.categoryList(fp)
            buff = slurp(fp)

            row = email_extract.extract(guid, buff, args.out_dir, category,
                                        args.target_email)
            spit(outfile, row + "\n")
        except Exception as e:
            print "exception line: {} | {} ".format(i, e.message)

        if i % 100 == 0:
            prn("completed line: {}".format(i + args.start))
Ejemplo n.º 8
0
if __name__ == "__main__":
    desc = '''
examples:
    cat input_file.tsv | ./printview.py
    '''
    parser = argparse.ArgumentParser(
        description="printview", 
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=desc)
    parser.add_argument("target", help="target email")
    parser.add_argument("tmpl", help="path to template file")
    parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File")

    args = parser.parse_args()
    T = Template(slurp(args.tmpl))

    def split(x, c): 
        a= x.split(c) if x else ''
        return a if a else []

    def formatName(n):
        a = n.split() if n else []
        return ' '.join(a[:5])

    def formatScore(s):
        x = float(s) * 100
        return "{:10.2f}%".format(x)

    def getTopics(_id):
        with newman_connector() as cnx:
Ejemplo n.º 9
0
        
    msg = clean_string(msg, [EXPR_OPTS['fix_utf8']])
    spit("{}/{}.txt".format(_dir, email_id), msg)
    row= createRow(email_id, "emails/{}".format(email_id), target_email, mail, categories, attach, msg)

    return row

if __name__ == "__main__":

    desc = '''
examples:
    cat email.eml | ./this.py
    '''
    parser = argparse.ArgumentParser(
        description=" ... ", 
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=desc)
    parser.add_argument("target_email", help="target email")
    parser.add_argument("outdir", help="Out Dir")
    parser.add_argument("file_path", help="File Path")
    #parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File")
    args = parser.parse_args()
    guid = md5(args.file_path)
    category = categoryList(args.file_path)
    buff = slurp(args.file_path)
    row = extract(guid, buff, args.outdir, category, args.target_email)

    print row


Ejemplo n.º 10
0
    msg = clean_string(msg, [EXPR_OPTS['fix_utf8']])
    spit("{}/{}.txt".format(_dir, email_id), msg)
    row = createRow(email_id, "emails/{}".format(email_id), target_email, mail,
                    categories, attach, msg)

    return row


if __name__ == "__main__":

    desc = '''
examples:
    cat email.eml | ./this.py
    '''
    parser = argparse.ArgumentParser(
        description=" ... ",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=desc)
    parser.add_argument("target_email", help="target email")
    parser.add_argument("outdir", help="Out Dir")
    parser.add_argument("file_path", help="File Path")
    #parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File")
    args = parser.parse_args()
    guid = md5(args.file_path)
    category = categoryList(args.file_path)
    buff = slurp(args.file_path)
    row = extract(guid, buff, args.outdir, category, args.target_email)

    print row
Ejemplo n.º 11
0
def getIngestLog(*args):
    job_id = nth(args, 0)
    logfile = "{}/{}.tee.log".format(work_dir, job_id)    
    sz = slurp(logfile)
    tangelo.content_type("application/json")    
    return {'log' : sz }
Ejemplo n.º 12
0
def getState(*args):
    email_addr = nth(args, 0)
    logfile = "{}/{}.log".format(work_dir, email_addr)
    sz = slurp(logfile)
    tangelo.content_type("application/json")    
    return {'log' : sz }