mirror of https://github.com/certd/certd
perf: 支持重置管理员密码,忘记密码的补救方案
parent
5d2d0955b1
commit
732cbc5e92
28
README.md
28
README.md
|
@ -6,7 +6,7 @@ CertD 是一个免费全自动申请和部署SSL证书的工具。
|
|||
## 一、特性
|
||||
本项目不仅支持证书申请过程自动化,还可以自动化部署证书,让你的证书永不过期。
|
||||
|
||||
* 全自动申请证书(支持阿里云、腾讯云、华为云注册的域名)
|
||||
* 全自动申请证书(支持阿里云、腾讯云、华为云、Cloudflare注册的域名)
|
||||
* 全自动部署证书(目前支持服务器上传部署、部署到阿里云、腾讯云等)
|
||||
* 支持通配符域名
|
||||
* 支持多个域名打到一个证书上
|
||||
|
@ -101,8 +101,9 @@ http://your_server_ip:7001
|
|||
* 数据存在`/data/certd`目录下,不用担心数据丢失
|
||||
|
||||
|
||||
## 五、一些说明
|
||||
|
||||
## 五、一些说明及问题处理
|
||||
### 1. 一些说明
|
||||
* 本项目ssl证书提供商为letencrypt
|
||||
* 申请过程遵循acme协议
|
||||
* 需要验证域名所有权,一般有两种方式(目前本项目仅支持dns-01)
|
||||
|
@ -114,6 +115,29 @@ http://your_server_ip:7001
|
|||
* 免费证书过期时间90天,以后可能还会缩短,所以自动化部署必不可少
|
||||
* 设置每天自动运行,当证书过期前20天,会自动重新申请证书并部署
|
||||
|
||||
### 2. 问题处理
|
||||
#### 2.1 忘记管理员密码
|
||||
解决方法如下:
|
||||
1. 修改docker-compose.yaml文件,将环境变量`certd_system_resetAdminPassword`改为`true`
|
||||
```yaml
|
||||
services:
|
||||
certd:
|
||||
environment: # 环境变量
|
||||
- certd_system_resetAdminPassword=false
|
||||
```
|
||||
2. 重启容器
|
||||
```shell
|
||||
docker compose up -d
|
||||
docker logs -f --tail 500 certd
|
||||
# 观察日志,当日志中输出“重置1号管理员用户的密码完成”,即可操作下一步
|
||||
```
|
||||
3. 修改docker-compose.yaml,将`certd_system_resetAdminPassword`改回`false`
|
||||
4. 再次重启容器
|
||||
```shell
|
||||
docker compose up -d
|
||||
```
|
||||
5. 使用admin/123456登录系统,请及时修改管理员密码
|
||||
|
||||
## 六、联系作者
|
||||
如有疑问,欢迎加入群聊(请备注certd)
|
||||
* QQ群:141236433
|
||||
|
|
|
@ -15,6 +15,8 @@ services:
|
|||
- TZ=Asia/Shanghai
|
||||
- certd_auth_jwt_secret=changeme
|
||||
# ↑↑↑↑↑ ---------------------------------- 3、 修改成你的自定义密钥【必须,安全需要】
|
||||
- certd_system_resetAdminPassword=false
|
||||
# ↑↑↑↑↑ 如果忘记管理员密码,可以设置为true,重启之后,管理员密码将改成123456,然后请及时修改回false
|
||||
# 设置环境变量即可自定义certd配置
|
||||
# 服务端配置项见: packages/ui/certd-server/src/config/config.default.ts
|
||||
# 服务端配置规则: certd_ + 配置项, 点号用_代替
|
||||
|
|
|
@ -2,17 +2,18 @@
|
|||
const WebFramework = require('@midwayjs/koa').Framework;
|
||||
const { Bootstrap } = require('@midwayjs/bootstrap');
|
||||
|
||||
const DirectoryFileDetector = require( "@midwayjs/core").DirectoryFileDetector;
|
||||
|
||||
const baseDir = process.cwd()
|
||||
const pipelineDir = baseDir +"./node_modules/@certd/pipeline"
|
||||
const customFileDetector = new DirectoryFileDetector({loadDir:[baseDir,pipelineDir]})
|
||||
const DirectoryFileDetector = require('@midwayjs/core').DirectoryFileDetector;
|
||||
|
||||
const baseDir = process.cwd();
|
||||
const pipelineDir = baseDir + './node_modules/@certd/pipeline';
|
||||
const customFileDetector = new DirectoryFileDetector({
|
||||
loadDir: [baseDir, pipelineDir],
|
||||
});
|
||||
|
||||
module.exports = async () => {
|
||||
// 加载框架并执行
|
||||
await Bootstrap.configure({
|
||||
moduleDetector:customFileDetector
|
||||
moduleDetector: customFileDetector,
|
||||
}).run();
|
||||
// 获取依赖注入容器
|
||||
const container = Bootstrap.getApplicationContext();
|
||||
|
|
|
@ -78,6 +78,9 @@ const development = {
|
|||
certd: {
|
||||
fileRootDir: '/app/data/files',
|
||||
},
|
||||
system: {
|
||||
resetAdminPasswd: false,
|
||||
},
|
||||
} as MidwayConfig;
|
||||
mergeConfig(development, 'development');
|
||||
export default development;
|
||||
|
|
|
@ -16,6 +16,7 @@ import { AuthorityMiddleware } from './middleware/authority';
|
|||
import * as staticFile from '@midwayjs/static-file';
|
||||
import * as cron from './modules/plugin/cron';
|
||||
import { logger } from './utils/logger';
|
||||
import { ResetPasswdMiddleware } from './middleware/reset-passwd/middleware';
|
||||
@Configuration({
|
||||
imports: [koa, orm, cache, flyway, validateComp, cron, staticFile],
|
||||
importConfigs: [
|
||||
|
@ -53,6 +54,9 @@ export class ContainerLifeCycle {
|
|||
PreviewMiddleware,
|
||||
//授权处理
|
||||
AuthorityMiddleware,
|
||||
|
||||
//resetPasswd,重置密码模式下不提供服务
|
||||
ResetPasswdMiddleware,
|
||||
]);
|
||||
|
||||
logger.info('当前环境:', this.app.getEnv()); // prod
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import { Config, Provide } from '@midwayjs/decorator';
|
||||
import {
|
||||
IMidwayKoaContext,
|
||||
NextFunction,
|
||||
IWebMiddleware,
|
||||
} from '@midwayjs/koa';
|
||||
import { IMidwayKoaContext, NextFunction, IWebMiddleware } from '@midwayjs/koa';
|
||||
import { PreviewException } from '../basic/exception/preview-exception';
|
||||
|
||||
/**
|
||||
|
@ -20,6 +16,7 @@ export class PreviewMiddleware implements IWebMiddleware {
|
|||
await next();
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
let { url, request } = ctx;
|
||||
const body: any = request.body;
|
||||
let id = body.id || request.query.id;
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
import {
|
||||
Autoload,
|
||||
Config,
|
||||
Init,
|
||||
Inject,
|
||||
Provide,
|
||||
Scope,
|
||||
ScopeEnum,
|
||||
} from '@midwayjs/decorator';
|
||||
import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
|
||||
import { CommonException } from '../../basic/exception/common-exception';
|
||||
import { UserService } from '../../modules/authority/service/user-service';
|
||||
import { logger } from '../../utils/logger';
|
||||
|
||||
/**
|
||||
* 重置密码模式
|
||||
*/
|
||||
@Provide()
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
export class ResetPasswdMiddleware implements IWebMiddleware {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
@Config('system.resetAdminPasswd')
|
||||
private resetAdminPasswd: boolean;
|
||||
resolve() {
|
||||
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
if (this.resetAdminPasswd === true) {
|
||||
throw new CommonException(
|
||||
'1号管理员密码已修改为123456,当前为重置密码模式,无法响应请求,请关闭重置密码模式恢复正常服务'
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Init()
|
||||
async init() {
|
||||
if (this.resetAdminPasswd === true) {
|
||||
logger.info('开始重置1号管理员用户的密码');
|
||||
const newPasswd = '123456';
|
||||
await this.userService.resetPassword(1, newPasswd);
|
||||
logger.info(`重置1号管理员用户的密码完成,新密码为:${newPasswd}`);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -155,4 +155,12 @@ export class UserService extends BaseService<UserEntity> {
|
|||
|
||||
await this.update(param);
|
||||
}
|
||||
|
||||
async resetPassword(userId: any, newPasswd: string) {
|
||||
const param = {
|
||||
id: userId,
|
||||
password: newPasswd,
|
||||
};
|
||||
await this.update(param);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue