• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN Proxy Script (incomplete)

Status
Not open for further replies.

kanalumaddela

Insider
Insider
Update: Changed the script to instead notify users by PM a client that is using a proxy. Must be configured when loaded.

Currently attempting to use https://iphub.info/ 's API to detect and kick user's who use proxies. The script is currently minimal to test basic detection and client kicking. None of the config options do anything, just there to keep track of what I want in.

The script will check the client's IP 2 seconds after they connect/move. The current issues is that when a client connects to the server the .getIP() returns blank. If a client switches channels, it will retrieve the IP just fine. I don't really understand why, considering another script I made that uses the clientMove event with a delay can retrieve a channel a client has moved to.

PHP:
registerPlugin({
    name: 'Proxy Check',
    version: '0.1',
    engine: '>= 0.9.16.4',
    description: 'Moves clients based off of channel triggers',
    author: 'kanalumaddela <[email protected]>',
    vars: [
        {
            name: 'client_uids',
            title: 'List of client uids to PM (comma separated)',
            type: 'string'
        }
    ]
},
function(sinusbot, config) {
    var engine = require('engine');
    var backend = require('backend');
    var event = require('event');
   
    var clientpmarray = config.client_uids.split(",");
   
    event.on('clientMove', function(ev) {
        if (!ev.client.isSelf() && ev.toChannel) {
            engine.log('[Proxy Check] ' + ev.client.name() + ' \s IP is: ' + ev.client.getIP());
        setTimeout(function() {
            var clientip = this.client.getIP();
            engine.log('[Proxy Check] ' +  this.client.name() + ' \s IP with the 2 sec delay check is: ' + clientip);
            if (clientip) {
                var apiurl = 'http://legacy.iphub.info/api.php?ip=' + clientip + '&showtype=4';
                sinusbot.http({
                    "method": "GET",
                    "url": apiurl,
                    "timeout": 6000,
                    "maxSize": 1024*1024*5,
                }, function(error, response) {
                    if(response.statusCode != 200) {
                        sinusbot.log(error);
                        return;
                    }
                    var apiresponse = JSON.parse(response.data);
                    engine.log(apiresponse.proxy);
                    if (apiresponse.proxy == 1) {
                        pmclients(ev.client.name() );
                    }
                    else {
                        engine.log('[Proxy Check] ' + ev.client.name() + ' is not using a proxy.');
                    }
                });
            }
        }.bind(ev), 2000);
        }
    });
   
    function pmclients(user) {
        for (x = 0; x < clientpmarray.length; x++) {
            if (backend.getClientByUID(clientpmarray[x])) {
                var client = backend.getClientByUID(clientpmarray[x]);
                client.chat('[Proxy Check] - ' + user + ' is using a proxy');
            } else {
                engine.log('[Proxy Check] - User does not exist/is not online');
            }
        }
    }
   
    engine.log('[Proxy Check] - Loading...');
   
});

What works
  • detecting people using proxies and successfully kicks them when they switch channels
What doesn't work
  • Detecting people when they connect to the server (issue still persists 0.9.16.4-aa0f89d)
 
Last edited:

Xuxe

Containerholic
Staff member
is awesome!
V.I.P.
Contributor
Insider
The script will check the client's IP 2 seconds after they connect/move. The current issues is that when a client connects to the server the .getIP() returns blank

Hi,
this is currently normal i think, not all of the data is instantly available there are running update "ticks" . May we need to look again in to this @flyth .
But i recommend you, do not instantly kick some one better combine this with a kind of spamming protection / switching channels or something. Not every one who uses a VPN comes to troll you ;)
 

kanalumaddela

Insider
Insider
But i recommend you, do not instantly kick some one better combine this with a kind of spamming protection / switching channels or something. Not every one who uses a VPN comes to troll you ;)
Yes,I plan to do that. I just wanted to make sure I had a functional script before working on anything else.

If I wanted to have something where a user has the option to request using their VPN. How would that work? Would there be a chat event inside the clientmove event?
 

Xuxe

Containerholic
Staff member
is awesome!
V.I.P.
Contributor
Insider
If I wanted to have something where a user has the option to request using their VPN. How would that work? Would there be a chat event inside the clientmove event?

You could count the moves in x Time or something like that, but your idea with the "whitelist" sounds better.
 

kanalumaddela

Insider
Insider
You could count the moves in x Time or something like that, but your idea with the "whitelist" sounds better.
Now that I'm actually awake, I have some questions and thoughts.
  1. How would you count the # of times a client has moved within a certain time (e.g. 5 mins)
  2. Should I rely completely on the storage system to manage whitelisted server groups/uuids? OR stick with setting them in the config of the script?
    1. If I were to use the storage system, would it be smart to add/remove these whitelists via chat commands? (e.g. !proxycheck whitelist sg <id> or !proxycheck whitelist uuid <uuid>)
 

