Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/src/services/DiscordClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ module.exports = class DiscordMapClient {
Object.keys(perms).forEach((key) => (perms[key] = true))
perms.areaRestrictions = []
perms.webhooks = webhooks.map((x) => x.name)
perms.scanner = Object.keys(scanner)
.map((x) => x !== 'backendConfig' && scanner[x].enabled && x)
.filter((x) => x !== false)
perms.scanner = Object.keys(scanner).filter(
(x) => x !== 'backendConfig' && x && scanner[x].enabled,
)
console.log(
`[DISCORD] User ${user.username}#${user.discriminator} (${user.id}) in allowed users list, skipping guild and role check.`,
)
Expand Down
18 changes: 10 additions & 8 deletions server/src/services/functions/scannerPerms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ const { scanner } = require('../config')

module.exports = function scannerPerms(roles, provider) {
let perms = []
if (Object.keys(scanner).length) {
roles.forEach((role) => {
Object.keys(scanner).forEach((mode) => {
if (scanner[mode][provider]?.includes(role)) {
perms.push(mode)
}
})
roles.forEach((role) => {
Object.keys(scanner).forEach((mode) => {
if (
scanner[mode][provider] &&
(scanner[mode][provider].includes(role) ||
!scanner[mode][provider].length)
) {
perms.push(mode)
}
})
}
})
if (perms.length) {
perms = [...new Set(perms)]
}
Expand Down
81 changes: 73 additions & 8 deletions server/src/services/logUserAuth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/* eslint-disable no-console */
const { capitalize } = require('@material-ui/core')
const Fetch = require('./Fetch')

const capCamel = (str) => capitalize(str.replace(/([a-z](?=[A-Z]))/g, '$1 '))

const mapPerms = (perms, userPerms) =>
perms
.map(
(perm) => `${capCamel(perm)}: ${userPerms[perm] ? '\u2705' : '\u274c'}`,
)
.join('\n')

module.exports = async function getAuthInfo(req, user, strategy) {
const ip =
req.headers['cf-connecting-ip'] ||
Expand All @@ -19,7 +29,9 @@ module.exports = async function getAuthInfo(req, user, strategy) {
name: `${user.username}`,
icon_url: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
},
description: `${user.username} Failed Authentication`,
description: `${user.username} ${
user.valid ? 'Successfully' : 'Failed'
} Authentication`,
thumbnail: {
url: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
},
Expand All @@ -38,42 +50,95 @@ module.exports = async function getAuthInfo(req, user, strategy) {
},
{
name: 'Geo Lookup',
value: `${geo.city}, ${geo.regionName}, ${geo.zip}`,
value: `${geo.city || ''}, ${geo.regionName || ''}, ${geo.zip || ''}`,
},
{
name: 'Google Map',
value: `https://www.google.com/maps?q=${geo.lat},${geo.lon}`,
value: `https://www.google.com/maps?q=${geo.lat || 0},${geo.lon || 0}`,
},
{
name: 'Network Provider',
value: `${geo.isp}, ${geo.as}`,
value: `${geo.isp || ''}, ${geo.as || ''}`,
},
{
name: 'Mobile',
value: `${geo.mobile}`,
value: `${Boolean(geo.mobile)}`,
inline: true,
},
{
name: 'Proxy',
value: `${geo.proxy}`,
value: `${Boolean(geo.proxy)}`,
inline: true,
},
{
name: 'Hosting',
value: `${geo.hosting}`,
value: `${Boolean(geo.hosting)}`,
inline: true,
},
{
name: 'Pokemon',
value: mapPerms(['pokemon', 'iv', 'pvp'], user.perms),
inline: true,
},
{
name: 'Gyms',
value: mapPerms(['gyms', 'raids', 'gymBadges'], user.perms),
inline: true,
},
{
name: 'Admin',
value: mapPerms(['scanCells', 'spawnpoints', 'devices'], user.perms),
inline: true,
},
{
name: 'Wayfarer',
value: mapPerms(['portals', 'submissionCells'], user.perms),
inline: true,
},
{
name: 'Pokestops',
value: mapPerms(
['pokestops', 'quests', 'lures', 'invasions'],
user.perms,
),
inline: true,
},
{
name: 'Other',
value: mapPerms(['nests', 'weather', 'scanAreas', 'donor'], user.perms),
inline: true,
},
],
timestamp: new Date(),
}
if (user.perms.areaRestrictions.length) {
embed.fields.push({
name: 'Area Restrictions',
value: user.perms.areaRestrictions.map((str) => capCamel(str)).join('\n'),
inline: true,
})
}
if (user.perms.webhooks.length) {
embed.fields.push({
name: 'Webhooks',
value: user.perms.webhooks.map((str) => capCamel(str)).join('\n'),
inline: true,
})
}
if (user.perms.scanner.length) {
embed.fields.push({
name: 'Scanner',
value: user.perms.scanner.map((str) => capCamel(str)).join('\n'),
inline: true,
})
}
if (user.valid) {
console.log(
'[DISCORD]',
user.username,
`(${user.id})`,
'Authenticated successfully.',
)
embed.description = `${user.username} Successfully Authenticated`
embed.color = 0x00ff00
} else if (user.blocked) {
console.warn('[DISCORD]', user.id, 'Blocked due to', user.blocked)
Expand Down