vk-ssl-auto-deploy 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,9 +42,7 @@ npm root -g
42
42
 
43
43
  则拼接上 `vk-ssl-auto-deploy`,即执行命令 `cd /usr/lib/node_modules/vk-ssl-auto-deploy` 进入工具目录
44
44
 
45
- ### 5. 修改证书保存目录
46
-
47
- 查看配置文件 [查看配置说明](#配置说明)
45
+ ### 5. 编辑配置文件,修改证书保存目录
48
46
 
49
47
  ```bash
50
48
  vim config.json
@@ -60,6 +58,28 @@ vim config.json
60
58
  - 输入 :q! - 不保存退出
61
59
  - 输入 :w - 仅保存
62
60
 
61
+ **配置说明**
62
+
63
+ 编辑 `config.json` 文件,主要修改3参数,`certSaveDir`、`nginxDir`、`key`
64
+
65
+ ```json
66
+ {
67
+ "key": "",
68
+ "certSaveDir": "/vk-cert",
69
+ "nginxDir": "/www/server/nginx/sbin/nginx",
70
+ "domains": [],
71
+ "callbackCommand": [],
72
+ "port": 6001
73
+ }
74
+ ```
75
+
76
+ - `key`: 你的密钥
77
+ - `certSaveDir`: 证书存储目录,最终证书路径为 `${certSaveDir}/域名.crt`、`${certSaveDir}/域名.key`、`${certSaveDir}/域名.pem`
78
+ - `nginxDir`: 你的nginx的安装目录
79
+ - `domains`: 指定拉取的域名,不指定代表拉取你的所有域名证书
80
+ - `callbackCommand`: 一般不需要改
81
+ - `port`: 服务监听端口(默认 6001)(一般无需改动)
82
+
63
83
  ### 6. 启动服务,并设置开机自启
64
84
 
65
85
  #### Linux系统
@@ -70,9 +90,9 @@ vim config.json
70
90
 
71
91
  ```bash
72
92
  # 进入安装目录(需改成你的目录)
73
- cd /usr/lib/node_modules/vk-ssl-auto-deploy
74
-
75
- # 生成开机启动脚本
93
+ cd /usr/lib/node_modules/vk-ssl-auto-deploy
94
+
95
+ # 生成开机启动脚本
76
96
  pm2 startup
77
97
 
78
98
  # 启动服务
@@ -138,27 +158,6 @@ pm2-startup uninstall
138
158
  # 方法二:在任务计划程序中删除对应的任务
139
159
  ```
140
160
 
141
-
142
- ## 配置说明
143
-
144
- 编辑 `config.json` 文件可以修改服务端口和路由前缀:
145
-
146
- ```json
147
- {
148
- "port": 6001,
149
- "certSaveDir": "/vk-cert",
150
- "ipWhitelist": [],
151
- "callbackCommand": [
152
- "sudo nginx -t && sudo service nginx reload"
153
- ]
154
- }
155
- ```
156
-
157
- - `port`: 服务监听端口(默认 6001)(一般无需改动)
158
- - `certSaveDir`: 证书存储目录,最终证书路径为 `${certSaveDir}/${证书id}/`(一般无需改动)
159
- - `ipWhitelist`: IP白名单,默认为空,表示不限制IP,如果需要限制IP,可以填写IP地址,多个IP地址用逗号分隔
160
- - `callbackCommand`: 证书部署成功后执行的服务器命令,一般用于重载nginx配置等
161
-
162
161
  ## 查找nginx安装目录
163
162
 
164
163
  通过查看进程信息
package/app.js CHANGED
@@ -38,14 +38,14 @@ app.use((err, req, res, next) => {
38
38
  res.locals.error = req.app.get('env') === 'development' ? err : {};
39
39
  res.status(err.status || 500);
40
40
  res.render('error');
41
- });
42
-
43
-
41
+ });
42
+
43
+
44
44
  // 启动服务器
45
45
  const port = process.env.PORT || config.port;
46
46
  const host = process.env.HOST || '0.0.0.0';
47
47
 
48
- app.listen(port, host, () => {
48
+ app.listen(port, host, () => {
49
49
  console.log('listenPort:', port)
50
50
  });
51
51
 
package/config.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
- "port": 6001,
2
+ "key": "h85ymdt87reg4pr2p652zcgsuw2jsg7r",
3
3
  "certSaveDir": "/vk-cert",
4
4
  "nginxDir": "/www/server/nginx/sbin/nginx",
5
- "key": "h85ymdt87reg4pr2p652zcgsuw2jsg7r",
6
5
  "domains": [],
7
- "callbackCommand": []
6
+ "callbackCommand": [],
7
+ "port": 6001
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vk-ssl-auto-deploy",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "SSL证书自动部署工具 - 提供HTTP API接口,支持证书文件自动上传和部署",
5
5
  "main": "app.js",
6
6
  "bin": {
package/routes/cert.js CHANGED
@@ -44,8 +44,8 @@ let scheduledTaskTimer = null;
44
44
  let lastExecutionDate = null;
45
45
  let isTaskRunning = false;
46
46
  let scheduledExecutionTime = null; // 固定的执行时间 { hour, minute }
47
- let lastCountdownText = ''; // 上次打印的倒计时文本
48
- let needWrite = false;
47
+ let lastCountdownText = ''; // 上次打印的倒计时文本
48
+ let needWrite = false;
49
49
 
50
50
  // 文件锁路径
51
51
  const LOCK_FILE = path.join(__dirname, '..', '.cert-deploy.lock');
@@ -584,10 +584,10 @@ async function executeDeployTask() {
584
584
 
585
585
  /**
586
586
  * 初始化定时任务
587
- * 服务启动时随机确定一个执行时间(9:00-10:59之间),每天在该固定时间执行
587
+ * 服务启动时随机确定一个执行时间
588
588
  */
589
589
  function initScheduledTask() {
590
- logger.info('[定时任务] 初始化定时任务...');
590
+ logger.info('[定时任务] 重新初始化定时任务...');
591
591
  needWrite = true;
592
592
  // 清除旧的定时器
593
593
  if (scheduledTaskTimer) {
@@ -596,10 +596,10 @@ function initScheduledTask() {
596
596
 
597
597
  // 生成固定的随机执行时间(只在服务启动时生成一次)
598
598
  if (!scheduledExecutionTime) {
599
- // 生成9:00-10:59之间的随机分钟数(0-119分钟)
600
- const randomMinute = Math.floor(Math.random() * 120);
599
+ // 生成一天之间的随机分钟数(避开11:00 - 22:00)
600
+ const randomMinute = Math.floor(Math.random() * 780);
601
601
  scheduledExecutionTime = {
602
- hour: 9 + Math.floor(randomMinute / 60),
602
+ hour: (22 + Math.floor(randomMinute / 60)) % 24,
603
603
  minute: randomMinute % 60
604
604
  };
605
605
 
@@ -635,7 +635,7 @@ function initScheduledTask() {
635
635
 
636
636
  // 计算剩余时间(毫秒)
637
637
  const remainingMs = targetTime - now;
638
- const remainingSeconds = Math.floor(remainingMs / 1000);
638
+ const remainingSeconds = Math.floor(remainingMs / 1000);
639
639
  const hours = Math.floor(remainingSeconds / 3600);
640
640
  const minutes = Math.floor((remainingSeconds % 3600) / 60);
641
641
  const seconds = remainingSeconds % 60;
@@ -648,7 +648,7 @@ function initScheduledTask() {
648
648
  } else if (minutes > 0) {
649
649
  // 超过1分钟:只显示分钟数
650
650
  countdownText = `${minutes}分钟+ 后执行`;
651
- } else if (seconds === 0){
651
+ } else if (seconds === 0) {
652
652
  countdownText = `即将执行`;
653
653
  } else {
654
654
  // 1分钟内:进行秒级倒计时
@@ -657,11 +657,11 @@ function initScheduledTask() {
657
657
 
658
658
  // 只有当倒计时文本发生变化时才打印
659
659
  if (countdownText !== lastCountdownText && needWrite) {
660
- if (countdownText === "即将执行") {
661
- needWrite = false;
662
- process.stdout.write(`\r[定时任务] ${countdownText}${' '.repeat(10)}`);
663
- } else {
664
- process.stdout.write(`\r[定时任务] 将在 ${countdownText}${' '.repeat(5)}`);
660
+ if (countdownText === "即将执行") {
661
+ needWrite = false;
662
+ process.stdout.write(`\r[定时任务] ${countdownText}${' '.repeat(10)}`);
663
+ } else {
664
+ process.stdout.write(`\r[定时任务] 将在 ${countdownText}${' '.repeat(5)}`);
665
665
  }
666
666
  lastCountdownText = countdownText;
667
667
  }
@@ -671,20 +671,20 @@ function initScheduledTask() {
671
671
  if (currentSecond === 0) {
672
672
  if (currentHour === scheduledExecutionTime.hour && currentMinute === scheduledExecutionTime.minute) {
673
673
  // 检查今天是否已经执行过
674
- if (lastExecutionDate !== currentDate) {
674
+ if (lastExecutionDate !== currentDate) {
675
675
  // 换行后输出触发信息
676
676
  console.log('');
677
677
  logger.success(
678
678
  `[定时任务] 触发执行 - 当前时间: ${currentHour}:${currentMinute.toString().padStart(2, '0')}`
679
679
  );
680
- lastExecutionDate = currentDate;
680
+ lastExecutionDate = currentDate;
681
681
 
682
682
  // 异步执行任务,使用try-catch确保异常不会影响定时器
683
683
  executeDeployTask().catch(error => {
684
684
  logger.error('[定时任务] 执行失败:', error);
685
- }).finally(()=> {
686
- needWrite = true;
687
- lastCountdownText = "";
685
+ }).finally(() => {
686
+ needWrite = true;
687
+ lastCountdownText = "";
688
688
  })
689
689
  }
690
690
  }