mirror of https://github.com/halo-dev/halo
👽 将web服务器由tomcat改为undertow
parent
7a238a4877
commit
e059dd05e3
17
pom.xml
17
pom.xml
|
@ -56,6 +56,17 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 邮件 -->
|
||||
|
@ -138,6 +149,12 @@
|
|||
<optional>true</optional>
|
||||
<scope>true</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>4.0.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<!-- 生产环境打包配置 -->
|
||||
|
|
|
@ -8,6 +8,7 @@ import cc.ryanc.halo.model.dto.HaloConst;
|
|||
import cc.ryanc.halo.repository.PostRepository;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -76,10 +77,11 @@ public class PostServiceImpl implements PostService {
|
|||
public void updateAllSummary(Integer postSummary) {
|
||||
List<Post> posts = this.findAllPosts(HaloConst.POST_TYPE_POST);
|
||||
for (Post post : posts) {
|
||||
if (!(HaloUtils.htmlToText(post.getPostContent()).length() < postSummary)) {
|
||||
post.setPostSummary(HaloUtils.getSummary(post.getPostContent(), postSummary));
|
||||
String text = HtmlUtil.cleanHtmlTag(post.getPostContent());
|
||||
if (text.length() > postSummary) {
|
||||
post.setPostSummary(text.substring(0,postSummary));
|
||||
} else {
|
||||
post.setPostSummary(HaloUtils.htmlToText(post.getPostContent()));
|
||||
post.setPostSummary(text);
|
||||
}
|
||||
postRepository.save(post);
|
||||
}
|
||||
|
|
|
@ -246,72 +246,6 @@ public class HaloUtils {
|
|||
return Instant.ofEpochSecond(unixTime).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(format));
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取html中的文字
|
||||
*
|
||||
* @param html html
|
||||
* @return string
|
||||
*/
|
||||
public static String htmlToText(String html) {
|
||||
if (!"".equals(html)) {
|
||||
return html.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", "");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取文章摘要
|
||||
*
|
||||
* @param html html
|
||||
* @param summary summary
|
||||
* @return string
|
||||
*/
|
||||
public static String getSummary(String html,Integer summary){
|
||||
return htmlToText(html).substring(0,summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* md5加密字符串
|
||||
*
|
||||
* @param str str
|
||||
* @return MD5
|
||||
*/
|
||||
public static String getMD5(String str) {
|
||||
String md5 = "";
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] messageByte = str.getBytes("UTF-8");
|
||||
byte[] md5Byte = md.digest(messageByte);
|
||||
md5 = bytesToHex(md5Byte);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return md5;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 2进制转16进制
|
||||
*
|
||||
* @param bytes bytes
|
||||
* @return string
|
||||
*/
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
StringBuffer hexStr = new StringBuffer();
|
||||
int num;
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
num = bytes[i];
|
||||
if(num < 0) {
|
||||
num += 256;
|
||||
}
|
||||
if(num < 16){
|
||||
hexStr.append("0");
|
||||
}
|
||||
hexStr.append(Integer.toHexString(num));
|
||||
}
|
||||
return hexStr.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户端ip地址
|
||||
*
|
||||
|
|
|
@ -12,6 +12,7 @@ import cc.ryanc.halo.service.PostService;
|
|||
import cc.ryanc.halo.service.UserService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -129,9 +130,9 @@ public class AdminController extends BaseController {
|
|||
Pattern patternEmail = Pattern.compile("\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}");
|
||||
Matcher matcher = patternEmail.matcher(loginName);
|
||||
if (matcher.find()) {
|
||||
user = userService.userLoginByEmail(loginName, HaloUtils.getMD5(loginPwd)).get(0);
|
||||
user = userService.userLoginByEmail(loginName, SecureUtil.md5(loginPwd)).get(0);
|
||||
} else {
|
||||
user = userService.userLoginByName(loginName, HaloUtils.getMD5(loginPwd)).get(0);
|
||||
user = userService.userLoginByName(loginName, SecureUtil.md5(loginPwd)).get(0);
|
||||
}
|
||||
if (aUser == user) {
|
||||
session.setAttribute(HaloConst.USER_SESSION_KEY, user);
|
||||
|
|
|
@ -10,6 +10,7 @@ import cc.ryanc.halo.service.PostService;
|
|||
import cc.ryanc.halo.service.UserService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -137,7 +138,7 @@ public class CommentController extends BaseController{
|
|||
"您在" + HaloConst.OPTIONS.get("blog_title") + "的评论已审核通过!", map, "common/mail/mail_passed.ftl");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("邮件服务器未配置:{0}",e.getMessage());
|
||||
log.error("邮件服务器未配置:",e.getMessage());
|
||||
}
|
||||
}
|
||||
return "redirect:/admin/comments?status="+status;
|
||||
|
@ -157,7 +158,7 @@ public class CommentController extends BaseController{
|
|||
try{
|
||||
commentService.removeByCommentId(commentId);
|
||||
}catch (Exception e){
|
||||
log.error("删除评论失败:{0}",e.getMessage());
|
||||
log.error("删除评论失败:",e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments?status="+status;
|
||||
}
|
||||
|
@ -197,7 +198,7 @@ public class CommentController extends BaseController{
|
|||
comment.setCommentAuthorEmail(user.getUserEmail());
|
||||
comment.setCommentAuthorUrl(HaloConst.OPTIONS.get("blog_url"));
|
||||
comment.setCommentAuthorIp(HaloUtils.getIpAddr(request));
|
||||
comment.setCommentAuthorAvatarMd5(HaloUtils.getMD5(userService.findUser().getUserEmail()));
|
||||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(userService.findUser().getUserEmail()));
|
||||
comment.setCommentDate(new Date());
|
||||
String lastContent = " //<a href='#comment-id-"+lastComment.getCommentId()+"'>@"+lastComment.getCommentAuthor()+"</a>:"+lastComment.getCommentContent();
|
||||
comment.setCommentContent(commentContent+lastContent);
|
||||
|
|
|
@ -10,6 +10,7 @@ import cc.ryanc.halo.service.PostService;
|
|||
import cc.ryanc.halo.service.TagService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import lombok.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -164,18 +165,19 @@ public class PostController extends BaseController{
|
|||
postSummary = Integer.parseInt(HaloConst.OPTIONS.get("post_summary"));
|
||||
}
|
||||
//文章摘要
|
||||
String summaryText = HaloUtils.htmlToText(post.getPostContent());
|
||||
String summaryText = HtmlUtil.cleanHtmlTag(post.getPostContent());
|
||||
if(summaryText.length()>postSummary){
|
||||
String summary = HaloUtils.getSummary(post.getPostContent(), postSummary);
|
||||
String summary = summaryText.substring(0,postSummary);
|
||||
post.setPostSummary(summary);
|
||||
}else{
|
||||
post.setPostSummary(summaryText);
|
||||
}
|
||||
//添加文章时,添加文章时间和修改文章时间为当前时间,修改文章时,只更新修改文章时间
|
||||
if(null!=post.getPostId()){
|
||||
post.setPostDate(postService.findByPostId(post.getPostId()).get().getPostDate());
|
||||
Post oldPost = postService.findByPostId(post.getPostId()).get();
|
||||
post.setPostDate(oldPost.getPostDate());
|
||||
post.setPostUpdate(new Date());
|
||||
post.setPostViews(postService.findByPostId(post.getPostId()).get().getPostViews());
|
||||
post.setPostViews(oldPost.getPostViews());
|
||||
}else{
|
||||
post.setPostDate(new Date());
|
||||
post.setPostUpdate(new Date());
|
||||
|
@ -329,7 +331,7 @@ public class PostController extends BaseController{
|
|||
postService.updateAllSummary(postSummary);
|
||||
return true;
|
||||
}catch (Exception e){
|
||||
log.error("未知错误:{0}",e.getMessage());
|
||||
log.error("未知错误:",e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import cc.ryanc.halo.utils.HaloUtils;
|
|||
import cc.ryanc.halo.utils.ZipUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -19,6 +18,7 @@ import org.springframework.util.ResourceUtils;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.websocket.server.PathParam;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
|
@ -115,7 +115,7 @@ public class ThemeController extends BaseController {
|
|||
return new JsonResult(0,"请选择上传的主题!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("上传主题失败:{0}", e.getMessage());
|
||||
log.error("上传主题失败:", e.getMessage());
|
||||
return new JsonResult(0,"主题上传失败!");
|
||||
}
|
||||
return new JsonResult(1,"主题上传成功!");
|
||||
|
|
|
@ -3,7 +3,7 @@ package cc.ryanc.halo.web.controller.admin;
|
|||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -80,9 +80,9 @@ public class UserController {
|
|||
@ModelAttribute("userId") Long userId,
|
||||
HttpSession session) {
|
||||
try {
|
||||
User user = userService.findByUserIdAndUserPass(userId, HaloUtils.getMD5(beforePass));
|
||||
User user = userService.findByUserIdAndUserPass(userId, SecureUtil.md5(beforePass));
|
||||
if (null != user) {
|
||||
user.setUserPass(HaloUtils.getMD5(newPass));
|
||||
user.setUserPass(SecureUtil.md5(newPass));
|
||||
userService.saveByUser(user);
|
||||
session.invalidate();
|
||||
} else {
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.ryanc.halo.model.dto.HaloConst;
|
|||
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||
import cc.ryanc.halo.service.*;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -106,7 +107,7 @@ public class InstallController {
|
|||
}
|
||||
user.setUserDisplayName(userDisplayName);
|
||||
user.setUserEmail(userEmail);
|
||||
user.setUserPass(HaloUtils.getMD5(userPwd));
|
||||
user.setUserPass(SecureUtil.md5(userPwd));
|
||||
userService.saveByUser(user);
|
||||
|
||||
//默认分类
|
||||
|
|
|
@ -9,6 +9,7 @@ import cc.ryanc.halo.service.MailService;
|
|||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -108,9 +109,7 @@ public class FrontCommentController {
|
|||
comment.setCommentContent(StringUtils.substringAfter(comment.getCommentContent(),":")+lastContent);
|
||||
}
|
||||
if(StringUtils.isNotEmpty(comment.getCommentAuthorUrl())){
|
||||
if(!StringUtils.containsAny(comment.getCommentAuthorUrl(),"https://") || !StringUtils.containsAny(comment.getCommentAuthorUrl(),"http://")){
|
||||
comment.setCommentAuthorUrl("http://"+comment.getCommentAuthorUrl());
|
||||
}
|
||||
comment.setCommentAuthorUrl(URLUtil.formatUrl(comment.getCommentAuthorUrl()));
|
||||
}
|
||||
commentService.saveByComment(comment);
|
||||
if(comment.getCommentParent()>0){
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
server:
|
||||
port: 8090
|
||||
tomcat:
|
||||
min-spare-threads: 20
|
||||
max-threads: 100
|
||||
max-connections: 5000
|
||||
remote-ip-header: x-forwarded-for
|
||||
use-forward-headers: true
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
|
|
Loading…
Reference in New Issue