示例#1
0
def delete_snapshot_div(network_value, host_value):
    if not network_value:
        raise PreventUpdate
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    options = [{
        'label': snapshot,
        'value': snapshot
    } for snapshot in batfish.get_existing_snapshots()]
    children = [
        dbc.Form(
            [
                dcc.Dropdown(id="delete_snapshot_dropdown",
                             placeholder='Delete Snapshot',
                             style={
                                 'margin': '5px',
                                 'width': '150px',
                             },
                             options=options,
                             value=None),
                dbc.Button("Delete",
                           id="delete_snapshot_submit_button",
                           color="dark",
                           outline=True,
                           size="sm",
                           style=dict(
                               margin="5px",
                               height="25px",
                           )),
                html.P(id='delete_snapshot_hidden', style={"display": "none"})
            ],
            inline=True,
        ),
    ]
    return children
示例#2
0
def create_network(network_name, submit, batfish_host):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "create_network_submit_button":
        raise PreventUpdate
    batfish = Batfish(batfish_host)
    batfish.set_network(network_name)
示例#3
0
def delete_network(submit, delete_network, batfish_host):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "delete_network_submit_button":
        raise PreventUpdate
    batfish = Batfish(batfish_host)
    batfish.delete_network(delete_network)
示例#4
0
def set_change_configuration(changed_configuration,
                             changed_configuration_submit,
                             chaos_traceroute_submit, choose_node,
                             batfish_host, batfish_network, batfish_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id not in [
            "change_configuration_submit", "chaos_traceroute_submit"
    ]:
        raise PreventUpdate
    if button_id == "chaos_traceroute_submit":
        return False

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(batfish_snapshot)

    with open(r"assets\snapshot_holder\configs\\" + choose_node + ".txt",
              'w') as f:
        f.write(changed_configuration)

    nodes_df = batfish.get_info('fileParseStatus')
    for key, value in nodes_df.iterrows():
        if choose_node.lower() not in value['Nodes']:
            with open(
                    r"assets\snapshot_holder\configs\\" + value['Nodes'][0] +
                    ".txt", 'w') as f:
                f.write(
                    batfish.get_configuration(value['File_Name'],
                                              batfish_snapshot))
    return True
示例#5
0
def set_batfish_snapshot(host_value, network_value):
    if not network_value:
        raise PreventUpdate
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    options = [{
        'label': snapshot,
        'value': snapshot
    } for snapshot in batfish.get_existing_snapshots()]
    dropdown = dcc.Dropdown(id="select-snapshot-button",
                            placeholder='Select Snapshot',
                            className="main_page_dropdown",
                            options=options,
                            value=None),
    return dropdown
示例#6
0
def get_batfish_networks(n, value):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "set_batfish_host_submit_button":
        raise PreventUpdate
    batfish = Batfish(value)
    options = [{
        'label': network,
        'value': network
    } for network in batfish.get_existing_networks]
    dropdown1 = dcc.Dropdown(id="select-network-button",
                             placeholder='Select a Network',
                             className="main_page_dropdown",
                             options=options,
                             value=None)
    dropdown2 = dcc.Dropdown(id="modal-select-network-button",
                             placeholder='Select a Network',
                             style={
                                 'margin': '5px',
                                 'width': '150px',
                             },
                             options=options,
                             value=None)
    create_delete_network_children = [
        dbc.Form(
            [
                dbc.FormGroup(
                    [
                        dbc.Input(id="create-network-form",
                                  value="",
                                  placeholder="New Network Name"),
                    ],
                    className="mr-3",
                ),
                dbc.Button(
                    "Submit",
                    id="create_network_submit_button",
                    color="dark",
                    outline=True,
                    size="sm",
                ),
                dcc.Dropdown(id="delete_network_dropdown",
                             placeholder='Select a Network',
                             options=options,
                             value=None),
                dbc.Button(
                    "Delete",
                    id="delete_network_submit_button",
                    color="dark",
                    outline=True,
                    size="sm",
                ),
                html.H1(id="delete-success", style={"display": "none"})
            ],
            inline=True,
        )
    ]
    return dropdown2, dropdown1, create_delete_network_children
示例#7
0
def set_update_trace_graph(
    source,
    destination,
    submit,
    bidir,
    src_ports,
    dst_ports,
    applications,
    ip_protocols,
    host_value,
    network_value,
    snapshot_value,
):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "main_page_traceroute_submit":
        raise PreventUpdate
    src_ports = src_ports.split(',') if src_ports else None
    dst_ports = dst_ports.split(',') if dst_ports else None
    applications = applications.split(',') if applications else None
    ip_protocols = ip_protocols.split(',') if ip_protocols else None

    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    result = batfish.traceroute(source, destination, bidir, snapshot_value,
                                src_ports, dst_ports, applications,
                                ip_protocols)
    reverse_flow_graph = []
    reverse_flow_traces = []

    if bidir:
        forward_flow_details = get_traceroute_details('forward', result, True)
        forward_flow_graph = forward_flow_details[0]
        forward_flow_traces = forward_flow_details[1]
        reverse_flow_details = get_traceroute_details('reverse', result, True)
        reverse_flow_graph = reverse_flow_details[0]
        reverse_flow_traces = reverse_flow_details[1]

    else:
        forward_flow_details = get_traceroute_details('forward', result, False)
        forward_flow_graph = forward_flow_details[0]
        forward_flow_traces = forward_flow_details[1]

    return forward_flow_graph, forward_flow_traces, reverse_flow_graph, reverse_flow_traces,
示例#8
0
def display_interfaces_for_node(choose_node, batfish_host, batfish_network,
                                original_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "traceroute_deactivate_node":
        raise PreventUpdate

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(original_snapshot)

    batfish_df = batfish.get_info("nodeProperties")
    batfish_df = batfish_df.set_index('Node')

    interfaces = batfish_df.loc[choose_node].at['Interfaces']

    interfaces_dict = [{'label': '', 'value': ''}]

    interfaces_dict += [{
        'label': interface,
        'value': interface
    } for interface in interfaces]
    options = interfaces_dict
    return options
示例#9
0
def set_dst_type_input(dst_type, host_value, network_value, snapshot_value):
    if not dst_type:
        raise PreventUpdate

    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)

    if dst_type == 'Interface':
        batfish_df = batfish.get_layer3_edges
        options = [str(x) for x in batfish_df["Interface"]]
        interfaces = [{
            'label': interface,
            'value': interface
        } for interface in options]

        children = dcc.Dropdown(
            id="traceroute_dst",
            placeholder='Select Destination',
            options=interfaces,
        )
    else:

        children = dcc.Input(id="traceroute_dst",
                             type="text",
                             placeholder="Input IP Address",
                             className="traceroute_dst_ip_input",
                             style=dict(borderTopLeftRadius="0px",
                                        borderBottomLeftRadius="0px",
                                        height="36px")),

    return children
示例#10
0
def set_chaos_trace_graph(source, destination, submit, choose_node,
                          deactivate_node, deactivated_interface, src_ports,
                          dst_ports, applications, ip_protocols,
                          change_configuration_switch, host_value,
                          network_value, snapshot_value):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]
    deactivated_nodes = []
    deactivated_interfaces = []

    if button_id not in [
            "chaos_traceroute_submit", "change_configuration_submit"
    ]:
        raise PreventUpdate

    src_ports = src_ports.split(',') if src_ports else None
    dst_ports = dst_ports.split(',') if dst_ports else None
    applications = applications.split(',') if applications else None
    ip_protocols = ip_protocols.split(',') if ip_protocols else None
    batfish = Batfish(host_value)
    batfish.set_network(network_value)

    bidir = False
    if change_configuration_switch:
        reference_snapshot = snapshot_value + "_CHANGED"
        batfish.init_snapshot(reference_snapshot)
    else:
        reference_snapshot = snapshot_value + "_FAIL"
        deactivated_nodes.append(choose_node)
        if not deactivate_node:
            deactivated_interfaces.append(deactivated_interface)
        batfish.network_failure(snapshot_value, reference_snapshot,
                                deactivated_nodes, deactivated_interfaces)

    result = batfish.traceroute(source, destination, bidir, reference_snapshot,
                                src_ports, dst_ports, applications,
                                ip_protocols)
    chaos_flow_details = get_traceroute_details('forward', result, False, True)
    chaos_flow_graph = chaos_flow_details[0]
    chaos_flow_traces = chaos_flow_details[1]
    delete_old_files()

    return chaos_flow_graph, chaos_flow_traces
