#!/usr/bin/env python

import os
from optparse import OptionParser

def highlight(status, watch):
    if watch:
	return status.upper()
    elif status == 'running':
	return '\x1b[32mRUNNING\x1b[0m'
    elif status == 'start':
        return '\x1b[36mSTART\x1b[0m'
    else:
        return '\x1b[31m%s\x1b[0m'%(status.upper())

def main(watch):
    print 'Services:\n'
    status  = os.popen('systemctl status spoofer | grep Active').readlines()[0].strip().split('(')[1].split(')')[0]
    print 'Spoofer------: {}'.format(highlight(status, watch))

    status  = os.popen('systemctl status flipevil | grep Active').readlines()[0].strip().split('(')[1].split(')')[0]
    print 'Flip Evil----: {}'.format(highlight(status, watch))


    status  = os.popen('systemctl status snortd | grep Active').readlines()[0].strip().split('(')[1].split(')')[0]
    print 'Snort--------: {}'.format(highlight(status, watch))


    status  = os.popen('systemctl status syslog-ng | grep Active').readlines()[0].strip().split('(')[1].split(')')[0]
    print 'Syslog-ng----: {}'.format(highlight(status, watch))

    status  = os.popen('systemctl status chksnort | grep Active').readlines()[0].strip().split('(')[1].split(')')[0]
    print 'Snort checker: {}'.format(highlight(status, watch)) 
    print ''
    print '------------------------------'
    
    print 'Evil logs:\n'
    log_p = '/var/log/spoofer/curr_evil.log'
    if os.path.isfile(log_p):
    	logf = open(log_p, 'r')
        logs = logf.readlines()
    	logs = logs[len(logs) - 7:]
    	logf.close()
    	for log in logs:
	    print log.strip()     
        print ''
        print '------------------------------'
    else:
        print 'No logfile present'
        print ''
        print '------------------------------'

    print 'Snort Alerts:\n'
    alert_p = '/var/log/snort/alert'
    if os.path.isfile(alert_p):
        alertf = open(alert_p, 'r')
        alerts = alertf.readlines()
        alerts = alerts[len(alerts) - 14:]
        alertf.close()
        for line in alerts:
            print line.strip()
    else:
        print 'No alert file present'
        print ''
        print '------------------------------'

if __name__ == '__main__':
    parser = OptionParser()    
    parser.add_option('-w', '--watch', dest = 'watch', help = 'use to run with no colors', default = False, action = 'store_true')
    (options, args) = parser.parse_args()
    main(options.watch)

