mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
漫画图片防封功能增强
This commit is contained in:
parent
53d169360f
commit
7bf7db85e9
@ -10,19 +10,20 @@
|
||||
<div class="ibox-content">
|
||||
<form class="form-horizontal m-t" id="signupForm">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">分类:</label>
|
||||
<div class="col-sm-8">
|
||||
<select data-placeholder="--选择类别--" name="catid" id="catid"
|
||||
class="form-control chosen-select" tabindex="2" dict-type="novel_category" >
|
||||
</select>
|
||||
<label class="col-sm-3 control-label">分类:</label>
|
||||
<div class="col-sm-8">
|
||||
<select data-placeholder="--选择类别--" name="catid" id="catid"
|
||||
class="form-control chosen-select" tabindex="2" dict-type="novel_category">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">封面:</label>
|
||||
<div class="col-sm-8">
|
||||
<img title="点击选择图片" id="picImage" style="cursor:pointer;width: 100px;height: 100px" src="/img/webuploader.png"/>
|
||||
<img title="点击选择图片" id="picImage" style="cursor:pointer;width: 100px;height: 100px"
|
||||
src="/img/webuploader.png"/>
|
||||
<input id="picUrl" name="picUrl" class="form-control"
|
||||
type="hidden" >
|
||||
type="hidden">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -104,7 +105,7 @@
|
||||
size: 1000,
|
||||
accept: 'file',
|
||||
done: function (r) {
|
||||
$("#picImage").attr("src",r.fileName);
|
||||
$("#picImage").attr("src", r.fileName);
|
||||
$("#picUrl").val(r.fileName);
|
||||
},
|
||||
error: function (r) {
|
||||
|
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>xyz.zinglizingli</groupId>
|
||||
<artifactId>novel-front</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.2.beta</version>
|
||||
<name>novel-front</name>
|
||||
<description>小说精品楼-前台web网站</description>
|
||||
|
||||
|
@ -3,6 +3,7 @@ package xyz.zinglizingli.common.filter;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
@ -15,7 +16,7 @@ import xyz.zinglizingli.common.utils.SpringUtil;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
@ -105,23 +106,23 @@ public class SearchFilter implements Filter {
|
||||
final String method = req.getMethod();
|
||||
|
||||
|
||||
// 案例:充当客户端通过restTemplate请求网络数据,并充当服务端将数据返回给浏览器
|
||||
// 客户端请求数据:输入流(byte[])==》字符串
|
||||
// 服务端响应数据:字符串 == 》 输出流(byte[])
|
||||
// 案例:充当客户端通过restTemplate请求网络数据,并充当服务端将数据返回给浏览器
|
||||
// 客户端请求数据:输入流(byte[])==》字符串
|
||||
// 服务端响应数据:字符串 == 》 输出流(byte[])
|
||||
|
||||
//默认方式:
|
||||
//RestTemplate restTemplate = new RestTemplate();
|
||||
// ①当返回的response-header的content-type属性有charset值时,
|
||||
// restTemplate的StringHttpMessageConverter会设置默认charset为content-type属性
|
||||
// charset值
|
||||
// StringHttpMessageConverter.setDefaultCharset(Charset.forName(charset));
|
||||
// ②当返回的response-header的content-type属性没有charset值时
|
||||
// restTemplate的StringHttpMessageConverter会使用默认的charset即ISO-8859-1
|
||||
//默认方式:
|
||||
//RestTemplate restTemplate = new RestTemplate();
|
||||
// ①当返回的response-header的content-type属性有charset值时,
|
||||
// restTemplate的StringHttpMessageConverter会设置默认charset为content-type属性
|
||||
// charset值
|
||||
// StringHttpMessageConverter.setDefaultCharset(Charset.forName(charset));
|
||||
// ②当返回的response-header的content-type属性没有charset值时
|
||||
// restTemplate的StringHttpMessageConverter会使用默认的charset即ISO-8859-1
|
||||
|
||||
// 对服务端请求返回的输入流(byte[])采用何种编码转换成字符串(String)
|
||||
restTemplate = RestTemplateUtil.getInstance("utf-8");//请求html/css/js等文件
|
||||
// 对客户端响应返回的字符串(String)采用何种编码转换成输出流(byte[])
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
// 对服务端请求返回的输入流(byte[])采用何种编码转换成字符串(String)
|
||||
restTemplate = RestTemplateUtil.getInstance("utf-8");//请求html/css/js等文件
|
||||
// 对客户端响应返回的字符串(String)采用何种编码转换成输出流(byte[])
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
|
||||
/*//=====现在浏览器有编码自动识别功能,所以上面的代码没有加content-type的Header也没有问题==========
|
||||
//=====正确做法应该是下面代码片段1和代码片段2二选一==========
|
||||
@ -142,45 +143,81 @@ public class SearchFilter implements Filter {
|
||||
*/
|
||||
|
||||
|
||||
if (HttpMethod.GET.name().equals(method)) {
|
||||
if (HttpMethod.GET.name().equals(method)) {
|
||||
|
||||
|
||||
String fileName = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||
if (localFileFix.contains(fileName) || fileName.startsWith("9a4a540e-1759-4268-90fa-7fb652c3604a.")) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
String fileName = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||
if (localFileFix.contains(fileName) || fileName.startsWith("9a4a540e-1759-4268-90fa-7fb652c3604a.")) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String queryString = req.getQueryString();
|
||||
if (queryString != null && queryString.length() > 0 && !queryString.contains("bsh_bid=")) {
|
||||
queryString = "?" + URLDecoder.decode(req.getQueryString());
|
||||
} else {
|
||||
queryString = "";
|
||||
}
|
||||
|
||||
|
||||
if (forObject == null) {
|
||||
String postFix = requestURI.substring(requestURI.lastIndexOf(".") + 1);
|
||||
if (picPostFix.contains(postFix)) {
|
||||
// 对服务端请求返回的输入流(byte[])采用何种编码转换成字符串(String)
|
||||
restTemplate = RestTemplateUtil.getInstance("iso-8859-1");//请求图片
|
||||
resp.setContentType("image/apng");
|
||||
}
|
||||
if (requestURI.startsWith("/manhua/images/")) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Referer","https://www.dmzj.com");
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
||||
String realUrl = "https://images.dmzj.com/" + requestURI.substring(15);
|
||||
ResponseEntity<Resource> resEntity = restTemplate.exchange(realUrl, HttpMethod.GET, requestEntity, Resource.class);
|
||||
InputStream input = resEntity.getBody().getInputStream();
|
||||
OutputStream out = resp.getOutputStream();
|
||||
byte[] b = new byte[4096];
|
||||
for (int n; (n = input.read(b)) != -1;) {
|
||||
out.write(b, 0, n);
|
||||
}
|
||||
input.close();
|
||||
out.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 对服务端请求返回的输入流(byte[])采用何种编码转换成字符串(String)
|
||||
|
||||
|
||||
|
||||
String queryString = req.getQueryString();
|
||||
if (queryString != null && queryString.length() > 0 && !queryString.contains("bsh_bid=")) {
|
||||
queryString = "?" + URLDecoder.decode(req.getQueryString());
|
||||
} else {
|
||||
queryString = "";
|
||||
}
|
||||
|
||||
} else if(requestURI.startsWith("/manhua/statics/")){
|
||||
String realPath = "https://static.dmzj.com/"+requestURI.substring(16);
|
||||
ResponseEntity<String> forEntity = restTemplate.getForEntity(realPath, String.class);
|
||||
forObject = forEntity.getBody();
|
||||
forObject = forObject.replaceAll("https://images.dmzj.com/", "/manhua/images/");
|
||||
|
||||
if (forObject == null) {
|
||||
}else {
|
||||
String realPath = "https://www.dmzj.com/" + requestURI.substring(8);
|
||||
|
||||
|
||||
ResponseEntity<String> forEntity = restTemplate.getForEntity("https://www.dmzj.com/"+requestURI.substring(8), String.class);
|
||||
ResponseEntity<String> forEntity = restTemplate.getForEntity(realPath, String.class);
|
||||
forObject = forEntity.getBody();
|
||||
|
||||
// forObject = new String(forObject.getBytes("ISO-8859-1"),"utf-8");
|
||||
forObject=forObject.replace("https://www.dmzj.com/js/ad/ad_12.js","");
|
||||
forObject=forObject.replace("https://www.dmzj.com/js/ad/ad_13.js","");
|
||||
forObject=forObject.replace("https://static.dmzj.com/ocomic/js/dmzjMhFinally-new.js","");
|
||||
forObject=forObject.replace("https://static.dmzj.com/ocomic/js/dmzjMhFinally-new.js","");
|
||||
forObject=forObject.replace("https://static.dmzj.com/module/js/float_code.js","");
|
||||
forObject=forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>","");
|
||||
forObject=forObject.replaceAll("https://static.dmzj.com/public/js/dmzj-land-2015.6.js","");
|
||||
forObject=forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>","");
|
||||
forObject=forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>","");
|
||||
forObject=forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>","");
|
||||
forObject=forObject.replaceAll("globalNav.js","");
|
||||
forObject=forObject.replaceAll("TSB.js","");
|
||||
forObject=forObject+"<script>var browser={\n" +
|
||||
forObject = forObject.replace("https://www.dmzj.com/js/ad/ad_12.js", "");
|
||||
forObject = forObject.replace("https://www.dmzj.com/js/ad/ad_13.js", "");
|
||||
forObject = forObject.replace("https://static.dmzj.com/ocomic/js/dmzjMhFinally-new.js", "");
|
||||
forObject = forObject.replace("https://static.dmzj.com/ocomic/js/dmzjMhFinally-new.js", "");
|
||||
forObject = forObject.replace("https://static.dmzj.com/module/js/float_code.js", "");
|
||||
forObject = forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>", "");
|
||||
forObject = forObject.replaceAll("https://static.dmzj.com/public/js/dmzj-land-2015.6.js", "");
|
||||
forObject = forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>", "");
|
||||
forObject = forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>", "");
|
||||
forObject = forObject.replaceAll("<script type=\"text/javascript\">var cnzz_protocol =[^<]+</script>", "");
|
||||
forObject = forObject.replaceAll("globalNav.js", "");
|
||||
forObject = forObject.replaceAll("TSB.js", "");
|
||||
forObject = forObject.replaceAll("https://images.dmzj.com/", "/manhua/images/");
|
||||
forObject = forObject.replaceAll("https://static.dmzj.com/", "/manhua/statics/");
|
||||
forObject = forObject + "<script>var browser={\n" +
|
||||
" versions:function(){\n" +
|
||||
" var u = window.navigator.userAgent;\n" +
|
||||
" return {\n" +
|
||||
@ -199,7 +236,7 @@ public class SearchFilter implements Filter {
|
||||
" }()\n" +
|
||||
"};" +
|
||||
"</script>";
|
||||
forObject=forObject+"<script>$(function(){$(\"#app_manhua\").remove();" +
|
||||
forObject = forObject + "<script>$(function(){$(\"#app_manhua\").remove();" +
|
||||
"$('.btmBtnBox').remove();$('.red_box').remove()" +
|
||||
";$('.mainNav').remove();$('.wrap_last_head').remove();$('.wrap_last_mid').remove()" +
|
||||
";$('.comic_gd').remove();$('.comic_last').remove();$('.side_bar').remove()" +
|
||||
@ -239,7 +276,7 @@ public class SearchFilter implements Filter {
|
||||
// "})();\n" +
|
||||
// "</script>\n</head>")//页面访问自动推送到百度
|
||||
// .replaceAll("<script.*wap\\.js.*script>", "")//去除广告
|
||||
;
|
||||
;
|
||||
|
||||
|
||||
// if (requestURI.matches(SUANWEI_BOOK_HTML_REGEX)) {
|
||||
@ -276,47 +313,47 @@ public class SearchFilter implements Filter {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Map<String, String[]> oldParameterMap = req.getParameterMap();
|
||||
Map<String, String> newParameterMap = new HashMap<>();
|
||||
Set<Map.Entry<String, String[]>> entries = oldParameterMap.entrySet();
|
||||
for (Map.Entry<String, String[]> entry : entries) {
|
||||
newParameterMap.put(entry.getKey(), entry.getValue()[0]);
|
||||
}
|
||||
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
map.setAll(newParameterMap);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
|
||||
forObject = restTemplate.postForEntity("https://www.dmzj.com/"+requestURI.substring(8), request, String.class).getBody();
|
||||
// forObject = new String(forObject.getBytes("ISO-8859-1"),"utf-8");
|
||||
forObject = forObject.replaceAll("/manhua/", "https://www.dmzj.com/")
|
||||
.replaceAll("笔趣岛", "酸味书屋")
|
||||
.replaceAll("笔趣阁", "酸味书屋")
|
||||
.replaceFirst("</head>", "<script>\n" +
|
||||
"var _hmt = _hmt || [];" +
|
||||
"(function() {" +
|
||||
" var hm = document.createElement(\"script\");" +
|
||||
" hm.src = \"https://hm.baidu.com/hm.js?0bd7345ca6b694ea3dfbe87da008082e\";" +
|
||||
" var s = document.getElementsByTagName(\"script\")[0]; " +
|
||||
" s.parentNode.insertBefore(hm, s);" +
|
||||
"})();" +
|
||||
"</script></head>")
|
||||
.replaceAll("<a\\s+href=\"/bookcase.php\">书架</a>", "<a href=\"" + noteURI.get(new Random().nextInt(noteURI.size())) + "\">笔记</a>")
|
||||
.replaceAll("<a href=\"/.*/\">返回</a>", "<a href=\"javascript:history.go(-1)\">返回</a>")
|
||||
;
|
||||
forObject = setBookURIToHTML(forObject, SUANWEI_BOOK_REGEX);
|
||||
//resp.setCharacterEncoding("utf-8");
|
||||
//setContentType(postFix, resp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Map<String, String[]> oldParameterMap = req.getParameterMap();
|
||||
Map<String, String> newParameterMap = new HashMap<>();
|
||||
Set<Map.Entry<String, String[]>> entries = oldParameterMap.entrySet();
|
||||
for (Map.Entry<String, String[]> entry : entries) {
|
||||
newParameterMap.put(entry.getKey(), entry.getValue()[0]);
|
||||
}
|
||||
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
map.setAll(newParameterMap);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
|
||||
forObject = restTemplate.postForEntity("https://www.dmzj.com/" + requestURI.substring(8), request, String.class).getBody();
|
||||
// forObject = new String(forObject.getBytes("ISO-8859-1"),"utf-8");
|
||||
forObject = forObject.replaceAll("/manhua/", "https://www.dmzj.com/")
|
||||
.replaceAll("笔趣岛", "酸味书屋")
|
||||
.replaceAll("笔趣阁", "酸味书屋")
|
||||
.replaceFirst("</head>", "<script>\n" +
|
||||
"var _hmt = _hmt || [];" +
|
||||
"(function() {" +
|
||||
" var hm = document.createElement(\"script\");" +
|
||||
" hm.src = \"https://hm.baidu.com/hm.js?0bd7345ca6b694ea3dfbe87da008082e\";" +
|
||||
" var s = document.getElementsByTagName(\"script\")[0]; " +
|
||||
" s.parentNode.insertBefore(hm, s);" +
|
||||
"})();" +
|
||||
"</script></head>")
|
||||
.replaceAll("<a\\s+href=\"/bookcase.php\">书架</a>", "<a href=\"" + noteURI.get(new Random().nextInt(noteURI.size())) + "\">笔记</a>")
|
||||
.replaceAll("<a href=\"/.*/\">返回</a>", "<a href=\"javascript:history.go(-1)\">返回</a>")
|
||||
;
|
||||
forObject = setBookURIToHTML(forObject, SUANWEI_BOOK_REGEX);
|
||||
//resp.setCharacterEncoding("utf-8");
|
||||
//setContentType(postFix, resp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
@ -333,6 +370,7 @@ public class SearchFilter implements Filter {
|
||||
//resp.setCharacterEncoding("utf-8");
|
||||
|
||||
}
|
||||
|
||||
resp.getWriter().print(forObject);
|
||||
return;
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ server:
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
# url: jdbc:mysql://148.70.59.92:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
# username: xiongxiaoyang
|
||||
# password: Lzslov123!
|
||||
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: books
|
||||
password: books
|
||||
# url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
# username: root
|
||||
# password: test123456
|
||||
cache:
|
||||
ehcache:
|
||||
config: classpath:ehcache.xml
|
||||
|
Loading…
x
Reference in New Issue
Block a user