diff --git a/install/src/org/compiere/install/Config.java b/install/src/org/compiere/install/Config.java index 5e3e44e1b9..34832782f0 100644 --- a/install/src/org/compiere/install/Config.java +++ b/install/src/org/compiere/install/Config.java @@ -98,6 +98,15 @@ public abstract class Config p_data.p_properties.setProperty(key, value); } // setProperty + /** + * Get Configuration Property + * @param key key + * @return value or "" + */ + protected String getProperty(String key) + { + return p_data.p_properties.getProperty(key, ""); + } // getProperty /** * UI Signal OK diff --git a/install/src/org/compiere/install/ConfigDB2.java b/install/src/org/compiere/install/ConfigDB2.java index c629908acc..954642e848 100644 --- a/install/src/org/compiere/install/ConfigDB2.java +++ b/install/src/org/compiere/install/ConfigDB2.java @@ -3,53 +3,53 @@ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.install; - -import java.io.*; -import java.net.*; -import java.sql.*; - -import org.compiere.db.*; -import org.compiere.util.*; - -import com.ibm.db2.jcc.*; - -/** - * DB/2 Configuration Test - * - * @author Jorg Janke - * @version $Id: ConfigDB2.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ - */ -public class ConfigDB2 extends Config -{ - /** - * ConfigOracle - * @param data configuration - */ - public ConfigDB2 (ConfigurationData data) - { - super (data); - } // ConfigOracle - - /** DB/2 Driver */ - private static DB2Driver s_db2Driver = null; - /** Last Connection */ - private Connection m_con = null; - - /** - * Init - */ + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.install; + +import java.io.*; +import java.net.*; +import java.sql.*; + +import org.compiere.db.*; +import org.compiere.util.*; + +import com.ibm.db2.jcc.*; + +/** + * DB/2 Configuration Test + * + * @author Jorg Janke + * @version $Id: ConfigDB2.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ + */ +public class ConfigDB2 extends Config +{ + /** + * ConfigOracle + * @param data configuration + */ + public ConfigDB2 (ConfigurationData data) + { + super (data); + } // ConfigOracle + + /** DB/2 Driver */ + private static DB2Driver s_db2Driver = null; + /** Last Connection */ + private Connection m_con = null; + + /** + * Init + */ public void init() { p_data.setDatabasePort(String.valueOf(DB_DB2.DEFAULT_PORT_0)); @@ -57,30 +57,30 @@ public class ConfigDB2 extends Config p_data.setDatabaseSystemPassword(true); } // init - - /************************************************************************** - * Test - * @return error message or null if OK - */ - public String test() - { - // Database Server - String server = p_data.getDatabaseServer(); - boolean pass = server != null && server.length() > 0 - && server.toLowerCase().indexOf("localhost") == -1 - && !server.equals("127.0.0.1"); - String error = "Not correct: DB Server = " + server; - InetAddress databaseServer = null; - try - { - if (pass) - databaseServer = InetAddress.getByName(server); - } - catch (Exception e) - { - error += " - " + e.getMessage(); - pass = false; - } + + /************************************************************************** + * Test + * @return error message or null if OK + */ + public String test() + { + // Database Server + String server = p_data.getDatabaseServer(); + boolean pass = server != null && server.length() > 0 + && server.toLowerCase().indexOf("localhost") == -1 + && !server.equals("127.0.0.1"); + String error = "Not correct: DB Server = " + server; + InetAddress databaseServer = null; + try + { + if (pass) + databaseServer = InetAddress.getByName(server); + } + catch (Exception e) + { + error += " - " + e.getMessage(); + pass = false; + } signalOK(getPanel().okDatabaseServer, "ErrorDatabaseServer", pass, true, error); log.info("OK: Database Server = " + databaseServer); @@ -89,10 +89,10 @@ public class ConfigDB2 extends Config // Database Port int databasePort = p_data.getDatabasePort(); - pass = p_data.testPort (databaseServer, databasePort, true); - error = "DB Server Port = " + databasePort; - signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort", - pass, true, error); + pass = p_data.testPort (databaseServer, databasePort, true); + error = "DB Server Port = " + databasePort; + signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort", + pass, true, error); if (!pass) return error; log.info("OK: Database Port = " + databasePort); @@ -100,24 +100,24 @@ public class ConfigDB2 extends Config // JDBC Database Info - String databaseName = p_data.getDatabaseName(); // Service Name - String systemPassword = p_data.getDatabaseSystemPassword(); - pass = systemPassword != null && systemPassword.length() > 0; - error = "No Database System Password entered"; - signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", - pass, true, error); - if (!pass) - return error; - // - // URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1 - String url = "jdbc:db2://" + databaseServer.getHostName() - + ":" + databasePort - + "/" + databaseName; - pass = testJDBC(url, "db2admin", systemPassword); - error = "Error connecting: " + url - + " - as db2admin/" + systemPassword; - signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", - pass, true, error); + String databaseName = p_data.getDatabaseName(); // Service Name + String systemPassword = p_data.getDatabaseSystemPassword(); + pass = systemPassword != null && systemPassword.length() > 0; + error = "No Database System Password entered"; + signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", + pass, true, error); + if (!pass) + return error; + // + // URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1 + String url = "jdbc:db2://" + databaseServer.getHostName() + + ":" + databasePort + + "/" + databaseName; + pass = testJDBC(url, "db2admin", systemPassword); + error = "Error connecting: " + url + + " - as db2admin/" + systemPassword; + signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", + pass, true, error); if (!pass) return error; log.info("OK: Connection = " + url); @@ -128,20 +128,20 @@ public class ConfigDB2 extends Config // Database User Info - String databaseUser = p_data.getDatabaseUser(); // UID - String databasePassword = p_data.getDatabasePassword(); // PWD - pass = databasePassword != null && databasePassword.length() > 0; - error = "Invalid Database User Password"; - signalOK(getPanel().okDatabaseUser, "ErrorJDBC", - pass, true, error); - if (!pass) - return error; - // Ignore result as it might not be imported - pass = testJDBC(url, databaseUser, databasePassword); - error = "Database imported? Cannot connect to User: " + databaseUser + "/" + databasePassword; - signalOK(getPanel().okDatabaseUser, "ErrorJDBC", - pass, false, error); - if (pass) + String databaseUser = p_data.getDatabaseUser(); // UID + String databasePassword = p_data.getDatabasePassword(); // PWD + pass = databasePassword != null && databasePassword.length() > 0; + error = "Invalid Database User Password"; + signalOK(getPanel().okDatabaseUser, "ErrorJDBC", + pass, true, error); + if (!pass) + return error; + // Ignore result as it might not be imported + pass = testJDBC(url, databaseUser, databasePassword); + error = "Database imported? Cannot connect to User: " + databaseUser + "/" + databasePassword; + signalOK(getPanel().okDatabaseUser, "ErrorJDBC", + pass, false, error); + if (pass) { log.info("OK: Database User = " + databaseUser); if (m_con != null) @@ -154,99 +154,99 @@ public class ConfigDB2 extends Config if (!p_data.getAppsServerType().equals(ConfigurationData.APPSTYPE_TOMCAT)) { - String cmd = "db2 "; - if (Env.isWindows()) - cmd = "db2cmd -c -w -i db2 "; - String sqlcmd1 = cmd + "connect to xx"; - String sqlcmd2 = cmd + "-f utils/db2/Test.sql"; - log.config(sqlcmd2); - pass = testSQL(sqlcmd2); - error = "Error connecting via: " + sqlcmd2; - signalOK(getPanel().okDatabaseSQL, "ErrorTNS", - pass, true, error); - if (pass) - log.info("OK: Database SQL Connection"); - } - - m_con = null; - return null; - } // test - - /** - * Test JDBC Connection to Server - * @param url connection string - * @param uid user id - * @param pwd password - * @return true if OK - */ - private boolean testJDBC (String url, String uid, String pwd) - { - log.fine("Url=" + url + ", UID=" + uid); - try - { - if (s_db2Driver == null) - { - s_db2Driver = new DB2Driver(); - DriverManager.registerDriver(s_db2Driver); - } - m_con = DriverManager.getConnection(url, uid, pwd); + String cmd = "db2 "; + if (Env.isWindows()) + cmd = "db2cmd -c -w -i db2 "; + String sqlcmd1 = cmd + "connect to xx"; + String sqlcmd2 = cmd + "-f utils/db2/Test.sql"; + log.config(sqlcmd2); + pass = testSQL(sqlcmd2); + error = "Error connecting via: " + sqlcmd2; + signalOK(getPanel().okDatabaseSQL, "ErrorTNS", + pass, true, error); + if (pass) + log.info("OK: Database SQL Connection"); + } + + m_con = null; + return null; + } // test + + /** + * Test JDBC Connection to Server + * @param url connection string + * @param uid user id + * @param pwd password + * @return true if OK + */ + private boolean testJDBC (String url, String uid, String pwd) + { + log.fine("Url=" + url + ", UID=" + uid); + try + { + if (s_db2Driver == null) + { + s_db2Driver = new DB2Driver(); + DriverManager.registerDriver(s_db2Driver); + } + m_con = DriverManager.getConnection(url, uid, pwd); } catch (Exception e) { - log.severe(e.toString()); + log.warning(e.toString()); return false; } return true; - } // testJDBC - - /** - * Test Command Line Connection - * @param sqlcmd sql command line - * @return true if OK - */ - private boolean testSQL (String sqlcmd) - { - if (true) - return true; - // - StringBuffer sbOut = new StringBuffer(); - StringBuffer sbErr = new StringBuffer(); - int result = -1; - try - { - Process p = Runtime.getRuntime().exec (sqlcmd); - InputStream in = p.getInputStream(); - int c; - while ((c = in.read()) != -1) - { - sbOut.append((char)c); - System.out.print((char)c); - } - in.close(); - in = p.getErrorStream(); - while ((c = in.read()) != -1) - sbErr.append((char)c); - in.close(); - // Get result - try - { - Thread.yield(); - result = p.exitValue(); - } - catch (Exception e) // Timing issue on Solaris. - { - Thread.sleep(200); // .2 sec - result = p.exitValue(); - } + } // testJDBC + + /** + * Test Command Line Connection + * @param sqlcmd sql command line + * @return true if OK + */ + private boolean testSQL (String sqlcmd) + { + if (true) + return true; + // + StringBuffer sbOut = new StringBuffer(); + StringBuffer sbErr = new StringBuffer(); + int result = -1; + try + { + Process p = Runtime.getRuntime().exec (sqlcmd); + InputStream in = p.getInputStream(); + int c; + while ((c = in.read()) != -1) + { + sbOut.append((char)c); + System.out.print((char)c); + } + in.close(); + in = p.getErrorStream(); + while ((c = in.read()) != -1) + sbErr.append((char)c); + in.close(); + // Get result + try + { + Thread.yield(); + result = p.exitValue(); + } + catch (Exception e) // Timing issue on Solaris. + { + Thread.sleep(200); // .2 sec + result = p.exitValue(); + } } catch (Exception ex) { - log.severe(ex.toString()); + log.warning(ex.toString()); } log.finer(sbOut.toString()); if (sbErr.length() > 0) - log.warning(sbErr.toString()); - return result == 0; - } // testSQL - -} // ConfigDB2 + log.warning(sbErr.toString()); + return result == 0; + } // testSQL + +} // ConfigDB2 diff --git a/install/src/org/compiere/install/ConfigOracle.java b/install/src/org/compiere/install/ConfigOracle.java index eb2c3765a0..8d408f0f9c 100644 --- a/install/src/org/compiere/install/ConfigOracle.java +++ b/install/src/org/compiere/install/ConfigOracle.java @@ -1,466 +1,416 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.install; - -import java.io.*; -import java.net.*; -import java.sql.*; -import java.util.*; -import java.util.regex.*; -import org.compiere.db.*; -import oracle.jdbc.*; - - -/** - * Oracle Confguration - * - * @author Jorg Janke - * @version $Id: ConfigOracle.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ - */ -public class ConfigOracle extends Config -{ - /** - * ConfigOracle - * @param data configuration - */ - public ConfigOracle (ConfigurationData data) - { - super (data); - } // ConfigOracle - - /** Oracle Driver */ - private static OracleDriver s_oracleDriver = null; - /** Discovered TNS */ - private String[] p_discovered = null; - /** Discovered Database Name */ - private String[] p_dbname = null; - /** Last Connection */ - private Connection m_con = null; - - /** - * Init - */ - public void init() - { - p_data.setDatabasePort(String.valueOf(DB_Oracle.DEFAULT_PORT)); - // - p_data.setDatabaseSystemPassword(true); - } // init - - /** - * Discover Databases. - * To be overwritten by database configs - * @param selected selected database - * @return array of databases - */ - public String[] discoverDatabases(String selected) - { - if (p_discovered != null) - return p_discovered; - // - ArrayList list = new ArrayList(); - ArrayList dblist = new ArrayList(); - // default value to lowercase or null - String def = selected; - if (def != null && def.trim().length() == 0) - def = null; - if (def != null) { - list.add(def.toLowerCase()); - dblist.add(def.toLowerCase()); - } - - String path = System.getenv("ORACLE_HOME"); - if (path == null) - { - // Search for Oracle Info - path = System.getProperty("java.library.path"); - String[] entries = path.split(File.pathSeparator); - for (int e = 0; e < entries.length; e++) - { - String entry = entries[e].toLowerCase(); - if (entry.indexOf("ora") != -1 && entry.endsWith("bin")) - { - StringBuffer sb = getTNS_File (entries[e].substring(0, entries[e].length()-4)); - String[] tnsnames = getTNS_Names (sb, true); - String[] dbNames = getTNS_Names (sb, false); - if (tnsnames != null) - { - for (int i = 0; i < tnsnames.length; i++) - { - String tns = tnsnames[i]; // is lower case - String db = dbNames[i]; - if (!tns.equals(def)) { - list.add(tns); - dblist.add(db); - } else { - dblist.remove(0); - dblist.add(0, db); - } - } - break; - } - } - } // for all path entries - } - else - { - StringBuffer sb = getTNS_File (path); - String[] tnsnames = getTNS_Names (sb, true); - String[] dbNames = getTNS_Names (sb, false); - if (tnsnames != null) - { - for (int i = 0; i < tnsnames.length; i++) - { - String tns = tnsnames[i]; // is lower case - String db = dbNames[i]; - if (!tns.equals(def)) { - list.add(tns); - dblist.add(db); - } else { - dblist.remove(0); - dblist.add(0, db); - } - } - } - } - - p_discovered = new String[list.size()]; - list.toArray(p_discovered); - p_dbname = new String[dblist.size()]; - dblist.toArray(p_dbname); - return p_discovered; - } // discoverDatabases - - - @Override - public String getDatabaseName(String nativeConnectioName) - { - int idx = -1; - if (p_discovered == null) return nativeConnectioName; - for (int i = 0; i < p_discovered.length; i++) - { - if (p_discovered[i].equals(nativeConnectioName)) - { - idx = i; - break; - } - } - if (idx >= 0 - && p_dbname != null - && idx < p_dbname.length) - return p_dbname[idx]; - else - return nativeConnectioName; - } - - /** - * Get File tnmsnames.ora in StringBuffer - * @param oraHome ORACLE_HOME - * @return tnsnames.ora or null - */ - private StringBuffer getTNS_File (String oraHome) - { - String tnsnames = oraHome + File.separator - + "network" + File.separator - + "admin" + File.separator - + "tnsnames.ora"; - File tnsfile = new File (tnsnames); - if (!tnsfile.exists()) - return null; - - log.fine(tnsnames); - StringBuffer sb = new StringBuffer(); - try - { - FileReader fr = new FileReader (tnsfile); - int c; - while ((c = fr.read()) != -1) - sb.append((char)c); - } - catch (IOException ex) - { - log.severe("Error Reading " + tnsnames); - ex.printStackTrace(); - return null; - } - if (sb.length() == 0) - return null; - return sb; - } // getTNS_File - - /** - * Get TNS Names entries. - * Assumes standard tnsmanes.ora formatting of NetMgr - * @param tnsnames content of tnsnames.ora - * @return tns names or null - */ - private String[] getTNS_Names (StringBuffer tnsnames, boolean tns) - { - if (tnsnames == null) - return null; - - ArrayList list = new ArrayList(); - Pattern pattern = Pattern.compile("$", Pattern.MULTILINE); - String[] lines = pattern.split(tnsnames); - for (int i = 0; i < lines.length; i++) - { - String line = lines[i].trim(); - log.finest(i + ": " + line); - if (tns) // get TNS Name - { - if (line.length() > 0 - && Character.isLetter(line.charAt(0)) // no # ( - && line.indexOf("=") != -1 - && line.indexOf("EXTPROC_") == -1 - && line.indexOf("_HTTP") == -1) - { - String entry = line.substring(0, line.indexOf('=')).trim().toLowerCase(); - log.fine(entry); - list.add(entry); - } - } - else // search service names - { - if (line.length() > 0 - && line.toUpperCase().indexOf("SERVICE_NAME") != -1) - { - String entry = line.substring(line.indexOf('=')+1).trim().toLowerCase(); - int index = entry.indexOf(')'); - if (index != 0) - entry = entry.substring(0, index).trim(); - log.fine(entry); - list.add(entry); - } - - } - } - // Convert to Array - if (list.size() == 0) - return null; - String[] retValue = new String[list.size()]; - list.toArray(retValue); - return retValue; - } // getTNS_Names - - - /************************************************************************** - * Test - * @return error message or null if OK - */ - public String test() - { - // Database Server - String server = p_data.getDatabaseServer(); - boolean pass = server != null && server.length() > 0 - && server.toLowerCase().indexOf("localhost") == -1 - && !server.equals("127.0.0.1"); - String error = "Not correct: DB Server = " + server; - InetAddress databaseServer = null; - try - { - if (pass) - databaseServer = InetAddress.getByName(server); - } - catch (Exception e) - { - error += " - " + e.getMessage(); - pass = false; - } - signalOK(getPanel().okDatabaseServer, "ErrorDatabaseServer", - pass, true, error); - log.info("OK: Database Server = " + databaseServer); - setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer.getHostName()); - setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, p_data.getDatabaseType()); - - // Database Port - int databasePort = p_data.getDatabasePort(); - pass = p_data.testPort (databaseServer, databasePort, true); - error = "DB Server Port = " + databasePort; - signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort", - pass, true, error); - if (!pass) - return error; - log.info("OK: Database Port = " + databasePort); - setProperty(ConfigurationData.ADEMPIERE_DB_PORT, String.valueOf(databasePort)); - - - // JDBC Database Info - String databaseName = p_data.getDatabaseName(); // Service Name - String systemPassword = p_data.getDatabaseSystemPassword(); - pass = systemPassword != null && systemPassword.length() > 0; - error = "No Database System Password entered"; - signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", - pass, true, error); - if (!pass) - return error; - // - // URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1 - String url = "jdbc:oracle:thin:@//" + databaseServer.getHostName() - + ":" + databasePort - + "/" + databaseName; - pass = testJDBC(url, "system", systemPassword); - error = "Error connecting: " + url - + " - as system/" + systemPassword; - signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", - pass, true, error); - if (!pass) - return error; - log.info("OK: Connection = " + url); - setProperty(ConfigurationData.ADEMPIERE_DB_URL, url); - log.info("OK: Database System User " + databaseName); - setProperty(ConfigurationData.ADEMPIERE_DB_NAME, databaseName); - setProperty(ConfigurationData.ADEMPIERE_DB_SYSTEM, systemPassword); - - - // Database User Info - String databaseUser = p_data.getDatabaseUser(); // UID - String databasePassword = p_data.getDatabasePassword(); // PWD - pass = databasePassword != null && databasePassword.length() > 0; - error = "Invalid Database User Password"; - signalOK(getPanel().okDatabaseUser, "ErrorJDBC", - pass, true, error); - if (!pass) - return error; - // Ignore result as it might not be imported - pass = testJDBC(url, databaseUser, databasePassword); - error = "Database imported? Cannot connect to User: " + databaseUser + "/" + databasePassword; - signalOK(getPanel().okDatabaseUser, "ErrorJDBC", - pass, false, error); - if (pass) - { - log.info("OK: Database User = " + databaseUser); - if (m_con != null) - setProperty(ConfigurationData.ADEMPIERE_WEBSTORES, getWebStores(m_con)); - } - else - log.warning(error); - setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser); - setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword); - - // TNS Name Info via sqlplus - if not tomcat - if (!p_data.getAppsServerType().equals(ConfigurationData.APPSTYPE_TOMCAT)) - { - String sqlplus = "sqlplus system/" + systemPassword + "@" - + databaseServer.getHostName() + "/" + databaseName - + " @utils/oracle/Test.sql"; - log.config(sqlplus); - pass = testSQL(sqlplus); - error = "Error connecting via: " + sqlplus; - signalOK(getPanel().okDatabaseSQL, "ErrorTNS", - pass, true, error); - if (pass) - log.info("OK: Database SQL Connection"); - } - - // OCI Test - if (System.getProperty("TestOCI", "N").equals("Y")) - { - url = "jdbc:oracle:oci8:@" + databaseName; - pass = testJDBC(url, "system", systemPassword); - if (pass) - log.info("OK: Connection = " + url); - else - log.warning("Cannot connect via Net8: " + url); - } - log.info("OCI Test Skipped"); - - // - m_con = null; - return null; - } // test - - - /** - * Test JDBC Connection to Server - * @param url connection string - * @param uid user id - * @param pwd password - * @return true if OK - */ - private boolean testJDBC (String url, String uid, String pwd) - { - log.fine("Url=" + url + ", UID=" + uid); - try - { - if (s_oracleDriver == null) - { - s_oracleDriver = new OracleDriver(); - DriverManager.registerDriver(s_oracleDriver); - } - m_con = DriverManager.getConnection(url, uid, pwd); - } - catch (UnsatisfiedLinkError ule) - { - log.warning("Check [ORACLE_HOME]/jdbc/Readme.txt for (OCI) driver setup"); - log.warning(ule.toString()); - } - catch (Exception e) - { - log.severe(e.toString()); - return false; - } - return true; - } // testJDBC - - /** - * Test TNS Connection - * @param sqlplus sqlplus command line - * @return true if OK - */ - private boolean testSQL (String sqlplus) - { - StringBuffer sbOut = new StringBuffer(); - StringBuffer sbErr = new StringBuffer(); - int result = -1; - try - { - Process p = Runtime.getRuntime().exec (sqlplus); - InputStream in = p.getInputStream(); - int c; - while ((c = in.read()) != -1) - { - sbOut.append((char)c); - System.out.print((char)c); - } - in.close(); - in = p.getErrorStream(); - while ((c = in.read()) != -1) - sbErr.append((char)c); - in.close(); - // Get result - try - { - Thread.yield(); - result = p.exitValue(); - } - catch (Exception e) // Timing issue on Solaris. - { - Thread.sleep(200); // .2 sec - result = p.exitValue(); - } - } - catch (Exception ex) - { - log.severe(ex.toString()); - } - log.finer(sbOut.toString()); - if (sbErr.length() > 0) - log.warning(sbErr.toString()); - return result == 0; - } // testSQL - -} // ConfigOracle +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.install; + +import java.io.*; +import java.net.*; +import java.sql.*; +import java.util.*; +import java.util.regex.*; +import org.compiere.db.*; +import oracle.jdbc.*; + + +/** + * Oracle Confguration + * + * @author Jorg Janke + * @version $Id: ConfigOracle.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ + */ +public class ConfigOracle extends Config +{ + /** + * ConfigOracle + * @param data configuration + * @param XE express edition + */ + public ConfigOracle (ConfigurationData data, boolean XE) + { + super (data); + m_XE = XE; + } // ConfigOracle + + /** Oracle Driver */ + private static OracleDriver s_oracleDriver = null; + /** Discoverd TNS */ + private String[] p_discovered = null; + /** Last Connection */ + private Connection m_con = null; + /** Express Edition */ + private boolean m_XE = false; + + /** + * Init + */ + public void init() + { + p_data.setDatabasePort(String.valueOf(DB_Oracle.DEFAULT_PORT)); + // + p_data.setDatabaseSystemPassword(true); + } // init + + /** + * Discover Databases. + * To be overwritten by database configs + * @param selected selected database + * @return array of databases + */ + public String[] discoverDatabases(String selected) + { + if (p_discovered != null) + return p_discovered; + // + ArrayList list = new ArrayList(); + // default value to lowercase or null + String def = selected; + if (def != null && def.trim().length() == 0) + def = null; + if (def != null) + list.add(def.toLowerCase()); + + if (m_XE) + { + String serviceName = "xe"; + if (!list.contains(serviceName)) + list.add(serviceName); + } + // Search for Oracle Info + String path = System.getProperty("java.library.path"); + String[] entries = path.split(File.pathSeparator); + for (int e = 0; e < entries.length; e++) + { + String entry = entries[e].toLowerCase(); + if (entry.indexOf("ora") != -1 && entry.endsWith("bin")) + { + StringBuffer sb = getTNS_File (entries[e].substring(0, entries[e].length()-4)); + String[] serviceNames = getTNS_Names (sb); + if (serviceNames != null) + { + for (int i = 0; i < serviceNames.length; i++) + { + String serviceName = serviceNames[i].toLowerCase(); + if (!list.contains(serviceName)) + list.add(serviceName); + } + break; + } + } + } // for all path entries + + p_discovered = new String[list.size()]; + list.toArray(p_discovered); + return p_discovered; + } // discoverDatabases + + /** + * Get File tnmsnames.ora in StringBuffer + * @param oraHome ORACLE_HOME + * @return tnsnames.ora or null + */ + private StringBuffer getTNS_File (String oraHome) + { + String tnsnames = oraHome + File.separator + + "network" + File.separator + + "admin" + File.separator + + "tnsnames.ora"; + File tnsfile = new File (tnsnames); + if (!tnsfile.exists()) + return null; + + log.fine(tnsnames); + StringBuffer sb = new StringBuffer(); + try + { + FileReader fr = new FileReader (tnsfile); + int c; + while ((c = fr.read()) != -1) + sb.append((char)c); + } + catch (IOException ex) + { + log.warning("Error Reading " + tnsnames); + ex.printStackTrace(); + return null; + } + if (sb.length() == 0) + return null; + return sb; + } // getTNS_File + + /** + * Get TNS Names entries. + * Assumes standard tnsmanes.ora formatting of NetMgr + * @param tnsnames content of tnsnames.ora + * @return service names or null + */ + private String[] getTNS_Names (StringBuffer tnsnames) + { + if (tnsnames == null) + return null; + + ArrayList list = new ArrayList(); + Pattern pattern = Pattern.compile("$", Pattern.MULTILINE); + String[] lines = pattern.split(tnsnames); + for (int i = 0; i < lines.length; i++) + { + String line = lines[i].trim(); + log.finest(i + ": " + line); + if (false) // get TNS Name + { + if (line.length() > 0 + && Character.isLetter(line.charAt(0)) // no # ( + && line.indexOf("=") != -1 + && line.indexOf("EXTPROC_") == -1 + && line.indexOf("_HTTP") == -1) + { + String entry = line.substring(0, line.indexOf('=')).trim().toLowerCase(); + log.fine(entry); + list.add(entry); + } + } + else // search service names + { + if (line.length() > 0 + && line.toUpperCase().indexOf("SERVICE_NAME") != -1) + { + String entry = line.substring(line.indexOf('=')+1).trim().toLowerCase(); + int index = entry.indexOf(')'); + if (index != 0) + entry = entry.substring(0, index).trim(); + log.fine(entry); + list.add(entry); + } + + } + } + // Convert to Array + if (list.size() == 0) + return null; + String[] retValue = new String[list.size()]; + list.toArray(retValue); + return retValue; + } // getTNS_Names + + + /************************************************************************** + * Test + * @return error message or null if OK + */ + public String test() + { + // Database Server + String server = p_data.getDatabaseServer(); + boolean pass = server != null && server.length() > 0 + && server.toLowerCase().indexOf("localhost") == -1 + && !server.equals("127.0.0.1"); + String error = "Not correct: DB Server = " + server; + InetAddress databaseServer = null; + try + { + if (pass) + databaseServer = InetAddress.getByName(server); + } + catch (Exception e) + { + error += " - " + e.getMessage(); + pass = false; + } + signalOK(getPanel().okDatabaseServer, "ErrorDatabaseServer", + pass, true, error); + log.info("OK: Database Server = " + databaseServer); + setProperty(ConfigurationData.ADEMPIERE_DB_SERVER, databaseServer.getHostName()); + setProperty(ConfigurationData.ADEMPIERE_DB_TYPE, p_data.getDatabaseType()); + setProperty(ConfigurationData.ADEMPIERE_DB_PATH, "oracle"); + + // Database Port + int databasePort = p_data.getDatabasePort(); + pass = p_data.testPort (databaseServer, databasePort, true); + error = "DB Server Port = " + databasePort; + signalOK(getPanel().okDatabaseServer, "ErrorDatabasePort", + pass, true, error); + if (!pass) + return error; + log.info("OK: Database Port = " + databasePort); + setProperty(ConfigurationData.ADEMPIERE_DB_PORT, String.valueOf(databasePort)); + + + // JDBC Database Info + String databaseName = p_data.getDatabaseName(); // Service Name + String systemPassword = p_data.getDatabaseSystemPassword(); + pass = systemPassword != null && systemPassword.length() > 0; + error = "No Database System Password entered"; + signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", + pass, true, error); + if (!pass) + return error; + // + // URL (derived) jdbc:oracle:thin:@//prod1:1521/prod1 + String url = "jdbc:oracle:thin:@//" + databaseServer.getHostName() + + ":" + databasePort + + "/" + databaseName; + pass = testJDBC(url, "system", systemPassword); + error = "Error connecting: " + url + + " - as system/" + systemPassword; + signalOK(getPanel().okDatabaseSystem, "ErrorJDBC", + pass, true, error); + if (!pass) + return error; + log.info("OK: Connection = " + url); + setProperty(ConfigurationData.ADEMPIERE_DB_URL, url); + log.info("OK: Database System User " + databaseName); + setProperty(ConfigurationData.ADEMPIERE_DB_NAME, databaseName); + setProperty(ConfigurationData.ADEMPIERE_DB_SYSTEM, systemPassword); + + + // Database User Info + String databaseUser = p_data.getDatabaseUser(); // UID + String databasePassword = p_data.getDatabasePassword(); // PWD + pass = databasePassword != null && databasePassword.length() > 0; + error = "Invalid Database User Password"; + signalOK(getPanel().okDatabaseUser, "ErrorJDBC", + pass, true, error); + if (!pass) + return error; + // Ignore result as it might not be imported + pass = testJDBC(url, databaseUser, databasePassword); + error = "Cannot connect to User: " + databaseUser + "/" + databasePassword + " - Database may not be imported yet (OK on initial run)."; + signalOK(getPanel().okDatabaseUser, "ErrorJDBC", + pass, false, error); + if (pass) + { + log.info("OK: Database User = " + databaseUser); + if (m_con != null) + setProperty(ConfigurationData.ADEMPIERE_WEBSTORES, getWebStores(m_con)); + } + else + log.warning(error); + setProperty(ConfigurationData.ADEMPIERE_DB_USER, databaseUser); + setProperty(ConfigurationData.ADEMPIERE_DB_PASSWORD, databasePassword); + + // TNS Name Info via sqlplus - if not tomcat + if (!p_data.getAppsServerType().equals(ConfigurationData.APPSTYPE_TOMCAT)) + { + String sqlplus = "sqlplus system/" + systemPassword + "@" + databaseName + + " @" + getProperty(ConfigurationData.ADEMPIERE_HOME) + + "/utils/oracle/Test.sql"; + log.config(sqlplus); + pass = testSQL(sqlplus); + error = "Error connecting via: " + sqlplus; + signalOK(getPanel().okDatabaseSQL, "ErrorTNS", + pass, true, error); + if (pass) + log.info("OK: Database SQL Connection"); + } + + // OCI Test + if (System.getProperty("TestOCI", "N").equals("Y")) + { + url = "jdbc:oracle:oci8:@" + databaseName; + pass = testJDBC(url, "system", systemPassword); + if (pass) + log.info("OK: Connection = " + url); + else + log.warning("Cannot connect via Net8: " + url); + } + log.info("OCI Test Skipped"); + + // + m_con = null; + return null; + } // test + + + /** + * Test JDBC Connection to Server + * @param url connection string + * @param uid user id + * @param pwd password + * @return true if OK + */ + private boolean testJDBC (String url, String uid, String pwd) + { + log.fine("Url=" + url + ", UID=" + uid); + try + { + if (s_oracleDriver == null) + { + s_oracleDriver = new OracleDriver(); + DriverManager.registerDriver(s_oracleDriver); + } + m_con = DriverManager.getConnection(url, uid, pwd); + } + catch (UnsatisfiedLinkError ule) + { + log.warning("Check [ORACLE_HOME]/jdbc/Readme.txt for (OCI) driver setup"); + log.warning(ule.toString()); + } + catch (Exception e) + { + log.warning(e.toString()); + return false; + } + return true; + } // testJDBC + + /** + * Test TNS Connection + * @param sqlplus sqlplus command line + * @return true if OK + */ + private boolean testSQL (String sqlplus) + { + StringBuffer sbOut = new StringBuffer(); + StringBuffer sbErr = new StringBuffer(); + int result = -1; + try + { + Process p = Runtime.getRuntime().exec (sqlplus); + InputStream in = p.getInputStream(); + int c; + while ((c = in.read()) != -1) + { + sbOut.append((char)c); + System.out.print((char)c); + } + in.close(); + in = p.getErrorStream(); + while ((c = in.read()) != -1) + sbErr.append((char)c); + in.close(); + // Get result + try + { + Thread.yield(); + result = p.exitValue(); + } + catch (Exception e) // Timing issue on Solaris. + { + Thread.sleep(200); // .2 sec + result = p.exitValue(); + } + } + catch (Exception ex) + { + log.warning(ex.toString()); + } + log.finer(sbOut.toString()); + if (sbErr.length() > 0) + log.warning(sbErr.toString()); + return result == 0; + } // testSQL + +} // ConfigOracle diff --git a/install/src/org/compiere/install/ConfigurationData.java b/install/src/org/compiere/install/ConfigurationData.java index 5751b16bd9..8320240efb 100644 --- a/install/src/org/compiere/install/ConfigurationData.java +++ b/install/src/org/compiere/install/ConfigurationData.java @@ -1,1366 +1,1361 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -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.4 2006/07/30 00:57:42 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(); - /** Adempiere Home */ - private File m_adempiereHome; - - - /** Static Logger */ - static CLogger log = CLogger.getCLogger (ConfigurationData.class); - - - /** Properties File name */ - public static final String ADEMPIERE_ENV_FILE = "AdempiereEnv.properties"; - - /** Adempiere Home */ - public static final String ADEMPIERE_HOME = "ADEMPIERE_HOME"; - /** */ - public static final String JAVA_HOME = "JAVA_HOME"; - /** */ - public static final String JAVA_TYPE = "ADEMPIERE_JAVA_TYPE"; - /** */ - public static final String ADEMPIERE_JAVA_OPTIONS = "ADEMPIERE_JAVA_OPTIONS"; - /** Default Keysore Password */ - public static final String KEYSTORE_PASSWORD = "myPassword"; - - /** */ - public static final String ADEMPIERE_APPS_TYPE = "ADEMPIERE_APPS_TYPE"; - /** */ - public static final String ADEMPIERE_APPS_SERVER = "ADEMPIERE_APPS_SERVER"; - /** */ - public static final String ADEMPIERE_APPS_DEPLOY = "ADEMPIERE_APPS_DEPLOY"; - /** */ - public static final String ADEMPIERE_JNP_PORT = "ADEMPIERE_JNP_PORT"; - /** */ - public static final String ADEMPIERE_WEB_PORT = "ADEMPIERE_WEB_PORT"; - /** */ - public static final String ADEMPIERE_SSL_PORT = "ADEMPIERE_SSL_PORT"; - /** */ - public static final String ADEMPIERE_WEB_ALIAS = "ADEMPIERE_WEB_ALIAS"; - - /** */ - public static final String ADEMPIERE_KEYSTORE = "ADEMPIERE_KEYSTORE"; - /** */ - public static final String ADEMPIERE_KEYSTOREPASS = "ADEMPIERE_KEYSTOREPASS"; - /** */ - public static final String ADEMPIERE_KEYSTORECODEALIAS = "ADEMPIERE_KEYSTORECODEALIAS"; - /** */ - public static final String ADEMPIERE_KEYSTOREWEBALIAS = "ADEMPIERE_KEYSTOREWEBALIAS"; - - /** */ - public static final String ADEMPIERE_DB_TYPE = "ADEMPIERE_DB_TYPE"; - /** */ - public static final String ADEMPIERE_DB_SERVER = "ADEMPIERE_DB_SERVER"; - /** */ - public static final String ADEMPIERE_DB_PORT = "ADEMPIERE_DB_PORT"; - /** */ - public static final String ADEMPIERE_DB_NAME = "ADEMPIERE_DB_NAME"; - /** */ - public static final String ADEMPIERE_DB_URL = "ADEMPIERE_DB_URL"; - - /** */ - public static final String ADEMPIERE_DB_USER = "ADEMPIERE_DB_USER"; - /** */ - public static final String ADEMPIERE_DB_PASSWORD = "ADEMPIERE_DB_PASSWORD"; - /** */ - public static final String ADEMPIERE_DB_SYSTEM = "ADEMPIERE_DB_SYSTEM"; - - /** */ - public static final String ADEMPIERE_MAIL_SERVER = "ADEMPIERE_MAIL_SERVER"; - /** */ - public static final String ADEMPIERE_MAIL_USER = "ADEMPIERE_MAIL_USER"; - /** */ - public static final String ADEMPIERE_MAIL_PASSWORD = "ADEMPIERE_MAIL_PASSWORD"; - /** */ - public static final String ADEMPIERE_ADMIN_EMAIL = "ADEMPIERE_ADMIN_EMAIL"; - /** */ - public static final String ADEMPIERE_MAIL_UPDATED = "ADEMPIERE_MAIL_UPDATED"; - - /** */ - public static final String ADEMPIERE_FTP_SERVER = "ADEMPIERE_FTP_SERVER"; - /** */ - public static final String ADEMPIERE_FTP_USER = "ADEMPIERE_FTP_USER"; - /** */ - public static final String ADEMPIERE_FTP_PASSWORD = "ADEMPIERE_FTP_PASSWORD"; - /** */ - public static final String ADEMPIERE_FTP_PREFIX = "ADEMPIERE_FTP_PREFIX"; - - /** */ - public static final String ADEMPIERE_WEBSTORES = "ADEMPIERE_WEBSTORES"; - - - - /** - * Load Configuration Data - * @return true if loaded - */ - public boolean load() - { - // Load C:\Adempiere\AdempiereEnv.properties - String adempiereHome = System.getProperty(ADEMPIERE_HOME); - if (adempiereHome == null || adempiereHome.length() == 0) - adempiereHome = System.getProperty("user.dir"); - - boolean envLoaded = false; - String fileName = adempiereHome + File.separator + ADEMPIERE_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)); - // - setAdempiereHome((String)p_properties.get(ADEMPIERE_HOME)); - String s = (String)p_properties.get(ADEMPIERE_KEYSTOREPASS); - if (s == null || s.length() == 0) - s = KEYSTORE_PASSWORD; - setKeyStore(s); - // - setAppsServerType((String)p_properties.get(ADEMPIERE_APPS_TYPE)); - initAppsServer(); - setAppsServer((String)p_properties.get(ADEMPIERE_APPS_SERVER)); - setAppsServerDeployDir((String)p_properties.get(ADEMPIERE_APPS_DEPLOY)); - setAppsServerJNPPort((String)p_properties.get(ADEMPIERE_JNP_PORT)); - setAppsServerWebPort((String)p_properties.get(ADEMPIERE_WEB_PORT)); - setAppsServerSSLPort((String)p_properties.get(ADEMPIERE_SSL_PORT)); - // - setDatabaseType((String)p_properties.get(ADEMPIERE_DB_TYPE)); - initDatabase((String)p_properties.get(ADEMPIERE_DB_NAME)); // fills Database Options - setDatabaseDiscovered((String)p_properties.get(ADEMPIERE_DB_NAME)); - setDatabaseServer((String)p_properties.get(ADEMPIERE_DB_SERVER)); - setDatabasePort((String)p_properties.get(ADEMPIERE_DB_PORT)); - setDatabaseName((String)p_properties.get(ADEMPIERE_DB_NAME)); - - setDatabaseUser((String)p_properties.get(ADEMPIERE_DB_USER)); - setDatabasePassword((String)p_properties.get(ADEMPIERE_DB_PASSWORD)); - setDatabaseSystemPassword((String)p_properties.get(ADEMPIERE_DB_SYSTEM)); - - p_panel.fMailServer.setText((String)p_properties.get(ADEMPIERE_MAIL_SERVER)); - p_panel.fMailUser.setText((String)p_properties.get(ADEMPIERE_MAIL_USER)); - p_panel.fMailPassword.setText((String)p_properties.get(ADEMPIERE_MAIL_PASSWORD)); - p_panel.fAdminEMail.setText((String)p_properties.get(ADEMPIERE_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(); - // - setAdempiereHome(adempiereHome); - setKeyStore(KEYSTORE_PASSWORD); - // AppsServer - initAppsServer(); - setAppsServer(hostName); - // Database Server - initDatabase(""); - String connectionName = getDatabaseDiscovered(); - if (connectionName != null) { - setDatabaseName(resolveDatabaseName(connectionName)); - } - setDatabaseSystemPassword(""); - setDatabaseServer(hostName); - setDatabaseUser("adempiere"); - setDatabasePassword("adempiere"); - // 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(ADEMPIERE_FTP_SERVER)) - { - p_properties.setProperty(ADEMPIERE_FTP_SERVER, "localhost"); - p_properties.setProperty(ADEMPIERE_FTP_USER, "anonymous"); - p_properties.setProperty(ADEMPIERE_FTP_PASSWORD, "user@host.com"); - p_properties.setProperty(ADEMPIERE_FTP_PREFIX, "my"); - } - // Default Java Options - if (!p_properties.containsKey(ADEMPIERE_JAVA_OPTIONS)) - p_properties.setProperty(ADEMPIERE_JAVA_OPTIONS, "-Xms64M -Xmx512M"); - // Web Alias - if (!p_properties.containsKey(ADEMPIERE_WEB_ALIAS) && localhost != null) - p_properties.setProperty(ADEMPIERE_WEB_ALIAS, localhost.getCanonicalHostName()); - - // (String)p_properties.get(ADEMPIERE_DB_URL) // derived - - // Keystore Alias - if (!p_properties.containsKey(ADEMPIERE_KEYSTORECODEALIAS)) - p_properties.setProperty(ADEMPIERE_KEYSTORECODEALIAS, "adempiere"); - if (!p_properties.containsKey(ADEMPIERE_KEYSTOREWEBALIAS)) - p_properties.setProperty(ADEMPIERE_KEYSTOREWEBALIAS, "adempiere"); - - return true; - } // load - - - public String resolveDatabaseName(String connectionName) { - int index = p_panel.fDatabaseType.getSelectedIndex(); - if (index < 0 || index >= DBTYPE.length) - log.warning("DatabaseType Index invalid: " + index); - else if (m_databaseConfig[index] == null) - log.warning("DatabaseType Config missing: " + DBTYPE[index]); - else - return m_databaseConfig[index].getDatabaseName(connectionName); - return connectionName; - } - - - /************************************************************************** - * test - * @return true if test ok - */ - public boolean test() - { - String error = testJava(); - if (error != null) - { - log.severe(error); - return false; - } - - error = testAdempiere(); - 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 Adempiere and set AdempiereHome - * @return error message or null if OK - */ - private String testAdempiere() - { - // Adempiere Home - m_adempiereHome = new File (getAdempiereHome()); - boolean pass =m_adempiereHome.exists(); - String error = "Not found: AdempiereHome = " + m_adempiereHome; - p_panel.signalOK(p_panel.okAdempiereHome, "ErrorAdempiereHome", - pass, true, error); - if (!pass) - return error; - log.info("OK: AdempiereHome = " + m_adempiereHome); - p_properties.setProperty(ADEMPIERE_HOME, m_adempiereHome.getAbsolutePath()); - System.setProperty(ADEMPIERE_HOME, m_adempiereHome.getAbsolutePath()); - - // KeyStore - String fileName = KeyStoreMgt.getKeystoreFileName(m_adempiereHome.getAbsolutePath()); - p_properties.setProperty(ADEMPIERE_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(ADEMPIERE_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; - } // testAdempiere - - - /************************************************************************** - * 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(ADEMPIERE_MAIL_SERVER, ""); - return error; - } - p_properties.setProperty(ADEMPIERE_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(ADEMPIERE_ADMIN_EMAIL, adminEMail.toString()); - p_properties.setProperty(ADEMPIERE_MAIL_USER, mailUser); - p_properties.setProperty(ADEMPIERE_MAIL_PASSWORD, mailPassword); - p_properties.setProperty(ADEMPIERE_MAIL_UPDATED, "No"); - } - else - { - log.warning(error); - p_properties.setProperty(ADEMPIERE_ADMIN_EMAIL, ""); - p_properties.setProperty(ADEMPIERE_MAIL_USER, ""); - p_properties.setProperty(ADEMPIERE_MAIL_PASSWORD, ""); - p_properties.setProperty(ADEMPIERE_MAIL_UPDATED, ""); - } - return null; - } // testMail - - /** - * Test Mail - * @param mailServer mail server - * @param adminEMail email of admin - * @param mailUser user ID - * @param mailPassword password - * @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"); - // - if (testPort (mailServer, 110, true)) - log.config("OK: POP3 Server contacted"); - else - log.info("POP3 Server NOT available"); - if (testPort (mailServer, 143, true)) - { - log.config("OK: IMAP4 Server contacted"); - imapOK = true; - } - else - log.info("IMAP4 Server NOT available"); - // - if (!smtpOK) - { - String error = "No active Mail Server"; - p_panel.signalOK (p_panel.okMailServer, "ErrorMailServer", - false, false, error); - log.warning(error); - return false; - } - // - try - { - EMail email = new EMail (new Properties(), - mailServer.getHostName (), - adminEMail.toString (), adminEMail.toString(), - "Adempiere Server Setup Test", - "Test: " + getProperties()); - email.createAuthenticator (mailUser, mailPassword); - if (EMail.SENT_OK.equals (email.send ())) - { - log.info("OK: Send Test Email to " + adminEMail); - } - else - { - log.warning("Could NOT send Email to " + adminEMail); - } - } - catch (Exception ex) - { - log.severe(ex.getLocalizedMessage()); - return false; - } - - // - if (!imapOK) - return false; - - // Test Read Mail Access - Properties props = new Properties(); - props.put("mail.store.protocol", "smtp"); - props.put("mail.transport.protocol", "smtp"); - props.put("mail.host", mailServer.getHostName()); - props.put("mail.user", mailUser); - props.put("mail.smtp.auth", "true"); - log.config("Connecting to " + mailServer.getHostName()); - // - Session session = null; - Store store = null; - try - { - EMailAuthenticator auth = new EMailAuthenticator (mailUser, mailPassword); - session = Session.getDefaultInstance(props, auth); - session.setDebug (CLogMgt.isLevelFinest()); - log.config("Session=" + session); - // Connect to Store - store = session.getStore("imap"); - log.config("Store=" + store); - } - catch (NoSuchProviderException nsp) - { - log.warning("Mail IMAP Provider - " + nsp.getMessage()); - return false; - } - catch (Exception e) - { - log.warning("Mail IMAP - " + e.getMessage()); - return false; - } - try - { - store.connect(mailServer.getHostName(), mailUser, mailPassword); - log.config("Store - connected"); - Folder folder = store.getDefaultFolder(); - Folder inbox = folder.getFolder("INBOX"); - log.info("OK: Mail Connect to " + inbox.getFullName() + " #Msg=" + inbox.getMessageCount()); - // - store.close(); - } - catch (MessagingException mex) - { - log.severe("Mail Connect " + mex.getMessage()); - return false; - } - return true; - } // testMailServer - - - /************************************************************************** - * Test Apps Server Port (client perspective) - * @param protocol protocol (http, ..) - * @param server server name - * @param port port - * @param file file name - * @return true if able to connect - */ - protected boolean testPort (String protocol, String server, int port, String file) - { - URL url = null; - try - { - url = new URL (protocol, server, port, file); - } - catch (MalformedURLException ex) - { - log.severe("No URL for Protocol=" + protocol - + ", Server=" + server - + ": " + ex.getMessage()); - return false; - } - try - { - URLConnection c = url.openConnection(); - Object o = c.getContent(); - log.severe("In use=" + url); // error - } - catch (Exception ex) - { - log.fine("Not used=" + url); // ok - return false; - } - return true; - } // testPort - - /** - * Test Server Port - * @param port port - * @return true if able to create - */ - protected boolean testServerPort (int port) - { - try - { - ServerSocket ss = new ServerSocket (port); - log.fine(ss.getInetAddress() + ":" + ss.getLocalPort() + " - created"); - ss.close(); - } - catch (Exception ex) - { - log.severe("Port " + port + ": " + ex.getMessage()); - return false; - } - return true; - } // testPort - - - /** - * Test Port - * @param host host - * @param port port - * @param shouldBeUsed true if it should be used - * @return true if some server answered on port - */ - protected boolean testPort (InetAddress host, int port, boolean shouldBeUsed) - { - Socket pingSocket = null; - try - { - pingSocket = new Socket(host, port); - } - catch (Exception e) - { - if (shouldBeUsed) - log.severe("Open Socket " + host + ":" + port + " - " + e.getMessage()); - else - log.fine(host + ":" + port + " - " + e.getMessage()); - return false; - } - if (!shouldBeUsed) - log.severe("Open Socket " + host + ":" + port + " - " + pingSocket); - - log.fine(host + ":" + port + " - " + pingSocket); - if (pingSocket == null) - return false; - // success - try - { - pingSocket.close(); - } - catch (IOException e) - { - log.severe("close socket=" + e.toString()); - } - return true; - } // testPort - - - /************************************************************************** - * Save Settings - * @return true if saved - */ - public boolean save() - { - // Add - p_properties.setProperty("ADEMPIERE_MAIN_VERSION", Adempiere.MAIN_VERSION); - p_properties.setProperty("ADEMPIERE_DATE_VERSION", Adempiere.DATE_VERSION); - p_properties.setProperty("ADEMPIERE_DB_VERSION", Adempiere.DB_VERSION); - - log.finest(p_properties.toString()); - - // Before we save, load Ini - Ini.setClient(false); - String fileName = m_adempiereHome.getAbsolutePath() + File.separator + Ini.ADEMPIERE_PROPERTY_FILE; - Ini.loadProperties(fileName); - - // Save Environment - fileName = m_adempiereHome.getAbsolutePath() + File.separator + ADEMPIERE_ENV_FILE; - try - { - FileOutputStream fos = new FileOutputStream(new File(fileName)); - p_properties.store(fos, ADEMPIERE_ENV_FILE); - fos.flush(); - fos.close(); - } - catch (Exception e) - { - log.severe("Cannot save Properties to " + fileName + " - " + e.toString()); - JOptionPane.showConfirmDialog(p_panel, - ConfigurationPanel.res.getString("ErrorSave"), - ConfigurationPanel.res.getString("AdempiereServerSetup"), - JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); - return false; - } - catch (Throwable t) - { - log.severe("Cannot save Properties to " + fileName + " - " + t.toString()); - JOptionPane.showConfirmDialog(p_panel, - ConfigurationPanel.res.getString("ErrorSave"), - ConfigurationPanel.res.getString("AdempiereServerSetup"), - JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); - return false; - } - log.info(fileName); - return saveIni(); - } // save - - /** - * Synchronize and save Connection Info in Ini - * @return true - */ - private boolean saveIni() - { - Ini.setAdempiereHome(m_adempiereHome.getAbsolutePath()); - - // Create Connection - String ccType = Database.DB_ORACLE; - if (getDatabaseType().equals(DBTYPE_MS)) - ccType = Database.DB_MSSQLServer; - else if (getDatabaseType().equals(DBTYPE_DB2)) - ccType = Database.DB_DB2; - else if (getDatabaseType().equals(DBTYPE_DERBY)) - ccType = Database.DB_DERBY; - //begin vpj-cd e-evolution 03/17/2005 PostgreSQL - else if (getDatabaseType().equals(DBTYPE_POSTGRESQL)) - ccType = Database.DB_POSTGRESQL; - else if (getDatabaseType().equals(DBTYPE_FYRACLE)) - ccType = Database.DB_FYRACLE; - - //end vpj-cd e-evolution 03/17/2005 PostgreSQL - CConnection cc = null; - try - { - cc = CConnection.get (ccType, - getDatabaseServer(), getDatabasePort(), getDatabaseName(), - getDatabaseUser(), getDatabasePassword()); - cc.setAppsHost(p_panel.fAppsServer.getText()); - cc.setConnectionProfile(CConnection.PROFILE_LAN); - } - catch(Exception e) - { - log.log(Level.SEVERE, "connection", e); - return false; - } - if (cc == null) - { - log.severe("No Connection"); - return false; - } - Ini.setProperty(Ini.P_CONNECTION, cc.toStringLong()); - Ini.saveProperties(false); - return true; - } // saveIni - - - /** - * Get Properties - * @return properties - */ - Properties getProperties () - { - return p_properties; - } // getProperties - - /** - * Get Adempiere Home - * @return adempiere home - */ - public String getAdempiereHome() - { - return p_panel.fAdempiereHome.getText(); - } // getAdempiereHome - - /** - * Set Adempiere Home - * @param adempiereHome - */ - public void setAdempiereHome (String adempiereHome) - { - p_panel.fAdempiereHome.setText(adempiereHome); - } // setAdempiereHome - - /** - * Get Key Store - * @return password - */ - public String getKeyStore () - { - char[] pw = p_panel.fKeyStore.getPassword(); - if (pw != null) - return new String(pw); - return ""; - } // getKeyStore - - /** - * Set Key Store Password - * @param password - */ - public void setKeyStore (String password) - { - p_panel.fKeyStore.setText(password); - } // setKeyStore - - - /************************************************************************** - * Java Settings - *************************************************************************/ - - /** SUN VM (default) */ - private static String JAVATYPE_SUN = "sun"; - /** Apple VM */ - private static String JAVATYPE_MAC = "mac"; - /** IBM VM */ - private static String JAVATYPE_IBM = ""; - /** Java VM Types */ - static String[] JAVATYPE = new String[] - {JAVATYPE_SUN, JAVATYPE_MAC, JAVATYPE_IBM}; - /** Database Configs */ - private Config[] m_javaConfig = new Config[] - {new ConfigVMSun(this), new ConfigVMMac(this), null}; - - /** - * Init Database - */ - public void initJava() - { - int index = p_panel.fJavaType.getSelectedIndex(); - if (index < 0 || index >= JAVATYPE.length) - log.warning("JavaType Index invalid: " + index); - else if (m_javaConfig[index] == null) - { - log.warning("JavaType Config missing: " + JAVATYPE[index]); - p_panel.fJavaType.setSelectedIndex(0); - } - else - m_javaConfig[index].init(); - } // initDatabase - - /** - * Test Java - * @return error message or null of OK - */ - public String testJava() - { - int index = p_panel.fJavaType.getSelectedIndex(); - if (index < 0 || index >= JAVATYPE.length) - return "JavaType Index invalid: " + index; - else if (m_javaConfig[index] == null) - return "JavaType Config class missing: " + index; - return m_javaConfig[index].test(); - } // testJava - - /** - * Set Java Type - * @param javaType The javaType to set. - */ - public void setJavaType (String javaType) - { - int index = -1; - for (int i = 0; i < JAVATYPE.length; i++) - { - if (JAVATYPE[i].equals(javaType)) - { - index = i; - break; - } - } - if (index == -1) - { - index = 0; - log.warning("Invalid JavaType=" + javaType); - } - p_panel.fJavaType.setSelectedIndex(index); - } // setJavaType - - /** - * @return Returns the javaType. - */ - public String getJavaType () - { - return (String)p_panel.fJavaType.getSelectedItem(); - } - - /** - * @return Returns the javaHome. - */ - public String getJavaHome () - { - return p_panel.fJavaHome.getText(); - } - /** - * @param javaHome The javaHome to set. - */ - public void setJavaHome (String javaHome) - { - p_panel.fJavaHome.setText(javaHome); - } - - /************************************************************************** - * Apps Server Settings - *************************************************************************/ - - /** JBoss (default) */ - protected static String APPSTYPE_JBOSS = "jboss"; - /** Tomcat only */ - protected static String APPSTYPE_TOMCAT = "tomcatOnly"; - /** IBM WS */ - private static String APPSTYPE_IBM = ""; - /** Oracle */ - private static String APPSTYPE_ORACLE = ""; - /** Application Server Type */ - static String[] APPSTYPE = new String[] - {APPSTYPE_JBOSS, APPSTYPE_TOMCAT, - APPSTYPE_IBM, APPSTYPE_ORACLE}; - /** Database Configs */ - private Config[] m_appsConfig = new Config[] - {new ConfigJBoss(this), new ConfigTomcat(this), - null, null}; - - /** - * Init Apps Server - */ - public void initAppsServer() - { - int index = p_panel.fAppsType.getSelectedIndex(); - if (index < 0 || index >= APPSTYPE.length) - log.warning("AppsServerType Index invalid: " + index); - else if (m_appsConfig[index] == null) - { - log.warning("AppsServerType Config missing: " + APPSTYPE[index]); - p_panel.fAppsType.setSelectedIndex(0); - } - else - m_appsConfig[index].init(); - } // initAppsServer - - /** - * Test Apps Server - * @return error message or null of OK - */ - public String testAppsServer() - { - int index = p_panel.fAppsType.getSelectedIndex(); - if (index < 0 || index >= APPSTYPE.length) - return "AppsServerType Index invalid: " + index; - else if (m_appsConfig[index] == null) - return "AppsServerType Config class missing: " + index; - return m_appsConfig[index].test(); - } // testAppsServer - - - /** - * Set Apps Server Type - * @param appsType The appsType to set. - */ - public void setAppsServerType (String appsType) - { - int index = -1; - for (int i = 0; i < APPSTYPE.length; i++) - { - if (APPSTYPE[i].equals(appsType)) - { - index = i; - break; - } - } - if (index == -1) - { - index = 0; - log.warning("Invalid AppsType=" + appsType); - } - p_panel.fAppsType.setSelectedIndex(index); - } // setAppsServerType - - /** - * Get Apps Server Type - * @return Apps Server Type - */ - public String getAppsServerType () - { - return (String)p_panel.fAppsType.getSelectedItem(); - } // setDatabaseType - - /** - * @return Returns the appsServer. - */ - public String getAppsServer () - { - return p_panel.fAppsServer.getText(); - } - /** - * @param appsServer The appsServer to set. - */ - public void setAppsServer (String appsServer) - { - p_panel.fAppsServer.setText(appsServer); - } - - /** - * @return Returns the appsServerDeployDir. - */ - public String getAppsServerDeployDir () - { - return p_panel.fDeployDir.getText(); - } - /** - * @param appsServerDeployDir The appsServerDeployDir to set. - */ - public void setAppsServerDeployDir (String appsServerDeployDir) - { - p_panel.fDeployDir.setText(appsServerDeployDir); - } - /** - * @param enable if true enable entry - */ - public void setAppsServerDeployDir (boolean enable) - { - p_panel.fDeployDir.setEnabled(enable); - p_panel.bDeployDir.setEnabled(enable); - } - /** - * @return Returns the appsServerJNPPort. - */ - public int getAppsServerJNPPort () - { - try - { - return Integer.parseInt(p_panel.fJNPPort.getText()); - } - catch (Exception e) - { - setAppsServerJNPPort("0"); - } - return 0; - } - /** - * @param appsServerJNPPort The appsServerJNPPort to set. - */ - public void setAppsServerJNPPort (String appsServerJNPPort) - { - p_panel.fJNPPort.setText(appsServerJNPPort); - } - /** - * @param enable if enable JNP entry - */ - public void setAppsServerJNPPort (boolean enable) - { - p_panel.fJNPPort.setEnabled(enable); - } - /** - * @return Returns the appsServerSSLPort. - */ - public int getAppsServerSSLPort () - { - try - { - return Integer.parseInt(p_panel.fSSLPort.getText()); - } - catch (Exception e) - { - setAppsServerSSLPort("0"); - } - return 0; - } - /** - * @param appsServerSSLPort The appsServerSSLPort to set. - */ - public void setAppsServerSSLPort (String appsServerSSLPort) - { - p_panel.fSSLPort.setText(appsServerSSLPort); - } - /** - * @param enable if tre enable SSL entry - */ - public void setAppsServerSSLPort (boolean enable) - { - p_panel.fSSLPort.setEnabled(enable); - } - /** - * @return Returns the appsServerWebPort. - */ - public int getAppsServerWebPort () - { - try - { - return Integer.parseInt(p_panel.fWebPort.getText()); - } - catch (Exception e) - { - setAppsServerWebPort("0"); - } - return 0; - } - /** - * @param appsServerWebPort The appsServerWebPort to set. - */ - public void setAppsServerWebPort (String appsServerWebPort) - { - p_panel.fWebPort.setText(appsServerWebPort); - } - /** - * @param enable if tre enable Web entry - */ - public void setAppsServerWebPort (boolean enable) - { - p_panel.fWebPort.setEnabled(enable); - } - - - /************************************************************************** - * Database Settings - *************************************************************************/ - - /** Derby/Cloudscape */ - private static String DBTYPE_DERBY = "derby"; - /** Oracle directory */ - private static String DBTYPE_ORACLE = "oracle"; - /** DB/2 */ - private static String DBTYPE_DB2 = ""; - /** MS SQL Server */ - private static String DBTYPE_MS = ""; - - // begin e-evolution vpj-cd 02/07/2005 PostgreSQL - /** PostgreSQL */ - private static String DBTYPE_POSTGRESQL = "postgresql"; - private static String DBTYPE_EDB = "enterprisedb"; - private static String DBTYPE_FYRACLE = "fyracle"; - - // end e-evolution vpj-cd 02/07/2005 PostgreSQL - - /** Database Types */ - static String[] DBTYPE = new String[] - {//DBTYPE_DERBY, - DBTYPE_ORACLE, - //DBTYPE_DB2, - //DBTYPE_MS, - DBTYPE_FYRACLE, - //begin e-evolution vpj-cd 02/07/2005 PostgreSQL - DBTYPE_POSTGRESQL - - }; - //end e-evolution vpj-cd 02/07/2005 PostgreSQL - - /** Database Configs */ - private Config[] m_databaseConfig = new Config[] - { - //new ConfigDerby(this), - new ConfigOracle(this), - //new ConfigDB2(this), - //begin e-evolution vpj-cd 02/07/2005 PostgreSQL - //null - //null, - new ConfigFyracle(this), - new ConfigPostgreSQL(this) -// new ConfigEDB(this) - // end e-evolution vpj-cd 02/07/2005 PostgreSQL - }; - - /** - * Init Database - * @param selected DB - */ - public void initDatabase(String selected) - { - int index = p_panel.fDatabaseType.getSelectedIndex(); - if (index < 0 || index >= DBTYPE.length) - log.warning("DatabaseType Index invalid: " + index); - else if (m_databaseConfig[index] == null) - { - log.warning("DatabaseType Config missing: " + DBTYPE[index]); - p_panel.fDatabaseType.setSelectedIndex(0); - } - else - { - m_databaseConfig[index].init(); - String[] databases = m_databaseConfig[index].discoverDatabases(selected); - DefaultComboBoxModel model = new DefaultComboBoxModel(databases); - p_panel.fDatabaseDiscovered.setModel(model); - p_panel.fDatabaseDiscovered.setEnabled(databases.length != 0); - } - } // initDatabase - - /** - * Test Database - * @return error message or null of OK - */ - public String testDatabase() - { - int index = p_panel.fDatabaseType.getSelectedIndex(); - if (index < 0 || index >= DBTYPE.length) - return "DatabaseType Index invalid: " + index; - else if (m_databaseConfig[index] == null) - return "DatabaseType Config class missing: " + index; - return m_databaseConfig[index].test(); - } // testDatabase - - - /** - * Set Database Type - * @param databaseType The databaseType to set. - */ - public void setDatabaseType (String databaseType) - { - int index = -1; - for (int i = 0; i < DBTYPE.length; i++) - { - if (DBTYPE[i].equals(databaseType)) - { - index = i; - break; - } - } - if (index == -1) - { - index = 0; - log.warning("Invalid DatabaseType=" + databaseType); - } - p_panel.fDatabaseType.setSelectedIndex(index); - } // setDatabaseType - - /** - * @return Returns the databaseType. - */ - public String getDatabaseType () - { - return (String)p_panel.fDatabaseType.getSelectedItem(); - } - /** - * @return Returns the database Discovered. - */ - public String getDatabaseDiscovered () - { - return (String)p_panel.fDatabaseDiscovered.getSelectedItem(); - } - /** - * @param databaseDiscovered The database Discovered to set. - */ - public void setDatabaseDiscovered (String databaseDiscovered) - { - p_panel.fDatabaseDiscovered.setSelectedItem(databaseDiscovered); - } - - /** - * @return Returns the databaseName. - */ - public String getDatabaseName () - { - return p_panel.fDatabaseName.getText(); - } - /** - * @param databaseName The databaseName to set. - */ - public void setDatabaseName (String databaseName) - { - p_panel.fDatabaseName.setText(databaseName); - } - - /** - * @return Returns the database User Password. - */ - public String getDatabasePassword () - { - char[] pw = p_panel.fDatabasePassword.getPassword(); - if (pw != null) - return new String(pw); - return ""; - } - /** - * @param databasePassword The databasePassword to set. - */ - public void setDatabasePassword (String databasePassword) - { - p_panel.fDatabasePassword.setText(databasePassword); - } - /** - * @return Returns the databasePort. - */ - public int getDatabasePort () - { - try - { - return Integer.parseInt(p_panel.fDatabasePort.getText()); - } - catch (Exception e) - { - setDatabasePort("0"); - } - return 0; - } // getDatabasePort - /** - * @param databasePort The databasePort to set. - */ - public void setDatabasePort (String databasePort) - { - p_panel.fDatabasePort.setText(databasePort); - } - /** - * @return Returns the databaseServer. - */ - public String getDatabaseServer () - { - return p_panel.fDatabaseServer.getText(); - } - /** - * @param databaseServer The databaseServer to set. - */ - public void setDatabaseServer (String databaseServer) - { - p_panel.fDatabaseServer.setText(databaseServer); - } - /** - * @return Returns the databaseSystemPassword. - */ - public String getDatabaseSystemPassword () - { - char[] pw = p_panel.fSystemPassword.getPassword(); - if (pw != null) - return new String(pw); - return ""; - } - /** - * @param databaseSystemPassword The databaseSystemPassword to set. - */ - public void setDatabaseSystemPassword (String databaseSystemPassword) - { - p_panel.fSystemPassword.setText(databaseSystemPassword); - } - /** - * @param enable enable Database System Password - */ - public void setDatabaseSystemPassword (boolean enable) - { - p_panel.fSystemPassword.setEnabled(enable); - } - /** - * @return Returns the databaseUser. - */ - public String getDatabaseUser () - { - return p_panel.fDatabaseUser.getText(); - } - /** - * @param databaseUser The databaseUser to set. - */ - public void setDatabaseUser (String databaseUser) - { - p_panel.fDatabaseUser.setText(databaseUser); - } - -} // ConfigurationData +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +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.4 2006/07/30 00:57:42 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(); + /** Adempiere Home */ + private File m_adempiereHome; + + + /** Static Logger */ + static CLogger log = CLogger.getCLogger (ConfigurationData.class); + + + /** Properties File name */ + public static final String ADEMPIERE_ENV_FILE = "AdempiereEnv.properties"; + + /** Adempiere Home */ + public static final String ADEMPIERE_HOME = "ADEMPIERE_HOME"; + /** */ + public static final String JAVA_HOME = "JAVA_HOME"; + /** */ + public static final String JAVA_TYPE = "ADEMPIERE_JAVA_TYPE"; + /** */ + public static final String ADEMPIERE_JAVA_OPTIONS = "ADEMPIERE_JAVA_OPTIONS"; + /** Default Keysore Password */ + public static final String KEYSTORE_PASSWORD = "myPassword"; + + /** */ + public static final String ADEMPIERE_APPS_TYPE = "ADEMPIERE_APPS_TYPE"; + /** */ + public static final String ADEMPIERE_APPS_SERVER = "ADEMPIERE_APPS_SERVER"; + /** */ + public static final String ADEMPIERE_APPS_DEPLOY = "ADEMPIERE_APPS_DEPLOY"; + /** */ + public static final String ADEMPIERE_JNP_PORT = "ADEMPIERE_JNP_PORT"; + /** */ + public static final String ADEMPIERE_WEB_PORT = "ADEMPIERE_WEB_PORT"; + /** */ + public static final String ADEMPIERE_SSL_PORT = "ADEMPIERE_SSL_PORT"; + /** */ + public static final String ADEMPIERE_WEB_ALIAS = "ADEMPIERE_WEB_ALIAS"; + + /** */ + public static final String ADEMPIERE_KEYSTORE = "ADEMPIERE_KEYSTORE"; + /** */ + public static final String ADEMPIERE_KEYSTOREPASS = "ADEMPIERE_KEYSTOREPASS"; + /** */ + public static final String ADEMPIERE_KEYSTORECODEALIAS = "ADEMPIERE_KEYSTORECODEALIAS"; + /** */ + public static final String ADEMPIERE_KEYSTOREWEBALIAS = "ADEMPIERE_KEYSTOREWEBALIAS"; + + /** DB Type */ + public static final String ADEMPIERE_DB_TYPE = "ADEMPIERE_DB_TYPE"; + /** DB Path */ + public static final String ADEMPIERE_DB_PATH = "ADEMPIEREe_DB_PATH"; + /** */ + /** */ + public static final String ADEMPIERE_DB_SERVER = "ADEMPIERE_DB_SERVER"; + /** */ + public static final String ADEMPIERE_DB_PORT = "ADEMPIERE_DB_PORT"; + /** */ + public static final String ADEMPIERE_DB_NAME = "ADEMPIERE_DB_NAME"; + /** */ + public static final String ADEMPIERE_DB_URL = "ADEMPIERE_DB_URL"; + + /** */ + public static final String ADEMPIERE_DB_USER = "ADEMPIERE_DB_USER"; + /** */ + public static final String ADEMPIERE_DB_PASSWORD = "ADEMPIERE_DB_PASSWORD"; + /** */ + public static final String ADEMPIERE_DB_SYSTEM = "ADEMPIERE_DB_SYSTEM"; + + /** */ + public static final String ADEMPIERE_MAIL_SERVER = "ADEMPIERE_MAIL_SERVER"; + /** */ + public static final String ADEMPIERE_MAIL_USER = "ADEMPIERE_MAIL_USER"; + /** */ + public static final String ADEMPIERE_MAIL_PASSWORD = "ADEMPIERE_MAIL_PASSWORD"; + /** */ + public static final String ADEMPIERE_ADMIN_EMAIL = "ADEMPIERE_ADMIN_EMAIL"; + /** */ + public static final String ADEMPIERE_MAIL_UPDATED = "ADEMPIERE_MAIL_UPDATED"; + + /** */ + public static final String ADEMPIERE_FTP_SERVER = "ADEMPIERE_FTP_SERVER"; + /** */ + public static final String ADEMPIERE_FTP_USER = "ADEMPIERE_FTP_USER"; + /** */ + public static final String ADEMPIERE_FTP_PASSWORD = "ADEMPIERE_FTP_PASSWORD"; + /** */ + public static final String ADEMPIERE_FTP_PREFIX = "ADEMPIERE_FTP_PREFIX"; + + /** */ + public static final String ADEMPIERE_WEBSTORES = "ADEMPIERE_WEBSTORES"; + + + + /** + * Load Configuration Data + * @return true if loaded + */ + public boolean load() + { + // Load C:\Adempiere\AdempiereEnv.properties + String adempiereHome = System.getProperty(ADEMPIERE_HOME); + if (adempiereHome == null || adempiereHome.length() == 0) + adempiereHome = System.getProperty("user.dir"); + + boolean envLoaded = false; + String fileName = adempiereHome + File.separator + ADEMPIERE_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.warning(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)); + // + setAdempiereHome((String)p_properties.get(ADEMPIERE_HOME)); + String s = (String)p_properties.get(ADEMPIERE_KEYSTOREPASS); + if (s == null || s.length() == 0) + s = KEYSTORE_PASSWORD; + setKeyStore(s); + // + setAppsServerType((String)p_properties.get(ADEMPIERE_APPS_TYPE)); + initAppsServer(); + setAppsServer((String)p_properties.get(ADEMPIERE_APPS_SERVER)); + setAppsServerDeployDir((String)p_properties.get(ADEMPIERE_APPS_DEPLOY)); + setAppsServerJNPPort((String)p_properties.get(ADEMPIERE_JNP_PORT)); + setAppsServerWebPort((String)p_properties.get(ADEMPIERE_WEB_PORT)); + setAppsServerSSLPort((String)p_properties.get(ADEMPIERE_SSL_PORT)); + // + setDatabaseType((String)p_properties.get(ADEMPIERE_DB_TYPE)); + initDatabase((String)p_properties.get(ADEMPIERE_DB_NAME)); // fills Database Options + setDatabaseDiscovered((String)p_properties.get(ADEMPIERE_DB_NAME)); + setDatabaseServer((String)p_properties.get(ADEMPIERE_DB_SERVER)); + setDatabasePort((String)p_properties.get(ADEMPIERE_DB_PORT)); + setDatabaseName((String)p_properties.get(ADEMPIERE_DB_NAME)); + + setDatabaseUser((String)p_properties.get(ADEMPIERE_DB_USER)); + setDatabasePassword((String)p_properties.get(ADEMPIERE_DB_PASSWORD)); + setDatabaseSystemPassword((String)p_properties.get(ADEMPIERE_DB_SYSTEM)); + + p_panel.fMailServer.setText((String)p_properties.get(ADEMPIERE_MAIL_SERVER)); + p_panel.fMailUser.setText((String)p_properties.get(ADEMPIERE_MAIL_USER)); + p_panel.fMailPassword.setText((String)p_properties.get(ADEMPIERE_MAIL_PASSWORD)); + p_panel.fAdminEMail.setText((String)p_properties.get(ADEMPIERE_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(); + // + setAdempiereHome(adempiereHome); + setKeyStore(KEYSTORE_PASSWORD); + // AppsServer + initAppsServer(); + setAppsServer(hostName); + // Database Server + initDatabase(""); + setDatabaseName(getDatabaseDiscovered()); + setDatabaseSystemPassword(""); + setDatabaseServer(hostName); + setDatabaseUser("adempiere"); + setDatabasePassword("adempiere"); + // 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(ADEMPIERE_FTP_SERVER)) + { + p_properties.setProperty(ADEMPIERE_FTP_SERVER, "localhost"); + p_properties.setProperty(ADEMPIERE_FTP_USER, "anonymous"); + p_properties.setProperty(ADEMPIERE_FTP_PASSWORD, "user@host.com"); + p_properties.setProperty(ADEMPIERE_FTP_PREFIX, "my"); + } + // Default Java Options + if (!p_properties.containsKey(ADEMPIERE_JAVA_OPTIONS)) + p_properties.setProperty(ADEMPIERE_JAVA_OPTIONS, "-Xms64M -Xmx512M"); + // Web Alias + if (!p_properties.containsKey(ADEMPIERE_WEB_ALIAS) && localhost != null) + p_properties.setProperty(ADEMPIERE_WEB_ALIAS, localhost.getCanonicalHostName()); + + // (String)p_properties.get(ADEMPIERE_DB_URL) // derived + + // Keystore Alias + if (!p_properties.containsKey(ADEMPIERE_KEYSTORECODEALIAS)) + p_properties.setProperty(ADEMPIERE_KEYSTORECODEALIAS, "adempiere"); + if (!p_properties.containsKey(ADEMPIERE_KEYSTOREWEBALIAS)) + p_properties.setProperty(ADEMPIERE_KEYSTOREWEBALIAS, "adempiere"); + + return true; + } // load + + + /************************************************************************** + * test + * @return true if test ok + */ + public boolean test() + { + String error = testJava(); + if (error != null) + { + log.severe(error); + return false; + } + + error = testAdempiere(); + if (error != null) + { + log.warning(error); + return false; + } + + p_panel.setStatusBar(p_panel.lAppsServer.getText()); + error = testAppsServer(); + if (error != null) + { + log.warning(error); + return false; + } + + p_panel.setStatusBar(p_panel.lDatabaseServer.getText()); + error = testDatabase(); + if (error != null) + { + log.warning(error); + return false; + } + + p_panel.setStatusBar(p_panel.lMailServer.getText()); + error = testMail(); + if (error != null) + { + log.warning(error); + return false; + } + + return true; + } // test + + + /** + * Test Adempiere and set AdempiereHome + * @return error message or null if OK + */ + private String testAdempiere() + { + // Adempiere Home + m_adempiereHome = new File (getAdempiereHome()); + boolean pass =m_adempiereHome.exists(); + String error = "Not found: AdempiereHome = " + m_adempiereHome; + p_panel.signalOK(p_panel.okAdempiereHome, "ErrorAdempiereHome", + pass, true, error); + if (!pass) + return error; + log.info("OK: AdempiereHome = " + m_adempiereHome); + p_properties.setProperty(ADEMPIERE_HOME, m_adempiereHome.getAbsolutePath()); + System.setProperty(ADEMPIERE_HOME, m_adempiereHome.getAbsolutePath()); + + // KeyStore + String fileName = KeyStoreMgt.getKeystoreFileName(m_adempiereHome.getAbsolutePath()); + p_properties.setProperty(ADEMPIERE_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(ADEMPIERE_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; + } // testAdempiere + + + /************************************************************************** + * 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(ADEMPIERE_MAIL_SERVER, ""); + return error; + } + p_properties.setProperty(ADEMPIERE_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(ADEMPIERE_ADMIN_EMAIL, adminEMail.toString()); + p_properties.setProperty(ADEMPIERE_MAIL_USER, mailUser); + p_properties.setProperty(ADEMPIERE_MAIL_PASSWORD, mailPassword); + p_properties.setProperty(ADEMPIERE_MAIL_UPDATED, "No"); + } + else + { + log.warning(error); + p_properties.setProperty(ADEMPIERE_ADMIN_EMAIL, ""); + p_properties.setProperty(ADEMPIERE_MAIL_USER, ""); + p_properties.setProperty(ADEMPIERE_MAIL_PASSWORD, ""); + p_properties.setProperty(ADEMPIERE_MAIL_UPDATED, ""); + } + return null; + } // testMail + + /** + * Test Mail + * @param mailServer mail server + * @param adminEMail email of admin + * @param mailUser user ID + * @param mailPassword password + * @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"); + // + if (testPort (mailServer, 110, true)) + log.config("OK: POP3 Server contacted"); + else + log.info("POP3 Server NOT available"); + if (testPort (mailServer, 143, true)) + { + log.config("OK: IMAP4 Server contacted"); + imapOK = true; + } + else + log.info("IMAP4 Server NOT available"); + // + if (!smtpOK) + { + String error = "No active Mail Server"; + p_panel.signalOK (p_panel.okMailServer, "ErrorMailServer", + false, false, error); + log.warning(error); + return false; + } + // + try + { + EMail email = new EMail (new Properties(), + mailServer.getHostName (), + adminEMail.toString (), adminEMail.toString(), + "Adempiere Server Setup Test", + "Test: " + getProperties()); + email.createAuthenticator (mailUser, mailPassword); + if (EMail.SENT_OK.equals (email.send ())) + { + log.info("OK: Send Test Email to " + adminEMail); + } + else + { + log.warning("Could NOT send Email to " + adminEMail); + } + } + catch (Exception ex) + { + log.severe(ex.getLocalizedMessage()); + return false; + } + + // + if (!imapOK) + return false; + + // Test Read Mail Access + Properties props = new Properties(); + props.put("mail.store.protocol", "smtp"); + props.put("mail.transport.protocol", "smtp"); + props.put("mail.host", mailServer.getHostName()); + props.put("mail.user", mailUser); + props.put("mail.smtp.auth", "true"); + log.config("Connecting to " + mailServer.getHostName()); + // + Session session = null; + Store store = null; + try + { + EMailAuthenticator auth = new EMailAuthenticator (mailUser, mailPassword); + session = Session.getDefaultInstance(props, auth); + session.setDebug (CLogMgt.isLevelFinest()); + log.config("Session=" + session); + // Connect to Store + store = session.getStore("imap"); + log.config("Store=" + store); + } + catch (NoSuchProviderException nsp) + { + log.warning("Mail IMAP Provider - " + nsp.getMessage()); + return false; + } + catch (Exception e) + { + log.warning("Mail IMAP - " + e.getMessage()); + return false; + } + try + { + store.connect(mailServer.getHostName(), mailUser, mailPassword); + log.config("Store - connected"); + Folder folder = store.getDefaultFolder(); + Folder inbox = folder.getFolder("INBOX"); + log.info("OK: Mail Connect to " + inbox.getFullName() + " #Msg=" + inbox.getMessageCount()); + // + store.close(); + } + catch (MessagingException mex) + { + log.severe("Mail Connect " + mex.getMessage()); + return false; + } + return true; + } // testMailServer + + + /************************************************************************** + * Test Apps Server Port (client perspective) + * @param protocol protocol (http, ..) + * @param server server name + * @param port port + * @param file file name + * @return true if able to connect + */ + protected boolean testPort (String protocol, String server, int port, String file) + { + URL url = null; + try + { + url = new URL (protocol, server, port, file); + } + catch (MalformedURLException ex) + { + log.severe("No URL for Protocol=" + protocol + + ", Server=" + server + + ": " + ex.getMessage()); + return false; + } + try + { + URLConnection c = url.openConnection(); + Object o = c.getContent(); + if (o == null) + log.warning("In use=" + url); // error + else + log.warning("In Use=" + url); // error + } + catch (Exception ex) + { + log.fine("Not used=" + url); // ok + return false; + } + return true; + } // testPort + + /** + * Test Server Port + * @param port port + * @return true if able to create + */ + protected boolean testServerPort (int port) + { + try + { + ServerSocket ss = new ServerSocket (port); + log.fine(ss.getInetAddress() + ":" + ss.getLocalPort() + " - created"); + ss.close(); + } + catch (Exception ex) + { + log.warning("Port " + port + ": " + ex.getMessage()); + return false; + } + return true; + } // testPort + + + /** + * Test Port + * @param host host + * @param port port + * @param shouldBeUsed true if it should be used + * @return true if some server answered on port + */ + protected boolean testPort (InetAddress host, int port, boolean shouldBeUsed) + { + Socket pingSocket = null; + try + { + pingSocket = new Socket(host, port); + } + catch (Exception e) + { + if (shouldBeUsed) + log.warning("Open Socket " + host + ":" + port + " - " + e.getMessage()); + else + log.fine(host + ":" + port + " - " + e.getMessage()); + return false; + } + if (!shouldBeUsed) + log.warning("Open Socket " + host + ":" + port + " - " + pingSocket); + + log.fine(host + ":" + port + " - " + pingSocket); + if (pingSocket == null) + return false; + // success + try + { + pingSocket.close(); + } + catch (IOException e) + { + log.warning("close socket=" + e.toString()); + } + return true; + } // testPort + + + /************************************************************************** + * Save Settings + * @return true if saved + */ + public boolean save() + { + // Add + p_properties.setProperty("ADEMPIERE_MAIN_VERSION", Adempiere.MAIN_VERSION); + p_properties.setProperty("ADEMPIERE_DATE_VERSION", Adempiere.DATE_VERSION); + p_properties.setProperty("ADEMPIERE_DB_VERSION", Adempiere.DB_VERSION); + + log.finest(p_properties.toString()); + + // Before we save, load Ini + Ini.setClient(false); + String fileName = m_adempiereHome.getAbsolutePath() + File.separator + Ini.ADEMPIERE_PROPERTY_FILE; + Ini.loadProperties(fileName); + + // Save Environment + fileName = m_adempiereHome.getAbsolutePath() + File.separator + ADEMPIERE_ENV_FILE; + try + { + FileOutputStream fos = new FileOutputStream(new File(fileName)); + p_properties.store(fos, ADEMPIERE_ENV_FILE); + fos.flush(); + fos.close(); + } + catch (Exception e) + { + log.severe("Cannot save Properties to " + fileName + " - " + e.toString()); + JOptionPane.showConfirmDialog(p_panel, + ConfigurationPanel.res.getString("ErrorSave"), + ConfigurationPanel.res.getString("AdempiereServerSetup"), + JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); + return false; + } + catch (Throwable t) + { + log.severe("Cannot save Properties to " + fileName + " - " + t.toString()); + JOptionPane.showConfirmDialog(p_panel, + ConfigurationPanel.res.getString("ErrorSave"), + ConfigurationPanel.res.getString("AdempiereServerSetup"), + JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); + return false; + } + log.info(fileName); + return saveIni(); + } // save + + /** + * Synchronize and save Connection Info in Ini + * @return true + */ + private boolean saveIni() + { + Ini.setAdempiereHome(m_adempiereHome.getAbsolutePath()); + + // Create Connection + String ccType = Database.DB_ORACLE; + if (getDatabaseType().equals(DBTYPE_MS)) + ccType = Database.DB_MSSQLServer; + else if (getDatabaseType().equals(DBTYPE_DB2)) + ccType = Database.DB_DB2; + else if (getDatabaseType().equals(DBTYPE_DERBY)) + ccType = Database.DB_DERBY; + //begin vpj-cd e-evolution 03/17/2005 PostgreSQL + else if (getDatabaseType().equals(DBTYPE_POSTGRESQL)) + ccType = Database.DB_POSTGRESQL; + else if (getDatabaseType().equals(DBTYPE_FYRACLE)) + ccType = Database.DB_FYRACLE; + + //end vpj-cd e-evolution 03/17/2005 PostgreSQL + CConnection cc = null; + try + { + cc = CConnection.get (ccType, + getDatabaseServer(), getDatabasePort(), getDatabaseName(), + getDatabaseUser(), getDatabasePassword()); + cc.setAppsHost(p_panel.fAppsServer.getText()); + cc.setConnectionProfile(CConnection.PROFILE_LAN); + } + catch(Exception e) + { + log.log(Level.SEVERE, "connection", e); + return false; + } + if (cc == null) + { + log.warning("No Connection"); + return false; + } + Ini.setProperty(Ini.P_CONNECTION, cc.toStringLong()); + Ini.saveProperties(false); + return true; + } // saveIni + + + /** + * Get Properties + * @return properties + */ + Properties getProperties () + { + return p_properties; + } // getProperties + + /** + * Get Adempiere Home + * @return adempiere home + */ + public String getAdempiereHome() + { + return p_panel.fAdempiereHome.getText(); + } // getAdempiereHome + + /** + * Set Adempiere Home + * @param adempiereHome + */ + public void setAdempiereHome (String adempiereHome) + { + p_panel.fAdempiereHome.setText(adempiereHome); + } // setAdempiereHome + + /** + * Get Key Store + * @return password + */ + public String getKeyStore () + { + char[] pw = p_panel.fKeyStore.getPassword(); + if (pw != null) + return new String(pw); + return ""; + } // getKeyStore + + /** + * Set Key Store Password + * @param password + */ + public void setKeyStore (String password) + { + p_panel.fKeyStore.setText(password); + } // setKeyStore + + + /************************************************************************** + * Java Settings + *************************************************************************/ + + /** SUN VM (default) */ + private static String JAVATYPE_SUN = "sun"; + /** Apple VM */ + private static String JAVATYPE_MAC = "mac"; + /** IBM VM */ + private static String JAVATYPE_IBM = ""; + /** Java VM Types */ + static String[] JAVATYPE = new String[] + {JAVATYPE_SUN, JAVATYPE_MAC, JAVATYPE_IBM}; + /** Database Configs */ + private Config[] m_javaConfig = new Config[] + {new ConfigVMSun(this), new ConfigVMMac(this), null}; + + /** + * Init Database + */ + public void initJava() + { + int index = p_panel.fJavaType.getSelectedIndex(); + if (index < 0 || index >= JAVATYPE.length) + log.warning("JavaType Index invalid: " + index); + else if (m_javaConfig[index] == null) + { + log.warning("JavaType Config missing: " + JAVATYPE[index]); + p_panel.fJavaType.setSelectedIndex(0); + } + else + m_javaConfig[index].init(); + } // initDatabase + + /** + * Test Java + * @return error message or null of OK + */ + public String testJava() + { + int index = p_panel.fJavaType.getSelectedIndex(); + if (index < 0 || index >= JAVATYPE.length) + return "JavaType Index invalid: " + index; + else if (m_javaConfig[index] == null) + return "JavaType Config class missing: " + index; + return m_javaConfig[index].test(); + } // testJava + + /** + * Set Java Type + * @param javaType The javaType to set. + */ + public void setJavaType (String javaType) + { + int index = -1; + for (int i = 0; i < JAVATYPE.length; i++) + { + if (JAVATYPE[i].equals(javaType)) + { + index = i; + break; + } + } + if (index == -1) + { + index = 0; + log.warning("Invalid JavaType=" + javaType); + } + p_panel.fJavaType.setSelectedIndex(index); + } // setJavaType + + /** + * @return Returns the javaType. + */ + public String getJavaType () + { + return (String)p_panel.fJavaType.getSelectedItem(); + } + + /** + * @return Returns the javaHome. + */ + public String getJavaHome () + { + return p_panel.fJavaHome.getText(); + } + /** + * @param javaHome The javaHome to set. + */ + public void setJavaHome (String javaHome) + { + p_panel.fJavaHome.setText(javaHome); + } + + /************************************************************************** + * Apps Server Settings + *************************************************************************/ + + /** JBoss (default) */ + protected static String APPSTYPE_JBOSS = "jboss"; + /** Tomcat only */ + protected static String APPSTYPE_TOMCAT = "tomcatOnly"; + /** IBM WS */ + private static String APPSTYPE_IBM = ""; + /** Oracle */ + private static String APPSTYPE_ORACLE = ""; + /** Application Server Type */ + static String[] APPSTYPE = new String[] + {APPSTYPE_JBOSS, APPSTYPE_TOMCAT, + APPSTYPE_IBM, APPSTYPE_ORACLE}; + /** Database Configs */ + private Config[] m_appsConfig = new Config[] + {new ConfigJBoss(this), new ConfigTomcat(this), + null, null}; + + /** + * Init Apps Server + */ + public void initAppsServer() + { + int index = p_panel.fAppsType.getSelectedIndex(); + if (index < 0 || index >= APPSTYPE.length) + log.warning("AppsServerType Index invalid: " + index); + else if (m_appsConfig[index] == null) + { + log.warning("AppsServerType Config missing: " + APPSTYPE[index]); + p_panel.fAppsType.setSelectedIndex(0); + } + else + m_appsConfig[index].init(); + } // initAppsServer + + /** + * Test Apps Server + * @return error message or null of OK + */ + public String testAppsServer() + { + int index = p_panel.fAppsType.getSelectedIndex(); + if (index < 0 || index >= APPSTYPE.length) + return "AppsServerType Index invalid: " + index; + else if (m_appsConfig[index] == null) + return "AppsServerType Config class missing: " + index; + return m_appsConfig[index].test(); + } // testAppsServer + + + /** + * Set Apps Server Type + * @param appsType The appsType to set. + */ + public void setAppsServerType (String appsType) + { + int index = -1; + for (int i = 0; i < APPSTYPE.length; i++) + { + if (APPSTYPE[i].equals(appsType)) + { + index = i; + break; + } + } + if (index == -1) + { + index = 0; + log.warning("Invalid AppsType=" + appsType); + } + p_panel.fAppsType.setSelectedIndex(index); + } // setAppsServerType + + /** + * Get Apps Server Type + * @return Apps Server Type + */ + public String getAppsServerType () + { + return (String)p_panel.fAppsType.getSelectedItem(); + } // setDatabaseType + + /** + * @return Returns the appsServer. + */ + public String getAppsServer () + { + return p_panel.fAppsServer.getText(); + } + /** + * @param appsServer The appsServer to set. + */ + public void setAppsServer (String appsServer) + { + p_panel.fAppsServer.setText(appsServer); + } + + /** + * @return Returns the appsServerDeployDir. + */ + public String getAppsServerDeployDir () + { + return p_panel.fDeployDir.getText(); + } + /** + * @param appsServerDeployDir The appsServerDeployDir to set. + */ + public void setAppsServerDeployDir (String appsServerDeployDir) + { + p_panel.fDeployDir.setText(appsServerDeployDir); + } + /** + * @param enable if true enable entry + */ + public void setAppsServerDeployDir (boolean enable) + { + p_panel.fDeployDir.setEnabled(enable); + p_panel.bDeployDir.setEnabled(enable); + } + /** + * @return Returns the appsServerJNPPort. + */ + public int getAppsServerJNPPort () + { + try + { + return Integer.parseInt(p_panel.fJNPPort.getText()); + } + catch (Exception e) + { + setAppsServerJNPPort("0"); + } + return 0; + } + /** + * @param appsServerJNPPort The appsServerJNPPort to set. + */ + public void setAppsServerJNPPort (String appsServerJNPPort) + { + p_panel.fJNPPort.setText(appsServerJNPPort); + } + /** + * @param enable if enable JNP entry + */ + public void setAppsServerJNPPort (boolean enable) + { + p_panel.fJNPPort.setEnabled(enable); + } + /** + * @return Returns the appsServerSSLPort. + */ + public int getAppsServerSSLPort () + { + try + { + return Integer.parseInt(p_panel.fSSLPort.getText()); + } + catch (Exception e) + { + setAppsServerSSLPort("0"); + } + return 0; + } + /** + * @param appsServerSSLPort The appsServerSSLPort to set. + */ + public void setAppsServerSSLPort (String appsServerSSLPort) + { + p_panel.fSSLPort.setText(appsServerSSLPort); + } + /** + * @param enable if tre enable SSL entry + */ + public void setAppsServerSSLPort (boolean enable) + { + p_panel.fSSLPort.setEnabled(enable); + } + /** + * @return Returns the appsServerWebPort. + */ + public int getAppsServerWebPort () + { + try + { + return Integer.parseInt(p_panel.fWebPort.getText()); + } + catch (Exception e) + { + setAppsServerWebPort("0"); + } + return 0; + } + /** + * @param appsServerWebPort The appsServerWebPort to set. + */ + public void setAppsServerWebPort (String appsServerWebPort) + { + p_panel.fWebPort.setText(appsServerWebPort); + } + /** + * @param enable if tre enable Web entry + */ + public void setAppsServerWebPort (boolean enable) + { + p_panel.fWebPort.setEnabled(enable); + } + + + /************************************************************************** + * Database Settings + *************************************************************************/ + + /** Derby/Cloudscape */ + private static String DBTYPE_DERBY = ""; + /** Oracle directory */ + private static String DBTYPE_ORACLE = "oracle"; + /** Oracle XP */ + private static String DBTYPE_ORACLEXE = "oracleXE"; + /** DB/2 */ + private static String DBTYPE_DB2 = ""; + /** MS SQL Server */ + private static String DBTYPE_MS = ""; + + // begin e-evolution vpj-cd 02/07/2005 PostgreSQL + /** PostgreSQL */ + private static String DBTYPE_POSTGRESQL = "postgresql"; + private static String DBTYPE_EDB = "enterprisedb"; + private static String DBTYPE_FYRACLE = "fyracle"; + + // end e-evolution vpj-cd 02/07/2005 PostgreSQL + + /** Database Types */ + static String[] DBTYPE = new String[] + {DBTYPE_ORACLEXE, + DBTYPE_ORACLE, + //DBTYPE_DB2, + //DBTYPE_MS, + DBTYPE_FYRACLE, + //begin e-evolution vpj-cd 02/07/2005 PostgreSQL + DBTYPE_POSTGRESQL + + }; + //end e-evolution vpj-cd 02/07/2005 PostgreSQL + + /** Database Configs */ + private Config[] m_databaseConfig = new Config[] + { + new ConfigOracle(this,true), + new ConfigOracle(this,false), + //new ConfigDB2(this), + //begin e-evolution vpj-cd 02/07/2005 PostgreSQL + //null + //null, + new ConfigFyracle(this), + new ConfigPostgreSQL(this) +// new ConfigEDB(this) + // end e-evolution vpj-cd 02/07/2005 PostgreSQL + }; + + /** + * Init Database + * @param selected DB + */ + public void initDatabase(String selected) + { + int index = p_panel.fDatabaseType.getSelectedIndex(); + if (index < 0 || index >= DBTYPE.length) + log.warning("DatabaseType Index invalid: " + index); + else if (m_databaseConfig[index] == null) + { + log.warning("DatabaseType Config missing: " + DBTYPE[index]); + p_panel.fDatabaseType.setSelectedIndex(0); + } + else + { + m_databaseConfig[index].init(); + String[] databases = m_databaseConfig[index].discoverDatabases(selected); + DefaultComboBoxModel model = new DefaultComboBoxModel(databases); + p_panel.fDatabaseDiscovered.setModel(model); + p_panel.fDatabaseDiscovered.setEnabled(databases.length != 0); + if (databases.length > 0) + p_panel.fDatabaseName.setText(databases[0]); + } + } // initDatabase + + /** + * Test Database + * @return error message or null of OK + */ + public String testDatabase() + { + int index = p_panel.fDatabaseType.getSelectedIndex(); + if (index < 0 || index >= DBTYPE.length) + return "DatabaseType Index invalid: " + index; + else if (m_databaseConfig[index] == null) + return "DatabaseType Config class missing: " + index; + return m_databaseConfig[index].test(); + } // testDatabase + + + /** + * Set Database Type + * @param databaseType The databaseType to set. + */ + public void setDatabaseType (String databaseType) + { + int index = -1; + for (int i = 0; i < DBTYPE.length; i++) + { + if (DBTYPE[i].equals(databaseType)) + { + index = i; + break; + } + } + if (index == -1) + { + index = 0; + log.warning("Invalid DatabaseType=" + databaseType); + } + p_panel.fDatabaseType.setSelectedIndex(index); + } // setDatabaseType + + /** + * @return Returns the databaseType. + */ + public String getDatabaseType () + { + return (String)p_panel.fDatabaseType.getSelectedItem(); + } + /** + * @return Returns the database Discovered. + */ + public String getDatabaseDiscovered () + { + return (String)p_panel.fDatabaseDiscovered.getSelectedItem(); + } + /** + * @param databaseDiscovered The database Discovered to set. + */ + public void setDatabaseDiscovered (String databaseDiscovered) + { + p_panel.fDatabaseDiscovered.setSelectedItem(databaseDiscovered); + } + + /** + * @return Returns the databaseName. + */ + public String getDatabaseName () + { + return p_panel.fDatabaseName.getText(); + } + /** + * @param databaseName The databaseName to set. + */ + public void setDatabaseName (String databaseName) + { + p_panel.fDatabaseName.setText(databaseName); + } + + /** + * @return Returns the database User Password. + */ + public String getDatabasePassword () + { + char[] pw = p_panel.fDatabasePassword.getPassword(); + if (pw != null) + return new String(pw); + return ""; + } + /** + * @param databasePassword The databasePassword to set. + */ + public void setDatabasePassword (String databasePassword) + { + p_panel.fDatabasePassword.setText(databasePassword); + } + /** + * @return Returns the databasePort. + */ + public int getDatabasePort () + { + try + { + return Integer.parseInt(p_panel.fDatabasePort.getText()); + } + catch (Exception e) + { + setDatabasePort("0"); + } + return 0; + } // getDatabasePort + /** + * @param databasePort The databasePort to set. + */ + public void setDatabasePort (String databasePort) + { + p_panel.fDatabasePort.setText(databasePort); + } + /** + * @return Returns the databaseServer. + */ + public String getDatabaseServer () + { + return p_panel.fDatabaseServer.getText(); + } + /** + * @param databaseServer The databaseServer to set. + */ + public void setDatabaseServer (String databaseServer) + { + p_panel.fDatabaseServer.setText(databaseServer); + } + /** + * @return Returns the databaseSystemPassword. + */ + public String getDatabaseSystemPassword () + { + char[] pw = p_panel.fSystemPassword.getPassword(); + if (pw != null) + return new String(pw); + return ""; + } + /** + * @param databaseSystemPassword The databaseSystemPassword to set. + */ + public void setDatabaseSystemPassword (String databaseSystemPassword) + { + p_panel.fSystemPassword.setText(databaseSystemPassword); + } + /** + * @param enable enable Database System Password + */ + public void setDatabaseSystemPassword (boolean enable) + { + p_panel.fSystemPassword.setEnabled(enable); + } + /** + * @return Returns the databaseUser. + */ + public String getDatabaseUser () + { + return p_panel.fDatabaseUser.getText(); + } + /** + * @param databaseUser The databaseUser to set. + */ + public void setDatabaseUser (String databaseUser) + { + p_panel.fDatabaseUser.setText(databaseUser); + } + +} // ConfigurationData diff --git a/install/src/org/compiere/install/ConfigurationPanel.java b/install/src/org/compiere/install/ConfigurationPanel.java index 57a5f33a02..eaa5d4b690 100644 --- a/install/src/org/compiere/install/ConfigurationPanel.java +++ b/install/src/org/compiere/install/ConfigurationPanel.java @@ -1,679 +1,632 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.install; - -import java.awt.*; -import java.awt.event.*; -import java.util.*; -import java.util.logging.*; -import javax.swing.*; -import javax.swing.border.TitledBorder; -import javax.swing.plaf.metal.MetalLookAndFeel; - -import org.apache.tools.ant.*; -import org.compiere.*; -import org.compiere.apps.*; -import org.compiere.swing.*; -import org.compiere.util.*; - - -/** - * Configuration Panel - * - * @author Jorg Janke - * @version $Id: ConfigurationPanel.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ - */ -public class ConfigurationPanel extends CPanel implements ActionListener -{ - /** - * Constructor - * @param statusBar for info - */ - public ConfigurationPanel (JLabel statusBar) - { - m_statusBar = statusBar; - try - { - jbInit(); - } - catch (Exception e) - { - e.printStackTrace(); - System.exit(1); - } - } // ConfigurationPanel - - /** Error Info */ - private String m_errorString; - /** Test Success */ - private volatile boolean m_success = false; - /** Sync */ - private volatile boolean m_testing = false; - - /** Translation */ - static ResourceBundle res = ResourceBundle.getBundle("org.compiere.install.SetupRes"); - - /** Setup Frame */ - private Setup m_setup = null; - /** Status Bar */ - private JLabel m_statusBar; - /** Configuration Data */ - private ConfigurationData m_data = new ConfigurationData(this); - - private static ImageIcon iOpen = new ImageIcon(ConfigurationPanel.class.getResource("openFile.gif")); - private static ImageIcon iSave = new ImageIcon(Adempiere.class.getResource("images/Save16.gif")); - private static ImageIcon iHelp = new ImageIcon(Adempiere.class.getResource("images/Help16.gif")); - - - // ------------- Static UI - private GridBagLayout gridBagLayout = new GridBagLayout(); - private static final int FIELDLENGTH = 15; - // Java - private CLabel lJavaHome = new CLabel(); - CTextField fJavaHome = new CTextField(FIELDLENGTH); - CCheckBox okJavaHome = new CCheckBox(); - private CButton bJavaHome = new CButton(iOpen); - private CLabel lJavaType = new CLabel(); - CComboBox fJavaType = new CComboBox(ConfigurationData.JAVATYPE); - // Adempiere - KeyStore - private CLabel lAdempiereHome = new CLabel(); - CTextField fAdempiereHome = new CTextField(FIELDLENGTH); - CCheckBox okAdempiereHome = new CCheckBox(); - private CButton bAdempiereHome = new CButton(iOpen); - private CLabel lKeyStore = new CLabel(); - CPassword fKeyStore = new CPassword(); - CCheckBox okKeyStore = new CCheckBox(); - // Apps Server - Type - CLabel lAppsServer = new CLabel(); - CTextField fAppsServer = new CTextField(FIELDLENGTH); - CCheckBox okAppsServer = new CCheckBox(); - private CLabel lAppsType = new CLabel(); - CComboBox fAppsType = new CComboBox(ConfigurationData.APPSTYPE); - // Deployment Directory - JNP - private CLabel lDeployDir = new CLabel(); - CTextField fDeployDir = new CTextField(FIELDLENGTH); - CCheckBox okDeployDir = new CCheckBox(); - CButton bDeployDir = new CButton(iOpen); - private CLabel lJNPPort = new CLabel(); - CTextField fJNPPort = new CTextField(FIELDLENGTH); - CCheckBox okJNPPort = new CCheckBox(); - // Web Ports - private CLabel lWebPort = new CLabel(); - CTextField fWebPort = new CTextField(FIELDLENGTH); - CCheckBox okWebPort = new CCheckBox(); - private CLabel lSSLPort = new CLabel(); - CTextField fSSLPort = new CTextField(FIELDLENGTH); - CCheckBox okSSLPort = new CCheckBox(); - // Database - private CLabel lDatabaseType = new CLabel(); - CComboBox fDatabaseType = new CComboBox(ConfigurationData.DBTYPE); - // - CLabel lDatabaseServer = new CLabel(); - CTextField fDatabaseServer = new CTextField(FIELDLENGTH); - private CLabel lDatabaseName = new CLabel(); - CTextField fDatabaseName = new CTextField(FIELDLENGTH); - private CLabel lDatabaseDiscovered = new CLabel(); - CComboBox fDatabaseDiscovered = new CComboBox(); - private CLabel lDatabasePort = new CLabel(); - CTextField fDatabasePort = new CTextField(FIELDLENGTH); - private CLabel lSystemPassword = new CLabel(); - CPassword fSystemPassword = new CPassword(); - private CLabel lDatabaseUser = new CLabel(); - CTextField fDatabaseUser = new CTextField(FIELDLENGTH); - private CLabel lDatabasePassword = new CLabel(); - CPassword fDatabasePassword = new CPassword(); - CCheckBox okDatabaseServer = new CCheckBox(); - CCheckBox okDatabaseUser = new CCheckBox(); - CCheckBox okDatabaseSystem = new CCheckBox(); - CCheckBox okDatabaseSQL = new CCheckBox(); - // - CLabel lMailServer = new CLabel(); - CTextField fMailServer = new CTextField(FIELDLENGTH); - private CLabel lAdminEMail = new CLabel(); - CTextField fAdminEMail = new CTextField(FIELDLENGTH); - private CLabel lMailUser = new CLabel(); - CTextField fMailUser = new CTextField(FIELDLENGTH); - private CLabel lMailPassword = new CLabel(); - CPassword fMailPassword = new CPassword(); - CCheckBox okMailServer = new CCheckBox(); - CCheckBox okMailUser = new CCheckBox(); - // - private CButton bHelp = new CButton(iHelp); - private CButton bTest = new CButton(); - private CButton bSave = new CButton(iSave); - - - /** - * Static Layout Init - * @throws Exception - */ - private void jbInit() throws Exception - { - this.setLayout(gridBagLayout); - Insets bInsets = new Insets(0, 5, 0, 5); - TitledBorder titledBorder = new TitledBorder("dummy"); - - // Java - lJavaHome.setToolTipText(res.getString("JavaHomeInfo")); - lJavaHome.setText(res.getString("JavaHome")); - fJavaHome.setText("."); - okJavaHome.setEnabled(false); - bJavaHome.setMargin(bInsets); - bJavaHome.setToolTipText(res.getString("JavaHomeInfo")); - lJavaType.setToolTipText(res.getString("JavaTypeInfo")); - lJavaType.setText(res.getString("JavaType")); - fJavaType.setPreferredSize(fJavaHome.getPreferredSize()); - - JLabel sectionLabel = new JLabel("Java"); - sectionLabel.setForeground(titledBorder.getTitleColor()); - JSeparator separator = new JSeparator(); - this.add(sectionLabel, new GridBagConstraints(0, 0, 7, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 5, 0, 10), 0, 0)); - this.add(separator, new GridBagConstraints(0, 1, 7, 1, 1.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 10), 0, 0)); - - this.add(lJavaHome, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fJavaHome, new GridBagConstraints(1, 2, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 0), 0, 0)); - this.add(okJavaHome, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 2, 5), 0, 0)); - this.add(bJavaHome, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); - this.add(lJavaType, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fJavaType, new GridBagConstraints(5, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 2, 0), 0, 0)); - // AdempiereHome - KeyStore - lAdempiereHome.setToolTipText(res.getString("AdempiereHomeInfo")); - lAdempiereHome.setText(res.getString("AdempiereHome")); - fAdempiereHome.setText("."); - okAdempiereHome.setEnabled(false); - bAdempiereHome.setMargin(bInsets); - bAdempiereHome.setToolTipText(res.getString("AdempiereHomeInfo")); - lKeyStore.setText(res.getString("KeyStorePassword")); - lKeyStore.setToolTipText(res.getString("KeyStorePasswordInfo")); - fKeyStore.setText(""); - okKeyStore.setEnabled(false); - - sectionLabel = new JLabel("Adempiere"); - sectionLabel.setForeground(titledBorder.getTitleColor()); - separator = new JSeparator(); - this.add(sectionLabel, new GridBagConstraints(0, 3, 7, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 5, 0, 0), 0, 0)); - this.add(separator, new GridBagConstraints(0, 4, 7, 1, 1.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 10), 0, 0)); - this.add(lAdempiereHome, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fAdempiereHome, new GridBagConstraints(1, 5, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 2, 0), 0, 0)); - this.add(okAdempiereHome, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 2, 5), 0, 0)); - this.add(bAdempiereHome, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); - this.add(lKeyStore, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0 - ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); - this.add(fKeyStore, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 2, 0), 0, 0)); - this.add(okKeyStore, new GridBagConstraints(6, 5, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - // Apps Server - Type - lAppsServer.setToolTipText(res.getString("AppsServerInfo")); - lAppsServer.setText(res.getString("AppsServer")); - lAppsServer.setFont(lAppsServer.getFont().deriveFont(Font.BOLD)); - fAppsServer.setText("."); - okAppsServer.setEnabled(false); - lAppsType.setToolTipText(res.getString("AppsTypeInfo")); - lAppsType.setText(res.getString("AppsType")); - fAppsType.setPreferredSize(fAppsServer.getPreferredSize()); - sectionLabel = new JLabel(res.getString("AppsServer")); - sectionLabel.setForeground(titledBorder.getTitleColor()); - separator = new JSeparator(); - this.add(sectionLabel, new GridBagConstraints(0, 6, 6, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 5, 0, 0), 0, 0)); - this.add(separator, new GridBagConstraints(0, 7, 7, 1, 1.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 10), 0, 0)); - this.add(lAppsServer, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fAppsServer, new GridBagConstraints(1, 8, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 2, 0), 0, 0)); - this.add(okAppsServer, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 2, 5), 0, 0)); - this.add(lAppsType, new GridBagConstraints(4, 8, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fAppsType, new GridBagConstraints(5, 8, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 2, 0), 0, 0)); - // Deployment - JNP - lDeployDir.setToolTipText(res.getString("DeployDirInfo")); - lDeployDir.setText(res.getString("DeployDir")); - fDeployDir.setText("."); - okDeployDir.setEnabled(false); - bDeployDir.setMargin(bInsets); - bDeployDir.setToolTipText(res.getString("DeployDirInfo")); - lJNPPort.setToolTipText(res.getString("JNPPortInfo")); - lJNPPort.setText(res.getString("JNPPort")); - fJNPPort.setText("."); - okJNPPort.setEnabled(false); - this.add(lDeployDir, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fDeployDir, new GridBagConstraints(1, 9, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okDeployDir, new GridBagConstraints(2, 9, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - this.add(bDeployDir, new GridBagConstraints(3, 9, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); - this.add(lJNPPort, new GridBagConstraints(4, 9, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fJNPPort, new GridBagConstraints(5, 9, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okJNPPort, new GridBagConstraints(6, 9, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - // Web Ports - lWebPort.setToolTipText(res.getString("WebPortInfo")); - lWebPort.setText(res.getString("WebPort")); - fWebPort.setText("."); - okWebPort.setEnabled(false); - lSSLPort.setText("SSL"); - fSSLPort.setText("."); - okSSLPort.setEnabled(false); - this.add(lWebPort, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fWebPort, new GridBagConstraints(1, 10, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okWebPort, new GridBagConstraints(2, 10, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - this.add(lSSLPort, new GridBagConstraints(4, 10, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fSSLPort, new GridBagConstraints(5, 10, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okSSLPort, new GridBagConstraints(6, 10, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - // Database Server - Type - lDatabaseServer.setToolTipText(res.getString("DatabaseServerInfo")); - lDatabaseServer.setText(res.getString("DatabaseServer")); - lDatabaseServer.setFont(lDatabaseServer.getFont().deriveFont(Font.BOLD)); - okDatabaseServer.setEnabled(false); - lDatabaseType.setToolTipText(res.getString("DatabaseTypeInfo")); - lDatabaseType.setText(res.getString("DatabaseType")); - fDatabaseType.setPreferredSize(fDatabaseServer.getPreferredSize()); - sectionLabel = new JLabel(res.getString("DatabaseServer")); - sectionLabel.setForeground(titledBorder.getTitleColor()); - separator = new JSeparator(); - this.add(sectionLabel, new GridBagConstraints(0, 11, 6, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 5, 0, 0), 0, 0)); - this.add(separator, new GridBagConstraints(0, 12, 7, 1, 1.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 10), 0, 0)); - this.add(lDatabaseServer, new GridBagConstraints(0, 13, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fDatabaseServer, new GridBagConstraints(1, 13, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 2, 0), 0, 0)); - this.add(okDatabaseServer, new GridBagConstraints(2, 13, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 2, 5), 0, 0)); - this.add(lDatabaseType, new GridBagConstraints(4, 13, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fDatabaseType, new GridBagConstraints(5, 13, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 2, 0), 0, 0)); - //Database/Service Name - lDatabaseName.setToolTipText(res.getString("DatabaseNameInfo")); - lDatabaseName.setText(res.getString("DatabaseName")); - fDatabaseName.setText("."); - - //TNS/Native connection - lDatabaseDiscovered.setToolTipText(res.getString("TNSNameInfo")); - lDatabaseDiscovered.setText(res.getString("TNSName")); - fDatabaseDiscovered.setEditable(true); - fDatabaseDiscovered.setPreferredSize(fDatabaseName.getPreferredSize()); - okDatabaseSQL.setEnabled(false); - this.add(lDatabaseName, new GridBagConstraints(0, 14, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fDatabaseName, new GridBagConstraints(1, 14, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okDatabaseSQL, new GridBagConstraints(2, 14, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - this.add(lDatabaseDiscovered, new GridBagConstraints(4, 14, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - this.add(fDatabaseDiscovered, new GridBagConstraints(5, 14, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - // Port - System - lDatabasePort.setToolTipText(res.getString("DatabasePortInfo")); - lDatabasePort.setText(res.getString("DatabasePort")); - fDatabasePort.setText("."); - lSystemPassword.setToolTipText(res.getString("SystemPasswordInfo")); - lSystemPassword.setText(res.getString("SystemPassword")); - fSystemPassword.setText("."); - okDatabaseSystem.setEnabled(false); - this.add(lDatabasePort, new GridBagConstraints(0, 15, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fDatabasePort, new GridBagConstraints(1, 15, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(lSystemPassword, new GridBagConstraints(4, 15, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fSystemPassword, new GridBagConstraints(5, 15, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okDatabaseSystem, new GridBagConstraints(6, 15, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - - // User - Password - lDatabaseUser.setToolTipText(res.getString("DatabaseUserInfo")); - lDatabaseUser.setText(res.getString("DatabaseUser")); - fDatabaseUser.setText("."); - lDatabasePassword.setToolTipText(res.getString("DatabasePasswordInfo")); - lDatabasePassword.setText(res.getString("DatabasePassword")); - fDatabasePassword.setText("."); - okDatabaseUser.setEnabled(false); - this.add(lDatabaseUser, new GridBagConstraints(0, 16, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fDatabaseUser, new GridBagConstraints(1, 16, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(lDatabasePassword, new GridBagConstraints(4, 16, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fDatabasePassword, new GridBagConstraints(5, 16, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okDatabaseUser, new GridBagConstraints(6, 16, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - - sectionLabel = new JLabel(res.getString("MailServer")); - sectionLabel.setForeground(titledBorder.getTitleColor()); - separator = new JSeparator(); - this.add(sectionLabel, new GridBagConstraints(0, 17, 6, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 5, 0, 0), 0, 0)); - this.add(separator, new GridBagConstraints(0, 18, 7, 1, 1.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 10), 0, 0)); - // Mail Server - Email - lMailServer.setToolTipText(res.getString("MailServerInfo")); - lMailServer.setText(res.getString("MailServer")); - lMailServer.setFont(lMailServer.getFont().deriveFont(Font.BOLD)); - fMailServer.setText("."); - lAdminEMail.setToolTipText(res.getString("AdminEMailInfo")); - lAdminEMail.setText(res.getString("AdminEMail")); - fAdminEMail.setText("."); - okMailServer.setEnabled(false); - this.add(lMailServer, new GridBagConstraints(0, 19, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fMailServer, new GridBagConstraints(1, 19, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 2, 0), 0, 0)); - this.add(okMailServer, new GridBagConstraints(2, 19, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 2, 5), 0, 0)); - this.add(lAdminEMail, new GridBagConstraints(4, 19, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); - this.add(fAdminEMail, new GridBagConstraints(5, 19, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 2, 0), 0, 0)); - - // Mail User = Password - lMailUser.setToolTipText(res.getString("MailUserInfo")); - lMailUser.setText(res.getString("MailUser")); - fMailUser.setText("."); - lMailPassword.setToolTipText(res.getString("MailPasswordInfo")); - lMailPassword.setText(res.getString("MailPassword")); - fMailPassword.setText("."); - okMailUser.setEnabled(false); - this.add(lMailUser, new GridBagConstraints(0, 20, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fMailUser, new GridBagConstraints(1, 20, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 0), 0, 0)); - this.add(lMailPassword, new GridBagConstraints(4, 20, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); - this.add(fMailPassword, new GridBagConstraints(5, 20, 1, 1, 0.5, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 5, 2, 0), 0, 0)); - this.add(okMailUser, new GridBagConstraints(6, 20, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0)); - - //grap extra space when window is maximized - CPanel filler = new CPanel(); - filler.setOpaque(false); - filler.setBorder(null); - this.add(filler, new GridBagConstraints(0, 21, 1, 1, 0.0, 1.0 - ,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); - - // End - bTest.setToolTipText(res.getString("TestInfo")); - bTest.setText(res.getString("Test")); - bSave.setToolTipText(res.getString("SaveInfo")); - bSave.setText(res.getString("Save")); - bHelp.setToolTipText(res.getString("HelpInfo")); - this.add(bTest, new GridBagConstraints(0, 22, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 5, 10, 5), 0, 0)); - this.add(bHelp, new GridBagConstraints(3, 22, 2, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 5, 10, 5), 0, 0)); - this.add(bSave, new GridBagConstraints(5, 22, 2, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(15, 5, 10, 5), 0, 0)); - // - bAdempiereHome.addActionListener(this); - bJavaHome.addActionListener(this); - bDeployDir.addActionListener(this); - fJavaType.addActionListener(this); - fAppsType.addActionListener(this); - fDatabaseType.addActionListener(this); - fDatabaseDiscovered.addActionListener(this); - bHelp.addActionListener(this); - bTest.addActionListener(this); - bSave.addActionListener(this); - } // jbInit - - /** - * Dynamic Initial. - * Called by Setup - * @return true if success - */ - public boolean dynInit() - { - return m_data.load(); - } // dynInit - - /** - * Set Status Bar Text - * @param text text - */ - protected void setStatusBar(String text) - { - m_statusBar.setText(text); - } // setStatusBar - - - /************************************************************************** - * ActionListener - * @param e event - */ - public void actionPerformed(ActionEvent e) - { - if (m_testing) - return; - // TNS Name Changed - if (e.getSource() == fDatabaseDiscovered) - { - String dbName = (String)fDatabaseDiscovered.getSelectedItem(); - if (dbName != null && dbName.length() > 0) - fDatabaseName.setText(m_data.resolveDatabaseName(dbName)); - } - // - else if (e.getSource() == fJavaType) - m_data.initJava(); - else if (e.getSource() == fAppsType) - m_data.initAppsServer(); - else if (e.getSource() == fDatabaseType) - m_data.initDatabase(""); - // - else if (e.getSource() == bJavaHome) - setPath (fJavaHome); - else if (e.getSource() == bAdempiereHome) - setPath (fAdempiereHome); - else if (e.getSource() == bDeployDir) - setPath (fDeployDir); - else if (e.getSource() == bHelp) - new Setup_Help((Frame)SwingUtilities.getWindowAncestor(this)); - else if (e.getSource() == bTest) - startTest(false); - else if (e.getSource() == bSave) - startTest(true); - } // actionPerformed - - - - /** - * Set Path in Field - * @param field field to set Path - */ - private void setPath (CTextField field) - { - JFileChooser fc = new JFileChooser(field.getText()); - fc.setDialogType(JFileChooser.OPEN_DIALOG); - fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - fc.setMultiSelectionEnabled(false); - fc.setDialogTitle(field.getToolTipText()); - if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) - field.setText(fc.getSelectedFile().getAbsolutePath()); - } // setPath - - - /************************************************************************** - * Start Test Async. - * @param saveIt save - * @return SwingWorker - */ - private SwingWorker startTest(final boolean saveIt) - { - SwingWorker worker = new SwingWorker() - { - // Start it - public Object construct() - { - m_testing = true; - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - bTest.setEnabled(false); - m_success = false; - m_errorString = null; - try - { - test(); - } - catch (Exception ex) - { - ex.printStackTrace(); - m_errorString += "\n" + ex.toString(); - } - // - setCursor(Cursor.getDefaultCursor()); - if (m_errorString == null) - m_success = true; - bTest.setEnabled(true); - m_testing = false; - return new Boolean(m_success); - } - // Finish it - public void finished() - { - if (m_errorString != null) - { - CLogger.get().severe(m_errorString); - JOptionPane.showConfirmDialog (m_statusBar.getParent(), - m_errorString, - res.getString("ServerError"), - JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); - } - else if (saveIt) - save(); - } - }; - worker.start(); - return worker; - } // startIt - - /** - * Test it - * @throws Exception - */ - private void test() throws Exception - { - bSave.setEnabled(false); - if (!m_data.test()) - return; - // - m_statusBar.setText(res.getString("Ok")); - bSave.setEnabled(true); - m_errorString = null; - } // test - - /** - * UI Signal OK - * @param cb ckeck box - * @param resString resource string key - * @param pass true if test passed - * @param critical true if critial - * @param errorMsg error Message - */ - void signalOK (CCheckBox cb, String resString, - boolean pass, boolean critical, String errorMsg) - { - m_errorString = res.getString(resString); - cb.setSelected(pass); - if (pass) - cb.setToolTipText(null); - else - { - cb.setToolTipText(errorMsg); - m_errorString += " \n(" + errorMsg + ")"; - } - if (!pass && critical) - cb.setBackground(Color.RED); - else - cb.setBackground(Color.GREEN); - } // setOK - - - /************************************************************************** - * Save Settings. - * Called from startTest.finished() - */ - private void save() - { - if (!m_success) - return; - - bSave.setEnabled(false); - bTest.setEnabled(false); - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - if (!m_data.save()) - return; - - // Final Info - JOptionPane.showConfirmDialog(this, res.getString("EnvironmentSaved"), - res.getString("AdempiereServerSetup"), - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); - - /** Run Ant **/ - try - { - CLogger.get().info("Starting Ant ... "); - System.setProperty("ant.home", "."); - String[] args = new String[] {"setup"}; - // Launcher.main (args); // calls System.exit - Main antMain = new Main(); - antMain.startAnt(args, null, null); - } - catch (Exception e) - { - CLogger.get().log(Level.SEVERE, "ant", e); - } - - // To be sure - ((Frame)SwingUtilities.getWindowAncestor(this)).dispose(); - System.exit(0); // remains active when License Dialog called - /** **/ - } // save - -} // ConfigurationPanel +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.install; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.util.logging.*; +import javax.swing.*; +import javax.swing.border.TitledBorder; +import javax.swing.plaf.metal.MetalLookAndFeel; + +import org.apache.tools.ant.*; +import org.compiere.*; +import org.compiere.apps.*; +import org.compiere.swing.*; +import org.compiere.util.*; + + +/** + * Configuration Panel + * + * @author Jorg Janke + * @version $Id: ConfigurationPanel.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ + */ +public class ConfigurationPanel extends CPanel implements ActionListener +{ + /** + * Constructor + * @param statusBar for info + */ + public ConfigurationPanel (JLabel statusBar) + { + m_statusBar = statusBar; + try + { + jbInit(); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + } // ConfigurationPanel + + /** Error Info */ + private String m_errorString; + /** Test Success */ + private volatile boolean m_success = false; + /** Sync */ + private volatile boolean m_testing = false; + + /** Translation */ + static ResourceBundle res = ResourceBundle.getBundle("org.compiere.install.SetupRes"); + + /** Setup Frame */ + private Setup m_setup = null; + /** Status Bar */ + private JLabel m_statusBar; + /** Configuration Data */ + private ConfigurationData m_data = new ConfigurationData(this); + + private static ImageIcon iOpen = new ImageIcon(ConfigurationPanel.class.getResource("openFile.gif")); + private static ImageIcon iSave = new ImageIcon(Adempiere.class.getResource("images/Save16.gif")); + private static ImageIcon iHelp = new ImageIcon(Adempiere.class.getResource("images/Help16.gif")); + + + // ------------- Static UI + private GridBagLayout gridBagLayout = new GridBagLayout(); + private static final int FIELDLENGTH = 15; + // Java + private CLabel lJavaHome = new CLabel(); + CTextField fJavaHome = new CTextField(FIELDLENGTH); + CCheckBox okJavaHome = new CCheckBox(); + private CButton bJavaHome = new CButton(iOpen); + private CLabel lJavaType = new CLabel(); + CComboBox fJavaType = new CComboBox(ConfigurationData.JAVATYPE); + // Adempiere - KeyStore + private CLabel lAdempiereHome = new CLabel(); + CTextField fAdempiereHome = new CTextField(FIELDLENGTH); + CCheckBox okAdempiereHome = new CCheckBox(); + private CButton bAdempiereHome = new CButton(iOpen); + private CLabel lKeyStore = new CLabel(); + CPassword fKeyStore = new CPassword(); + CCheckBox okKeyStore = new CCheckBox(); + // Apps Server - Type + CLabel lAppsServer = new CLabel(); + CTextField fAppsServer = new CTextField(FIELDLENGTH); + CCheckBox okAppsServer = new CCheckBox(); + private CLabel lAppsType = new CLabel(); + CComboBox fAppsType = new CComboBox(ConfigurationData.APPSTYPE); + // Deployment Directory - JNP + private CLabel lDeployDir = new CLabel(); + CTextField fDeployDir = new CTextField(FIELDLENGTH); + CCheckBox okDeployDir = new CCheckBox(); + CButton bDeployDir = new CButton(iOpen); + private CLabel lJNPPort = new CLabel(); + CTextField fJNPPort = new CTextField(FIELDLENGTH); + CCheckBox okJNPPort = new CCheckBox(); + // Web Ports + private CLabel lWebPort = new CLabel(); + CTextField fWebPort = new CTextField(FIELDLENGTH); + CCheckBox okWebPort = new CCheckBox(); + private CLabel lSSLPort = new CLabel(); + CTextField fSSLPort = new CTextField(FIELDLENGTH); + CCheckBox okSSLPort = new CCheckBox(); + // Database + private CLabel lDatabaseType = new CLabel(); + CComboBox fDatabaseType = new CComboBox(ConfigurationData.DBTYPE); + // + CLabel lDatabaseServer = new CLabel(); + CTextField fDatabaseServer = new CTextField(FIELDLENGTH); + private CLabel lDatabaseName = new CLabel(); + CTextField fDatabaseName = new CTextField(FIELDLENGTH); + private CLabel lDatabaseDiscovered = new CLabel(); + CComboBox fDatabaseDiscovered = new CComboBox(); + private CLabel lDatabasePort = new CLabel(); + CTextField fDatabasePort = new CTextField(FIELDLENGTH); + private CLabel lSystemPassword = new CLabel(); + CPassword fSystemPassword = new CPassword(); + private CLabel lDatabaseUser = new CLabel(); + CTextField fDatabaseUser = new CTextField(FIELDLENGTH); + private CLabel lDatabasePassword = new CLabel(); + CPassword fDatabasePassword = new CPassword(); + CCheckBox okDatabaseServer = new CCheckBox(); + CCheckBox okDatabaseUser = new CCheckBox(); + CCheckBox okDatabaseSystem = new CCheckBox(); + CCheckBox okDatabaseSQL = new CCheckBox(); + // + CLabel lMailServer = new CLabel(); + CTextField fMailServer = new CTextField(FIELDLENGTH); + private CLabel lAdminEMail = new CLabel(); + CTextField fAdminEMail = new CTextField(FIELDLENGTH); + private CLabel lMailUser = new CLabel(); + CTextField fMailUser = new CTextField(FIELDLENGTH); + private CLabel lMailPassword = new CLabel(); + CPassword fMailPassword = new CPassword(); + CCheckBox okMailServer = new CCheckBox(); + CCheckBox okMailUser = new CCheckBox(); + // + private CButton bHelp = new CButton(iHelp); + private CButton bTest = new CButton(); + private CButton bSave = new CButton(iSave); + + + /** + * Static Layout Init + * @throws Exception + */ + private void jbInit() throws Exception + { + this.setLayout(gridBagLayout); + Insets bInsets = new Insets(0, 5, 0, 5); + TitledBorder titledBorder = new TitledBorder("dummy"); + + // Java + lJavaHome.setToolTipText(res.getString("JavaHomeInfo")); + lJavaHome.setText(res.getString("JavaHome")); + fJavaHome.setText("."); + okJavaHome.setEnabled(false); + bJavaHome.setMargin(bInsets); + bJavaHome.setToolTipText(res.getString("JavaHomeInfo")); + lJavaType.setToolTipText(res.getString("JavaTypeInfo")); + lJavaType.setText(res.getString("JavaType")); + fJavaType.setPreferredSize(fJavaHome.getPreferredSize()); + this.add(lJavaHome, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fJavaHome, new GridBagConstraints(1, 0, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okJavaHome, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + this.add(bJavaHome, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + this.add(lJavaType, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fJavaType, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + // AdempiereHome - KeyStore + lAdempiereHome.setToolTipText(res.getString("AdempiereHomeInfo")); + lAdempiereHome.setText(res.getString("AdempiereHome")); + fAdempiereHome.setText("."); + okAdempiereHome.setEnabled(false); + bAdempiereHome.setMargin(bInsets); + bAdempiereHome.setToolTipText(res.getString("AdempiereHomeInfo")); + lKeyStore.setText(res.getString("KeyStorePassword")); + lKeyStore.setToolTipText(res.getString("KeyStorePasswordInfo")); + fKeyStore.setText(""); + okKeyStore.setEnabled(false); + this.add(lAdempiereHome, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fAdempiereHome, new GridBagConstraints(1, 1, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okAdempiereHome, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + this.add(bAdempiereHome, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + this.add(lKeyStore, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + this.add(fKeyStore, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okKeyStore, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + // Apps Server - Type + lAppsServer.setToolTipText(res.getString("AppsServerInfo")); + lAppsServer.setText(res.getString("AppsServer")); + lAppsServer.setFont(lAppsServer.getFont().deriveFont(Font.BOLD)); + fAppsServer.setText("."); + okAppsServer.setEnabled(false); + lAppsType.setToolTipText(res.getString("AppsTypeInfo")); + lAppsType.setText(res.getString("AppsType")); + fAppsType.setPreferredSize(fAppsServer.getPreferredSize()); + this.add(lAppsServer, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); + this.add(fAppsServer, new GridBagConstraints(1, 2, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 0), 0, 0)); + this.add(okAppsServer, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 5, 5), 0, 0)); + this.add(lAppsType, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); + this.add(fAppsType, new GridBagConstraints(5, 2, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 0), 0, 0)); + // Deployment - JNP + lDeployDir.setToolTipText(res.getString("DeployDirInfo")); + lDeployDir.setText(res.getString("DeployDir")); + fDeployDir.setText("."); + okDeployDir.setEnabled(false); + bDeployDir.setMargin(bInsets); + bDeployDir.setToolTipText(res.getString("DeployDirInfo")); + lJNPPort.setToolTipText(res.getString("JNPPortInfo")); + lJNPPort.setText(res.getString("JNPPort")); + fJNPPort.setText("."); + okJNPPort.setEnabled(false); + this.add(lDeployDir, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fDeployDir, new GridBagConstraints(1, 3, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okDeployDir, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + this.add(bDeployDir, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + this.add(lJNPPort, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fJNPPort, new GridBagConstraints(5, 3, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okJNPPort, new GridBagConstraints(6, 3, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + // Web Ports + lWebPort.setToolTipText(res.getString("WebPortInfo")); + lWebPort.setText(res.getString("WebPort")); + fWebPort.setText("."); + okWebPort.setEnabled(false); + lSSLPort.setText("SSL"); + fSSLPort.setText("."); + okSSLPort.setEnabled(false); + this.add(lWebPort, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fWebPort, new GridBagConstraints(1, 4, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okWebPort, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + this.add(lSSLPort, new GridBagConstraints(4, 4, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fSSLPort, new GridBagConstraints(5, 4, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okSSLPort, new GridBagConstraints(6, 4, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + // Database Server - Type + lDatabaseServer.setToolTipText(res.getString("DatabaseServerInfo")); + lDatabaseServer.setText(res.getString("DatabaseServer")); + lDatabaseServer.setFont(lDatabaseServer.getFont().deriveFont(Font.BOLD)); + okDatabaseServer.setEnabled(false); + lDatabaseType.setToolTipText(res.getString("DatabaseTypeInfo")); + lDatabaseType.setText(res.getString("DatabaseType")); + fDatabaseType.setPreferredSize(fDatabaseServer.getPreferredSize()); + this.add(lDatabaseServer, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); + this.add(fDatabaseServer, new GridBagConstraints(1, 5, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 0), 0, 0)); + this.add(okDatabaseServer, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 5, 5), 0, 0)); + this.add(lDatabaseType, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); + this.add(fDatabaseType, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 0), 0, 0)); + // DB Name - TNS + lDatabaseName.setToolTipText(res.getString("DatabaseNameInfo")); + lDatabaseName.setText(res.getString("DatabaseName")); + fDatabaseName.setText("."); + lDatabaseDiscovered.setToolTipText(res.getString("TNSNameInfo")); + lDatabaseDiscovered.setText(res.getString("TNSName")); + fDatabaseDiscovered.setEditable(true); + fDatabaseDiscovered.setPreferredSize(fDatabaseName.getPreferredSize()); + okDatabaseSQL.setEnabled(false); + this.add(lDatabaseName, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fDatabaseName, new GridBagConstraints(1, 6, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okDatabaseSQL, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + this.add(lDatabaseDiscovered, new GridBagConstraints(4, 6, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + this.add(fDatabaseDiscovered, new GridBagConstraints(5, 6, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + // Port - System + lDatabasePort.setToolTipText(res.getString("DatabasePortInfo")); + lDatabasePort.setText(res.getString("DatabasePort")); + fDatabasePort.setText("."); + lSystemPassword.setToolTipText(res.getString("SystemPasswordInfo")); + lSystemPassword.setText(res.getString("SystemPassword")); + fSystemPassword.setText("."); + okDatabaseSystem.setEnabled(false); + this.add(lDatabasePort, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fDatabasePort, new GridBagConstraints(1, 7, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(lSystemPassword, new GridBagConstraints(4, 7, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fSystemPassword, new GridBagConstraints(5, 7, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okDatabaseSystem, new GridBagConstraints(6, 7, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + + // User - Password + lDatabaseUser.setToolTipText(res.getString("DatabaseUserInfo")); + lDatabaseUser.setText(res.getString("DatabaseUser")); + fDatabaseUser.setText("."); + lDatabasePassword.setToolTipText(res.getString("DatabasePasswordInfo")); + lDatabasePassword.setText(res.getString("DatabasePassword")); + fDatabasePassword.setText("."); + okDatabaseUser.setEnabled(false); + this.add(lDatabaseUser, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fDatabaseUser, new GridBagConstraints(1, 8, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(lDatabasePassword, new GridBagConstraints(4, 8, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fDatabasePassword, new GridBagConstraints(5, 8, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okDatabaseUser, new GridBagConstraints(6, 8, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + + // Mail Server - Email + lMailServer.setToolTipText(res.getString("MailServerInfo")); + lMailServer.setText(res.getString("MailServer")); + lMailServer.setFont(lMailServer.getFont().deriveFont(Font.BOLD)); + fMailServer.setText("."); + lAdminEMail.setToolTipText(res.getString("AdminEMailInfo")); + lAdminEMail.setText(res.getString("AdminEMail")); + fAdminEMail.setText("."); + okMailServer.setEnabled(false); + this.add(lMailServer, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); + this.add(fMailServer, new GridBagConstraints(1, 9, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 0), 0, 0)); + this.add(okMailServer, new GridBagConstraints(2, 9, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 5, 5), 0, 0)); + this.add(lAdminEMail, new GridBagConstraints(4, 9, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); + this.add(fAdminEMail, new GridBagConstraints(5, 9, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 0), 0, 0)); + + // Mail User = Password + lMailUser.setToolTipText(res.getString("MailUserInfo")); + lMailUser.setText(res.getString("MailUser")); + fMailUser.setText("."); + lMailPassword.setToolTipText(res.getString("MailPasswordInfo")); + lMailPassword.setText(res.getString("MailPassword")); + fMailPassword.setText("."); + okMailUser.setEnabled(false); + this.add(lMailUser, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fMailUser, new GridBagConstraints(1, 10, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(lMailPassword, new GridBagConstraints(4, 10, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + this.add(fMailPassword, new GridBagConstraints(5, 10, 1, 1, 0.5, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 0), 0, 0)); + this.add(okMailUser, new GridBagConstraints(6, 10, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + + // End + bTest.setToolTipText(res.getString("TestInfo")); + bTest.setText(res.getString("Test")); + bSave.setToolTipText(res.getString("SaveInfo")); + bSave.setText(res.getString("Save")); + bHelp.setToolTipText(res.getString("HelpInfo")); + this.add(bTest, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 10, 5), 0, 0)); + this.add(bHelp, new GridBagConstraints(3, 11, 2, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 10, 5), 0, 0)); + this.add(bSave, new GridBagConstraints(5, 11, 2, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 10, 5), 0, 0)); + // + bAdempiereHome.addActionListener(this); + bJavaHome.addActionListener(this); + bDeployDir.addActionListener(this); + fJavaType.addActionListener(this); + fAppsType.addActionListener(this); + fDatabaseType.addActionListener(this); + fDatabaseDiscovered.addActionListener(this); + bHelp.addActionListener(this); + bTest.addActionListener(this); + bSave.addActionListener(this); + } // jbInit + + /** + * Dynamic Initial. + * Called by Setup + * @return true if success + */ + public boolean dynInit() + { + return m_data.load(); + } // dynInit + + /** + * Set Status Bar Text + * @param text text + */ + protected void setStatusBar(String text) + { + m_statusBar.setText(text); + } // setStatusBar + + + /************************************************************************** + * ActionListener + * @param e event + */ + public void actionPerformed(ActionEvent e) + { + if (m_testing) + return; + // TNS Name Changed + if (e.getSource() == fDatabaseDiscovered) + { + String dbName = (String)fDatabaseDiscovered.getSelectedItem(); + if (dbName != null && dbName.length() > 0) + fDatabaseName.setText(dbName); + } + // + else if (e.getSource() == fJavaType) + m_data.initJava(); + else if (e.getSource() == fAppsType) + m_data.initAppsServer(); + else if (e.getSource() == fDatabaseType) + m_data.initDatabase(""); + // + else if (e.getSource() == bJavaHome) + setPath (fJavaHome); + else if (e.getSource() == bAdempiereHome) + setPath (fAdempiereHome); + else if (e.getSource() == bDeployDir) + setPath (fDeployDir); + else if (e.getSource() == bHelp) + new Setup_Help((Frame)SwingUtilities.getWindowAncestor(this)); + else if (e.getSource() == bTest) + startTest(false); + else if (e.getSource() == bSave) + startTest(true); + } // actionPerformed + + + + /** + * Set Path in Field + * @param field field to set Path + */ + private void setPath (CTextField field) + { + JFileChooser fc = new JFileChooser(field.getText()); + fc.setDialogType(JFileChooser.OPEN_DIALOG); + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fc.setMultiSelectionEnabled(false); + fc.setDialogTitle(field.getToolTipText()); + if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) + field.setText(fc.getSelectedFile().getAbsolutePath()); + } // setPath + + + /************************************************************************** + * Start Test Async. + * @param saveIt save + * @return SwingWorker + */ + private org.compiere.apps.SwingWorker startTest(final boolean saveIt) + { + org.compiere.apps.SwingWorker worker = new org.compiere.apps.SwingWorker() + { + // Start it + public Object construct() + { + m_testing = true; + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + bTest.setEnabled(false); + m_success = false; + m_errorString = null; + try + { + test(); + } + catch (Exception ex) + { + ex.printStackTrace(); + m_errorString += "\n" + ex.toString(); + } + // + setCursor(Cursor.getDefaultCursor()); + if (m_errorString == null) + m_success = true; + bTest.setEnabled(true); + m_testing = false; + return new Boolean(m_success); + } + // Finish it + public void finished() + { + if (m_errorString != null) + { + CLogger.get().severe(m_errorString); + JOptionPane.showConfirmDialog (m_statusBar.getParent(), + m_errorString, + res.getString("ServerError"), + JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); + } + else if (saveIt) + save(); + } + }; + worker.start(); + return worker; + } // startIt + + /** + * Test it + * @throws Exception + */ + private void test() throws Exception + { + bSave.setEnabled(false); + if (!m_data.test()) + return; + // + m_statusBar.setText(res.getString("Ok")); + bSave.setEnabled(true); + m_errorString = null; + } // test + + /** + * UI Signal OK + * @param cb ckeck box + * @param resString resource string key + * @param pass true if test passed + * @param critical true if critial + * @param errorMsg error Message + */ + void signalOK (CCheckBox cb, String resString, + boolean pass, boolean critical, String errorMsg) + { + m_errorString = res.getString(resString); + cb.setSelected(pass); + if (pass) + cb.setToolTipText(null); + else + { + cb.setToolTipText(errorMsg); + m_errorString += " \n(" + errorMsg + ")"; + } + if (!pass && critical) + cb.setBackground(Color.RED); + else + cb.setBackground(Color.GREEN); + } // setOK + + + /************************************************************************** + * Save Settings. + * Called from startTest.finished() + */ + private void save() + { + if (!m_success) + return; + + bSave.setEnabled(false); + bTest.setEnabled(false); + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + if (!m_data.save()) + return; + + // Final Info + JOptionPane.showConfirmDialog(this, res.getString("EnvironmentSaved"), + res.getString("AdempiereServerSetup"), + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); + + /** Run Ant **/ + try + { + CLogger.get().info("Starting Ant ... "); + System.setProperty("ant.home", "."); + String[] args = new String[] {"setup"}; + // Launcher.main (args); // calls System.exit + Main antMain = new Main(); + antMain.startAnt(args, null, null); + } + catch (Exception e) + { + CLogger.get().log(Level.SEVERE, "ant", e); + } + + // To be sure + ((Frame)SwingUtilities.getWindowAncestor(this)).dispose(); + System.exit(0); // remains active when License Dialog called + /** **/ + } // save + +} // ConfigurationPanel diff --git a/install/src/org/compiere/install/KeyStoreMgt.java b/install/src/org/compiere/install/KeyStoreMgt.java index 25861fba24..765c7efd7d 100644 --- a/install/src/org/compiere/install/KeyStoreMgt.java +++ b/install/src/org/compiere/install/KeyStoreMgt.java @@ -1,426 +1,433 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.install; - -import java.io.*; -import java.net.*; -import java.security.*; -import java.security.cert.Certificate; -import java.util.*; -import java.util.logging.*; -import javax.swing.*; -import org.compiere.*; -import org.compiere.util.*; -import sun.security.tools.*; - -/** - * Class to manage SSL KeyStore - * - * @author Jorg Janke - * @version $Id: KeyStoreMgt.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ - */ -public class KeyStoreMgt -{ - /** - * Constructor. - * @param fileName key store file name - * @param password - same password for key store and certificate - */ - public KeyStoreMgt (String fileName, char[] password) - { - log.info(fileName); - m_file = new File (fileName); - m_password = password; - } // KeyStoreMgt - - /** Logger */ - private static CLogger log = CLogger.getCLogger(KeyStoreMgt.class); - /** KeyStore File */ - private File m_file = null; - /** KeyStore Password */ - private char[] m_password = null; - /** KeyStore */ - private KeyStore m_keyStore = null; - - - /** Directory below ADEMPIERE_HOME */ - public static String KEYSTORE_DIRECTORY = "keystore"; - /** Name of KeyStore */ - public static String KEYSTORE_NAME = "myKeystore"; - /** Certificate Alias */ - public static String CERTIFICATE_ALIAS = "adempiere"; - - - /** - * Verify/Create Key Store - * @param parent frame - * @return null or error message - */ - public String verify (JFrame parent) - { - KeyStore ks = null; - try - { - ks = getKeyStore(); - } - catch (Exception e) - { - log.log(Level.SEVERE, "get KeyStore", e); - return e.getMessage(); - } - // No KeyStore - if (ks == null) - { - createCertificate(CERTIFICATE_ALIAS, parent); - try - { - ks = getKeyStore(); - } - catch (Exception e) - { - log.log(Level.SEVERE, "new KeyStore", e); - return e.getMessage(); - } - } // new key store - - // No KeyStore - if (ks == null) - return "No Key Store"; - - // Verify Certificate - Certificate cert = null; - try - { - cert = getCertificate(CERTIFICATE_ALIAS); - } - catch (Exception e) - { - log.log(Level.SEVERE, "certificate", e); - return e.getMessage(); - } - if (cert == null) - return "No Certificate found"; - - return null; // OK - } // verify - - /** - * Get KeyStore - * @return KeyStore or null - * @throws Exception - */ - public KeyStore getKeyStore() throws Exception - { - try - { - m_keyStore = KeyStore.getInstance("JKS"); - } - catch (Exception e) - { - log.log(Level.SEVERE, "Instance", e); - } - // Load Existing - if (m_file.exists()) - { - log.fine(m_file.toString()); - InputStream is = null; - try - { - is = new FileInputStream (m_file); - } - catch (Exception e) - { - log.log(Level.SEVERE, "load", e); - return null; - } - m_keyStore.load(is, m_password); - } - else - return null; // does not exist - // - log.fine("Provider=" + m_keyStore.getProvider() - + " - Type=" + m_keyStore.getType()); - // - return m_keyStore; - } // getKeyStore - - /** - * Get Certificate - * @param alias alias - * @return certificate or null - * @throws Exception - */ - public Certificate getCertificate (String alias) throws Exception - { - log.config("Alias=" + alias); - - Date date = m_keyStore.getCreationDate(alias); - if (date == null) // no certificate - return null; - log.fine("Created=" + date); - // - Key key = m_keyStore.getKey(alias, m_password); - if (CLogMgt.isLevelFinest()) - log.info("Key=" + key); // Multiple lines - else - log.fine(key.getAlgorithm()); - // - Certificate cert = m_keyStore.getCertificate(alias); - if (CLogMgt.isLevelFinest()) - log.info("Certificate = " + cert); // Multiple lines - else - log.fine(cert.getType()); - - // log.fine("Certificate - Type=" + cert.getType() - // + " - PublicKey=" + cert.getPublicKey()); - return cert; - } // getCertificate - - - /************************************************************************** - * Create Certificate - * @param alias alias - * @param parent interactive dialog - */ - private void createCertificate (String alias, JFrame parent) - { - log.info(""); - try - { - File dir = m_file.getParentFile(); - if (!dir.exists()) - dir.mkdir(); - } - catch (Exception e) - { - log.log(Level.SEVERE, "directory", e); - } - - String dname = getDname(parent); - if (dname == null) - return; - // - try - { - genkey (alias, m_password, m_file.getAbsolutePath(), dname); - selfcert (alias, m_password, m_file.getAbsolutePath(), dname); - } - catch (Exception e) - { - log.log(Level.SEVERE, "certificate", e); - } - } // createCertificate - - /** - * Get Distinguised Name - * @param parent interactive dialog - * @return dname or null - */ - public static String getDname(JFrame parent) - { - String cn = null; - try - { - InetAddress address = InetAddress.getLocalHost(); - cn = address.getCanonicalHostName(); - } - catch (Exception e) - { - } - String ou = System.getProperty("user.name"); - String o = "AdempiereUser"; - String l = "MyTown"; - String s = ""; - String c = System.getProperty("user.country"); - // - if (parent != null) - { - KeyStoreDialog skd = new KeyStoreDialog(parent, - cn, ou, o, l, s, c); - if (!skd.isOK()) - return null; - cn = skd.getCN(); - ou = skd.getOU(); - o = skd.getO(); - l = skd.getL(); - s = skd.getS(); - c = skd.getC(); - } - // - if (cn == null || cn.length() == 0) - { - log.severe("No Common Name (CN)"); - return null; - } - if (ou == null || ou.length() == 0) - { - log.severe("No Organization Unit (OU)"); - return null; - } - if (o == null || o.length() == 0) - { - log.severe("No Organization (O)"); - return null; - } - if (c == null || c.length() == 0) - { - log.severe("No Country (C)"); - return null; - } - - // Escape commas - StringBuffer dname = new StringBuffer(); - dname.append("CN=").append(escapeCommas(cn)); // common name - dname.append(", OU=").append(escapeCommas(ou)); // org unit - dname.append(", O=").append(escapeCommas(o)); // org - if (l != null && l.length() > 0) - dname.append(", L=").append(escapeCommas(l)); // locality - if (s != null && s.length() > 0) - dname.append(", S=").append(escapeCommas(s)); // state - dname.append(", C=").append(escapeCommas(c)); // country - return dname.toString(); - } // getDname - - /** - * Escape Commas - * @param in input string - * @return excaped string - */ - public static String escapeCommas(String in) - { - if (in == null || in.indexOf(",") == -1) - return in; - StringBuffer out = new StringBuffer(); - char[] chars = in.toCharArray(); - for (int i = 0; i < chars.length; i++) - { - if (chars[i] == ',') - out.append('\\').append(','); - else - out.append(chars[i]); - } - return out.toString(); - } // escapeCommas - - /** - * Generate Key - * @param alias adempiere - * @param password password - * @param fileName key store file name (may have spaces) - * @param dname distinguished name - */ - public static void genkey (String alias, char[] password, String fileName, String dname) - { - StringBuffer cmd = new StringBuffer ("-genkey -keyalg rsa"); - cmd.append(" -alias ").append(alias); - cmd.append(" -dname \"").append(dname).append("\""); - cmd.append(" -keypass ").append(password).append(" -validity 365"); - if (fileName.indexOf(' ') != -1) - cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password); - else - cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password); - keytool (cmd.toString()); - } // genkey - - /** - * Generate Key - * @param alias adempiere - * @param password password - * @param fileName key store file name (may have spaces) - * @param dname distinguished name - */ - public static void selfcert (String alias, char[] password, String fileName, String dname) - { - StringBuffer cmd = new StringBuffer ("-selfcert"); - cmd.append(" -alias ").append(alias); - cmd.append(" -dname \"").append(dname).append("\""); - cmd.append(" -keypass ").append(password).append(" -validity 180"); - if (fileName.indexOf(' ') != -1) - cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password); - else - cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password); - keytool (cmd.toString()); - } // selfcert - - /** - * Submit Command to Key Tool - * @param cmd command - */ - public static void keytool(String cmd) - { - log.info("keytool " + cmd); - ArrayList list = new ArrayList(); - StringTokenizer st = new StringTokenizer(cmd, " "); - String quoteBuffer = null; - while (st.hasMoreTokens()) - { - String token = st.nextToken(); - // System.out.println("= " + token + " = quoteBuffer=" + quoteBuffer + " - Size=" + list.size() ); - if (quoteBuffer == null) - { - if (token.startsWith("\"")) - quoteBuffer = token.substring(1); - else - list.add(token); - } - else - quoteBuffer += " " + token; - if (token.endsWith("\"")) - { - String str = quoteBuffer.substring(0, quoteBuffer.length()-1); - // System.out.println(" Buffer= " + str ); - list.add(str); - quoteBuffer = null; - } - } // all tokens - - // - String[] args = new String[list.size()]; - list.toArray(args); - // System.out.println(" args #" + args.length); - KeyTool.main(args); - } // ketyool - - /** - * Get Keystore File Name - * @param baseDir ADEMPIERE_HOME - * @return file name - */ - public static String getKeystoreFileName (String baseDir) - { - String fileName = baseDir; - if (fileName == null) - fileName = ""; - else if (!fileName.endsWith(File.separator)) - fileName += File.separator; - fileName += KEYSTORE_DIRECTORY + File.separator + KEYSTORE_NAME; - return fileName; - } // getKeystoreFileName - - - /************************************************************************** - * Test - * @param args ignored - */ - public static void main (String[] args) - { - Adempiere.startupEnvironment(true); - System.out.println(new KeyStoreMgt ( - "C:/Adempiere/keystore/myKeystore2", "myPassword".toCharArray()).verify(null)); - } // main - -} // MyKeyStore +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.install; + +import java.io.*; +import java.net.*; +import java.security.*; +import java.security.cert.Certificate; +import java.util.*; +import java.util.logging.*; +import javax.swing.*; +import org.compiere.*; +import org.compiere.util.*; +import sun.security.tools.*; + +/** + * Class to manage SSL KeyStore + * + * @author Jorg Janke + * @version $Id: KeyStoreMgt.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $ + */ +public class KeyStoreMgt +{ + /** + * Constructor. + * @param fileName key store file name + * @param password - same password for key store and certificate + */ + public KeyStoreMgt (String fileName, char[] password) + { + log.info(fileName); + m_file = new File (fileName); + m_password = password; + } // KeyStoreMgt + + /** Logger */ + private static CLogger log = CLogger.getCLogger(KeyStoreMgt.class); + /** KeyStore File */ + private File m_file = null; + /** KeyStore Password */ + private char[] m_password = null; + /** KeyStore */ + private KeyStore m_keyStore = null; + + + /** Directory below ADEMPIERE_HOME */ + public static String KEYSTORE_DIRECTORY = "keystore"; + /** Name of KeyStore */ + public static String KEYSTORE_NAME = "myKeystore"; + /** Certificate Alias */ + public static String CERTIFICATE_ALIAS = "adempiere"; + + + /** + * Verify/Create Key Store + * @param parent frame + * @return null or error message + */ + public String verify (JFrame parent) + { + KeyStore ks = null; + try + { + ks = getKeyStore(); + } + catch (Exception e) + { + log.log(Level.SEVERE, "get KeyStore", e); + return e.getMessage(); + } + // No KeyStore + if (ks == null) + { + createCertificate(CERTIFICATE_ALIAS, parent); + try + { + ks = getKeyStore(); + } + catch (Exception e) + { + log.log(Level.SEVERE, "new KeyStore", e); + return e.getMessage(); + } + } // new key store + + // No KeyStore + if (ks == null) + return "No Key Store"; + + // Verify Certificate + Certificate cert = null; + try + { + cert = getCertificate(CERTIFICATE_ALIAS); + } + catch (Exception e) + { + log.log(Level.SEVERE, "certificate", e); + return e.getMessage(); + } + if (cert == null) + return "No Certificate found"; + + return null; // OK + } // verify + + /** + * Get KeyStore + * @return KeyStore or null + * @throws Exception + */ + public KeyStore getKeyStore() throws Exception + { + try + { + m_keyStore = KeyStore.getInstance("JKS"); + } + catch (Exception e) + { + log.log(Level.SEVERE, "Instance", e); + } + // Load Existing + if (m_file.exists()) + { + log.fine(m_file.toString()); + InputStream is = null; + try + { + is = new FileInputStream (m_file); + } + catch (Exception e) + { + log.log(Level.SEVERE, "load", e); + return null; + } + m_keyStore.load(is, m_password); + } + else + return null; // does not exist + // + log.fine("Provider=" + m_keyStore.getProvider() + + " - Type=" + m_keyStore.getType()); + // + return m_keyStore; + } // getKeyStore + + /** + * Get Certificate + * @param alias alias + * @return certificate or null + * @throws Exception + */ + public Certificate getCertificate (String alias) throws Exception + { + log.config("Alias=" + alias); + + Date date = m_keyStore.getCreationDate(alias); + if (date == null) // no certificate + return null; + log.fine("Created=" + date); + // + Key key = m_keyStore.getKey(alias, m_password); + if (CLogMgt.isLevelFinest()) + log.info("Key=" + key); // Multiple lines + else + log.fine(key.getAlgorithm()); + // + Certificate cert = m_keyStore.getCertificate(alias); + if (CLogMgt.isLevelFinest()) + log.info("Certificate = " + cert); // Multiple lines + else + log.fine(cert.getType()); + + // log.fine("Certificate - Type=" + cert.getType() + // + " - PublicKey=" + cert.getPublicKey()); + return cert; + } // getCertificate + + + /************************************************************************** + * Create Certificate + * @param alias alias + * @param parent interactive dialog + */ + private void createCertificate (String alias, JFrame parent) + { + log.info(""); + try + { + File dir = m_file.getParentFile(); + if (!dir.exists()) + dir.mkdir(); + } + catch (Exception e) + { + log.log(Level.SEVERE, "directory", e); + } + + String dname = getDname(parent); + if (dname == null) + return; + // + try + { + genkey (alias, m_password, m_file.getAbsolutePath(), dname); + selfcert (alias, m_password, m_file.getAbsolutePath(), dname); + } + catch (Exception e) + { + log.log(Level.SEVERE, "certificate", e); + } + } // createCertificate + + /** + * Get Distinguised Name + * @param parent interactive dialog + * @return dname or null + */ + public static String getDname(JFrame parent) + { + String cn = null; + try + { + InetAddress address = InetAddress.getLocalHost(); + cn = address.getCanonicalHostName(); + } + catch (Exception e) + { + } + String ou = System.getProperty("user.name"); + String o = "AdempiereUser"; + String l = "MyTown"; + String s = ""; + String c = System.getProperty("user.country"); + // + if (parent != null) + { + KeyStoreDialog skd = new KeyStoreDialog(parent, + cn, ou, o, l, s, c); + if (!skd.isOK()) + return null; + cn = skd.getCN(); + ou = skd.getOU(); + o = skd.getO(); + l = skd.getL(); + s = skd.getS(); + c = skd.getC(); + } + // + if (cn == null || cn.length() == 0) + { + log.warning("No Common Name (CN)"); + return null; + } + if (ou == null || ou.length() == 0) + { + log.warning("No Organization Unit (OU)"); + return null; + } + if (o == null || o.length() == 0) + { + log.warning("No Organization (O)"); + return null; + } + if (c == null || c.length() == 0) + { + log.warning("No Country (C)"); + return null; + } + + // Escape commas + StringBuffer dname = new StringBuffer(); + dname.append("CN=").append(escapeCommas(cn)); // common name + dname.append(", OU=").append(escapeCommas(ou)); // org unit + dname.append(", O=").append(escapeCommas(o)); // org + if (l != null && l.length() > 0) + dname.append(", L=").append(escapeCommas(l)); // locality + if (s != null && s.length() > 0) + dname.append(", S=").append(escapeCommas(s)); // state + dname.append(", C=").append(escapeCommas(c)); // country + return dname.toString(); + } // getDname + + /** + * Escape Commas + * @param in input string + * @return excaped string + */ + public static String escapeCommas(String in) + { + if (in == null || in.indexOf(",") == -1) + return in; + StringBuffer out = new StringBuffer(); + char[] chars = in.toCharArray(); + for (int i = 0; i < chars.length; i++) + { + if (chars[i] == ',') + out.append('\\').append(','); + else + out.append(chars[i]); + } + return out.toString(); + } // escapeCommas + + /** + * Generate Key + * @param alias adempiere + * @param password password + * @param fileName key store file name (may have spaces) + * @param dname distinguished name + */ + public static void genkey (String alias, char[] password, String fileName, String dname) + { + StringBuffer cmd = new StringBuffer ("-genkey -keyalg rsa"); + cmd.append(" -alias ").append(alias); + cmd.append(" -dname \"").append(dname).append("\""); + cmd.append(" -keypass ").append(password).append(" -validity 365"); + if (fileName.indexOf(' ') != -1) + cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password); + else + cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password); + keytool (cmd.toString()); + } // genkey + + /** + * Generate Key + * @param alias adempiere + * @param password password + * @param fileName key store file name (may have spaces) + * @param dname distinguished name + */ + public static void selfcert (String alias, char[] password, String fileName, String dname) + { + StringBuffer cmd = new StringBuffer ("-selfcert"); + cmd.append(" -alias ").append(alias); + cmd.append(" -dname \"").append(dname).append("\""); + cmd.append(" -keypass ").append(password).append(" -validity 180"); + if (fileName.indexOf(' ') != -1) + cmd.append(" -keystore \"").append(fileName).append("\" -storepass ").append(password); + else + cmd.append(" -keystore ").append(fileName).append(" -storepass ").append(password); + keytool (cmd.toString()); + } // selfcert + + /** + * Submit Command to Key Tool + * @param cmd command + */ + public static void keytool(String cmd) + { + log.info("keytool " + cmd); + ArrayList list = new ArrayList(); + StringTokenizer st = new StringTokenizer(cmd, " "); + String quoteBuffer = null; + while (st.hasMoreTokens()) + { + String token = st.nextToken(); + // System.out.println("= " + token + " = quoteBuffer=" + quoteBuffer + " - Size=" + list.size() ); + if (quoteBuffer == null) + { + if (token.startsWith("\"")) + quoteBuffer = token.substring(1); + else + list.add(token); + } + else + quoteBuffer += " " + token; + if (token.endsWith("\"")) + { + String str = quoteBuffer.substring(0, quoteBuffer.length()-1); + // System.out.println(" Buffer= " + str ); + list.add(str); + quoteBuffer = null; + } + } // all tokens + + // + String[] args = new String[list.size()]; + list.toArray(args); + // System.out.println(" args #" + args.length); + //vpj-cd add support java 6 + try + { + KeyTool.main(args); + } + catch (Exception e) + { + } + } // ketyool + + /** + * Get Keystore File Name + * @param baseDir ADEMPIERE_HOME + * @return file name + */ + public static String getKeystoreFileName (String baseDir) + { + String fileName = baseDir; + if (fileName == null) + fileName = ""; + else if (!fileName.endsWith(File.separator)) + fileName += File.separator; + fileName += KEYSTORE_DIRECTORY + File.separator + KEYSTORE_NAME; + return fileName; + } // getKeystoreFileName + + + /************************************************************************** + * Test + * @param args ignored + */ + public static void main (String[] args) + { + Adempiere.startupEnvironment(true); + System.out.println(new KeyStoreMgt ( + "C:/Adempiere/keystore/myKeystore2", "myPassword".toCharArray()).verify(null)); + } // main + +} // MyKeyStore