# Path: install/packages.py
# def install(installType):
# 
# Path: install/bro.py
# def install(chosenInterface,webServer):
# 
# Path: install/criticalStack.py
# def get_user_input(input_string):
# def install(csKey):
# 
# Path: install/logstash.py
# def get_user_input(input_string):
# def install(esServer,esUser,esPass):
# 
# Path: install/kibana.py
# def install(chosenInterfaceIP):
# def importDashboard(jsonFileName):
# def importIndexMapping(jsonFileName):
# 
# Path: install/sweetSecurity.py
# def installClient(chosenInterface):
# def installServer():
# def addWebCreds(address,user,pwd,location):
# 
# Path: install/apache.py
# def get_user_input(input_string):
# def install(installType,chosenInterface,chosenIP):
# 
# Path: install/fail2ban.py
# def install():


import argparse, fcntl, getpass, json, os, re, shutil, socket, sqlite3, struct, sys
from time import sleep
from install import packages
from install import bro
from install import criticalStack
from install import elasticSearch
from install import logstash
from install import kibana
from install import sweetSecurity
from install import apache
from install import fail2ban
        #		print "Must choose Y or N."
        #	else:
        #		break
        # if installFail2Ban == 'y' or installFail2Ban == '':
        #	fail2ban.install()
        apache.install(installType, chosenInterface, chosenInterfaceIP)
        print "  Creating web portal credentials"
        os.popen('sudo htpasswd -cb /etc/apache2/.htpasswd %s "%s"' % (httpUser, httpPass)).read()
        os.popen('sudo htpasswd -cb /etc/apache2/.elasticsearch %s "%s"' % (elasticUser, elasticPass)).read()
        # Get system default configurations
        fileCheckKey = None
        while True:
            installFileCheck = get_user_input("\033[1mCheck Files Against FileCheck.IO (y/N)\033[0m: ")
            if installFileCheck.lower() not in ('y', 'n', ''):
                print "Must choose Y or N."
            else:
                break
        if installFileCheck.lower() == 'y':
            installFileCheck = 'y'
            while True:
                fileCheckKey = get_user_input("    \033[1mEnter Your FileCheckIO API Key\033[0m: ")
                if not re.match(r'[0-9a-fA-F]{56}', fileCheckKey):
                    print("        Not a valid API key.")
                else:
                    break
        elasticSearch.install(fileCheckKey)
        kibana.install(chosenInterfaceIP)
        print "Restarting Apache"
        os.popen('sudo service apache2 restart').read()
        logstash.install('localhost', elasticUser, elasticPass)

# Path: install/packages.py
# def install(installType):
# 
# Path: install/bro.py
# def install(chosenInterface,webServer):
# 
# Path: install/criticalStack.py
# def get_user_input(input_string):
# def install(csKey):
# 
# Path: install/logstash.py
# def get_user_input(input_string):
# def install(esServer,esUser,esPass):
# 
# Path: install/kibana.py
# def install(chosenInterfaceIP):
# def importDashboard(jsonFileName):
# def importIndexMapping(jsonFileName):
# 
# Path: install/sweetSecurity.py
# def installClient(chosenInterface):
# def installServer():
# def addWebCreds(address,user,pwd,location):
# 
# Path: install/apache.py
# def get_user_input(input_string):
# def install(installType,chosenInterface,chosenIP):
# 
# Path: install/fail2ban.py
# def install():


# Path: setup.py
import argparse, fcntl, getpass, json, os, re, shutil, socket, sqlite3, struct, sys
from time import sleep
from install import packages
from install import bro
from install import criticalStack
from install import elasticSearch
from install import logstash
from install import kibana
from install import sweetSecurity
from install import apache
from install import fail2ban

        #		print "Must choose Y or N."
        #	else:
        #		break
        # if installFail2Ban == 'y' or installFail2Ban == '':
        #	fail2ban.install()
        apache.install(installType, chosenInterface, chosenInterfaceIP)
        print "  Creating web portal credentials"
        os.popen('sudo htpasswd -cb /etc/apache2/.htpasswd %s "%s"' % (httpUser, httpPass)).read()
        os.popen('sudo htpasswd -cb /etc/apache2/.elasticsearch %s "%s"' % (elasticUser, elasticPass)).read()
        # Get system default configurations
        fileCheckKey = None
        while True:
            installFileCheck = get_user_input("\033[1mCheck Files Against FileCheck.IO (y/N)\033[0m: ")
            if installFileCheck.lower() not in ('y', 'n', ''):
                print "Must choose Y or N."
            else:
                break
        if installFileCheck.lower() == 'y':
            installFileCheck = 'y'
            while True:
                fileCheckKey = get_user_input("    \033[1mEnter Your FileCheckIO API Key\033[0m: ")
                if not re.match(r'[0-9a-fA-F]{56}', fileCheckKey):
                    print("        Not a valid API key.")
                else:
                    break
        elasticSearch.install(fileCheckKey)
        kibana.install(chosenInterfaceIP)
        print "Restarting Apache"
        os.popen('sudo service apache2 restart').read()
        logstash.install('localhost', elasticUser, elasticPass)

        sweetSecurity.installClient(chosenInterface)