xDefcon

Well-Known Member
Contributor
The current issues is that when a client connects to the server the .getIP() returns blank. If a client switches channels, it will retrieve the IP just fine. I don't really understand why, considering another script I made that uses the clientMove event with a delay can retrieve a channel a client has moved to.

I have coded a similar script, and a custom API to detect proxies, but cause of the inconsistance of getIP() method, reported maybe 5 weeks ago, i could not publish the script. Maybe flyth will fix this on the next version. If you look on the forums there are 2 discussion about this problem.
 

kanalumaddela

Insider
Insider
Updated the script to instead PM a list of configured users. It'll send a simple message saying <client> is using a proxy.

The .getIP() still persists on 0.9.16.4 and I'm going to assume it's one of the those things that the bot will start to retrieve on a client's first connect sometime.
 

Analyzetm

Member
What doesn't work
  • Detecting people when they connect to the server (issue still persists 0.9.16.4-aa0f89d)
[/QUOTE]

You can make your Check when they connect..

sinusbot.on('clientMove', function (ev) {
if (ev.oldChannel == 0) {
chatPrivate(ev.clientId,'Willkommen zurück '+ev.clientNick+'.');
OnTime(ev);
if (config.command_ontime == 1){
chatPrivate(ev.clientId, 'Diese ist jederzeit mit !ontime abrufbar als PN an mich!');
chatPrivate(ev.clientId, 'Hast du deine TS Identität schon mit Steam verknüpft?');
chatPrivate(ev.clientId, 'Falls nicht !register an mich und los gehts!');
}
}
});

The Clientmove event starts on each move and connect. With ev.oldchannel check if you moved from another channel then ev.oldchannel is "1"
For new connections this is always set to 0 so my messages in this part of my script is a "Welcome-message" :)
 

kanalumaddela

Insider
Insider
I haven't touched this script in a long ass time and on top of that, iphub has updated to their v2 API, so who knows how long the legacy one will be up. iphub v2 also is no longer a viable option as they introduced multiple plans to allow more requests. If there's a decent API to check for proxies and vpns, then maybe I'll work on coding a better version from scratch.
 

kanalumaddela

Insider
Insider
This is not meant to necro, but to add some more information. I made a literal quick script (10 mins) using iphub's v2 api and it works. I just don't know how it'll be on larger servers that have constantly connecting players. Currently it'll just send the messages to global chat. It'll only be sent if the user's ip is either a proxy or possibly a proxy.

Here's the code, you'll have to hardcode the api key since I was legitimately to lazy to add in a basic variable. You have to register on iphub now if you want to get an api key (https://iphub.info/)
PHP:
registerPlugin({
    name: '[Updated] Proxy Check',
    version: '0.1',
    description: 'check proxies',
    author: 'kanalumaddela <[email protected]>'
}, function(sinusbot, config) {
    var engine = require('engine');
    var backend = require('backend');
    var event = require('event');

    event.on('clientMove', function(ev) {
        engine.log('[Proxy Check] ' + ev.fromChannel);
        var fromchannel = ev.fromChannel;
        if (!ev.client.isSelf() && !fromchannel) {
            setTimeout(function() {
                var clientip = this.client.getIPAddress();
                engine.log('[Proxy Check] ' +  this.client.name() + ' \s IP with the 1.5 sec delay check is: ' + clientip);
                if (clientip) {
                    var apiurl = 'http://v2.api.iphub.info/ip/'+clientip+'?key='; // insert your api key after the =
                    sinusbot.http({
                        "method": "GET",
                        "url": apiurl,
                        "timeout": 3000,
                        "maxSize": 1024*1024*5,
                    }, function(error, response) {
                        if(response.statusCode != 200) {
                            engine.log(error);
                            return;
                        }
                        var apiresponse = JSON.parse(response.data);
                        engine.log(apiresponse.block);
                        if (apiresponse.code) {
                            backend.chat('Failed to retrieve ip info for: '+ev.client.name()+' [uid: '+ev.client.uid()+'] Take note.');
                        }
                        if (apiresponse.block == 1) {
                            backend.chat(ev.client.name()+' [uid: '+ev.client.uid()+'] is using a proxy.');
                        }
                        if (apiresponse.block == 2) {
                            backend.chat(ev.client.name()+' [uid: '+ev.client.uid()+'] [b][i]could be[/i][/b] a proxy.');
                        }
                    });
                }
            }.bind(ev), 1500); // timeout exist to get the ip

        }
    });

});
 
Status
Not open for further replies.
Top