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

📄 configureproxiesform.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.install.forms;

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.extensions.store.ExtensionStore;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.forms.DefaultWizardForm;

public class ConfigureProxiesForm extends DefaultWizardForm {
    
    final static Log log = LogFactory.getLog(ConfigureProxiesForm.class);

    // Private statics for sequence attributes
    public final static String ATTR_USE_SOCKS_PROXY = "useSOCKSProxy";
    public final static String ATTR_USE_HTTP_PROXY = "useHTTPProxy";
    public final static String ATTR_SOCKS_PROXY_HOSTNAME = "SOCKSProxyHostname";
    public final static String ATTR_SOCKS_PROXY_PORT = "SOCKSProxyPort";
    public final static String ATTR_SOCKS_PROXY_USERNAME = "SOCKSProxyUsername";
    public final static String ATTR_SOCKS_PROXY_PASSWORD = "SOCKSProxyPassword";
    public final static String ATTR_HTTP_PROXY_HOSTNAME = "HTTPProxyHostname";
    public final static String ATTR_HTTP_PROXY_PORT = "HTTPProxyPort";
    public final static String ATTR_HTTP_PROXY_USERNAME = "HTTPProxyUsername";
    public final static String ATTR_HTTP_PROXY_PASSWORD = "HTTPProxyPassword";
    public final static String ATTR_EXTENSION_STORE_EXCEPTION = "extensionStoreException";
    public final static Object ATTR_HTTP_NON_PROXY_HOSTS = "HTTPNonProxyHosts";
    
    // Private instance variables
    private boolean useSOCKSProxy;
    private boolean useHTTPProxy;
    private String socksProxyHostname;
    private String socksProxyPort;
    private String socksProxyUsername;
    private String socksProxyPassword;
    private String httpProxyHostname;
    private String httpProxyPort;
    private String httpProxyUsername;
    private String httpProxyPassword;
    private PropertyList httpNonProxyHosts;

