/[shmookey]/portconf/index.py


UCC Code Repository

Contents of /portconf/index.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (hide annotations) (download) (as text)
Wed May 7 07:44:48 2008 UTC (12 years, 8 months ago) by shmookey
File MIME type: text/x-python
File size: 5928 byte(s)
pycisco fixes

1 shmookey 53 #!/usr/bin/python
2    
3 shmookey 62 import sys, re, pexpect
4 shmookey 86 import Log
5 shmookey 53
6 shmookey 62 try:
7 shmookey 86 from Config import libPaths, dbName, dbUser, dbPass, dbHost, dbPort
8 shmookey 84 except:
9 shmookey 86 Log.Message ("Error occured in finding basic configuration paramaters. Reverting to installer.", "index.py", "ERROR")
10 shmookey 62 import install
11     sys.exit ()
12    
13 shmookey 94 for path in libPaths: sys.path.append (path)
14 shmookey 86
15     try:
16     import pycisco, pyaaa
17     except:
18     Log.Message ("Couldn't import pycisco or pyaaa. Reverting to installer.", "index.py", "ERROR")
19     import install
20     sys.exit ()
21    
22 shmookey 62 import cgi, cgitb
23 shmookey 53 cgitb.enable ()
24     print "Content-Type: text/html"
25     print
26 shmookey 94 print """
27     <!--#set var="TITLE" value="Port Administration Configuration Tool" -->
28     <!--#set var="SIDEBAR" value="../sidebar.py" -->
29     <!--#include virtual="includes/header.html" -->
30     """
31 shmookey 53
32 shmookey 94
33 shmookey 62 import pycisco
34    
35 shmookey 53 print "<h2>Port Administration Configuration Tool</h2>"
36    
37     form = cgi.FieldStorage ()
38    
39    
40     def ShowDefaultPage ():
41     print "<p>Select a switch to get started!</p>"
42     print "<form action='index.html' method='get'>"
43     print "<select name='switch'>"
44     switches = pycisco.GetSwitches ()
45     for switch in switches:
46     print "<option value='" + switch + "'>" + switch + "</option>"
47     print "</select>"
48     print "<input type='hidden' name='action' value='status' />"
49     print "<input type='submit' value='View Port Summary' />"
50     print "</form>"
51    
52     def ShowSwitchStatus (switchName):
53     print "<h3>Port summary for " + switchName + "</h3>"
54    
55     print "<script type='text/javascript'>"
56     print """
57     $(document).ready (function () {
58     $("a.portfast").click (function () {
59     // Change the appearance and class so that it's no longer a "reveal"-style link
60     $(this).attr ("class", "portfastload");
61     $(this).text ("Wait...");
62    
63     portName = $(this).parents("tr").attr ('id');
64 shmookey 61 $(this).load ("update.py?action=getportfast&switch=""" + switchName + """&port=" + portName);
65 shmookey 53 $(this).unbind ();
66     $(this).click (togglePortfast);
67     });
68     $("a.errors").click (function () {
69     $(this).attr ("class", "errorsload");
70     $(this).text ("Wait...");
71     td = $(this).parents ("td");
72     portName = $(this).parents("tr").attr ('id');
73 shmookey 61 td.load ("update.py?action=geterrors&switch=""" + switchName + """&port=" + portName);
74 shmookey 53 });
75     $("a.status").click (function () {
76     $(this).attr ("class", "statusload");
77     $(this).text ("Wait...");
78     td = $(this).parents ("td");
79     portName = $(this).parents("tr").attr ('id');
80 shmookey 61 $(this).load ("update.py?action=toggleshutdown&switch=""" + switchName + """&port=" + portName);
81 shmookey 53 });
82     togglePortfast = function () {
83     $(this).text ("Wait...");
84     portName = $(this).parents("tr").attr ('id');
85 shmookey 61 $(this).load ("update.py?action=toggleportfast&switch=""" + switchName + """&port=" + portName);
86 shmookey 53 };
87     toggleShutdown = function () {
88     $(this).text ("Wait...");
89     portName = $(this).parents("tr").attr ('id');
90 shmookey 61 $(this).load ("update.py?action=toggleshutdown&switch=""" + switchName + """&port=" + portName);
91 shmookey 53 };
92     descClick = function () {
93     $(this).attr ("class", "descinput");
94     portName = $(this).parents("tr").attr ('id');
95     td = $(this).parents ("td");
96     td.html ("<input type='text' value='" + $(this).text() + "' />");
97     td.children ().focus ().blur (function () {
98     portName = $(this).parents("tr").attr ('id');
99     portDesc = $(this).attr ("value");
100     td = $(this).parents ("td");
101     td.html ("<a style='cursor:pointer'>Saving...</a>");
102     td.children ().click (descClick);
103 shmookey 61 td.children().load ("update.py?action=setdescription&switch=""" + switchName + """&port=" + portName + "&desc=" + escape (portDesc));
104 shmookey 53 });
105 shmookey 61 //td.load ("update.py?action=geterrors&switch=""" + switchName + """&port=" + portName);
106 shmookey 53 };
107     vlanClick = function () {
108     $(this).attr ("class", "vlaninput");
109     portName = $(this).parents("tr").attr ('id');
110     td = $(this).parents ("td");
111     td.html ("<input type='text' value='" + $(this).text() + "' />");
112     td.children ().focus ().blur (function () {
113     portName = $(this).parents("tr").attr ('id');
114     vlan = $(this).attr ("value");
115     td = $(this).parents ("td");
116     td.html ("<a style='cursor:pointer'>Saving...</a>");
117     td.children ().click (vlanClick);
118 shmookey 61 td.children().load ("update.py?action=setvlan&switch=""" + switchName + """&port=" + escape(portName) + "&vlan=" + escape (vlan));
119 shmookey 53 });
120     };
121     $("a.desc").click (descClick);
122     $("a.vlan").click (vlanClick);
123     });
124     """
125     print "</script>"
126    
127     try:
128     ports = pycisco.GetPortSummary (switchName)
129     except pexpect.TIMEOUT:
130     print "<h3 style='color:rgb(255,0,0)'>Switch appears to be down.</h3>"
131     return
132     print "<table border='0' cellpadding='2' cellspacing='0' class='rowset' >"
133     print "<tr>"
134     print "<th>Number</th>"
135     print "<th>Description</th>"
136     print "<th>Connected</th>"
137     print "<th>VLAN</th>"
138     print "<th>Duplex</th>"
139     print "<th>Speed</th>"
140     print "<th>Media</th>"
141     print "<th>Portfast</th>"
142     print "<th>Errors</th>"
143     print "</tr>"
144     even = True
145     for port in ports:
146     print "<tr class='" + (even and "even" or "odd") + "' id='" + port["name"] + "'>"
147     print "<td>" + port["name"] + "</td>"
148     print "<td><a style='cursor:pointer' class='desc'>" + (port["description"] or "(not set)") + "</a></td>"
149     print "<td><a style='cursor:pointer' class='status'>" + port["connectstate"] + "</a></td>"
150     print "<td><a style='cursor:pointer' class='vlan'>" + port["vlan"] + "</a></td>"
151     print "<td>" + port["duplex"] + "</td>"
152     print "<td>" + port["speed"] + "</td>"
153     print "<td>" + port["media"] + "</td>"
154     print "<td><a style='cursor:pointer' class='portfast'>" + port["portfast"] + "</a></td>"
155     print "<td><a style='cursor:pointer' class='errors'>" + port["errors"] + "</td>"
156     print "</tr>"
157     even = not even
158     print "</table>"
159    
160    
161     if not form.has_key ("action"):
162     ShowDefaultPage ()
163     elif form["action"].value == "status":
164     if not form.has_key ("switch"):
165     print "Missing switch argument, please stop trying to craft your own URLs!"
166     else:
167     ShowSwitchStatus (form["switch"].value)
168    
169 shmookey 94 print """<!--#include virtual="includes/footer.html" -->"""

Properties

Name Value
svn:executable *

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26