Added a notify in SecurityIpItem when the ip address was added to the whitelist.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8355 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-06-03 15:14:26 +00:00
parent d959d27e41
commit fb28284be3
7 changed files with 45 additions and 19 deletions

View File

@ -90,8 +90,8 @@ public:
// 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;
virtual void removeIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type) =0;
virtual bool addIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type,const std::string& comment) =0;
virtual bool removeIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type) =0;
// isAddressAccepted()
// addr: full IPv4 address. Port is ignored.

View File

@ -357,10 +357,11 @@ void p3BanList::getBannedIps(std::list<BanListPeer> &lst)
lst.push_back(it->second) ;
}
void p3BanList::removeIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type)
bool p3BanList::removeIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type)
{
RS_STACK_MUTEX(mBanMtx) ;
bool changed = false;
std::map<sockaddr_storage,BanListPeer>::iterator it ;
if(list_type == RSBANLIST_TYPE_BLACKLIST)
@ -369,6 +370,7 @@ void p3BanList::removeIpRange(const struct sockaddr_storage& addr,int masked_byt
{
mBanRanges.erase(it) ;
IndicateConfigChanged();
changed = true;
}
}
else if(list_type == RSBANLIST_TYPE_WHITELIST)
@ -377,13 +379,16 @@ void p3BanList::removeIpRange(const struct sockaddr_storage& addr,int masked_byt
{
mWhiteListedRanges.erase(it) ;
IndicateConfigChanged();
changed = true;
}
}
else
std::cerr << "(EE) Only whitelist or blacklist ranges can be removed." << std::endl;
return changed;
}
void p3BanList::addIpRange(const sockaddr_storage &addr, int masked_bytes,uint32_t list_type,const std::string& comment)
bool p3BanList::addIpRange(const sockaddr_storage &addr, int masked_bytes,uint32_t list_type,const std::string& comment)
{
RS_STACK_MUTEX(mBanMtx) ;
@ -399,21 +404,31 @@ void p3BanList::addIpRange(const sockaddr_storage &addr, int masked_bytes,uint32
if(masked_bytes != 0 && masked_bytes != 1 && masked_bytes != 2)
{
std::cerr << "Unhandled masked byte size " << masked_bytes << ". Should be 0,1 or 2" << std::endl;
return ;
return false;
}
bool changed = false;
sockaddr_storage addrrange = makeBitsRange(addr,masked_bytes) ;
if(list_type == RSBANLIST_TYPE_BLACKLIST)
{
mBanRanges[addrrange] = blp ;
changed = true;
}
else if(list_type == RSBANLIST_TYPE_WHITELIST)
{
mWhiteListedRanges[addrrange] = blp ;
changed = true;
}
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;
if (changed)
IndicateConfigChanged() ;
condenseBanSources_locked() ;
return changed;
}
int p3BanList::tick()

View File

@ -66,8 +66,8 @@ public:
virtual void getBannedIps(std::list<BanListPeer>& list) ;
virtual void getWhiteListedIps(std::list<BanListPeer>& list) ;
virtual void addIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type,const std::string& comment) ;
virtual void removeIpRange(const sockaddr_storage &addr, int masked_bytes, uint32_t list_type);
virtual bool addIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type,const std::string& comment) ;
virtual bool removeIpRange(const sockaddr_storage &addr, int masked_bytes, uint32_t list_type);
virtual void enableIPFiltering(bool b) ;
virtual bool ipFilteringEnabled() ;

View File

@ -153,13 +153,18 @@ void RsBanListToolButton::applyIp()
}
masked_bytes = action->data().toUInt();
bool changed = false;
switch (mMode) {
case MODE_ADD:
rsBanList->addIpRange(addr, masked_bytes, list_type, "");
changed = rsBanList->addIpRange(addr, masked_bytes, list_type, "");
break;
case MODE_REMOVE:
rsBanList->removeIpRange(addr, masked_bytes, list_type);
changed = rsBanList->removeIpRange(addr, masked_bytes, list_type);
break;
}
if (changed) {
emit banListChanged();
}
}

View File

@ -46,6 +46,9 @@ public:
void setMode(List list, Mode mode);
bool setIpAddress(const QString &ipAddress);
signals:
void banListChanged();
private:
void updateUi();

View File

@ -67,9 +67,11 @@ void SecurityIpItem::setup()
/* specific ones */
connect(ui->peerDetailsButton, SIGNAL(clicked()), this, SLOT(peerDetails()));
connect(ui->rsBanListButton, SIGNAL(banListChanged()), ui->rsBanListChangedLabel, SLOT(show()));
ui->avatar->setId(ChatId(mSslId));
ui->rsBanListButton->setMode(RsBanListToolButton::LIST_WHITELIST, RsBanListToolButton::MODE_ADD);
ui->rsBanListChangedLabel->hide();
ui->expandFrame->hide();

View File

@ -159,6 +159,9 @@
</item>
<item row="1" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QToolButton" name="peerDetailsButton">
<property name="focusPolicy">
@ -204,6 +207,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="rsBanListChangedLabel">
<property name="text">
<string>IP addres was added to the whitelist</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -468,15 +478,6 @@
</widget>
</item>
</layout>
<action name="actionNew_Message">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/mail_send.png</normaloff>:/images/mail_send.png</iconset>
</property>
<property name="text">
<string>Write Message</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>