Giter Club home page Giter Club logo

sban's Introduction

sban

Build status License: MIT

This mod is based on the concepts introduced by xban2, and expands on them by using an sql database instead of a serialised table file. This approach to ban management:

  • Offers API access to core functions that can be disabled if reqd
  • Improves the robustness of the data.
  • Grants an enhanced view of player accounts and ban records.
  • Provides tiered access to player record information.
  • Provides optional automatic ban expiration.
  • Provides the capability to pre-emptively ban players.
  • Offers increased accessibility via SSH connections to the database with your favourite database management gui.
  • Can preserve existing bans by importing records from Minetest or xban2.

Transactions are coded without locks so it's not recommended to write to the database whilst Minetest is using it. Reading the database shouldn't be an issue.

Existing users please note: sban will not allow minetest to run if your db version doesn't match the current version required, if that happens and only if, you need to apply sban/tools/sban_update.sql to the database by copying the file into the world folder, then you can use sqlite3 in a terminal, after navigating to the world folder, using the commands:

sqlite3 sban.sqlite
.read sban_update.sql
.exit

It's a good idea to make a backup prior to running the update just in case and the update should not be applied more than once!

INSTALLATION

sban requires lsqlite3 (https://github.com/LuaDist/lsqlite3).

If you have luarocks (https://luarocks.org/) installed on the target server, you can easily install lsqlite3 in a terminal:

sudo luarocks install lsqlite3

If the target server runs mods in secure mode[recommended], you must add sban to the list of trusted mods in minetest.conf:

secure.trusted_mods = sban

COMMANDS

The mod provides the following chat console commands. These commands require the ban privilege. The ban_admin and server privileges extend the functionality of some commands.

bang

Launches a GUI. Comprehensive management of bans via a user interface for in-game convenience. On launch the interface shows a hotlist containing the last 10 players to join. Use search to find a player if they are not currently in the list. Multiple records are shown if available, accessible via the arrows.

Usage: /bang

Please note any client accessing this form without the required privilege i.e. a hacked client, will be logged and banned automatically!

ban

Bans a player permanently.

Usage: /ban <name_or_ip> <reason>

Example: /ban Steve Some reason.

The server privilege enables the pre-emptive banning of player names or IP addresses for which the server has no current record.

tempban

Bans a player temporarily.

Usage: /tempban <name_or_ip> <time> <reason>

Example: /tempban Steve 2D Some reason.

The time parameter is a string in the format <count> <unit>, where <unit> is either s for seconds, m for minutes, h for hours, D for days, W for weeks, M for months, or Y for years. If the unit is omitted, it is assumed to mean seconds. For example, 42 means 42 seconds, 1337m means 1337 minutes, and so on. You can chain more than one such group and they will add up. For example, 1Y3M3D7h will ban for 1 year, 3 months, 3 days and 7 hours.

unban

Unbans a player.

Usage: /unban <name_or_ip> <reason>

Example: /unban Steve Some reason.

Note that this command requires a reason.

ban_record

Displays player record and ban record.

Usage: /ban_record <name_or_ip>

Example: /ban_record Steve

This prints the player record and ban record for a player. The records are printed to the chat console with one entry per line.

The player record includes names and, if sufficient privileges, IP addresses used by the player. The number of records displayed is limited to 10 by default to prevent chat console spam, and can be adjusted through the setting sban.display_max in minetest.conf.

The ban record includes a list of all ban related actions performed on the player under any known name or IP address. This includes the time a ban came into effect, the expiration time (if applicable), the reason, and the source of the ban.

Note that the records of players with the server privilege can only be viewed by other players with the server privilege.

ban_wl

Manages the whitelist.

Usage: /ban_wl (add|del|list) <name_or_ip>

Example: /ban_wl add Steve

Whitelisted players are allowed on the server even if they are marked as banned. This is useful to ensure moderators cannot ban each other.

The add subcommand adds a player to the whitelist. The del subcommand removes a player from the whitelist. The list subcommand lists the players on the whitelist.

ADMINISTRATION COMMANDS

These commands are for administering the server and require the server privilege. You can import a server's previous ban history from xban2's xban.db file or from Minetest's ipban.txt file.

This is an intensive process that will cause lag, so it's recommended you perform this on a local instance and copy the database to the server before starting with the sban mod installed.

ban_dbi

Imports bans from xban.db or ipban.txt files into an existing sban.sqlite file.

Usage: /ban_dbi <filename>

Example: /ban_dbi xban.db or /ban_dbi ipban.txt

It's possible to place multiple files in the world folder and execute the command on each file. For example:

/ban_dbi xban_1.db
/ban_dbi xban_2.db

Each record is checked against the database by player name to prevent duplicate entries.

ban_dbe

Extracts all valid player records from an xban.db file and saves them in xban.sql.

Usage: /ban_dbe <input_filename>

Example: /ban_dbe xban.db

This creates a file called xban.sql in the world folder. Import the file from the sqlite prompt using:

.open sban.sqlite
.read xban.sql
.exit

The time of the import operation is dependant on the size of the .sql file.

ban_dbx

Dumps the database back to xban2 file format. Use it before you uninstall this mod if you intend using xban2 and wish to retain the data.

Usage: /ban_dbx

Do this before enabling xban2 mod otherwise it will be overwritten by the currently loaded data.

whois

Usage: //whois <name>

Example: //whois sadie

Returns all known accounts and ip addresses associated with a player name.

CONFIG SETTINGS

You can add these optional settings to minetest.conf to adjust the sban mod's behaviour. Deleting them removes the modification and sban will revert back to the default behaviour. Minetest config file can only be changed when the server isn't running!

sban.api

Controls loading of the API functions. Default: true

sban.api = false

This would disable the API functions and prevent other mods access via the global sban table.

sban.display_max

Changes the maximum number of player records displayed when using the /ban_record command.

sban.display_max = 12

This would increase the number of records shown from the default: 10 records to 12.

sban.ban_max

Allows server owners to set an expiry date for bans. It uses the same format for durations as the /tempban command.

sban.ban_max = 90D

In this example all permanent player bans created after the setting has been added to minetest.conf, and after a server restart, will expire 90 days after the ban was set. If required, longer ban durations can still be set with the tempban command.

Please note: existing ban expiry dates are not affected by changing this setting, including permanent bans but they will be applied to any subsequent new bans.

sban.accounts_per_id

Restricts how many accounts an id can have.

sban.accounts_per_id = 5

Please note this setting is optional and the default behaviour is unrestricted.

sban.ip_limit

Restricts how many ip addresses an id can have.

sban.ip_limit = 10

Please note this setting is optional and the default behaviour is unrestricted.

sban.import_enabled

Disables the import/export sections of code.

sban.import_enabled = false

The default is true, this setting allows you to disable the code and commands associated with importing & exporting data and should only be set to false once you have imported your ban sources.

sban.cache.max

Maximum cached name records.

sban.cache.max = 1000

If you don't add this setting sban will use the value above as the default.

sban.cache.ttl

Time in seconds to deduct from the last player to login as the cutoff point for pre caching names.

sban.cache.max = 86400

If you don't add this setting sban will use the value above as the default. Disable name caching by setting to -2

CREDITS

Thanks to:

Shara for suggesting improvements and editing documentation.
rubenwardy for suggesting improvements to the interface layout.
sofar for requesting a gui and suggesting the hotlist concept.

sban's People

Contributors

ezhh avatar panquesito7 avatar rubenwardy avatar shivajiva101 avatar sofar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sban's Issues

Banning someone doesn't always kick them

Checking with ban_record shows they were banned, I then kicked them (which worked). This is 5.4.0-dev

There are no applicable log messages:

ACTION[Server]: [sban] Joker-_- banned by rubenwardy reason: hacking
ACTION[Server]: rubenwardy kicks Joker-_-    (this was manually done)
[Server]: [CTF | team] Removing player "Joker-_-"

Mods are capture the flag + MT-CTF/rules, MT-CTF/servermods, sauth (d2e0aa834c7c0b6d6000af98eb22088b905441c3), sban (44695d2)

Crash on latest commit

ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'sban' in callback on_prejoinplayer(): mods/sban/init.lua:1110: attempt to index local 'data' (a nil value)

on latest commit

After temp ban ended server crashes

After temp banning a player for an hour all was well and then the hour ended and about 10 minutes later the server crashed with this error

2019-11-24 23:17:08: ERROR[Main]: ModError: Failed to load and run script from /home/minetest/minetest/bin/../mods/sban/init.lua:
2019-11-24 23:17:08: ERROR[Main]: /home/minetest/minetest/bin/../mods/sban/init.lua:1363: bad argument #8 to 'format' (string expected, got nil)
2019-11-24 23:17:08: ERROR[Main]: stack traceback:
2019-11-24 23:17:08: ERROR[Main]: [C]: in function 'format'
2019-11-24 23:17:08: ERROR[Main]: /home/minetest/minetest/bin/../mods/sban/init.lua:1363: in function 'process_expired_bans'
2019-11-24 23:17:08: ERROR[Main]: /home/minetest/minetest/bin/../mods/sban/init.lua:1374: in main chunk

Server does not start at all now it just gives this error

Banning someone doesn't ban then

I first banned a player, and it kicked them from a game:

CTF_Bot, ban PotatoGuy cheating
<CTF_Bot> *** PotatoGuy left the game

However they then appeared back ingame later on, and banning had no response

CTF_Bot, ban PotatoGuy cheating

So I had to kick them.

I'm also using the irc mod and sauth.

secure.trusted_mods = sban,irc,sauth

Here is the ban record:

<CTF_Bot> Player records: 1
<CTF_Bot> [1] Name: PotatoGuy IP: <> Created: Sun 08 Oct 2017 07:19:29 PM UTC Last login: Mon 09 Oct 2017 12:21:55 AM UTC
<CTF_Bot> Ban records: 1
<CTF_Bot> [1] Name: PotatoGuy Created: Sun 08 Oct 2017 07:23:07 PM UTC Banned by: user Reason: cheating Expires: Sun 08 Oct 2017 07:23:07 PM UTC
<CTF_Bot> [1] Unbanned by: sban Reason: ban expired Time: Mon 09 Oct 2017 12:21:53 AM UTC
<CTF_Bot> Banned: false


2017-10-08 19:23:07: ACTION[Server]: [sban] PotatoGuy temp banned by user reason: cheating
2017-10-09 00:21:53: ACTION[Server]: [sban] PotatoGuy unbanned by sban reason: ban expired
/home/minetest/.minetest/mods/sban/init.lua:44: attempt to index local 't' (a number value)
	/home/minetest/.minetest/mods/sban/init.lua:44: in function 'parse_time'
	/home/minetest/.minetest/mods/sban/init.lua:775: in function 'func'
/home/minetest/.minetest/mods/sban/init.lua:44: attempt to index local 't' (a number value)
	/home/minetest/.minetest/mods/sban/init.lua:44: in function 'parse_time'
	/home/minetest/.minetest/mods/sban/init.lua:775: in function 'func'

GUI: Changing index can lead to incorrect bans

List of players pre-populates based on those currently online; however players online might change in the time it takes you to enter a ban reason and click Ban. Because the visible list doesn't update as players join and leave, there is a danger you will ban a player other than the intended one, since the list has, unseen by you, updated and another player is now at that index.

Crashes server

This is a great mod, but it seems to crash my server when a typo is made in the username, at least for a tempban. I got this error:

2018-09-14 17:01:44: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod '' in callback on_chat_message(): /home/billys/.minetest/mods/sban/init.lua:150: bad argument #1 to 'format' (number expected, got nil) 2018-09-14 17:01:44: ERROR[Main]: stack traceback: 2018-09-14 17:01:44: ERROR[Main]: [C]: in function 'format' 2018-09-14 17:01:44: ERROR[Main]: /home/billys/.minetest/mods/sban/init.lua:150: in function 'active_ban' 2018-09-14 17:01:44: ERROR[Main]: /home/billys/.minetest/mods/sban/init.lua:1549: in function 'func' 2018-09-14 17:01:44: ERROR[Main]: /usr/share/minetest/builtin/profiler/instrumentation.lua:106: in function 'func' 2018-09-14 17:01:44: ERROR[Main]: /usr/share/minetest/builtin/game/chatcommands.lua:30: in function </usr/share/minetest/builtin/game/chatcommands.lua:9> 2018-09-14 17:01:44: ERROR[Main]: /usr/share/minetest/builtin/game/register.lua:420: in function </usr/share/minetest/builtin/game/register.lua:400>

Unban player crashes server

a staff member perm banned a player and we since decided to unban this player but when I type in /bang and then enter the players name and a unban reason the server crashes when i click unban

with this error

2020-01-01 15:57:04: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod '' in callback on_playerReceiveFields(): /home/minetest/minetest/bin/../mods/sban/init.lua:937: bad argument #10 to 'format' (string expected, got nil)
2020-01-01 15:57:04: ERROR[Main]: stack traceback:
2020-01-01 15:57:04: ERROR[Main]: [C]: in function 'format'
2020-01-01 15:57:04: ERROR[Main]: /home/minetest/minetest/bin/../mods/sban/init.lua:937: in function 'update_ban_record'
2020-01-01 15:57:04: ERROR[Main]: /home/minetest/minetest/bin/../mods/sban/init.lua:1663: in function '?'
2020-01-01 15:57:04: ERROR[Main]: ...e/minetest/minetest/bin/../builtin/game/register.lua:429: in function <...e/minetest/minetest/bin/../builtin/game/register.lua:413>

Banned players can just rejoin under a different name

15:03:51: ACTION[Server]: Emt [ADDRESS_BBBBB] joins game. 
16:41:36: ACTION[Server]: WhatsApp [ADDRESS_BBBBB] joins game. 
17:32:56: ACTION[Server]: WhatsApp [ADDRESS_BBBBB] joins game. 
18:45:04: ACTION[Server]: hey [ADDRESS_AAAAA] joins game. 
18:49:00: ACTION[Server]: WhatsApp [ADDRESS_BBBBB] joins game. 
19:05:39: ACTION[Server]: Emt [ADDRESS_BBBBB] joins game. 
19:08:06: ACTION[Server]: Emt [ADDRESS_BBBBB] joins game. 
19:08:24: ACTION[Server]: Emt [ADDRESS_BBBBB] joins game. 
19:21:45: ACTION[Server]: [sban] WhatsApp temp banned by root reason: spam
19:21:51: ACTION[Server]: [sban] hey banned by root reason: Spam
19:22:02: ACTION[Server]: Server: Player with the name "hey" tried to connect from ADDRESS_AAAAA but it was disallowed for the following reason: Banned: Expires: Wed 06 Dec 2017 07:21:51 PM UTC, Reason: spam
19:22:04: ACTION[Server]: Server: Player with the name "WhatsApp" tried to connect from ADDRESS_BBBBB but it was disallowed for the following reason: Banned: Expires: Wed 06 Dec 2017 07:21:45 PM UTC, Reason: spam
19:22:19: ACTION[Server]: Emt [ADDRESS_BBBBB] joins game. <-- rejoins after tempban
19:22:29: ACTION[Server]: Whatsapp [ADDRESS_BBBBB] joins game. 
19:22:37: ACTION[Server]: SNIPER [ADDRESS_AAAAA] joins game.    <-- rejoins after permaban
19:23:05: ACTION[Server]: Whatsapp [ADDRESS_BBBBB] joins game. 
19:23:24: ACTION[Server]: SNIPER1 [ADDRESS_AAAAA] joins game. 
19:24:04: ACTION[Server]: SNIPER2 [ADDRESS_AAAAA] joins game. 
19:25:40: ACTION[Server]: sniper3 [ADDRESS_AAAAA] joins game. 
19:27:36: ACTION[Server]: tus1 [ADDRESS_AAAAA] joins game. 

I have no_guests installed, but it only returns when rejecting a player - not when banned. I'll try making sure that sban runs first

Performance improvements by creating indexes and primary keys on sban tables (upgrade script attached)

Wrote an upgrade script to create indexes on name and ip fields as well as adding some primary keys for the id columns that didn't have them. This should greatly improve performance as the database size grows.

Attached is the upgrade script file saved as .txt, github didn't like the .sql file for some reason.
shouldn't need to change any queries, just run the script on the db.

I didn't get to try this upgrade script with real data, it should work, but if there are any primary key conflicts during upgrading it should rollback the transaction. in the case of conflicts, i considered adding "PRIMARY KEY ON CONFLICT IGNORE" or "PRIMARY KEY ON CONFLICT REPLACE" but im not sure which would be more appropriate.

sban_upgrade_indexes.txt

Crash: attempt to index local 'data' (a nil value)

ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'sban' in callback on_prejoinplayer():mods/sban/init.lua:1225: attempt to index local 'data' (a nil value)
stack traceback:
 	mods/sban/init.lua:1225: in function <mods/sban/init.lua:1210>
 	builtin/game/register.lua:412: in function <builtin/game/register.lua:392>

ban_record states that banned player doesn't exist

/ban_record LoneWolfHT
Unknown player!

sban.sqlite:

sqlite> SELECT * FROM name WHERE name="LoneWolfHT";
-- 0 records --
sqlite> SELECT * FROM active WHERE name="LoneWolfHT";
6170|LoneWolfHT|Lone_Wolf|1599147415|Impersonating staff|0|(13158,2,-81)

Nothing in the stdout logs

Mods are capture the flag + MT-CTF/rules, MT-CTF/servermods, sauth, sban

The bang/GUI crashes the server while showing some players

I am not sure, but trying to diagnose this (see the logged error below) I think that the crash happens when the GUI tries to show a player's record with an 'expires: never' ban (trying the /ban_record command on the same player works fine instead).

2021-12-05 14:44:29: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'sauth' in callback on_playerReceiveFields(): /home/minetest/mt/bin/../mods/sban/init.lua:1480: attempt to concatenate a nil value
2021-12-05 14:44:29: ERROR[Main]: stack traceback:
2021-12-05 14:44:29: ERROR[Main]:        /home/minetest/mt/bin/../mods/sban/init.lua:1480: in function 'create_info'
2021-12-05 14:44:29: ERROR[Main]:        /home/minetest/mt/bin/../mods/sban/init.lua:1547: in function 'update_state'
2021-12-05 14:44:29: ERROR[Main]:        /home/minetest/mt/bin/../mods/sban/init.lua:1660: in function 'func'
2021-12-05 14:44:29: ERROR[Main]:        .../minetest/mt/bin/../builtin/profiler/instrumentation.lua:106: in function <.../minetest/mt/bin/../builtin/profiler/instrumentation.lua:100>
2021-12-05 14:44:29: ERROR[Main]:        /home/minetest/mt/bin/../builtin/game/register.lua:425: in function </home/minetest/mt/bin/../builtin/game/register.lua:409>

Looking at the error log it seems the nil value which is causing the error is entry.expires in init.lua line 1480:

sban/init.lua

Lines 1479 to 1481 in 30c8823

if entry.expires ~= 0 then
str = str.."Expires: "..hrdf(entry.expires).."\n"
end

I should mention now that I just updated the mod and the sban.sqlite file according to instructions from README.md, starting from a fairly old situation (Dark Lands). So I went looking in sban_update.sqlite and noticed that there is indeed a statement to explicitly set the expires field to zero where it is '' (nil).

sban/tools/sban_update.sql

Lines 197 to 198 in 30c8823

-- initialise expires
UPDATE active SET expires = 0 WHERE expires = '';

However:

  1. the statement only attempts to alter the active table while there is no such statement for the expired table (from which my error is originating);
  2. The active table itself is actually not updated, because at that stage the relevant data is in the active_tmp table instead but the script updates active (which should be empty, data gets inserted into it later).

Does this makes sense or I'm looking at the wrong end of the stick?

EDIT: I think the type(e.expires) == "number" check in the chunk below is the reason why /ban_record works instead:

sban/init.lua

Lines 557 to 559 in 30c8823

if type(e.expires) == "number" and e.expires > 0 then
expires = hrdf(e.expires)
end

Crash

/home/minetest/.minetest/mods/sban/init.lua:958: bad argument #1 to 'ipairs' (table expected, got nil)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.