diff --git a/swad_changelog.h b/swad_changelog.h index b81bb2647..1361c2a45 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -386,10 +386,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.40 (2019-02-13)" +#define Log_PLATFORM_VERSION "SWAD 18.40.1 (2019-02-13)" #define CSS_FILE "swad18.33.css" #define JS_FILE "swad18.32.1.js" /* + Version 18.40.1: Feb 13, 2019 Code refactorization in firewall. (239201 lines) Version 18.40: Feb 13, 2019 New table for banned IPs to mitigate DoS attacks. (239198 lines) 2 changes necessary in database: RENAME TABLE firewall TO firewall_log; diff --git a/swad_firewall.c b/swad_firewall.c index 5b61c5d26..ec2784ad9 100644 --- a/swad_firewall.c +++ b/swad_firewall.c @@ -58,6 +58,8 @@ extern struct Globals Gbl; static void FW_BanIP (void); +static void FW_WriteHTML (const char *Title,const char *H1); + /*****************************************************************************/ /************************** Log access into firewall *************************/ /*****************************************************************************/ @@ -108,15 +110,8 @@ void FW_CheckFirewallAndExitIfBanned (void) { /* Return status 403 Forbidden */ fprintf (stdout,"Content-Type: text/html; charset=windows-1252\n" - "Status: 403\r\n\r\n" - "" - "" - "Forbidden" - "" - "" - "

You are banned temporarily

" - "" - "\n"); + "Status: 403\r\n\r\n"); + FW_WriteHTML ("Forbidden","You are temporarily banned"); /* Close database connection and exit */ DB_CloseDBConnection (); @@ -152,16 +147,9 @@ void FW_CheckFirewallAndExitIfTooManyRequests (void) /* Return status 429 Too Many Requests */ fprintf (stdout,"Content-Type: text/html; charset=windows-1252\n" "Retry-After: %lu\n" - "Status: 429\r\n\r\n" - "" - "" - "Too Many Requests" - "" - "" - "

Please stop that

" - "" - "\n", + "Status: 429\r\n\r\n", (unsigned long) Fw_TIME_BANNED); + FW_WriteHTML ("Too Many Requests","Please stop that"); /* Close database connection and exit */ DB_CloseDBConnection (); @@ -183,3 +171,20 @@ static void FW_BanIP (void) " ('%s',NOW(),FROM_UNIXTIME(UNIX_TIMESTAMP()+%lu))", Gbl.IP,(unsigned long) Fw_TIME_BANNED); } + +/*****************************************************************************/ +/********************************* Ban an IP *********************************/ +/*****************************************************************************/ + +static void FW_WriteHTML (const char *Title,const char *H1) + { + fprintf (stdout,"" + "" + "%s" + "" + "" + "

%s

" + "" + "\n", + Title,H1); + }