|
@@ -9,7 +9,7 @@ import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.constant.WebsocketConst;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.UUIDGenerator;
|
|
|
-import org.jeecg.modules.adweb.common.constant.ShellConstans;
|
|
|
+import org.jeecg.modules.adweb.common.dto.ServerDTO;
|
|
|
import org.jeecg.modules.adweb.common.service.FeishuService;
|
|
|
import org.jeecg.modules.adweb.common.service.ShellService;
|
|
|
import org.jeecg.modules.adweb.common.service.WebSocketService;
|
|
@@ -26,8 +26,6 @@ import org.springframework.stereotype.Service;
|
|
|
import java.security.InvalidKeyException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author jerry
|
|
@@ -68,14 +66,7 @@ public class SelfWebSiteService {
|
|
|
private String username;
|
|
|
@Value("${AdwebSiteConnect.password}")
|
|
|
private String password;
|
|
|
- @Value("${AdwebSiteConnect.tempDomain}")
|
|
|
- private String tempDomain;
|
|
|
- @Value("${AdwebSiteConnect.tempCname}")
|
|
|
- private String tempCname;
|
|
|
- @Value("${AdwebSiteProdConnect.privateIp}")
|
|
|
- private String wpSiteReleasePrivateIp;
|
|
|
- @Value("${usWest118Server.shellpath}")
|
|
|
- private String usWest118ServerShellPath;
|
|
|
+
|
|
|
@Resource
|
|
|
private FeishuService openFeishuMsgService;
|
|
|
|
|
@@ -209,6 +200,9 @@ public class SelfWebSiteService {
|
|
|
*/
|
|
|
public boolean siteStartOrStop(LoginUser sysUser, Integer siteId, Integer status) {
|
|
|
AdwebSite adwebSite = siteService.getById(siteId);
|
|
|
+
|
|
|
+ // 获取站点所在生产服务器信息
|
|
|
+ ServerDTO serverInfo = new ServerDTO();
|
|
|
boolean flag = false;
|
|
|
switch (status) {
|
|
|
case 1:
|
|
@@ -218,10 +212,10 @@ public class SelfWebSiteService {
|
|
|
flag = stopSiteLocal(sysUser, adwebSite);
|
|
|
break;
|
|
|
case 3:
|
|
|
- flag = startSite(sysUser, adwebSite);
|
|
|
+ flag = startSite(sysUser, adwebSite, serverInfo);
|
|
|
break;
|
|
|
case 4:
|
|
|
- flag = stopSite(sysUser, adwebSite);
|
|
|
+ flag = stopSite(sysUser, adwebSite, serverInfo);
|
|
|
break;
|
|
|
}
|
|
|
return flag;
|
|
@@ -289,9 +283,9 @@ public class SelfWebSiteService {
|
|
|
* @param adwebSite
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean startSite(LoginUser sysUser, AdwebSite adwebSite) {
|
|
|
+ private boolean startSite(LoginUser sysUser, AdwebSite adwebSite, ServerDTO serverInfo) {
|
|
|
//站点启动
|
|
|
- String cmd = "./shell/start_site " + wpSiteReleasePrivateIp + " " + adwebSite.getCode() + " ";
|
|
|
+ String cmd = "./shell/start_site " + serverInfo.getIp() + " " + adwebSite.getCode() + " ";
|
|
|
shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
@Override
|
|
|
public void stdout(String line) {
|
|
@@ -306,7 +300,7 @@ public class SelfWebSiteService {
|
|
|
public void stderr(String line) {
|
|
|
log.info("错误 :" + line);
|
|
|
}
|
|
|
- });
|
|
|
+ }, serverInfo);
|
|
|
return siteStatusUpdate(sysUser, adwebSite, 0);
|
|
|
}
|
|
|
|
|
@@ -317,8 +311,8 @@ public class SelfWebSiteService {
|
|
|
* @param adwebSite
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean stopSite(LoginUser sysUser, AdwebSite adwebSite) {
|
|
|
- String cmd = "./shell/stop_site " + wpSiteReleasePrivateIp + " " + adwebSite.getCode() + " ";
|
|
|
+ private boolean stopSite(LoginUser sysUser, AdwebSite adwebSite, ServerDTO serverInfo) {
|
|
|
+ String cmd = "./shell/stop_site " + serverInfo.getIp() + " " + adwebSite.getCode() + " ";
|
|
|
shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
@Override
|
|
|
public void stdout(String line) {
|
|
@@ -333,7 +327,7 @@ public class SelfWebSiteService {
|
|
|
public void stderr(String line) {
|
|
|
log.info("错误 :" + line);
|
|
|
}
|
|
|
- });
|
|
|
+ }, serverInfo);
|
|
|
return siteStatusUpdate(sysUser, adwebSite, 3);
|
|
|
}
|
|
|
|
|
@@ -369,7 +363,7 @@ public class SelfWebSiteService {
|
|
|
AdwebSite adwebSite = siteService.getById(siteId);
|
|
|
String siteToken = UUIDGenerator.generate().toUpperCase();
|
|
|
HttpSession session = request.getSession();
|
|
|
-// String cmd = " ./shell/auto_website " + wpSiteReleasePrivateIp + " " + adwebSite.getCode() + " " + adwebSite.getInCode() + " " + domain + " " + siteToken + " " + tempDomain;
|
|
|
+// String cmd = " ./shell/auto_website " + serverInfo.getIp() + " " + adwebSite.getCode() + " " + adwebSite.getInCode() + " " + domain + " " + siteToken + " " + tempDomain;
|
|
|
if (StringUtils.isEmpty(adwebSite.getDevServerIp())) {
|
|
|
return Result.error("该站点的服务器IP没有设置,请设置后在发布上线!");
|
|
|
}
|
|
@@ -378,6 +372,8 @@ public class SelfWebSiteService {
|
|
|
return Result.error("该站点的服务器IP设置不正确,请重试!");
|
|
|
}
|
|
|
|
|
|
+ String usWest118ServerShellPath = "/home/ci-user/shell";
|
|
|
+
|
|
|
//原始域名
|
|
|
String originDomain = domain;
|
|
|
//检验域名是否以www开头
|
|
@@ -410,26 +406,26 @@ public class SelfWebSiteService {
|
|
|
// return false;
|
|
|
try {
|
|
|
// modifyMaterialImgToUs(adwebSite.getCode());
|
|
|
- shellService.exceShellByUsWest118(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("标准 :" + line);
|
|
|
- msgSetInSessionProd(request, line);
|
|
|
- if ("ERROR:FILE_NAME IS EXISTS".equals(line)) {
|
|
|
- // TODO ----
|
|
|
- }
|
|
|
- if ("[Creationcompleted]".equals(line)) {
|
|
|
- log.info("======网站上线成功======");
|
|
|
- statusSuccess.append("ok");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误 :" + line);
|
|
|
- statusFail.append(line);
|
|
|
- }
|
|
|
- });
|
|
|
+// shellService.exceShellByUsWest118(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
+// @Override
|
|
|
+// public void stdout(String line) {
|
|
|
+// log.info("标准 :" + line);
|
|
|
+// msgSetInSessionProd(request, line);
|
|
|
+// if ("ERROR:FILE_NAME IS EXISTS".equals(line)) {
|
|
|
+// // TODO ----
|
|
|
+// }
|
|
|
+// if ("[Creationcompleted]".equals(line)) {
|
|
|
+// log.info("======网站上线成功======");
|
|
|
+// statusSuccess.append("ok");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void stderr(String line) {
|
|
|
+// log.info("错误 :" + line);
|
|
|
+// statusFail.append(line);
|
|
|
+// }
|
|
|
+// });
|
|
|
// //发布完成后,调用脚本,停止测试站点的访问
|
|
|
// try {
|
|
|
// String delCmd = "/home/ci-user/shell/deldns " + adwebSite.getCode();
|
|
@@ -515,6 +511,7 @@ public class SelfWebSiteService {
|
|
|
StringBuilder delSuccess = new StringBuilder();
|
|
|
StringBuilder delFail = new StringBuilder();
|
|
|
AdwebSite adwebSite = siteService.getById(siteId);
|
|
|
+ String usWest118ServerShellPath = "/home/ci-user/shell";
|
|
|
//检验域名是否以www开头
|
|
|
if (domain.startsWith("www.")) {
|
|
|
domain = domain.replace("www.", "");
|
|
@@ -525,47 +522,47 @@ public class SelfWebSiteService {
|
|
|
log.info("===== delReleaseWebsite domain:{},siteId:{},cmd:{} ====", domain, siteId, cmd);
|
|
|
try {
|
|
|
String finalDomain = domain;
|
|
|
- shellService.exceShellByUsWest118(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("标准 :" + line);
|
|
|
- if ("remove site success".equals(line) || "remove site nginx success".equals(line)) {
|
|
|
- log.info("======执行删除旧站点,成功通知======");
|
|
|
- String title = "网站域名:" + finalDomain + " 删除发布失败的旧站点成功";
|
|
|
- String message = "**站点ID:** " + siteId + "\n";
|
|
|
- message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
- message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
-
|
|
|
- delSuccess.append(line);
|
|
|
- }
|
|
|
-
|
|
|
- if ("remove site failed".equals(line) || "remove site nginx failed".equals(line)) {
|
|
|
- log.info("======执行删除旧站点,失败通知======");
|
|
|
- String title = "网站域名:" + finalDomain + " 删除发布失败的旧站点失败";
|
|
|
- String message = "**站点ID:** " + siteId + "\n";
|
|
|
- message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
- message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
- message += "**错误信息:** " + line + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
-
|
|
|
- delFail.append(line);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误 :" + line);
|
|
|
- String title = "网站域名:" + finalDomain + " 删除发布失败的旧站点失败";
|
|
|
- String message = "**站点ID:** " + siteId + "\n";
|
|
|
- message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
- message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
- message += "**错误信息:** " + line + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
-
|
|
|
- delFail.append(line);
|
|
|
- }
|
|
|
- });
|
|
|
+// shellService.exceShellByUsWest118(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
+// @Override
|
|
|
+// public void stdout(String line) {
|
|
|
+// log.info("标准 :" + line);
|
|
|
+// if ("remove site success".equals(line) || "remove site nginx success".equals(line)) {
|
|
|
+// log.info("======执行删除旧站点,成功通知======");
|
|
|
+// String title = "网站域名:" + finalDomain + " 删除发布失败的旧站点成功";
|
|
|
+// String message = "**站点ID:** " + siteId + "\n";
|
|
|
+// message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
+// message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
+// sendAdWebV2FeiShuMsg(title, message);
|
|
|
+//
|
|
|
+// delSuccess.append(line);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ("remove site failed".equals(line) || "remove site nginx failed".equals(line)) {
|
|
|
+// log.info("======执行删除旧站点,失败通知======");
|
|
|
+// String title = "网站域名:" + finalDomain + " 删除发布失败的旧站点失败";
|
|
|
+// String message = "**站点ID:** " + siteId + "\n";
|
|
|
+// message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
+// message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
+// message += "**错误信息:** " + line + "\n";
|
|
|
+// sendAdWebV2FeiShuMsg(title, message);
|
|
|
+//
|
|
|
+// delFail.append(line);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void stderr(String line) {
|
|
|
+// log.info("错误 :" + line);
|
|
|
+// String title = "网站域名:" + finalDomain + " 删除发布失败的旧站点失败";
|
|
|
+// String message = "**站点ID:** " + siteId + "\n";
|
|
|
+// message += "**临时域名:** " + adwebSite.getDomainDev() + "\n";
|
|
|
+// message += "**服务器IP:** " + adwebSite.getDevServerIp() + "\n";
|
|
|
+// message += "**错误信息:** " + line + "\n";
|
|
|
+// sendAdWebV2FeiShuMsg(title, message);
|
|
|
+//
|
|
|
+// delFail.append(line);
|
|
|
+// }
|
|
|
+// });
|
|
|
} catch (Exception e) {
|
|
|
log.error("删除发布失败的旧站点失败,退出执行;" + e.getMessage(), e);
|
|
|
delFail.append(e.getMessage());
|
|
@@ -581,371 +578,6 @@ public class SelfWebSiteService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 自动添加SSL(脚本执行)
|
|
|
- *
|
|
|
- * @param adwebSite
|
|
|
- */
|
|
|
- public AdwebSite autoAddSsl(AdwebSite adwebSite) {
|
|
|
- String cmd;
|
|
|
- StringBuilder isExists = new StringBuilder();
|
|
|
- StringBuilder notExists = new StringBuilder();
|
|
|
- cmd = "./shell/read_cert " + wpSiteReleasePrivateIp + " " + adwebSite.getDomain();
|
|
|
- shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("控制台:" + line);
|
|
|
- //存在
|
|
|
- if (line.startsWith(ShellConstans.addSsl.IS_ERROR_INFO)) {
|
|
|
- isExists.append(line);
|
|
|
- }
|
|
|
- //不存在
|
|
|
- if (line.startsWith(ShellConstans.addSsl.NULL_ERROR_INFO)) {
|
|
|
- notExists.append(line);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误:" + line);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if (StringUtils.isNotBlank(isExists.toString())) {
|
|
|
- StringBuilder privekeySb = new StringBuilder();
|
|
|
- StringBuilder cert = new StringBuilder();
|
|
|
- StringBuilder chain = new StringBuilder();
|
|
|
- StringBuilder dataTime = new StringBuilder();
|
|
|
- final Map<String, Boolean> certWriteMap = new HashMap<>();
|
|
|
- certWriteMap.put("isCertWrite", false);
|
|
|
- certWriteMap.put("isPrivateKeyWrite", false);
|
|
|
- certWriteMap.put("isChainWrite", false);
|
|
|
- cmd = "./shell/update_cert " + wpSiteReleasePrivateIp + " " + adwebSite.getDomain();
|
|
|
- shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("控制台:" + line);
|
|
|
- if (line.startsWith(ShellConstans.addSsl.DATE_TIME)) {
|
|
|
- dataTime.append(line);
|
|
|
- }
|
|
|
- //cert
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_CERT)) {
|
|
|
- certWriteMap.put("isCertWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_CERT)) {
|
|
|
- certWriteMap.put("isCertWrite", false);
|
|
|
- }
|
|
|
- // 私有key可写
|
|
|
- if (certWriteMap.get("isCertWrite") && !line.startsWith(ShellConstans.addSsl.START_CERT)) {
|
|
|
- cert.append(line);
|
|
|
- cert.append('\n');
|
|
|
- }
|
|
|
- //privkey
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_PRIVKEY)) {
|
|
|
- certWriteMap.put("isPrivateKeyWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_PRIVKEY)) {
|
|
|
- certWriteMap.put("isPrivateKeyWrite", false);
|
|
|
- }
|
|
|
- // 私有key可写
|
|
|
- if (certWriteMap.get("isPrivateKeyWrite") && !line.startsWith(ShellConstans.addSsl.START_PRIVKEY)) {
|
|
|
- privekeySb.append(line);
|
|
|
- privekeySb.append('\n');
|
|
|
- }
|
|
|
- //chain
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_CHAIN)) {
|
|
|
- certWriteMap.put("isChainWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_CHAIN)) {
|
|
|
- certWriteMap.put("isChainWrite", false);
|
|
|
- }
|
|
|
- // 私有key可写
|
|
|
- if (certWriteMap.get("isChainWrite") && !line.startsWith(ShellConstans.addSsl.START_CHAIN)) {
|
|
|
- chain.append(line);
|
|
|
- chain.append('\n');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误:" + line);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- } else if (StringUtils.isNotBlank(notExists.toString())) {
|
|
|
- StringBuilder privekeySb = new StringBuilder();
|
|
|
- StringBuilder cert = new StringBuilder();
|
|
|
- StringBuilder chain = new StringBuilder();
|
|
|
- StringBuilder dataTime = new StringBuilder();
|
|
|
- final Map<String, Boolean> certWriteMap = new HashMap<>();
|
|
|
- certWriteMap.put("isCertWrite", false);
|
|
|
- certWriteMap.put("isPrivateKeyWrite", false);
|
|
|
- certWriteMap.put("isChainWrite", false);
|
|
|
- cmd = "./shell/make_cert " + wpSiteReleasePrivateIp + " " + adwebSite.getCode() + " " + adwebSite.getInCode() + " " + adwebSite.getDomain();
|
|
|
- shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("控制台:" + line);
|
|
|
- if (line.startsWith(ShellConstans.addSsl.DATE_TIME)) {
|
|
|
- dataTime.append(line);
|
|
|
- }
|
|
|
- //cert
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_CERT)) {
|
|
|
- certWriteMap.put("isCertWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_CERT)) {
|
|
|
- certWriteMap.put("isCertWrite", false);
|
|
|
- }
|
|
|
- // 私有key可写
|
|
|
- if (certWriteMap.get("isCertWrite") && !line.startsWith(ShellConstans.addSsl.START_CERT)) {
|
|
|
- cert.append(line);
|
|
|
- cert.append('\n');
|
|
|
- }
|
|
|
- //privkey
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_PRIVKEY)) {
|
|
|
- certWriteMap.put("isPrivateKeyWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_PRIVKEY)) {
|
|
|
- certWriteMap.put("isPrivateKeyWrite", false);
|
|
|
- }
|
|
|
- // 私有key可写
|
|
|
- if (certWriteMap.get("isPrivateKeyWrite") && !line.startsWith(ShellConstans.addSsl.START_PRIVKEY)) {
|
|
|
- privekeySb.append(line);
|
|
|
- privekeySb.append('\n');
|
|
|
- }
|
|
|
- //chain
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_CHAIN)) {
|
|
|
- certWriteMap.put("isChainWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_CHAIN)) {
|
|
|
- certWriteMap.put("isChainWrite", false);
|
|
|
- }
|
|
|
- // 私有key可写
|
|
|
- if (certWriteMap.get("isChainWrite") && !line.startsWith(ShellConstans.addSsl.START_CHAIN)) {
|
|
|
- chain.append(line);
|
|
|
- chain.append('\n');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误:" + line);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
- return adwebSite;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param adwebSite
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Result<?> autoAddSslV2(AdwebSite adwebSite) {
|
|
|
- log.info("===== autoAddSslV2 ==> 开始生成SSL证书 domain:{},code:{},siteId:{} =====", adwebSite.getDomain(), adwebSite.getCode(), adwebSite.getId());
|
|
|
- String domainNew = adwebSite.getDomain().replace("http://", "").replace("https://", "").replace("www.", "");
|
|
|
- log.info("===== autoAddSslV2 ==> 开始生成SSL证书 domain:{},code:{},siteId:{},domainNew:{} =====", adwebSite.getDomain(), adwebSite.getCode(), adwebSite.getId(), domainNew);
|
|
|
-// domainNew = "xyexcavator.com";
|
|
|
-// String cmd = "sudo sh " + usWest118ServerShellPath + "/test_check_site_ssl_exist.sh " + adwebSite.getCode() + " " + domainNew;
|
|
|
-// String cmd = "sudo sh " + usWest118ServerShellPath + "/generate_site_ssl.sh " + adwebSite.getCode() + " " + domainNew;
|
|
|
- String cmd = "sudo sh " + usWest118ServerShellPath + "/switch_root_user.sh " + adwebSite.getCode() + " " + domainNew;
|
|
|
- log.info("===== autoAddSslV2 ==> 开始生成SSL证书 domain:{},code:{},siteId:{},domainNew:{},cmd:{} =====", adwebSite.getDomain(), adwebSite.getCode(), adwebSite.getId(), domainNew, cmd);
|
|
|
- try {
|
|
|
- String finalDomainNew = domainNew;
|
|
|
- final Map<String, Boolean> certWriteMap = new HashMap<>();
|
|
|
- certWriteMap.put("isCertWrite", false);
|
|
|
- certWriteMap.put("isPrivateKeyWrite", false);
|
|
|
- certWriteMap.put("isChainWrite", false);
|
|
|
- StringBuilder privateKey = new StringBuilder();
|
|
|
- StringBuilder cert = new StringBuilder();
|
|
|
- StringBuilder chain = new StringBuilder();
|
|
|
- shellService.exceShellByUsWest118(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("标准 :" + line);
|
|
|
- //cert
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_CERT)) {
|
|
|
- certWriteMap.put("isCertWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_CERT)) {
|
|
|
- certWriteMap.put("isCertWrite", false);
|
|
|
- }
|
|
|
- if (certWriteMap.get("isCertWrite") && !line.startsWith(ShellConstans.addSsl.START_CERT)) {
|
|
|
- cert.append(line);
|
|
|
- cert.append('\n');
|
|
|
- }
|
|
|
-
|
|
|
- //privkey
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_PRIVKEY)) {
|
|
|
- certWriteMap.put("isPrivateKeyWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_PRIVKEY)) {
|
|
|
- certWriteMap.put("isPrivateKeyWrite", false);
|
|
|
- }
|
|
|
- if (certWriteMap.get("isPrivateKeyWrite") && !line.startsWith(ShellConstans.addSsl.START_PRIVKEY)) {
|
|
|
- privateKey.append(line);
|
|
|
- privateKey.append('\n');
|
|
|
- }
|
|
|
-
|
|
|
- //chain
|
|
|
- if (line.startsWith(ShellConstans.addSsl.START_CHAIN)) {
|
|
|
- certWriteMap.put("isChainWrite", true);
|
|
|
- } else if (line.startsWith(ShellConstans.addSsl.END_CHAIN)) {
|
|
|
- certWriteMap.put("isChainWrite", false);
|
|
|
- }
|
|
|
- if (certWriteMap.get("isChainWrite") && !line.startsWith(ShellConstans.addSsl.START_CHAIN)) {
|
|
|
- chain.append(line);
|
|
|
- chain.append('\n');
|
|
|
- }
|
|
|
-
|
|
|
- if ("SSL Certificate generation failed".equals(line)) {
|
|
|
- log.info("======网站SSL证书生成失败======");
|
|
|
- String title = "网站域名:" + finalDomainNew + " 站点SSL证书创建失败";
|
|
|
- String message = "**站点ID:** " + adwebSite.getId() + "\n";
|
|
|
- message += "**站点Code:** " + adwebSite.getCode() + "\n";
|
|
|
-// message += "**服务器IP:** " + adwebSite.getProdServerIp() + "\n";
|
|
|
- message += "**错误信息:** " + line + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误 :" + line);
|
|
|
- String title = "网站域名:" + finalDomainNew + " 站点SSL证书创建失败";
|
|
|
- String message = "**站点ID:** " + adwebSite.getId() + "\n";
|
|
|
- message += "**站点Code:** " + adwebSite.getCode() + "\n";
|
|
|
-// message += "**服务器IP:** " + adwebSite.getProdServerIp() + "\n";
|
|
|
- message += "**错误信息:** " + line + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if (StringUtils.isNotBlank(privateKey.toString()) && StringUtils.isNotBlank(cert.toString()) && StringUtils.isNotBlank(chain.toString())) {
|
|
|
- log.info("======= SSL证书获取成功 =======");
|
|
|
- log.info("privateKey:{}", privateKey);
|
|
|
- log.info("cert:{}", cert);
|
|
|
- log.info("chain:{}", chain);
|
|
|
-
|
|
|
- String certStr = cert.toString();
|
|
|
- boolean certStatus = certStr.contains("-----END CERTIFICATE-----");
|
|
|
- if (certStatus) {
|
|
|
- int index = certStr.lastIndexOf("-----END CERTIFICATE-----");
|
|
|
- certStr = certStr.substring(0, index + 25);
|
|
|
- }
|
|
|
- log.info("certStr:{}", certStr);
|
|
|
-
|
|
|
- // 站点SSL证书创建成功-操作
|
|
|
- log.info("======= 将证书信息保存至站点 =======");
|
|
|
- AdwebSite adwebSiteSSL = new AdwebSite();
|
|
|
- adwebSiteSSL.setId(adwebSite.getId());
|
|
|
-
|
|
|
- adwebSiteSSL.setUtime(new Date());
|
|
|
- siteService.updateById(adwebSiteSSL);
|
|
|
-
|
|
|
- //发送飞书消息
|
|
|
- String title = "网站域名:" + finalDomainNew + " 站点SSL证书创建成功";
|
|
|
- String message = "**站点ID:** " + adwebSite.getId() + "\n";
|
|
|
- message += "**站点Code:** " + adwebSite.getCode() + "\n";
|
|
|
-// message += "**服务器IP:** " + adwebSite.getProdServerIp() + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
-// return Result.OK("该站点SSL证书创建成功!");
|
|
|
- return domainHttpToHttps(adwebSite);
|
|
|
- } else {
|
|
|
- //发送飞书消息
|
|
|
- String title = "网站域名:" + finalDomainNew + " 站点SSL证书获取失败";
|
|
|
- String message = "**站点ID:** " + adwebSite.getId() + "\n";
|
|
|
- message += "**站点Code:** " + adwebSite.getCode() + "\n";
|
|
|
-// message += "**服务器IP:** " + adwebSite.getProdServerIp() + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
- return Result.error("该站点SSL证书获取失败!");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("网站SSL证书创建失败退出执行;" + e.getMessage(), e);
|
|
|
- return Result.error("该站点SSL证书创建失败,请重试!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 网站 http升级为https
|
|
|
- *
|
|
|
- * @param adwebSite
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Result<?> domainHttpToHttps(AdwebSite adwebSite) {
|
|
|
- log.info("===== domainHttpToHttps ==> 开始执行将站点由http升级为https操作 domain:{},code:{},siteId:{} =====", adwebSite.getDomain(), adwebSite.getCode(), adwebSite.getId());
|
|
|
- String domainNew = adwebSite.getDomain().replace("http://", "").replace("https://", "").replace("www.", "");
|
|
|
- log.info("===== domainHttpToHttps ==> 开始执行将站点由http升级为https操作 domain:{},code:{},siteId:{},domainNew:{} =====", adwebSite.getDomain(), adwebSite.getCode(), adwebSite.getId(), domainNew);
|
|
|
- String cmd = "sudo sh " + usWest118ServerShellPath + "/adweb-publish_https.sh " + adwebSite.getCode() + " " + domainNew;
|
|
|
- log.info("===== domainHttpToHttps ==> 开始执行将站点由http升级为https操作 domain:{},code:{},siteId:{},domainNew:{},cmd:{} =====", adwebSite.getDomain(), adwebSite.getCode(), adwebSite.getId(), domainNew, cmd);
|
|
|
- try {
|
|
|
- shellService.exceShellByUsWest118(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("标准 :" + line);
|
|
|
- if ("Site Https Created successfully".equals(line)) {
|
|
|
- log.info("======网站http升级为https成功======");
|
|
|
- String title = "网站域名:" + domainNew + " 站点http升级为https成功";
|
|
|
- String message = "**站点ID:** " + adwebSite.getId() + "\n";
|
|
|
- message += "**站点Code:** " + adwebSite.getCode() + "\n";
|
|
|
-// message += "**服务器IP:** " + adwebSite.getProdServerIp() + "\n";
|
|
|
- message += "**成功信息:** " + line + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
-
|
|
|
- log.info("======网站http升级为https成功,开始更新站点信息======");
|
|
|
- adwebSite.setDomain("https://" + domainNew);
|
|
|
- siteService.updateById(adwebSite);
|
|
|
- }
|
|
|
-
|
|
|
- if ("test nginx failed".equals(line) || "SSL Certificate not found".equals(line)) {
|
|
|
- log.info("======网站http升级为https失败======");
|
|
|
- String title = "网站域名:" + domainNew + " 站点http升级为https失败";
|
|
|
- String message = "**站点ID:** " + adwebSite.getId() + "\n";
|
|
|
- message += "**站点Code:** " + adwebSite.getCode() + "\n";
|
|
|
-// message += "**服务器IP:** " + adwebSite.getProdServerIp() + "\n";
|
|
|
- message += "**错误信息:** " + line + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误 :" + line);
|
|
|
- String title = "网站域名:" + domainNew + " 站点http升级为https失败";
|
|
|
- String message = "**站点ID:** " + adwebSite.getId() + "\n";
|
|
|
- message += "**站点Code:** " + adwebSite.getCode() + "\n";
|
|
|
-// message += "**服务器IP:** " + adwebSite.getProdServerIp() + "\n";
|
|
|
- message += "**错误信息:** " + line + "\n";
|
|
|
- sendAdWebV2FeiShuMsg(title, message);
|
|
|
- }
|
|
|
- });
|
|
|
- return Result.OK();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("网站http升级为https失败退出执行;" + e.getMessage(), e);
|
|
|
- return Result.error("该站点http升级为https失败,请重试!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 手动添加SSL
|
|
|
- *
|
|
|
- * @param adwebSite
|
|
|
- * @return
|
|
|
- */
|
|
|
- public void munualAddSSL(AdwebSite adwebSite, String fullchainUrl, String privkeyUrl) {
|
|
|
- String cmd = "./shell/add_ssl " + wpSiteReleasePrivateIp + " " + adwebSite.getCode() + " " + adwebSite.getInCode() + " " + adwebSite.getDomain() + " " + fullchainUrl + " " + privkeyUrl;
|
|
|
- shellService.exceShell(cmd, new ShellSSH2Util.StdoutListener() {
|
|
|
- @Override
|
|
|
- public void stdout(String line) {
|
|
|
- log.info("控制台:" + line);
|
|
|
- if (line.contains("EXIST!")) {
|
|
|
- log.info("更新!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stderr(String line) {
|
|
|
- log.info("错误 :" + line);
|
|
|
- }
|
|
|
- //TODO 脚本异常处理
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* @param msgTitle
|
|
|
* @param message
|