修复bug
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
package sc545.pay.interceptor;
|
||||
|
||||
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import sc545.pay.utils.DBUtil;
|
||||
import sc545.pay.utils.ReadTxt;
|
||||
import sc545.pay.utils.Utils;
|
||||
|
||||
|
||||
|
||||
|
||||
public class testInterceptor implements HandlerInterceptor{
|
||||
|
||||
@Override
|
||||
public boolean preHandle(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
Object handler) throws Exception {
|
||||
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
request.setCharacterEncoding("utf-8");
|
||||
|
||||
/*************************************拉黑高频访问ip******************************************/
|
||||
if(!"".equals(ReadTxt.getSetting(null, "拉黑ip.txt", Utils.getIpAddr(request), ""))){
|
||||
PrintWriter out = response.getWriter();
|
||||
out.print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>系统检测到高频次访问已被拉黑IP<br>若误封请前往微信公众号【顺诚百宝箱】反馈<br>感谢理解!<br>IP:"+Utils.getIpAddr(request));
|
||||
return false;
|
||||
}
|
||||
String ipdate = ReadTxt.getSetting(null, "访问者IP.txt", Utils.getIpAddr(request), "");//获取此ip上次访问时间和已经访问的次数
|
||||
String[] idt = ipdate.split("_");//分隔
|
||||
long i=0;//已经访问的次数
|
||||
if(!"".equals(ipdate)){
|
||||
if(ipdate.indexOf("_")>0) i=Utils.getNum(idt[1]);
|
||||
//检查此ip第一次访问到现在过了几秒
|
||||
Date ds = Utils.string2Date(idt[0], null);
|
||||
long xc = (new Date().getTime() - ds.getTime())/1000;
|
||||
if(xc<=30){//30秒超过50次
|
||||
if(i>50){//拉黑此ip3天
|
||||
ReadTxt.writeSetting(null,"拉黑ip.txt", Utils.getIpAddr(request), Utils.date2String(new Date(), null));
|
||||
ReadTxt.delSetting(null, "访问者IP.txt", Utils.getIpAddr(request));
|
||||
}else{//正常ip
|
||||
}
|
||||
}else{//正常ip
|
||||
ReadTxt.delSetting(null, "访问者IP.txt", Utils.getIpAddr(request));
|
||||
}
|
||||
ReadTxt.writeSetting(null,"访问者IP.txt", Utils.getIpAddr(request), idt[0]+"_"+(++i));
|
||||
}else
|
||||
ReadTxt.writeSetting(null,"访问者IP.txt", Utils.getIpAddr(request), Utils.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")+"_1");
|
||||
/*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DBUtil db = new DBUtil();
|
||||
|
||||
//闭站
|
||||
String cw = ReadTxt.getSetting(null, "setting.ini", "closeweb", "0");
|
||||
if("1".equals(cw)) {
|
||||
String uri = request.getRequestURI();
|
||||
if(uri.indexOf("/admin")<0){
|
||||
Utils.outHtml(response.getWriter(), ReadTxt.getSetting(null, "setting.ini", "closewebtxt", "本站暂停访问"), "/*about:blank*/");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,10 +2,8 @@ package sc545.pay.utils;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
package sc545.pay.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -29,12 +21,9 @@ import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.ParseException;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
@@ -317,7 +306,8 @@ public class HttpUtils {
|
||||
}
|
||||
|
||||
|
||||
private static org.apache.http.client.HttpClient wrapClient(HttpClient base) {
|
||||
@SuppressWarnings("deprecation")
|
||||
private static org.apache.http.client.HttpClient wrapClient(HttpClient base) {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLSv1");
|
||||
X509TrustManager tm = new X509TrustManager() {
|
||||
@@ -491,6 +481,7 @@ public class HttpUtils {
|
||||
* @param header
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static String doPost2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if (StringUtils.isBlank(url)) {
|
||||
@@ -548,6 +539,7 @@ public class HttpUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static String doGet2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if (StringUtils.isBlank(url)) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package sc545.pay.utils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -29,8 +29,7 @@ import org.apache.commons.lang.time.DateUtils;
|
||||
public class Utils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = floatToString(0.01235788889f, 3,false);
|
||||
System.out.println(s);
|
||||
getWeekNum();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -702,12 +701,6 @@ public class Utils {
|
||||
*/
|
||||
public static long getDatePoor(Date endDate, Date nowDate) {
|
||||
|
||||
long nd = 1000 * 24 * 60 * 60;// 一天
|
||||
|
||||
long nh = 1000 * 60 * 60;// 一小时
|
||||
|
||||
long nm = 1000 * 60;// 一分钟
|
||||
|
||||
long ns = 1000;// 一秒
|
||||
|
||||
// 获得两个时间的毫秒时间差异
|
||||
@@ -718,6 +711,13 @@ public class Utils {
|
||||
return sec;
|
||||
|
||||
}
|
||||
|
||||
/**获取今天是周几,1-7*/
|
||||
public static long getWeekNum() {
|
||||
long[] weekDays = {7,1,2,3,4,5,6};
|
||||
Calendar c = Calendar.getInstance();
|
||||
return weekDays[c.get(Calendar.DAY_OF_WEEK)-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户真实ip
|
||||
|
||||
@@ -37,21 +37,4 @@
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<!-- 配置静态资源 -->
|
||||
<mvc:resources location="/" mapping="/**/*.js" />
|
||||
<mvc:resources location="/" mapping="/**/*.css" />
|
||||
<mvc:resources location="/assets/" mapping="/assets/**/*" />
|
||||
<mvc:resources location="/images/" mapping="/images/*"
|
||||
cache-period="360000" />
|
||||
|
||||
<mvc:interceptors>
|
||||
<mvc:interceptor>
|
||||
<mvc:mapping path="/**" />
|
||||
<bean class="sc545.pay.interceptor.testInterceptor" />
|
||||
</mvc:interceptor>
|
||||
|
||||
</mvc:interceptors>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user