mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: better blacklist
This commit is contained in:
1 parent
42f920d25c
commit
0676cc0a27
9 files changed
+21
-90
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.32.31",
|
"version": "2.32.32",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ async function cli() {
|
|||||||
args[i] = new ObjectID(args[i]);
|
args[i] = new ObjectID(args[i]);
|
||||||
} else if ((+args[i]).toString() === args[i]) {
|
} else if ((+args[i]).toString() === args[i]) {
|
||||||
args[i] = +args[i];
|
args[i] = +args[i];
|
||||||
|
} else if (args[i].startsWith('~')) {
|
||||||
|
args[i] = argv.options[args[i].substr(1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let result = global.Hydro.model[modelName][func](...args);
|
let result = global.Hydro.model[modelName][func](...args);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ async function _address(
|
|||||||
if (bset.has(ip)) return;
|
if (bset.has(ip)) return;
|
||||||
bset.add(ip);
|
bset.add(ip);
|
||||||
report({ message: `ip ${ip}` });
|
report({ message: `ip ${ip}` });
|
||||||
const users = await db.collection('user').find({ loginip: ip }).toArray();
|
const users = await db.collection('user').find({ $or: [{ loginip: ip }, { regip: ip }] }).toArray();
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
for (const udoc of users) {
|
for (const udoc of users) {
|
||||||
tasks.push(_user(udoc._id, bset, uset, dset, dryrun, report));
|
tasks.push(_user(udoc._id, bset, uset, dset, dryrun, report));
|
||||||
@@ -50,7 +50,7 @@ async function _user(
|
|||||||
const udoc = await user.getById('system', uid);
|
const udoc = await user.getById('system', uid);
|
||||||
if (!udoc) return;
|
if (!udoc) return;
|
||||||
report({ message: `user ${udoc._id} ${udoc.uname}` });
|
report({ message: `user ${udoc._id} ${udoc.uname}` });
|
||||||
await _address(udoc.loginip(), bset, uset, dset, dryrun, report);
|
await _address(udoc._loginip, bset, uset, dset, dryrun, report);
|
||||||
const ddocs = await db.collection('document').find({ docType: document.TYPE_DISCUSSION, owner: uid })
|
const ddocs = await db.collection('document').find({ docType: document.TYPE_DISCUSSION, owner: uid })
|
||||||
.sort({ domainId: 1, docId: 1 }).toArray();
|
.sort({ domainId: 1, docId: 1 }).toArray();
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
|
|||||||
@@ -1,91 +1,20 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
import { Udoc } from '../interface';
|
|
||||||
import { Value } from '../typeutils';
|
|
||||||
import user from '../model/user';
|
import user from '../model/user';
|
||||||
import * as document from '../model/document';
|
|
||||||
import * as setting from '../model/setting';
|
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
import paginate from '../lib/paginate';
|
import { PRIV } from '../model/builtin';
|
||||||
import { STATUS, PRIV } from '../model/builtin';
|
|
||||||
|
|
||||||
export const description = 'Delete a user';
|
export const description = 'Delete a user';
|
||||||
|
|
||||||
const collDocument = db.collection('document');
|
const collDocument = db.collection('document');
|
||||||
const collDomainUser = db.collection('domain.user');
|
const collDomainUser = db.collection('domain.user');
|
||||||
const collRecord = db.collection('record');
|
const collRecord = db.collection('record');
|
||||||
|
const collMessage = db.collection('message');
|
||||||
|
|
||||||
const $unset: Value<Partial<Udoc>> = {
|
export async function run({ uid }) {
|
||||||
regip: '', regat: '', loginat: '', loginip: '',
|
await collDocument.deleteMany({ owner: uid });
|
||||||
};
|
|
||||||
for (const s of setting.PREFERENCE_SETTINGS) {
|
|
||||||
$unset[s.key] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteRecord(uid: number) {
|
|
||||||
const [, pcount] = await paginate(
|
|
||||||
collRecord.find(),
|
|
||||||
1,
|
|
||||||
100,
|
|
||||||
);
|
|
||||||
for (let i = 1; i <= pcount; i++) {
|
|
||||||
const [rdocs] = await paginate(
|
|
||||||
collRecord.find(),
|
|
||||||
1,
|
|
||||||
100,
|
|
||||||
);
|
|
||||||
const tasks = [];
|
|
||||||
for (const rdoc of rdocs) {
|
|
||||||
if (rdoc.pid) {
|
|
||||||
tasks.push(document.inc(rdoc.domainId, document.TYPE_PROBLEM, rdoc.pid, 'nSubmit', -1));
|
|
||||||
}
|
|
||||||
if (rdoc.status === STATUS.STATUS_ACCEPTED) {
|
|
||||||
tasks.push(document.inc(rdoc.domainId, document.TYPE_PROBLEM, rdoc.pid, 'nAccept', -1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await Promise.all(tasks);
|
|
||||||
}
|
|
||||||
await collRecord.deleteMany({ uid });
|
await collRecord.deleteMany({ uid });
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteDiscussion(uid: number) {
|
|
||||||
const [, pcount] = await paginate(
|
|
||||||
collDocument.find({ docType: document.TYPE_DISCUSSION, owner: uid }),
|
|
||||||
1,
|
|
||||||
100,
|
|
||||||
);
|
|
||||||
for (let i = 1; i <= pcount; i++) {
|
|
||||||
const [ddocs] = await paginate(
|
|
||||||
collDocument.find({ docType: document.TYPE_DISCUSSION, owner: uid }),
|
|
||||||
1,
|
|
||||||
100,
|
|
||||||
);
|
|
||||||
const tasks = [];
|
|
||||||
for (const ddoc of ddocs) {
|
|
||||||
tasks.push(document.deleteMulti(ddoc.domainId, document.TYPE_DISCUSSION_REPLY, {
|
|
||||||
parentId: ddoc.docId,
|
|
||||||
parentType: document.TYPE_DISCUSSION,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
await Promise.all(tasks);
|
|
||||||
}
|
|
||||||
await collDocument.deleteMany({ docType: document.TYPE_DISCUSSION, owner: uid });
|
|
||||||
// TODO delete replies
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function run({
|
|
||||||
uid,
|
|
||||||
}) {
|
|
||||||
await deleteRecord(uid);
|
|
||||||
await deleteDiscussion(uid);
|
|
||||||
await collDomainUser.deleteMany({ uid });
|
await collDomainUser.deleteMany({ uid });
|
||||||
const uname = String.random(32);
|
await collMessage.deleteMany({ $or: [{ from: uid }, { to: uid }] });
|
||||||
await user.setById(uid, {
|
await user.setPriv(uid, PRIV.PRIV_NONE);
|
||||||
uname,
|
|
||||||
unameLower: uname.toLowerCase(),
|
|
||||||
priv: PRIV.PRIV_NONE,
|
|
||||||
}, $unset);
|
|
||||||
await user.setPassword(uid, String.random(32));
|
|
||||||
// TODO delete contest, homework, etc
|
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ export class HandlerCommon {
|
|||||||
|
|
||||||
translate(str: string) {
|
translate(str: string) {
|
||||||
if (!str) return '';
|
if (!str) return '';
|
||||||
return str.toString().translate(this.user.viewLang, this.session.viewLang, system.get('server.language'));
|
return str.toString().translate(this.user?.viewLang, this.session?.viewLang, system.get('server.language'));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTitle(str: string) {
|
renderTitle(str: string) {
|
||||||
@@ -333,8 +333,8 @@ export class HandlerCommon {
|
|||||||
async renderHTML(name: string, context: any): Promise<string> {
|
async renderHTML(name: string, context: any): Promise<string> {
|
||||||
const UserContext: any = {
|
const UserContext: any = {
|
||||||
...this.user,
|
...this.user,
|
||||||
avatar: avatar(this.user.avatar || '', 128),
|
avatar: avatar(this.user?.avatar || '', 128),
|
||||||
perm: this.user.perm.toString(),
|
perm: this.user?.perm?.toString(),
|
||||||
viewLang: this.translate('__id'),
|
viewLang: this.translate('__id'),
|
||||||
};
|
};
|
||||||
if (!global.Hydro.lib.template) return JSON.stringify(context, serializer);
|
if (!global.Hydro.lib.template) return JSON.stringify(context, serializer);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ const replacer = (k, v) => {
|
|||||||
class Nunjucks extends nunjucks.Environment {
|
class Nunjucks extends nunjucks.Environment {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(new Loader(), { autoescape: true, trimBlocks: true });
|
super(new Loader(), { autoescape: true, trimBlocks: true });
|
||||||
this.addFilter('json', (self) => JSON.stringify(self, replacer));
|
this.addFilter('json', (self) => (self ? JSON.stringify(self, replacer) : ''));
|
||||||
this.addFilter('parseYaml', (self) => yaml.load(self));
|
this.addFilter('parseYaml', (self) => yaml.load(self));
|
||||||
this.addFilter('dumpYaml', (self) => yaml.dump(self));
|
this.addFilter('dumpYaml', (self) => yaml.dump(self));
|
||||||
this.addFilter('serialize', (self, ignoreFunction = true) => serialize(self, { ignoreFunction }));
|
this.addFilter('serialize', (self, ignoreFunction = true) => serialize(self, { ignoreFunction }));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.17.6",
|
"version": "4.17.7",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{% set layout_name = "basic" %}
|
{% set layout_name = "basic" %}
|
||||||
{% extends "layout/html5.html" %}
|
{% extends "layout/html5.html" %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% include "partials/nav.html" %}
|
{% if UserContext %}{% include "partials/nav.html" %}{% endif %}
|
||||||
<div class="slideout-panel" id="panel">
|
<div class="slideout-panel" id="panel">
|
||||||
<div class="slideout-overlay"></div>
|
<div class="slideout-overlay"></div>
|
||||||
{% include "partials/header_mobile.html" %}
|
{% if UserContext %}{% include "partials/header_mobile.html" %}{% endif %}
|
||||||
<div class="main">
|
<div class="main">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% include "partials/footer.html" %}
|
{% include "partials/footer.html" %}
|
||||||
</div>
|
</div>
|
||||||
{% include "partials/login_dialog.html" %}
|
{% if UserContext %}{% include "partials/login_dialog.html" %}{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -25,9 +25,9 @@
|
|||||||
<meta property="og:image" content="{{ static_url('favicon-96x96.png') }}" />
|
<meta property="og:image" content="{{ static_url('favicon-96x96.png') }}" />
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% if not isIE(handler.request.headers['user-agent']) %}
|
{% if not isIE(handler.request.headers['user-agent']) %}
|
||||||
<script src="{{ static_url(handler.user.theme|default('default') + '.theme.js') }}"></script>
|
<script src="{{ static_url((handler.user|default({})).theme|default('default') + '.theme.js') }}"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<link rel="stylesheet" media="all" href="{{ static_url(handler.user.theme|default('default') + '.theme.css') }}">
|
<link rel="stylesheet" media="all" href="{{ static_url((handler.user|default({})).theme|default('default') + '.theme.css') }}">
|
||||||
<link rel="stylesheet" media="all" href="{{ url('ui_extracss') }}">
|
<link rel="stylesheet" media="all" href="{{ url('ui_extracss') }}">
|
||||||
<title>{{ handler.renderTitle(page_name) }}</title>
|
<title>{{ handler.renderTitle(page_name) }}</title>
|
||||||
{% if not isIE(handler.request.headers['user-agent']) %}
|
{% if not isIE(handler.request.headers['user-agent']) %}
|
||||||
|
|||||||
Reference in new issue
Block a user