load/save of banlist comments. Removed unused menu entries. Added auto-fill of input fields on sleection

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8343 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-06-02 13:02:20 +00:00
parent 25c0dfe69e
commit 777c915be2
7 changed files with 74 additions and 26 deletions

View File

@ -43,7 +43,8 @@ void RsTlvBanListEntry::TlvClear()
addr.TlvClear(); addr.TlvClear();
level = 0; level = 0;
reason = 0; reason = 0;
age = 0; age = 0;
comment.clear();
} }
uint32_t RsTlvBanListEntry::TlvSize() const uint32_t RsTlvBanListEntry::TlvSize() const
@ -55,6 +56,7 @@ uint32_t RsTlvBanListEntry::TlvSize() const
s += 4; // reason; s += 4; // reason;
s += 4; // age; s += 4; // age;
s += 1; // masked_bytes; s += 1; // masked_bytes;
s += GetTlvStringSize(comment) ;
return s; return s;
@ -81,6 +83,7 @@ bool RsTlvBanListEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) con
ok &= setRawUInt32(data, tlvend, offset, reason); ok &= setRawUInt32(data, tlvend, offset, reason);
ok &= setRawUInt32(data, tlvend, offset, age); ok &= setRawUInt32(data, tlvend, offset, age);
ok &= setRawUInt8(data, tlvend, offset, masked_bytes); ok &= setRawUInt8(data, tlvend, offset, masked_bytes);
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_COMMENT, comment);
return ok; return ok;
@ -118,6 +121,7 @@ bool RsTlvBanListEntry::GetTlv(void *data, uint32_t size, uint32_t *offset)
uint8_t tmp ; uint8_t tmp ;
ok &= getRawUInt8(data, tlvend, offset, &(tmp)); ok &= getRawUInt8(data, tlvend, offset, &(tmp));
masked_bytes = tmp ; masked_bytes = tmp ;
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_COMMENT, comment);
/*************************************************************************** /***************************************************************************
* NB: extra components could be added (for future expansion of the type). * NB: extra components could be added (for future expansion of the type).

View File

@ -52,6 +52,7 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
uint32_t reason; uint32_t reason;
uint32_t age; uint32_t age;
uint8_t masked_bytes ; uint8_t masked_bytes ;
std::string comment ;
}; };
typedef t_RsTlvList<RsTlvBanListEntry,TLV_TYPE_BAN_LIST> RsTlvBanList; typedef t_RsTlvList<RsTlvBanListEntry,TLV_TYPE_BAN_LIST> RsTlvBanList;

View File

@ -226,7 +226,8 @@ const uint16_t TLV_TYPE_DSDV_ENDPOINT = 0x1080;
const uint16_t TLV_TYPE_DSDV_ENTRY = 0x1081; const uint16_t TLV_TYPE_DSDV_ENTRY = 0x1081;
const uint16_t TLV_TYPE_DSDV_ENTRY_SET= 0x1082; const uint16_t TLV_TYPE_DSDV_ENTRY_SET= 0x1082;
const uint16_t TLV_TYPE_BAN_ENTRY = 0x1090; const uint16_t TLV_TYPE_BAN_ENTRY_dep = 0x1090;
const uint16_t TLV_TYPE_BAN_ENTRY = 0x1092;
const uint16_t TLV_TYPE_BAN_LIST = 0x1091; const uint16_t TLV_TYPE_BAN_LIST = 0x1091;
const uint16_t TLV_TYPE_MSG_ADDRESS = 0x10A0; const uint16_t TLV_TYPE_MSG_ADDRESS = 0x10A0;

View File

@ -141,9 +141,10 @@ BanListPeer::BanListPeer()
void BanListPeer::toRsTlvBanListEntry(RsTlvBanListEntry &e) const void BanListPeer::toRsTlvBanListEntry(RsTlvBanListEntry &e) const
{ {
e.addr.addr = addr; e.addr.addr = addr;
e.level = level;
e.reason = reason;
e.masked_bytes = masked_bytes; e.masked_bytes = masked_bytes;
e.reason = reason;
e.level = level;
e.comment = comment;
e.age = time(NULL) - mTs; e.age = time(NULL) - mTs;
} }
@ -155,8 +156,8 @@ void BanListPeer::fromRsTlvBanListEntry(const RsTlvBanListEntry &e)
level = e.level; // LOCAL, FRIEND, FoF. level = e.level; // LOCAL, FRIEND, FoF.
state = true; // true=>active, false=>just stored but inactive state = true; // true=>active, false=>just stored but inactive
connect_attempts = 0; // recorded by the BanList service connect_attempts = 0; // recorded by the BanList service
comment = e.comment; // recorded by the BanList service
mTs = time(NULL) - e.age; mTs = time(NULL) - e.age;
comment.clear() ; //
} }
static sockaddr_storage makeBitsRange(const sockaddr_storage& addr,int masked_bytes) static sockaddr_storage makeBitsRange(const sockaddr_storage& addr,int masked_bytes)
@ -409,6 +410,8 @@ void p3BanList::addIpRange(const sockaddr_storage &addr, int masked_bytes,uint32
std::cerr << "(EE) Cannot add IP range. Bad list_type. Should be eiter RSBANLIST_CHECKING_FLAGS_BLACKLIST or RSBANLIST_CHECKING_FLAGS_WHITELIST" << std::endl; std::cerr << "(EE) Cannot add IP range. Bad list_type. Should be eiter RSBANLIST_CHECKING_FLAGS_BLACKLIST or RSBANLIST_CHECKING_FLAGS_WHITELIST" << std::endl;
IndicateConfigChanged() ; IndicateConfigChanged() ;
condenseBanSources_locked() ;
} }
int p3BanList::tick() int p3BanList::tick()
@ -1026,6 +1029,7 @@ int p3BanList::sendBanSet(const RsPeerId& peerid)
RsTlvBanListEntry bi; RsTlvBanListEntry bi;
it->second.toRsTlvBanListEntry(bi) ; it->second.toRsTlvBanListEntry(bi) ;
bi.comment.clear() ; // don't send comments.
item->peerList.mList.push_back(bi); item->peerList.mList.push_back(bi);
} }
} }

View File

@ -69,7 +69,10 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_ORIGIN,new QTableWidgetItem(tr("Origin"))) ; ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_ORIGIN,new QTableWidgetItem(tr("Origin"))) ;
ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_COMMENT,new QTableWidgetItem(tr("Comment"))) ; ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_COMMENT,new QTableWidgetItem(tr("Comment"))) ;
ui.filteredIpsTable->setColumnHidden(COLUMN_STATUS,true) ;
ui.filteredIpsTable->verticalHeader()->hide() ; ui.filteredIpsTable->verticalHeader()->hide() ;
ui.whiteListIpsTable->setColumnHidden(COLUMN_STATUS,true) ;
ui.whiteListIpsTable->verticalHeader()->hide() ;
QObject::connect(ui.filteredIpsTable,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(ipFilterContextMenu(const QPoint&))) ; QObject::connect(ui.filteredIpsTable,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(ipFilterContextMenu(const QPoint&))) ;
QObject::connect(ui.whiteListIpsTable,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(ipWhiteListContextMenu(const QPoint&))) ; QObject::connect(ui.whiteListIpsTable,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(ipWhiteListContextMenu(const QPoint&))) ;
@ -81,6 +84,8 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
QObject::connect(ui.ipInputAddBlackList_PB,SIGNAL(clicked()),this,SLOT(addIpRangeToBlackList())); QObject::connect(ui.ipInputAddBlackList_PB,SIGNAL(clicked()),this,SLOT(addIpRangeToBlackList()));
QObject::connect(ui.ipInputAddWhiteList_PB,SIGNAL(clicked()),this,SLOT(addIpRangeToWhiteList())); QObject::connect(ui.ipInputAddWhiteList_PB,SIGNAL(clicked()),this,SLOT(addIpRangeToWhiteList()));
QObject::connect(ui.ipInput_LE,SIGNAL(textChanged(const QString&)),this,SLOT(checkIpRange(const QString&))); QObject::connect(ui.ipInput_LE,SIGNAL(textChanged(const QString&)),this,SLOT(checkIpRange(const QString&)));
QObject::connect(ui.filteredIpsTable,SIGNAL(currentCellChanged(int,int,int,int)),this,SLOT(updateSelectedBlackListIP(int,int,int,int)));
QObject::connect(ui.whiteListIpsTable,SIGNAL(currentCellChanged(int,int,int,int)),this,SLOT(updateSelectedWhiteListIP(int,int,int,int)));
QTimer *timer = new QTimer(this); QTimer *timer = new QTimer(this);
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus())); timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
@ -440,6 +445,9 @@ void ServerPage::loadFilteredIps()
ui.groupIPRanges_CB->setChecked(rsBanList->autoRangeEnabled()) ; ui.groupIPRanges_CB->setChecked(rsBanList->autoRangeEnabled()) ;
ui.groupIPRanges_SB->setValue(rsBanList->autoRangeLimit()) ; ui.groupIPRanges_SB->setValue(rsBanList->autoRangeLimit()) ;
ui.whiteListIpsTable->setColumnHidden(COLUMN_STATUS,true);
ui.filteredIpsTable->setColumnHidden(COLUMN_STATUS,true);
std::list<BanListPeer> lst ; std::list<BanListPeer> lst ;
rsBanList->getBannedIps(lst) ; rsBanList->getBannedIps(lst) ;
@ -456,6 +464,40 @@ void ServerPage::loadFilteredIps()
for(std::list<BanListPeer>::const_iterator it(lst.begin());it!=lst.end();++it,++row) for(std::list<BanListPeer>::const_iterator it(lst.begin());it!=lst.end();++it,++row)
addPeerToIPTable(ui.whiteListIpsTable,row,*it) ; addPeerToIPTable(ui.whiteListIpsTable,row,*it) ;
} }
void ServerPage::updateSelectedBlackListIP(int row,int,int,int)
{
QString addr_string = ui.filteredIpsTable->item(row,COLUMN_RANGE)->text() ;
sockaddr_storage addr ;
int masked_bytes ;
if(!parseAddrFromQString(addr_string,addr,masked_bytes))
{
std::cerr <<"Cannot parse IP \"" << addr_string.toStdString() << "\"" << std::endl;
return ;
}
ui.ipInput_LE->setText(QString::fromStdString(sockaddr_storage_iptostring(addr))) ;
ui.ipInputRange_SB->setValue(32 - 8*masked_bytes) ;
ui.ipInputComment_LE->setText(ui.filteredIpsTable->item(row,COLUMN_COMMENT)->text()) ;
}
void ServerPage::updateSelectedWhiteListIP(int row, int,int,int)
{
QString addr_string = ui.whiteListIpsTable->item(row,COLUMN_RANGE)->text() ;
sockaddr_storage addr ;
int masked_bytes ;
if(!parseAddrFromQString(addr_string,addr,masked_bytes))
{
std::cerr <<"Cannot parse IP \"" << addr_string.toStdString() << "\"" << std::endl;
return ;
}
ui.ipInput_LE->setText(QString::fromStdString(sockaddr_storage_iptostring(addr))) ;
ui.ipInputRange_SB->setValue(32 - 8*masked_bytes) ;
ui.ipInputComment_LE->setText(ui.whiteListIpsTable->item(row,COLUMN_COMMENT)->text()) ;
}
void ServerPage::addPeerToIPTable(QTableWidget *table,int row,const BanListPeer& blp) void ServerPage::addPeerToIPTable(QTableWidget *table,int row,const BanListPeer& blp)
{ {
@ -515,7 +557,7 @@ void ServerPage::ipFilterContextMenu(const QPoint& point)
bool status = item->data(Qt::UserRole).toBool(); bool status = item->data(Qt::UserRole).toBool();
contextMenu.addAction(tr("Remove"),this,SLOT(removeBannedIp())); uint32_t reason = ui.filteredIpsTable->item(row,COLUMN_REASON)->data(Qt::UserRole).toUInt();
QString addr_string = ui.filteredIpsTable->item(row,COLUMN_RANGE)->text() ; QString addr_string = ui.filteredIpsTable->item(row,COLUMN_RANGE)->text() ;
@ -532,14 +574,8 @@ void ServerPage::ipFilterContextMenu(const QPoint& point)
QString range1 = QString::fromStdString(print_addr_range(addr,1)) ; QString range1 = QString::fromStdString(print_addr_range(addr,1)) ;
QString range2 = QString::fromStdString(print_addr_range(addr,2)) ; QString range2 = QString::fromStdString(print_addr_range(addr,2)) ;
if(masked_bytes != 0) if(reason == RSBANLIST_REASON_USER)
contextMenu.addAction(QObject::tr("Ban only IP %1").arg(range0),this,SLOT(enableBannedIp()))->setEnabled(false) ; contextMenu.addAction(tr("Remove"),this,SLOT(removeBannedIp()));
if(masked_bytes != 1)
contextMenu.addAction(QObject::tr("Ban entire range %2").arg(range1),this,SLOT(enableBannedIp()))->setEnabled(false) ;
if(masked_bytes != 2)
contextMenu.addAction(QObject::tr("Ban entire range %1").arg(range2),this,SLOT(enableBannedIp()))->setEnabled(false) ;
contextMenu.addAction(QObject::tr("Move IP %1 to whitelist" ).arg(range0),this,SLOT(moveToWhiteList0())) ; contextMenu.addAction(QObject::tr("Move IP %1 to whitelist" ).arg(range0),this,SLOT(moveToWhiteList0())) ;
contextMenu.addAction(QObject::tr("Whitelist entire range %1").arg(range1),this,SLOT(moveToWhiteList1())) ; contextMenu.addAction(QObject::tr("Whitelist entire range %1").arg(range1),this,SLOT(moveToWhiteList1())) ;
@ -646,10 +682,10 @@ void ServerPage::ipWhiteListContextMenu(const QPoint& point)
QString range1 = QString::fromStdString(print_addr_range(addr,1)) ; QString range1 = QString::fromStdString(print_addr_range(addr,1)) ;
QString range2 = QString::fromStdString(print_addr_range(addr,2)) ; QString range2 = QString::fromStdString(print_addr_range(addr,2)) ;
contextMenu.addAction(QObject::tr("Whitelist only IP " )+range0,this,SLOT(enableBannedIp()))->setEnabled(false) ; // contextMenu.addAction(QObject::tr("Whitelist only IP " )+range0,this,SLOT(enableBannedIp()))->setEnabled(false) ;
#warning UNIMPLEMENTED CODE //#warning UNIMPLEMENTED CODE
contextMenu.addAction(QObject::tr("Whitelist entire range ")+range1,this,SLOT(enableBannedIp()))->setEnabled(false) ; // contextMenu.addAction(QObject::tr("Whitelist entire range ")+range1,this,SLOT(enableBannedIp()))->setEnabled(false) ;
contextMenu.addAction(QObject::tr("Whitelist entire range ")+range2,this,SLOT(enableBannedIp()))->setEnabled(false) ; // contextMenu.addAction(QObject::tr("Whitelist entire range ")+range2,this,SLOT(enableBannedIp()))->setEnabled(false) ;
contextMenu.exec(QCursor::pos()) ; contextMenu.exec(QCursor::pos()) ;
} }
@ -667,11 +703,6 @@ void ServerPage::removeWhiteListedIp()
removeCurrentRowFromWhiteList(addr,bytes) ; removeCurrentRowFromWhiteList(addr,bytes) ;
} }
void ServerPage::enableBannedIp()
{
#warning UNIMPLEMENTED CODE
std::cerr << "Removing banned IP" << std::endl;
}
/** Loads the settings for this page */ /** Loads the settings for this page */
void ServerPage::updateStatus() void ServerPage::updateStatus()

