示例#1
0
def login():
    """Device authentication use Ncclient"""

    #Store variable globally for use later
    global success_login_form, username, password, netconf_port, device, netconf_session

    if request.form:
        # Set variable from form data. Set defaults if not entered in the login form
        if not request.form['netconfPort']:
            netconf_port = 830
        else:
            netconf_port = request.form['netconfPort']

        username = request.form['username']
        password = request.form['password']
        device = request.form['ipAddress']

        # Create NETCONF and netmiko session objects
        netconf_session = ConnectWith.create_netconf_connection(
            request.form['username'], request.form['password'],
            request.form['ipAddress'], netconf_port)

        if netconf_session == 'error':
            return render_template('device_login.html', status="Login Failed")
        else:
            #Used to ensure user is authenticated prior to accessing any pages. If not 1 user is redirected to login page
            success_login_form = 1
            return redirect(url_for('base_blueprint.index'))
    else:
        return render_template('device_login.html', status=None)
示例#2
0
def get_qos():
    """View Qos statistics"""

    global service_policies, qos, netconf_session

    netconf_session = ConnectWith.create_netconf_connection(username, password, device)
    qos = GetQos.get_interfaces(netconf_session)
    service_policies = GetPolicies.fetch_service_policy(netconf_session)

    return render_template('qos.html', interfaces=get_interfaces[0], interface_qos=qos)
示例#3
0
def login():
    global device, username, password, netconf_session, netmiko_session, model, netconf_port, ssh_port

    login_form = LoginForm(request.form)
    if 'login' in request.form:

        device = request.form['device']
        username = request.form['username']
        password = request.form['password']
        netconf_port = request.form['netconf']
        ssh_port = request.form['ssh']

        if not netconf_port:
            netconf_port = 830
        if not ssh_port:
            ssh_port = 22

        if device and username and password:

            # Attempt to create connection objects. Must have both to get to homepage
            netconf_session = ConnectWith.create_netconf_connection(
                request.form['username'], request.form['password'],
                request.form['device'], netconf_port)
            netmiko_session = ConnectWith.creat_netmiko_connection(
                request.form['username'], request.form['password'],
                request.form['device'], ssh_port)

            model = GetInfo.get_device_model(netmiko_session)

            # Using netmiko and ncclient for connections, verify that both pass. If one fails, return to login
            if netmiko_session == 'Authenitcation Error':
                flash("Authentication Failure")
                return redirect(url_for('base_blueprint.login'))
            elif netmiko_session == 'ssh_exception' or netmiko_session == 'Connection Timeout':
                flash("Check Device Connectivity")
                return redirect(url_for('base_blueprint.login'))

            if netconf_session == 'Authentication Error':
                flash("Authentication Failure")
                return redirect(url_for('base_blueprint.login'))
            elif netconf_session == 'Connection Timeout' or netconf_session == 'Connectivity Issue':
                flash("Check Device Connectivity")
                return redirect(url_for('base_blueprint.login'))
            else:
                return redirect(url_for('base_blueprint.get_routing'))

        return render_template('accounts/login.html',
                               msg='Wrong user or password',
                               form=login_form)

    if not current_user.is_authenticated:
        return render_template('accounts/login.html', form=login_form)
    return redirect(url_for('home_blueprint.index'))
示例#4
0
def add_devices():
    login_form = LoginForm(request.form)
    if 'login' in request.form:

        netconf_port = request.form['netconf']
        ssh_port = request.form['ssh']

        if not netconf_port:
            netconf_port = 830
        if not ssh_port:
            ssh_port = 22

        # Attempt to create connection objects. Must have both to get to homepage
        netconf_session = ConnectWith.create_netconf_connection(
            request.form['username'], request.form['password'],
            request.form['device'], netconf_port)
        netmiko_session = ConnectWith.creat_netmiko_connection(
            request.form['username'], request.form['password'],
            request.form['device'], ssh_port)

        # Using netmiko and ncclient for connections, verify that both pass. If one fails, return to login
        if netmiko_session == 'Authenitcation Error':
            flash("Authentication Failure")
            return redirect(url_for('base_blueprint.add_devices'))
        elif netmiko_session == 'ssh_exception' or netmiko_session == 'Connection Timeout':
            flash("Check Device Connectivity")
            return redirect(url_for('base_blueprint.add_devices'))

        if netconf_session == 'Authentication Error':
            flash("Authentication Failure")
            return redirect(url_for('base_blueprint.add_devices'))
        elif netconf_session == 'Connection Timeout' or netconf_session == 'Connectivity Issue':
            flash("Check Device Connectivity")
            return redirect(url_for('base_blueprint.add_devices'))
        else:
            serial_model = GetFacts.get_serial_model(netmiko_session)
            uptime_software = GetFacts.get_serial_model(netmiko_session)
            DbOps.update_device_facts(request.form['device'], serial_model[0],
                                      serial_model[1], uptime_software[0],
                                      uptime_software[1],
                                      request.form['username'],
                                      request.form['password'], ssh_port,
                                      netconf_port)

            return redirect(url_for('base_blueprint.route_default'))

    else:
        return render_template('accounts/new_inventory_login.html',
                               form=login_form)
示例#5
0
def get_routing():
    """Gets all things routing, arp, interfaces, routing protocols"""

    global get_interfaces, local_as, netconf_session, management_int, unassigned_ints, interface_nums

    netconf_session = ConnectWith.create_netconf_connection(username, password, device)
    get_interfaces = GetInterfacesInfo.get_ip_interfaces(netconf_session, device)
    management_int = get_interfaces[1]
    unassigned_ints = get_interfaces[2]
    interface_nums = get_interfaces[3]
    bgp_status = GetInfo.get_bgp_status(netmiko_session)
    local_as = bgp_status[1][0]
    ospf_status = GetInfo.get_ospf_status(netmiko_session)
    arp_table = GetInfo.get_arp(netmiko_session)

    return render_template('routing.html', interfaces=get_interfaces[0],
                           bgp=bgp_status[0], ospf=ospf_status, arp=arp_table, intial='yes')
示例#6
0
def start_polling(username, password, host, device_type, port, ssh_port):

    global device, session, netconf_port

    username = username
    password = password
    device = host
    netconf_port = port

    session = ConnectWith.create_netconf_connection(username, password, device,
                                                    netconf_port)

    # Check for device type. Insures polling only happens with compatable technologies
    if device_type[:3][-2:] != 'SR':
        get_trunk_ports(ssh_port, username, password, device)

    get_port_channels()
    get_ip_interfaces()
    get_prefix_lists()
示例#7
0
def indivisual_poll(user, pwd, host, port, polling, ssh_port=None):

    global device, session, netconf_port

    username = user
    password = pwd
    device = host
    netconf_port = port

    session = ConnectWith.create_netconf_connection(username, password, device,
                                                    netconf_port)

    if session == 'error':
        pass
    elif polling == 'access':
        get_access_ports()
    elif polling == 'portchannel':
        get_port_channels()
    elif polling == 'trunks':
        get_trunk_ports(ssh_port, username, password, device)
    elif polling == 'interfaces':
        get_ip_interfaces()