/**
 * @(#)file    TestController.java
 * @(#)author  
 * @(#)version 1.0
 * @(#)date    2022. 9. 2.
 * @(#)since   
 *
 * Copyright (c) www.hsnc.co.kr, Inc.
 * All rights reserved.
 * This software is the proprietary information of Hanwha S&C, Inc.
 */
package com.udapsoft.waf.system.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.udapsoft.common.commonSign.CommonMailThreadManager;
import kr.co.udapsoft.common.commonSign.CommonSignThreadManager;

/**
 * <p>Thread Controller Class</p>
 * CommonThread, CommonMailThread Stop Servlet
 * @version 1.0
 * @author 
 */
@SuppressWarnings("serial")
public class ThreadController extends HttpServlet {

	@Override
	public void init(ServletConfig config) throws ServletException {
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		WAFLogger.debug("doGet!!!!!!!!!!!!!!");
		WAFLogger.debug("remoteAddr=" + req.getRemoteAddr());
		
		String ip = req.getRemoteAddr();
		
		if ("127.0.0.1".equals(ip) || "0:0:0:0:0:0:0:1".equals(ip)
				|| "211.38.140.247".equals(ip) || "fe80::f17e:bfd1:1ac5:4ccd%17".equals(ip)) {
			WAFLogger.debug("before sign=" + CommonSignThreadManager.isRun());
			WAFLogger.debug("before mail=" + CommonMailThreadManager.isRun());
			
			CommonSignThreadManager.doStop();
			CommonMailThreadManager.doStop();
			
			WAFLogger.debug("after sign=" + CommonSignThreadManager.isRun());
			WAFLogger.debug("after mail=" + CommonMailThreadManager.isRun());
		} else {
			throw new ServletException("Thread stop error!!");
		}
		
		res.setContentType("text/html; charset=utf-8");
		PrintWriter out = res.getWriter();
		out.println("<html>");
		out.println("Thread Stopped.");
		out.println("</html>");
	}
	
	@Override
	public void destroy() {
		super.destroy();
	}
}