コード例 #1
0
def modalSpecificInterfaceOnHost(x, y):
    """Show specific interface details from device.

    x = device id
    y = interface name
    """
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)

    activeSession = retrieveSSHSession(host)

    # Removes dashes from interface in URL, replacing '_' with '/'
    interface = interfaceReplaceSlash(y)
    # Replace's '_' with '.'
    host.interface = interface.replace('=', '.')

    intConfig, intMac, intStats = host.pull_interface_info(activeSession)
    macToIP = ''
    writeToLog('viewed interface %s on host %s' % (interface, host.hostname))
    return render_template("/viewspecificinterfaceonhost.html",
                           host=host,
                           interface=interface,
                           intConfig=intConfig,
                           intMac=intMac,
                           macToIP=macToIP,
                           intStats=intStats)
コード例 #2
0
def modalEditInterfaceOnHost(x, y):
    """Display modal to edit specific interface on device.

    x = device id
    y = interface name
    """
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)

    activeSession = retrieveSSHSession(host)

    # Removes dashes from interface in URL
    interface = interfaceReplaceSlash(y)

    intConfig = phi.pullInterfaceConfigSession(activeSession, interface, host)
    # Edit form
    form = EditInterfaceForm(request.values, host=host, interface=interface)

    if form.validate_on_submit():
        flash('Interface to edit - "%s"' % (interface))
        return redirect('/confirm/confirmintedit')

    return render_template("/editinterface.html",
                           hostid=host.id,
                           interface=interface,
                           intConfig=intConfig,
                           form=form)
コード例 #3
0
def confirmHostDelete(x):
    """Confirm deleting device interface from local database.

    x = device ID
    """
    host = db_modifyDatabase.getHostByID(x)
    return render_template("confirm/confirmhostdelete.html", host=host)
コード例 #4
0
def resultsMultiIntEdit(x, y):
    """Display results from editing multiple device interfaces.  WIP.

    x = device id
    y = interfaces separated by '&' in front of each interface name
    """
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)

    result = []
    # Split by interfaces, separated by '&'
    for a in y.split('&'):
        if a:
            # Removes dashes from interface in URL
            a = interfaceReplaceSlash(a)

    result.append(host.save_config_on_device(activeSession))

    writeToLog('edited multiple interfaces on host %s' % (host.hostname))
    return render_template("results/resultsmultipleintedit.html",
                           host=host,
                           interfaces=y,
                           result=result)
コード例 #5
0
ファイル: views.py プロジェクト: slaffcheff/netconfig
def modalSpecificInterfaceOnHost(x, y):
    initialChecks()
    # x = device id, y = interface name
    host = db_modifyDatabase.getHostByID(x)
    # Removes dashes from interface in URL, replacing '_' with '/'
    interface = interfaceReplaceSlash(y)
    # Replace's '_' with '.'
    interface = interface.replace('=', '.')

    activeSession = retrieveSSHSession(host)

    if host.ios_type == 'cisco_ios':
        intConfig, intMac = phi.pullInterfaceInfo(activeSession, interface,
                                                  host)
        intStats = phi.pullInterfaceStats(activeSession, interface, host)
        macToIP = ''
    elif host.ios_type == 'cisco_nxos':
        intConfig, intMac = phi.pullInterfaceInfo(activeSession, interface,
                                                  host)
        intStats = phi.pullInterfaceStats(activeSession, interface, host)
        macToIP = ''
    else:
        intConfig = phi.pullInterfaceConfigSession(activeSession, interface,
                                                   host)
        intMac = ''
        macToIP = ''
        intStats = ''
    writeToLog('viewed interface %s on host %s' % (interface, host.hostname))
    return render_template("/viewspecificinterfaceonhost.html",
                           host=host,
                           interface=interface,
                           intConfig=intConfig,
                           intMac=intMac,
                           macToIP=macToIP,
                           intStats=intStats)
コード例 #6
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def resultsMultiIntEdit(x, y):
    initialChecks()
    # x = device id, y = interfaces separated by '&' in front of each interface name
    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)

    result = []
    # Split by interfaces, separated by '&'
    for a in y.split('&'):
        if a:
            # Removes dashes from interface in URL
            a = interfaceReplaceSlash(a)
            #result.append(ci.editInterface(activeSession, a, datavlan, voicevlan, other, host))

    result.append(host.save_config_on_device(activeSession))

    writeToLog('edited multiple interfaces on host %s' % (host.hostname))
    return render_template("results/resultsmultipleintedit.html",
                           host=host,
                           interfaces=y,
                           result=result)


