1 20 21 package org.jivesoftware.messenger.container; 22 23 import org.jivesoftware.messenger.XMPPServer; 24 import org.jivesoftware.util.JiveGlobals; 25 import org.jivesoftware.util.LocaleUtils; 26 import org.jivesoftware.util.Log; 27 import org.mortbay.http.SunJsseListener; 28 import org.mortbay.jetty.Server; 29 import org.mortbay.jetty.servlet.WebApplicationContext; 30 import org.mortbay.log.Factory; 31 import org.mortbay.log.LogImpl; 32 import org.mortbay.log.OutputStreamLogSink; 33 import org.mortbay.util.InetAddrPort; 34 35 import java.io.File ; 36 37 43 public class AdminConsolePlugin implements Plugin { 44 45 private static Server jetty = null; 46 private String interfaceName; 47 private int port; 48 private int securePort; 49 50 53 public AdminConsolePlugin() { 54 } 55 56 public void initializePlugin(PluginManager manager, File pluginDir) { 57 try { 58 System.setProperty("org.apache.commons.logging.LogFactory", "org.mortbay.log.Factory"); 60 File logDir = new File (JiveGlobals.getHomeDirectory(), "logs"); 61 if (!logDir.exists()) { 62 logDir.mkdirs(); 63 } 64 File logFile = new File (logDir, "admin-console.log"); 65 OutputStreamLogSink logSink = new OutputStreamLogSink(logFile.toString()); 66 logSink.start(); 67 LogImpl log = (LogImpl) Factory.getFactory().getInstance(""); 68 log.setVerbose(-1); 70 log.add(logSink); 71 72 jetty = new Server(); 73 74 boolean plainStarted = false; 76 interfaceName = JiveGlobals.getXMLProperty("adminConsole.interface"); 79 port = JiveGlobals.getXMLProperty("adminConsole.port", 9090); 80 InetAddrPort address = new InetAddrPort(interfaceName, port); 81 if (port > 0) { 82 jetty.addListener(address); 83 plainStarted = true; 84 } 85 86 boolean secureStarted = false; 87 try { 88 securePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091); 89 if (securePort > 0) { 90 SunJsseListener listener = new SunJsseListener(); 91 String keyStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.keystore", 93 "resources" + File.separator + "security" + File.separator + "keystore"); 94 keyStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + keyStoreLocation; 95 96 String keypass = JiveGlobals.getProperty("xmpp.socket.ssl.keypass", "changeit"); 98 keypass = keypass.trim(); 99 100 String trustStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.truststore", 102 "resources" + File.separator + "security" + File.separator + "truststore"); 103 trustStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + 104 trustStoreLocation; 105 106 String trustpass = JiveGlobals.getProperty("xmpp.socket.ssl.trustpass", "changeit"); 108 trustpass = trustpass.trim(); 109 110 listener.setKeystore(keyStoreLocation); 111 listener.setKeyPassword(keypass); 112 listener.setPassword(keypass); 113 114 listener.setHost(interfaceName); 115 listener.setPort(securePort); 116 117 jetty.addListener(listener); 118 secureStarted = true; 119 } 120 } 121 catch (Exception e) { 122 Log.error(e); 123 } 124 125 WebApplicationContext webAppContext = jetty.addWebApplication("/", 127 pluginDir.getAbsoluteFile() + File.separator + "webapp"); 128 webAppContext.setWelcomeFiles(new String []{"index.jsp"}); 129 130 jetty.start(); 131 132 String warning = LocaleUtils.getLocalizedString("admin.console.warning"); 133 String listening = LocaleUtils.getLocalizedString("admin.console.listening"); 134 135 if (!plainStarted && !secureStarted) { 136 Log.info(warning); 137 System.out.println(warning); 138 } 139 else if (!plainStarted && secureStarted) { 140 Log.info(listening + " https://" + 141 XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort); 142 System.out.println(listening + " https://" + 143 XMPPServer.getInstance().getServerInfo().getName() + ":" + securePort); 144 } 145 else if (!secureStarted && plainStarted) { 146 Log.info(listening + " http://" + 147 XMPPServer.getInstance().getServerInfo().getName() + ":" + port); 148 System.out.println(listening + " http://" + 149 XMPPServer.getInstance().getServerInfo().getName() + ":" + port); 150 } 151 else { 152 String msg = listening + ":\n" + 153 " http://" + XMPPServer.getInstance().getServerInfo().getName() + ":" + 154 port + "\n" + 155 " https://" + XMPPServer.getInstance().getServerInfo().getName() + ":" + 156 securePort; 157 Log.info(msg); 158 System.out.println(msg); 159 } 160 } 161 catch (Exception e) { 162 System.err.println("Error starting admin console: " + e.getMessage()); 163 Log.error("Trouble initializing admin console", e); 164 } 165 } 166 167 public void destroyPlugin() { 168 try { 169 if (jetty != null) { 170 jetty.stop(); 171 jetty = null; 172 } 173 } 174 catch (InterruptedException e) { 175 Log.error(LocaleUtils.getLocalizedString("admin.error"), e); 176 } 177 } 178 179 184 public static Server getJettyServer() { 185 return jetty; 186 } 187 } | Popular Tags |