added: to 'ipban' winix function:

possibility to remove a ban (or all bans)
added: to SessionManager: sorting of the ban list (in the second thread)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@903 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-10-27 09:03:49 +00:00
parent 099dd55d0c
commit 9ef3736989
11 changed files with 113 additions and 9 deletions

View File

@ -16,7 +16,7 @@
IPBanContainer::IPBanContainer()
{
is_ipban_tab_sorted = false;
is_ipban_tab_sorted = true; // an empty list is sorted
soft_max_size = 100;
max_size = 110;
}
@ -49,6 +49,7 @@ IPBan & IPBanContainer::AddIP(int ip)
RemoveOldRecords();
ipban_tab.push_back(ip_ban);
is_ipban_tab_sorted = false;
return ipban_tab.back();
}
else
@ -58,6 +59,31 @@ IPBan & IPBanContainer::AddIP(int ip)
}
void IPBanContainer::RemoveIP(int ip)
{
IPBan * ipban = FindIP(ip);
if( ipban )
{
size_t index = ipban - &ipban_tab[0];
ipban_tab.erase(ipban_tab.begin() + index);
}
}
bool IPBanContainer::IsSorted()
{
return is_ipban_tab_sorted;
}
void IPBanContainer::Clear()
{
ipban_tab.clear();
is_ipban_tab_sorted = true;
}
// we need to remove some old records for the size of the container
// to be less or equal to soft_max_size
void IPBanContainer::RemoveOldRecords()

View File

@ -27,7 +27,9 @@ public:
size_t Size();
IPBan & GetIPBan(size_t index);
void SetMaxSize(size_t soft_size, size_t size);
void RemoveIP(int ip);
void Clear();
bool IsSorted();
private:

View File

@ -234,6 +234,7 @@ PT::WTextStream IPToStr(unsigned int ip);
PT::WTextStream IPToStr(int ip);
bool IsWhite(wchar_t s);
bool IsWhite(const wchar_t * str, bool treat_new_line_as_white = false);
bool IsWhite(const std::wstring & str, bool treat_new_line_as_white = false);

View File

@ -460,8 +460,16 @@ IPBan & SessionManager::GetIPBan(size_t index)
}
void SessionManager::RemoveIPBan(int ip)
{
ban_tab.RemoveIP(ip);
}
void SessionManager::ClearIPBanList()
{
ban_tab.Clear();
}
/*
@ -488,6 +496,7 @@ SessionContainer::Iterator i;
{
Lock();
CheckWheterIPListIsSorted();
CheckSession(i);
exit = synchro->was_stop_signal;
@ -496,6 +505,17 @@ SessionContainer::Iterator i;
}
// objects locked
void SessionManager::CheckWheterIPListIsSorted()
{
if( !ban_tab.IsSorted() )
{
log << log4 << "SM: sorting the ban list" << logend;
ban_tab.Sort();
}
}
// it's called from the other thread (with Lock and Unlock)
void SessionManager::CheckSession(SessionContainer::Iterator & i)
{

View File

@ -62,7 +62,8 @@ public:
IPBan & AddIPToBanList(int ip);
size_t BanListSize();
IPBan & GetIPBan(size_t index);
void RemoveIPBan(int ip);
void ClearIPBanList();
private:
@ -96,6 +97,7 @@ private:
void CheckSession(SessionContainer::Iterator & i);
bool IsSessionOutdated(const Session & s) const;
void DeleteSession(Session * del_session);
void CheckWheterIPListIsSorted();
};

View File

@ -324,20 +324,40 @@ void System::RedirectWithFunctionAndParamsTo(const std::wstring & url)
}
void System::RedirectToLastDir()
void System::RedirectToLastDir(const wchar_t * postfix)
{
if( !cur->request->dir_tab.empty() )
RedirectTo( *cur->request->dir_tab.back() );
RedirectTo( *cur->request->dir_tab.back(), postfix );
}
void System::RedirectToLastItem()
void System::RedirectToLastItem(const wchar_t * postfix)
{
if( cur->request->last_item )
RedirectTo( *cur->request->last_item );
RedirectTo( *cur->request->last_item, postfix );
}
void System::RedirectToLastFunction(const wchar_t * postfix)
{
RedirectToLastDir();
if( cur->request->is_item )
{
cur->request->redirect_to += cur->request->item.url;
cur->request->redirect_to += '/';
}
if( cur->request->function )
cur->request->redirect_to += cur->request->function->fun.url;
if( postfix )
{
cur->request->redirect_to += '/';
cur->request->redirect_to += postfix;
}
}
bool System::CanChangeUser(const Item & item, long new_user_id)
{

View File

@ -96,8 +96,10 @@ public:
void RedirectTo(const std::wstring & url);
void RedirectWithFunctionAndParamsTo(const wchar_t * url);
void RedirectWithFunctionAndParamsTo(const std::wstring & url);
void RedirectToLastDir();
void RedirectToLastItem(); // redirect to an item if exists or to the last directory
void RedirectToLastDir(const wchar_t * postfix = 0);
void RedirectToLastItem(const wchar_t * postfix = 0); // redirect to an item if exists or to the last directory
void RedirectToLastFunction(const wchar_t * postfix = 0);
bool CanChangeUser(const Item & item, long new_user_id);
bool CanChangeGroup(const Item & item, long new_group_id);

View File

@ -7,8 +7,13 @@
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "ipban.h"
#include "functions.h"
#include "core/sessionmanager.h"
@ -28,15 +33,31 @@ bool IPBanFun::HasAccess()
}
void IPBanFun::MakePost()
{
}
void IPBanFun::MakeGet()
{
if( cur->request->IsParam(L"removeip") )
{
if( cur->request->ParamValue(L"removeip") == L"all" )
{
session_manager->ClearIPBanList();
}
else
{
AssignString(cur->request->ParamValue(L"removeip"), tmp_ip_str);
int ip = (int)inet_addr(tmp_ip_str.c_str());
session_manager->RemoveIPBan(ip);
}
system->RedirectToLastFunction();
}
}

View File

@ -28,6 +28,10 @@ public:
void MakePost();
void MakeGet();
private:
std::string tmp_ip_str;
};

View File

@ -49,6 +49,7 @@ private:
std::string pass_decrypted;
std::wstring pass_hashed;
std::wstring salt;
};

View File

@ -34,6 +34,11 @@
[end]
</table>
<p>
<a href="[doc_base_url][dir][if item_is][item_url]/[end]ipban/removeip:all">Remove all IP's from the list</a>
</p>
[else]
<p>There are not any IP addresses banned at the moment.</p>
[end]