View File

@ -52,6 +52,8 @@ public slots:
void updateStatus(); void updateStatus();
private slots: private slots:
void updateSelectedBlackListIP(int row, int, int, int);
void updateSelectedWhiteListIP(int row,int,int,int);
void addIpRangeToBlackList(); void addIpRangeToBlackList();
void addIpRangeToWhiteList(); void addIpRangeToWhiteList();
void moveToWhiteList0(); void moveToWhiteList0();
@ -67,7 +69,6 @@ private slots:
void ipFilterContextMenu(const QPoint &); void ipFilterContextMenu(const QPoint &);
void ipWhiteListContextMenu(const QPoint &point); void ipWhiteListContextMenu(const QPoint &point);
void removeBannedIp(); void removeBannedIp();
void enableBannedIp();
void saveAddresses(); void saveAddresses();
void toggleUPnP(); void toggleUPnP();
void toggleIpDetermination(bool) ; void toggleIpDetermination(bool) ;

View File

@ -527,6 +527,9 @@ behind a firewall or a VPN.</string>
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="sortingEnabled"> <property name="sortingEnabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -626,11 +629,14 @@ behind a firewall or a VPN.</string>
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;White listed IPs are gathered from the following sources: IPs coming inside a manually exchanged certificate, IP ranges entered by you in this window, or in the security feed items.&lt;/p&gt;&lt;p&gt;The default behavior for Retroshare is to disallow connections to peers not in the white-list. You can change this behavior for each peer in the &amp;quot;Details&amp;quot; window of each Retroshare node. If not activated, connections will still be checked w.r.t. the whitelist, and the blacklit above, but will pass if not in the whitelist.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;White listed IPs are gathered from the following sources: IPs coming inside a manually exchanged certificate, IP ranges entered by you in this window, or in the security feed items.&lt;/p&gt;&lt;p&gt;The default behavior for Retroshare is to (1) always allow connection to peers with IP in the whitelist, even if that IP is also blacklisted; (2) optionally require IPs to be in the whitelist. You can change this behavior for each peer in the &amp;quot;Details&amp;quot; window of each Retroshare node. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="sortingEnabled"> <property name="sortingEnabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -694,7 +700,7 @@ behind a firewall or a VPN.</string>
<number>16</number> <number>16</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>24</number> <number>32</number>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<number>8</number> <number>8</number>