Source code: configurator/JSPservletConfig.java
1 package configurator;
2
3 import javax.servlet.*;
4 import javax.servlet.http.*;
5 import java.io.*;
6 import java.util.*;
7 import java.net.*;
8 import java.util.jar.*;
9 import java.util.zip.*;
10 /**
11 * Publication configuration helper servlet.
12 * Changes:<ul>
13 * <li>Version 1.0.4: support for Cocoon with download from our site.</li></ul>
14 * <p>Copyright (c) 2000-2001
15 * <pre>
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; version 2
19 * of the License.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 * </pre>
25 * @author Alexis Grandemange
26 * @version 1, 0, 4
27 * @see JSPservlet
28 */
29 public class JSPservletConfig extends HttpServlet {
30 /** Unique pagebox identifier. */
31 String ID = null;
32 /** keystore name. */
33 String keystore = null;
34 /** keystore password. */
35 String keystorePassword = null;
36 /** Certificate Authority URL. */
37 String CAURL = null;
38 /** Certificate Revocation List URL. */
39 String CRLURL = null;
40 /** User to use to connect to CA for certificate. */
41 String CAuser = null;
42 /** Password to use to connect to CA for certificate. */
43 String CApassword = null;
44 /** User to use to connect to CA for CRL. */
45 String CRLuser = null;
46 /** Password to use to connect to CA for CRL. */
47 String CRLpassword = null;
48 /** Static pages expiration time (sec). */
49 int expiration = 0;
50 /** Certificate Revocation List scan period. */
51 int CRLperiod = 0;
52 /** Cache directory path. */
53 String CachePath = null;
54 /** Log file cache. */
55 String LogFile = null;
56 /** Remote location property file path. */
57 String RemoteLocations = null;
58 /** Property file path of publisher location per archive. */
59 String Publishers = null;
60 /** all permission policy file path. */
61 String AllPermissionPolicy = null;
62 /** default property file path. */
63 String DefaultPolicy = null;
64 /** Version 1.0.4. Directory where to install ClassPath archives. */
65 String ClassPathDir = null;
66 /** Version 1.0.4. Mapping property file. */
67 String PageboxMapping = null;
68 /** name to use to invoke ServletLog. */
69 String logName = null;
70 /** name to use to invoke ServletStat. */
71 String statName = null;
72 /** trace mode. */
73 boolean toTrace = true;
74 /** stat mode. */
75 boolean toStat = true;
76 /** web.xml path. */
77 String webXml = null;
78 /** URL where to download JSPservlet. */
79 String JSPservletURL = null;
80 /** Application server current directory. */
81 String curDir = null;
82 /** msg buffer filled by check method. */
83 String msg = "";
84 HttpServletRequest request = null;
85 HttpServletResponse response = null;
86 InetAddress ia = null;
87 /**
88 * GET request handling.
89 * @param request HttpServletRequest.
90 * @param response HttpServletResponse.
91 */
92 public void doGet(HttpServletRequest request, HttpServletResponse response)
93 throws ServletException, IOException {
94 ia = InetAddress.getLocalHost();
95 this.request = request;
96 this.response = response;
97 ID = request.getParameter("ID");
98 keystore = request.getParameter("Keystore");
99 keystorePassword = request.getParameter("Password");
100 CAURL = request.getParameter("CAURL");
101 CRLURL = request.getParameter("CRLURL");
102 CAuser = request.getParameter("CAuser");
103 CApassword = request.getParameter("CApassword");
104 CRLuser = request.getParameter("CRLuser");
105 CRLpassword = request.getParameter("CRLpassword");
106 String szExpiration = request.getParameter("Expiration");
107 if (szExpiration != null)
108 expiration = Integer.parseInt(szExpiration);
109 String szCRLperiod = request.getParameter("CRLperiod");
110 if (szCRLperiod != null)
111 CRLperiod = Integer.parseInt(szCRLperiod);
112 CachePath = request.getParameter("CachePath");
113 LogFile = request.getParameter("LogFile");
114 RemoteLocations = request.getParameter("RemoteLocations");
115 Publishers = request.getParameter("Publishers");
116 AllPermissionPolicy = request.getParameter("AllPermissionPolicy");
117 DefaultPolicy = request.getParameter("DefaultPolicy");
118 logName = request.getParameter("LogName");
119 statName = request.getParameter("StatName");
120 ClassPathDir = request.getParameter("ClassPathDir");
121 PageboxMapping = request.getParameter("PageboxMapping");
122 webXml = request.getParameter("WebXml");
123 JSPservletURL = request.getParameter("JSPservletURL");
124 String szToGenerate = request.getParameter("Generate");
125 String szToCheck = request.getParameter("Check");
126 String szToSet = request.getParameter("Set");
127 msg = null;
128 PrintWriter out = response.getWriter();
129 if (curDir == null) {
130 File f = new File(".");
131 curDir = f.getAbsolutePath(); // just an help - not a good value!
132 if (curDir.endsWith(File.separator + "."))
133 curDir = curDir.substring(0, curDir.length() -2);
134 }
135 if (szToGenerate != null) {
136 if (generate(out, true))
137 return;
138 } else
139 if (szToCheck != null)
140 check();
141 else
142 if (szToSet != null)
143 setenv();
144 else
145 initialize();
146 out.println("<html>\n<head><title>JSPservletConfig</title></head>\n<body>");
147 out.println("<h2><font color=#DB1260>JSPservlet configurator</font></h2><hr>");
148 out.println("<form action=" + request.getRequestURI() + " method=\"GET\">");
149 out.println("<table border=0 cellspacing=2 cellpadding=2 width=100%>");
150 out.println(
151 "<font face=\"Arial\" size=2><tr><td width=35%><b>ID</b></td><td width=5% align=\"right\">" +
152 "<font face=\"Arial\" color=#DB1260 size=2><b>*</b></font></td><td width=60%>" +
153 "<input type=\"text\" name=\"ID\" size=60 value=\"" + ID + "\"></td></tr>");
154 out.println(
155 "<tr><td width=35%><b>Keystore</b></td><td width=5%> </td><td width=60%>" +
156 "<input type=\"text\" name=\"Keystore\" size=60 value=\"" + keystore +
157 "\"></td></tr>");
158 out.println(
159 "<tr><td width=35%><b>Password</b></td><td width=5%> </td><td width=60%>" +
160 "<input type=\"text\" name=\"Password\" size=60 value=\"" +
161 keystorePassword + "\"></td></tr>");
162 out.println(
163 "<tr><td width=35%><b>CA certificate URL</b></td><td width=5%> </td><td width=60%>" +
164 "<input type=\"text\" name=\"CAURL\" size=60 value=\"" + CAURL +
165 "\"></td></tr>");
166 out.println(
167 "<tr><td width=35%><b>CRL certificate URL</b></td><td width=5%> </td><td width=60%>" +
168 "<input type=\"text\" name=\"CRLURL\" size=60 value=\"" + CRLURL +
169 "\"></td></tr>");
170 out.println(
171 "<tr><td width=35%><b>CA user</b></td><td width=5%> </td><td width=60%>" +
172 "<input type=\"text\" name=\"CAuser\" size=60 value=\"" + CAuser +
173 "\"></td></tr>");
174 out.println(
175 "<tr><td width=35%><b>CA password</b></td><td width=5%> </td><td width=60%>" +
176 "<input type=\"text\" name=\"CApassword\" size=60 value=\"" + CApassword +
177 "\"></td></tr>");
178 out.println(
179 "<tr><td width=35%><b>CRL user</b></td><td width=5%> </td><td width=60%>" +
180 "<input type=\"text\" name=\"CRLuser\" size=60 value=\"" + CRLuser +
181 "\"></td></tr>");
182 out.println(
183 "<tr><td width=35%><b>CRL password</b></td><td width=5%> </td><td width=60%>" +
184 "<input type=\"text\" name=\"CRLpassword\" size=60 value=\"" + CRLpassword
185 + "\"></td></tr>");
186 out.println("<tr><td width=35%><b>Trace</b></td><td width=5%> </td>" +
187 "<td width=5%><input type=\"checkbox\" " + (toTrace ? "checked" : "") +
188 " name=\"trace\" value=on></td><td width=55%> </td></tr>");
189 out.println("<tr><td width=35%><b>Statistics</b></td><td width=5%> </td>" +
190 "<td width=5%><input type=\"checkbox\" " + (toStat ? "checked" : "") +
191 " name=\"stat\" value=on></td><td width=55%> </td></tr>");
192 out.println(
193 "<tr><td width=35%><b>Resource expiration time</b></td><td width=5%> </td><td width=60%>" +
194 "<input type=\"text\" name=\"Expiration\" size=60 value=\"" + expiration +
195 "\"></td></tr>");
196 out.println(
197 "<tr><td width=35%><b>CRL scan period</b></td><td width=5%> </td><td width=60%>"
198 + "<input type=\"text\" name=\"CRLperiod\" size=60 value=\"" + CRLperiod +
199 "\"></td></tr>");
200 out.println(
201 "<tr><td width=35%><b>Cache path</b></td><td width=5% align=\"right\">" +
202 "<font face=\"Arial\" color=#DB1260 size=2><b>*</b></font></td><td width=60%>"
203 + "<input type=\"text\" name=\"CachePath\" size=60 value=\"" + CachePath +
204 "\"></td></tr>");
205 out.println(
206 "<tr><td width=35%><b>Log file</b></td><td width=5%> </td><td width=60%>" +
207 "<input type=\"text\" name=\"LogFile\" size=60 value=\"" + LogFile +
208 "\"></td></tr>");
209 out.println(
210 "<tr><td width=35%><b>Remote location property file</b></td><td width=5%> </td><td width=60%>"
211 + "<input type=\"text\" name=\"RemoteLocations\" size=60 value=\"" +
212 RemoteLocations + "\"></td></tr>");
213 out.println(
214 "<tr><td width=35%><b>Publishers property file</b></td><td width=5%> </td><td width=60%>"
215 + "<input type=\"text\" name=\"Publishers\" size=60 value=\"" +
216 Publishers + "\"></td></tr>");
217 out.println(
218 "<tr><td width=35%><b>AllPermission policy file</b></td><td width=5%> </td><td width=60%>" +
219 "<input type=\"text\" name=\"AllPermissionPolicy\" size=60 value=\"" +
220 AllPermissionPolicy + "\"></td></tr>");
221 out.println(
222 "<tr><td width=35%><b>Default policy file</b></td><td width=5%> </td>" +
223 "<td width=60%><input type=\"text\" name=\"DefaultPolicy\" size=60 value=\"" +
224 DefaultPolicy + "\"></td></tr>");
225 out.println(
226 "<tr><td width=35%><b>Support lib directory</b></td><td width=5%> </td><td width=60%>"
227 + "<input type=\"text\" name=\"ClassPathDir\" size=60 value=\"" +
228 ClassPathDir + "\"></td></tr>");
229 out.println(
230 "<tr><td width=35%><b>Mapping property file</b></td><td width=5%> </td><td width=60%>"
231 + "<input type=\"text\" name=\"PageboxMapping\" size=60 value=\"" +
232 PageboxMapping + "\"></td></tr>");
233 out.println(
234 "<tr><td width=35%><b>ServletLog name</b></td><td width=5%> </td><td width=60%>"
235 + "<input type=\"text\" name=\"LogName\" size=60 value=\"" + logName +
236 "\"></td></tr>");
237 out.println(
238 "<tr><td width=35%><b>ServletStat name</b></td><td width=5%> </td><td width=60%>" +
239 "<input type=\"text\" name=\"StatName\" size=60 value=\"" + statName +
240 "\"></td></tr></font></table><font face=\"Arial\" size=2>");
241 out.println("<p>The following two parameters are used only "
242 + "if you click set and want to upload JSPservlet.</p></font>");
243 out.println("<table border=0 cellspacing=2 cellpadding=2 width=100%>");
244 out.println("<font face=\"Arial\" size=2>" +
245 "<tr><td width=35%><b>web.xml directory</b></td><td width=5% align=\"right\">" +
246 "<font face=\"Arial\" color=green size=2><b>*</b></font></td><td width=60%>" +
247 "<input type=\"text\" name=\"WebXml\" size=60 value=\"" + webXml +
248 "\"></td></tr>");
249 out.println(
250 "<tr><td width=35%><b>JSPservlet URL</b></td><td width=5% align=\"right\">" +
251 "<font face=\"Arial\" color=green size=2><b>*</b></font></td><td width=60%>" +
252 "<input type=\"text\" name=\"JSPservletURL\" size=60 value=\"" +
253 JSPservletURL + "\"></td></tr></font></table>");
254 out.println("<table border=0 cellspacing=2 cellpadding=2 width=100%>");
255 out.println("<font face=\"Arial\" size=2>" +
256 "<tr><td width=20%><input type=\"Submit\" value=\"Check\" name=\"Check\"></td>" +
257 "<td width=20%><input type=\"Submit\" value=\"Generate\" name=\"Generate\">" +
258 "</td><td width=20%><input type=\"Submit\"value=\"Set\" name=\"Set\"></td>");
259 out.println(
260 "<td width=40%> </td></tr></font></table><hr><font face=\"Arial\" size=2>");
261 if (msg.length() > 0)
262 out.println(msg);
263 else
264 out.println("No message");
265 out.println(
266 "<hr>Alexis Grandemange (c) 2000-2001 GNU GPL 2\n</font></body></html>");
267 out.flush();
268 }
269 /** Initialize parameters. */
270 private final void initialize() {
271 ID = "";
272 keystore = "keystore";
273 keystorePassword = "keystorePassword";
274 CAURL = "";
275 CRLURL = "";
276 CAuser = "";
277 CApassword = "";
278 CRLuser = "";
279 CRLpassword = "";
280 toTrace = toStat = true;
281 CachePath = curDir;
282 expiration = 30;
283 CRLperiod = 30;
284 LogFile = CachePath + File.separator + "JSPservlet.log";
285 RemoteLocations = CachePath + File.separator + "remoteLocation.properties";
286 Publishers = CachePath + File.separator + "publisher.properties";
287 AllPermissionPolicy = CachePath + File.separator + "allPermission.policy";
288 DefaultPolicy = CachePath + File.separator + "default.policy";
289 ClassPathDir = CachePath + File.separator + "lib";
290 PageboxMapping = CachePath + File.separator + "mapping-cocoon.properties";
291 logName = "ServletLog";
292 statName = "ServletStat";
293 webXml = CachePath + File.separator + "WEB-INF";
294 msg = "";
295 /*
296 * We use com.caucho.jsp.QJspFactory as in JSPservlet to minimize
297 * dependencies. Here we select the archive to download depending on
298 * the configurator application server.
299 */
300 try {
301 Class c = Class.forName("com.caucho.jsp.QJspFactory");
302 if (c == null)
303 return;
304 JSPservletURL = "http://pagebox.net/resin.jar";
305 }
306 catch(Exception e) {}
307 if (JSPservletURL == null)
308 JSPservletURL = "http://pagebox.net/tomcat.jar";
309 }
310 /** Checks parameter validity */
311 private final void check() {
312 msg = "";
313 if ((ID == null) || (ID.length() == 0))
314 msg +=
315 "<font color=green face=\"Arial\" size=2><b>Mandatory: ID must be set.</b></font><BR>\n";
316 if ((CachePath != null) && (CachePath.length() > 0)) {
317 File f = new File(CachePath);
318 if (!f.exists())
319 msg += "Warning: " + CachePath + " doesn't exist.<BR>\n";
320 else
321 if (!f.isDirectory())
322 msg += "<font color=red face=\"Arial\" size=2><b>Error: " + CachePath +
323 " is not a directory.</b></font><BR>\n";
324 if (CachePath.equals(curDir))
325 msg += "Warning: Do you really want to use " + CachePath +
326 " as cache path?<BR>\n";
327 else {
328 if (LogFile == null || LogFile.length() == 0 || LogFile.startsWith(curDir))
329 LogFile = CachePath + File.separator + "JSPservlet.log";
330 if (RemoteLocations == null || RemoteLocations.length() == 0 ||
331 RemoteLocations.startsWith(curDir))
332 RemoteLocations = CachePath + File.separator +
333 "remoteLocation.properties";
334 if (Publishers == null || Publishers.length() == 0 ||
335 Publishers.startsWith(curDir))
336 Publishers = CachePath + File.separator + "publisher.properties";
337 if (AllPermissionPolicy == null || AllPermissionPolicy.length() == 0)
338 AllPermissionPolicy = CachePath + File.separator +
339 "allPermission.policy";
340 else {
341 f = new File(AllPermissionPolicy);
342 if (!f.exists() && AllPermissionPolicy.startsWith(curDir))
343 AllPermissionPolicy = CachePath + File.separator +
344 "allPermission.policy";
345 }
346 if (DefaultPolicy == null || DefaultPolicy.length() == 0)
347 DefaultPolicy = CachePath + File.separator + "default.policy";
348 else {
349 f = new File(DefaultPolicy);
350 if (!f.exists() && DefaultPolicy.startsWith(curDir))
351 DefaultPolicy = CachePath + File.separator + "default.policy";
352 }
353 if (ClassPathDir == null || ClassPathDir.length() == 0)
354 ClassPathDir = CachePath + File.separator + "lib";
355 else {
356 if (ClassPathDir.startsWith(curDir))
357 ClassPathDir = CachePath + File.separator + "lib";
358 }
359 if (PageboxMapping == null || PageboxMapping.length() == 0)
360 PageboxMapping = CachePath + File.separator +
361 "mapping-cocoon.properties";
362 else {
363 f = new File(PageboxMapping);
364 if (!f.exists() && PageboxMapping.startsWith(curDir))
365 PageboxMapping = CachePath + File.separator +
366 "mapping-cocoon.properties";
367 }
368 if (webXml == null || webXml.length() == 0)
369 webXml = CachePath + File.separator + "WEB-INF";
370 else {
371 f = new File(webXml);
372 if (!f.exists() && webXml.startsWith(curDir))
373 webXml = CachePath + File.separator + "WEB-INF";
374 }
375 }
376 } else
377 msg += "Warning: cache path is not set<BR>\n";
378 if ((LogFile != null) && (LogFile.length() > 0)) {
379 File f = new File(LogFile);
380 f = f.getParentFile();
381 if (!f.exists())
382 msg += "Warning: directory where to create logs (" + f.getName() +
383 ") doesn't exist<BR>\n";
384 else
385 if (!f.canWrite())
386 msg +=
387 "<font color=red face=\"Arial\" size=2><b>Error: unable to create log file in " +
388 f.getAbsolutePath() + "</b></font><BR>\n";
389 } else
390 msg += "Warning: log file is not set<BR>\n";
391 if ((RemoteLocations != null) && (RemoteLocations.length() > 0)) {
392 File f = new File(RemoteLocations);
393 f = f.getParentFile();
394 if (!f.exists())
395 msg += "Warning: directory where to create remote locations property file ("
396 + f.getName() + ") doesn't exist<BR>\n";
397 else
398 if (!f.canWrite())
399 msg += "<font color=red face=\"Arial\" size=2><b>Error: " +
400 "unable to create remote locations property file in " +
401 f.getAbsolutePath() + "</b></font><BR>\n";
402 } else
403 msg += "Warning: remote locations property file is not set<BR>\n";
404 if ((Publishers != null) && (Publishers.length() > 0)) {
405 File f = new File(Publishers);
406 f = f.getParentFile();
407 if (!f.exists())
408 msg +=
409 "Warning: directory where to create publishers per archive property file ("
410 + f.getName() + ") doesn't exist<BR>\n";
411 else
412 if (!f.canWrite())
413 msg += "<font color=red face=\"Arial\" size=2><b>Error: " +
414 "unable to create publishers per archive property file in " +
415 f.getAbsolutePath() + "</b></font><BR>\n";
416 } else
417 msg += "Warning: publishers per archive property file is not set<BR>\n";
418 if ((AllPermissionPolicy != null) && (AllPermissionPolicy.length() > 0)) {
419 File f = new File(AllPermissionPolicy);
420 if (!f.exists())
421 msg += "Warning: allPermission policy " + AllPermissionPolicy +
422 " doesn't exist<BR>\n";
423 } else
424 msg += "Warning: allPermission policy file is not set<BR>\n";
425 if ((DefaultPolicy != null) && (DefaultPolicy.length() > 0)) {
426 File f = new File(DefaultPolicy);
427 if (!f.exists())
428 msg += "Warning: default policy " + DefaultPolicy + " doesn't exist<BR>\n";
429 } else
430 msg += "Warning: default policy file is not set<BR>\n";
431 if ((ClassPathDir != null) && (ClassPathDir.length() > 0)) {
432 File f = new File(ClassPathDir);
433 if (!f.exists())
434 msg += "Warning: support archive directory " + ClassPathDir +
435 " doesn't exist<BR>\n";
436 } else
437 msg += "Warning: support archive directory is not set<BR>\n";
438 if ((PageboxMapping != null) && (PageboxMapping.length() > 0)) {
439 File f = new File(PageboxMapping);
440 if (!f.exists())
441 msg += "Warning: Mapping property file " + PageboxMapping +
442 " doesn't exist<BR>\n";
443 } else
444 msg += "Warning: Mapping property file is not set<BR>\n";
445 if (request.getParameter("trace") != null)
446 toTrace = true;
447 else
448 toTrace = false;
449 if (request.getParameter("stat") != null)
450 toStat = true;
451 else
452 toStat = false;
453 }
454 /**
455 * Generates and returns a web.xml file.
456 * @param out PrintWriter.
457 * @param bHTTP true - set response time (HTTP flow).
458 */
459 private final boolean generate(PrintWriter out, boolean bHTTP) {
460 if (bHTTP)
461 msg = "";
462 if ((ID == null) || (ID.length() == 0)) {
463 msg = "ID must be set to generate\n";
464 return false;
465 }
466 if ((CachePath == null) || (CachePath.length() == 0)) {
467 File f = new File(ID);
468 CachePath = f.getAbsolutePath();
469 }
470 if ((LogFile == null) || (LogFile.length() == 0))
471 LogFile = CachePath + File.separator + "JSPservlet.log";
472 if ((RemoteLocations == null) || (RemoteLocations.length() == 0))
473 RemoteLocations = CachePath + File.separator + "remoteLocation.properties";
474 if ((Publishers == null) || (Publishers.length() == 0))
475 Publishers = CachePath + File.separator + "publisher.properties";
476 if ((AllPermissionPolicy == null) || (AllPermissionPolicy.length() == 0))
477 AllPermissionPolicy = CachePath + File.separator + "allPermission.policy";
478 if ((DefaultPolicy == null) || (DefaultPolicy.length() == 0))
479 DefaultPolicy = CachePath + File.separator + "default.policy";
480 if (bHTTP)
481 response.setContentType("text/xml");
482 out.println(
483 "<!DOCTYPE web-app\nPUBLIC \"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN\"\n" +
484 "\"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd\">");
485 out.println("<!-- Review on " + ia.getHostName() + "\n");
486 File f = new File(CachePath);
487 if (!f.exists())
488 out.println(
489 "\tACTION: Create CachePath:"+ CachePath + " Reason: doesn't exist\n");
490 else
491 if (!f.isDirectory())
492 out.println("\tERROR: CachePath:" + CachePath + " is not a directory\n");
493 else
494 if (!f.canWrite())
495 out.println(
496 "\tERROR: Appplication Server account doesn't have write access on CachePath:" +
497 CachePath + "\n");
498 f = new File(LogFile);
499 f = f.getParentFile();
500 if (!f.exists())
501 out.println("\tACTION: Create parent dir of LogFile:" + LogFile +
502 " Reason: doesn't exist\n");
503 f = new File(RemoteLocations);
504 f = f.getParentFile();
505 if (!f.exists())
506 out.println("\tACTION: Create parent dir of RemoteLocations:" +
507 RemoteLocations + " Reason: doesn't exist\n");
508 f = new File(Publishers);
509 f = f.getParentFile();
510 if (!f.exists())
511 out.println("\tACTION: Create parent dir of Publishers:" + Publishers +
512 " Reason: doesn't exist\n");
513 f = new File(AllPermissionPolicy);
514 if (!f.exists())
515 out.println("\tACTION: Create AllPermission policy file:" +
516 AllPermissionPolicy + " or comment it. Reason: doesn't exist\n" +
517 "\tNOTE: if you comment it the archives will run without sandbox\n");
518 f = new File(DefaultPolicy);
519 if (!f.exists())
520 out.println("\tACTION: Create default policy file:" + DefaultPolicy +
521 " or comment it. Reason: doesn't exist\n" +
522 "\tNOTE: if you comment it the archives will run without sandbox\n");
523 f = new File(ClassPathDir);
524 if (!f.exists())
525 out.println("\tACTION: Create and populate support archive directory:" +
526 ClassPathDir + " or comment it. Reason: doesn't exist\n" +
527 "\tNOTE: if you comment it you will run without support archives\n");
528 f = new File(PageboxMapping);
529 if (!f.exists())
530 out.println("\tACTION: Create Mapping property file:" + PageboxMapping +
531 " or comment it. Reason: doesn't exist\n" +
532 "\tNOTE: if you comment it you will run without mapping\n");
533 out.println("-->\n");
534 if (expiration == 0)
535 expiration = 30;
536 if (CRLperiod == 0)
537 CRLperiod = 30;
538 out.println("\n\n<web-app>\n\t<servlet>\n\t\t<servlet-name>JSPservlet" +
539 "</servlet-name>\n\t\t<servlet-class>JSPservletPkg.JSPservlet</servlet-class>\n");
540 out.println(genParm("cachePath", CachePath.replace('\\', '/'), "local cache"));
541 if (request.getParameter("trace") != null) {
542 toTrace = true;
543 out.println(genParm("toTrace", "TRUE", "trace activation"));
544 } else {
545 toTrace = true;
546 out.println(genParm("toTrace", "FALSE", "trace activation"));
547 }
548 if (request.getParameter("stat") != null) {
549 toStat = true;
550 out.println(genParm("toStat", "TRUE", "stat activation"));
551 } else {
552 toStat = false;
553 out.println(genParm("toStat", "FALSE", "stat activation"));
554 }
555 out.println(genParm("ID", ID, "unique identifier"));
556 out.println(genParm("logfile", LogFile.replace('\\', '/'), "trace location"));
557 out.println(genParm("remoteLocations", RemoteLocations.replace('\\', '/'),
558 "jar remote location"));
559 out.println(genParm("Publishers", Publishers.replace('\\', '/'),
560 "Publishers per archive"));
561 out.println(genParm("allPermissionPolicy",
562 AllPermissionPolicy.replace('\\', '/'), "policy file granting all rights"));
563 out.println(genParm("defaultPolicy", DefaultPolicy.replace('\\', '/'),
564 "policy file for archives without explicit policy"));
565 out.println(genParm("keystore", keystore,
566 "keystore location + download policy"));
567 out.println(genParm("keystorePassword", keystorePassword,
568 "keystore password"));
569 if ((CRLURL == null) || (CRLURL.length() == 0)) {
570 out.println("\t\t<!-- Uncomment the line if you fill the URL\n");
571 out.println(genParm("CRLURL", "LDAP://directory.verisign.com",
572 "Certificate Revocation List LDAP URL"));
573 out.println("\t\t-->\n");
574 } else
575 out.println(genParm("CRLURL", CRLURL,
576 "Certificate Revocation List LDAP URL"));
577 if ((CAURL == null) || (CAURL.length() == 0)) {
578 out.println("\t\t<!-- Uncomment the line if you fill the URL\n");
579 out.println(genParm("CAURL", "LDAP://directory.verisign.com",
580 "CA Certificate LDAP URL"));
581 out.println("\t\t-->\n");
582 } else
583 out.println(genParm("CAURL", CAURL, "CA Certificate LDAP URL"));
584 if ((CRLuser == null) || (CRLuser.length() == 0)) {
585 out.println("\t\t<!-- Uncomment the line if you fill the identifier\n");
586 out.println(genParm("CRLLDAPuser", CRLuser, "CRL LDAP user"));
587 out.println("\t\t-->\n");
588 } else
589 out.println(genParm("CRLLDAPuser", CRLuser, "CRL LDAP user"));
590 if ((CRLpassword == null) || (CRLpassword.length() == 0)) {
591 out.println("\t\t<!-- Uncomment the line if you fill the password\n");
592 out.println(genParm("CRLLDAPpasswd", CRLpassword, "CRL LDAP password"));
593 out.println("\t\t-->\n");
594 } else
595 out.println(genParm("CRLLDAPpasswd", CRLpassword, "CRL LDAP password"));
596 if ((CAuser == null) || (CAuser.length() == 0)) {
597 out.println("\t\t<!-- Uncomment the line if you fill the identifier\n");
598 out.println(genParm("CALDAPuser", CAuser, "CA certificate LDAP user"));
599 out.println("\t\t-->\n");
600 } else
601 out.println(genParm("CALDAPuser", CAuser, "CA certificate LDAP user"));
602 if ((CApassword == null) || (CApassword.length() == 0)) {
603 out.println("\t\t<!-- Uncomment the line if you fill the password\n");
604 out.println(genParm("CALDAPpasswd", CApassword,
605 "CA certificate LDAP password"));
606 out.println("\t\t-->\n");
607 } else
608 out.println(genParm("CALDAPpasswd", CApassword,
609 "CA certificate LDAP password"));
610 out.println(genParm("expiration", "" + expiration, "resource expiration time"));
611 out.println(genParm("CRLperiod", "" + CRLperiod,
612 "Certificate Revocation List scan period"));
613 out.println(genParm("ErrorPage", "/JSPerror.html",
614 "Page to display in case of unidentified error"));
615 out.println(genParm("NotFoundPage", "/JSPnotFound.html",
616 "Page to display when target servlet not found"));
617 out.println(genParm("UnauthorizedPage", "/JSPunauthorized.html",
618 "Target page tried an unauthorized access"));
619 out.println(genParm("RevokedPage", "/JSPrevoked.html",
620 "Revoked archive certificate"));
621 String classPathDir = ClassPathDir.replace('\\', '/');
622 String classPath = classPathDir + "/InputSource.jar" + File.pathSeparator;
623 classPath += (classPathDir + "/xerces_1_2.jar" + File.pathSeparator);
624 classPath += (classPathDir + "/turbine-pool.jar" + File.pathSeparator);
625 classPath += (classPathDir + "/w3c.jar" + File.pathSeparator);
626 classPath += (classPathDir + "/bsf.jar" + File.pathSeparator);
627 classPath += (classPathDir + "/xalan_1_2_D02.jar" + File.pathSeparator);
628 classPath += (classPathDir + "/fop_0_15_0.jar" + File.pathSeparator);
629 classPath += (classPathDir + "/cocoonPatch.jar" + File.pathSeparator);
630 classPath += (classPathDir + "/cocoon.jar" + File.pathSeparator);
631 classPath += (classPathDir + "/xml.jar" + File.pathSeparator);
632 classPath += (classPathDir + "/activation.jar" + File.pathSeparator);
633 classPath += (classPathDir + "/mail.jar" + File.pathSeparator);
634 classPath += (classPathDir + "/soap.jar" + File.pathSeparator);
635 classPath += (classPathDir + "/loopback.jar" + File.pathSeparator);
636 classPath += (classPathDir + "/cocoonSupport.jar");
637 out.println(genParm("ClassPath", classPath,
638 "policy file for archives without explicit policy"));
639 out.println(genParm("PageboxMapping", PageboxMapping.replace('\\', '/'),
640 "Mapping property file"));
641 /** Cocoon parameters. */
642 out.println(genParm("properties", "WEB-INF/cocoon.properties",
643 "Cocoon properties"));
644 /** SOAP parameters. */
645 out.println(genParm("faultListener", "org.apache.soap.server.DOMFaultListener",
646 "SOAP parameter"));
647 out.println(
648 "\t</servlet>\n\n\t<servlet>\n\t\t<servlet-name>ServletUpdate</servlet-name>\n\t\t" +
649 "<servlet-class>JSPservletPkg.ServletUpdate</servlet-class>\n\t</servlet>\n\n");
650 out.println("\t<servlet>\n\t\t<servlet-name>ServletLog</servlet-name>\n\t\t" +
651 "<servlet-class>JSPservletPkg.ServletLog</servlet-class>\n\t</servlet>\n\n");
652 out.println("\t<servlet>\n\t\t<servlet-name>ServletStat</servlet-name>\n\t\t" +
653 "<servlet-class>JSPservletPkg.ServletStat</servlet-class>\n\t</servlet>\n\n");
654 out.println(genMapping("ServletUpdate", "ServletUpdate"));
655 out.println(genMapping("ServletLog", logName));
656 out.println(genMapping("ServletStat", statName));
657 out.println(genMapping("JSPservlet", "/"));
658 out.println("</web-app>");
659 return true;
660 }
661 /**
662 * Service method invoked by generate. Builds a parameter entry (web.xml).
663 * @param name parameter name.
664 * @param value parameter value.
665 * @param descr parameter description.
666 */
667 static final String genParm(String name, String value, String descr) {
668 return "\t\t<init-param>\n\t\t<param-name>" + name +
669 "</param-name>\n\t\t<param-value>" + value +
670 "</param-value>\n\t\t<description>" + descr +
671 "</description>\n\t\t</init-param>\n";
672 }
673 /**
674 * Service method invoked by generate. Builds a servlet mapping (web.xml).
675 * @param name servlet name.
676 * @param value servlet invocation name.
677 */
678 static final String genMapping(String name, String value) {
679 return "\t<servlet-mapping>\n\t\t<servlet-name>" + name + "</servlet-name>" +
680 "\n\t\t<url-pattern>" + (value.startsWith("/") ? value : "/" + value) +
681 "</url-pattern>\n\t</servlet-mapping>\n\n";
682 }
683 /**
684 * method setting remote environment in order to host JSPservlet.
685 * should be invoked only if JSPservletConfig is installed on the target machine.
686 */
687 void setenv() {
688 msg = "";
689 if (request.getParameter("trace") != null)
690 toTrace = true;
691 else
692 toTrace = false;
693 if (request.getParameter("stat") != null)
694 toStat = true;
695 else
696 toStat = false;
697 if ((CachePath != null) && (CachePath.length() > 0) &&
698 !CachePath.equals(curDir)) {
699 File f = new File(CachePath);
700 if (!f.exists())
701 f.mkdirs();
702 }
703 if ((LogFile != null) && (LogFile.length() > 0)) {
704 File f = new File(LogFile);
705 f = f.getParentFile();
706 if (!f.exists())
707 f.mkdirs();
708 }
709 if ((RemoteLocations != null) && (RemoteLocations.length() > 0)) {
710 File f = new File(RemoteLocations);
711 f = f.getParentFile();
712 if (!f.exists())
713 f.mkdirs();
714 }
715 if ((Publishers != null) && (Publishers.length() > 0)) {
716 File f = new File(Publishers);
717 f = f.getParentFile();
718 if (!f.exists())
719 f.mkdirs();
720 }
721 if ((AllPermissionPolicy != null) && (AllPermissionPolicy.length() > 0)) {
722 File f = new File(AllPermissionPolicy);
723 if (!f.exists()) {
724 File p = f.getParentFile();
725 if (!p.exists())
726 p.mkdirs();
727 }
728 PrintWriter pw = null;
729 try {
730 pw = new PrintWriter(new BufferedWriter(
731 new FileWriter(AllPermissionPolicy, false)));
732 }
733 catch(IOException ioe) {
734 msg +=
735 "<font color=red face=\"Arial\" size=2><b>Error: unable to create " +
736 AllPermissionPolicy + "<BR>\n" + ioe + "</b></font><BR>\n";
737 return;
738 }
739 pw.println("grant {");
740 pw.println("\tpermission java.security.AllPermission;");
741 pw.println("};");
742 pw.close();
743 }
744 if ((DefaultPolicy != null) && (DefaultPolicy.length() > 0)) {
745 File f = new File(DefaultPolicy);
746 if (!f.exists()) {
747 File p = f.getParentFile();
748 if (!p.exists())
749 p.mkdirs();
750 }
751 PrintWriter pw = null;
752 try {
753 pw = new PrintWriter(new BufferedWriter(
754 new FileWriter(DefaultPolicy, false)));
755 }
756 catch(IOException ioe) {
757 msg +=
758 "<font color=red face=\"Arial\" size=2><b>Error: unable to create " +
759 DefaultPolicy + "<BR>\n" + ioe + "</b></font><BR>\n";
760 return;
761 }
762 pw.println("grant {");
763 pw.println("\tpermission java.util.PropertyPermission \"*\", \"read\";");
764 pw.println("};");
765 pw.close();
766 }
767 if ((ClassPathDir != null) && (ClassPathDir.length() > 0)) {
768 File f = new File(ClassPathDir);
769 if (!f.exists())
770 f.mkdirs();
771 else
772 if (!f.isDirectory()) {
773 msg += "<font color=red face=\"Arial\" size=2><b>Error: " + ClassPathDir
774 + " is not a directory<BR>\n";
775 return;
776 }
777 copy("InputSource.jar", "http://pagebox.net/");
778 copy("xerces_1_2.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
779 copy("turbine-pool.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
780 copy("w3c.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
781 copy("bsf.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
782 copy("xalan_1_2_D02.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
783 copy("fop_0_15_0.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
784 copy("cocoonPatch.jar", "http://pagebox.net/");
785 copy("cocoon.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
786 copy("xml.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
787 copy("activation.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
788 copy("mail.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
789 copy("soap.jar", "http://pagebox.sourceforge.net/cocoon1.8.2-lib/");
790 copy("loopback.jar", "http://pagebox.net/");
791 copy("cocoonSupport.jar", "http://pagebox.net/");
792 }
793 if ((PageboxMapping != null) && (PageboxMapping.length() > 0)) {
794 File f = new File(PageboxMapping);
795 if (!f.exists()) {
796 File p = f.getParentFile();
797 if (!p.exists())
798 p.mkdirs();
799 }
800 try {
801 URL url = new URL(
802 "http://pagebox.sourceforge.net/cocoon1.8.2-lib/mapping-cocoon.properties");
803 InputStream is = url.openStream();
804 BufferedOutputStream bos = new BufferedOutputStream(
805 new FileOutputStream(PageboxMapping));
806 BufferedInputStream bis = new BufferedInputStream(is);
807 int i;
808 while((i = bis.read()) != -1)
809 bos.write(i);
810 bos.close();
811 bis.close();
812 }
813 catch(Exception e) {
814 msg +=
815 "<font color=red face=\"Arial\" size=2><b>Error: unable to access " +
816 "http://pagebox.sourceforge.net/cocoon1.8.2-lib/mapping-cocoon.properties"
817 + "<BR>\n" + e + "</b></font><BR>\n";
818 }
819 }
820 File parent = null; // created in webXml step and used in JSPservletURL step
821 if ((webXml != null) && (webXml.length() > 0)) {
822 if (!webXml.endsWith("WEB-INF")) {
823 msg +=
824 "<font color=red face=\"Arial\" size=2><b>Error: invalid web.xml directory:" +
825 webXml + ". Should end with WEB-INF</b></font><BR>\n";
826 return;
827 }
828 File f = new File(webXml);
829 if (!f.exists())
830 f.mkdirs();
831 PrintWriter pw = null;
832 try {
833 pw = new PrintWriter(new BufferedWriter(
834 new FileWriter(webXml + File.separator + "web.xml", false)));
835 }
836 catch(IOException ioe) {
837 msg +=
838 "<font color=red face=\"Arial\" size=2><b>Error: unable to create " +
839 File.separator + "web.xml" + webXml + "<BR>\n" + ioe +
840 "</b></font><BR>\n";
841 return;
842 }
843 generate(pw, false);
844 pw.close();
845 parent = f.getParentFile();
846 try {
847 URL url = new URL(
848 "http://pagebox.sourceforge.net/cocoon1.8.2-lib/cocoon.properties");
849 InputStream is = url.openStream();
850 pw = new PrintWriter(new BufferedWriter(
851 new FileWriter(webXml + File.separator + "cocoon.properties", false)));
852 BufferedReader br = new BufferedReader(new InputStreamReader(is));
853 String line = null;
854 while((line = br.readLine()) != null) {
855 int idx = line.indexOf(
856 "/usr/local/etc/httpd/sites/pagebox.net/JSPservletDemo");
857 if (idx == -1) {
858 pw.println(line);
859 continue;
860 }
861 String toPrint = line.substring(0, idx);
862 toPrint += CachePath.replace('\\', '/');
863 toPrint += line.substring(idx +
864 "/usr/local/etc/httpd/sites/pagebox.net/JSPservletDemo".length());
865 pw.println(toPrint);
866 }
867 pw.close();
868 br.close();
869 }
870 catch(Exception e) {
871 msg +=
872 "<font color=red face=\"Arial\" size=2><b>Error: unable to access " +
873 "http://pagebox.sourceforge.net/cocoon1.8.2-lib/cocoon.properties"
874 + "<BR>\n" + e + "</b></font><BR>\n";
875 }
876 }
877 if ((JSPservletURL != null) && (JSPservletURL.length() > 0)) {
878 try {
879 URL url = new URL(JSPservletURL);
880 InputStream is = url.openStream();
881 JarInputStream jis = new JarInputStream(is);
882 JarEntry je = null;
883 while((je = jis.getNextJarEntry()) != null) {
884 String entryName = je.getName();
885 if ((entryName.startsWith(webInfClasses) &&
886 entryName.endsWith(".class")) || entryName.endsWith(".html")) {
887 BufferedInputStream bis = new BufferedInputStream(jis);
888 File f = new File(parent, entryName);
889 File p = f.getParentFile();
890 if (!p.exists())
891 p.mkdirs();
892 BufferedOutputStream bos = new BufferedOutputStream(
893 new FileOutputStream(f));
894 int i;
895 while((i = bis.read()) != -1)
896 bos.write(i);
897 bos.close();
898 // bis.close();
899 }
900 }
901 is.close();
902 }
903 catch(Exception e) {
904 msg += "<font color=red face=\"Arial\" size=2><b>Error: unable to access "
905 + JSPservletURL + "<BR>\n" + e + "</b></font><BR>\n";
906 return;
907 }
908 }
909 }
910 /** Version 1.0.4.
911 * Service method to download support archives from a repository.
912 * @param archive archive name.
913 * @param Url archive download url.
914 */
915 void copy(String archive, String Url) {
916 try {
917 File f = new File(ClassPathDir + File.separator + archive);
918 // If the archive exists don't download it again.
919 // Rationale: most of the time either all the archive is transfered or
920 // nothing
921 if (f.exists())
922 return;
923 URL url = new URL(Url + archive);
924 InputStream is = url.openStream();
925 BufferedOutputStream bos = new BufferedOutputStream(
926 new FileOutputStream(f));
927 BufferedInputStream bis = new BufferedInputStream(is);
928 int i;
929 while((i = bis.read()) != -1)
930 bos.write(i);
931 bos.close();
932 bis.close();
933 }
934 catch(Exception e) {
935 msg += "<font color=red face=\"Arial\" size=2><b>Error: unable to access "
936 + Url + archive + "<BR>\n" + e + "</b></font><BR>\n";
937 return;
938 }
939 }
940 /** copy classes found there and html without path */
941 private static final String webInfClasses = "WEB-INF/classes/";
942 }
943
944