1 2 23 24 package net.fenyo.gnetwatch; 25 26 import java.io.*; 27 import java.util.*; 28 import javax.net.ssl.*; 29 import java.util.regex.Matcher ; 30 import java.util.regex.Pattern ; 31 import java.security.*; 32 import java.security.cert.*; 33 34 import net.fenyo.gnetwatch.GUI.*; 35 import net.fenyo.gnetwatch.actions.ExternalCommand; 36 import net.fenyo.gnetwatch.activities.*; 37 import net.fenyo.gnetwatch.data.EventReachable; 38 39 import org.dom4j.*; 40 import org.dom4j.io.*; 41 42 import org.apache.commons.logging.*; 43 44 51 52 public class CommandLine { 53 private static Log log = LogFactory.getLog(CommandLine.class); 54 55 static public class NoCheckTrustManager implements X509TrustManager { 56 private X509TrustManager myTrustManager; 57 58 public NoCheckTrustManager() throws java.security.NoSuchAlgorithmException { 59 TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); 60 try { 61 trustManagerFactory.init((KeyStore) null); 62 myTrustManager = (X509TrustManager) trustManagerFactory.getTrustManagers()[0]; 63 } catch (KeyStoreException ex) { 64 log.error("Exception", ex); 65 } 66 } 67 68 public X509Certificate[] getAcceptedIssuers() { 69 return myTrustManager.getAcceptedIssuers(); 70 } 71 72 public void checkClientTrusted(X509Certificate chain[], String authType) throws CertificateException {} 73 74 public void checkServerTrusted(X509Certificate chain[], String authType) throws CertificateException {} 75 } 76 77 84 public static void main(String [] args) 85 throws IOException, FileNotFoundException, InterruptedException { 86 Config config = null; 87 Synchro synchro = null; 88 Background background = null; 89 GUI gui = null; 90 Main main = null; 91 SNMPManager snmp_manager = null; 92 CaptureManager capture_mgr = null; 93 94 config = new Config(); 96 97 GenericTools.initLogEngine(config); 99 log.info(config.getString("log_engine_initialized")); 100 log.info(config.getString("begin")); 101 102 105 SSLContext ssl_context = null; 107 try { 108 ssl_context = SSLContext.getInstance("SSL"); 109 ssl_context.init(null, new TrustManager [] {new NoCheckTrustManager() }, new SecureRandom()); 110 } catch (final NoSuchAlgorithmException ex) { 111 log.error("Exception", ex); 112 } catch (final KeyManagementException ex) { 113 log.error("Exception", ex); 114 } 115 HttpsURLConnection.setDefaultSSLSocketFactory(ssl_context.getSocketFactory()); 116 HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier () { 117 public final boolean verify(String hostname, SSLSession session) { 118 return true; 119 } 120 }); 121 122 background = new Background(config); 124 background.createBackgroundThread(); 125 126 capture_mgr = new CaptureManager(config); 128 129 main = new Main(config, capture_mgr); 131 132 snmp_manager = new SNMPManager(); 134 135 gui = new GUI(config, background, main, snmp_manager); 137 main.setGUI(gui); 138 capture_mgr.setGUI(gui); 139 gui.waitForCreation(); 140 141 gui.createFromXML(gui.getConfig().getProperty("initialobjects")); 143 144 gui.join(); 146 log.info(config.getString("end")); 148 149 config.setEnd(); 151 gui.end(); 152 background.end(); 153 capture_mgr.unRegisterAllListeners(); 154 } 155 } 156 | Popular Tags |