Ejemplo n.º 1
0
def pull_cfgs(args):

	redirect = []
	auditcreeper = False
	commands = initialize.configuration
	argument_node = args.node 
	output = False
	argument_node = args.node
	remediation = False
	with_remediation = False 
	
	### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES
	node_object = process_nodes()

	### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER
	match_node = search_node(argument_node,node_object)

	if(len(match_node) == 0):
		print("[+] [NO MATCHING NODES AGAINST DATABASE]")
		print("")

	else:
		node_element(match_node,node_object)
		node_create(match_node,node_object)	
		for index in initialize.element:
			redirect.append('pull_cfgs')

		confirm(redirect,commands)
		print("")
Ejemplo n.º 2
0
def push_local(args):

    controller = 'push_cfgs'
    commands = initialize.configuration
    argument_node = args.node
    filename = args.filename

    ### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES
    node_object = process_nodes()

    ### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER
    match_node = search_node(argument_node, node_object)

    if (len(match_node) == 0):
        print("+ [NO MATCHING NODES AGAINST DATABASE]")
        print("")

    else:
        node_element(match_node, node_object)
        node_create(match_node, node_object)
        home_directory = os.path.expanduser('~')

        for index in initialize.element:

            config_list = []

            f = open("{}/{}".format(home_directory, filename), "r")

            init_config = f.readlines()
            parse_commands(init_config)

        confirm_push(controller, commands)
Ejemplo n.º 3
0
def pull_cfgs(args):
    argument_confirm = args.confirm
    argument_node = args.node
    commands = initialize.configuration
    output = False
    redirect = []
    authentication = True
    """
		:param argument_configm: Argument accepted as boolean
		:type augument_confirm: bool

		:param argument_node: Argument accepted as regular expression.
		:type augument_node: str
		
		:param commands: Referenced to global variable commands which keeps track of all commands per node.
		:type commands: list

		:param output: Flag to output to stdout.  
		:type ext: bool 
		
		:param redirect: A list of which method superloop will access. This variable is sent to the multithread_engine. Each element is a redirect per node.
		:type alt_key_file: list
	"""
    try:
        if argument_confirm is None or argument_confirm.lower() == 'true':
            confirm_flag = True
        elif argument_confirm.lower() == 'false':
            confirm_flag = False
        else:
            raise argparse.ArgumentTypeError('Boolean value expected.')
        node_object = process_nodes()
        match_node = search_node(argument_node, node_object)
        """
			:param node_object: All node(s) in the database with all attributes.
			:type node_object: list
	
			:param match_node: Nodes that matches the arguements passed in by user.
			:type match_node: list
		"""
        if len(match_node) == 0:
            print('+ No matching node(s) found in database.')
            print('')
        else:
            node_element(match_node, node_object)
            node_create(match_node, node_object)
            for index in initialize.element:
                redirect.append('pull_cfgs')
            if (confirm_flag):
                confirm(redirect, commands, authentication)
            else:
                multithread_engine(initialize.ntw_device, redirect, commands,
                                   authentication)
            print('')
    except Exception as error:
        print('ExceptionError: an exception occured')
        print(error)

    return None
Ejemplo n.º 4
0
def ssh_connect(args):

    auditcreeper = False
    commands = initialize.configuration
    argument_node = args.hostname
    username = os.environ.get('USERNAME')

    ### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES
    node_object = process_nodes()

    ### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER
    match_node = search_node(argument_node, node_object)

    if (len(match_node) == 0):
        print("[+] [NO MATCHING NODES AGAINST DATABASE]")
        print("")

    else:
        node_element(match_node, node_object)
        id = 1
        ssh_id = 0

        print("ID\tname\t\t\taddress\t\tplatform")

        for index in initialize.element:

            print("{}\t{}\t{}\t{}".format(id, node_object[index]['hostname'],
                                          node_object[index]['ip'],
                                          node_object[index]['platform']))
            id = id + 1

        port = get_port(node_object, initialize.element, ssh_id)

        if (len(initialize.element) == 1):
            subprocess.call("ssh {}@{} -p {}".format(
                username, node_object[initialize.element[ssh_id]]['ip'], port),
                            shell=True)

        else:
            ssh_id = int(input("Enter ID to SSH to: "))

            ### NODE_ID WILL MAP TO THE CORRECT NODE_OBJECT HOST TO CONNECT TO.
            ssh_id = ssh_id - 1

            port = get_port(node_object, initialize.element, ssh_id)
            subprocess.call("ssh {}@{} -p {}".format(
                username, node_object[initialize.element[ssh_id]]['ip'], port),
                            shell=True)
