Exemple #1
0
def register_host(mac):
    default_settings = common_tools.yaml_to_dict(
        common_tools.correct_path(settings['default_settings']))
    default_settings['mac'] = mac
    filename = common_tools.correct_path(settings['hosts'] + '/' +
                                         mac.replace(':', '') + '.yaml')
    common_tools.dict_to_yaml(filename, default_settings)
    return (filename, default_settings)
Exemple #2
0
def remove_host(mac):
    # This will set the host as a variable
    file_to_be_deleted = common_tools.correct_path(settings['hosts'] + '/' +
                                                   mac.replace(':', '') +
                                                   '.yaml')
    # This will delete the host
    os.remove(file_to_be_deleted)
    # This will return that it is deleted
    return file_to_be_deleted + ' has been removed.'
Exemple #3
0
def update_host(mac, value, key):
    if value == 'mac':
        if is_valid_mac(value) is False:
            return False
    # This will define the host as its dictionary
    host = get_info('host', mac=mac)
    # This will change the desired value
    host[key] = value
    # This will set the save path
    host_path = settings['hosts'] + '/' + host['mac'].replace(':',
                                                              '') + '.yaml'
    # This will make sure it is set correctly so it works in windows
    host_path = common_tools.correct_path(host_path)
    # This will write the dictionary to its yaml file
    common_tools.dict_to_yaml(host_path, host)
    # This will return the host as a dictionary
    return host
Exemple #4
0
def get_info(desired_info, mac=None):
    # This defines the list of all the hosts path
    hosts = os.listdir(settings['hosts'])
    # This defines the list of all the hosts
    for host_in_list in range(len(hosts)):
        hosts[host_in_list] = common_tools.correct_path(settings['hosts'] +
                                                        '/' +
                                                        hosts[host_in_list])
    # This will set the data as a list
    information = []
    # This goes through all the data
    for host in hosts:
        # This checks if the data desired is the host list
        if desired_info == 'host':
            # This fills the information list with all the host information
            information.append(common_tools.yaml_to_dict(host))
        else:
            try:
                information.append(
                    common_tools.yaml_to_dict(host)[desired_info])
            except KeyError:
                raise KeyError(
                    'Expected: host, mac, description, or ipxe-script as a ' +
                    str(type('string')) + '. Did not except ' + desired_info +
                    ' as a ' + str(type(desired_info)))
        # This checks to see if the mac variable has been changed
        if mac is not None:
            # This will just return the list that is requested
            for desired_mac in get_info('host'):
                if mac == desired_mac['mac']:
                    if desired_info == 'host':
                        return desired_mac
                    else:
                        return desired_mac[desired_info]
        # This will raise an error if the desired_info was set wrong and hopefully explain the correct info
    return information
Exemple #5
0
import common_tools
import os

settings = common_tools.yaml_to_dict(
    common_tools.correct_path('settings/host_management.yaml'))

# testing mac address is FF:FF:FF:FF:FF:FF


# This will validate the mac address
# Mac addresses are hex based
# Mac addresses are 18 characters
# Example of a valid mac is the following 12:34:56:78:9A:BC
def is_valid_mac(mac):
    # This is how I determine if it is correct to validate or not quickly
    valid = False
    # This checks if it is the default mac and will just return that as True
    if mac == settings['default_fake_mac']:
        return True
    # This is every single hex number
    all_hex_numbers = [
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'
    ]
    # 17 is the length of a mac address with the separators
    if len(mac) == 17:
        # This is for keeping track of how many times a hex character has been found.
        correct = 0
        # This will go through every single mac address character. Ignoring the seperator
        for character in mac.replace(':', ''):
            # This will go through ever single hex character
            for hex_number in all_hex_numbers:
from flask import url_for, render_template
import common_tools

settings = common_tools.correct_path('settings/html_renderer.yaml')


def get_html(debug=False,
             template='layout.html',
             title='Title',
             statics_dir='static',
             css=['style.css'],
             is_logged_on=False,
             user=None,
             hosts=None):
    user = str(user)
    if user[0] != '<':
        is_logged_on = True
    stylesheets = []
    links = []
    web_links = [common_tools.yaml_to_dict(settings)['links_path']]

    # This check if the user is signed in so it can add more links
    if is_logged_on:
        web_links.append(
            common_tools.yaml_to_dict(settings)['logged_on_links_path'])

    # This will prep the list being handed to jinja
    for dict in web_links:
        links.append(get_links(common_tools.yaml_to_dict(dict)))
    passable = []
Exemple #7
0
import web
import common_tools
import secrets

secret = secrets.token_urlsafe(16)
web.app.secret_key = secret

settings = common_tools.correct_path('settings/manager.yaml')

if common_tools.yaml_to_dict(settings)['debug']:
    port = common_tools.yaml_to_dict(settings)['debug_port']
    IP = common_tools.yaml_to_dict(settings)['debug_IP']
else:
    port = common_tools.yaml_to_dict(settings)['http_port']
    IP = common_tools.yaml_to_dict(settings)['IP']

if '__main__' == __name__:
    web.host = IP
    web.debug = common_tools.yaml_to_dict(settings)['debug']
    web.app.run(port=port,
                host=IP,
                debug=common_tools.yaml_to_dict(settings)['debug'])