#####################################
# End Multiple Interface Selections #
#####################################
コード例 #7
0
def resultsIntEdit(x, y, datavlan, voicevlan, other):
    """Display results for editing specific interface config settings.

    x = device id
    y = interface name
    d = data vlan
    v = voice vlan
    o = other
    """
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)

    activeSession = retrieveSSHSession(host)

    # Remove dashes from interface in URL and edit interface config
    result = host.run_edit_interface_cmd(interfaceReplaceSlash(y), datavlan,
                                         voicevlan, other, activeSession)

    writeToLog('edited interface %s on host %s' % (y, host.hostname))
    return render_template("results/resultsinterfaceedit.html",
                           host=host,
                           interface=y,
                           datavlan=datavlan,
                           voicevlan=voicevlan,
                           other=other,
                           result=result)
コード例 #8
0
ファイル: views.py プロジェクト: slaffcheff/netconfig
def resultsFWACLGenerator():
    try:
        host = db_modifyDatabase.getHostByID(session['HOSTID'])
    except:
        return redirect('/fwaclgenerator')

    changeTicket = session['CHANGETICKET']
    changeDesc = session['CHANGEDESC']
    sourceIP = session['SOURCEIP']
    destIP = session['DESTIP']
    ports = session['PORTS']

    resultStatus, configList, backoutList, allAccessAllowed = fop.main(
        host, changeTicket, changeDesc, sourceIP, destIP, ports)

    session.pop('HOSTNAME', None)
    session.pop('HOSTID', None)
    session.pop('CHANGETICKET', None)
    session.pop('CHANGEDESC', None)
    session.pop('SOURCEIP', None)
    session.pop('DESTIP', None)
    session.pop('PORTS', None)

    return render_template("results/resultsfwaclgenerator.html",
                           resultStatus=resultStatus,
                           configList=configList,
                           backoutList=backoutList,
                           allAccessAllowed=allAccessAllowed)
コード例 #9
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def confirmIntDisable(x, y):
    # x = device id, y = interface name
    host = db_modifyDatabase.getHostByID(x)
    # Removes dashes from interface in URL
    y = interfaceReplaceSlash(y)
    return render_template("confirm/confirmintdisable.html",
                           host=host,
                           interface=y)
コード例 #10
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def confirmCfgCmdCustom():
    host = db_modifyDatabase.getHostByID(request.form['hostid'])
    session['HOSTNAME'] = request.form['hostname']
    session['COMMAND'] = request.form['command']
    session['HOSTID'] = request.form['hostid']
    session['IOS_TYPE'] = host.ios_type

    return render_template("confirm/confirmcfgcmdcustom.html")
コード例 #11
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def modalCmdShowCDPNeigh(x):
    initialChecks()
    # x = device id
    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    result = host.pull_cdp_neighbor(activeSession)
    writeToLog('viewed CDP neighbors via button on host %s' % (host.hostname))
    return render_template("/cmdshowcdpneigh.html", host=host, result=result)
コード例 #12
0
def deviceUptime(x):
    """Get uptime of selected device.

    x = host id.
    """
    initialChecks()
    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    return jsonify(host.pull_device_uptime(activeSession))
コード例 #13
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def enterConfigMode(x):
    initialChecks()
    # x = device id
    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    host.enter_config_mode(activeSession)

    writeToLog('entered config mode via iShell on host %s' % (host.hostname))
    return ('', 204)
コード例 #14
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def modalCmdShowVersion(x):
    initialChecks()
    # x = device id
    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    result = host.pull_version(activeSession)

    writeToLog('viewed version info via button on host %s' % (host.hostname))
    return render_template("/cmdshowversion.html", host=host, result=result)
コード例 #15
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def modalCmdSaveConfig(x):
    initialChecks()
    # x = device id
    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    result = host.save_config_on_device(activeSession)

    writeToLog('saved config via button on host %s' % (host.hostname))
    return render_template("/cmdsaveconfig.html", host=host)
コード例 #16
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def modalCfgCmdCustom(x):
    initialChecks()
    # x = device id
    host = db_modifyDatabase.getHostByID(x)

    # Custom Commands form
    form = CustomCfgCommandsForm(request.values, hostname=host.hostname)

    return render_template("/cfgcmdcustom.html", host=host, form=form)
コード例 #17
0
ファイル: views.py プロジェクト: slaffcheff/netconfig
def confirmMultiIntEdit(x, y):
    # x = device id
    # y = interfaces separated by '&' in front of each interface name
    #y = interfaceReplaceSlash(y)
    host = db_modifyDatabase.getHostByID(x)
    return render_template("confirm/confirmmultipleintedit.html",
                           hostid=x,
                           interfaces=y,
                           host=host)
