/[shmookey]/portconf/login.py


UCC Code Repository

Contents of /portconf/login.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 120 - (hide annotations) (download) (as text)
Thu Jun 5 07:30:56 2008 UTC (13 years, 6 months ago) by shmookey
File MIME type: text/x-python
File size: 2846 byte(s)
general improvements, beginning stump of a configuration interface

1 shmookey 56 #!/usr/bin/python
2    
3 shmookey 113 import sys, re, pexpect
4     import Log, common
5 shmookey 56
6 shmookey 113 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 shmookey 56
13 shmookey 113 for path in libPaths: sys.path.append (path)
14 shmookey 56
15 shmookey 113 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 shmookey 56
22 shmookey 113 import cgi, cgitb
23     cgitb.enable ()
24 shmookey 56
25     def ShowDefaultPage ():
26 shmookey 113 pageText = """
27 shmookey 56 <p>Log-in to get started!</p>
28 shmookey 117 <form class='loginform'>
29 shmookey 56 <table border='0' cellpadding='2' cellspacing='0' class='rowset'>
30 shmookey 117 <tr><td>Username:</td><td><input type='text' id='username'></input></td></tr>
31     <tr><td>Password:</td><td><input type='password' id='password'></input></td></tr>
32 shmookey 56 <tr><td><input type='hidden' name='action' value='status' />
33     <input type='submit' value='Log-in' /></td></tr>
34     </table>
35     </form>
36 shmookey 113
37 shmookey 56 <script type='text/javascript'>
38 shmookey 117 setLoginFormAction = function () {
39     username = $("#username").attr ("value");
40     password = $("#password").attr ("value");
41 shmookey 113 $('form.loginform').html ("<table border='0' cellpadding='2' cellspacing='0' class='rowset'>Logging in...</table>");
42 shmookey 117 $.getScript ("update-login.py?action=login&username=" + username + "&password=" + password, function () {
43     if (result == "success") {
44     $('form.loginform').html ("<table border='0' cellpadding='2' cellspacing='0' class='rowset'>Log-in successful.</table>");
45     window.location = "/";
46     } else {
47 shmookey 120 if (result == "failure") errorText = "Login failed.";
48     else if (result == "dberror") errorText = "There was a problem with the database.";
49 shmookey 117 $('form.loginform').html ("<table border='0' cellpadding='2' cellspacing='0' class='rowset'>" +
50 shmookey 120 "<tr><td>" + errorText + "</td></tr>" +
51 shmookey 117 "<tr><td>Username:</td><td><input type='text' id='username'></input></td></tr>" +
52     "<tr><td>Password:</td><td><input type='password' id='password'></input></td></tr>" +
53     "<tr><td><input type='hidden' name='action' value='status' />" +
54     "<input type='submit' value='Log-in' /></td></tr>" +
55     "</table>" );
56     $('form.loginform').submit (setLoginFormAction);
57     }
58     });
59 shmookey 113 return false;
60 shmookey 117 };
61     $('form.loginform').submit (setLoginFormAction);
62 shmookey 56 </script>
63     """
64    
65 shmookey 113 return pageText
66 shmookey 56
67    
68 shmookey 113 def GetBody ():
69 shmookey 115 pageText = ShowDefaultPage ()
70 shmookey 56
71 shmookey 113 return pageText
72 shmookey 56
73 shmookey 113 def GetSidebar ():
74     pageText = """
75     <dt><a href="./">Navigation</a></dt>
76     <dd><ul>
77     <li><a href="./">Log-in</a></li>
78     </ul></dd>
79     """
80     return pageText
81    
82     switchList = []
83     pageBuffer = ""
84     pageBuffer += "Content-Type: text/html\n\n"
85 shmookey 115 pageBuffer += common.GetHeader ("Log-In - Port Administration Configuration Tool", GetSidebar ())
86 shmookey 113 pageBuffer += GetBody ()
87     pageBuffer += common.GetFooter ()
88    
89     print pageBuffer

Properties

Name Value
svn:executable *

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26