add vpn whitelist command

This commit is contained in:
RaidMax 2022-03-23 13:34:04 -05:00
parent 20858991e1
commit 7be096e0b6
2 changed files with 43 additions and 20 deletions

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using IW4MAdmin.Application.Configuration; using IW4MAdmin.Application.Configuration;
using Jint; using Jint;
@ -84,9 +85,9 @@ namespace IW4MAdmin.Application.Misc
var item = _config[_pluginName][key]; var item = _config[_pluginName][key];
if (item is JArray array) if (item is JsonElement { ValueKind: JsonValueKind.Array } jElem)
{ {
item = array.ToObject<List<dynamic>>(); item = jElem.Deserialize<List<dynamic>>();
} }
return JsValue.FromObject(_scriptEngine, item); return JsValue.FromObject(_scriptEngine, item);

View File

@ -1,14 +1,31 @@
var plugin = { const commands = [{
author: 'RaidMax', name: "whitelistvpn",
version: 1.2, description: "whitelists a player's client id from VPN detection",
name: 'VPN Detection Plugin', alias: "wv",
permission: "SeniorAdmin",
targetRequired: true,
arguments: [{
name: "players",
required: true
}],
execute: (gameEvent) => {
plugin.vpnExceptionIds.push(gameEvent.Target.ClientId);
plugin.configHandler.SetValue('vpnExceptionIds', plugin.vpnExceptionIds);
gameEvent.Origin.Tell(`Successfully whitelisted ${gameEvent.Target.Name}`);
}
}];
const plugin = {
author: 'RaidMax',
version: 1.3,
name: 'VPN Detection Plugin',
manager: null, manager: null,
logger: null, logger: null,
vpnExceptionIds: [], vpnExceptionIds: [],
checkForVpn: function (origin) { checkForVpn: function (origin) {
var exempt = false; let exempt = false;
// prevent players that are exempt from being kicked // prevent players that are exempt from being kicked
this.vpnExceptionIds.forEach(function (id) { this.vpnExceptionIds.forEach(function (id) {
if (id === origin.ClientId) { if (id === origin.ClientId) {
@ -18,40 +35,41 @@ var plugin = {
}); });
if (exempt) { if (exempt) {
this.logger.WriteInfo(`${origin} is whitelisted, so we are not checking VPN status`);
return; return;
} }
var usingVPN = false; let usingVPN = false;
try { try {
var cl = new System.Net.Http.HttpClient(); const cl = new System.Net.Http.HttpClient();
var re = cl.GetAsync('https://api.xdefcon.com/proxy/check/?ip=' + origin.IPAddressString).Result; const re = cl.GetAsync(`https://api.xdefcon.com/proxy/check/?ip=${origin.IPAddressString}`).Result;
var userAgent = 'IW4MAdmin-' + this.manager.GetApplicationSettings().Configuration().Id; const userAgent = `IW4MAdmin-${this.manager.GetApplicationSettings().Configuration().Id}`;
cl.DefaultRequestHeaders.Add('User-Agent', userAgent); cl.DefaultRequestHeaders.Add('User-Agent', userAgent);
var co = re.Content; const co = re.Content;
var parsedJSON = JSON.parse(co.ReadAsStringAsync().Result); const parsedJSON = JSON.parse(co.ReadAsStringAsync().Result);
co.Dispose(); co.Dispose();
re.Dispose(); re.Dispose();
cl.Dispose(); cl.Dispose();
usingVPN = parsedJSON.success && parsedJSON.proxy; usingVPN = parsedJSON.success && parsedJSON.proxy;
} catch (e) { } catch (e) {
this.logger.WriteWarning('There was a problem checking client IP for VPN ' + e.message); this.logger.WriteWarning(`There was a problem checking client IP for VPN ${e.message}`);
} }
if (usingVPN) { if (usingVPN) {
this.logger.WriteInfo(origin + ' is using a VPN (' + origin.IPAddressString + ')'); this.logger.WriteInfo(origin + ' is using a VPN (' + origin.IPAddressString + ')');
var contactUrl = this.manager.GetApplicationSettings().Configuration().ContactUri; const contactUrl = this.manager.GetApplicationSettings().Configuration().ContactUri;
var additionalInfo = ''; let additionalInfo = '';
if (contactUrl) { if (contactUrl) {
additionalInfo = _localization.LocalizationIndex["SERVER_KICK_VPNS_NOTALLOWED_INFO"] + ' ' + contactUrl; additionalInfo = _localization.LocalizationIndex['SERVER_KICK_VPNS_NOTALLOWED_INFO'] + ' ' + contactUrl;
} }
origin.Kick(_localization.LocalizationIndex["SERVER_KICK_VPNS_NOTALLOWED"] + ' ' + additionalInfo, _IW4MAdminClient); origin.Kick(_localization.LocalizationIndex['SERVER_KICK_VPNS_NOTALLOWED'] + ' ' + additionalInfo, _IW4MAdminClient);
} }
}, },
onEventAsync: function (gameEvent, server) { onEventAsync: function (gameEvent, server) {
// join event // join event
if (gameEvent.Type === 4) { if (gameEvent.TypeName === 'Join') {
this.checkForVpn(gameEvent.Origin); this.checkForVpn(gameEvent.Origin);
} }
}, },
@ -59,6 +77,10 @@ var plugin = {
onLoadAsync: function (manager) { onLoadAsync: function (manager) {
this.manager = manager; this.manager = manager;
this.logger = manager.GetLogger(0); this.logger = manager.GetLogger(0);
this.configHandler = _configHandler;
this.configHandler.GetValue('vpnExceptionIds').forEach(element => this.vpnExceptionIds.push(element));
this.logger.WriteInfo(`Loaded ${this.vpnExceptionIds.length} ids into whitelist`);
}, },
onUnloadAsync: function () { onUnloadAsync: function () {
@ -66,4 +88,4 @@ var plugin = {
onTickAsync: function (server) { onTickAsync: function (server) {
} }
}; };