📄 configurationdata.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.install;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.swing.*;
import org.compiere.*;
import org.compiere.db.*;
import org.compiere.util.*;
/**
* Configuration Data
*
* @author Jorg Janke
* @version $Id: ConfigurationData.java,v 1.13 2006/02/12 02:18:59 jjanke Exp $
*/
public class ConfigurationData
{
/**
* Constructor
* @param panel UI panel
*/
public ConfigurationData (ConfigurationPanel panel)
{
super ();
p_panel = panel;
} // ConfigurationData
/** UI Panel */
protected ConfigurationPanel p_panel = null;
/** Environment Properties */
protected Properties p_properties = new Properties();
/** Compiere Home */
private File m_compiereHome;
/** Static Logger */
static CLogger log = CLogger.getCLogger (ConfigurationData.class);
public static final String COMPIERE_ENV_FILE = "CompiereEnv.properties";
public static final String COMPIERE_HOME = "COMPIERE_HOME";
public static final String JAVA_HOME = "JAVA_HOME";
public static final String JAVA_TYPE = "COMPIERE_JAVA_TYPE";
public static final String COMPIERE_JAVA_OPTIONS = "COMPIERE_JAVA_OPTIONS";
public static final String KEYSTORE_PASSWORD = "myPassword";
public static final String COMPIERE_APPS_TYPE = "COMPIERE_APPS_TYPE";
public static final String COMPIERE_APPS_SERVER = "COMPIERE_APPS_SERVER";
public static final String COMPIERE_APPS_DEPLOY = "COMPIERE_APPS_DEPLOY";
public static final String COMPIERE_JNP_PORT = "COMPIERE_JNP_PORT";
public static final String COMPIERE_WEB_PORT = "COMPIERE_WEB_PORT";
public static final String COMPIERE_SSL_PORT = "COMPIERE_SSL_PORT";
public static final String COMPIERE_WEB_ALIAS = "COMPIERE_WEB_ALIAS";
public static final String COMPIERE_KEYSTORE = "COMPIERE_KEYSTORE";
public static final String COMPIERE_KEYSTOREPASS = "COMPIERE_KEYSTOREPASS";
public static final String COMPIERE_KEYSTORECODEALIAS = "COMPIERE_KEYSTORECODEALIAS";
public static final String COMPIERE_KEYSTOREWEBALIAS = "COMPIERE_KEYSTOREWEBALIAS";
public static final String COMPIERE_DB_TYPE = "COMPIERE_DB_TYPE";
public static final String COMPIERE_DB_SERVER = "COMPIERE_DB_SERVER";
public static final String COMPIERE_DB_PORT = "COMPIERE_DB_PORT";
public static final String COMPIERE_DB_NAME = "COMPIERE_DB_NAME";
public static final String COMPIERE_DB_URL = "COMPIERE_DB_URL";
public static final String COMPIERE_DB_USER = "COMPIERE_DB_USER";
public static final String COMPIERE_DB_PASSWORD = "COMPIERE_DB_PASSWORD";
public static final String COMPIERE_DB_SYSTEM = "COMPIERE_DB_SYSTEM";
public static final String COMPIERE_MAIL_SERVER = "COMPIERE_MAIL_SERVER";
public static final String COMPIERE_MAIL_USER = "COMPIERE_MAIL_USER";
public static final String COMPIERE_MAIL_PASSWORD = "COMPIERE_MAIL_PASSWORD";
public static final String COMPIERE_ADMIN_EMAIL = "COMPIERE_ADMIN_EMAIL";
public static final String COMPIERE_MAIL_UPDATED = "COMPIERE_MAIL_UPDATED";
public static final String COMPIERE_FTP_SERVER = "COMPIERE_FTP_SERVER";
public static final String COMPIERE_FTP_USER = "COMPIERE_FTP_USER";
public static final String COMPIERE_FTP_PASSWORD = "COMPIERE_FTP_PASSWORD";
public static final String COMPIERE_FTP_PREFIX = "COMPIERE_FTP_PREFIX";
public static final String COMPIERE_WEBSTORES = "COMPIERE_WEBSTORES";
/**
* Load Configuration Data
* @return true if loaded
*/
public boolean load()
{
// Load C:\Compiere2\CompiereEnv.properties
String compiereHome = System.getProperty(COMPIERE_HOME);
if (compiereHome == null || compiereHome.length() == 0)
compiereHome = System.getProperty("user.dir");
boolean envLoaded = false;
String fileName = compiereHome + File.separator + COMPIERE_ENV_FILE;
File env = new File (fileName);
if (env.exists())
{
try
{
FileInputStream fis = new FileInputStream(env);
p_properties.load(fis);
fis.close();
}
catch (Exception e)
{
log.severe(e.toString());
}
log.info(env.toString());
if (p_properties.size() > 5)
envLoaded = true;
//
setJavaType((String)p_properties.get(JAVA_TYPE));
initJava();
setJavaHome((String)p_properties.get(JAVA_HOME));
//
setCompiereHome((String)p_properties.get(COMPIERE_HOME));
String s = (String)p_properties.get(COMPIERE_KEYSTOREPASS);
if (s == null || s.length() == 0)
s = KEYSTORE_PASSWORD;
setKeyStore(s);
//
setAppsServerType((String)p_properties.get(COMPIERE_APPS_TYPE));
initAppsServer();
setAppsServer((String)p_properties.get(COMPIERE_APPS_SERVER));
setAppsServerDeployDir((String)p_properties.get(COMPIERE_APPS_DEPLOY));
setAppsServerJNPPort((String)p_properties.get(COMPIERE_JNP_PORT));
setAppsServerWebPort((String)p_properties.get(COMPIERE_WEB_PORT));
setAppsServerSSLPort((String)p_properties.get(COMPIERE_SSL_PORT));
//
setDatabaseType((String)p_properties.get(COMPIERE_DB_TYPE));
initDatabase((String)p_properties.get(COMPIERE_DB_NAME)); // fills Database Options
setDatabaseDiscovered((String)p_properties.get(COMPIERE_DB_NAME));
setDatabaseServer((String)p_properties.get(COMPIERE_DB_SERVER));
setDatabasePort((String)p_properties.get(COMPIERE_DB_PORT));
setDatabaseName((String)p_properties.get(COMPIERE_DB_NAME));
setDatabaseUser((String)p_properties.get(COMPIERE_DB_USER));
setDatabasePassword((String)p_properties.get(COMPIERE_DB_PASSWORD));
setDatabaseSystemPassword((String)p_properties.get(COMPIERE_DB_SYSTEM));
p_panel.fMailServer.setText((String)p_properties.get(COMPIERE_MAIL_SERVER));
p_panel.fMailUser.setText((String)p_properties.get(COMPIERE_MAIL_USER));
p_panel.fMailPassword.setText((String)p_properties.get(COMPIERE_MAIL_PASSWORD));
p_panel.fAdminEMail.setText((String)p_properties.get(COMPIERE_ADMIN_EMAIL));
}
InetAddress localhost = null;
String hostName = "unknown";
try
{
localhost = InetAddress.getLocalHost();
hostName = localhost.getHostName();
}
catch (Exception e)
{
log.severe("Cannot get local host name");
}
// No environment file found - defaults
// envLoaded = false;
if (!envLoaded)
{
log.info("Defaults");
initJava();
//
setCompiereHome(compiereHome);
setKeyStore(KEYSTORE_PASSWORD);
// AppsServer
initAppsServer();
setAppsServer(hostName);
// Database Server
initDatabase("");
setDatabaseName(getDatabaseDiscovered());
setDatabaseSystemPassword("");
setDatabaseServer(hostName);
setDatabaseUser("compiere");
setDatabasePassword("compiere");
// Mail Server
p_panel.fMailServer.setText(hostName);
p_panel.fMailUser.setText("info");
p_panel.fMailPassword.setText("");
p_panel.fAdminEMail.setText("info@" + hostName);
//
} // !envLoaded
// Default FTP stuff
if (!p_properties.containsKey(COMPIERE_FTP_SERVER))
{
p_properties.setProperty(COMPIERE_FTP_SERVER, "localhost");
p_properties.setProperty(COMPIERE_FTP_USER, "anonymous");
p_properties.setProperty(COMPIERE_FTP_PASSWORD, "user@host.com");
p_properties.setProperty(COMPIERE_FTP_PREFIX, "my");
}
// Default Java Options
if (!p_properties.containsKey(COMPIERE_JAVA_OPTIONS))
p_properties.setProperty(COMPIERE_JAVA_OPTIONS, "-Xms64M -Xmx512M");
// Web Alias
if (!p_properties.containsKey(COMPIERE_WEB_ALIAS) && localhost != null)
p_properties.setProperty(COMPIERE_WEB_ALIAS, localhost.getCanonicalHostName());
// (String)p_properties.get(COMPIERE_DB_URL) // derived
// Keystore Alias
if (!p_properties.containsKey(COMPIERE_KEYSTORECODEALIAS))
p_properties.setProperty(COMPIERE_KEYSTORECODEALIAS, "compiere");
if (!p_properties.containsKey(COMPIERE_KEYSTOREWEBALIAS))
p_properties.setProperty(COMPIERE_KEYSTOREWEBALIAS, "compiere");
return true;
} // load
/**************************************************************************
* test
* @return true if test ok
*/
public boolean test()
{
String error = testJava();
if (error != null)
{
log.severe(error);
return false;
}
error = testCompiere();
if (error != null)
{
log.severe(error);
return false;
}
p_panel.setStatusBar(p_panel.lAppsServer.getText());
error = testAppsServer();
if (error != null)
{
log.severe(error);
return false;
}
p_panel.setStatusBar(p_panel.lDatabaseServer.getText());
error = testDatabase();
if (error != null)
{
log.severe(error);
return false;
}
p_panel.setStatusBar(p_panel.lMailServer.getText());
error = testMail();
if (error != null)
{
log.severe(error);
return false;
}
return true;
} // test
/**
* Test Compiere and set CompiereHome
* @return error message or null if OK
*/
private String testCompiere()
{
// Compiere Home
m_compiereHome = new File (getCompiereHome());
boolean pass =m_compiereHome.exists();
String error = "Not found: CompiereHome = " + m_compiereHome;
p_panel.signalOK(p_panel.okCompiereHome, "ErrorCompiereHome",
pass, true, error);
if (!pass)
return error;
log.info("OK: CompiereHome = " + m_compiereHome);
p_properties.setProperty(COMPIERE_HOME, m_compiereHome.getAbsolutePath());
System.setProperty(COMPIERE_HOME, m_compiereHome.getAbsolutePath());
// KeyStore
String fileName = KeyStoreMgt.getKeystoreFileName(m_compiereHome.getAbsolutePath());
p_properties.setProperty(COMPIERE_KEYSTORE, fileName);
// KeyStore Password
String pw = new String(p_panel.fKeyStore.getPassword());
pass = pw != null && pw.length() > 0;
error = "Invalid Key Store Password = " + pw;
p_panel.signalOK(p_panel.okKeyStore, "KeyStorePassword",
pass, true, error);
if (!pass)
return error;
p_properties.setProperty(COMPIERE_KEYSTOREPASS, pw);
KeyStoreMgt ks = new KeyStoreMgt (fileName, p_panel.fKeyStore.getPassword());
error = ks.verify((JFrame)SwingUtilities.getWindowAncestor(p_panel));
pass = error == null;
p_panel.signalOK(p_panel.okKeyStore, "KeyStorePassword",
pass, true, error);
if (!pass)
return error;
log.info("OK: KeyStore = " + fileName);
return null;
} // testCompiere
/**************************************************************************
* Test (optional) Mail
* @return error message or null, if OK
*/
private String testMail()
{
// Mail Server
String server = p_panel.fMailServer.getText();
boolean pass = server != null && server.length() > 0
&& server.toLowerCase().indexOf("localhost") == -1
&& !server.equals("127.0.0.1");
String error = "Error Mail Server = " + server;
InetAddress mailServer = null;
try
{
if (pass)
mailServer = InetAddress.getByName(server);
}
catch (Exception e)
{
error += " - " + e.getMessage();
pass = false;
}
p_panel.signalOK(p_panel.okMailServer, "ErrorMailServer",
pass, true, error);
if (!pass)
{
p_properties.setProperty(COMPIERE_MAIL_SERVER, "");
return error;
}
p_properties.setProperty(COMPIERE_MAIL_SERVER, mailServer.getHostName());
// Mail User
String mailUser = p_panel.fMailUser.getText();
String mailPassword = new String(p_panel.fMailPassword.getPassword());
// m_errorString = "ErrorMailUser";
// log.config("Mail User = " + mailUser + "/" + mailPassword);
// Mail Address
String adminEMailString = p_panel.fAdminEMail.getText();
InternetAddress adminEMail = null;
try
{
adminEMail = new InternetAddress (adminEMailString);
}
catch (Exception e)
{
error = "Not valid: " + adminEMailString + " - " + e.getMessage();
pass = false;
}
//
if (pass)
{
error = "Not verified EMail = " + adminEMail;
pass = testMailServer(mailServer, adminEMail, mailUser, mailPassword);
}
p_panel.signalOK(p_panel.okMailUser, "ErrorMail",
pass, false, error);
if (pass)
{
log.info("OK: EMail = " + adminEMail);
p_properties.setProperty(COMPIERE_ADMIN_EMAIL, adminEMail.toString());
p_properties.setProperty(COMPIERE_MAIL_USER, mailUser);
p_properties.setProperty(COMPIERE_MAIL_PASSWORD, mailPassword);
p_properties.setProperty(COMPIERE_MAIL_UPDATED, "No");
}
else
{
log.warning(error);
p_properties.setProperty(COMPIERE_ADMIN_EMAIL, "");
p_properties.setProperty(COMPIERE_MAIL_USER, "");
p_properties.setProperty(COMPIERE_MAIL_PASSWORD, "");
p_properties.setProperty(COMPIERE_MAIL_UPDATED, "");
}
return null;
} // testMail
/**
* Test Mail
* @return true of OK
*/
private boolean testMailServer(InetAddress mailServer, InternetAddress adminEMail,
String mailUser, String mailPassword)
{
boolean smtpOK = false;
boolean imapOK = false;
if (testPort (mailServer, 25, true))
{
log.config("OK: SMTP Server contacted");
smtpOK = true;
}
else
log.info("SMTP Server NOT available");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -