Source code: org/projectapollo/mysqladmin/MysqlAdmin.java
1 package org.projectapollo.mysqladmin;
2
3 import java.io.*;
4 import java.util.*;
5
6 import javax.servlet.*;
7 import javax.servlet.http.*;
8
9 import apollo.Session.*;
10 import apollo.Statistics.*;
11 import apollo.Log.*;
12 import apollo.*;
13
14 /** This a web based MySQL administration system
15 * @author Joe Kislo
16 * @version 1.0 11/15/99
17 */
18 public class MysqlAdmin extends HttpServlet {
19 String sessionFilename;
20 public static ManagerTracker MT;
21
22 public static String getStrAlertBox(String text) {
23 StringTokenizer st = new StringTokenizer(text, "\n");
24 StringBuffer sb = new StringBuffer();
25 boolean first=true;
26 while (st.hasMoreTokens()) {
27 if (first) {
28 first=false;
29 } else {
30 sb.append("\\n");
31 }
32 sb.append(st.nextToken());
33 }
34 return "<SCRIPT language=JavaScript>\n<!-- HIDE FROM _OLD_ BROWSERS\nalert(\""+sb.toString()+"\");\n\n// STOP HIDING -->\n</SCRIPT>";
35 }
36
37 public void init(ServletConfig config) throws ServletException {
38 super.init(config);
39 String propFileName = config.getInitParameter("PropertiesFile");
40
41 //Look to see if somebody passed in the PropertiesFile parameter
42 if (propFileName==null) {
43
44 //They didn't, so use the normal apollo startup procedure
45 MT = InitSystem.initSystem(config, this);
46 } else {
47
48 //Somebody passed in an explicit pointer to the properties file, better use it
49 Properties prop = new Properties();
50
51 try {
52 prop.load(new FileInputStream(propFileName));
53 } catch (IOException io) {
54 throw new ServletException("IO Error reading properties file!");
55 }
56 MT = InitSystem.initSystem(config, prop);
57 }
58 }
59
60 public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
61 doService(req,res);
62 }
63
64 public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
65 doService(req,res);
66 }
67 private void doService(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
68 MT.getStatsManager().getStat("Servlet").incStat("TotalTransactions");
69 long startTime = System.currentTimeMillis();
70 try {
71 if (req.getParameter("SessionID") == null) {
72 HTTPResponse response = MT.getPM().handleRequest(MT, "",(new HTTPRequest(req)),null);
73 response.render(res,req);
74
75 } else {
76 WebSession thisSession = MT.getSM().getSession(req.getParameter("SessionID"));
77 HTTPResponse response = MT.getPM().handleRequest(MT, req.getParameter("PageHandler"), (new HTTPRequest(req)),thisSession);
78 response.render(res,req);
79 }
80 } catch (Exception e) {
81 //Get the output stream
82
83 ServletOutputStream out = res.getOutputStream();
84 res.setContentType("text/html");
85 if (e instanceof InvalidSessionID) {
86 out.println("Invalid session ID! Try relogging in.");
87 } else if (e instanceof SessionExpired) {
88 out.println("The session you are trying to use is expired. The expiration period for your session was 10 minutes, you exceeded that time between transactions. For security reasons, you were automatically logged out. Please return to the login screen and relogin.");
89 } else {
90 //Add it to the stats
91 MT.getStatsManager().getStat("UserExceptions").incStat("TotalExceptions");
92 MT.getStatsManager().getStat("UserExceptions").addStat("Exceptions",new ExceptionData(e));
93
94 MT.getLM().log(LogManager.RUNTIME_EXCEPTION, e);
95 HTTPWriter writer = new HTTPWriter(out);
96 e.printStackTrace(writer);
97 writer.close();
98 }
99 }
100
101 MT.getStatsManager().getStat("Servlet").incStat("TotalServletCPUTime",(((float) (System.currentTimeMillis() - startTime))/1000));
102 }
103
104
105 public void destroy() {
106 super.destroy();
107 MT.destroy();
108 }
109 public String getServletInfo() {
110 return "An example of the Apollo Project";
111 }
112
113 }