gettunnelsaction.java
来自「这是linux下ssl vpn的实现程序」· Java 代码 · 共 104 行
JAVA
104 行
/*
* 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.actions;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jdom.Document;
import org.jdom.Element;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.actions.XMLOutputAction;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.policyframework.ResourceUtil;
import com.sslexplorer.security.SystemDatabase;
import com.sslexplorer.security.User;
import com.sslexplorer.security.VPNSession;
import com.sslexplorer.tunnels.Tunnel;
/**
* This action retrieves a list of available tunnels.
*
* @author Brett Smith
* @version $Revision$
*/
public class GetTunnelsAction extends XMLOutputAction {
static Log log = LogFactory.getLog(GetTunnelsAction.class);
public GetTunnelsAction() {
super();
}
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
try {
// Get the VPN session
VPNSession session = CoreServlet.getServlet().getLogonController().getVPNSession(request);
// Check that we were returned a value
if (session == null) {
log.error(request.getRemoteHost() + " cannot get tunnels because the VPN session is invalid");
sendError("Invalid VPN session!", response);
} else {
// Return any tunnels that should be started
SystemDatabase sdb = CoreServlet.getServlet().getSystemDatabase();
List tunnels = ResourceUtil.filterResources(session.getSessionInfo().getUser(), sdb.getTunnels(), false);
Element tunnelsElement = new Element("tunnels");
for (Iterator i = tunnels.iterator(); i.hasNext();) {
Tunnel tunnel = (Tunnel) i.next();
try {
Element tunnelElement = new Element("tunnel");
tunnelElement.setAttribute("id", String.valueOf(tunnel.getResourceId()));
tunnelElement.setAttribute("username", String.valueOf(tunnel.getUsername()));
tunnelElement.setAttribute("type", String.valueOf(tunnel.getType()));
tunnelElement.setAttribute("autoStart", String.valueOf(tunnel.isAutoStart()));
tunnelElement.setAttribute("transport", tunnel.getTransport());
tunnelElement.setAttribute("sourcePort", String.valueOf(tunnel.getSourcePort()));
tunnelElement.setAttribute("destinationPort", String.valueOf(tunnel.getDestination().getPort()));
tunnelElement.setAttribute("destinationHost", tunnel.getDestination().getHost());
tunnelElement.setAttribute("allowExternalHosts", String.valueOf(tunnel.isAllowExternalHosts()));
tunnelsElement.addContent(tunnelElement);
} catch (Exception e) {
log.warn("Failed to add tunnel.", e);
}
}
Document doc = new Document(tunnelsElement);
sendDocument(doc, response);
}
} catch (Exception ex) {
log.error("Request to get list of tunnels failed.", ex);
}
return null;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?