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

📄 shutdownaction.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 */
package com.sslexplorer.setup.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

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 com.sslexplorer.boot.ContextHolder;
import com.sslexplorer.core.BundleActionMessage;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.GlobalWarning;
import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.setup.forms.ShutdownForm;
import com.sslexplorer.tasks.shutdown.ShutdownTimerTask;
import com.sslexplorer.tasks.timer.StoppableTimer;

/**
 * Action to shut the server down.
 */
public class ShutdownAction extends AuthenticatedDispatchAction {
    final static Log log = LogFactory.getLog(ShutdownAction.class);

    /**
     * @param requiresAdministrator
     */
    public ShutdownAction() {
        super(PolicyConstants.SERVICE_CONTROL_RESOURCE_TYPE, new Permission[] {
                        PolicyConstants.PERM_SHUTDOWN,
                        PolicyConstants.PERM_RESTART
                    });
    }

    public ActionForward sendMessage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        return CoreUtil.addParameterToForward(mapping.findForward("message"), "users", "*");
    }

    public ActionForward cancelShutdown(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        ShutdownForm shutdownForm = (ShutdownForm) form;
        shutdownForm.setReferer(CoreUtil.getReferer(request));
        StoppableTimer timer = (StoppableTimer) CoreServlet.getServlet().getServletContext().getAttribute(StoppableTimer.NAME);
        timer.cancelTimerTask(ShutdownTimerTask.NAME);
        CoreUtil.removeGlobalWarning((HttpSession) null, "shutdown.global.warning.message");
        shutdownForm.setAlreadyPerforming(false);
        return new ActionForward("/showHome.do");
    }

    public ActionForward continueShutDown(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        ShutdownForm shutdownForm = (ShutdownForm) form;
        return new ActionForward(shutdownForm.getReferer(), true);
    }

    public ActionForward installShutdown(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        ShutdownForm shutdownForm = (ShutdownForm) form;
        performShutdown(request, shutdownForm);
        return mapping.findForward("success");
    }

    public ActionForward immediateConfirmed(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                    HttpServletResponse response) throws Exception {
        ShutdownForm shutdownForm = (ShutdownForm) form;
        performShutdown(request, shutdownForm);
        // return to the home as there is a delay before the shutdown.
        return mapping.findForward("home");
    }

    public ActionForward shutdown(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        ShutdownForm shutdownForm = (ShutdownForm) form;
        PolicyUtil.checkPermission(PolicyConstants.SERVICE_CONTROL_RESOURCE_TYPE, 
            shutdownForm.getShutdownType().equals(ShutdownForm.SHUTDOWN) ? PolicyConstants.PERM_SHUTDOWN : PolicyConstants.PERM_RESTART , request);
        if (shutdownForm.isImmediate()) {
            // for an imediate shut down.
            return new ActionForward("/confirmImmediateShutdown.do");
        } else {
            performShutdown(request, shutdownForm);
            // return to the home as there is a delay before the shutdown.
            return mapping.findForward("home");
        }
    }

    private void performShutdown(HttpServletRequest request, ShutdownForm shutdownForm) throws Exception {
        StoppableTimer timer = (StoppableTimer) CoreServlet.getServlet().getServletContext().getAttribute(StoppableTimer.NAME);
        final boolean restart = "restart".equals(shutdownForm.getShutdownType());
        if (restart) {
            if (!ContextHolder.getContext().isRestartAvailableMode()) {
                throw new Exception("Server is not running as a service. Restart is not possible.");
            }
        }
        ShutdownTimerTask stt = new ShutdownTimerTask(restart, shutdownForm.getShutdownDelay());
        timer.schedule(ShutdownTimerTask.NAME, stt, stt.getDelay());
        CoreUtil.addMultipleGlobalWarning(GlobalWarning.ALL_USERS, new BundleActionMessage("setup", "shutdown.global.warning.message",
            shutdownForm.getShutdownType(), stt.getShutDownTimeString()));
        request.getSession().setAttribute(Constants.RESTARTING, Boolean.valueOf(restart));
    }

    public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.SETUP_CONSOLE_CONTEXT;
    }

    public Resource createResource(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        throw new Exception("Create resource not supported.");
    }
}

⌨️ 快捷键说明

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