Merge pull request !55 from Arno/dev
This commit is contained in:
不忘初心 2019-03-21 15:17:41 +08:00 committed by Arno
commit f95f223e0b
7 changed files with 100 additions and 51 deletions

View File

@ -12,7 +12,7 @@
<artifactId>jpom</artifactId> <artifactId>jpom</artifactId>
<name>Jpom Java项目在线管理</name> <name>Jpom Java项目在线管理</name>
<inceptionYear>2017</inceptionYear> <inceptionYear>2017</inceptionYear>
<version>1.1</version> <version>2.0</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>

View File

@ -32,6 +32,6 @@ set ARGS=--server.port=2123 --jpom.path=%basePath% --jpom.log=%basePath%log --jp
set TEMPCLASSPATH= set TEMPCLASSPATH=
for /f "delims=" %%I in ('dir /B %Lib%') do (set TEMPCLASSPATH=!TEMPCLASSPATH!%Lib%%%I;) for /f "delims=" %%I in ('dir /B %Lib%') do (set TEMPCLASSPATH=!TEMPCLASSPATH!%Lib%%%I;)
@REM echo 启动成功,关闭窗口不影响运行 @REM echo 启动成功,关闭窗口不影响运行
cmd /S /C "javaw %JVM% -classpath %TEMPCLASSPATH%%JAVA_HOME%\lib\tools.jar -Dappliction=%Tag% -Dbasedir=%basePath% %MainClass% %ARGS% >> %Log%" cmd /S /C "javaw %JVM% -classpath %TEMPCLASSPATH%"%JAVA_HOME%"\lib\tools.jar -Dappliction=%Tag% -Dbasedir=%basePath% %MainClass% %ARGS% >> %Log%"
:end :end

View File

@ -2,7 +2,6 @@ package cn.keepbx.jpom.controller.system;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.JsonMessage; import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.controller.multipart.MultipartFileBuilder; import cn.jiangzeyin.controller.multipart.MultipartFileBuilder;
import cn.keepbx.jpom.common.BaseController; import cn.keepbx.jpom.common.BaseController;
@ -18,12 +17,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -107,7 +102,7 @@ public class CertificateController extends BaseController {
MultipartFileBuilder cert = createMultipart().addFieldName("cert").setSavePath(temporary).setUseOriginalFilename(true); MultipartFileBuilder cert = createMultipart().addFieldName("cert").setSavePath(temporary).setUseOriginalFilename(true);
String certPath = cert.save(); String certPath = cert.save();
//解析证书 //解析证书
JSONObject jsonObject = decodeCert(FileUtil.file(certPath)); JSONObject jsonObject = CertModel.decodeCert(certPath);
if (jsonObject == null) { if (jsonObject == null) {
throw new RuntimeException("解析证书失败"); throw new RuntimeException("解析证书失败");
} }
@ -116,49 +111,15 @@ public class CertificateController extends BaseController {
CertModel certModel = new CertModel(); CertModel certModel = new CertModel();
certModel.setId(id); certModel.setId(id);
certModel.setWhitePath(path); certModel.setWhitePath(path);
certModel.setCert(certPath);
certModel.setKey(keyPath);
//
certModel.setDomain(jsonObject.getString("domain")); certModel.setDomain(jsonObject.getString("domain"));
certModel.setExpirationTime(jsonObject.getLongValue("expirationTime")); certModel.setExpirationTime(jsonObject.getLongValue("expirationTime"));
certModel.setCert(certPath);
certModel.setEffectiveTime(jsonObject.getLongValue("effectiveTime")); certModel.setEffectiveTime(jsonObject.getLongValue("effectiveTime"));
certModel.setKey(keyPath);
return certModel; return certModel;
} }
/**
* 解析证书
*
* @param file 证书文件
*/
private JSONObject decodeCert(File file) {
if (file == null) {
return null;
}
try {
BufferedInputStream inStream = FileUtil.getInputStream(file);
// 创建X509工厂类
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// 创建证书对象
X509Certificate oCert = (X509Certificate) cf.generateCertificate(inStream);
inStream.close();
//到期时间
Date expirationTime = oCert.getNotAfter();
//生效日期
Date effectiveTime = oCert.getNotBefore();
//域名
String name = oCert.getSubjectDN().getName();
int i = name.indexOf("=");
String domain = name.substring(i + 1);
JSONObject jsonObject = new JSONObject();
jsonObject.put("expirationTime", expirationTime.getTime());
jsonObject.put("effectiveTime", effectiveTime.getTime());
jsonObject.put("domain", domain);
return jsonObject;
} catch (Exception e) {
DefaultSystemLog.ERROR().error(e.getMessage(), e);
}
return null;
}
/** /**
* 证书列表 * 证书列表
@ -172,6 +133,9 @@ public class CertificateController extends BaseController {
/** /**
* 删除证书 * 删除证书
*
* @param id id
* @return json
*/ */
@RequestMapping(value = "/certificate/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @RequestMapping(value = "/certificate/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody @ResponseBody
@ -185,6 +149,4 @@ public class CertificateController extends BaseController {
} }
return JsonMessage.getString(200, "删除成功"); return JsonMessage.getString(200, "删除成功");
} }
} }

