mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
system check & setting_secret
This commit is contained in:
1 parent
c52ddd7512
commit
57f711ed4f
18 files changed
+295
-134
No files matched your search
@@ -132,8 +132,12 @@ class HomeSecurityHandler extends Handler {
|
||||
);
|
||||
}
|
||||
}
|
||||
const path = [
|
||||
['Hydro', 'homepage'],
|
||||
['home_security', null],
|
||||
];
|
||||
this.response.template = 'home_security.html';
|
||||
this.response.body = { sessions, geoipProvider: (geoip || {}).provider };
|
||||
this.response.body = { sessions, geoipProvider: (geoip || {}).provider, path };
|
||||
if (useragent) this.response.body.icon = useragent.icon;
|
||||
}
|
||||
|
||||
@@ -202,7 +206,7 @@ class HomeSettingsHandler extends Handler {
|
||||
async post(args) {
|
||||
const $set = {};
|
||||
for (const key in args) {
|
||||
if (setting.SETTINGS_BY_KEY[key]) {
|
||||
if (setting.SETTINGS_BY_KEY[key] && !setting.SETTINGS_BY_KEY[key].disabled) {
|
||||
$set[key] = args[key];
|
||||
}
|
||||
}
|
||||
|
||||
+27
-5
@@ -3,9 +3,12 @@ const system = require('../model/system');
|
||||
const { STATUS, PRIV } = require('../model/builtin');
|
||||
const record = require('../model/record');
|
||||
const judge = require('./judge');
|
||||
const { Route, Handler } = require('../service/server');
|
||||
const {
|
||||
Route, Connection, Handler, ConnectionHandler,
|
||||
} = require('../service/server');
|
||||
const hpm = require('../lib/hpm');
|
||||
const loader = require('../loader');
|
||||
const check = require('../check');
|
||||
|
||||
class SystemHandler extends Handler {
|
||||
async prepare() {
|
||||
@@ -24,6 +27,24 @@ class SystemMainHandler extends SystemHandler {
|
||||
}
|
||||
}
|
||||
|
||||
class SystemCheckConnHandler extends ConnectionHandler {
|
||||
async prepare() {
|
||||
this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
||||
await this.check();
|
||||
}
|
||||
|
||||
async check() {
|
||||
const log = (payload) => this.send({ type: 'log', payload });
|
||||
const warn = (payload) => this.send({ type: 'warn', payload });
|
||||
const error = (payload) => this.send({ type: 'error', payload });
|
||||
await check.start(log, warn, error, (id) => { this.id = id; });
|
||||
}
|
||||
|
||||
async cleanup() {
|
||||
check.cancel(this.token);
|
||||
}
|
||||
}
|
||||
|
||||
class SystemDashboardHandler extends SystemHandler {
|
||||
async get() {
|
||||
this.response.template = 'manage_dashboard.html';
|
||||
@@ -111,8 +132,8 @@ class SystemScriptHandler extends SystemHandler {
|
||||
|
||||
class SystemSettingHandler extends SystemHandler {
|
||||
async get() {
|
||||
this.response.template = 'manage_settings.html';
|
||||
this.response.body.path.push(['manage_settings', null]);
|
||||
this.response.template = 'manage_setting.html';
|
||||
this.response.body.path.push(['manage_setting', null]);
|
||||
this.response.body.current = {};
|
||||
this.response.body.settings = setting.SYSTEM_SETTINGS;
|
||||
for (const s of this.response.body.settings) {
|
||||
@@ -129,7 +150,7 @@ class SystemSettingHandler extends SystemHandler {
|
||||
const subtasks = [];
|
||||
for (const sub in args[key]) {
|
||||
const s = setting.SYSTEM_SETTINGS_BY_KEY[`${key}.${sub}`];
|
||||
if (s) {
|
||||
if (s && !((s.flag & setting.FLAG_SECRET) && args[key][sub] === '')) {
|
||||
if (s.ui === 'number') args[key][sub] = Number(args[key][sub]);
|
||||
subtasks.push(system.set(`${key}.${sub}`, args[key][sub]));
|
||||
}
|
||||
@@ -137,7 +158,7 @@ class SystemSettingHandler extends SystemHandler {
|
||||
tasks.push(Promise.all(subtasks));
|
||||
} else {
|
||||
const s = setting.SYSTEM_SETTINGS_BY_KEY[key];
|
||||
if (s) {
|
||||
if (s && !((s.flag & setting.FLAG_SECRET) && args[key] === '')) {
|
||||
if (s.ui === 'number') args[key] = Number(args[key]);
|
||||
tasks.push(system.set(key, args[key]));
|
||||
}
|
||||
@@ -154,6 +175,7 @@ async function apply() {
|
||||
Route('manage_script', '/manage/script', SystemScriptHandler);
|
||||
Route('manage_module', '/manage/module', SystemModuleHandler);
|
||||
Route('manage_setting', '/manage/setting', SystemSettingHandler);
|
||||
Connection('manage_check', '/manage/check-conn', SystemCheckConnHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.manage = module.exports = apply;
|
||||
@@ -1,10 +1,16 @@
|
||||
/* eslint-disable no-empty-function */
|
||||
/* eslint-disable class-methods-use-this */
|
||||
const { Route, Handler } = require('../service/server');
|
||||
const { NotFoundError } = require('../error');
|
||||
|
||||
class NotFoundHandler extends Handler {
|
||||
async prepare() { // eslint-disable-line class-methods-use-this
|
||||
async prepare() {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
||||
async get() { }
|
||||
|
||||
async post() { }
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
|
||||
Reference in new issue
Block a user