-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
322 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,7 @@ show tables; | |
* WOLF_CRYPT_KEY 加密应用Secret及OAuth2登陆用户ID使用的Key. | ||
* RBAC_TOKEN_EXPIRE_TIME `Agent` 登录接口返回的token的有效期, 默认为30天. 单位为秒. | ||
* CONSOLE_TOKEN_EXPIRE_TIME `Console` 登录接口返回的token的有效期, 默认为30天. 单位为秒. | ||
* CONSOLE_LOGIN_WITH_CAPTCHA 控制 `Console` 登录是否使用 Captcha 验证码。如果控制台部署在公网上,建议开启该功能以提高安全性。该环境变量的取值为 yes 或 no,默认为 no。 | ||
* RBAC_SQL_URL 连接数据库的数据库链接. 默认为: `postgres://wolfroot:[email protected]:5432/wolf` | ||
* RBAC_REDIS_URL redis缓存的链接. 默认为: `redis://127.0.0.1:6379/0` | ||
* MEM_CACHE_BY_REDIS 使用redis作为对象缓存. 默认为`no`. 当要部署多节点的`wolf`服务时,可使用redis作为对象缓存,解决缓存不一致问题. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,8 @@ The output should be similar to the following, indicating that the database tabl | |
* `RBAC_TOKEN_KEY`: A key used to encrypt the user token. It is highly recommended to set this value. | ||
* `WOLF_CRYPT_KEY`: A key used to encrypt the application secret and OAuth2 login user ID keys. | ||
* `RBAC_TOKEN_EXPIRE_TIME`: The expiration time of the token returned by the `Agent` login interface. The default is 30 days and the unit is seconds. | ||
* `CONSOLE_TOKEN_EXPIRE_TIME`: The expiration time of the token returned by the Console login interface. The default is 30 days and the unit is seconds. | ||
* `CONSOLE_TOKEN_EXPIRE_TIME`: The expiration time of the token returned by the `Console` login interface. The default is 30 days and the unit is seconds. | ||
* `CONSOLE_LOGIN_WITH_CAPTCHA`: Controls whether Captcha verification is used for `Console` login. If the console is deployed on a public network, it is recommended to enable this feature to improve security. The environment variable can be set to `yes` or `no`, with a default value of `no`. | ||
* `RBAC_SQL_URL`: The link to the database. The default value is `postgres://wolfroot:[email protected]:5432/wolf`. | ||
* `RBAC_REDIS_URL`: The link to the redis cache. The default value is `redis://127.0.0.1:6379/0`. | ||
* `MEM_CACHE_BY_REDIS`: Use redis as the object cache. The default is no. When deploying a multi-node wolf service, you can use redis as the object cache to resolve cache inconsistency issues. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const util = require('../util/util') | ||
const {newCaptcha} = require('../util/captcha-util'); | ||
|
||
const BasicService = require('./basic-service') | ||
|
||
|
||
class Captcha extends BasicService { | ||
constructor(ctx) { | ||
super(ctx, null) | ||
} | ||
|
||
async get() { | ||
this.checkMethod('GET') | ||
const {cid, data: captchaData} = await newCaptcha(); | ||
const data = { | ||
"cid": cid, | ||
"captcha": captchaData, | ||
} | ||
this.success(data); | ||
} | ||
|
||
} | ||
|
||
module.exports = Captcha | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
const config = require('../../conf/config') | ||
const svgCaptcha = require('svg-captcha') | ||
const log4js = require('./log4js') | ||
const {redisClient} = require('./redis-util') | ||
const util = require('./util') | ||
|
||
const ERR_CAPTCHA_INVALID = 'ERR_CAPTCHA_INVALID' | ||
|
||
function captchaKey(cid) { | ||
return `cha:${cid}` | ||
} | ||
|
||
|
||
async function newCaptcha() { | ||
const newCaptcha = svgCaptcha.create({ | ||
size: 4, | ||
fontSize: 45, | ||
noise: Math.floor(Math.random() * 4) + 1, | ||
ignoreChars: '0o1i', | ||
width: 120, | ||
height: 40, | ||
color: true, | ||
background: '#ccc', | ||
}) | ||
const text = newCaptcha.text; | ||
const cid = util.randomString(20); | ||
const key = captchaKey(cid); | ||
const expiresIn = 60 * 5; | ||
const res = await redisClient.set(key, text, 'EX', expiresIn); | ||
if (res !== 'OK') { | ||
throw new Error('redis set error'); | ||
} | ||
const data = newCaptcha.data; | ||
return {cid, data} | ||
} | ||
|
||
async function captchaValidate(cid, text) { | ||
const key = captchaKey(cid); | ||
const captchaText = await redisClient.get(key); | ||
if (!captchaText) { | ||
log4js.log("captcha {cid: %s} not found", cid); | ||
return {valid: false, errmsg: ERR_CAPTCHA_INVALID} | ||
} | ||
if (captchaText != text) { | ||
return {valid: false, errmsg: ERR_CAPTCHA_INVALID} | ||
} | ||
return {valid: true, errmsg: ''} | ||
} | ||
|
||
|
||
exports.newCaptcha = newCaptcha | ||
exports.captchaValidate = captchaValidate |
Oops, something went wrong.