示例#11
0
def get_change_configuration(choose_node, batfish_host, batfish_network,
                             batfish_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "acl_choose_node":
        raise PreventUpdate

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(batfish_snapshot)
    nodes_df = batfish.get_info('fileParseStatus')
    for key, value in nodes_df.iterrows():
        if choose_node.lower() in value['Nodes']:
            return batfish.get_configuration(value['File_Name'],
                                             batfish_snapshot)
示例#12
0
def delete_snapshot(batfish_network, submit, delete_snapshot, batfish_host):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]
    if not submit:
        raise PreventUpdate
    if button_id == "delete_snapshot_submit_button":
        batfish = Batfish(batfish_host)
        batfish.set_network(batfish_network)
        batfish.delete_snapshot(delete_snapshot)
示例#13
0
def get_acl_configuration_modal(n, batfish_host, batfish_network,
                                batfish_snapshot):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "acl_get_config_button":
        raise PreventUpdate

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(batfish_snapshot)
    nodes_df = batfish.get_info('nodeProperties')
    options = [{'label': node, 'value': node} for node in nodes_df['Node']]
    return options
示例#14
0
def set_update_tab_content(content_type, snapshot_value, host_value,
                           network_value):
    if not snapshot_value:
        raise PreventUpdate
    time.sleep(.05)
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)

    tab_content = {
        'layer3': get_layer3_graph(batfish.get_layer3_edges),
        'ospf': get_ospf_graph(batfish.get_ospf_edges),
        'bgp': get_bgp_graph(batfish.get_bgp_edges),
        'traceroute': get_traceroute_content(batfish.get_layer3_edges),
        'all_things_acl': get_acl_content()
    }
    return tab_content.get(content_type)
