EntityScript

Draft 1.2:
Index


core_gatekeeper




# -*- coding: utf-8 -*-
"""
COPYRIGHT (C) 2020-2023 NEW ENTITY OPERATIONS INC. ALL RIGHTS RESERVED
INSTANCE: core_gatekeeper
MODIFIED: 2023/05/26
OVERVIEW:

core_gatekeeper handles default authentication tasks and will permit or kick
members according to set definitions

"""
__version__ = "0.0.7"
__author__ = "Ryan McKenna"
__copyright__ = "Copyright (C) 2020-2023 New Entity Operations Inc."
__credits__ = [
 "Ryan McKenna",
 "New Entity Operations Inc.", "New Entity Operations, LLC"]
__email__ = "Operator@NewEntityOperations.com"
__license__ = "New Entity License"
__maintainer__ = "Ryan McKenna"
__status__ = "Production"

from tkinter import (END, Frame, Label, Menu, PhotoImage, StringVar, Tk,
 ttk, _tkinter)

## Static, non-circular bucket location
from DATA.alien_vault import (ALIEN_MANIFEST,
 VAULT_ALIENACTION, VAULT_ALIENCREATORTITLE,
 VAULT_ALIENHEIGHT, VAULT_ALIENTITLE, VAULT_ALIENWIDTH, VAULT_COPYRIGHT,
 VAULT_DIRDATA, VAULT_FE_ICON, VAULT_gatekeeper_photo,
 VAULT_gatekeeper_IDENTITY_NAME, VAULT_gatekeeper_KEY_NAME,
 VAULT_gatekeeper_TEXT_FRONT, VAULT_KEY, VAULT_KEY_LOCATION,
 VAULT_MEMBER_ACTIVE_HOLDER, VAULT_PATH_MEMBER_ACTIVE, VAULT_SLUG_ICON,
 VAULT_SUBCOPYRIGHT, VAULT_QUITALERT, VAULT_Image, VAULT_ImageTk,
 VAULT_KEY_BOUND, VAULT_MB, VAULT_oFo, VAULT_PATH_INSTANCE, VAULT_PUBLIC_MEMBER,
 VAULT_DEBUG_GATEKEEPER, VAULT_DEBUG_LOGGER, VAULT_DEBUG_STEPS,
 VAULT_ACTION_AUDITED)

## Logging
from preset.logging import LoggingGatekeeper as LGatekeeper

