📄 tunnelitem.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.struts.util.LabelValueBean;
import com.sslexplorer.boot.Util;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.forwarding.VPNListeningSocket;
import com.sslexplorer.navigation.AbstractFavoriteItem;
import com.sslexplorer.security.VPNSession;
import com.sslexplorer.tunnels.TransportType;
import com.sslexplorer.tunnels.Tunnel;
/**
* Implementation of an {@link com.sslexplorer.navigation.AbstractFavoriteItem}
* that wraps {@link com.sslexplorer.tunnels.Tunnel} resources for display.
*
* @author Brett Smith <a href="mailto: brett@3sp.com"><brett@3sp.com></a>
* @author James D Robinson <a href="mailto:james@3sp.com"><james@3sp.com></a>
* @version $Revsion$
*/
public class TunnelItem extends AbstractFavoriteItem {
VPNListeningSocket socket;
VPNSession session;
/**
* Constructor
*
* @param tunnel tunnel
*/
public TunnelItem(Tunnel tunnel, List policies) {
super(tunnel, policies);
}
/**
* Constructor
*
* @param socket socket
*/
public TunnelItem(VPNListeningSocket socket, List policies) {
super(socket.getTunnel(), policies);
this.socket = socket;
}
/**
* Constructor
*
* @param tunnel tunnel
* @param session session
*/
public TunnelItem(Tunnel tunnel, VPNSession session, List policies) {
this(tunnel, policies);
this.session = session;
}
/**
* Constructor
*
* @param socket socket
* @param session session
*/
public TunnelItem(VPNListeningSocket socket, VPNSession session, List policies) {
this(socket, policies);
this.session = session;
}
/**
* Get the active listening socket for this tunnel. <code>null</code> will
* be returned if this tunnel is not currently active.
*
* @return socket
*/
public VPNListeningSocket getSocket() {
return socket;
}
/**
* Get the transport type for this resource.
*
* @return transport type
* @see Tunnel#getTransport()
*/
public String getTransport() {
return ((Tunnel) this.getResource()).getTransport();
}
/**
* Get the source port for this tunnel
*
* @return source port
* @see Tunnel#getSourcePort()
*/
public String getSourcePort() {
return String.valueOf(((Tunnel) this.getResource()).getSourcePort());
}
/**
* Get the destination host for this tunnel
*
* @return destination host
* @see Tunnel#getDestination()
*/
public String getDestinationHost() {
return ((Tunnel) this.getResource()).getDestination().getHost();
}
/**
* Get the type of tunnel.
*
* @return type of tunnel
* @see Tunnel#getType()
*/
public String getTunnelType() {
return ((LabelValueBean) TransportType.TYPES.get(((Tunnel) this.getResource()).getType())).getLabel();
}
/**
* Get the destination port for this tunnel
*
* @return destination port
* @see Tunnel#getDestination()
*/
public String getDestinationPort() {
return String.valueOf(((Tunnel) this.getResource()).getDestination().getPort());
}
/**
* Get if external hosts are allowed to connect to this tunnel
*
* @return external hosts allowed
* @see Tunnel#isAllowExternalHosts()
*/
public String getExternalHostsAllowed() {
return ((Tunnel) this.getResource()).isAllowExternalHosts() ? "Yes" : "No";
}
/**
* Get if this tunnel should autostart.
*
* @return autostart
* @see Tunnel#isAutoStart()
*/
public String getAutoStart() {
return ((Tunnel) this.getResource()).isAutoStart() ? "Yes" : "No";
}
/**
* Get if this tunnel is currently open and active.
*
* @return tunnel open
*/
public String getOpen() {
return socket != null ? "true" : "false";
}
/**
* Get the ticket attached to the active tunnel. <code>null</code> will be
* returned if the tunnel is not active
*
* @return tunnel ticket
*/
public String getTunnelTicket() {
return socket == null ? "" : socket.getTicket();
}
/**
* Get the ticket for the VPN client that is handling the active tunnel.
* <code>null</code> will be returned if the tunnel is not active.
*
* @return vpn client ticket
*/
public String getVPNTicket() {
return session == null ? "" : session.getVPNTicket();
}
/**
* Get the tunnel object this item wraps. Provided more for convenience as
* {@link com.sslexplorer.policyframework.ResourceItem#getResource} would
* normally be used.
*
* @return tunnel
*/
public Tunnel getTunnel() {
return ((Tunnel) this.getResource());
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.navigation.FavoriteItem#getOnClick()
*/
public String getOnClick() {
return "return true";
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.navigation.FavoriteItem#getLink()
*/
public String getLink(String referer) {
if (new Boolean(getOpen()).booleanValue()) {
return getCloseLink(referer);
} else {
return getOpenLink(referer);
}
}
/**
* Get the link to use to open this tunnel
*
* @param referer referer
* @return open link
*/
public String getOpenLink(String referer) {
String encodedReferer = Util.urlEncode(referer);
String path = null;
if (session == null) {
// If the tunnel is autostart it will start when the VPN client starts anyway
if(((Tunnel)getResource()).isAutoStart()) {
path = "/launchVPNClient.do?returnTo=" + encodedReferer;
}
else {
path = "/launchVPNClient.do?returnTo=" + Util.urlEncode("/updateTunnel.do?actionTarget=indirectOpen&selectedResource=" + getResource().getResourceId());
}
}
else {
path = "http://localhost:" + ( session == null ? -1 : session.getClientPort() ) + "/updateTunnel?actionTarget=open&ticket="
+ getResource().getResourceId() + "&redirect=" + encodedReferer
+ "&errorRedirect=" + encodedReferer;
}
return path;
}
/**
* Get the link to use to close the tunnel
*
* @param referer
* @return close link
*/
public String getCloseLink(String referer) {
String encodedReferer = Util.urlEncode(referer);
return "http://localhost:" + session.getClientPort() + "/updateTunnel?actionTarget=close&ticket="
+ getResource().getResourceId() + "/" + this.getTunnelTicket() + "&redirect=" + encodedReferer
+ "&errorRedirect=" + encodedReferer;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.navigation.FavoriteItem#getName()
*/
public String getFavoriteName() {
return getSourcePort() + ":" + getDestinationHost() + ":" + getDestinationPort();
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.navigation.FavoriteItem#getTarget()
*/
public String getTarget() {
return "_self";
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.navigation.AbstractFavoriteItem#getFavoriteSubType()
*/
public String getFavoriteSubType() {
return getTunnel().getType() == TransportType.LOCAL_TUNNEL_ID ? "Local" : "Remote";
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.navigation.AbstractFavoriteItem#getSmallIconPath(javax.servlet.http.HttpServletRequest)
*/
public String getSmallIconPath(HttpServletRequest request) {
return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runTunnel.gif";
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.navigation.AbstractFavoriteItem#getLargeIconPath(javax.servlet.http.HttpServletRequest)
*/
public String getLargeIconPath(HttpServletRequest request) {
return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runTunnelLarge.gif";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -