✨ 支持老版本通知服务升级
This commit is contained in:
parent
e92e2beb4d
commit
f21da41d6d
@ -26,7 +26,7 @@ const login = async ({ res, request }) => {
|
|||||||
if (loginErrCount >= allowErrCount) {
|
if (loginErrCount >= allowErrCount) {
|
||||||
const { ip, country, city } = await getNetIPInfo(clientIp)
|
const { ip, country, city } = await getNetIPInfo(clientIp)
|
||||||
// 异步发送通知&禁止登录
|
// 异步发送通知&禁止登录
|
||||||
asyncSendNotice('err_login', '登录错误提醒', `错误登录次数: ${ loginErrTotal }<br/>地点:${ country + city }<br/>IP: ${ ip }`)
|
asyncSendNotice('err_login', '登录错误提醒', `错误登录次数: ${ loginErrTotal }\n地点:${ country + city }\nIP: ${ ip }`)
|
||||||
forbidLogin = true
|
forbidLogin = true
|
||||||
loginErrCount = 0
|
loginErrCount = 0
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ const beforeLoginHandler = async (clientIp, jwtExpires) => {
|
|||||||
consola.info('登录成功:', new Date(), { ip, country, city })
|
consola.info('登录成功:', new Date(), { ip, country, city })
|
||||||
|
|
||||||
// 邮件登录通知
|
// 邮件登录通知
|
||||||
asyncSendNotice('login', '登录提醒', `地点:${ country + city }<br/>IP: ${ ip }`)
|
asyncSendNotice('login', '登录提醒', `地点:${ country + city }\nIP: ${ ip }`)
|
||||||
|
|
||||||
global.loginRecord.unshift(clientIPInfo)
|
global.loginRecord.unshift(clientIPInfo)
|
||||||
if (global.loginRecord.length > 10) global.loginRecord = global.loginRecord.slice(0, 10)
|
if (global.loginRecord.length > 10) global.loginRecord = global.loginRecord.slice(0, 10)
|
||||||
@ -102,7 +102,7 @@ const updatePwd = async ({ res, request }) => {
|
|||||||
keyObj.pwd = newPwd
|
keyObj.pwd = newPwd
|
||||||
await writeKey(keyObj)
|
await writeKey(keyObj)
|
||||||
|
|
||||||
asyncSendNotice('updatePwd', '用户密码修改提醒', `原用户名:${ user }<br/>更新用户名: ${ newLoginName }`)
|
asyncSendNotice('updatePwd', '用户密码修改提醒', `原用户名:${ user }\n更新用户名: ${ newLoginName }`)
|
||||||
|
|
||||||
res.success({ data: true, msg: 'success' })
|
res.success({ data: true, msg: 'success' })
|
||||||
}
|
}
|
||||||
|
@ -48,41 +48,47 @@ function initGroupDB() {
|
|||||||
function initNotifyDB() {
|
function initNotifyDB() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const notifyDB = new NotifyDB().getInstance()
|
const notifyDB = new NotifyDB().getInstance()
|
||||||
notifyDB.count({}, async (err, count) => {
|
notifyDB.find({}, async (err, notifyList) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
consola.log('初始化notifyDB错误:', err)
|
consola.log('初始化notifyDB错误:', err)
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
if (count === 0) {
|
let defaultData = [{
|
||||||
|
'type': 'login',
|
||||||
|
'desc': '登录面板提醒',
|
||||||
|
'sw': false
|
||||||
|
}, {
|
||||||
|
'type': 'err_login',
|
||||||
|
'desc': '登录错误提醒(连续5次)',
|
||||||
|
'sw': false
|
||||||
|
}, {
|
||||||
|
'type': 'updatePwd',
|
||||||
|
'desc': '修改密码提醒',
|
||||||
|
'sw': false
|
||||||
|
}, {
|
||||||
|
'type': 'host_login',
|
||||||
|
'desc': '服务器登录提醒',
|
||||||
|
'sw': false
|
||||||
|
}, {
|
||||||
|
'type': 'onekey_complete',
|
||||||
|
'desc': '批量指令执行完成提醒',
|
||||||
|
'sw': false
|
||||||
|
}, {
|
||||||
|
'type': 'host_expired',
|
||||||
|
'desc': '服务器到期提醒',
|
||||||
|
'sw': false
|
||||||
|
}]
|
||||||
|
if (notifyList.length === 0) {
|
||||||
consola.log('初始化notifyDB✔')
|
consola.log('初始化notifyDB✔')
|
||||||
const defaultData = [{
|
} else {
|
||||||
'type': 'login',
|
consola.log('同步notifyDB✔')
|
||||||
'desc': '登录面板提醒',
|
defaultData = defaultData.map(defaultItem => {
|
||||||
'sw': true
|
let item = notifyList.find(notify => notify.type === defaultItem.type)
|
||||||
}, {
|
defaultItem.sw = item ? item.sw : false
|
||||||
'type': 'err_login',
|
return item
|
||||||
'desc': '登录错误提醒(连续5次)',
|
})
|
||||||
'sw': true
|
|
||||||
}, {
|
|
||||||
'type': 'updatePwd',
|
|
||||||
'desc': '修改密码提醒',
|
|
||||||
'sw': true
|
|
||||||
}, {
|
|
||||||
'type': 'host_login',
|
|
||||||
'desc': '服务器登录提醒',
|
|
||||||
'sw': true
|
|
||||||
}, {
|
|
||||||
'type': 'onekey_complete',
|
|
||||||
'desc': '批量指令执行完成提醒',
|
|
||||||
'sw': true
|
|
||||||
}, {
|
|
||||||
'type': 'host_expired',
|
|
||||||
'desc': '服务器到期提醒',
|
|
||||||
'sw': true
|
|
||||||
} ]
|
|
||||||
await writeNotifyList(defaultData)
|
|
||||||
}
|
}
|
||||||
|
await writeNotifyList(defaultData)
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
|
@ -11,15 +11,15 @@ const expiredNotifyJob = async () => {
|
|||||||
const restDay = Number(((expired - Date.now()) / (1000 * 60 * 60 * 24)).toFixed(1))
|
const restDay = Number(((expired - Date.now()) / (1000 * 60 * 60 * 24)).toFixed(1))
|
||||||
console.log(Date.now(), restDay)
|
console.log(Date.now(), restDay)
|
||||||
let title = '服务器到期提醒'
|
let title = '服务器到期提醒'
|
||||||
let content = `别名: ${ name }<br/>IP: ${ host }<br/>到期时间:${ formatTimestamp(expired, 'week') }<br/>控制台: ${ consoleUrl || '未填写' }`
|
let content = `别名: ${ name }\nIP: ${ host }\n到期时间:${ formatTimestamp(expired, 'week') }\n控制台: ${ consoleUrl || '未填写' }`
|
||||||
if(0 <= restDay && restDay <= 1) {
|
if(0 <= restDay && restDay <= 1) {
|
||||||
let temp = '有服务器将在一天后到期,请关注<br/>'
|
let temp = '有服务器将在一天后到期,请关注\n'
|
||||||
asyncSendNotice('host_expired', title, temp + content)
|
asyncSendNotice('host_expired', title, temp + content)
|
||||||
}else if(3 <= restDay && restDay < 4) {
|
}else if(3 <= restDay && restDay < 4) {
|
||||||
let temp = '有服务器将在三天后到期,请关注<br/>'
|
let temp = '有服务器将在三天后到期,请关注\n'
|
||||||
asyncSendNotice('host_expired', title, temp + content)
|
asyncSendNotice('host_expired', title, temp + content)
|
||||||
}else if(7 <= restDay && restDay < 8) {
|
}else if(7 <= restDay && restDay < 8) {
|
||||||
let temp = '有服务器将在七天后到期,请关注<br/>'
|
let temp = '有服务器将在七天后到期,请关注\n'
|
||||||
asyncSendNotice('host_expired', title, temp + content)
|
asyncSendNotice('host_expired', title, temp + content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,12 +57,13 @@ function sendEmail({ service, user, pass }, title, content) {
|
|||||||
async function asyncSendNotice(noticeAction, title, content) {
|
async function asyncSendNotice(noticeAction, title, content) {
|
||||||
try {
|
try {
|
||||||
let sw = await getNotifySwByType(noticeAction) // 获取对应动作的通知开关
|
let sw = await getNotifySwByType(noticeAction) // 获取对应动作的通知开关
|
||||||
|
console.log(noticeAction, sw)
|
||||||
if (!sw) return
|
if (!sw) return
|
||||||
let notifyConfig = await readNotifyConfig()
|
let notifyConfig = await readNotifyConfig()
|
||||||
let { type } = notifyConfig
|
let { type } = notifyConfig
|
||||||
if (!type) return consola.error('通知类型不存在: ', type)
|
if (!type) return consola.error('通知类型不存在: ', type)
|
||||||
title = `EasyNode-${ title }`
|
title = `EasyNode-${ title }`
|
||||||
content += `<br/>通知发送时间:${ new Date() }`
|
content += `\n通知发送时间:${ new Date() }`
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'sct':
|
case 'sct':
|
||||||
let { sendKey } = notifyConfig['sct']
|
let { sendKey } = notifyConfig['sct']
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<!-- <el-alert type="success" :closable="false">
|
<el-alert type="success" :closable="false">
|
||||||
<template #title>
|
<template #title>
|
||||||
<span style="letter-spacing: 2px;"> 请添加邮箱并确保测试邮件通过 </span>
|
<span style="letter-spacing: 2px;"> 请确保[通知配置]中的通知方式能够正常收到测试通知 </span>
|
||||||
</template>
|
</template>
|
||||||
</el-alert> -->
|
</el-alert>
|
||||||
<!--
|
|
||||||
{"type":"login","desc":"登录面板提醒","sw":true,"_id":"jxbeElEds9virx4m"}
|
|
||||||
{"type":"updatePwd","desc":"修改密码提醒","sw":true,"_id":"uPa6imN4pKnAIgMW"}
|
|
||||||
{"type":"err_login","desc":"登录错误提醒(连续5次)","sw":true,"_id":"wARAnQXturdZHdWK"}
|
|
||||||
-->
|
|
||||||
<el-table v-loading="notifyListLoading" :data="notifyList">
|
<el-table v-loading="notifyListLoading" :data="notifyList">
|
||||||
<el-table-column prop="desc" label="通知类型" />
|
<el-table-column prop="desc" label="通知类型" />
|
||||||
<el-table-column prop="sw" label="开关">
|
<el-table-column prop="sw" label="开关">
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
label-suffix=":"
|
label-suffix=":"
|
||||||
>
|
>
|
||||||
<el-form-item label="通知方式" prop="type" class="form_item">
|
<el-form-item label="通知方式" prop="type" class="form_item">
|
||||||
<el-select v-model="noticeConfig.type" placeholder="">
|
<el-select v-model="noticeConfig.type" placeholder="" class="input">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in noticeTypeList"
|
v-for="item in noticeTypeList"
|
||||||
:key="item.type"
|
:key="item.type"
|
||||||
@ -25,6 +25,7 @@
|
|||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<!-- server酱 -->
|
||||||
<template v-if="noticeConfig.type === 'sct'">
|
<template v-if="noticeConfig.type === 'sct'">
|
||||||
<el-form-item label="SendKey" prop="sct.sendKey" class="form_item">
|
<el-form-item label="SendKey" prop="sct.sendKey" class="form_item">
|
||||||
<el-input
|
<el-input
|
||||||
@ -32,9 +33,12 @@
|
|||||||
clearable
|
clearable
|
||||||
placeholder="SCT******"
|
placeholder="SCT******"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
class="input"
|
||||||
/>
|
/>
|
||||||
|
<p class="tips">普通用户每日最多支持5条,有条件建议开通会员服务防止丢失重要通知。<a class="link" href="https://sct.ftqq.com/r/9338" target="_blank">Server酱官网</a> </p>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
|
<!-- 邮箱 -->
|
||||||
<template v-if="noticeConfig.type === 'email'">
|
<template v-if="noticeConfig.type === 'email'">
|
||||||
<el-form-item label="服务商" prop="email.service" class="form_item">
|
<el-form-item label="服务商" prop="email.service" class="form_item">
|
||||||
<el-input
|
<el-input
|
||||||
@ -42,8 +46,9 @@
|
|||||||
clearable
|
clearable
|
||||||
placeholder=""
|
placeholder=""
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
class="input"
|
||||||
/>
|
/>
|
||||||
<span class="tips">邮箱服务商, 例如: Gmial、qq、126、163, 支持列表: <a class="link" href="https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json" target="_blank">点击查询</a> </span>
|
<span class="tips">邮箱服务商, 例如: QQ、126、163、Gmial, 支持列表: <a class="link" href="https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json" target="_blank">点击查询</a> </span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="邮箱地址" prop="email.user" class="form_item">
|
<el-form-item label="邮箱地址" prop="email.user" class="form_item">
|
||||||
<el-input
|
<el-input
|
||||||
@ -51,6 +56,7 @@
|
|||||||
clearable
|
clearable
|
||||||
placeholder="邮箱地址"
|
placeholder="邮箱地址"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
class="input"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="SMTP" prop="auth.pass" class="form_item">
|
<el-form-item label="SMTP" prop="auth.pass" class="form_item">
|
||||||
@ -59,6 +65,7 @@
|
|||||||
clearable
|
clearable
|
||||||
placeholder="SMTP授权码/密码"
|
placeholder="SMTP授权码/密码"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
class="input"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
@ -75,7 +82,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, onMounted, getCurrentInstance } from 'vue'
|
import { ref, reactive, onMounted, getCurrentInstance } from 'vue'
|
||||||
|
|
||||||
const { proxy: { $api, $message, $messageBox, $notification } } = getCurrentInstance()
|
const { proxy: { $api, $notification } } = getCurrentInstance()
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const noticeConfig = ref({})
|
const noticeConfig = ref({})
|
||||||
@ -134,10 +141,13 @@ onMounted(() => {
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.form_item {
|
.form_item {
|
||||||
width: 350px;
|
// width: 350px;
|
||||||
|
.input {
|
||||||
|
width: 450px;
|
||||||
|
}
|
||||||
.tips {
|
.tips {
|
||||||
font-size: 12px;
|
width: 100%;
|
||||||
|
font-size: 14px;
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user