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

📄 tunneldetailsform.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.tunnels.wizards.forms;

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 com.sslexplorer.core.BundleActionMessage;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.forms.AbstractResourceDetailsWizardForm;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.tunnels.TransportType;
import com.sslexplorer.wizard.AbstractWizardSequence;

public class TunnelDetailsForm extends AbstractResourceDetailsWizardForm {

    public final static String ATTR_SOURCE_PORT = "sourcePort";
    public final static String ATTR_DESTINATION_HOST = "destinationHost";
    public final static String ATTR_DESTINATION_PORT = "destinationPort";
    public final static String ATTR_TYPE = "tunnelType";
    public final static String ATTR_TRANSPORT = "transport";
    public final static String ATTR_AUTO_START = "autoStart";
    public final static String ATTR_ALLOW_EXTERNAL_HOSTS = "allowExternalHosts";

    private String sourcePort;
    private String destinationHost;
    private String destinationPort;
    private int tunnelType;
    private String transport;
    private boolean autoStart;
    private boolean allowExternalHosts;

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

    public TunnelDetailsForm() {
        super(true, true, "/WEB-INF/jsp/content/tunnels/tunnelWizard/tunnelDetails.jspf", "resourceName", true, false,
                        "tunnelDetails", "tunnels", "tunnelWizard.tunnelDetails", 2,
                        PolicyConstants.SSL_TUNNEL_RESOURCE_TYPE);
    }

    public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception {
        super.init(sequence, request);
        sourcePort = ((Integer) sequence.getAttribute(ATTR_SOURCE_PORT, new Integer(0))).toString();
        destinationHost = (String) sequence.getAttribute(ATTR_DESTINATION_HOST, "");
        destinationPort = ((Integer) sequence.getAttribute(ATTR_DESTINATION_PORT, new Integer(0))).toString();
        tunnelType = ((Integer) sequence.getAttribute(ATTR_TYPE, new Integer(0))).intValue();
        transport = (String) sequence.getAttribute(ATTR_TRANSPORT, "");
        autoStart = ((Boolean) sequence.getAttribute(ATTR_AUTO_START, Boolean.FALSE)).booleanValue();
        allowExternalHosts = ((Boolean) sequence.getAttribute(ATTR_ALLOW_EXTERNAL_HOSTS, Boolean.FALSE)).booleanValue();
    }

    public void apply(AbstractWizardSequence sequence) throws Exception {
        super.apply(sequence);
        sequence.putAttribute(ATTR_SOURCE_PORT, new Integer(sourcePort));
        sequence.putAttribute(ATTR_DESTINATION_HOST, destinationHost);
        sequence.putAttribute(ATTR_DESTINATION_PORT, new Integer(destinationPort));
        sequence.putAttribute(ATTR_TYPE, new Integer(tunnelType));
        sequence.putAttribute(ATTR_TRANSPORT, transport);
        sequence.putAttribute(ATTR_AUTO_START, new Boolean(autoStart));
        sequence.putAttribute(ATTR_ALLOW_EXTERNAL_HOSTS, new Boolean(allowExternalHosts));
    }

    public Resource getResourceByName(String name) throws Exception {
        return CoreServlet.getServlet().getSystemDatabase().getTunnel(name);
    }

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        if (getResourceName() != null && isCommiting()) {
            ActionErrors errs = super.validate(mapping, request);
            AbstractWizardSequence seq = getWizardSequence(request);

            try {
                Integer.valueOf(sourcePort).intValue();
            } catch (NumberFormatException e) {
                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                .getCurrentPageForm().getResourcePrefix()
                                + ".error.sourcePortNotInteger"));
            }

            try {
                Integer.valueOf(destinationPort).intValue();
            } catch (NumberFormatException e) {
                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                .getCurrentPageForm().getResourcePrefix()
                                + ".error.destinationPortNotInteger"));
            }

            if (destinationHost == null || destinationHost.equals("")) {
                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                .getCurrentPageForm().getResourcePrefix()
                                + ".error.noDestinationHost"));
            }
            
            if (transport.equals(TransportType.UDP_TUNNEL) && tunnelType == TransportType.REMOTE_TUNNEL_ID) {
                errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq
                                .getCurrentPageForm().getResourcePrefix()
                                + ".error.remote.udp"));
            }
            
            return errs;
        }
        return null;
    }

    public String getSourcePort() {
        return sourcePort;
    }

    public void setSourcePort(String sourcePort) {
        this.sourcePort = sourcePort;
    }

    public boolean isAllowExternalHosts() {
        return allowExternalHosts;
    }

    public void setAllowExternalHosts(boolean allowExternalHosts) {
        this.allowExternalHosts = allowExternalHosts;
    }

    public boolean isAutoStart() {
        return autoStart;
    }

    public void setAutoStart(boolean autoStart) {
        this.autoStart = autoStart;
    }

    public String getDestinationHost() {
        return destinationHost;
    }

    public void setDestinationHost(String destinationHost) {
        this.destinationHost = destinationHost;
    }

    public String getDestinationPort() {
        return destinationPort;
    }

    public void setDestinationPort(String destinationPort) {
        this.destinationPort = destinationPort;
    }

    public int getTunnelType() {
        return tunnelType;
    }

    public void setTunnelType(int tunnelType) {
        this.tunnelType = tunnelType;
    }

    public void setTransport(String transport) {
        this.transport = transport;
    }

    public String getTransport() {
        return transport;
    }

    
    public List getTunnelTypeList() {
        return TransportType.TYPES;
    }
    
    public List getTransportList() {
        return TransportType.TRANSPORTS;
      }

    public void parentResourcePermissionChanged(AbstractWizardSequence sequence) {        
    }
}

⌨️ 快捷键说明

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