#!/usr/bin/python import sys, re, pexpect import Log try: from Config import libPaths, dbName, dbUser, dbPass, dbHost, dbPort except: Log.Message ("Error occured in finding basic configuration paramaters. Reverting to installer.", "index.py", "ERROR") import install sys.exit () for path in Config.libPaths: sys.path.append (path) try: import pycisco, pyaaa except: Log.Message ("Couldn't import pycisco or pyaaa. Reverting to installer.", "index.py", "ERROR") import install sys.exit () import cgi, cgitb cgitb.enable () print "Content-Type: text/html" print import pycisco print "

Port Administration Configuration Tool

" form = cgi.FieldStorage () def ShowDefaultPage (): print "

Select a switch to get started!

" print "
" print "" print "" print "" print "
" def ShowSwitchStatus (switchName): print "

Port summary for " + switchName + "

" print "" try: ports = pycisco.GetPortSummary (switchName) except pexpect.TIMEOUT: print "

Switch appears to be down.

" return print "" print "" print "" print "" print "" print "" print "" print "" print "" print "" print "" print "" even = True for port in ports: print "" print "" print "" print "" print "" print "" print "" print "" print "" print "" print "" even = not even print "
NumberDescriptionConnectedVLANDuplexSpeedMediaPortfastErrors
" + port["name"] + "" + (port["description"] or "(not set)") + "" + port["connectstate"] + "" + port["vlan"] + "" + port["duplex"] + "" + port["speed"] + "" + port["media"] + "" + port["portfast"] + "" + port["errors"] + "
" if not form.has_key ("action"): ShowDefaultPage () elif form["action"].value == "status": if not form.has_key ("switch"): print "Missing switch argument, please stop trying to craft your own URLs!" else: ShowSwitchStatus (form["switch"].value)