winix/templates/ipban.cpp

124 lines
2.3 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2012, Tomasz Sowa
* All rights reserved.
*
*/
#include "templates.h"
#include "core/request.h"
#include "core/misc.h"
#include "functions/functions.h"
namespace TemplatesFunctions
{
static size_t ipban_index;
void ipban_tab(Info & i)
{
ipban_index = i.iter;
i.res = ipban_index < session_manager->BanListSize();
}
void ipban_tab_id(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
i.out << ipban_index;
}
void ipban_tab_ip(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
{
PT::WTextStream buf = IPToStr(session_manager->GetIPBan(ipban_index).ip);
i.out << buf;
}
}
void ipban_tab_incorrect_login(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
i.out << session_manager->GetIPBan(ipban_index).incorrect_login_events;
}
void ipban_tab_ban_level(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
{
IPBan & ipban = session_manager->GetIPBan(ipban_index);
if( ipban.HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL3) )
i.out << "3";
else
if( ipban.HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL2) )
i.out << "2";
else
if( ipban.HasFlag(WINIX_IPBAN_FLAG_BAN_LEVEL1) )
i.out << "1";
}
}
void ipban_tab_has_active_flag(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
i.res = session_manager->GetIPBan(ipban_index).HasFlag(WINIX_IPBAN_FLAG_ACTIVE);
}
void ipban_tab_expires(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
{
IPBan & ipban = session_manager->GetIPBan(ipban_index);
if( ipban.expires != 0 )
{
time_t expires_local = system->ToLocal(ipban.expires);
PT::Date date(expires_local);
i.out << date;
}
}
}
void ipban_tab_last_used(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
{
IPBan & ipban = session_manager->GetIPBan(ipban_index);
if( ipban.last_used != 0 )
{
time_t last_used_local = system->ToLocal(ipban.last_used);
PT::Date date(last_used_local);
i.out << date;
}
}
}
void ipban_tab_is_logging_allowed(Info & i)
{
if( ipban_index < session_manager->BanListSize() )
{
IPBan & ipban = session_manager->GetIPBan(ipban_index);
i.res = !functions->fun_login.CannotLoginFrom(ipban);
}
}
} // namespace TemplatesFunctions