⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        // Create the webapp
        HttpContext context = new HttpContext();
        context.setContextPath("/");
        context.setResourceBase("./dummy/");
        context.addHandler(new SecureHandler());
        server.addContext(context);

        // Configure the server
        server.setRequestsPerGC(2000);
        server.setStatsOn(false);

        insecureThread = new Thread(threadGroup, "InsecureWebServer") {
            public void run() {
                // Start the server
                try {
                    server.start();
                } catch (Exception e) {
                    log.error("Failed to start HTTP Jetty. " + e.getMessage(), e);
                    if (useWrapper) {
                        WrapperManager.stop(1);
                    } else {
                        System.exit(1);
                    }
                }
            }
        };

        if (log.isInfoEnabled())
            log.info("Starting HTTP redirect server");
        insecureThread.start();

    }

    private void normalMode() throws Exception {

        if (log.isInfoEnabled())
            log.info("Starting Jetty Web Server");

        server = new Server();

        // SunJsseListener listener = new SunJsseListener();
        String keystorePassword = getContextProperty("webServer.keystore.sslCertificate.password");
        if (keystorePassword.equals("")) {
            throw new Exception(
                            "Private key / certificate password has not been set. Please run the SSL Explorer Installation Wizard.");
        }

        actualPort = defaultPort == -1 ? Integer.parseInt(getContextProperty("webServer.port")) : defaultPort;
        String bind = getContextProperty("webServer.bindAddress");
        listeners = new ArrayList();
        PropertyList l = new PropertyList(bind.equals("") ? "0.0.0.0" : bind);
        for (Iterator i = l.iterator(); i.hasNext();) {
            String address = (String) i.next();
            if (log.isInfoEnabled())
                log.info("Adding listener on " + address + ":" + actualPort);
            if (!serverLock.isStarted()) {
                serverLock.start(actualPort);
            }
            SocketListener listener = null;
            if (getContextProperty("webServer.protocol").equals("http")) {
                listener = new SocketListener();
                log.warn("SSL-Explorer is configured to listen for plain HTTP connections.");
            } else {
                listener = new CustomJsseListener(keystorePassword);
                MsieSslHandler sslHandler = new MsieSslHandler();
                sslHandler.setUserAgentSubString("MSIE 5");
                listener.setHttpHandler(sslHandler);
            }
            listener.setPort(actualPort);
            listener.setMinThreads(Integer.parseInt(getContextProperty("webServer.minThreads")));
            listener.setMaxThreads(Integer.parseInt(getContextProperty("webServer.maxThreads")));
            listener.setMaxIdleTimeMs(Integer.parseInt(getContextProperty("webServer.maxIdleTimeMs")));
            listener.setHost(address);
            listener.setBufferSize(Integer.parseInt(getContextProperty("webServer.bufferSize")));
            listener.setBufferReserve(Integer.parseInt(getContextProperty("webServer.bufferReserve")));

            // listener.setNeedClientAuth(true);
            listeners.add(listener);

            listener.setLowResourcePersistTimeMs(Integer.parseInt(getContextProperty("webServer.lowResourcePersistTimeMs")));
            listener.setPoolName("main");
            server.addListener(listener);
        }

        /*
         * <Call name="addListener"> <Arg> <New
         * class="org.enhydra.servlet.connectionMethods.EnhydraDirector.EnhydraListener">
         * <Set name="Port">9003</Set> <Set name="MinThreads">10</Set> <Set
         * name="MaxThreads">100</Set> <Set name="SessionAffinity">true</Set>
         * <Set name="BindAddress">(All Interfaces)</Set> <Set
         * name="AuthKey">(Unauthenticated)</Set> <Set name="ClientTimeout">300</Set>
         * </New> </Arg> </Call>
         */
        // EnhydraListener enhydraListener = new EnhydraListener();
        // enhydraListener.setPort(9003);
        // enhydraListener.setMinThreads(10);
        // enhydraListener.setMaxThreads(100);
        // enhydraListener.setSessionAffinity("true");
        // enhydraListener.setBindAddress("(All Interfaces)");
        // enhydraListener.setAuthKey("(Unauthenticated)");
        // enhydraListener.setClientTimeout(300);
        // server.addListener(enhydraListener);
        // Add the context
        httpContext = new CustomHttpContext(server, "/", useDevConfig);
        httpContext.setRedirectNullPath(false);
        server.addContext(httpContext);

        // Add the webapp
        webappContext = new CustomWebApplicationContext(useDevConfig);

        // Load any extension classes before adding the context to the server
        File exts = new File("webapp/WEB-INF/exts");

        // If the exts folder does not exist create it.
        if (!exts.exists())
            exts.mkdirs();

        File[] jars = exts.listFiles(new FilenameFilter() {
            public boolean accept(File f, String filename) {
                return filename.endsWith(".jar");
            }
        });

        for (int i = 0; i < jars.length; i++) {
            addContextLoaderURL(jars[i].toURL());
        }

        server.addContext(webappContext);
        webappContext.setRedirectNullPath(false);

        // Configure the server
        server.setRequestsPerGC(Integer.parseInt(getContextProperty("webServer.requestsPerGC")));
        server.setStatsOn(false);

        // Set the request log
        if ("true".equals(getContextProperty("webServer.requestLog"))) {
            NCSARequestLog requestLog = new NCSARequestLog(jettyLog);
            requestLog.setRetainDays(90);
            requestLog.setAppend(true);
            requestLog.setExtended(false);
            requestLog.setBuffered(false);
            requestLog.setLogTimeZone("GMT");
            server.setRequestLog(requestLog);
        }

        mainThread = new Thread(threadGroup, "WebServer") {
            public void run() {
                // Start the server
                try {
                    server.start();
                    if (useDevConfig) {
                        log.warn("Server startup took " + ((System.currentTimeMillis() - startupStarted) / 1000) + " seconds");
                    }
                } catch (Exception e) {
                    log.error("Failed to start Jetty. " + e.getMessage(), e);
                    if (useWrapper) {
                        WrapperManager.stop(1);
                    } else {
                        System.exit(1);
                    }
                }
            }
        };
        mainThread.start();
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.Context#addWebApp(java.lang.String,
     *      java.lang.String)
     */
    public void addWebApp(String path, String warFile) throws Exception {
        log.info("Adding webapp '" + path + "' using path / war '" + warFile + "'");
        HttpContext context = server.addWebApplication(path, warFile);
        context.start();
    }

    private void setupMode() throws Exception {
        actualPort = defaultPort == -1 ? 28080 : defaultPort;
        serverLock.start(actualPort);

        server = new Server();
        SocketListener socketListener = new SocketListener();
        socketListener.setPort(actualPort);
        socketListener.setMinThreads(10);
        socketListener.setMaxThreads(200);
        socketListener.setMaxIdleTimeMs(0);
        socketListener.setLowResourcePersistTimeMs(2000);
        socketListener.setAcceptQueueSize(0);
        socketListener.setPoolName("P1");
        server.addListener(socketListener);

        // // Add the context
        // HttpContext context = new CustomHttpContext(server, "/",
        // useDevConfig);
        // server.addContext(context);

        // Create the webapp

        webappContext = new CustomWebApplicationContext(useDevConfig);
        server.addContext(webappContext);

        // Configure the server
        server.setRequestsPerGC(2000);
        server.setStatsOn(false);

        String realHostname = hostname == null ? InetAddress.getLocalHost().getHostName() : hostname;

        /*
         * If the 'Active DNS' feature is enabled, the DNS server may return the
         * wild-card name. This will probably fail. As a work-around, if the
         * hostname looks like a wildcard, then it is simply changed to
         * 'localhost'.
         */
        if (realHostname.startsWith("*.")) {
            realHostname = "localhost";
        }

        //
        final String fRealHostname = realHostname;
        final int realPort = defaultPort == -1 ? 28080 : defaultPort;

        mainThread = new Thread(threadGroup, "WebServer") {
            public void run() {
                // Start the server
                try {
                    server.start();

                    if (!useWrapper && !"true".equals(System.getProperty("sslexplorer.noBrowserLaunch"))) {
                        try {
                            BrowserLauncher.openURL("http://" + fRealHostname + ":" + realPort);
                            System.out.println("A browser has been opened and pointed to http://" + fRealHostname + ":" + realPort
                                            + ". ");
                        } catch (Exception ex) {
                            System.out.println("Point your browser to http://" + fRealHostname + ":" + realPort + ". ");
                        }
                    } else {
                        System.out.println("Point your browser to http://" + fRealHostname + ":" + realPort + ". ");
                    }
                    System.out
                                    .println("\nPress CTRL+C or use the 'Shutdown' option from the web interface to leave the installation wizard.");
                } catch (Exception e) {
                    log.error("Failed to start Jetty. " + e.getMessage(), e);
                    if (useWrapper) {
                        WrapperManager.stop(1);
                    } else {
                        System.exit(1);
                    }
                }
            }
        };

        System.out.print("Starting SSL Explorer installation wizard");
        mainThread.start();

        // Wait for up to 30 seconds for the server to become available
        boolean running = false;

        if (!"true".equals(System.getProperty("sslexplorer.disableStartupCheck", "false"))) {
            int i = 0;
            for (; i < 120 && !running; i++) {
                try {
                    System.out.print(".");
                    Socket s = new Socket(realHostname, realPort);
                    s.close();
                    running = true;
                } catch (Exception ex) {
                    try {
                        Thread.sleep(1000);
                    } catch (Exception ex2) {
                    }
                }
            }
            System.out.println();
        } else {
            running = true;
        }
        if (!running) {
            System.out.println("Failed to start installation wizard. Check the logs for more detail.");
            if (useWrapper) {
                WrapperManager.stop(1);
            } else {
                System.exit(1);
            }
        }
    }

    private void configureProxyServers() throws Exception {

        String httpProxyHost = getContextProperty("proxies.http.proxyHost");
        if (!httpProxyHost.equals("")) {
            if (log.isInfoEnabled())
                log.info("Configuring outgoing HTTP connections to use a proxy server.");
            System.setProperty("http.proxyHost", httpProxyHost);
            System.setProperty("com.maverick.ssl.https.HTTPProxyHostname", httpProxyHost);
            String httpProxyPort = getContextProperty("proxies.http.proxyPort");
            System.setProperty("http.proxyPort", httpProxyPort);
            System.setProperty("com.maverick.ssl.https.HTTPProxyPort", httpProxyPort);
            // TODO impossible to support HTTPS proxying ATM - We would have
            // to
            // write our own HttpURLConnection as well
            // System.setProperty("com.maverick.ssl.https.HTTPProxySecure",
            // getPropertyDatabase().getProperty(0, null,
            // "proxies.http.secure"));
            System.setProperty("com.maverick.ssl.https.HTTPProxySecure", "false");

            PropertyList list = new PropertyList(getContextProperty("proxies.http.nonProxyHosts"));
            StringBuffer hosts = new StringBuffer();
            for (Iterator i = list.iterator(); i.hasNext();) {
                if (hosts.length() != 0) {
                    hosts.append("|");
                }
                hosts.append(i.next());
            }
            System.setProperty("http.nonProxyHosts", hosts.toString());
            System.setProperty("com.maverick.ssl.https.HTTPProxyNonProxyHosts", hosts.toString());
        }
        String socksProxyHost = getContextProperty("proxies.socksProxyHost");
        if (!socksProxyHost.equals("")) {
            if (log.isInfoEnabled())
                log.info("Configuring outgoing TCP/IP connections to use a SOCKS proxy server.");
            System.setProperty("socksProxyHost", httpProxyHost);
            System.setProperty("socksProxyPort", getContextProperty("proxies.socksProxyPort"));
        }
        if (!socksProxyHost.equals("") || !httpProxyHost.equals("")) {
            Authenticator.setDefault(new ProxyAuthenticator());
        }
    }

    private void displaySystemInfo() throws SocketException {

        //

        if (useDevConfig) {
            log.warn("Development environment enabled. Do not use this on a production server.");
        }

        if (log.isInfoEnabled()) {
            log.info("Java version is " + System.getProperty("java.version"));
            log.info("SSL Explorer is installed on " + hostname + "/" + hostAddress);
            log.info("Configuration: " + CONF_DIR.getAbsolutePath());
        }

        Enumeration e = NetworkInterface.getNetworkInterfaces();

        while (e.hasMoreElements()) {
            NetworkInterface netface = (NetworkInterface) e.nextElement();
            if (log.isInfoEnabled())
                log.info("Net interface: " + netface.getName());

            Enumeration e2 = netface.getInetAddresses();

            while (e2.hasMoreElements()) {
                InetAddress ip = (InetAddress) e2.nextElement();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -