1 | <%@ page import="java.io.File,
|
---|
2 | java.io.IOException,
|
---|
3 | java.util.Date"
|
---|
4 | session="false" %>
|
---|
5 | <html>
|
---|
6 | <head>
|
---|
7 | <title>System Fingerprint</title>
|
---|
8 | </head>
|
---|
9 | <body bgcolor=#ffffff>
|
---|
10 | <%!
|
---|
11 |
|
---|
12 | /*
|
---|
13 | * Fingerprint the users system. This is mainly for use in
|
---|
14 | * diagnosing classpath problems. It is intended to dump out
|
---|
15 | * a copy of the environment this webapp is running in,
|
---|
16 | * and additionally attempt to identify versions of each jar
|
---|
17 | * in the classpath.
|
---|
18 | *
|
---|
19 | * @author Brian Ewins
|
---|
20 | */
|
---|
21 |
|
---|
22 | private java.util.Properties versionProps=new java.util.Properties();
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Identify the version of a jar file. This uses a properties file
|
---|
26 | * containing known names and sizes in the format
|
---|
27 | * 'name(size)=version'. Version strings should be like 'xerces-1.4'
|
---|
28 | * ie they should include the name of the library.
|
---|
29 | */
|
---|
30 | public String getFileVersion(File file) throws IOException {
|
---|
31 | String key="<td>"+file.getName()+"</td>";
|
---|
32 | key+= "<td>"+file.length()+"</td>";
|
---|
33 | Date timestamp=new Date(file.lastModified());
|
---|
34 | key+= "<td>"+timestamp.toString()+"</td>";
|
---|
35 | return key;
|
---|
36 |
|
---|
37 | /* TODO: implement
|
---|
38 | String value=versionProps.getProperty(key);
|
---|
39 | if (value==null) {
|
---|
40 | // make it possible to have jars without version nos
|
---|
41 | value=versionProps.getProperty(file.getName());
|
---|
42 | }
|
---|
43 | if (value==null) {
|
---|
44 | // fall back on something obvious
|
---|
45 | value=key;
|
---|
46 | Date timestamp=new Date(file.lastModified());
|
---|
47 | value+=" / "+timestamp.toString();
|
---|
48 | }
|
---|
49 | return value;
|
---|
50 | */
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Split up a classpath-like variable. Returns a list of files.
|
---|
55 | * TODO: this can't cope with relative paths. I think theres code in BCEL that
|
---|
56 | * can be used for this?
|
---|
57 | */
|
---|
58 | File[] splitClasspath(String path) throws IOException {
|
---|
59 | java.util.StringTokenizer st=
|
---|
60 | new java.util.StringTokenizer(path,
|
---|
61 | System.getProperty("path.separator"));
|
---|
62 | int toks=st.countTokens();
|
---|
63 | File[] files=new File[toks];
|
---|
64 | for(int i=0;i<toks;i++) {
|
---|
65 | files[i]=new File(st.nextToken());
|
---|
66 | }
|
---|
67 | return files;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /** given a list of files, return a list of jars which actually exist */
|
---|
71 | File[] scanFiles(File[] files) throws IOException {
|
---|
72 | File[] jars=new File[files.length];
|
---|
73 | int found=0;
|
---|
74 | for (int i=0; i<files.length; i++) {
|
---|
75 | if (files[i].getName().toLowerCase().endsWith(".jar")
|
---|
76 | && files[i].exists()) {
|
---|
77 | jars[found]=files[i];
|
---|
78 | found++;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | if (found<files.length) {
|
---|
82 | File[] temp=new File[found];
|
---|
83 | System.arraycopy(jars,0,temp,0,found);
|
---|
84 | jars=temp;
|
---|
85 | }
|
---|
86 | return jars;
|
---|
87 | }
|
---|
88 |
|
---|
89 | private static final File[] NO_FILES=new File[0];
|
---|
90 |
|
---|
91 | /** scan a directory for jars */
|
---|
92 | public File[] scanDir(String dir) throws IOException
|
---|
93 | {
|
---|
94 | if(dir==null) {
|
---|
95 | return NO_FILES;
|
---|
96 | }
|
---|
97 | return scanDir(new File(dir));
|
---|
98 | }
|
---|
99 |
|
---|
100 | public File[] scanDir(File dir) throws IOException {
|
---|
101 | if (!dir.exists() || !dir.isDirectory()) {
|
---|
102 | return NO_FILES;
|
---|
103 | }
|
---|
104 | return scanFiles(dir.listFiles());
|
---|
105 | }
|
---|
106 |
|
---|
107 | /** scan a classpath for jars */
|
---|
108 | public File[] scanClasspath(String path) throws IOException {
|
---|
109 | if (path==null) {
|
---|
110 | return NO_FILES;
|
---|
111 | }
|
---|
112 | return scanFiles(splitClasspath(path));
|
---|
113 | }
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * scan a 'dirpath' (like the java.ext.dirs system property) for jars
|
---|
117 | */
|
---|
118 | public File[] scanDirpath(String path) throws IOException {
|
---|
119 | if (path==null) {
|
---|
120 | return NO_FILES;
|
---|
121 | }
|
---|
122 | File[] current=new File[0];
|
---|
123 | File[] dirs=splitClasspath(path);
|
---|
124 | for(int i=0; i<dirs.length; i++) {
|
---|
125 | File[] jars=scanDir(dirs[i]);
|
---|
126 | File[] temp=new File[current.length+jars.length];
|
---|
127 | System.arraycopy(current,0,temp,0,current.length);
|
---|
128 | System.arraycopy(jars,0,temp,current.length,jars.length);
|
---|
129 | current=temp;
|
---|
130 | }
|
---|
131 | return scanFiles(current);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /** print out the jar versions for a directory */
|
---|
135 | public void listDirectory(String title, JspWriter out,String dir, String comment) throws IOException {
|
---|
136 | listVersions(title, out,scanDir(dir), comment);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /** print out the jar versions for a directory-like system property */
|
---|
140 | public void listDirProperty(String title, JspWriter out,String key, String comment) throws IOException {
|
---|
141 | listVersions(title, out,scanDir(System.getProperty(key)), comment);
|
---|
142 | }
|
---|
143 |
|
---|
144 | /** print out the jar versions for a classpath-like system property */
|
---|
145 | public void listClasspathProperty(String title, JspWriter out,String key, String comment) throws IOException {
|
---|
146 | listVersions(title, out,scanClasspath(System.getProperty(key)), comment);
|
---|
147 | }
|
---|
148 |
|
---|
149 | /** print out the jar versions for a 'java.ext.dirs'-like system property */
|
---|
150 | public void listDirpathProperty(String title, JspWriter out,String key, String comment) throws IOException {
|
---|
151 | listVersions(title, out,scanDirpath(System.getProperty(key)), comment);
|
---|
152 | }
|
---|
153 |
|
---|
154 | /** print out the jar versions for a context-relative directory */
|
---|
155 | public void listContextPath(String title, JspWriter out, String path, String comment) throws IOException {
|
---|
156 | listVersions(title, out,scanDir(getServletConfig().getServletContext().getRealPath(path)), comment);
|
---|
157 | }
|
---|
158 |
|
---|
159 | /** print out the jar versions for a given list of files */
|
---|
160 | public void listVersions(String title, JspWriter out,File[] jars, String comment) throws IOException {
|
---|
161 | out.print("<h2>");
|
---|
162 | out.print(title);
|
---|
163 | out.println("</h2>");
|
---|
164 | out.println("<table>");
|
---|
165 | for (int i=0; i<jars.length; i++) {
|
---|
166 | out.println("<tr>"+getFileVersion(jars[i])+"</tr>");
|
---|
167 | }
|
---|
168 | out.println("</table>");
|
---|
169 | if(comment!=null && comment.length()>0) {
|
---|
170 | out.println("<p>");
|
---|
171 | out.println(comment);
|
---|
172 | out.println("<p>");
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | %>
|
---|
177 | <h1>System Fingerprint</h1>
|
---|
178 | <h2>JVM and Server Version</h2>
|
---|
179 | <table>
|
---|
180 | <tr>
|
---|
181 | <td>Servlet Engine</td>
|
---|
182 | <td><%= getServletConfig().getServletContext().getServerInfo() %></td>
|
---|
183 | <td><%= getServletConfig().getServletContext().getMajorVersion() %></td>
|
---|
184 | <td><%= getServletConfig().getServletContext().getMinorVersion() %></td>
|
---|
185 | </tr>
|
---|
186 | <tr>
|
---|
187 | <td>Java VM</td>
|
---|
188 | <td><%= System.getProperty("java.vm.vendor") %></td>
|
---|
189 | <td><%= System.getProperty("java.vm.name") %></td>
|
---|
190 | <td><%= System.getProperty("java.vm.version") %></td>
|
---|
191 | </tr>
|
---|
192 | <tr>
|
---|
193 | <td>Java RE</td>
|
---|
194 | <td><%= System.getProperty("java.vendor") %></td>
|
---|
195 | <td><%= System.getProperty("java.version") %></td>
|
---|
196 | <td> </td>
|
---|
197 | </tr>
|
---|
198 | <tr>
|
---|
199 | <td>Platform</td>
|
---|
200 | <td><%= System.getProperty("os.name") %></td>
|
---|
201 | <td><%= System.getProperty("os.arch") %></td>
|
---|
202 | <td><%= System.getProperty("os.version") %></td>
|
---|
203 | </tr>
|
---|
204 | </table>
|
---|
205 |
|
---|
206 | <%
|
---|
207 | listClasspathProperty("Boot jars", out,"sun.boot.class.path", "Only valid on a sun jvm");
|
---|
208 | listClasspathProperty("System jars", out,"java.class.path", null);
|
---|
209 | listDirpathProperty("Extra system jars", out,"java.ext.dirs", null);
|
---|
210 | listContextPath("Webapp jars", out, "/WEB-INF/lib", null);
|
---|
211 | // identify the container...
|
---|
212 | String container=getServletConfig().getServletContext().getServerInfo();
|
---|
213 | if (container.startsWith("Tomcat Web Server/3.2")) {
|
---|
214 | String home=System.getProperty("tomcat.home");
|
---|
215 | if(home!=null) {
|
---|
216 | listDirectory("Tomcat 3.2 Common Jars", out,
|
---|
217 | home+File.separator
|
---|
218 | +"lib",
|
---|
219 | null);
|
---|
220 | }
|
---|
221 | } else if (container.startsWith("Tomcat Web Server/3.3")) {
|
---|
222 | String home=System.getProperty("tomcat.home");
|
---|
223 | if(home!=null) {
|
---|
224 | listDirectory("Tomcat 3.3 Container Jars", out,
|
---|
225 | home+File.separator
|
---|
226 | +"lib"+File.separator
|
---|
227 | +"container",
|
---|
228 | null);
|
---|
229 | listDirectory("Tomcat 3.3 Common Jars", out,
|
---|
230 | home+File.separator
|
---|
231 | +"lib"+File.separator
|
---|
232 | +"common",
|
---|
233 | null);
|
---|
234 | }
|
---|
235 | } else if (container.startsWith("Apache Tomcat/4.0")) {
|
---|
236 | //handle catalina common dir
|
---|
237 | String home=System.getProperty("catalina.home");
|
---|
238 | if(home!=null) {
|
---|
239 | listDirectory("Tomcat 4.0 Common Jars", out,
|
---|
240 | home+File.separator
|
---|
241 | +"common"+File.separator
|
---|
242 | +"lib",
|
---|
243 | null);
|
---|
244 | }
|
---|
245 | } else if (container.startsWith("Apache Tomcat/4.1")) {
|
---|
246 | //handle catalina common dir
|
---|
247 | String home=System.getProperty("catalina.home");
|
---|
248 | if(home!=null) {
|
---|
249 | listDirectory("Tomcat 4.1 Common Jars", out,
|
---|
250 | home+File.separator
|
---|
251 | +"shared"+File.separator
|
---|
252 | +"lib",
|
---|
253 | null);
|
---|
254 | }
|
---|
255 | } else if (System.getProperty("resin.home")!=null) {
|
---|
256 | String home=System.getProperty("resin.home");
|
---|
257 | if(home!=null) {
|
---|
258 | listDirectory("Resin Common Jars", out,
|
---|
259 | home+File.separator
|
---|
260 | +"lib",
|
---|
261 | null);
|
---|
262 | }
|
---|
263 | } else if (System.getProperty("weblogic.httpd.servlet.classpath")!=null) {
|
---|
264 | listClasspathProperty("Weblogic Servlet Jars", out,
|
---|
265 | "weblogic.httpd.servlet.classpath",
|
---|
266 | null);
|
---|
267 | } else {
|
---|
268 | //TODO: identify more servlet engine classpaths.
|
---|
269 | }
|
---|
270 | %>
|
---|
271 | </body>
|
---|
272 | </html> |
---|