示例#15
0
def ask_a_question_modal_table(question, host_value, network_value,
                               snapshot_value):
    if question is None:
        raise PreventUpdate
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)
    batfish_df = batfish.get_info(question)
    batfish_df.to_csv('test.csv', index=False)
    new_df = pd.read_csv('test.csv')
    children = dash_table.DataTable(id='table',
                                    columns=[{
                                        "name": i,
                                        "id": i,
                                        "deletable": True
                                    } for i in batfish_df.columns],
                                    data=new_df.to_dict('records'),
                                    filter_action="native",
                                    export_format="csv",
                                    style_cell={
                                        'fontSize': 12,
                                        'font-family': 'sans-serif'
                                    },
                                    style_data_conditional=[{
                                        'if': {
                                            'row_index': 'odd'
                                        },
                                        'backgroundColor':
                                        'rgb(248, 248, 248)'
                                    }],
                                    style_header={
                                        'backgroundColor':
                                        'rgb(230, 230, 230)',
                                        'fontWeight': 'bold'
                                    })
    return children
示例#16
0
def get_chaos_form(n, graph_elements, batfish_host, batfish_network,
                   original_snapshot):

    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "traceroute_chaos_switch":
        raise PreventUpdate

    if not n:
        return None, None

    traceroute_nodes = []
    try:
        for traceroute_node in graph_elements:
            traceroute_nodes.append(traceroute_node['data']['label'])
    except KeyError:
        pass

    batfish = Batfish(batfish_host)
    batfish.set_network(batfish_network)
    batfish.set_snapshot(original_snapshot)

    batfish_df = batfish.get_info("nodeProperties")
    batfish_df = batfish_df.set_index('Node')

    nodes_dict = [{
        'label': node,
        'value': node
    } for node in set(traceroute_nodes)]
    node = nodes_dict[0]['value']
    interfaces = batfish_df.loc[node].at['Interfaces']

    interfaces_dict = [{'label': '', 'value': ''}]

    interfaces_dict += [{
        'label': interface,
        'value': interface
    } for interface in interfaces]

    form_children = [
        dbc.Col(children=[
            html.Fieldset(
                id="traceroute_source_fieldset",
                children=[
                    html.Legend("Choose Node"),
                    dbc.InputGroup([
                        dbc.Select(
                            id="traceroute_choose_node",
                            options=nodes_dict,
                            value=node,
                        ),
                    ]),
                ],
            ),
        ], ),
        dbc.Col(children=[
            html.Fieldset(
                id="traceroute_source_fieldset",
                children=[
                    html.Legend("Deactivate Node?"),
                    daq.BooleanSwitch(
                        id='deactivate_node_switch',
                        on=False,
                    ),
                ],
            ),
        ], ),
        dbc.Col(
            id="traceroute_deactivate_interface_col",
            children=[
                html.Fieldset(
                    id="traceroute_source_fieldset",
                    children=[
                        html.Legend("Deactivate Interface"),
                        dbc.InputGroup([
                            dbc.Select(
                                id="traceroute_deactivate_interface",
                                options=interfaces_dict,
                                value='',
                            ),
                        ]),
                    ],
                ),
            ],
        ),
        dbc.Col(children=[
            html.Div(
                dbc.Button("Change Configuration?",
                           id="chaos_traceroute_change_config_button")),
            daq.BooleanSwitch(id='change_configuration_switch',
                              on=False,
                              style={"display": "none"}),
        ]),
        dbc.Col(html.Div(dbc.Button("Chaos!",
                                    id="chaos_traceroute_submit")), ),
    ]

    fieldset_children = [
        html.Legend("Chaos Trace Route"),
        html.Div(id="chaos_traceroute_graph"),
        html.Div(dcc.Tabs(id="chaos_traceroute_tabs")),
    ]

    return form_children, fieldset_children
