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

📄 webserverform.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  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.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.LabelValueBean;

import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.InterfacesMultiSelectListDataSource;
import com.sslexplorer.input.MultiSelectSelectionModel;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.forms.DefaultWizardForm;

/**
 * Form used during installation to enter the web server details.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.13 $
 */
public class WebServerForm extends DefaultWizardForm {

    final static Log log = LogFactory.getLog(WebServerForm.class);

    // Private statics for sequence attributes

    /**
     * Web server port
     */
    public final static String ATTR_WEB_SERVER_PORT = "webServerPort";

    /**
     * Web server protocol
     */
    public final static String ATTR_WEB_SERVER_PROTOCOL = "webServerProtocol";

    /**
     * Listening interfaces
     */
    public final static String ATTR_LISTENING_INTERFACES = "bindAddresses";

    /**
     * Valid external hosts
     */
    public final static String ATTR_VALID_EXTERNAL_HOSTS = "validExternalHosts";

    /**
     * Invalid hostname action
     */
    public final static String ATTR_INVALID_HOSTNAME_ACTION = "invalidHostnameAction";

    // Private instance variables
    private String port;
    private String protocol;
    private String listeningInterfaces;
    private String invalidHostnameAction;
    private String validExternalHostnames;
    private MultiSelectSelectionModel model;

    public final static List TYPES = new ArrayList();

    static {
        TYPES.add(new LabelValueBean("HTTPS", "https"));
        TYPES.add(new LabelValueBean("HTTP", "http"));
    }

    /**
     * Constructor
     */
    public WebServerForm() {
        super(true, true, "/WEB-INF/jsp/content/install/webServer.jspf", "port", true, false, "webServer", "install",
                        "installation.webServer", 4);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence,
     *      javax.servlet.http.HttpServletRequest)
     */
    public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception {
        try {
            port = (String) sequence.getAttribute(ATTR_WEB_SERVER_PORT, CoreServlet.getServlet().getPropertyDatabase().getProperty(
                0, null, "webServer.port"));
            protocol = (String) sequence.getAttribute(ATTR_WEB_SERVER_PROTOCOL, CoreServlet.getServlet().getPropertyDatabase()
                            .getProperty(0, null, "webServer.protocol"));
            listeningInterfaces = (String) sequence.getAttribute(ATTR_LISTENING_INTERFACES, CoreServlet.getServlet()
                            .getPropertyDatabase().getProperty(0, null, "webServer.bindAddress"));
            validExternalHostnames = (String) sequence.getAttribute(ATTR_VALID_EXTERNAL_HOSTS, CoreServlet.getServlet()
                            .getPropertyDatabase().getProperty(0, null, "webServer.validExternalHostnames"));
            invalidHostnameAction = (String) sequence.getAttribute(ATTR_INVALID_HOSTNAME_ACTION, CoreServlet.getServlet()
                .getPropertyDatabase().getProperty(0, null, "webServer.invalidHostnameAction"));
            PropertyList pl = new PropertyList(listeningInterfaces);
            model = new MultiSelectSelectionModel(new InterfacesMultiSelectListDataSource(), pl);
        } 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_WEB_SERVER_PORT, port);
        sequence.putAttribute(ATTR_WEB_SERVER_PROTOCOL, protocol);
        sequence.putAttribute(ATTR_LISTENING_INTERFACES, listeningInterfaces);
        sequence.putAttribute(ATTR_VALID_EXTERNAL_HOSTS, validExternalHostnames);
        sequence.putAttribute(ATTR_INVALID_HOSTNAME_ACTION, invalidHostnameAction);
    }

    /*
     * (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 (isCommiting()) {
            ActionErrors errs = new ActionErrors();

            try {
                int port = Integer.parseInt(getPort());
                PropertyList l = PropertyList.createFromTextFieldText(getListeningInterfaces().equals("") ? "0.0.0.0"
                                : getListeningInterfaces());
                for (Iterator i = l.iterator(); i.hasNext();) {
                    String address = (String) i.next();
                    ServerSocket s = null;
                    try {
                    	if (log.isInfoEnabled())
                    		log.info("Testing listener on " + address + ":" + port);
                        s = new ServerSocket(port, 0, InetAddress.getByName(address));
                        if (address.equals("0.0.0.0")) {
                            break;
                        }
                    } catch (IOException e) {
                        log.error("Failed to setup server socket.", e);
                        if (port < 1024) {
                            errs.add(Globals.ERROR_KEY, new ActionMessage("installation.webServer.error.portConflictLess1024",
                                            getPort(), address));
                        } else {
                            errs.add(Globals.ERROR_KEY, new ActionMessage("installation.webServer.error.portConflict", getPort(),
                                            address));
                        }
                    } finally {
                        if (s != null) {
                            try {
                                s.close();
                            } catch (Exception e) {
                            }
                        }
                    }
                }

            } catch (NumberFormatException nfe) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.webServer.error.invalidPortNumber", getPort()));
            }
            return errs;
        } else {
            return null;
        }
    }

    /**
     * Get list list of listening interfaces as newline separated string
     * 
     * @return listening interfaces as newline separated string
     */
    public String getListeningInterfaces() {
        return listeningInterfaces;
    }

    /**
     * Set the list of listening interfaces as newline separated string
     * 
     * @param listeningInterfaces listening interfaces as newline separated
     *        string
     */
    public void setListeningInterfaces(String listeningInterfaces) {
        this.listeningInterfaces = listeningInterfaces;
    }

    /**
     * Get the port on which the server should run
     * 
     * @return port
     */
    public String getPort() {
        return port;
    }

    /**
     * Set the port on which the server should run
     * 
     * @param port port on which server should run
     */
    public void setPort(String port) {
        this.port = port;
    }

    /**
     * Get the newline separated list of valid external hostnames
     * 
     * @return valid external hostnames
     */
    public String getValidExternalHostnames() {
        return validExternalHostnames;
    }

    /**
     * Set the newline separated list of valid external hostnames
     * 
     * @param validExternalHostnames valid external hostnames
     */
    public void setValidExternalHostnames(String validExternalHostnames) {
        this.validExternalHostnames = validExternalHostnames;
    }

    /**
     * Get the model of items that may be selected for valid listening
     * interfaces
     * 
     * @return model for valid listening interfaces
     */
    public MultiSelectSelectionModel getModel() {
        return model;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public List getProtocolList() {
        return TYPES;
    }
    
    public String getInvalidHostnameAction() {
        return invalidHostnameAction;
    }
    
    public void setInvalidHostnameAction(String invalidHostnameAction) {
        this.invalidHostnameAction = invalidHostnameAction;
    }

}

⌨️ 快捷键说明

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