mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
add/remove from lists. Load/save from user whitelist/blacklist
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8321 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b2967418ff
commit
bb74d08f33
@ -54,6 +54,10 @@ extern RsBanList *rsBanList ;
|
||||
#define RSBANLIST_CHECK_RESULT_NOT_WHITELISTED 0x03
|
||||
#define RSBANLIST_CHECK_RESULT_ACCEPTED 0x04
|
||||
|
||||
#define RSBANLIST_TYPE_PEERLIST 1
|
||||
#define RSBANLIST_TYPE_BLACKLIST 2
|
||||
#define RSBANLIST_TYPE_WHITELIST 3
|
||||
|
||||
class RsTlvBanListEntry ;
|
||||
|
||||
class BanListPeer
|
||||
@ -83,7 +87,7 @@ public:
|
||||
// addIpRange()/removeIpRange()
|
||||
// addr: full IPv4 address. Port is ignored.
|
||||
// masked_bytes: 0=full IP, 1="/24", 2="/16"
|
||||
// list_type: RSBANLIST_CHECKING_FLAGS_BLACKLIST or RSBANLIST_CHECKING_FLAGS_WHITELIST
|
||||
// list_type: RSBANLIST_TYPE_WHITELIST or RSBANLIST_TYPE_BLACKLIST
|
||||
// comment: anything, user-based.
|
||||
|
||||
virtual void addIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type,const std::string& comment) =0;
|
||||
|
@ -67,6 +67,7 @@ uint32_t RsBanListSerialiser::sizeList(RsBanListItem *item)
|
||||
uint32_t RsBanListSerialiser::sizeListConfig(RsBanListConfigItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 4 ; // type
|
||||
s += item->banned_peers.TlvSize();
|
||||
s += 8 ; // update time
|
||||
s += item->peerId.serial_size() ;
|
||||
@ -132,6 +133,7 @@ bool RsBanListSerialiser::serialiseListConfig(RsBanListConfigItem *item, voi
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset,item->type);
|
||||
ok &= item->peerId.serialise(data, tlvsize, offset);
|
||||
ok &= setRawTimeT(data, tlvsize, &offset,item->update_time);
|
||||
|
||||
@ -228,6 +230,7 @@ RsBanListConfigItem *RsBanListSerialiser::deserialiseListConfig(void *data, uint
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt32(data, tlvsize, &offset,&item->type);
|
||||
ok &= item->peerId.deserialise(data, tlvsize, offset);
|
||||
ok &= getRawTimeT(data, tlvsize, &offset,item->update_time);
|
||||
|
||||
|
@ -32,9 +32,10 @@
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM 0x02
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM_deprecated 0x02
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM 0x04
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@ -67,7 +68,8 @@ public:
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPeerId peerId ;
|
||||
uint32_t type ;
|
||||
RsPeerId peerId ;
|
||||
time_t update_time ;
|
||||
RsTlvBanList banned_peers;
|
||||
};
|
||||
|
@ -341,7 +341,26 @@ void p3BanList::getBannedIps(std::list<BanListPeer> &lst)
|
||||
|
||||
void p3BanList::removeIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type)
|
||||
{
|
||||
#warning NOT IMPLEMENTED YET
|
||||
std::map<sockaddr_storage,BanListPeer>::iterator it ;
|
||||
|
||||
if(list_type == RSBANLIST_TYPE_BLACKLIST)
|
||||
{
|
||||
if( mBanRanges.end() != (it = mBanRanges.find(makeBitsRange(addr,masked_bytes))))
|
||||
{
|
||||
mBanRanges.erase(it) ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
else if(list_type == RSBANLIST_TYPE_WHITELIST)
|
||||
{
|
||||
if( mWhiteListedRanges.end() != (it = mWhiteListedRanges.find(makeBitsRange(addr,masked_bytes))))
|
||||
{
|
||||
mWhiteListedRanges.erase(it) ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
std::cerr << "(EE) Only whitelist or blacklist ranges can be removed." << std::endl;
|
||||
}
|
||||
|
||||
void p3BanList::addIpRange(const sockaddr_storage &addr, int masked_bytes,uint32_t list_type,const std::string& comment)
|
||||
@ -365,9 +384,9 @@ void p3BanList::addIpRange(const sockaddr_storage &addr, int masked_bytes,uint32
|
||||
|
||||
sockaddr_storage addrrange = makeBitsRange(addr,masked_bytes) ;
|
||||
|
||||
if(list_type == RSBANLIST_CHECKING_FLAGS_BLACKLIST)
|
||||
if(list_type == RSBANLIST_TYPE_BLACKLIST)
|
||||
mBanRanges[addrrange] = blp ;
|
||||
else if(list_type == RSBANLIST_CHECKING_FLAGS_WHITELIST)
|
||||
else if(list_type == RSBANLIST_TYPE_WHITELIST)
|
||||
mWhiteListedRanges[addrrange] = blp ;
|
||||
else
|
||||
std::cerr << "(EE) Cannot add IP range. Bad list_type. Should be eiter RSBANLIST_CHECKING_FLAGS_BLACKLIST or RSBANLIST_CHECKING_FLAGS_WHITELIST" << std::endl;
|
||||
@ -534,6 +553,7 @@ bool p3BanList::saveList(bool &cleanup, std::list<RsItem*>& itemlist)
|
||||
{
|
||||
RsBanListConfigItem *item = new RsBanListConfigItem ;
|
||||
|
||||
item->type = RSBANLIST_TYPE_PEERLIST ;
|
||||
item->peerId = it->second.mPeerId ;
|
||||
item->update_time = it->second.mLastUpdate ;
|
||||
item->banned_peers.TlvClear() ;
|
||||
@ -549,6 +569,45 @@ bool p3BanList::saveList(bool &cleanup, std::list<RsItem*>& itemlist)
|
||||
itemlist.push_back(item) ;
|
||||
}
|
||||
|
||||
// Add whitelist
|
||||
RsBanListConfigItem *item = new RsBanListConfigItem ;
|
||||
|
||||
item->type = RSBANLIST_TYPE_WHITELIST ;
|
||||
item->peerId.clear() ;
|
||||
item->update_time = 0 ;
|
||||
item->banned_peers.TlvClear() ;
|
||||
|
||||
for(std::map<sockaddr_storage,BanListPeer>::const_iterator it2 = mWhiteListedRanges.begin();it2!=mWhiteListedRanges.end();++it2)
|
||||
{
|
||||
RsTlvBanListEntry e ;
|
||||
it2->second.toRsTlvBanListEntry(e) ;
|
||||
|
||||
item->banned_peers.mList.push_back(e) ;
|
||||
}
|
||||
|
||||
itemlist.push_back(item) ;
|
||||
|
||||
// addblacklist
|
||||
|
||||
item = new RsBanListConfigItem ;
|
||||
|
||||
item->type = RSBANLIST_TYPE_BLACKLIST ;
|
||||
item->peerId.clear();
|
||||
item->update_time = 0 ;
|
||||
item->banned_peers.TlvClear() ;
|
||||
|
||||
for(std::map<sockaddr_storage,BanListPeer>::const_iterator it2 = mBanRanges.begin();it2!=mBanRanges.end();++it2)
|
||||
{
|
||||
RsTlvBanListEntry e ;
|
||||
it2->second.toRsTlvBanListEntry(e) ;
|
||||
|
||||
item->banned_peers.mList.push_back(e) ;
|
||||
}
|
||||
|
||||
itemlist.push_back(item) ;
|
||||
|
||||
// Other variables
|
||||
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
@ -593,22 +652,51 @@ bool p3BanList::loadList(std::list<RsItem*>& load)
|
||||
|
||||
RsBanListConfigItem *citem = dynamic_cast<RsBanListConfigItem*>( *it ) ;
|
||||
|
||||
if(citem != NULL)
|
||||
if(citem != NULL)
|
||||
{
|
||||
BanList& bl(mBanSources[citem->peerId]) ;
|
||||
|
||||
bl.mPeerId = citem->peerId ;
|
||||
bl.mLastUpdate = citem->update_time ;
|
||||
|
||||
bl.mBanPeers.clear() ;
|
||||
|
||||
for(std::list<RsTlvBanListEntry>::const_iterator it2(citem->banned_peers.mList.begin());it2!=citem->banned_peers.mList.end();++it2)
|
||||
if(citem->type == RSBANLIST_TYPE_PEERLIST)
|
||||
{
|
||||
BanListPeer blp ;
|
||||
blp.fromRsTlvBanListEntry(*it2) ;
|
||||
BanList& bl(mBanSources[citem->peerId]) ;
|
||||
|
||||
bl.mBanPeers[blp.addr] = blp ;
|
||||
bl.mPeerId = citem->peerId ;
|
||||
bl.mLastUpdate = citem->update_time ;
|
||||
|
||||
bl.mBanPeers.clear() ;
|
||||
|
||||
for(std::list<RsTlvBanListEntry>::const_iterator it2(citem->banned_peers.mList.begin());it2!=citem->banned_peers.mList.end();++it2)
|
||||
{
|
||||
BanListPeer blp ;
|
||||
blp.fromRsTlvBanListEntry(*it2) ;
|
||||
|
||||
bl.mBanPeers[blp.addr] = blp ;
|
||||
}
|
||||
}
|
||||
else if(citem->type == RSBANLIST_TYPE_BLACKLIST)
|
||||
{
|
||||
mBanRanges.clear() ;
|
||||
|
||||
for(std::list<RsTlvBanListEntry>::const_iterator it2(citem->banned_peers.mList.begin());it2!=citem->banned_peers.mList.end();++it2)
|
||||
{
|
||||
BanListPeer blp ;
|
||||
blp.fromRsTlvBanListEntry(*it2) ;
|
||||
|
||||
mBanRanges[blp.addr] = blp ;
|
||||
}
|
||||
}
|
||||
else if(citem->type == RSBANLIST_TYPE_WHITELIST)
|
||||
{
|
||||
mWhiteListedRanges.clear() ;
|
||||
|
||||
for(std::list<RsTlvBanListEntry>::const_iterator it2(citem->banned_peers.mList.begin());it2!=citem->banned_peers.mList.end();++it2)
|
||||
{
|
||||
BanListPeer blp ;
|
||||
blp.fromRsTlvBanListEntry(*it2) ;
|
||||
|
||||
mWhiteListedRanges[blp.addr] = blp ;
|
||||
}
|
||||
}
|
||||
else
|
||||
std::cerr << "(EE) BanList item unknown type " << citem->type << ". This is a bug." << std::endl;
|
||||
}
|
||||
|
||||
delete *it ;
|
||||
|
@ -184,7 +184,7 @@ void ServerPage::addIpRangeToBlackList()
|
||||
|
||||
bytes = 4 - ui.ipInputRange_SB->value()/8;
|
||||
|
||||
rsBanList->addIpRange(addr,bytes, RSBANLIST_CHECKING_FLAGS_BLACKLIST,ui.ipInputComment_LE->text().toStdString());
|
||||
rsBanList->addIpRange(addr,bytes, RSBANLIST_TYPE_BLACKLIST,ui.ipInputComment_LE->text().toStdString());
|
||||
}
|
||||
|
||||
void ServerPage::addIpRangeToWhiteList()
|
||||
@ -198,7 +198,7 @@ void ServerPage::addIpRangeToWhiteList()
|
||||
|
||||
bytes = 4 - ui.ipInputRange_SB->value()/8;
|
||||
|
||||
rsBanList->addIpRange(addr,bytes, RSBANLIST_CHECKING_FLAGS_WHITELIST,ui.ipInputComment_LE->text().toStdString());
|
||||
rsBanList->addIpRange(addr,bytes, RSBANLIST_TYPE_WHITELIST,ui.ipInputComment_LE->text().toStdString());
|
||||
}
|
||||
|
||||
void ServerPage::clearKnownAddressList()
|
||||
@ -510,7 +510,7 @@ void ServerPage::ipFilterContextMenu(const QPoint& point)
|
||||
|
||||
bool status = item->data(Qt::UserRole).toBool();
|
||||
|
||||
contextMenu.addAction(tr("Remove"),this,SLOT(removeBannedIp()))->setEnabled(false) ;
|
||||
contextMenu.addAction(tr("Remove"),this,SLOT(removeBannedIp()));
|
||||
|
||||
QString addr_string = ui.filteredIpsTable->item(row,COLUMN_RANGE)->text() ;
|
||||
|
||||
@ -562,6 +562,26 @@ bool ServerPage::removeCurrentRowFromBlackList(sockaddr_storage& collected_addr,
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
bool ServerPage::removeCurrentRowFromWhiteList(sockaddr_storage& collected_addr,int &masked_bytes)
|
||||
{
|
||||
int row = ui.whiteListIpsTable->currentRow();
|
||||
QTableWidgetItem *item = ui.whiteListIpsTable->item(row, COLUMN_STATUS);
|
||||
|
||||
if(item == NULL)
|
||||
return false;
|
||||
|
||||
QString addr_string = ui.whiteListIpsTable->item(row,COLUMN_RANGE)->text() ;
|
||||
|
||||
if(!parseAddrFromQString(addr_string,collected_addr,masked_bytes))
|
||||
{
|
||||
std::cerr <<"Cannot parse IP \"" << addr_string.toStdString() << "\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
rsBanList->removeIpRange(collected_addr,masked_bytes,RSBANLIST_TYPE_WHITELIST);
|
||||
return true ;
|
||||
}
|
||||
|
||||
void ServerPage::moveToWhiteList0()
|
||||
{
|
||||
sockaddr_storage addr ;
|
||||
@ -569,7 +589,7 @@ void ServerPage::moveToWhiteList0()
|
||||
|
||||
removeCurrentRowFromBlackList(addr,bytes) ;
|
||||
|
||||
rsBanList->addIpRange(addr,0,RSBANLIST_CHECKING_FLAGS_WHITELIST, tr("Added by you").toStdString());
|
||||
rsBanList->addIpRange(addr,0,RSBANLIST_TYPE_WHITELIST, tr("Added by you").toStdString());
|
||||
}
|
||||
void ServerPage::moveToWhiteList1()
|
||||
{
|
||||
@ -578,7 +598,7 @@ void ServerPage::moveToWhiteList1()
|
||||
|
||||
removeCurrentRowFromBlackList(addr,bytes) ;
|
||||
|
||||
rsBanList->addIpRange(addr,1,RSBANLIST_CHECKING_FLAGS_WHITELIST, tr("Added by you").toStdString());
|
||||
rsBanList->addIpRange(addr,1,RSBANLIST_TYPE_WHITELIST, tr("Added by you").toStdString());
|
||||
}
|
||||
void ServerPage::moveToWhiteList2()
|
||||
{
|
||||
@ -587,7 +607,7 @@ void ServerPage::moveToWhiteList2()
|
||||
|
||||
removeCurrentRowFromBlackList(addr,bytes) ;
|
||||
|
||||
rsBanList->addIpRange(addr,2,RSBANLIST_CHECKING_FLAGS_WHITELIST, tr("Added by you").toStdString());
|
||||
rsBanList->addIpRange(addr,2,RSBANLIST_TYPE_WHITELIST, tr("Added by you").toStdString());
|
||||
}
|
||||
void ServerPage::ipWhiteListContextMenu(const QPoint& point)
|
||||
{
|
||||
@ -601,8 +621,7 @@ void ServerPage::ipWhiteListContextMenu(const QPoint& point)
|
||||
|
||||
bool status = item->data(Qt::UserRole).toBool();
|
||||
|
||||
if(!status)
|
||||
contextMenu.addAction(tr("Remove"),this,SLOT(removeWhiteListedIp()))->setEnabled(false) ;
|
||||
contextMenu.addAction(tr("Remove"),this,SLOT(removeWhiteListedIp()));
|
||||
|
||||
QString addr_string = ui.whiteListIpsTable->item(row,COLUMN_RANGE)->text() ;
|
||||
|
||||
@ -628,13 +647,17 @@ void ServerPage::ipWhiteListContextMenu(const QPoint& point)
|
||||
}
|
||||
void ServerPage::removeBannedIp()
|
||||
{
|
||||
#warning UNIMPLEMENTED CODE
|
||||
std::cerr << "Removing banned IP" << std::endl;
|
||||
sockaddr_storage addr;
|
||||
int bytes ;
|
||||
|
||||
removeCurrentRowFromBlackList(addr,bytes) ;
|
||||
}
|
||||
void ServerPage::removeWhiteListedIp()
|
||||
{
|
||||
#warning UNIMPLEMENTED CODE
|
||||
std::cerr << "Removing White-Listed IP" << std::endl;
|
||||
sockaddr_storage addr;
|
||||
int bytes ;
|
||||
|
||||
removeCurrentRowFromWhiteList(addr,bytes) ;
|
||||
}
|
||||
void ServerPage::enableBannedIp()
|
||||
{
|
||||
|
@ -81,6 +81,7 @@ private:
|
||||
// Alternative Versions for HiddenNode Mode.
|
||||
void addPeerToIPTable(QTableWidget *table, int row, const BanListPeer &blp);
|
||||
bool removeCurrentRowFromBlackList(sockaddr_storage& collected_addr,int& masked_bytes);
|
||||
bool removeCurrentRowFromWhiteList(sockaddr_storage &collected_addr, int &masked_bytes);
|
||||
void loadHiddenNode();
|
||||
void updateStatusHiddenNode();
|
||||
void saveAddressesHiddenNode();
|
||||
|
Loading…
Reference in New Issue
Block a user