#!/usr/bin/python import cgi, cgitb, sys, re, pexpect cgitb.enable () import pycisco print "Content-Type: text/html" print 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)