mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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",
|
||||
"version": "2.32.31",
|
||||
"version": "2.32.32",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -71,6 +71,8 @@ async function cli() {
|
||||
args[i] = new ObjectID(args[i]);
|
||||
} else if ((+args[i]).toString() === 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);
|
||||
|
||||
@@ -16,7 +16,7 @@ async function _address(
|
||||
if (bset.has(ip)) return;
|
||||
bset.add(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 = [];
|
||||
for (const udoc of users) {
|
||||
tasks.push(_user(udoc._id, bset, uset, dset, dryrun, report));
|
||||
@@ -50,7 +50,7 @@ async function _user(
|
||||
const udoc = await user.getById('system', uid);
|
||||
if (!udoc) return;
|
||||
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 })
|
||||
.sort({ domainId: 1, docId: 1 }).toArray();
|
||||
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 * as document from '../model/document';
|
||||
import * as setting from '../model/setting';
|
||||
import db from '../service/db';
|
||||
import paginate from '../lib/paginate';
|
||||
import { STATUS, PRIV } from '../model/builtin';
|
||||
import { PRIV } from '../model/builtin';
|
||||
|
||||
export const description = 'Delete a user';
|
||||
|
||||
const collDocument = db.collection('document');
|
||||
const collDomainUser = db.collection('domain.user');
|
||||
const collRecord = db.collection('record');
|
||||
const collMessage = db.collection('message');
|
||||
|
||||
const $unset: Value<Partial<Udoc>> = {
|
||||
regip: '', regat: '', loginat: '', loginip: '',
|
||||
};
|
||||
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);
|
||||
}
|
||||
export async function run({ uid }) {
|
||||
await collDocument.deleteMany({ owner: 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 });
|
||||
const uname = String.random(32);
|
||||
await user.setById(uid, {
|
||||
uname,
|
||||
unameLower: uname.toLowerCase(),
|
||||
priv: PRIV.PRIV_NONE,
|
||||
}, $unset);
|
||||
await user.setPassword(uid, String.random(32));
|
||||
// TODO delete contest, homework, etc
|
||||
await collMessage.deleteMany({ $or: [{ from: uid }, { to: uid }] });
|
||||
await user.setPriv(uid, PRIV.PRIV_NONE);
|
||||
return uid;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ export class HandlerCommon {
|
||||
|
||||
translate(str: string) {
|
||||
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) {
|
||||
@@ -333,8 +333,8 @@ export class HandlerCommon {
|
||||
async renderHTML(name: string, context: any): Promise<string> {
|
||||
const UserContext: any = {
|
||||
...this.user,
|
||||
avatar: avatar(this.user.avatar || '', 128),
|
||||
perm: this.user.perm.toString(),
|
||||
avatar: avatar(this.user?.avatar || '', 128),
|
||||
perm: this.user?.perm?.toString(),
|
||||
viewLang: this.translate('__id'),
|
||||
};
|
||||
if (!global.Hydro.lib.template) return JSON.stringify(context, serializer);
|
||||
|
||||
@@ -57,7 +57,7 @@ const replacer = (k, v) => {
|
||||
class Nunjucks extends nunjucks.Environment {
|
||||
constructor() {
|
||||
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('dumpYaml', (self) => yaml.dump(self));
|
||||
this.addFilter('serialize', (self, ignoreFunction = true) => serialize(self, { ignoreFunction }));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.17.6",
|
||||
"version": "4.17.7",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{% set layout_name = "basic" %}
|
||||
{% extends "layout/html5.html" %}
|
||||
{% block body %}
|
||||
{% include "partials/nav.html" %}
|
||||
{% if UserContext %}{% include "partials/nav.html" %}{% endif %}
|
||||
<div class="slideout-panel" id="panel">
|
||||
<div class="slideout-overlay"></div>
|
||||
{% include "partials/header_mobile.html" %}
|
||||
{% if UserContext %}{% include "partials/header_mobile.html" %}{% endif %}
|
||||
<div class="main">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
{% include "partials/footer.html" %}
|
||||
</div>
|
||||
{% include "partials/login_dialog.html" %}
|
||||
{% if UserContext %}{% include "partials/login_dialog.html" %}{% endif %}
|
||||
{% endblock %}
|
||||
@@ -25,9 +25,9 @@
|
||||
<meta property="og:image" content="{{ static_url('favicon-96x96.png') }}" />
|
||||
{% endblock %}
|
||||
{% 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 %}
|
||||
<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') }}">
|
||||
<title>{{ handler.renderTitle(page_name) }}</title>
|
||||
{% if not isIE(handler.request.headers['user-agent']) %}
|
||||
|
||||
Reference in new issue
Block a user