1 14 package org.compiere.install; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.io.*; 19 import java.net.*; 20 import java.sql.*; 21 import java.util.*; 22 import java.util.regex.*; 23 24 import org.apache.log4j.LogManager; 25 import org.apache.log4j.Logger; 26 import org.apache.log4j.ConsoleAppender; 27 import org.apache.log4j.Level; 28 29 import javax.mail.*; 30 import javax.mail.internet.*; 31 import javax.swing.*; 32 33 import oracle.jdbc.*; 34 import org.compiere.*; 35 import org.compiere.apps.*; 36 import org.compiere.db.*; 37 import org.compiere.util.*; 38 39 40 47 public class ConfigurationPanel extends JPanel implements ActionListener 48 { 49 54 public ConfigurationPanel (JLabel statusBar) throws Exception  55 { 56 LogManager.resetConfiguration(); 57 Logger root = Logger.getRootLogger(); 58 root.addAppender(new ConsoleAppender(new LogLayout())); 60 root.setLevel(Level.ALL); 61 Log.setTraceLevel(10); 62 63 m_statusBar = statusBar; 64 jbInit(); 65 dynInit(); 66 } 68 public static final String COMPIERE_ENV_FILE = "CompiereEnv.properties"; 69 70 public static final String COMPIERE_HOME = "COMPIERE_HOME"; 71 public static final String JAVA_HOME = "JAVA_HOME"; 72 public static final String COMPIERE_JAVA_OPTIONS = "COMPIERE_JAVA_OPTIONS"; 73 74 public static final String COMPIERE_APPS_SERVER = "COMPIERE_APPS_SERVER"; 75 public static final String COMPIERE_JNP_PORT = "COMPIERE_JNP_PORT"; 76 public static final String COMPIERE_WEB_PORT = "COMPIERE_WEB_PORT"; 77 public static final String COMPIERE_SSL_PORT = "COMPIERE_SSL_PORT"; 78 79 public static final String COMPIERE_DB_SERVER = "COMPIERE_DB_SERVER"; 80 public static final String COMPIERE_DB_PORT = "COMPIERE_DB_PORT"; 81 public static final String COMPIERE_DB_NAME = "COMPIERE_DB_NAME"; 82 83 public static final String COMPIERE_DB_USER = "COMPIERE_DB_USER"; 84 public static final String COMPIERE_DB_PASSWORD = "COMPIERE_DB_PASSWORD"; 85 public static final String COMPIERE_DB_SYSTEM = "COMPIERE_DB_SYSTEM"; 86 87 public static final String COMPIERE_DB_URL = "COMPIERE_DB_URL"; 88 public static final String COMPIERE_DB_TNS = "COMPIERE_DB_TNS"; 89 90 public static final String COMPIERE_MAIL_SERVER = "COMPIERE_MAIL_SERVER"; 91 public static final String COMPIERE_MAIL_USER = "COMPIERE_MAIL_USER"; 92 public static final String COMPIERE_MAIL_PASSWORD = "COMPIERE_MAIL_PASSWORD"; 93 public static final String COMPIERE_ADMIN_EMAIL = "COMPIERE_ADMIN_EMAIL"; 94 95 public static final String COMPIERE_FTP_SERVER = "COMPIERE_FTP_SERVER"; 96 public static final String COMPIERE_FTP_USER = "COMPIERE_FTP_USER"; 97 public static final String COMPIERE_FTP_PASSWORD = "COMPIERE_FTP_PASSWORD"; 98 public static final String COMPIERE_FTP_PREFIX = "COMPIERE_FTP_PREFIX"; 99 100 private String m_errorString; 101 private File m_javaHome; 102 private File m_compiereHome; 103 private InetAddress m_appsServer; 104 private int m_WebPort; 105 private int m_JNPPort; 106 private InetAddress m_databaseServer; 107 private int m_databasePort; 108 private String m_databaseName; 109 private String m_connectionString; 110 private String m_systemPassword; 111 private String m_databaseUser; 112 private String m_databasePassword; 113 private String m_TNSName; 114 115 private InetAddress m_mailServer; 116 private InternetAddress m_adminEMail; 117 private String m_mailUser; 118 private String m_mailPassword; 119 120 private volatile boolean m_success = false; 121 private volatile boolean m_testing = false; 122 123 124 static ResourceBundle res = ResourceBundle.getBundle("org.compiere.install.SetupRes"); 125 126 127 private static Driver s_driver = null; 128 129 private Properties m_properties = new Properties(); 130 131 private JLabel m_statusBar; 132 133 private static ImageIcon iOpen = new ImageIcon(ConfigurationPanel.class.getResource("openFile.gif")); 134 private static ImageIcon iSave = new ImageIcon(Compiere.class.getResource("images/Save16.gif")); 135 private static ImageIcon iHelp = new ImageIcon(Compiere.class.getResource("images/Help16.gif")); 136 137 138 private GridBagLayout gridBagLayout = new GridBagLayout(); 140 private JLabel lCompiereHome = new JLabel(); 141 private JTextField fCompiereHome = new JTextField(); 142 private JLabel lWebPort = new JLabel(); 143 private JTextField fWebPort = new JTextField(); 144 private JLabel lAppsServer = new JLabel(); 145 private JTextField fAppsServer = new JTextField(); 146 private JLabel lDatabaseType = new JLabel(); 147 private JComboBox fDatabaseType = new JComboBox(); 148 private JLabel lDatabaseName = new JLabel(); 149 private JLabel lDatabasePort = new JLabel(); 150 private JLabel lDatabaseUser = new JLabel(); 151 private JLabel lDatabasePassword = new JLabel(); 152 private JTextField fDatabaseName = new JTextField(); 153 private JTextField fDatabasePort = new JTextField(); 154 private JTextField fDatabaseUser = new JTextField(); 155 private JPasswordField fDatabasePassword = new JPasswordField(); 156 private JLabel lTNSName = new JLabel(); 157 private JComboBox fTNSName = new JComboBox(); 158 private JLabel lSystemPassword = new JLabel(); 159 private JPasswordField fSystemPassword = new JPasswordField(); 160 private JLabel lMailServer = new JLabel(); 161 private JTextField fMailServer = new JTextField(); 162 private JLabel lAdminEMail = new JLabel(); 163 private JTextField fAdminEMail = new JTextField(); 164 private JLabel lDatabaseServer = new JLabel(); 165 private JTextField fDatabaseServer = new JTextField(); 166 private JLabel lJavaHome = new JLabel(); 167 private JTextField fJavaHome = new JTextField(); 168 private JButton bCompiereHome = new JButton(iOpen); 169 private JButton bJavaHome = new JButton(iOpen); 170 private JButton bHelp = new JButton(iHelp); 171 private JButton bTest = new JButton(); 172 private JButton bSave = new JButton(iSave); 173 private JLabel lJNPPort = new JLabel(); 174 private JTextField fJNPPort = new JTextField(); 175 private JLabel lMailUser = new JLabel(); 176 private JLabel lMailPassword = new JLabel(); 177 private JTextField fMailUser = new JTextField(); 178 private JPasswordField fMailPassword = new JPasswordField(); 179 180 181 185 private void jbInit() throws Exception  186 { 187 lCompiereHome.setToolTipText(res.getString("CompiereHomeInfo")); 188 lCompiereHome.setText(res.getString("CompiereHome")); 189 this.setLayout(gridBagLayout); 190 fCompiereHome.setText("D:\\Compiere2"); 191 lWebPort.setToolTipText(res.getString("WebPortInfo")); 192 lWebPort.setText(res.getString("WebPort")); 193 fWebPort.setText("80"); 194 lAppsServer.setToolTipText(res.getString("AppsServerInfo")); 195 lAppsServer.setText(res.getString("AppsServer")); 196 fAppsServer.setText("server.company.com"); 197 lDatabaseType.setToolTipText(res.getString("DatabaseTypeInfo")); 198 lDatabaseType.setText(res.getString("DatabaseType")); 199 lDatabaseName.setToolTipText(res.getString("DatabaseNameInfo")); 200 lDatabaseName.setText(res.getString("DatabaseName")); 201 lDatabasePort.setToolTipText(res.getString("DatabasePortInfo")); 202 lDatabasePort.setText(res.getString("DatabasePort")); 203 lDatabaseUser.setToolTipText(res.getString("DatabaseUserInfo")); 204 lDatabaseUser.setText(res.getString("DatabaseUser")); 205 lDatabasePassword.setToolTipText(res.getString("DatabasePasswordInfo")); 206 lDatabasePassword.setText(res.getString("DatabasePassword")); 207 fDatabaseName.setText("compiere"); 208 fDatabasePort.setText("1521"); 209 fDatabaseUser.setText("compiere"); 210 fDatabasePassword.setText("compiere"); 211 lTNSName.setToolTipText(res.getString("TNSNameInfo")); 212 lTNSName.setText(res.getString("TNSName")); 213 fTNSName.setEditable(true); 214 lSystemPassword.setToolTipText(res.getString("SystemPasswordInfo")); 215 lSystemPassword.setText(res.getString("SystemPassword")); 216 fSystemPassword.setText("manager"); 217 lMailServer.setToolTipText(res.getString("MailServerInfo")); 218 lMailServer.setText(res.getString("MailServer")); 219 fMailServer.setText("mail.company.com"); 220 lAdminEMail.setToolTipText(res.getString("AdminEMailInfo")); 221 lAdminEMail.setText(res.getString("AdminEMail")); 222 fAdminEMail.setText("admin@company.com"); 223 bTest.setToolTipText(res.getString("TestInfo")); 224 bTest.setText(res.getString("Test")); 225 bSave.setToolTipText(res.getString("SaveInfo")); 226 bSave.setText(res.getString("Save")); 227 lDatabaseServer.setToolTipText(res.getString("DatabaseServerInfo")); 228 lDatabaseServer.setText(res.getString("DatabaseServer")); 229 lJavaHome.setToolTipText(res.getString("JavaHomeInfo")); 230 lJavaHome.setText(res.getString("JavaHome")); 231 fJavaHome.setText("Java141"); 232 lJNPPort.setToolTipText(res.getString("JNPPortInfo")); 233 lJNPPort.setText(res.getString("JNPPort")); 234 fJNPPort.setText("1099"); 235 bHelp.setToolTipText(res.getString("HelpInfo")); 236 lMailUser.setToolTipText(res.getString("MailUserInfo")); 237 lMailUser.setText(res.getString("MailUser")); 238 lMailPassword.setToolTipText(res.getString("MailPasswordInfo")); 239 lMailPassword.setText(res.getString("MailPassword")); 240 fMailUser.setText("compiere"); 241 fMailPassword.setText("compiere"); 242 243 this.add(lCompiereHome, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 245 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 246 this.add(fCompiereHome, new GridBagConstraints(1, 1, 1, 1, 0.5, 0.0 247 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 248 this.add(lWebPort, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 249 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 250 this.add(fWebPort, new GridBagConstraints(1, 3, 1, 1, 0.5, 0.0 251 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 252 this.add(lAppsServer, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 253 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 254 this.add(fAppsServer, new GridBagConstraints(1, 2, 1, 1, 0.5, 0.0 255 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 256 this.add(lDatabaseType, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0 257 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 258 this.add(fDatabaseType, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0 259 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 260 this.add(lDatabasePort, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0 261 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 262 this.add(lDatabaseUser, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0 263 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 264 this.add(fDatabaseName, new GridBagConstraints(1, 6, 1, 1, 0.5, 0.0 265 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 266 this.add(fDatabasePort, new GridBagConstraints(1, 7, 1, 1, 0.5, 0.0 267 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 268 this.add(fDatabaseUser, new GridBagConstraints(1, 8, 1, 1, 0.5, 0.0 269 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0)); 270 this.add(lTNSName, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0 271 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 272 this.add(fTNSName, new GridBagConstraints(3, 5, 1, 1, 0.5, 0.0 273 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 274 this.add(lMailServer, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0 275 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 276 this.add(lSystemPassword, new GridBagConstraints(2, 7, 1, 1, 0.0, 0.0 277 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 278 this.add(fSystemPassword, new GridBagConstraints(3, 7, 1, 1, 0.5, 0.0 279 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 280 this.add(fDatabasePassword, new GridBagConstraints(3, 8, 1, 1, 0.5, 0.0 281 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0)); 282 this.add(lDatabasePassword, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0 283 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 284 this.add(fMailServer, new GridBagConstraints(1, 9, 1, 1, 0.5, 0.0 285 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0)); 286 this.add(bTest, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0 287 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 288 this.add(bSave, new GridBagConstraints(3, 11, 1, 1, 0.0, 0.0 289 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 290 this.add(lDatabaseServer, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 291 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 292 this.add(fDatabaseServer, new GridBagConstraints(1, 5, 1, 1, 0.5, 0.0 293 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 294 this.add(lDatabaseName, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0 295 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 296 this.add(lJavaHome, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 297 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 298 this.add(fJavaHome, new GridBagConstraints(1, 0, 1, 1, 0.5, 0.0 299 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 300 this.add(bCompiereHome, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 301 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 302 this.add(bHelp, new GridBagConstraints(2, 11, 1, 1, 0.0, 0.0 303 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 304 this.add(bJavaHome, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 305 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 306 this.add(lJNPPort, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 307 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 308 this.add(fJNPPort, new GridBagConstraints(3, 3, 1, 1, 0.5, 0.0 309 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 310 this.add(lMailPassword, new GridBagConstraints(2, 10, 1, 1, 0.0, 0.0 311 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 312 this.add(fMailPassword, new GridBagConstraints(3, 10, 1, 1, 0.5, 0.0 313 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0)); 314 this.add(lAdminEMail, new GridBagConstraints(2, 9, 1, 1, 0.0, 0.0 315 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 5), 0, 0)); 316 this.add(fMailUser, new GridBagConstraints(1, 10, 1, 1, 0.5, 0.0 317 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0)); 318 this.add(fAdminEMail, new GridBagConstraints(3, 9, 1, 1, 0.5, 0.0 319 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 5, 5), 0, 0)); 320 this.add(lMailUser, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0 321 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 5, 0), 0, 0)); 322 bCompiereHome.addActionListener(this); 324 bJavaHome.addActionListener(this); 325 bHelp.addActionListener(this); 326 bTest.addActionListener(this); 327 bSave.addActionListener(this); 328 } 330 331 335 private void dynInit() throws Exception  336 { 337 fWebPort.setColumns(30); 339 fJNPPort.setColumns(30); 340 341 fDatabaseType.addItem("Oracle 9i2"); 343 344 String ch = System.getProperty(COMPIERE_HOME); 346 if (ch == null || ch.length() == 0) 347 ch = System.getProperty("user.dir"); 348 fCompiereHome.setText(ch); 349 boolean envLoaded = false; 350 String fileName = ch + File.separator + COMPIERE_ENV_FILE; 351 File env = new File (fileName); 352 System.out.println(env + " - exists=" + env.exists()); 353 if (env.exists()) 354 { 355 try 356 { 357 FileInputStream fis = new FileInputStream(env); 358 m_properties.load(fis); 359 fis.close(); 360 } 361 catch (Exception e) 362 { 363 System.err.println(e.toString()); 364 } 365 System.out.println("Loading ..."); 366 if (m_properties.size() > 5) 367 envLoaded = true; 368 fCompiereHome.setText((String )m_properties.get(COMPIERE_HOME)); 370 fJavaHome.setText((String )m_properties.get(JAVA_HOME)); 371 fAppsServer.setText((String )m_properties.get(COMPIERE_APPS_SERVER)); 372 fWebPort.setText((String )m_properties.get(COMPIERE_WEB_PORT)); 373 fJNPPort.setText((String )m_properties.get(COMPIERE_JNP_PORT)); 374 375 fDatabaseServer.setText((String )m_properties.get(COMPIERE_DB_SERVER)); 376 fDatabasePort.setText((String )m_properties.get(COMPIERE_DB_PORT)); 377 fDatabaseName.setText((String )m_properties.get(COMPIERE_DB_NAME)); 378 379 fDatabaseUser.setText((String )m_properties.get(COMPIERE_DB_USER)); 380 fDatabasePassword.setText((String )m_properties.get(COMPIERE_DB_PASSWORD)); 381 fSystemPassword.setText((String )m_properties.get(COMPIERE_DB_SYSTEM)); 382 fillTNSName((String )m_properties.get(COMPIERE_DB_TNS)); 383 384 fMailServer.setText((String )m_properties.get(COMPIERE_MAIL_SERVER)); 385 fMailUser.setText((String )m_properties.get(COMPIERE_MAIL_USER)); 386 fMailPassword.setText((String )m_properties.get(COMPIERE_MAIL_PASSWORD)); 387 fAdminEMail.setText((String )m_properties.get(COMPIERE_ADMIN_EMAIL)); 388 } 389 390 if (!envLoaded) 392 { 393 System.out.println("Setting Defaults"); 394 String javaHome = System.getProperty("java.home"); 396 if (javaHome.endsWith("jre")) 397 javaHome = javaHome.substring(0, javaHome.length()-4); 398 fJavaHome.setText(javaHome); 399 fAppsServer.setText(InetAddress.getLocalHost().getHostName()); 401 fDatabaseServer.setText(InetAddress.getLocalHost().getHostName()); 403 fMailServer.setText(InetAddress.getLocalHost().getHostName()); 405 fillTNSName(""); 407 } 409 if (!m_properties.containsKey(COMPIERE_FTP_SERVER)) 411 { 412 m_properties.setProperty(COMPIERE_FTP_SERVER, "localhost"); 413 m_properties.setProperty(COMPIERE_FTP_USER, "anonymous"); 414 m_properties.setProperty(COMPIERE_FTP_PASSWORD, "user@host.com"); 415 m_properties.setProperty(COMPIERE_FTP_PREFIX, "my"); 416 } 417 if (!m_properties.containsKey(COMPIERE_JAVA_OPTIONS)) 419 m_properties.setProperty(COMPIERE_JAVA_OPTIONS, "-Xms32m -Xmx128m"); 420 421 } 424 428 private void fillTNSName (String defaultValue) 429 { 430 String def = defaultValue; 432 if (def != null && def.trim().length() == 0) 433 def = null; 434 if (def != null) 435 { 436 def = def.toLowerCase(); 437 fTNSName.addItem(def); 438 } 439 440 String path = System.getProperty("java.library.path"); 442 String [] entries = path.split(File.pathSeparator); 443 for (int e = 0; e < entries.length; e++) 444 { 445 String entry = entries[e].toLowerCase(); 446 if (entry.indexOf("ora") != -1 && entry.endsWith("bin")) 447 { 448 StringBuffer sb = getTNS_File (entries[e].substring(0, entries[e].length()-4)); 449 String [] tnsnames = getTNS_Names (sb); 450 if (tnsnames != null) 451 { 452 for (int i = 0; i < tnsnames.length; i++) 453 { 454 String tns = tnsnames[i]; 455 if (!tns.equals(def)) 456 fTNSName.addItem(tns); 457 } 458 break; 459 } 460 } 461 } 463 fTNSName.addActionListener(this); 465 if (fTNSName.getItemCount() > 0) 466 fTNSName.setSelectedIndex(0); 467 } 469 474 private StringBuffer getTNS_File (String oraHome) 475 { 476 String tnsnames = oraHome + File.separator 477 + "network" + File.separator 478 + "admin" + File.separator 479 + "tnsnames.ora"; 480 File tnsfile = new File (tnsnames); 481 if (!tnsfile.exists()) 482 return null; 483 484 System.out.println("Searching " + tnsnames); 485 StringBuffer sb = new StringBuffer (); 486 try 487 { 488 FileReader fr = new FileReader (tnsfile); 489 int c; 490 while ((c = fr.read()) != -1) 491 sb.append((char)c); 492 } 493 catch (IOException ex) 494 { 495 System.err.println("Error Reading " + tnsnames); 496 ex.printStackTrace(); 497 return null; 498 } 499 if (sb.length() == 0) 500 return null; 501 return sb; 502 } 504 510 private String [] getTNS_Names (StringBuffer tnsnames) 511 { 512 if (tnsnames == null) 513 return null; 514 515 ArrayList list = new ArrayList(); 516 Pattern pattern = Pattern.compile("$", Pattern.MULTILINE); 517 String [] lines = pattern.split(tnsnames); 518 for (int i = 0; i < lines.length; i++) 519 { 520 String line = lines[i].trim(); 521 if (line.length() > 0 522 && Character.isLetter(line.charAt(0)) && line.indexOf("=") != -1 524 && line.indexOf("EXTPROC_") == -1 525 && line.indexOf("_HTTP") == -1) 526 { 527 String entry = line.substring(0, line.indexOf('=')).trim().toLowerCase(); 528 System.out.println("- " + entry); 529 list.add(entry); 530 } 531 } 532 if (list.size() == 0) 534 return null; 535 String [] retValue = new String [list.size()]; 536 list.toArray(retValue); 537 return retValue; 538 } 540 541 542 546 public void actionPerformed(ActionEvent e) 547 { 548 if (m_testing) 549 return; 550 if (e.getSource() == fTNSName) 552 { 553 String tns = (String )fTNSName.getSelectedItem(); 554 if (tns != null) 555 { 556 int pos = tns.indexOf('.'); 557 if (pos != -1) 558 tns = tns.substring(0, pos); 559 fDatabaseName.setText(tns); 560 } 561 } 562 563 else if (e.getSource() == bJavaHome) 564 setPath (fJavaHome); 565 else if (e.getSource() == bCompiereHome) 566 setPath (fCompiereHome); 567 else if (e.getSource() == bHelp) 568 new Setup_Help((Frame)SwingUtilities.getWindowAncestor(this)); 569 else if (e.getSource() == bTest) 570 startTest(); 571 else if (e.getSource() == bSave) 572 save(); 573 } 575 579 private void setPath (JTextField field) 580 { 581 JFileChooser fc = new JFileChooser(field.getText()); 582 fc.setDialogType(JFileChooser.OPEN_DIALOG); 583 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 584 fc.setMultiSelectionEnabled(false); 585 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 586 field.setText(fc.getSelectedFile().getAbsolutePath()); 587 } 589 590 591 595 private SwingWorker startTest() 596 { 597 SwingWorker worker = new SwingWorker() 598 { 599 public Object construct() 601 { 602 m_testing = true; 603 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 604 bTest.setEnabled(false); 605 m_success = false; 606 m_errorString = null; 607 try 608 { 609 test(); 610 } 611 catch (Exception ex) 612 { 613 ex.printStackTrace(); 614 m_errorString = ex.getMessage(); 615 } 616 setCursor(Cursor.getDefaultCursor()); 618 if (m_errorString == null) 619 m_success = true; 620 bTest.setEnabled(true); 621 m_testing = false; 622 return new Boolean (m_success); 623 } 624 public void finished() 626 { 627 if (m_errorString != null) 628 { 629 System.err.println(m_errorString); 630 JOptionPane.showConfirmDialog (null, m_errorString, res.getString("ServerError"), 631 JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); 632 } 633 } 634 }; 635 worker.start(); 636 return worker; 637 } 639 643 private void test() throws Exception  644 { 645 System.out.println(); 646 System.out.println("** Test **"); 647 bSave.setEnabled(false); 648 649 650 m_errorString = res.getString("ErrorJavaHome"); 652 m_javaHome = new File (fJavaHome.getText()); 653 if (!m_javaHome.exists()) 654 return; 655 File tools = new File (fJavaHome.getText() + File.separator + "lib" + File.separator + "tools.jar"); 656 if (!tools.exists()) 657 { 658 System.err.println("Not Found Java SDK = " + tools); 659 return; 660 } 661 System.out.println("OK: JavaHome=" + m_javaHome.getAbsolutePath()); 662 m_properties.setProperty(JAVA_HOME, m_javaHome.getAbsolutePath()); 663 664 final String VERSION = "1.4.1"; 666 final String VERSION2 = "1.4.2"; 667 boolean versionOK = false; 668 String jh = m_javaHome.getAbsolutePath(); 669 if (jh.indexOf(VERSION) != -1) versionOK = true; 671 if (!versionOK && jh.indexOf(VERSION2) != -1) versionOK = true; 673 String thisJH = System.getProperty("java.home"); 674 if (thisJH.indexOf(jh) != -1) { 676 String thisJV = System.getProperty("java.version"); 677 versionOK = thisJV.indexOf(VERSION) != -1; 678 if (versionOK) 679 System.out.println(" Java Version OK = " + thisJV); 680 } 681 if (!versionOK) 682 System.out.println("** Please check Java Version - should be " + VERSION2 + "*"); 683 684 m_errorString = res.getString("ErrorCompiereHome"); 686 m_compiereHome = new File (fCompiereHome.getText()); 687 if (!m_compiereHome.exists()) 688 { 689 System.err.println("Not found CompiereHome = " + m_compiereHome); 690 return; 691 } 692 System.out.println("OK: CompiereHome = " + m_compiereHome); 693 m_properties.setProperty(COMPIERE_HOME, m_compiereHome.getAbsolutePath()); 694 695 696 m_errorString = res.getString("ErrorAppsServer"); 698 String server = fAppsServer.getText(); 699 if (server == null || server.length() == 0 || server.toLowerCase().indexOf("localhost") != -1) 700 { 701 System.err.println("Not correct AppsServer = " + m_appsServer); 702 return; 703 } 704 m_appsServer = InetAddress.getByName(server); 705 System.out.println("OK: AppsServer = " + m_appsServer); 706 m_properties.setProperty(COMPIERE_APPS_SERVER, m_appsServer.getHostName()); 707 708 m_errorString = res.getString("ErrorWebPort"); 710 m_statusBar.setText(lWebPort.getText()); 711 m_WebPort = Integer.parseInt(fWebPort.getText()); 712 if (testPort ("http", m_appsServer.getHostName(), m_WebPort, "/") || !testServerPort(m_WebPort)) 714 { 715 System.err.println("Not correct WebPort = " + m_WebPort); 716 return; 717 } 718 System.out.println("OK: WebPort = " + m_WebPort); 719 m_properties.setProperty(COMPIERE_WEB_PORT, String.valueOf(m_WebPort)); 720 int sslPort = m_WebPort == 80 ? 443 : 8443; 722 System.out.println("SSL WebPort = " + sslPort); 723 m_properties.setProperty(COMPIERE_SSL_PORT, String.valueOf(sslPort)); 724 725 726 m_errorString = res.getString("ErrorJNPPort"); 728 m_statusBar.setText(lJNPPort.getText()); 729 m_JNPPort = Integer.parseInt(fJNPPort.getText()); 730 if (testPort (m_appsServer, m_JNPPort, false) || !testServerPort(m_JNPPort)) 732 { 733 System.err.println("Not correct JNPPort = " + m_JNPPort); 734 return; 735 } 736 System.out.println("OK: JNPPort = " + m_JNPPort); 737 m_properties.setProperty(COMPIERE_JNP_PORT, String.valueOf(m_JNPPort)); 738 739 740 m_errorString = res.getString("ErrorDatabaseServer"); 742 m_statusBar.setText(lDatabaseServer.getText()); 743 server = fDatabaseServer.getText(); 744 if (server == null || server.length() == 0 || server.toLowerCase().indexOf("localhost") != -1) 745 { 746 System.err.println("Not correct Database Server = " + server); 747 return; 748 } 749 m_databaseServer = InetAddress.getByName(server); 750 System.out.println("OK: Database Server = " + m_databaseServer); 751 m_properties.setProperty(COMPIERE_DB_SERVER, m_databaseServer.getHostName()); 752 753 754 m_errorString = res.getString("ErrorDatabasePort"); 756 m_databasePort = Integer.parseInt(fDatabasePort.getText()); 757 if (!testPort (m_databaseServer, m_databasePort, true)) 759 { 760 System.err.println("Error Database Port = " + m_databasePort); 761 return; 762 } 763 System.out.println("OK: Database Port = " + m_databasePort); 764 m_properties.setProperty(COMPIERE_DB_PORT, String.valueOf(m_databasePort)); 765 766 767 m_errorString = res.getString("ErrorJDBC"); 769 m_statusBar.setText(lDatabaseName.getText()); 770 m_databaseName = fDatabaseName.getText(); m_systemPassword = new String (fSystemPassword.getPassword()); 772 if (!testJDBC("system", m_systemPassword)) 773 { 774 System.err.println("Error Database Name = " + m_databaseName); 775 System.err.println("Error Database SystemID = system/" + m_systemPassword); 776 return; 777 } 778 System.out.println("OK: Database Name = " + m_databaseName); 779 m_properties.setProperty(COMPIERE_DB_NAME, m_databaseName); 780 System.out.println("OK: Database SystemID = system/" + m_systemPassword); 781 m_properties.setProperty(COMPIERE_DB_SYSTEM, m_systemPassword); 782 StringBuffer url = new StringBuffer ("jdbc:oracle:thin:@") 784 .append(m_databaseServer).append(":") 785 .append(m_databasePort).append(":").append(m_databaseName); 786 System.out.println("OK: Database URL = " + url.toString()); 787 m_properties.setProperty(COMPIERE_DB_URL, url.toString()); 788 789 790 m_databaseUser = fDatabaseUser.getText(); m_databasePassword = new String (fDatabasePassword.getPassword()); if (testJDBC(m_databaseUser, m_databasePassword)) 795 System.out.println("OK: Database UserID = " + m_databaseUser + "/" + m_databasePassword); 796 else 797 System.out.println("Not created yet: Database UserID = " + m_databaseUser + "/" + m_databasePassword); 798 m_properties.setProperty(COMPIERE_DB_USER, m_databaseUser); 799 m_properties.setProperty(COMPIERE_DB_PASSWORD, m_databasePassword); 800 801 802 m_errorString = res.getString("ErrorTNS"); 804 m_statusBar.setText(lTNSName.getText()); 805 m_TNSName = (String )fTNSName.getSelectedItem(); 806 if (!testTNS("system", m_systemPassword)) 807 { 808 System.err.println("Error Database TNS Name = " + m_TNSName); 809 return; 810 } 811 System.out.println("OK: Database TNS Name = " + m_TNSName); 812 m_properties.setProperty(COMPIERE_DB_TNS, m_TNSName); 813 814 815 m_errorString = res.getString("ErrorMailServer"); 817 m_statusBar.setText(lMailServer.getText()); 818 server = fMailServer.getText(); 819 if (server == null || server.length() == 0) 820 { 821 System.err.println("Error Mail Server = " + server); 822 return; 823 } 824 m_mailServer = InetAddress.getByName(server); 825 System.out.println("OK: Mail Server = " + m_mailServer); 826 m_properties.setProperty(COMPIERE_MAIL_SERVER, m_mailServer.getHostName()); 827 828 829 m_errorString = "ErrorMailUser"; 831 m_statusBar.setText(lMailUser.getText()); 832 m_mailUser = fMailUser.getText(); 833 m_mailPassword = new String (fMailPassword.getPassword()); 834 m_properties.setProperty(COMPIERE_MAIL_USER, m_mailUser); 835 m_properties.setProperty(COMPIERE_MAIL_PASSWORD, m_mailPassword); 836 System.out.println(" Mail User = " + m_mailUser + "/" + m_mailPassword); 837 838 m_errorString = res.getString("ErrorMail"); 840 m_adminEMail = new InternetAddress (fAdminEMail.getText()); 841 if (testMail()) 843 System.out.println("OK: Admin EMail = " + m_adminEMail); 844 else 845 System.out.println("Not verified Admin EMail = " + m_adminEMail); 846 m_properties.setProperty(COMPIERE_ADMIN_EMAIL, m_adminEMail.toString()); 847 848 m_statusBar.setText(res.getString("Ok")); 850 System.out.println("** Test OK **"); 851 bSave.setEnabled(true); 852 m_errorString = null; 853 } 855 856 864 private boolean testPort (String protocol, String server, int port, String file) 865 { 866 URL url = null; 867 try 868 { 869 url = new URL (protocol, server, port, file); 870 } 871 catch (MalformedURLException ex) 872 { 873 ex.printStackTrace(); 874 return false; 875 } 876 System.out.println(" URL=" + url); 877 try 878 { 879 URLConnection c = url.openConnection(); 880 Object o = c.getContent(); 881 System.err.println(" URL Connection in use=" + url); } 883 catch (Exception ex) 884 { 885 return false; 886 } 887 return true; 888 } 890 895 private boolean testServerPort (int port) 896 { 897 try 898 { 899 ServerSocket ss = new ServerSocket (port); 900 System.out.println(" ServerPort " + ss.getInetAddress() + ":" + ss.getLocalPort()); 901 ss.close(); 902 } 903 catch (Exception ex) 904 { 905 System.err.println(ex); 906 return false; 907 } 908 return true; 909 } 911 912 919 public boolean testPort (InetAddress host, int port, boolean shouldBenUsed) 920 { 921 Socket pingSocket = null; 922 try 923 { 924 pingSocket = new Socket(host, port); 925 } 926 catch (Exception e) 927 { 928 if (shouldBenUsed) 929 System.err.println(" Open Socket " + host + " on " + port + ": " + e.getMessage()); 930 return false; 931 } 932 if (!shouldBenUsed) 933 System.err.println(" Open Socket " + host + " on " + port); 934 if (pingSocket == null) 935 return false; 936 try 938 { 939 pingSocket.close(); 940 } 941 catch (IOException e) 942 { 943 System.out.println(" CloseSocket=" + e.toString()); 944 } 945 return true; 946 } 948 954 private boolean testJDBC (String uid, String pwd) 955 { 956 m_connectionString = "jdbc:oracle:thin:@" 958 + m_databaseServer.getHostName() + ":" + m_databasePort + ":" + m_databaseName; 959 System.out.println(" JDBC = " + m_connectionString); 960 961 try 962 { 963 if (s_driver == null) 964 { 965 s_driver = new OracleDriver(); 966 DriverManager.registerDriver(s_driver); 967 } 968 Connection con = DriverManager.getConnection(m_connectionString, 969 uid, pwd); 970 } 971 catch (Exception e) 972 { 973 System.err.println(e.toString()); 974 return false; 975 } 976 return true; 977 } 979 985 private boolean testTNS (String uid, String pwd) 986 { 987 String connectionString = "jdbc:oracle:oci8:@" + m_TNSName; 988 System.out.println(" TNS = " + connectionString); 989 try 990 { 991 if (s_driver == null) 992 { 993 s_driver = new OracleDriver(); 994 DriverManager.registerDriver(s_driver); 995 } 996 Connection con = DriverManager.getConnection(connectionString, 997 uid, pwd); 998 } 999 catch (UnsatisfiedLinkError ule) 1000 { 1001 System.err.println("Check setup of Oracle Server / Oracle Client / LD_LIBRARY_PATH"); 1002 System.err.println(ule.toString()); 1003 return false; 1004 } 1005 catch (Exception e) 1006 { 1007 System.err.println(e.toString()); 1008 return false; 1009 } 1010 return true; 1011 } 1013 1017 private boolean testMail() 1018 { 1019 boolean smtpOK = false; 1020 boolean imapOK = false; 1021 if (testPort (m_mailServer, 25, true)) 1022 { 1023 System.out.println("OK: SMTP Server contacted"); 1024 smtpOK = true; 1025 } 1026 else 1027 System.err.println("Error: SMTP Server NOT available"); 1028 if (testPort (m_mailServer, 110, true)) 1030 System.out.println("OK: POP3 Server contacted"); 1031 else 1032 System.err.println("Error: POP3 Server NOT available"); 1033 if (testPort (m_mailServer, 143, true)) 1034 { 1035 System.out.println("OK: IMAP4 Server contacted"); 1036 imapOK = true; 1037 } 1038 else 1039 System.err.println("Error: IMAP4 Server NOT available"); 1040 if (!smtpOK) 1042 return false; 1043 try 1045 { 1046 EMail em = new EMail (m_mailServer.getHostName (), 1047 m_adminEMail.toString (), m_adminEMail.toString (), 1048 "Compiere Server Setup Test", "Test: " + m_properties); 1049 em.setEMailUser (m_mailUser, m_mailPassword); 1050 if (EMail.SENT_OK.equals (em.send ())) 1051 { 1052 System.out.println ("OK: Send Test Email to " + m_adminEMail); 1053 } 1054 else 1055 { 1056 System.err.println ("Error: Could NOT send Email to " 1057 + m_adminEMail); 1058 } 1059 } 1060 catch (Exception ex) 1061 { 1062 System.err.println("testMail - " + ex.getLocalizedMessage()); 1063 return false; 1064 } 1065 1066 if (!imapOK) 1068 return false; 1069 1070 Properties props = new Properties(); 1072 props.put("mail.store.protocol", "smtp"); 1073 props.put("mail.transport.protocol", "smtp"); 1074 props.put("mail.host", m_mailServer.getHostName()); 1075 props.put("mail.user", m_mailUser); 1076 props.put("mail.smtp.auth", "true"); 1077 System.out.println(" Connecting to " + m_mailServer.getHostName()); 1078 Session session = null; 1080 Store store = null; 1081 try 1082 { 1083 EMailAuthenticator auth = new EMailAuthenticator (m_mailUser, m_mailPassword); 1084 session = Session.getDefaultInstance(props, auth); 1085 session.setDebug (Log.isTraceLevel (10)); 1086 System.out.println(" Session=" + session); 1087 store = session.getStore("imap"); 1089 System.out.println(" Store=" + store); 1090 } 1091 catch (NoSuchProviderException nsp) 1092 { 1093 System.err.println("Error Mail IMAP Provider - " + nsp.getMessage()); 1094 return false; 1095 } 1096 catch (Exception e) 1097 { 1098 System.err.println("Error Mail IMAP - " + e.getMessage()); 1099 return false; 1100 } 1101 try 1102 { 1103 store.connect(m_mailServer.getHostName(), m_mailUser, m_mailPassword); 1104 System.out.println(" Store - connected"); 1105 Folder folder = store.getDefaultFolder(); 1106 Folder inbox = folder.getFolder("INBOX"); 1107 System.out.println("OK: Mail Connect to " + inbox.getFullName() + " #Msg=" + inbox.getMessageCount()); 1108 store.close(); 1110 } 1111 catch (MessagingException mex) 1112 { 1113 System.err.println("Error Mail Connect " + mex.getMessage()); 1114 return false; 1115 } 1116 return true; 1117 } 1119 1120 1121 1124 private void save() 1125 { 1126 SwingWorker sw = startTest(); 1127 while (sw.isAlive()) 1128 { 1129 try 1130 { 1131 Thread.sleep(2000); 1132 } 1133 catch (InterruptedException ex) 1134 { 1135 System.err.println("save-waiting: " + ex); 1136 } 1137 } 1138 sw.get(); if (!m_success) 1140 return; 1141 1142 m_properties.setProperty("COMPIERE_MAIN_VERSION", Compiere.MAIN_VERSION); 1144 m_properties.setProperty("COMPIERE_DATE_VERSION", Compiere.DATE_VERSION); 1145 m_properties.setProperty("COMPIERE_DB_VERSION", Compiere.DB_VERSION); 1146 1147 1148 1149 Ini.setClient(false); 1151 String fileName = m_compiereHome.getAbsolutePath() + File.separator + Ini.COMPIERE_PROPERTY_FILE; 1152 Ini.loadProperties(fileName); 1153 1154 fileName = m_compiereHome.getAbsolutePath() + File.separator + COMPIERE_ENV_FILE; 1156 try 1157 { 1158 FileOutputStream fos = new FileOutputStream(new File(fileName)); 1159 m_properties.store(fos, COMPIERE_ENV_FILE); 1160 fos.flush(); 1161 fos.close(); 1162 } 1163 catch (Exception e) 1164 { 1165 System.err.println ("Cannot save Properties to " + fileName + " - " + e.toString()); 1166 JOptionPane.showConfirmDialog(this, res.getString("ErrorSave"), res.getString("CompiereServerSetup"), 1167 JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); 1168 return; 1169 } 1170 catch (Throwable t) 1171 { 1172 System.err.println ("Cannot save Properties to " + fileName + " - " + t.toString()); 1173 JOptionPane.showConfirmDialog(this, res.getString("ErrorSave"), res.getString("CompiereServerSetup"), 1174 JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); 1175 return; 1176 } 1177 System.out.println("Properties saved to " + fileName); 1178 1179 Ini.setCompiereHome(m_compiereHome.getAbsolutePath()); 1181 CConnection cc = CConnection.get (Database.DB_ORACLE, 1182 m_databaseServer.getHostName(), m_databasePort, m_databaseName, 1183 m_databaseUser, m_databasePassword); 1184 cc.setAppsHost(m_appsServer.getHostName()); 1185 cc.setRMIoverHTTP(false); 1186 Ini.setProperty(Ini.P_CONNECTION, cc.toStringLong()); 1187 Ini.saveProperties(false); 1188 1189 1190 JOptionPane.showConfirmDialog(this, res.getString("EnvironmentSaved"), 1191 res.getString("CompiereServerSetup"), 1192 JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); 1193 1194 ((Frame)SwingUtilities.getWindowAncestor(this)).dispose(); 1195 System.exit(0); } 1198} | Popular Tags |