|
@@ -33,6 +33,7 @@ static char ipban_table[32] = "ipbanlist";
|
|
// globals
|
|
// globals
|
|
static Sql* sql_handle = NULL;
|
|
static Sql* sql_handle = NULL;
|
|
static int cleanup_timer_id = INVALID_TIMER;
|
|
static int cleanup_timer_id = INVALID_TIMER;
|
|
|
|
+static bool ipban_inited = false;
|
|
|
|
|
|
int ipban_cleanup(int tid, unsigned int tick, int id, intptr data);
|
|
int ipban_cleanup(int tid, unsigned int tick, int id, intptr data);
|
|
|
|
|
|
@@ -47,6 +48,11 @@ void ipban_init(void)
|
|
const char* database;
|
|
const char* database;
|
|
const char* codepage;
|
|
const char* codepage;
|
|
|
|
|
|
|
|
+ ipban_inited = true;
|
|
|
|
+
|
|
|
|
+ if( !login_config.ipban )
|
|
|
|
+ return;// ipban disabled
|
|
|
|
+
|
|
if( ipban_db_hostname[0] != '\0' )
|
|
if( ipban_db_hostname[0] != '\0' )
|
|
{// local settings
|
|
{// local settings
|
|
username = ipban_db_username;
|
|
username = ipban_db_username;
|
|
@@ -85,6 +91,9 @@ void ipban_init(void)
|
|
// finalize
|
|
// finalize
|
|
void ipban_final(void)
|
|
void ipban_final(void)
|
|
{
|
|
{
|
|
|
|
+ if( !login_config.ipban )
|
|
|
|
+ return;// ipban disabled
|
|
|
|
+
|
|
// release data
|
|
// release data
|
|
delete_timer(cleanup_timer_id, ipban_cleanup);
|
|
delete_timer(cleanup_timer_id, ipban_cleanup);
|
|
|
|
|
|
@@ -98,6 +107,9 @@ bool ipban_config_read(const char* key, const char* value)
|
|
{
|
|
{
|
|
const char* signature;
|
|
const char* signature;
|
|
|
|
|
|
|
|
+ if( ipban_inited )
|
|
|
|
+ return false;// settings can only be changed before init
|
|
|
|
+
|
|
signature = "sql.";
|
|
signature = "sql.";
|
|
if( strncmpi(key, signature, strlen(signature)) == 0 )
|
|
if( strncmpi(key, signature, strlen(signature)) == 0 )
|
|
{
|
|
{
|
|
@@ -186,6 +198,9 @@ bool ipban_check(uint32 ip)
|
|
char* data = NULL;
|
|
char* data = NULL;
|
|
int matches;
|
|
int matches;
|
|
|
|
|
|
|
|
+ if( !login_config.ipban )
|
|
|
|
+ return false;// ipban disabled
|
|
|
|
+
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u'",
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u'",
|
|
ipban_table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) )
|
|
ipban_table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) )
|
|
{
|
|
{
|
|
@@ -207,7 +222,12 @@ bool ipban_check(uint32 ip)
|
|
// log failed attempt
|
|
// log failed attempt
|
|
void ipban_log(uint32 ip)
|
|
void ipban_log(uint32 ip)
|
|
{
|
|
{
|
|
- unsigned long failures = loginlog_failedattempts(ip, login_config.dynamic_pass_failure_ban_interval);// how many times failed account? in one ip.
|
|
|
|
|
|
+ unsigned long failures;
|
|
|
|
+
|
|
|
|
+ if( !login_config.ipban )
|
|
|
|
+ return;// ipban disabled
|
|
|
|
+
|
|
|
|
+ failures = loginlog_failedattempts(ip, login_config.dynamic_pass_failure_ban_interval);// how many times failed account? in one ip.
|
|
|
|
|
|
// if over the limit, add a temporary ban entry
|
|
// if over the limit, add a temporary ban entry
|
|
if( failures >= login_config.dynamic_pass_failure_ban_limit )
|
|
if( failures >= login_config.dynamic_pass_failure_ban_limit )
|
|
@@ -222,6 +242,9 @@ void ipban_log(uint32 ip)
|
|
// remove expired bans
|
|
// remove expired bans
|
|
int ipban_cleanup(int tid, unsigned int tick, int id, intptr data)
|
|
int ipban_cleanup(int tid, unsigned int tick, int id, intptr data)
|
|
{
|
|
{
|
|
|
|
+ if( !login_config.ipban )
|
|
|
|
+ return 0;// ipban disabled
|
|
|
|
+
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") )
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ipbanlist` WHERE `rtime` <= NOW()") )
|
|
Sql_ShowDebug(sql_handle);
|
|
Sql_ShowDebug(sql_handle);
|
|
|
|
|