Ejemplo n.º 5
0
def push_local(args):
    argument_filename = args.filename
    argument_node = args.node
    commands = initialize.configuration
    redirect = []
    authentication = True
    """
		:param argument_filename: Argument accepted as template name.
		:type augument_filename: str
		
		:param argument_node: Argument accepted as regular expression.
		:type augument_node: str
		
		:param commands: Referenced to global variable commands which keeps track of all commands per node.
		:type commands: list

		:param redirect: A list of which method superloop will access. This variable is sent to the multithread_engine. Each element is a redirect per node.
		:type alt_key_file: list
	"""
    node_object = process_nodes()
    match_node = search_node(argument_node, node_object)
    """
		:param node_object: All node(s) in the database with all attributes.
		:type node_object: list

		:param match_node: Nodes that matches the arguements passed in by user.
		:type match_node: list
	"""
    if len(match_node) == 0:
        print('+ No matching node(s) found in database.')
        print('')
    else:
        node_element(match_node, node_object)
        node_create(match_node, node_object)
        for index in initialize.element:
            redirect.append('push_cfgs')
        for index in initialize.element:
            config_list = []
            with open('{}/{}'.format(get_home_directory(), argument_filename),
                      'r') as file:
                init_config = file.readlines()
            parse_commands(node_object[index], init_config, set_notation=True)
        confirm(redirect, commands, authentication)

    return None
Ejemplo n.º 6
0
def exec_cmd(args):
	argument_command = args.command
	argument_node = args.node
	redirect = []
	authentication = True
	"""
		:param argument_command: Referenced to global variable commands which keeps track of all commands per node.
		:type commands: list
		
		:param argument_node: Argument accepted as regular expression.
		:type augument_node: str
		
		:param redirect: A list of which method superloop will access. This variable is sent to the multithread_engine. Each element is a redirect per node.
		:type alt_key_file: list
	"""
	redirect.append('exec_cmd') 
	try:
		if argument_command == 'reload' or argument_command == 'reboot':
			print("superloopError: command not supported")
			return False
		else:
			node_object = process_nodes()
			match_node = search_node(argument_node,node_object)
			"""
				:param node_object: All node(s) in the database with all attributes.
				:type node_object: list
		
				:param match_node: Nodes that matches the arguements passed in by user.
				:type match_node: list
			"""
			if len(match_node) == 0:
				print('+ No matching node(s) found in database.')
				print()
			else:
				node_element(match_node,node_object)
				node_create(match_node,node_object)
				multithread_engine(initialize.ntw_device,redirect,argument_command,authentication)
	except Exception as error:
		print("ExceptionError: an exception occured")
		print(error)

	return None
Ejemplo n.º 7
0
def exec_command(args):

    controller = 'exec_command'
    command = args.argument
    argument_node = args.node

    ### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES
    node_object = process_nodes()

    ### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER
    match_node = search_node(argument_node, node_object)

    if (len(match_node) == 0):
        print("+ [NO MATCHING NODES AGAINST DATABASE]")
        print("")

    else:
        node_element(match_node, node_object)
        node_create(match_node, node_object)
        multithread_engine(initialize.ntw_device, controller, command)
Ejemplo n.º 8
0
def ssh_connect(args):
    argument_node = args.name
    auditcreeper = False
    commands = initialize.configuration
    username = os.environ.get('USERNAME')
    """
		:param argument_node: Argument accepted as regular expression.
		:type augument_node: str
		
		:param auditcreeper: When auditcreeper is active/non-active.
		:type auditcreeper: bool
		
		:param commands: Referenced to global variable commands which keeps track of all commands per node.
		:type commands: list
		
		:param username: Pulled from environment variable.  
		:type ext: str
	"""
    node_object = process_nodes()
    match_node = search_node(argument_node, node_object)
    """
		:param node_object: All node(s) in the database with all attributes.
		:type node_object: list

		:param match_node: Nodes that matches the arguements passed in by user.
		:type match_node: list
	"""
    try:
        if len(match_node) == 0:
            print('+ No matching nodes found in database.')
            print('')
        else:
            node_element(match_node, node_object)
            id = 1
            ssh_id = 0
            print('{} {: >27} {: >28} {: >26}'.format('id', 'name', 'address',
                                                      'platform'))
            for index in initialize.element:
                print(
                    '{id: {align}{space}} {name: {align}{space}} {mgmt_ip4: {align}{space}} {platform_name: {align}{space}}'
                    .format(
                        id=id,
                        name=node_object[index]['name'],
                        mgmt_ip4=node_object[index]['mgmt_ip4'],
                        platform_name=node_object[index]['hardware_vendor'],
                        align='<',
                        space=25))
                id = id + 1
            port = get_port(node_object, initialize.element, ssh_id)
            try:
                if (len(initialize.element) == 1):
                    subprocess.call('ssh {}@{} -p {}'.format(
                        username,
                        node_object[initialize.element[ssh_id]]['mgmt_ip4'],
                        port),
                                    shell=True)
                else:
                    try:
                        ssh_id = int(input('Enter ID to SSH to: '))
                        ssh_id = ssh_id - 1
                        if ssh_id + 1 < 1:
                            print('IndexError: incorrect connection id')
                    except KeyboardInterrupt as error:
                        print('')
                        print('Terminating...')
                    else:
                        port = get_port(node_object, initialize.element,
                                        ssh_id)
                        subprocess.call('ssh {}@{} -p {}'.format(
                            username, node_object[initialize.element[ssh_id]]
                            ['mgmt_ip4'], port),
                                        shell=True)
            except IndexError:
                print('IndexError: incorrect connection id')
    except ValueError as error:
        print('ValueError: expected an integer')