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 = []

    # This combines the lists for jinja
    for element in links:
        passable.append(element)

    if is_logged_on:
        links = passable[0] + passable[1]
    else:
        links = passable[0]

    # This will prep the css link for jinja and flask
    for css_file in css:
        stylesheets.append(statics_dir + '/' + css_file)

        # This will either print out what is being sent to flask or send it to flask
        if debug:
            pass
            # print(statics_dir, css_file)
            # print(stylesheets)
        else:
            url_for(statics_dir, filename=css_file)
    if not debug:
        return render_template(template,
                               title=title,
                               css=stylesheets,
                               pages=links,
                               user=user,
                               hosts=hosts)
示例#2
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)
示例#3
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
示例#4
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:
示例#5
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'])