/[shmookey]/portconf/index.py


UCC Code Repository

Contents of /portconf/index.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96 - (show annotations) (download) (as text)
Wed May 7 09:59:20 2008 UTC (12 years, 8 months ago) by shmookey
File MIME type: text/x-python
File size: 5911 byte(s)
general bugfixes

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

Properties

Name Value
svn:executable *

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26