## Base imports
from core_add import (BUCKET_BINGO, IPDVC, SET_POSTER, WAS_VALID)

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 = Tk()
  self.FRONTEND_ALIEN_VAULT.geometry(VAULT_ALIENHEIGHT[0]+ALIEN_MANIFEST.x+\
   VAULT_ALIENWIDTH[0])
  self.FRONTEND_ALIEN_VAULT.title(VAULT_ALIENTITLE[0])
  self.FRONTEND_ALIEN_VAULT.resizable(ALIEN_MANIFEST.no, ALIEN_MANIFEST.no)
  self.FRONTEND_ALIEN_VAULT.tk.call(ALIEN_MANIFEST.wm, ALIEN_MANIFEST.iconphoto,
  self.FRONTEND_ALIEN_VAULT._w, PhotoImage(file=VAULT_SLUG_ICON[0]+\
   VAULT_FE_ICON[0]))
  ALIEN_VAULT_CONTROLLER = ttk.Notebook(self.FRONTEND_ALIEN_VAULT)
  ## Login Member
  ENTITY_LOGIN = Frame(ALIEN_VAULT_CONTROLLER)
  ALIEN_VAULT_CONTROLLER.add(ENTITY_LOGIN, text=VAULT_ALIENACTION[0])
  ## Add Member
  ENTITY_ADD_MEMBER = ttk.Frame(ALIEN_VAULT_CONTROLLER)
  ALIEN_VAULT_CONTROLLER.add(ENTITY_ADD_MEMBER, text=VAULT_ALIENCREATORTITLE[0])
  HANGER = ttk.Frame(ENTITY_LOGIN)
  HANGER.place(x=0, y=0)

  ## Frame Support Code
  def ALERT_MESSAGE_INFO_COPYRIGHT():
   """
   Standard Copyright Info output
   """
   VAULT_MB[0].showinfo(ALIEN_MANIFEST.copyright_information,
     VAULT_COPYRIGHT[0]+ALIEN_MANIFEST.breakpoint+VAULT_SUBCOPYRIGHT[0])

  def _QuitCORE():
   """
   Quit and Exit button logic
   """
   response = VAULT_MB[0].askyesnocancel(ALIEN_MANIFEST.confirm_quit,
    VAULT_QUITALERT[0])
   if response == ALIEN_MANIFEST.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=ALIEN_MANIFEST.exit,
    command=_QuitCORE)
   MENU_ALIEN_VAULT.add_cascade(label=ALIEN_MANIFEST.file,
    menu=NavigatorAlienVaultMenu)
   NavigatorAlienVaultHelpMenu = Menu(MENU_ALIEN_VAULT, tearoff=0)
   NavigatorAlienVaultHelpMenu.add_command(label=ALIEN_MANIFEST.copyright,
    command=ALERT_MESSAGE_INFO_COPYRIGHT)
   MENU_ALIEN_VAULT.add_cascade(label=ALIEN_MANIFEST.help,
    menu=NavigatorAlienVaultHelpMenu)

  ## create menu
  create_entity_menu_AV(self)

  ## Base
  try:
   try:
    OperatorImageBadgeOpening = VAULT_Image[0].open(VAULT_gatekeeper_photo[0])
    OperatorImageBadgeSized = OperatorImageBadgeOpening.resize((89, 89),
     VAULT_Image[0].ANTIALIAS)
    OperatorImageBadgeOpeningPhoto = VAULT_ImageTk[0].PhotoImage(
     OperatorImageBadgeSized)
   except IndexError as e:
    VAULT_DEBUG_GATEKEEPER[0].error_missing_vault_image()
   LabelOverviewOperatorBadgeOpening = Label(ENTITY_LOGIN,
    text=ALIEN_MANIFEST.hello+VAULT_PUBLIC_MEMBER[0])
   LabelOverviewOperatorBadgeOpening.place(x=389, y=34)
   try:
    LabelOverviewOperatorBadgeOpening.config(
     image=OperatorImageBadgeOpeningPhoto,
     text=ALIEN_MANIFEST.hello+VAULT_PUBLIC_MEMBER[0])
    LabelOverviewOperatorBadgeOpening.image = OperatorImageBadgeOpeningPhoto
   except UnboundLocalError:
    VAULT_DEBUG_GATEKEEPER[0].error_cannot_set_vault_image()
  except FileNotFoundError:
   VAULT_DEBUG_GATEKEEPER[0].error_gatekeeper_emblem_not_located()

  try:
   CORE_ADD_MEMBER_HEADING = ttk.Label(ENTITY_ADD_MEMBER,
   text=VAULT_ALIENCREATORTITLE[0])
   CORE_ADD_MEMBER_HEADING.place(x=44, y=64)
   OVERVIEW_MEMBER_BADGE_OPENING = Frame(ENTITY_ADD_MEMBER)
   OVERVIEW_MEMBER_BADGE_OPENING.place(x=389, y=34)
   AddMemberText = ttk.Label(ENTITY_ADD_MEMBER,
    text=VAULT_gatekeeper_IDENTITY_NAME[0])
   AddMemberText.place(x=44, y=200)
   ADD_MEMBER_INPUT = 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=ALIEN_MANIFEST.space)
   AddMemberAlertTextIdentity.place(x=200, y=200)
   ## Key
   AddMemberKeyText = ttk.Label(ENTITY_ADD_MEMBER,
    text=VAULT_gatekeeper_KEY_NAME[0])
   AddMemberKeyText.place(x=44, y=300)
   ADD_MEMBER_KEY_INPUT = StringVar()
   ADD_MEMBER_KEY_INPUT = ttk.Entry(ENTITY_ADD_MEMBER,
    show=ALIEN_MANIFEST.star, 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=ALIEN_MANIFEST.space)
   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=VAULT_gatekeeper_TEXT_FRONT[0]+ALIEN_MANIFEST.generic_shortcode)
   CORE_OPENING_HEADING.place(x=44, y=64)
   OVERVIEW_OPERATOR_BADGE_OPENING = Frame(ENTITY_LOGIN)
   OVERVIEW_OPERATOR_BADGE_OPENING.place(x=389, y=34)
   LoginMemberText = ttk.Label(ENTITY_LOGIN,
    text=VAULT_gatekeeper_IDENTITY_NAME[0])
   LoginMemberText.place(x=44, y=200)
   MEMBER_INPUT = 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=ALIEN_MANIFEST.space)
   LoginAlertTextIdentity.place(x=200, y=200)
   ## Key
   LoginKeyText = ttk.Label(ENTITY_LOGIN, text=VAULT_gatekeeper_KEY_NAME[0])
   LoginKeyText.place(x=44, y=300)
   KEY_INPUT = StringVar()
   KEY_INPUT = ttk.Entry(ENTITY_LOGIN, show=ALIEN_MANIFEST.star, width=25,
    textvariable=KEY_INPUT)
   KEY_INPUT.place(x=44, y=244)
   ## Establish the cursor
   KEY_INPUT.focus()
   LoginAlertTextKey = ttk.Label(ENTITY_LOGIN, text=ALIEN_MANIFEST.space)
   LoginAlertTextKey.place(x=200, y=300)
  except _tkinter.TclError:
   VAULT_DEBUG_GATEKEEPER[0].environment_destroyed()

  def style_login():
   style = ttk.Style()
   style.theme_settings(ALIEN_MANIFEST.default,
    {ALIEN_MANIFEST.notebook: {ALIEN_MANIFEST.configure: {
     ALIEN_MANIFEST.padding: [ALIEN_MANIFEST.NBW, ALIEN_MANIFEST.NBH]}}})

  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
    """
    IPDVC.ACCESS.add_member(vcnkey=ADD_MEMBER_INPUT.get(),
     vcnkey_hash=ADD_MEMBER_KEY_INPUT.get())
    try:
     invisible_object = BUCKET_BING[0]
     VAULT_DEBUG_GATEKEEPER[0].member_form_status(STAUTS="ADDED")
     ADD_MEMBER_INPUT.delete(0, END)
     ADD_MEMBER_KEY_INPUT.delete(0, END)
     AddAlertText.configure(text=ALIEN_MANIFEST.new_member_created)
     BUCKET_BINGO.clear()
    except IndexError:
     VAULT_DEBUG_GATEKEEPER[0].member_form_status(STAUTS="NOT ADDED")
     ADD_MEMBER_INPUT.delete(0, END)
     ADD_MEMBER_KEY_INPUT.delete(0, END)
     AddAlertText.configure(text=ALIEN_MANIFEST.error_check_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()
    IPDVC.ACCESS.validate_member(vcnkey=MEMBER_ACTIVE,
    vcnkey_hash=HASHED_LOGIN_KEY)
    try:
     ## member, granted
     VAULT_DEBUG_STEPS[0].step_13(MODE="START")
     invisible_object = BUCKET_BINGO[0]
     VAULT_DEBUG_GATEKEEPER[0].member_located()
     BUCKET_BINGO.clear()
     try:
      invisible_key = WAS_VALID[0]
      WAS_VALID.clear()
      ## Set the network communication slugs to reflect the correct member
      SET_POSTER.bind()
      ## AUDIT
      logger = LGatekeeper.logger_authenticate_login
      helper = LGatekeeper.helper_authenticate_login
      special = LGatekeeper.special_authenticate_login+str(MEMBER_ACTIVE)+\
       LGatekeeper.termination_string
      VAULT_DEBUG_LOGGER[0].audit(INSTANCE=logger+helper+special)
      VAULT_ACTION_AUDITED[0](variable=logger+helper+special)
      VAULT_DEBUG_GATEKEEPER[0].valid_member_information(
       INFORMATION=VAULT_PATH_INSTANCE[0]+VAULT_PATH_MEMBER_ACTIVE[0])
      with open(VAULT_PATH_MEMBER_ACTIVE[0]+VAULT_MEMBER_ACTIVE_HOLDER[0],
       VAULT_oFo[0].write) as AMEMBER:
       AMEMBER.write(MEMBER_ACTIVE)
      AMEMBER.close()

      self.FRONTEND_ALIEN_VAULT.destroy()

      ## Set the keysetter if the instance was valid. This is then verified
      ## on the frontend, and if it isn't found, the instance is terminated
      VAULT_KEY_BOUND[0].verified = 1

      ## Flush the IPDVC
      IPDVC.flush()

      ## member, granted
      VAULT_DEBUG_STEPS[0].step_13(MODE="STOP")

     except IndexError:
      VAULT_DEBUG_GATEKEEPER[0].failure_key()
      LoginAlertTextIdentity.configure(text=ALIEN_MANIFEST.space)
      LoginAlertTextKey.configure(text=ALIEN_MANIFEST.invalid_key)
      ## Flush the IPDVC
      IPDVC.flush()

    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)
     VAULT_DEBUG_GATEKEEPER[0].failure_member_not_located()

     MEMBER_INPUT.delete(0, END)
     KEY_INPUT.delete(0, END)
     LoginAlertTextKey.configure(text=ALIEN_MANIFEST.space)
     LoginAlertTextIdentity.configure(text=ALIEN_MANIFEST.invalid_member)
     ## Flush the IPDVC
     IPDVC.flush()

  def login_binder():
   self.FRONTEND_ALIEN_VAULT.bind(ALIEN_MANIFEST.returncode,
    Authenticate.login)

  #*******************************************************#
  # SYSTEM ENABLED: START STEP 9: - KEY CHECK             #
  #*******************************************************#
  ## Start Key Check
  VAULT_DEBUG_STEPS[0].step_9(MODE="START")
  try:
   with open(VAULT_PATH_INSTANCE[0]+VAULT_DIRDATA[0]+VAULT_KEY[0],
    VAULT_oFo[0].read) as f:
    f_line = f.readlines()
   f.close()
   VAULT_DEBUG_GATEKEEPER[0].machine_key_set()
  except FileNotFoundError:
   VAULT_DEBUG_GATEKEEPER[0].warning_no_machine_key_set()

  ## End Key Check
  VAULT_DEBUG_STEPS[0].step_9(MODE="STOP")
  #************************************************************#
  # SYSTEM ENABLED: STOP STEP 9: KEY CHECK                     #
  #************************************************************#

  #************************************************************#
  # SYSTEM ENABLED: START STEP 10: Verify CHECK                #
  #************************************************************#
  VAULT_DEBUG_STEPS[0].step_10(MODE="START")
  try:
   with open(VAULT_KEY_LOCATION[0], VAULT_oFo[0].read) as fg:
    fg_line = fg.readlines()
    if f_line == fg_line:
     self.FRONTEND_ALIEN_VAULT.destroy()
     ## Set the keysetter if the instance was valid. This is then verified
     ## on the frontend, and if it isn't found, the instance is terminated
     KEY_BOUND.verified = 1
     VAULT_DEBUG_GATEKEEPER[0].key_match()
    else:
     VAULT_DEBUG_GATEKEEPER[0].failure_key_check_mismatch()
    fg.close()
    login_binder()
  except FileNotFoundError:
   VAULT_DEBUG_GATEKEEPER[0].failure_key_check_could_not_locate()
   try:
    login_binder()
   except _tkinter.TclError:
    VAULT_DEBUG_GATEKEEPER[0].failure_key_check_aborted()

  ## End Verify Match Check
  VAULT_DEBUG_STEPS[0].step_10(MODE="STOP")
  #************************************************************#
  # SYSTEM ENABLED: STOP STEP 10: Verify CHECK                 #
  #************************************************************#
  ## Add member code
  ADD_MEMBER = ttk.Button(ENTITY_ADD_MEMBER,
   text=VAULT_ALIENCREATORTITLE[0], command=Authenticate.add_member)
  ADD_MEMBER.place(x=320, y=400)
  LOGIN = ttk.Button(ENTITY_LOGIN, text=ALIEN_MANIFEST.login,
   command=Authenticate.login)
  LOGIN.place(x=320, y=400)
  ALIEN_VAULT_CONTROLLER.pack(expand=ALIEN_MANIFEST.expand_yes,
   fill=ALIEN_MANIFEST.both)



Return HOME