📄 main.java
字号:
if (log.isInfoEnabled())
log.info("IP address: " + ip.toString());
}
}
if (log.isInfoEnabled())
log.info("System properties follow:");
Properties sysProps = System.getProperties();
for (Iterator i = sysProps.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
int idx = 0;
String val = (String) entry.getValue();
while (true) {
if (entry.getKey().equals("java.class.path")) {
StringTokenizer t = new StringTokenizer(entry.getValue().toString(), System.getProperty("path.separator", ","));
while (t.hasMoreTokens()) {
String s = t.nextToken();
if (log.isInfoEnabled())
log.info("java.class.path=" + s);
}
break;
} else {
if ((val.length() - idx) > 256) {
if (log.isInfoEnabled())
log.info(" " + entry.getKey() + "=" + val.substring(idx, idx + 256));
idx += 256;
} else {
if (log.isInfoEnabled())
log.info(" " + entry.getKey() + "=" + val.substring(idx));
break;
}
}
}
}
}
private void loadSystemProperties() {
/*
* Read in system properties from a resource, more a debugging aid than
* anything else
*/
InputStream in = null;
try {
File f = new File(CONF_DIR, "system.properties");
in = new FileInputStream(f);
Properties p = new Properties();
p.load(in);
for (Enumeration e = p.keys(); e.hasMoreElements();) {
String k = (String) e.nextElement();
System.getProperties().setProperty(k, p.getProperty(k).trim());
}
} catch (IOException e) {
// Dont care
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ioe) {
}
}
}
/**
* Are we in development mode?
*/
useDevConfig = "true".equalsIgnoreCase(System.getProperty("sslexplorer.useDevConfig"));
if (!"".equals(System.getProperty("sslexplorer.localApplicationStore", ""))) {
appDir = new File(System.getProperty("sslexplorer.localApplicationStore"));
}
//
System.setProperty("org.mortbay.jetty.servlet.SessionCookie", System.getProperty("sslexplorer.cookie", "JSESSIONID"));
}
private Integer parseCommandLine(String[] args) {
defaultPort = -1;
jettyLog = "logs/yyyy_mm_dd.request.log";
boolean fullReset = false;
try {
for (int i = 0; i < args.length; i++) {
if (args[i].equals("--manager")) {
System.err
.println("The database manager can no longer be via the SSL-Explorer server command line. Run it directly from hsqldb.jar ensuring you have the SSL-Explorer webapp classes included in your class path.");
return new Integer(1);
} else if (args[i].equals("--setup")) {
System.err.println("WARNING: --setup is deprecated, please use --install");
install = true;
} else if (args[i].equals("--install")) {
install = true;
} else if (args[i].equals("--gui")) {
String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("windows")) {
gui = true;
} else if (os.equals("linux") || os.equals("solaris") || os.endsWith("aix")) {
String displaySysProp = System.getProperty("sslexplorer.display", "");
String display = null;
try {
display = displaySysProp.equals("") ? System.getenv("DISPLAY") : displaySysProp;
} catch (Throwable t) {
}
gui = display != null && display.length() > 0;
}
} else if (args[i].startsWith("--db")) {
DB_DIR = new File(args[i].substring(5));
if (DB_DIR.exists() && !DB_DIR.isDirectory()) {
throw new Exception("--db option specifies an existing file, must either not exist or be a directory");
}
} else if (args[i].startsWith("--applications")) {
appDir = new File(args[i].substring(15));
if (appDir.exists() && !appDir.isDirectory()) {
throw new Exception("--db option specifies an existing file, must either not exist or be a directory");
}
} else if (args[i].startsWith("--temp")) {
TMP_DIR = new File(args[i].substring(7));
if (TMP_DIR.exists() && !TMP_DIR.isDirectory()) {
throw new Exception("--temp option specifies an existing file, must either not exist or be a directory");
}
} else if (args[i].startsWith("--conf")) {
CONF_DIR = new File(args[i].substring(7));
if (!CONF_DIR.exists() || !CONF_DIR.isDirectory()) {
throw new Exception("--conf option does not specify a valid directory");
}
} else if (args[i].startsWith("--port")) {
defaultPort = Integer.parseInt(args[i].substring(7));
} else if (args[i].startsWith("--jettyLog")) {
jettyLog = args[i].substring(11);
} else if (args[i].equals("--full-reset")) {
fullReset = true;
} else if (args[i].startsWith("start")) {
// For compatibility with the install4j launcher
} else {
System.err.println("Starts / configures the SSL Explorer server.\n");
System.err.println("Usage: sslexplorer [OPTION]...");
System.err.println("\nThe server may be started in setup or normal mode. When setup.\n");
System.err.println("mode is enabled a plain http server will be started on port 28080\n");
System.err.println("allowing you configure using a browser.\n\n");
System.out.println("Options:\n");
System.out.println(" --install Start the server in installation mode.");
System.out.println(" --full-reset Deletes *all* configuration data and resets");
System.out.println(" SSL-Explorer to its initial state. Use with");
System.out.println(" greate caution.");
System.out.println(" --db=DIR Set the directory where the configuration");
System.out.println(" database is stored.");
System.out.println(" --conf=DIR Set the directory where the configuration");
System.out.println(" files are stored.");
System.out.println(" --temp=DIR Set the directory where the temporary");
System.out.println(" files are stored.");
System.out.println(" --port=NUMBER The port on which the server will start.");
System.out.println(" Note that this applies to both setup and");
System.out.println(" normal mode and will overide whatever port");
System.out.println(" been configured within SSL Explorer.");
System.out.println(" --jettyLog=LOG The location of the Jetty NCSA request log.");
System.out.println("\nInvalid option: " + args[i] + ".\n");
return new Integer(2);
}
}
// Create the temporary directory
if (!TMP_DIR.exists()) {
if (!TMP_DIR.mkdirs()) {
throw new Exception("Could not create temporary directory " + TMP_DIR.getAbsolutePath() + ".");
}
}
} catch (Exception e) {
System.err.println(e.getMessage());
return new Integer(2);
}
// Perform a full reset
if (fullReset) {
if (fullReset()) {
System.err.println("SSL-Explorer configuration has been fully reset");
return new Integer(0);
} else {
System.err.println("Aborted full reset.");
return new Integer(1);
}
}
// Another way for external processes to force starting installation
// wizard
if (new File(TMP_DIR, "setup.run").exists()) {
install = true;
}
return null;
}
/*
* Perform a full reset
*/
private boolean fullReset() {
if (gui) {
if (JOptionPane.showConfirmDialog(null, "The embedded configuration database will be\n"
+ "completely deleted and re-created the next\ntime you run the server. Are you absolutely\n"
+ "sure you wish to do this?", "Full Reset", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION) != JOptionPane.OK_OPTION) {
return false;
}
} else {
System.out.println("The embedded configuration database will be");
System.out.println("completely deleted and re-created the next");
System.out.println("time you run the server. Are you absolutely");
System.out.println("sure you wish to do this?");
System.out.println();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.print("(Y)es or (N)o: ");
String s;
try {
s = br.readLine();
if (s == null) {
return false;
}
if (s.toLowerCase().equals("y") || s.toLowerCase().equals("yes")) {
break;
}
if (s.toLowerCase().equals("n") || s.toLowerCase().equals("no")) {
return false;
}
System.out.println("\nPlease answer 'y' or 'yes' to perform the reset, or 'n' or 'no' to abort the reset.");
} catch (IOException e) {
return false;
}
}
}
// Start the reset
System.out.println("Resetting all configuration");
File[] f = getDBDirectory().listFiles();
if (f != null) {
for (int i = 0; i < f.length; i++) {
if (!f[i].getName().equals("CVS") && !f[i].equals(".cvsignore")) {
System.out.println(" Deleting " + f[i].getPath());
if (!f[i].delete()) {
System.out.println(" Failed to remove");
}
}
}
}
return true;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.Context#deobfuscatePassword(java.lang.String)
*/
public String deobfuscatePassword(String val) {
try {
return Password.deobfuscate(val);
} catch (Exception e) {
return "";
}
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.Context#obfuscatePassword(java.lang.String)
*/
public String obfuscatePassword(String val) {
return Password.obfuscate(val);
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.Context#setTrustMananger(javax.net.ssl.TrustManager)
*/
public void setTrustMananger(TrustManager trustManager, boolean require) {
if (listeners == null || listeners.size() == 0) {
log.warn("Not setting trust managers there are no SSL listeners configured.");
} else {
if (log.isInfoEnabled())
log.info("Set trust managers");
for (Iterator i = listeners.iterator(); i.hasNext();) {
SocketListener l = (SocketListener) i.next();
if (l instanceof CustomJsseListener) {
((CustomJsseListener) l).setNeedClientAuth(trustManager != null);
((CustomJsseListener) l).setTrustManager(trustManager, require);
}
}
}
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.Context#getContextProperty(java.lang.String)
*/
public String getContextProperty(String key) {
PropertyDefinition def = (PropertyDefinition) contextPropertyDefinitions.get(key);
if (def == null) {
throw new IllegalArgumentException("Context property definition for " + key
+ " does not exist, it is likely that the property is not defined in context-properties.xml");
}
String val = contextProperties.getProperty(key, def.getDefaultValue());
return def.getType() == PropertyDefinition.TYPE_PASSWORD ? deobfuscatePassword(val) : val;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.Context#setContextProperty(java.lang.String,
* java.lang.String)
*/
public String setContextProperty(String key, String value) {
String oldVal = getContextProperty(key);
PropertyDefinition def = (PropertyDefinition) contextPropertyDefinitions.get(key);
contextProperties.setProperty(key, def.getType() == PropertyDefinition.TYPE_PASSWORD ? obfuscatePassword(value) : value);
try {
OutputStream out = new FileOutputStream(new File(getConfDirectory(), "webserver.properties"));
contextProperties.store(out, "SSL-Explorer webserver properties");
Util.closeStream(out);
} catch (IOException ex) {
log.error("Failed to save web server properties! Your server may not initialize correctly", ex);
}
return oldVal;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.boot.Context#getContextPropertyDefinitions()
*/
public List getContextPropertyDefinitions() {
return new ArrayList(contextPropertyDefinitions.values());
}
public void addContextListener(ContextListener contextListener) {
contextListeners.add(contextListener);
}
public void removeContextListener(ContextListener contextListener) {
contextListeners.remove(contextListener);
}
public Preferences getPreferences() {
return PREF;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -