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

📄 updatetunnelaction.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.actions;

import java.util.ArrayList;
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.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.LabelValueBean;

import com.sslexplorer.core.CoreAttributeConstants;
import com.sslexplorer.core.CoreEvent;
import com.sslexplorer.core.CoreEventConstants;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.ResourceDeleteEvent;
import com.sslexplorer.policyframework.ResourceUtil;
import com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.VPNSession;
import com.sslexplorer.tunnels.TransportType;
import com.sslexplorer.tunnels.Tunnel;
import com.sslexplorer.tunnels.forms.TunnelItem;
import com.sslexplorer.tunnels.forms.TunnelsForm;

/**
 * Implementation of
 * {@link com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction}
 * that handles the updating of <i>SSL Tunnels</i>. These work slightly
 * differently to the other SSL-Explorer resources as communication occurs with
 * the VPN client.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @author James D Robinson <a href="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
 * @author Lee David Painter <a href="mailto:lee@3sp.com">&lt;lee@3sp.com&gt;</a>
 * @version $Revision$
 */
public class UpdateTunnelAction extends AbstractResourceDispatchAction {

    static Log log = LogFactory.getLog(GetTunnelsAction.class);

    /**
     * Constructor
     */
    public UpdateTunnelAction() {
        super();
    }

    /**
     * Open a tunnel. This actual open is done by the VPN client, this action
     * catches the open and displays a message
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward open(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        ActionMessages msgs = new ActionMessages();
        msgs.add(Globals.MESSAGE_KEY, new ActionMessage("tunnels.message.tunnelsOpened"));
        saveMessages(request, msgs);
        if (getSessionInfo().getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
            return mapping.findForward("tunnels");
        } else {
            return mapping.findForward("userTunnels");
        }

    }

    /**
     * Close a tunnel. This actual open is done by the VPN client, this action
     * catches the close and displays a message
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward close(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        ActionMessages msgs = new ActionMessages();
        msgs.add(Globals.MESSAGE_KEY, new ActionMessage("tunnels.message.tunnelsClosed"));
        saveMessages(request, msgs);
        if (getSessionInfo().getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
            return mapping.findForward("tunnels");
        } else {
            return mapping.findForward("userTunnels");
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#edit(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        return super.edit(mapping, form, request, response);
    }

    /**
     * Allows a non auto-start tunnel to be started during the start up sequence
     * of the VPN client.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward indirectOpen(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                      HttpServletResponse response) throws Exception {
        Tunnel t = CoreServlet.getServlet().getSystemDatabase().getTunnel(
            Integer.parseInt(request.getParameter("selectedResource")));
        ResourceUtil.checkResourceAccessRights(t, getSessionInfo());
        VPNSession vpnSession = CoreServlet.getServlet().getLogonController().getPrimaryVPNSession(
            CoreServlet.getServlet().getLogonController().getVPNSessionsByLogon(request));
        TunnelItem ti = new TunnelItem(t, vpnSession, null);
        if (getSessionInfo().getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
            return new ActionForward(ti.getOpenLink("/showTunnels.do?actionTarget=unspecified"), true);
        } else {
            return new ActionForward(ti.getOpenLink("/showUserTunnels.do?actionTarget=unspecified"), true);
        }
    }

    /**
     * Remve a tunnel.
     * 
     * @param mapping mapping
     * @param form form
     * @param request request
     * @param response response
     * @return forward
     * @throws Exception on any error
     */
    public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        TunnelsForm f = (TunnelsForm) form;
        List sel = new ArrayList();
        ActionMessages msgs = new ActionMessages();
        Tunnel resource = null;
        try {
            resource = CoreServlet.getServlet().getSystemDatabase().removeTunnel(f.getSelectedResource());
            ResourceUtil.checkResourceManagementRights(resource, getSessionInfo(), PolicyConstants.PERM_DELETE);
        } catch (Exception e) {
            throw e;
        }
        msgs.add(Globals.MESSAGE_KEY, new ActionMessage("tunnels.message.tunnelsRemoved", String.valueOf(sel.size())));
        saveMessages(request, msgs);
        if (getSessionInfo().getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
            return mapping.findForward("tunnels");
        } else {
            return mapping.findForward("userTunnels");
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.policyframework.actions.AbstractResourceDispatchAction#createResource(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public Resource createResource(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        return null;
    }

}

⌨️ 快捷键说明

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