stratum: ipset function to block botnets

can be (manually) used, if needed, in client_authorize
This commit is contained in:
Tanguy Pruvot 2017-12-15 23:48:20 +01:00
parent f95177cc14
commit a8e98c1839
2 changed files with 9 additions and 2 deletions

View file

@ -122,6 +122,7 @@ void get_random_key(char *key);
void client_sort(); void client_sort();
void client_block_ip(YAAMP_CLIENT *client, const char *reason); void client_block_ip(YAAMP_CLIENT *client, const char *reason);
void client_block_ipset(YAAMP_CLIENT *client, const char *ipset_name);
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first); bool client_reset_multialgo(YAAMP_CLIENT *client, bool first);
bool client_initialize_multialgo(YAAMP_CLIENT *client); bool client_initialize_multialgo(YAAMP_CLIENT *client);

View file

@ -125,11 +125,17 @@ int client_ask(YAAMP_CLIENT *client, const char *method, const char *format, ...
void client_block_ip(YAAMP_CLIENT *client, const char *reason) void client_block_ip(YAAMP_CLIENT *client, const char *reason)
{ {
char buffer[1024]; char buffer[1024];
sprintf(buffer, "iptables -A INPUT -s %s -p tcp --dport %d -j REJECT", client->sock->ip, g_tcp_port); sprintf(buffer, "iptables -A INPUT -s %s -p tcp --dport %d -j REJECT", client->sock->ip, g_tcp_port);
int s = system(buffer); int s = system(buffer);
stratumlog("%s: %s blocked (%s)\n", g_stratum_algo, client->sock->ip, reason);
}
stratumlog("%s %s blocked (%s)\n", client->sock->ip, client->username, reason); void client_block_ipset(YAAMP_CLIENT *client, const char *ipset_name)
{
char buffer[1024];
sprintf(buffer, "ipset -q -A %s %s", ipset_name, client->sock->ip);
int s = system(buffer);
stratumlog("%s: %s blocked via ipset %s\n", g_stratum_algo, client->sock->ip, ipset_name);
} }
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first) bool client_reset_multialgo(YAAMP_CLIENT *client, bool first)