diff --git a/libretroshare/src/serialiser/rstlvbanlist.cc b/libretroshare/src/serialiser/rstlvbanlist.cc index 23ea67885..bad6c1ab8 100644 --- a/libretroshare/src/serialiser/rstlvbanlist.cc +++ b/libretroshare/src/serialiser/rstlvbanlist.cc @@ -43,7 +43,8 @@ void RsTlvBanListEntry::TlvClear() addr.TlvClear(); level = 0; reason = 0; - age = 0; + age = 0; + comment.clear(); } uint32_t RsTlvBanListEntry::TlvSize() const @@ -55,6 +56,7 @@ uint32_t RsTlvBanListEntry::TlvSize() const s += 4; // reason; s += 4; // age; s += 1; // masked_bytes; + s += GetTlvStringSize(comment) ; 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, age); ok &= setRawUInt8(data, tlvend, offset, masked_bytes); + ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_COMMENT, comment); return ok; @@ -118,6 +121,7 @@ bool RsTlvBanListEntry::GetTlv(void *data, uint32_t size, uint32_t *offset) uint8_t tmp ; ok &= getRawUInt8(data, tlvend, offset, &(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). diff --git a/libretroshare/src/serialiser/rstlvbanlist.h b/libretroshare/src/serialiser/rstlvbanlist.h index 5c4caa428..f4cbf54c4 100644 --- a/libretroshare/src/serialiser/rstlvbanlist.h +++ b/libretroshare/src/serialiser/rstlvbanlist.h @@ -52,6 +52,7 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent) const; uint32_t reason; uint32_t age; uint8_t masked_bytes ; + std::string comment ; }; typedef t_RsTlvList RsTlvBanList; diff --git a/libretroshare/src/serialiser/rstlvbase.h b/libretroshare/src/serialiser/rstlvbase.h index 592378036..cb58aa520 100644 --- a/libretroshare/src/serialiser/rstlvbase.h +++ b/libretroshare/src/serialiser/rstlvbase.h @@ -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_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_MSG_ADDRESS = 0x10A0; diff --git a/libretroshare/src/services/p3banlist.cc b/libretroshare/src/services/p3banlist.cc index 927cd893a..a016eee1d 100644 --- a/libretroshare/src/services/p3banlist.cc +++ b/libretroshare/src/services/p3banlist.cc @@ -141,9 +141,10 @@ BanListPeer::BanListPeer() void BanListPeer::toRsTlvBanListEntry(RsTlvBanListEntry &e) const { e.addr.addr = addr; - e.level = level; - e.reason = reason; e.masked_bytes = masked_bytes; + e.reason = reason; + e.level = level; + e.comment = comment; e.age = time(NULL) - mTs; } @@ -155,8 +156,8 @@ void BanListPeer::fromRsTlvBanListEntry(const RsTlvBanListEntry &e) level = e.level; // LOCAL, FRIEND, FoF. state = true; // true=>active, false=>just stored but inactive connect_attempts = 0; // recorded by the BanList service + comment = e.comment; // recorded by the BanList service mTs = time(NULL) - e.age; - comment.clear() ; // } 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; IndicateConfigChanged() ; + + condenseBanSources_locked() ; } int p3BanList::tick() @@ -1026,6 +1029,7 @@ int p3BanList::sendBanSet(const RsPeerId& peerid) RsTlvBanListEntry bi; it->second.toRsTlvBanListEntry(bi) ; + bi.comment.clear() ; // don't send comments. item->peerList.mList.push_back(bi); } } diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index 5c858bc85..b6445dd8c 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -69,7 +69,10 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags) ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_ORIGIN,new QTableWidgetItem(tr("Origin"))) ; ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_COMMENT,new QTableWidgetItem(tr("Comment"))) ; + ui.filteredIpsTable->setColumnHidden(COLUMN_STATUS,true) ; 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.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.ipInputAddWhiteList_PB,SIGNAL(clicked()),this,SLOT(addIpRangeToWhiteList())); 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); timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus())); @@ -440,6 +445,9 @@ void ServerPage::loadFilteredIps() ui.groupIPRanges_CB->setChecked(rsBanList->autoRangeEnabled()) ; ui.groupIPRanges_SB->setValue(rsBanList->autoRangeLimit()) ; + ui.whiteListIpsTable->setColumnHidden(COLUMN_STATUS,true); + ui.filteredIpsTable->setColumnHidden(COLUMN_STATUS,true); + std::list lst ; rsBanList->getBannedIps(lst) ; @@ -456,6 +464,40 @@ void ServerPage::loadFilteredIps() for(std::list::const_iterator it(lst.begin());it!=lst.end();++it,++row) 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) { @@ -515,7 +557,7 @@ void ServerPage::ipFilterContextMenu(const QPoint& point) 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() ; @@ -532,14 +574,8 @@ void ServerPage::ipFilterContextMenu(const QPoint& point) QString range1 = QString::fromStdString(print_addr_range(addr,1)) ; QString range2 = QString::fromStdString(print_addr_range(addr,2)) ; - if(masked_bytes != 0) - contextMenu.addAction(QObject::tr("Ban only IP %1").arg(range0),this,SLOT(enableBannedIp()))->setEnabled(false) ; - - 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) ; + if(reason == RSBANLIST_REASON_USER) + contextMenu.addAction(tr("Remove"),this,SLOT(removeBannedIp())); 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())) ; @@ -646,10 +682,10 @@ void ServerPage::ipWhiteListContextMenu(const QPoint& point) QString range1 = QString::fromStdString(print_addr_range(addr,1)) ; QString range2 = QString::fromStdString(print_addr_range(addr,2)) ; - contextMenu.addAction(QObject::tr("Whitelist only IP " )+range0,this,SLOT(enableBannedIp()))->setEnabled(false) ; -#warning UNIMPLEMENTED CODE - 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 only IP " )+range0,this,SLOT(enableBannedIp()))->setEnabled(false) ; +//#warning UNIMPLEMENTED CODE +// 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.exec(QCursor::pos()) ; } @@ -667,11 +703,6 @@ void ServerPage::removeWhiteListedIp() removeCurrentRowFromWhiteList(addr,bytes) ; } -void ServerPage::enableBannedIp() -{ -#warning UNIMPLEMENTED CODE - std::cerr << "Removing banned IP" << std::endl; -} /** Loads the settings for this page */ void ServerPage::updateStatus() diff --git a/retroshare-gui/src/gui/settings/ServerPage.h b/retroshare-gui/src/gui/settings/ServerPage.h index a89cf58cb..1c84e10b5 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.h +++ b/retroshare-gui/src/gui/settings/ServerPage.h @@ -52,6 +52,8 @@ public slots: void updateStatus(); private slots: + void updateSelectedBlackListIP(int row, int, int, int); + void updateSelectedWhiteListIP(int row,int,int,int); void addIpRangeToBlackList(); void addIpRangeToWhiteList(); void moveToWhiteList0(); @@ -67,7 +69,6 @@ private slots: void ipFilterContextMenu(const QPoint &); void ipWhiteListContextMenu(const QPoint &point); void removeBannedIp(); - void enableBannedIp(); void saveAddresses(); void toggleUPnP(); void toggleIpDetermination(bool) ; diff --git a/retroshare-gui/src/gui/settings/ServerPage.ui b/retroshare-gui/src/gui/settings/ServerPage.ui index c0b657d60..edf452e23 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.ui +++ b/retroshare-gui/src/gui/settings/ServerPage.ui @@ -527,6 +527,9 @@ behind a firewall or a VPN. true + + QAbstractItemView::SingleSelection + false @@ -626,11 +629,14 @@ behind a firewall or a VPN. Qt::CustomContextMenu - <html><head/><body><p>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.</p><p>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 &quot;Details&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.</p></body></html> + <html><head/><body><p>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.</p><p>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 &quot;Details&quot; window of each Retroshare node. </p></body></html> true + + QAbstractItemView::SingleSelection + false @@ -694,7 +700,7 @@ behind a firewall or a VPN. 16 - 24 + 32 8