コード例 #18
0
def hostShellOutput(x, m, y):
    """Display iShell output fields.

    x = device id
    m = config or enable mode
    y = encoded commands from javascript
    """
    initialChecks()

    output = []
    configError = False

    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)

    # Decode command in URL received from javascript
    command = unquote_plus(y).decode('utf-8')

    # Replace '_' with '/'
    command = interfaceReplaceSlash(command)

    # Append prompt and command executed to beginning of output
    output.append(host.find_prompt_in_session(activeSession) + command)

    # Check if last character is a '?'
    if command[-1] == '?':
        if m == 'c':
            # Get command output as a list.
            # Insert list contents into 'output' list.
            configError = True
        else:
            # Get command output as a list.
            # Insert list contents into 'output' list.
            output.extend(getCmdOutputNoCR(activeSession, command))
            # Append prompt and command executed to end of output
            output.append(host.find_prompt_in_session(activeSession))

    else:
        if m == 'c':
            # Get command output as a list.
            # Insert list contents into 'output' list.
            output.extend(getCfgCmdOutput(activeSession, command))
        else:
            # Get command output as a list.
            # Insert list contents into 'output' list.
            output.extend(host.get_cmd_output(command, activeSession))
            # Append prompt and command executed to end of output.
            output.append(host.find_prompt_in_session(activeSession))

    writeToLog('ran command on host %s - %s' % (host.hostname, command))

    return render_template("hostshelloutput.html",
                           output=output,
                           command=command,
                           mode=m,
                           configError=configError)
コード例 #19
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def modalCmdShowStartConfig(x):
    initialChecks()
    # x = device id
    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    hostConfig = host.pull_start_config(activeSession)
    writeToLog('viewed startup-config via button on host %s' % (host.hostname))
    return render_template("/cmdshowstartconfig.html",
                           host=host,
                           hostConfig=hostConfig)
コード例 #20
0
def confirmMultiIntEdit(x, y):
    """Confirm editing multiple device interfaces.  WIP.

    x = device id
    y = interfaces separated by '&' in front of each interface name
    """
    host = db_modifyDatabase.getHostByID(x)
    return render_template("confirm/confirmmultipleintedit.html",
                           host=host,
                           interfaces=y)
コード例 #21
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def hostShell(x):
    initialChecks()
    # x = device id
    host = db_modifyDatabase.getHostByID(x)

    # Exit config mode if currently in it on page refresh/load
    exitConfigMode(host.id)

    writeToLog('accessed interactive shell on host %s' % (host.hostname))
    return render_template("hostshell.html", host=host)
コード例 #22
0
ファイル: views.py プロジェクト: slaffcheff/netconfig
def viewSpecificHost(x):
    # x is host.id
    initialChecks()

    # This fixes page refresh issue when clicking on a Modal that breaks DataTables
    if 'modal' in x:
        # Return empty response, as the page is loaded from the Modal JS
        # However this breaks the Loading modal JS function.  Unsure why, need to research
        return ('', 204)

    host = db_modifyDatabase.getHostByID(x)
    writeToLog('accessed host %s' % (host.hostname))

    # Get any existing SSH sessions
    activeSession = retrieveSSHSession(host)

    if host.ios_type == 'cisco_nxos':
        interfaces = phi.pullHostInterfacesNXOS(host.ipv4_addr, activeSession)
        #uptime = getCmdOutput(host.ipv4_addr, host.ios_type, 'show version | include uptime')
        #for x in uptime:
        #  uptimeOutput = x.split(' ', 3)[-1]

    elif host.ios_type == 'cisco_ios' or host.ios_type == 'cisco_iosxe':
        interfaces = phi.pullHostInterfacesIOS(host.ipv4_addr, activeSession)
        #uptime = getCmdOutput(host.ipv4_addr, host.ios_type, 'show version | include uptime')
        #for x in uptime:
        #  uptimeOutput = x.split(' ', 3)[-1]

    elif host.ios_type == 'cisco_asa':
        interfaces = phi.pullHostInterfacesASA(host.ipv4_addr, activeSession)
        #uptime = getCmdOutput(host.ipv4_addr, host.ios_type, 'show version | include up ')
        #for x in uptime:
        #  if 'failover' in x:
        #    break
        #  else:
        #    uptimeOutput = x.split(' ', 2)[-1]

    upInt, downInt, disabledInt, totalInt = phi.countInterfaceStatus(
        interfaces, host.ios_type)

    # if interfaces is x.x.x.x skipped - connection timeout, throw error page redirect
    if fn.containsSkipped(interfaces):
        disconnectFromSSH(ssh[sshKey])
        return redirect(url_for('noHostConnectError', host=host.hostname))
    elif not interfaces:
        disconnectFromSSH(ssh[sshKey])
        return redirect(url_for('noHostConnectError', host=host.hostname))
    else:
        return render_template("/db/viewspecifichost.html",
                               host=host,
                               interfaces=interfaces,
                               upInt=upInt,
                               downInt=downInt,
                               disabledInt=disabledInt,
                               totalInt=totalInt)