View File

@ -1,5 +1,7 @@
package cn.keepbx.jpom.model; package cn.keepbx.jpom.model;
import com.alibaba.fastjson.JSON;
/** /**
* @author jiangzeyin * @author jiangzeyin
* @date 2019/3/14 * @date 2019/3/14
@ -14,4 +16,9 @@ public abstract class BaseModel {
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
@Override
public String toString() {
return JSON.toJSONString(this);
}
} }

View File

@ -1,7 +1,17 @@
package cn.keepbx.jpom.model; package cn.keepbx.jpom.model;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.keepbx.jpom.service.system.CertService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.io.BufferedInputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Date;
/** /**
* 证书实体 * 证书实体
* *
@ -58,6 +68,7 @@ public class CertModel extends BaseModel {
} }
public long getExpirationTime() { public long getExpirationTime() {
this.convertInfo();
return expirationTime; return expirationTime;
} }
@ -66,14 +77,36 @@ public class CertModel extends BaseModel {
} }
public String getDomain() { public String getDomain() {
this.convertInfo();
return domain; return domain;
} }
/**
* 兼容手动添加的证书文件
*/
private void convertInfo() {
if (!StrUtil.isEmpty(domain)) {
return;
}
JSONObject jsonObject = decodeCert(getCert());
if (jsonObject != null) {
// 获取信息
this.setDomain(jsonObject.getString("domain"));
this.setExpirationTime(jsonObject.getLongValue("expirationTime"));
this.setEffectiveTime(jsonObject.getLongValue("effectiveTime"));
// 数据持久化到文件中
CertService certService = SpringUtil.getBean(CertService.class);
certService.updateCert(this);
}
}
public void setDomain(String domain) { public void setDomain(String domain) {
this.domain = domain; this.domain = domain;
} }
public long getEffectiveTime() { public long getEffectiveTime() {
this.convertInfo();
return effectiveTime; return effectiveTime;
} }
@ -84,4 +117,43 @@ public class CertModel extends BaseModel {
public JSONObject toJson() { public JSONObject toJson() {
return (JSONObject) JSONObject.toJSON(this); return (JSONObject) JSONObject.toJSON(this);
} }
/**
* 解析证书
*
* @param file 证书文件
*/
public static JSONObject decodeCert(String file) {
if (file == null) {
return null;
}
if (!FileUtil.exist(file)) {
return null;
}
try {
BufferedInputStream inStream = FileUtil.getInputStream(file);
// 创建X509工厂类
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// 创建证书对象
X509Certificate oCert = (X509Certificate) cf.generateCertificate(inStream);
inStream.close();
//到期时间
Date expirationTime = oCert.getNotAfter();
//生效日期
Date effectiveTime = oCert.getNotBefore();
//域名
String name = oCert.getSubjectDN().getName();
int i = name.indexOf("=");
String domain = name.substring(i + 1);
JSONObject jsonObject = new JSONObject();
jsonObject.put("expirationTime", expirationTime.getTime());
jsonObject.put("effectiveTime", effectiveTime.getTime());
jsonObject.put("domain", domain);
return jsonObject;
} catch (Exception e) {
DefaultSystemLog.ERROR().error(e.getMessage(), e);
}
return null;
}
} }

View File

@ -131,13 +131,11 @@
} }
function loadSuccess() { function loadSuccess() {
table.render({ table.render({
id: 'tab_certificate', id: 'tab_certificate',
elem: '#tab_certificate', elem: '#tab_certificate',
url: '/system/certificate/getCertList', url: '/system/certificate/getCertList',
height: 'full-52', // height: 'full-52',
even: true, even: true,
cols: [[ cols: [[
{field: 'id', title: 'id'}, {field: 'id', title: 'id'},
@ -213,7 +211,9 @@
if (200 == data.code) { if (200 == data.code) {
layer.msg('删除成功!'); layer.msg('删除成功!');
// 刷新项目列表 // 刷新项目列表
table.reload('tab_certificate', {height: 'full-52'}); table.reload('tab_certificate', {
// height: 'full-52'
});
} else { } else {
layer.msg(data.msg); layer.msg(data.msg);
} }

View File

@ -0,0 +1,8 @@
{
"self_product": {
"id": "self_product",
"cert": "/etc/nginx/cert/self_product/full_chain.pem",
"key": "/etc/nginx/cert/self_product/private.key",
"whitePath": "/etc/nginx/cert/"
}
}