Example #1
0
def set_dns_servers(dns_server_info):
    field = {1: 'primary', 2: 'secondary'}

    with ConfigurationManager('dns_server') as dnx:
        dns_server_settings = dnx.load_configuration()

        public_resolvers = dns_server_settings['dns_server']['resolvers']

        for i, (server_name, ip_address) in enumerate(dns_server_info.items(), 1):
            if (not server_name and ip_address):
                continue

            public_resolvers[field[i]].update({
                'name': server_name,
                'ip_address': ip_address
            })

        dnx.write_configuration(dns_server_settings)

    wan_information = load_configuration('config')['settings']
    interface = wan_information['interfaces']
    wan_dhcp = interface['wan']['dhcp']
    wan_int = interface['wan']['ident']
    if (not wan_dhcp):
        wan_ip = interface.get_ip_address(wan_int)

        wan_dfg = Interface.default_gateway(wan_int)
        cidr = System.standard_to_cidr(wan_netmask)

        # TODO: convert this to new module
        wan_netmask = Interface.netmask(wan_int)

        set_wan_interface({
            'ip_address': wan_ip, 'cidr': cidr, 'default_gateway': wan_dfg
        })
def load_page():
    interface_settings = load_configuration('config')['settings']

    wan_int = interface_settings['interfaces']['wan']
    default_wan_mac = wan_int['default_mac']
    configured_wan_mac = wan_int['configured_mac']
    dhcp = wan_int['dhcp']
    wan_int = wan_int['ident']

    # TODO: migrate away from instace
    Int = Interface()
    wan_ip = Int.ip_address(wan_int)
    wan_netmask = Int.netmask(wan_int)
    wan_dfg = Int.default_gateway(wan_int)

    current_wan_mac = default_wan_mac if not configured_wan_mac else configured_wan_mac

    interface_settings = {
        'mac': {
            'default': default_wan_mac,
            'current': current_wan_mac
        },
        'ip': {
            'dhcp': dhcp,
            'ip_address': wan_ip,
            'netmask': wan_netmask,
            'default_gateway': wan_dfg
        }
    }

    return interface_settings
Example #3
0
def set_dns_servers(dns_server_info):
    with ConfigurationManager('dns_server') as dnx:
        dns_server_settings = dnx.load_configuration()

        dns = dns_server_settings['dns_server']['resolvers']
        for i, (server_name, ip_address) in enumerate(dns_server_info.items(),
                                                      1):
            if (server_name and ip_address):
                server = dns[f'server{i}']
                server.update({'name': server_name, 'ip_address': ip_address})

        dnx.write_configuration(dns_server_settings)

    wan_information = load_configuration('config')
    interface = wan_information['settings']['interface']
    wan_dhcp = interface['wan']['dhcp']
    wan_int = interface['outside']
    if (not wan_dhcp):
        wan_ip = interface.get_ip_address(wan_int)
        wan_netmask = Interface.netmask(wan_int)
        wan_dfg = Interface.default_gateway(wan_int)

        cidr = System.standard_to_cidr(wan_netmask)

        wan_settings = {
            'ip_address': wan_ip,
            'cidr': cidr,
            'default_gateway': wan_dfg
        }
        set_wan_interface(wan_settings)