/[shmookey]/portconf/index.py


UCC Code Repository

Contents of /portconf/index.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 53 - (hide annotations) (download) (as text)
Thu Mar 13 05:47:17 2008 UTC (12 years, 10 months ago) by shmookey
Original Path: portconf/src/index.py
File MIME type: text/x-python
File size: 5309 byte(s)
Initial import.

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

Properties

Name Value
svn:executable *

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26