示例#17
0
def acl_table(original_platform, original_acl, refractored_platform,
              refractored_acl, submit, host_value, network_value,
              snapshot_value):
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if button_id != "acl_analyze_button":
        raise PreventUpdate
    batfish = Batfish(host_value)
    batfish.set_network(network_value)
    batfish.set_snapshot(snapshot_value)
    compare_acl_df = batfish.compare_acls(original_acl, refractored_acl,
                                          original_platform,
                                          refractored_platform)
    batfish.delete_snapshot("refractored")
    batfish.delete_snapshot("original")
    children = dash_table.DataTable(id='table',
                                    columns=[{
                                        "name": i,
                                        "id": i,
                                        "deletable": True
                                    } for i in compare_acl_df.columns],
                                    data=compare_acl_df.to_dict('records'),
                                    filter_action="native",
                                    style_cell={
                                        'fontSize': 12,
                                        'font-family': 'sans-serif'
                                    },
                                    style_data_conditional=[{
                                        'if': {
                                            'row_index': 'odd'
                                        },
                                        'backgroundColor':
                                        'rgb(248, 248, 248)'
                                    }],
                                    style_header={
                                        'backgroundColor':
                                        'rgb(230, 230, 230)',
                                        'fontWeight': 'bold'
                                    })
    return children
示例#18
0
def create_snapshot_modal(
        device_configs_upload_content, host_configs_upload_content,
        iptables_configs_upload_content, aws_configs_upload_content,
        misc_configs_upload_content, batfish_network, submit, snapshot_name,
        device_config_filenames, host_config_filenames,
        iptables_config_filenames, aws_config_filenames, misc_config_filenames,
        batfish_host):
    device_html_list = None
    host_html_list = None
    iptable_html_list = None
    aws_html_list = None
    misc_html_list = None

    if device_config_filenames is not None:
        device_html_list = html.Ul(
            [html.Li(x) for x in device_config_filenames])
    if host_config_filenames is not None:
        host_html_list = html.Ul([html.Li(x) for x in host_config_filenames])
    if iptables_config_filenames is not None:
        iptable_html_list = html.Ul(
            [html.Li(x) for x in iptables_config_filenames])
    if aws_config_filenames is not None:
        aws_html_list = html.Ul([html.Li(x) for x in aws_config_filenames])
    if misc_config_filenames is not None:
        misc_html_list = html.Ul([html.Li(x) for x in misc_config_filenames])

    all_children = html.Div([
        html.Ul(children=[
            html.Li(['Device Configs', device_html_list]),
            html.Li(['Host Configs', host_html_list]),
            html.Li(['IP Table Configs', iptable_html_list]),
            html.Li(['AWS Configs', aws_html_list]),
            html.Li(['Misc Configs', misc_html_list]),
        ], )
    ])
    ctx = dash.callback_context
    button_id = ctx.triggered[0]['prop_id'].split('.')[0]

    if not batfish_network:
        raise PreventUpdate

    if button_id == "create_snapshot_submit_button":
        if snapshot_name == "":
            return all_children, True
        if device_config_filenames is not None:
            for name, data in zip(device_config_filenames,
                                  device_configs_upload_content):
                save_file("device_config", name, data)
        if host_config_filenames is not None:
            for name, data in zip(host_config_filenames,
                                  host_configs_upload_content):
                save_file("host_config", name, data)
        if iptables_config_filenames is not None:
            for name, data in zip(iptables_config_filenames,
                                  iptables_configs_upload_content):
                save_file("iptable_config", name, data)
        if aws_config_filenames is not None:
            for name, data in zip(aws_config_filenames,
                                  aws_configs_upload_content):
                save_file("aws_config", name, data)
        if misc_config_filenames is not None:
            for name, data in zip(misc_config_filenames,
                                  misc_configs_upload_content):
                save_file("misc_config", name, data)
        batfish = Batfish(batfish_host)
        batfish.set_network(batfish_network)
        batfish.init_snapshot(snapshot_name)
        delete_old_files()
        device_html_list = None
        host_html_list = None
        iptable_html_list = None
        aws_html_list = None
        misc_html_list = None

        all_children = html.Div([
            html.Ul(children=[
                html.Li(['Device Configs', device_html_list]),
                html.Li(['Host Configs', host_html_list]),
                html.Li(['IP Table Configs', iptable_html_list]),
                html.Li(['AWS Configs', aws_html_list]),
                html.Li(['Misc Configs', misc_html_list]),
            ], )
        ])
        return all_children, False
    return all_children, False