core_gatekeeper
"""
Copyright (C) 2020 New Entity Operations Inc.
ALL RIGHTS RESERVED
core_gatekeeper handles default authentication tasks and will permit or kick
members according to set definitions
"""
## Gatekeeper imports
import tkinter as ITL
# from imports
from tkinter import (
ttk,
PhotoImage,
Menu,
_tkinter
)
## Imports: Addons
from PIL import (
Image,
ImageTk
)
## Imports: Custom
from core_settings import (
# The Special Member
PUBLIC_MEMBER,
)
from core_middlelayer import (
# Copyright
COPYRIGHT,
SUBCOPYRIGHT,
# Activities
ALIENACTION,
ALIENCREATORTITLE,
ALIENHEIGHT,
ALIENTITLE,
ALIENWIDTH,
# Static Content
gatekeeper_photo,
gatekeeper_IDENTITY_NAME,
gatekeeper_KEY_NAME,
gatekeeper_TEXT_FRONT,
SLUG_ICON, FE_ICON,
PATH_MEMBER_ACTIVE, MEMBER_ACTIVE_HOLDER,
# Data
DIRDATA,
# The Logged In Member
LOGIN_MEMBER,
# Keys
KEY, KEY_LOCATION
)
from core_operations import (
# Main AlienVault import
AlienVault
)
## Imports: Logs and Alerts
from core_alerts import (
ACTION_AUDITED,
ALERT_LOGGING_WARNING
)
class ALIEN_VAULT_CONSTRUCT():
def __init__(self):
"""
Create a main login screen to unlock the application
First, try the default key
"""
self.FRONTEND_ALIEN_VAULT = ITL.Tk()
self.FRONTEND_ALIEN_VAULT.geometry(ALIENHEIGHT+
'x'+ALIENWIDTH
)
self.FRONTEND_ALIEN_VAULT.title(ALIENTITLE)
self.FRONTEND_ALIEN_VAULT.resizable("no", "no")
self.FRONTEND_ALIEN_VAULT.tk.call('wm',
'iconphoto',
self.FRONTEND_ALIEN_VAULT._w,
PhotoImage(file=SLUG_ICON+FE_ICON)
)
self.FE_ALIEN_VAULT_COLORS = ["Black"]
ALIEN_VAULT_CONTROLLER = ttk.Notebook(self.FRONTEND_ALIEN_VAULT)
# Login Member
ENTITY_LOGIN = ttk.Frame(ALIEN_VAULT_CONTROLLER)
ALIEN_VAULT_CONTROLLER.add(ENTITY_LOGIN, text=ALIENACTION)
# Add Member
ENTITY_ADD_MEMBER = ttk.Frame(ALIEN_VAULT_CONTROLLER)
ALIEN_VAULT_CONTROLLER.add(
ENTITY_ADD_MEMBER, text=ALIENCREATORTITLE
)
HANGER = ITL.Frame(ENTITY_LOGIN, bg='Black')
HANGER.place(x=0, y=0)
## Frame Support Code
def ALERT_MESSAGE_INFO_COPYRIGHT():
"""
Standard Copyright Info output
"""
MB.showinfo('Copyright Information',
COPYRIGHT+'\n'+SUBCOPYRIGHT
)
def _QuitCORE():
"""
Quit and Exit button logic
"""
response = MB.askyesnocancel('Confirm Quit',
QUITALERT
)
if response == True:
self.FRONTEND_ALIEN_VAULT.quit()
self.FRONTEND_ALIEN_VAULT.destroy()
exit()
else:
pass
def create_entity_menu_AV(self):
"""
ENTITY MENU
"""
MENU_ALIEN_VAULT = Menu(self.FRONTEND_ALIEN_VAULT)
self.FRONTEND_ALIEN_VAULT.config(menu=MENU_ALIEN_VAULT)
NavigatorAlienVaultMenu = Menu(MENU_ALIEN_VAULT,
tearoff=0
)
NavigatorAlienVaultMenu.add_command(label="EXIT",
command=_QuitCORE
)
MENU_ALIEN_VAULT.add_cascade(label="File",
menu=NavigatorAlienVaultMenu
)
NavigatorAlienVaultHelpMenu = Menu(MENU_ALIEN_VAULT,
tearoff=0
)
NavigatorAlienVaultHelpMenu.add_command(label="Copyright",
command=ALERT_MESSAGE_INFO_COPYRIGHT
)
MENU_ALIEN_VAULT.add_cascade(label="Help",
menu=NavigatorAlienVaultHelpMenu
)
create_entity_menu_AV(self)
## Base
try:
OperatorImageBadgeOpening = Image.open(gatekeeper_photo)
OperatorImageBadgeSized = OperatorImageBadgeOpening.resize((89, 89),
Image.ANTIALIAS
)
OperatorImageBadgeOpeningPhoto = ImageTk.PhotoImage(
OperatorImageBadgeSized
)
LabelOverviewOperatorBadgeOpening = ITL.Label(ENTITY_LOGIN,
text='Hello '+PUBLIC_MEMBER
)
LabelOverviewOperatorBadgeOpening.place(x=389, y=34)
LabelOverviewOperatorBadgeOpening.config(
image=OperatorImageBadgeOpeningPhoto,
text='Hello'+PUBLIC_MEMBER
)
LabelOverviewOperatorBadgeOpening.image = OperatorImageBadgeOpeningPhoto
except:
FileNotFoundError
print(
"Gatekeeper Emblem Wasn't located, try another location"
)
try:
CORE_ADD_MEMBER_HEADING = ttk.Label(ENTITY_ADD_MEMBER,
text=ALIENCREATORTITLE
)
CORE_ADD_MEMBER_HEADING.place(x=44, y=64)
OVERVIEW_MEMBER_BADGE_OPENING = ITL.Frame(ENTITY_ADD_MEMBER)
OVERVIEW_MEMBER_BADGE_OPENING.place(x=389, y=34)
AddMemberText = ttk.Label(ENTITY_ADD_MEMBER,
text=gatekeeper_IDENTITY_NAME
)
AddMemberText.place(x=44, y=200)
ADD_MEMBER_INPUT = ITL.StringVar()
ADD_MEMBER_INPUT = ttk.Entry(ENTITY_ADD_MEMBER,
width=25,
textvariable=ADD_MEMBER_INPUT
)
ADD_MEMBER_INPUT.place(x=44, y=144)
# Establish the cursor
ADD_MEMBER_INPUT.focus()
AddMemberAlertTextIdentity = ttk.Label(ENTITY_ADD_MEMBER,
text=' '
)
AddMemberAlertTextIdentity.place(x=200, y=200)
# Key
AddMemberKeyText = ttk.Label(ENTITY_ADD_MEMBER,
text=gatekeeper_KEY_NAME
)
AddMemberKeyText.place(x=44, y=300)
ADD_MEMBER_KEY_INPUT = ITL.StringVar()
ADD_MEMBER_KEY_INPUT = ttk.Entry(ENTITY_ADD_MEMBER,
show="*",
width=25,
textvariable=ADD_MEMBER_KEY_INPUT
)
ADD_MEMBER_KEY_INPUT.place(x=44, y=244)
# Establish the cursor
ADD_MEMBER_KEY_INPUT.focus()
AddMemberAlertTextKey = ttk.Label(ENTITY_ADD_MEMBER, text=' ')
AddMemberAlertTextKey.place(x=200, y=300)
AddAlertText = ttk.Label(ENTITY_ADD_MEMBER
)
AddAlertText.place(x=200, y=200)
CORE_OPENING_HEADING = ttk.Label(ENTITY_LOGIN,
text=gatekeeper_TEXT_FRONT+'\u2122'
)
CORE_OPENING_HEADING.place(x=44, y=64)
OVERVIEW_OPERATOR_BADGE_OPENING = ITL.Frame(ENTITY_LOGIN)
OVERVIEW_OPERATOR_BADGE_OPENING.place(x=389, y=34)
LoginMemberText = ttk.Label(ENTITY_LOGIN,
text=gatekeeper_IDENTITY_NAME
)
LoginMemberText.place(x=44, y=200)
MEMBER_INPUT = ITL.StringVar()
MEMBER_INPUT = ttk.Entry(ENTITY_LOGIN,
width=25,
textvariable=MEMBER_INPUT
)
MEMBER_INPUT.place(x=44, y=144)
# Establish the cursor
MEMBER_INPUT.focus()
LoginAlertTextIdentity = ttk.Label(ENTITY_LOGIN,
text=' '
)
LoginAlertTextIdentity.place(x=200, y=200)
# Key
LoginKeyText = ttk.Label(ENTITY_LOGIN,
text=gatekeeper_KEY_NAME
)
LoginKeyText.place(x=44, y=300)
KEY_INPUT = ITL.StringVar()
KEY_INPUT = ttk.Entry(ENTITY_LOGIN,
show="*",
width=25,
textvariable=KEY_INPUT
)
KEY_INPUT.place(x=44, y=244)
# Establish the cursor
KEY_INPUT.focus()
LoginAlertTextKey = ttk.Label(ENTITY_LOGIN, text=' ')
LoginAlertTextKey.place(x=200, y=300)
except:
_tkinter.TclError
print("The environment has been destroyed")
def style_login():
style = ttk.Style()
style.theme_settings("default",
{"TNotebook.Tab": {"configure": {"padding": [30, 30]}}}
)
class Authenticate:
style_login()
def add_member(event=None):
"""
Allows someone with access to the system to create a unpriv'd member.
If there are no members on the system yet, this will default to a dummy account until setup
"""
from core_seeker import IPDVS
IPDVS.ACCESS.add_member(
vcnkey=ADD_MEMBER_INPUT.get(),
vcnkey_hash=ADD_MEMBER_KEY_INPUT.get()
)
try:
invisible_object = IPDVS.BINGO_BUCKET[0]
print("MEMBER FORM ADDED")
ADD_MEMBER_INPUT.delete(0, ITL.END)
ADD_MEMBER_KEY_INPUT.delete(0, ITL.END)
AddAlertText.configure(text="New member created")
IPDVS.BINGO_BUCKET.clear()
except:
IndexError
print("MEMBER WAS NOT ADDED")
ADD_MEMBER_INPUT.delete(0, ITL.END)
ADD_MEMBER_KEY_INPUT.delete(0, ITL.END)
AddAlertText.configure(
text="There was an error. \nCheck terminal output"
)
def login(event=None):
"""
Reads the defined VCN Key.
Takes the KEY_INPUT and hashes it in a seperate module, by testing for True
"""
HASHED_LOGIN_KEY = KEY_INPUT.get()
MEMBER_ACTIVE = MEMBER_INPUT.get()
from core_seeker import IPDVS
IPDVS.ACCESS.validate_member(
vcnkey=MEMBER_ACTIVE,
vcnkey_hash=HASHED_LOGIN_KEY
)
try:
invisible_object = IPDVS.BINGO_BUCKET[0]
print("MEMBER LOCATED...")
IPDVS.BINGO_BUCKET.clear()
try:
invisible_key = IPDVS.WAS_VALID[0]
IPDVS.WAS_VALID.clear()
# Set the network communication slugs to reflect the correct member
from core_add import SET_POSTER
SET_POSTER.bind()
# AUDIT
AUTHENTICATE__login__LOGGER = \
"[AUTHENTICATE__login__LOGGER: "
AUTHENTICATE__login__helper = \
"System Member: Entry Validated]"
AUTHENTICATE__login__special = \
" [SYSTEM_MEMBER: "+MEMBER_ACTIVE+"]"
print(AUTHENTICATE__login__LOGGER+\
AUTHENTICATE__login__helper+\
AUTHENTICATE__login__special+"\n")
ACTION_AUDITED(variable=\
AUTHENTICATE__login__LOGGER+\
AUTHENTICATE__login__helper+\
AUTHENTICATE__login__special)
with open(PATH_MEMBER_ACTIVE+MEMBER_ACTIVE_HOLDER, 'w') as AMEMBER:
AMEMBER.write(MEMBER_ACTIVE)
AMEMBER.close()
AlienVaultInstance.FRONTEND_ALIEN_VAULT.destroy()
from core_FRONTEND import ENTITY_CONSTRUCT
START_INSTANCE = ENTITY_CONSTRUCT()
START_INSTANCE.FRONTEND_INTERFACE.mainloop()
except:
IndexError
print("It seems that the key is invalid.")
LoginAlertTextIdentity.configure(text=" ")
LoginAlertTextKey.configure(text="Invalid Key")
except:
IndexError
# To handle unexpected output, uncomment the lines below and it'll show the error
# To hide these errors, uncomment the try: block below (better for production environments)
print("Invalid Member: Not located.")
MEMBER_INPUT.delete(0, ITL.END)
KEY_INPUT.delete(0, ITL.END)
LoginAlertTextKey.configure(text=" ")
LoginAlertTextIdentity.configure(text="Invalid Member")
#try:
# MEMBER_INPUT.delete(0, ITL.END)
# KEY_INPUT.delete(0, ITL.END)
# LoginAlertTextKey.configure(text=" ")
# LoginAlertTextIdentity.configure(text="Invalid Member")
#except:
# _tkinter.TclError
# print("The instance was terminated by the menu operator.")
def login_binder():
self.FRONTEND_ALIEN_VAULT.bind('',
Authenticate.login
)
try:
with open(DIRDATA+KEY, 'r') as f:
f_line = f.readlines()
f.close()
except:
FileNotFoundError
#*******************************************************#
# SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK #
#*******************************************************#
print(
"---------- SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK ----------"
)
print("No system key was found")
print("---- FALLBACK ----")
print(
"---------- SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK ----------"
)
#************************************************************#
# SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK #
#************************************************************#
try:
with open(KEY_LOCATION, 'r') as fg:
fg_line = fg.readlines()
if f_line == fg_line:
#*******************************************************#
# SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK #
#*******************************************************#
print(
"---------- SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK ----------"
)
self.FRONTEND_ALIEN_VAULT.destroy()
from core_FRONTEND import ENTITY_CONSTRUCT
START_INSTANCE = ENTITY_CONSTRUCT()
try:
START_INSTANCE.FRONTEND_INTERFACE.mainloop()
print(
"---------- SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK ----------"
)
#************************************************************#
# SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK #
#************************************************************#
except:
# This will run when you exit via the menu instance termination
_tkinter.TclError
print("The program is now down")
else:
#*******************************************************#
# SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK #
#*******************************************************#
print(
"---------- SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK ----------"
)
print("VCNKEY Mismatch: " \
"Make sure to update your keys. Falling back..."
)
print(
"---------- SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK ----------"
)
#************************************************************#
# SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK #
#************************************************************#
fg.close()
login_binder()
except:
FileNotFoundError
#*******************************************************#
# SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK #
#*******************************************************#
print(
"---------- SYSTEM ENABLED: START: Expand Step 10 - KEY CHECK ----------"
)
print(
"A system key was found, but not a VCNKEY"
)
print(KEY_LOCATION)
print(
"---------- SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK ----------"
)
#************************************************************#
# SYSTEM ENABLED: CONTINUE: Expand Step 10 - KEY CHECK #
#************************************************************#
try:
login_binder()
except:
_tkinter.TclError
print("The window was terminated, instance shuting down...")
ADD_MEMBER = ttk.Button(ENTITY_ADD_MEMBER,
text=ALIENCREATORTITLE,
command=Authenticate.add_member
)
ADD_MEMBER.place(x=320, y=400)
LOGIN = ttk.Button(ENTITY_LOGIN,
text="LOGIN",
command=Authenticate.login
)
LOGIN.place(x=320, y=400)
ALIEN_VAULT_CONTROLLER.pack(expand=1, fill="both")
## Runner
#START_INSTANCE = ENTITY_CONSTRUCT()
#START_INSTANCE.FRONTEND_INTERFACE.mainloop()
try:
AlienVaultInstance = ALIEN_VAULT_CONSTRUCT()
AlienVaultInstance.FRONTEND_ALIEN_VAULT.mainloop()
except:
_tkinter.TclError
print("**Shutdown complete**")
Return HOME