2021-08-19 07:55:45 -05:00
|
|
|
import { Users, Signins } from '@/models/index';
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2020-04-03 09:35:14 -05:00
|
|
|
// node built/tools/show-signin-history username
|
2019-01-10 17:07:09 -06:00
|
|
|
// => {Success} {Date} {IPAddrsss}
|
|
|
|
|
2020-04-03 09:35:14 -05:00
|
|
|
// node built/tools/show-signin-history username user-agent,x-forwarded-for
|
2019-01-10 17:07:09 -06:00
|
|
|
// with user-agent and x-forwarded-for
|
|
|
|
|
2020-04-03 09:35:14 -05:00
|
|
|
// node built/tools/show-signin-history username all
|
2019-01-10 17:07:09 -06:00
|
|
|
// with full request headers
|
|
|
|
|
2019-04-12 11:43:22 -05:00
|
|
|
async function main(username: string, headers?: string[]) {
|
2019-04-07 07:50:36 -05:00
|
|
|
const user = await Users.findOne({
|
2019-01-10 17:07:09 -06:00
|
|
|
host: null,
|
|
|
|
usernameLower: username.toLowerCase(),
|
|
|
|
});
|
|
|
|
|
2019-04-13 14:17:24 -05:00
|
|
|
if (user == null) throw new Error('User not found');
|
2019-01-10 17:07:09 -06:00
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
const history = await Signins.find({
|
|
|
|
userId: user.id
|
2019-01-10 17:07:09 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
for (const signin of history) {
|
|
|
|
console.log(`${signin.success ? 'OK' : 'NG'} ${signin.createdAt ? signin.createdAt.toISOString() : 'Unknown'} ${signin.ip}`);
|
|
|
|
|
|
|
|
// headers
|
|
|
|
if (headers != null) {
|
|
|
|
for (const key of Object.keys(signin.headers)) {
|
|
|
|
if (headers.includes('all') || headers.includes(key)) {
|
|
|
|
console.log(` ${key}: ${signin.headers[key]}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 09:35:14 -05:00
|
|
|
// get args
|
|
|
|
const args = process.argv.slice(2);
|
2019-01-10 17:07:09 -06:00
|
|
|
|
2020-04-03 09:35:14 -05:00
|
|
|
let username = args[0];
|
|
|
|
let headers: string[] | undefined;
|
2019-01-10 17:07:09 -06:00
|
|
|
|
2020-04-03 09:35:14 -05:00
|
|
|
if (args[1] != null) {
|
|
|
|
headers = args[1].split(/,/).map(header => header.toLowerCase());
|
2020-04-03 03:13:41 -05:00
|
|
|
}
|
2019-01-10 17:07:09 -06:00
|
|
|
|
2020-04-03 09:35:14 -05:00
|
|
|
// normalize args
|
|
|
|
username = username.replace(/^@/, '');
|
|
|
|
|
|
|
|
main(username, headers).then(() => {
|
|
|
|
process.exit(0);
|
|
|
|
}).catch(e => {
|
|
|
|
console.warn(e);
|
|
|
|
process.exit(1);
|
|
|
|
});
|