コード例 #23
0
def confirmHostEdit(x):
    """Confirm settings to edit host with in local database.

    x = original host ID
    """
    originalHost = db_modifyDatabase.getHostByID(x)
    hostname = request.form['hostname']
    ipv4_addr = request.form['ipv4_addr']
    hosttype = request.form['hosttype']
    ios_type = request.form['ios_type']

    # If exists, disconnect any existing SSH sessions
    #  and clear them from the SSH dict
    try:
        disconnectSpecificSSHSession(originalHost)
        writeToLog(
            'disconnected and cleared saved SSH session information for edited host %s'
            % (originalHost.hostname))
    except (socket.error, EOFError):
        writeToLog('no existing SSH sessions for edited host %s' %
                   (originalHost.hostname))
    except:
        writeToLog('could not clear SSH session for edited host %s' %
                   (originalHost.hostname))

    result = db_modifyDatabase.editHostInDatabase(originalHost.id, hostname,
                                                  ipv4_addr, hosttype,
                                                  ios_type)

    if result:
        updatedHost = db_modifyDatabase.getHostByID(x)
        writeToLog('edited host %s in database' % (originalHost.hostname))
        return render_template("confirm/confirmhostedit.html",
                               title='Edit host confirm',
                               originalHost=originalHost,
                               updatedHost=updatedHost,
                               hostname=hostname,
                               ipv4_addr=ipv4_addr,
                               hosttype=hosttype,
                               ios_type=ios_type)
    else:
        return redirect(url_for('confirmHostEdit', x=originalHost))
コード例 #24
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def editHost(x):
    # x is host ID
    host = db_modifyDatabase.getHostByID(x)
    form = EditHostForm()
    if form.validate_on_submit():
        return redirect('/confirm/confirmhostedit')
    return render_template('/edithost.html',
                           title='Edit host in database',
                           id=x,
                           originalHost=host.hostname,
                           form=form)
コード例 #25
0
ファイル: views.py プロジェクト: slaffcheff/netconfig
def modalCmdSaveConfig(x):
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)

    activeSession = retrieveSSHSession(host)

    hostConfig = saveConfigOnSession(activeSession, host)

    writeToLog('saved config via button on host %s' % (host.hostname))
    return render_template("/cmdsaveconfig.html", host=host)
コード例 #26
0
def confirmIntDisable(x, y):
    """Confirm disabling specific device interface before executing.

    x = device id
    y = interface name
    """
    host = db_modifyDatabase.getHostByID(x)
    # Removes dashes from interface in URL
    y = interfaceReplaceSlash(y)
    return render_template("confirm/confirmintdisable.html",
                           host=host,
                           interface=y)
コード例 #27
0
def modalCmdShowInventory(x):
    """Display modal with device inventory information.

    x = device id
    """
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    result = host.pull_inventory(activeSession)

    writeToLog('viewed inventory info via button on host %s' % (host.hostname))
    return render_template("/cmdshowinventory.html", host=host, result=result)
コード例 #28
0
def modalCfgCmdCustom(x):
    """Display modal to retrieve custom bulk config commands to execute.

    x = device id
    """
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)

    # Custom Commands form
    form = CustomCfgCommandsForm(request.values, hostname=host.hostname)

    return render_template("/cfgcmdcustom.html", host=host, form=form)
コード例 #29
0
def modalCmdSaveConfig(x):
    """Save device configuration to memory and display result in modal.

    x = device id
    """
    initialChecks()

    host = db_modifyDatabase.getHostByID(x)
    activeSession = retrieveSSHSession(host)
    host.save_config_on_device(activeSession)

    writeToLog('saved config via button on host %s' % (host.hostname))
    return render_template("/cmdsaveconfig.html", host=host)
コード例 #30
0
ファイル: views.py プロジェクト: jscobbie73/netconfig
def resultsHostDeleted(x):
    # x = device ID
    host = db_modifyDatabase.getHostByID(x)
    # Removes host from database
    result = db_modifyDatabase.deleteHostInDB(host.id)
    if result:
        disconnectSpecificSSHSession(host)
        writeToLog('deleted host %s in database' % (host.hostname))
        return render_template("results/resultshostdeleted.html",
                               host=host,
                               result=result)
    else:
        return redirect(url_for('confirmHostDelete', x=host.id))