001: /* CVS ID: $Id: SystemCheck.java,v 1.1.1.1 2002/10/02 18:42:51 wastl Exp $ */
002: package net.wastl.webmail.server;
003:
004: import java.io.*;
005: import java.util.regex.*;
006: import net.wastl.webmail.exceptions.*;
007:
008: /**
009: * SystemCheck.java
010: *
011: * Created: Tue Aug 31 15:40:57 1999
012: *
013: * Copyright (C) 1999-2000 Sebastian Schaffert
014: *
015: * This program is free software; you can redistribute it and/or
016: * modify it under the terms of the GNU General Public License
017: * as published by the Free Software Foundation; either version 2
018: * of the License, or (at your option) any later version.
019: *
020: * This program is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * You should have received a copy of the GNU General Public License
026: * along with this program; if not, write to the Free Software
027: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
028: */
029: /**
030: *
031: *
032: *
033: * @author Sebastian Schaffert
034: * @version
035: */
036:
037: public class SystemCheck {
038:
039: public SystemCheck(WebMailServer parent) throws WebMailException {
040: System.err.println("- Checking Java Virtual Machine ... ");
041: System.err.print(" * Version: "
042: + System.getProperty("java.version") + " ... ");
043:
044: /* Test if the Java version might cause trouble */
045: if (System.getProperty("java.version").compareTo("1.4") >= 0) {
046: System.err.println("ok.");
047: } else {
048: System.err
049: .println("warn. At least Java 1.4 is required for WebMail.");
050: //System.exit(1);
051: }
052:
053: /* Test if the operating system is supported */
054: System.err.print(" * Operating System: "
055: + System.getProperty("os.name") + "/"
056: + System.getProperty("os.arch") + " "
057: + System.getProperty("os.version") + " ... ");
058: if (System.getProperty("os.name").equals("SunOS")
059: || System.getProperty("os.name").equals("Solaris")
060: || System.getProperty("os.name").equals("Linux")) {
061: System.err.println("ok.");
062: } else {
063: System.err
064: .println("warning. WebMail was only tested\n on Solaris, HP-UX and Linux and may cause problems on your platform.");
065: }
066:
067: /* Check if we are running as root and issue a warning */
068: try {
069: System.err.print(" * User name: "
070: + System.getProperty("user.name") + " ... ");
071: if (!System.getProperty("user.name").equals("root")) {
072: System.err.println("ok.");
073: } else {
074: System.err
075: .println("warning. You are running WebMail as root. This may be a potential security problem.");
076: }
077: } catch (Exception ex) {
078: // Security restriction prohibit reading the username, then we do not need to
079: // check for root anyway
080: }
081:
082: /* Check whether all WebMail system properties are defined */
083: System.err.print(" * WebMail System Properties: ");
084: //checkPathProperty(parent,"webmail.plugin.path");
085: //checkPathProperty(parent,"webmail.auth.path");
086: checkPathProperty(parent, "webmail.lib.path");
087: checkPathProperty(parent, "webmail.template.path");
088: checkPathProperty(parent, "webmail.data.path");
089: checkPathProperty(parent, "webmail.xml.path");
090: System.err.println("ok!");
091:
092: System.err.print(" * Setting DTD-path in webmail.xml ... ");
093: File f1 = new File(parent.getProperty("webmail.data.path")
094: + System.getProperty("file.separator") + "webmail.xml");
095: File f2 = new File(parent.getProperty("webmail.data.path")
096: + System.getProperty("file.separator") + "webmail.xml."
097: + Long.toHexString(System.currentTimeMillis()));
098:
099: try {
100: Pattern regexp = Pattern
101: .compile("<!DOCTYPE SYSDATA SYSTEM \".*\">");
102: BufferedReader file1 = new BufferedReader(
103: new FileReader(f1));
104: PrintWriter file2 = new PrintWriter(new FileWriter(f2));
105: try {
106: String line = file1.readLine();
107: while (line != null) {
108: Matcher m = regexp.matcher(line);
109: String s = m
110: .replaceAll("<!DOCTYPE SYSDATA SYSTEM \"file://"
111: + parent
112: .getProperty("webmail.xml.path")
113: + System
114: .getProperty("file.separator")
115: + "sysdata.dtd" + "\">");
116: // String s=regexp.substituteAll(line,"<!DOCTYPE SYSDATA SYSTEM \"file://"+
117: // parent.getProperty("webmail.xml.path")+
118: // System.getProperty("file.separator")+
119: // "sysdata.dtd"+"\">");
120: //System.err.println(s);
121: file2.println(s);
122: line = file1.readLine();
123: }
124: } catch (EOFException ex) {
125: }
126: file2.close();
127: file1.close();
128: } catch (Exception ex) {
129: //ex.printStackTrace();
130: //throw new WebMailException("Error parsing webmail.xml!");
131: throw new WebMailException(ex);
132: }
133: f2.renameTo(f1);
134: System.err.println("done!");
135: }
136:
137: protected static void checkPathProperty(WebMailServer parent,
138: String property) throws WebMailException {
139: if (parent.getProperty(property) == null
140: || parent.getProperty(property).equals("")) {
141: System.err.println("fatal error. " + property
142: + " not defined.");
143: throw new WebMailException();
144: } else {
145: try {
146: File f = new File(parent.getProperty(property));
147: parent.setProperty(property, f.getCanonicalPath());
148: } catch (IOException ex) {
149: throw new WebMailException(ex.getMessage());
150: }
151: }
152: }
153:
154: } // SystemCheck
|