#!/usr/bin/python import sys, os, re, pexpect, time, Cookie import Log, common 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 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 () form = cgi.FieldStorage () defaultCursor = None def GetDefaultCursor (): global defaultCursor if defaultCursor == None: defaultCursor = pyaaa.SafeBase () defaultCursor._Resume (sessionID) return defaultCursor # Cookie stuff sessionID = None def ProcessCookie (): global sessionID cookie = Cookie.SimpleCookie (os.environ.get("HTTP_COOKIE", "")) if cookie.has_key ("sid"): sessionID = cookie["sid"].value try: GetDefaultCursor () except pyaaa.InvalidSession: # TODO: Remember when this happens to catch people trying to brute-force session IDs. Log.Message ("Invalid session ID: " + sessionID + ". Redirecting to login.", "index.py", "ERROR") print "Location: login.py" else: # Not logged in, fail. Log.Message ("User not logged in. Redirecting to login.", "index.py", "ERROR") print "Location: login.py" def GetSwitchList (): global switchList if switchList == []: switchList = GetDefaultCursor ()._GetRecords ("NetworkDevice") return switchList def ShowDefaultPage (): pageText = """
Select a switch to get started!
""" return pageText def ShowSwitchStatus (switchName): pageText = """Number | Description | Connected | VLAN | Duplex | Speed | Media | Portfast | Errors |
---|---|---|---|---|---|---|---|---|
%s | %s | %s | %s | %s | %s | %s | %s | %s |