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

📄 tunnelform.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.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 org.apache.struts.action.ActionMessage;
import org.apache.struts.util.LabelValueBean;

import com.sslexplorer.boot.HostService;
import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.input.MultiSelectSelectionModel;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.forms.AbstractFavoriteResourceForm;
import com.sslexplorer.security.User;
import com.sslexplorer.tunnels.TransportType;
import com.sslexplorer.tunnels.Tunnel;

public class TunnelForm extends AbstractFavoriteResourceForm {
    static Log log = LogFactory.getLog(TunnelForm.class);
    private String selectedTab = "details";

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

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errs = super.validate(mapping, request);
        if (isCommiting()) {
            if (getResourceName().equalsIgnoreCase("default")
                            && (!getEditing() || (getEditing() && !getResource().getResourceName().equalsIgnoreCase("default")))) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("error.createNetworkPlace.cantUseNameDefault"));
                setResourceName("");
            }
        }
        return errs;
    }

    public int getTabCount() {
        return 3;
    }

    public String getTabName(int idx) {
        switch (idx) {
            case 0:
                return "details";
            case 1:
                return "other";
            default:
                return "policies";
        }
    }

    public String getTabTitle(int idx) {
        
        // Get from resources
        return null;
    }

    public void initialise(User user, Resource resource, boolean editing, MultiSelectSelectionModel policyModel,
                    PropertyList selectedPolicies, User owner) throws Exception {
        super.initialise(user, resource, editing, policyModel, selectedPolicies, owner);
        Tunnel tunnel = (Tunnel) resource;
        sourcePort = String.valueOf(tunnel.getSourcePort()) ;
        destinationHost = tunnel.getDestination().getHost();
        destinationPort = String.valueOf(tunnel.getDestination().getPort());
        tunnelType = tunnel.getType();
        transport = tunnel.getTransport();
        autoStart = tunnel.isAutoStart();
        allowExternalHosts = tunnel.isAllowExternalHosts();
    }

    public String getSelectedTab() {
        return selectedTab;
    }

    public void setSelectedTab(String selectedTab) {
        this.selectedTab = selectedTab;
    }

    public void applyToResource() throws Exception {
        Tunnel tunnel = (Tunnel)getResource();
        tunnel.setType(getTunnelType());
        tunnel.setAutoStart(isAutoStart());
        tunnel.setTransport(getTransport());
        tunnel.setSourcePort(Integer.parseInt(getSourcePort()));
        tunnel.setDestination(new HostService(getDestinationHost(), Integer.parseInt(getDestinationPort())));
        tunnel.setAllowExternalHosts(isAllowExternalHosts());
    }

    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 String getTunnelTypeString() {
        return ((LabelValueBean) getTunnelTypeList().get(getTunnelType())).getLabel();
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
        this.allowExternalHosts = false;
        this.autoStart = false;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.tabs.TabModel#getTabBundle(int)
     */
    public String getTabBundle(int idx) {
        return null;
    }
}

⌨️ 快捷键说明

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