    public ConfigureProxiesForm() {
        super(true, true, "/WEB-INF/jsp/content/install/configureProxies.jspf", 
            "useSOCKSProxy", true, false, "configureProxies", "install", "installation.configureProxies", 5);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception {
        try {
            if(sequence.getAttribute(ATTR_SOCKS_PROXY_HOSTNAME, null) == null) {
                socksProxyHostname = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.socksProxyHost");
                if(socksProxyHostname.equals("")) {
                    socksProxyUsername = "";
                    socksProxyPort = "";
                    socksProxyPassword = "";
                }
                else {
                    useSOCKSProxy = true;
                    socksProxyUsername = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.socksProxyUser");
                    socksProxyPassword = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.socksProxyPassword");
                    socksProxyPort = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.socksProxyPort");
                }                    
            }
            else {
                useSOCKSProxy = ((String)sequence.getAttribute(ATTR_USE_SOCKS_PROXY, 
                    CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "webServer.port"))).equals("true");
                socksProxyHostname = (String)sequence.getAttribute(ATTR_SOCKS_PROXY_HOSTNAME, "");
                socksProxyPort = (String)sequence.getAttribute(ATTR_SOCKS_PROXY_PORT, "");
                socksProxyUsername = (String)sequence.getAttribute(ATTR_SOCKS_PROXY_USERNAME, "");
                socksProxyPassword = (String)sequence.getAttribute(ATTR_SOCKS_PROXY_PASSWORD, "");
            }

            if(sequence.getAttribute(ATTR_HTTP_PROXY_HOSTNAME, null) == null) {
                httpProxyHostname = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.http.proxyHost");
                httpNonProxyHosts = new PropertyList(CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.http.nonProxyHosts"));
                if(httpProxyHostname.equals("")) {
                    httpProxyUsername = "";
                    httpProxyPort = "";
                    httpProxyPassword = "";
                    httpNonProxyHosts.clear();
                }
                else {
                    useHTTPProxy = true;
                    httpProxyUsername = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.http.proxyUser");
                    httpProxyPassword = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.http.proxyPassword");
                    httpProxyPort = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "proxies.http.proxyPort");
                }                    
            }
            else {
                useHTTPProxy = ((String)sequence.getAttribute(ATTR_USE_HTTP_PROXY, 
                    CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "webServer.port"))).equals("true");
                httpProxyHostname = (String)sequence.getAttribute(ATTR_HTTP_PROXY_HOSTNAME, "");
                httpProxyPort = (String)sequence.getAttribute(ATTR_HTTP_PROXY_PORT, "");
                httpProxyUsername = (String)sequence.getAttribute(ATTR_HTTP_PROXY_USERNAME, "");
                httpProxyPassword = (String)sequence.getAttribute(ATTR_HTTP_PROXY_PASSWORD, "");
                httpNonProxyHosts = (PropertyList)sequence.getAttribute(ATTR_HTTP_NON_PROXY_HOSTS, null);
            }
        }
        catch(Exception e) {
            log.error("Failed to initialise form.");
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void apply(AbstractWizardSequence sequence) throws Exception {
        sequence.putAttribute(ATTR_USE_SOCKS_PROXY, String.valueOf(useSOCKSProxy));
        sequence.putAttribute(ATTR_USE_HTTP_PROXY, String.valueOf(useHTTPProxy));
        sequence.putAttribute(ATTR_SOCKS_PROXY_HOSTNAME, socksProxyHostname);
        sequence.putAttribute(ATTR_SOCKS_PROXY_PORT, socksProxyPort);
        sequence.putAttribute(ATTR_SOCKS_PROXY_USERNAME, socksProxyUsername);
        sequence.putAttribute(ATTR_SOCKS_PROXY_PASSWORD, socksProxyPassword);
        sequence.putAttribute(ATTR_HTTP_PROXY_HOSTNAME, httpProxyHostname);
        sequence.putAttribute(ATTR_HTTP_PROXY_PORT, httpProxyPort);
        sequence.putAttribute(ATTR_HTTP_PROXY_USERNAME, httpProxyUsername);
        sequence.putAttribute(ATTR_HTTP_PROXY_PASSWORD, httpProxyPassword);
        sequence.putAttribute(ATTR_HTTP_NON_PROXY_HOSTS, httpNonProxyHosts);

        
        String socksUsername = null, socksPassword = null, httpUsername = null, httpPassword = null;
        
    // Configure proxy settings as entered in the wizard sequence. 
        if(sequence.getAttribute(ConfigureProxiesForm.ATTR_USE_SOCKS_PROXY, "").equals("true")) {            
        	if (log.isInfoEnabled())
        		log.info("Configuring outgoing TCP/IP connections to use a SOCKS proxy server.");
            System.setProperty("socksProxyHost", (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_HOSTNAME, ""));
            System.setProperty("socksProxyPort", (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_PORT, "1080"));
            socksUsername = (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_USERNAME, "");
            socksPassword = (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_PASSWORD, "");
        } 
        if(sequence.getAttribute(ConfigureProxiesForm.ATTR_USE_HTTP_PROXY, "").equals("true")) {            
        	if (log.isInfoEnabled())
        		log.info("Configuring outgoing web connections to use a HTTP proxy server.");
            System.setProperty("http.proxyHost", (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_HOSTNAME, ""));
            System.setProperty("com.maverick.ssl.https.HTTPProxyHostname", (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_HOSTNAME, ""));
            System.setProperty("http.proxyPort", (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_PORT, "3128"));
            System.setProperty("com.maverick.ssl.https.HTTPProxyPort", (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_PORT, "3128"));
            PropertyList list =(PropertyList)sequence.getAttribute(ConfigureProxiesForm.ATTR_HTTP_NON_PROXY_HOSTS, null);            
            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());
            httpUsername = (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_USERNAME, "");
            httpPassword = (String)sequence.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_PASSWORD, "");
            System.setProperty("com.maverick.ssl.https.HTTPProxySecure", "false");
        }
        if(httpUsername != null || socksUsername != null) {
            Authenticator.setDefault(new ProxyAuthenticator(socksUsername, socksPassword, httpUsername, httpPassword));
        }
        
        ExtensionStore.getInstance().resetExtensionStoreUpdate();
        try {
            ExtensionStore.getInstance().getDownloadableExtensionStoreDescriptor(true);
            sequence.removeAttribute(ATTR_EXTENSION_STORE_EXCEPTION);
        }
        catch(Exception e) {
            log.error("Failed to connect to extension store.", e);
            sequence.putAttribute(ATTR_EXTENSION_STORE_EXCEPTION, e);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
     *      javax.servlet.http.HttpServletRequest)
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
//        if(superUserPassword != null) {
//            try {
//                // keyPassword length is less than six characters long
//                // This will also catch keyPassword when null
//                if (superUserPassword.length() < 6) {

⌨️ 快捷键说明

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