2009-07-23 13:11:51 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2009-08-19 18:15:16 -04:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2009-07-23 13:11:51 -04:00
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "ServerPage.h"
2009-08-17 16:19:02 -04:00
2009-07-23 13:11:51 -04:00
# include "rshare.h"
2011-01-07 11:56:57 -05:00
# include "rsharesettings.h"
2015-06-02 17:36:26 -04:00
# include "util/RsNetUtil.h"
2009-07-23 13:11:51 -04:00
# include <iostream>
2012-11-25 15:26:32 -05:00
# include <retroshare/rsconfig.h>
2010-08-06 05:40:23 -04:00
# include <retroshare/rspeers.h>
2012-02-10 17:23:06 -05:00
# include <retroshare/rsturtle.h>
2015-05-27 17:30:40 -04:00
# include <retroshare/rsbanlist.h>
2009-07-23 13:11:51 -04:00
2015-05-21 17:12:48 -04:00
# include <QMovie>
2015-05-27 17:30:40 -04:00
# include <QMenu>
2014-09-28 15:24:03 -04:00
# include <QTcpSocket>
2015-05-17 06:00:00 -04:00
# include <QNetworkProxy>
2015-05-21 17:12:48 -04:00
# include <QNetworkReply>
# include <QNetworkRequest>
# include <QNetworkAccessManager>
2009-07-23 13:11:51 -04:00
# include <QTimer>
2014-09-28 15:24:03 -04:00
# define ICON_STATUS_UNKNOWN ": / images / ledoff1.png"
# define ICON_STATUS_OK ": / images / ledon1.png"
2015-05-27 17:30:40 -04:00
# define COLUMN_RANGE 0
# define COLUMN_STATUS 1
# define COLUMN_ORIGIN 2
# define COLUMN_REASON 3
# define COLUMN_COMMENT 4
2014-12-23 10:53:36 -05:00
//#define SERVER_DEBUG 1
2013-10-18 17:10:33 -04:00
ServerPage : : ServerPage ( QWidget * parent , Qt : : WindowFlags flags )
2015-09-07 16:57:54 -04:00
: ConfigPage ( parent , flags ) , mIsHiddenNode ( false ) , mHiddenType ( RS_HIDDEN_TYPE_NONE )
2009-07-23 13:11:51 -04:00
{
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2015-05-21 17:44:29 -04:00
manager = NULL ;
2015-05-27 17:30:40 -04:00
ui . filteredIpsTable - > setHorizontalHeaderItem ( COLUMN_RANGE , new QTableWidgetItem ( tr ( " IP Range " ) ) ) ;
ui . filteredIpsTable - > setHorizontalHeaderItem ( COLUMN_STATUS , new QTableWidgetItem ( tr ( " Status " ) ) ) ;
ui . filteredIpsTable - > setHorizontalHeaderItem ( COLUMN_ORIGIN , new QTableWidgetItem ( tr ( " Origin " ) ) ) ;
ui . filteredIpsTable - > setHorizontalHeaderItem ( COLUMN_COMMENT , new QTableWidgetItem ( tr ( " Comment " ) ) ) ;
2015-06-02 09:02:20 -04:00
ui . filteredIpsTable - > setColumnHidden ( COLUMN_STATUS , true ) ;
2015-05-27 17:30:40 -04:00
ui . filteredIpsTable - > verticalHeader ( ) - > hide ( ) ;
2015-06-02 09:02:20 -04:00
ui . whiteListIpsTable - > setColumnHidden ( COLUMN_STATUS , true ) ;
ui . whiteListIpsTable - > verticalHeader ( ) - > hide ( ) ;
2015-05-27 17:30:40 -04:00
QObject : : connect ( ui . filteredIpsTable , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( ipFilterContextMenu ( const QPoint & ) ) ) ;
2015-05-30 09:57:10 -04:00
QObject : : connect ( ui . whiteListIpsTable , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( ipWhiteListContextMenu ( const QPoint & ) ) ) ;
2015-05-27 17:30:40 -04:00
QObject : : connect ( ui . denyAll_CB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleIpFiltering ( bool ) ) ) ;
2015-05-28 17:44:43 -04:00
QObject : : connect ( ui . includeFromDHT_CB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleAutoIncludeDHT ( bool ) ) ) ;
QObject : : connect ( ui . includeFromFriends_CB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleAutoIncludeFriends ( bool ) ) ) ;
QObject : : connect ( ui . groupIPRanges_CB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleGroupIps ( bool ) ) ) ;
QObject : : connect ( ui . groupIPRanges_SB , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( setGroupIpLimit ( int ) ) ) ;
2015-05-30 09:57:10 -04:00
QObject : : connect ( ui . ipInputAddBlackList_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( addIpRangeToBlackList ( ) ) ) ;
QObject : : connect ( ui . ipInputAddWhiteList_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( addIpRangeToWhiteList ( ) ) ) ;
2015-05-29 14:03:14 -04:00
QObject : : connect ( ui . ipInput_LE , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( checkIpRange ( const QString & ) ) ) ;
2015-06-02 09:02:20 -04:00
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 ) ) ) ;
2015-05-27 17:30:40 -04:00
2009-07-23 13:11:51 -04:00
QTimer * timer = new QTimer ( this ) ;
timer - > connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateStatus ( ) ) ) ;
timer - > start ( 1000 ) ;
2009-09-15 20:03:51 -04:00
//load();
2009-07-23 13:11:51 -04:00
updateStatus ( ) ;
bool b = rsPeers - > getAllowServerIPDetermination ( ) ;
ui . allowIpDeterminationCB - > setChecked ( b ) ;
ui . IPServersLV - > setEnabled ( b ) ;
std : : list < std : : string > ip_servers ;
rsPeers - > getIPServersList ( ip_servers ) ;
for ( std : : list < std : : string > : : const_iterator it ( ip_servers . begin ( ) ) ; it ! = ip_servers . end ( ) ; + + it )
ui . IPServersLV - > addItem ( QString : : fromStdString ( * it ) ) ;
2015-09-07 16:57:54 -04:00
ui . hiddenpage_incoming - > setVisible ( false ) ;
2014-01-19 01:27:02 -05:00
2017-01-29 15:47:13 -05:00
connect ( ui . netModeComboBox , SIGNAL ( activated ( int ) ) , this , SLOT ( toggleUPnP ( ) ) ) ;
connect ( ui . allowIpDeterminationCB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleIpDetermination ( bool ) ) ) ;
connect ( ui . cleanKnownIPs_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( clearKnownAddressList ( ) ) ) ;
connect ( ui . testIncoming_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( updateInProxyIndicator ( ) ) ) ;
connect ( ui . showDiscStatusBar , SIGNAL ( toggled ( bool ) ) , this , SLOT ( updateShowDiscStatusBar ( ) ) ) ;
2014-12-23 10:53:36 -05:00
# ifdef SERVER_DEBUG
2014-01-17 21:35:06 -05:00
std : : cerr < < " ServerPage::ServerPage() called " ;
std : : cerr < < std : : endl ;
2014-12-23 10:53:36 -05:00
# endif
2017-01-29 15:47:13 -05:00
connect ( ui . netModeComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . discComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . localAddress , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . extAddress , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . dynDNS , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . hiddenpage_proxyAddress_tor , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . hiddenpage_proxyPort_tor , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . hiddenpage_proxyAddress_i2p , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . hiddenpage_proxyPort_i2p , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( saveAddresses ( ) ) ) ;
connect ( ui . totalDownloadRate , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( saveRates ( ) ) ) ;
connect ( ui . totalUploadRate , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( saveRates ( ) ) ) ;
2009-07-23 13:11:51 -04:00
}
2017-01-29 15:47:13 -05:00
2015-05-29 14:03:14 -04:00
void ServerPage : : checkIpRange ( const QString & ipstr )
{
QColor color ;
struct sockaddr_storage addr ;
int bytes ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( ipstr , addr , bytes ) | | bytes ! = 0 )
2015-05-29 14:03:14 -04:00
{
std : : cout < < " setting palette 1 " < < std : : endl ;
color = QApplication : : palette ( ) . color ( QPalette : : Disabled , QPalette : : Base ) ;
}
else
{
std : : cout < < " setting palette 2 " < < std : : endl ;
color = QApplication : : palette ( ) . color ( QPalette : : Active , QPalette : : Base ) ;
}
/* unpolish widget to clear the stylesheet's palette cache */
ui . ipInput_LE - > style ( ) - > unpolish ( ui . ipInput_LE ) ;
QPalette palette = ui . ipInput_LE - > palette ( ) ;
palette . setColor ( ui . ipInput_LE - > backgroundRole ( ) , color ) ;
ui . ipInput_LE - > setPalette ( palette ) ;
}
2015-05-30 09:57:10 -04:00
void ServerPage : : addIpRangeToBlackList ( )
2015-05-29 14:03:14 -04:00
{
QString ipstr = ui . ipInput_LE - > text ( ) ;
sockaddr_storage addr ;
int bytes = 0 ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( ipstr , addr , bytes ) | | bytes ! = 0 )
2015-05-29 14:03:14 -04:00
return ;
bytes = 4 - ui . ipInputRange_SB - > value ( ) / 8 ;
2015-05-30 16:29:06 -04:00
rsBanList - > addIpRange ( addr , bytes , RSBANLIST_TYPE_BLACKLIST , ui . ipInputComment_LE - > text ( ) . toStdString ( ) ) ;
2015-05-30 09:57:10 -04:00
}
void ServerPage : : addIpRangeToWhiteList ( )
{
QString ipstr = ui . ipInput_LE - > text ( ) ;
sockaddr_storage addr ;
int bytes = 0 ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( ipstr , addr , bytes ) | | bytes ! = 0 )
2015-05-30 09:57:10 -04:00
return ;
bytes = 4 - ui . ipInputRange_SB - > value ( ) / 8 ;
2015-05-30 16:29:06 -04:00
rsBanList - > addIpRange ( addr , bytes , RSBANLIST_TYPE_WHITELIST , ui . ipInputComment_LE - > text ( ) . toStdString ( ) ) ;
2015-05-29 14:03:14 -04:00
}
2009-07-23 13:11:51 -04:00
2015-05-17 06:00:00 -04:00
void ServerPage : : clearKnownAddressList ( )
{
rsPeers - > resetOwnExternalAddressList ( ) ;
2015-05-16 09:59:26 -04:00
2015-05-17 06:00:00 -04:00
load ( ) ;
}
2012-02-10 17:23:06 -05:00
2009-07-23 13:11:51 -04:00
void ServerPage : : toggleIpDetermination ( bool b )
{
rsPeers - > allowServerIPDetermination ( b ) ;
ui . IPServersLV - > setEnabled ( b ) ;
}
2009-12-13 16:59:26 -05:00
void ServerPage : : toggleTunnelConnection ( bool b )
{
std : : cerr < < " ServerPage::toggleTunnelConnection() set tunnel to : " < < b < < std : : endl ;
2013-09-07 00:21:48 -04:00
//rsPeers->allowTunnelConnection(b) ;
2009-12-13 16:59:26 -05:00
}
2017-01-29 15:47:13 -05:00
void ServerPage : : updateShowDiscStatusBar ( ) { Settings - > setStatusBarFlag ( STATUSBAR_DISC , ui . showDiscStatusBar - > isChecked ( ) ) ; }
2009-07-23 13:11:51 -04:00
/** Loads the settings for this page */
void ServerPage : : load ( )
{
2014-12-23 10:53:36 -05:00
# ifdef SERVER_DEBUG
2014-01-17 21:35:06 -05:00
std : : cerr < < " ServerPage::load() called " ;
std : : cerr < < std : : endl ;
2014-12-23 10:53:36 -05:00
# endif
2009-07-23 13:11:51 -04:00
/* load up configuration from rsPeers */
RsPeerDetails detail ;
if ( ! rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , detail ) )
{
return ;
2015-05-27 17:30:40 -04:00
}
mIsHiddenNode = ( detail . netMode = = RS_NETMODE_HIDDEN ) ;
2009-07-23 13:11:51 -04:00
2015-06-10 15:12:46 -04:00
if ( mIsHiddenNode )
{
2015-09-07 16:57:54 -04:00
mHiddenType = detail . hiddenType ;
2015-06-10 15:12:46 -04:00
ui . tabWidget - > setTabEnabled ( 1 , false ) ;
2014-01-17 21:35:06 -05:00
loadHiddenNode ( ) ;
return ;
}
2015-06-10 15:12:46 -04:00
loadFilteredIps ( ) ;
ui . netModeComboBox - > show ( ) ;
2015-10-21 16:39:48 -04:00
ui . textlabel_upnp - > show ( ) ;
ui . iconlabel_upnp - > show ( ) ;
ui . label_nat - > show ( ) ;
2016-10-22 17:48:19 -04:00
ui . textlabel_hiddenMode - > hide ( ) ;
2015-10-20 22:16:20 -04:00
ui . iconlabel_hiddenMode - > hide ( ) ;
2015-04-13 15:00:09 -04:00
2009-07-23 13:11:51 -04:00
/* set net mode */
int netIndex = 0 ;
2011-07-30 13:13:08 -04:00
switch ( detail . netMode )
2009-07-23 13:11:51 -04:00
{
case RS_NETMODE_EXT :
netIndex = 2 ;
break ;
case RS_NETMODE_UDP :
netIndex = 1 ;
break ;
default :
case RS_NETMODE_UPNP :
netIndex = 0 ;
break ;
}
ui . netModeComboBox - > setCurrentIndex ( netIndex ) ;
2010-10-31 10:02:33 -04:00
/* DHT + Discovery: (public)
* Discovery only : ( private )
* DHT only : ( inverted )
* None : ( dark net )
*/
netIndex = 3 ; // NONE.
2016-07-22 10:06:24 -04:00
if ( detail . vs_dht ! = RS_VS_DHT_OFF )
2009-07-23 13:11:51 -04:00
{
2013-09-29 03:10:19 -04:00
if ( detail . vs_disc ! = RS_VS_DISC_OFF )
2010-10-31 10:02:33 -04:00
{
netIndex = 0 ; // PUBLIC
}
else
{
netIndex = 2 ; // INVERTED
}
2009-07-23 13:11:51 -04:00
}
2010-10-31 10:02:33 -04:00
else
{
2013-09-29 03:10:19 -04:00
if ( detail . vs_disc ! = RS_VS_DISC_OFF )
2010-10-31 10:02:33 -04:00
{
netIndex = 1 ; // PRIVATE
}
else
{
netIndex = 3 ; // NONE
}
}
2009-07-23 13:11:51 -04:00
ui . discComboBox - > setCurrentIndex ( netIndex ) ;
2012-11-25 15:26:32 -05:00
int dlrate = 0 ;
int ulrate = 0 ;
rsConfig - > GetMaxDataRates ( dlrate , ulrate ) ;
ui . totalDownloadRate - > setValue ( dlrate ) ;
ui . totalUploadRate - > setValue ( ulrate ) ;
2009-07-23 13:11:51 -04:00
toggleUPnP ( ) ;
2009-08-19 18:15:16 -04:00
2009-07-23 13:11:51 -04:00
/* Addresses must be set here - otherwise can't edit it */
/* set local address */
ui . localAddress - > setText ( QString : : fromStdString ( detail . localAddr ) ) ;
ui . localPort - > setValue ( detail . localPort ) ;
/* set the server address */
ui . extAddress - > setText ( QString : : fromStdString ( detail . extAddr ) ) ;
ui . extPort - > setValue ( detail . extPort ) ;
2011-01-07 11:56:57 -05:00
/* set DynDNS */
ui . dynDNS - > setText ( QString : : fromStdString ( detail . dyndns ) ) ;
ui . showDiscStatusBar - > setChecked ( Settings - > getStatusBarFlags ( ) & STATUSBAR_DISC ) ;
2012-02-10 17:23:06 -05:00
2013-02-22 16:42:27 -05:00
ui . ipAddressList - > clear ( ) ;
for ( std : : list < std : : string > : : const_iterator it ( detail . ipAddressList . begin ( ) ) ; it ! = detail . ipAddressList . end ( ) ; + + it )
ui . ipAddressList - > addItem ( QString : : fromStdString ( * it ) ) ;
2014-01-19 01:27:02 -05:00
2015-09-07 12:46:19 -04:00
/* HIDDEN PAGE SETTINGS - only Proxy (outgoing) */
2014-01-19 01:27:02 -05:00
std : : string proxyaddr ;
2014-09-28 15:24:03 -04:00
uint16_t proxyport ;
uint32_t status ;
2015-09-07 06:59:21 -04:00
// Tor
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_TOR , proxyaddr , proxyport , status ) ;
ui . hiddenpage_proxyAddress_tor - > setText ( QString : : fromStdString ( proxyaddr ) ) ;
ui . hiddenpage_proxyPort_tor - > setValue ( proxyport ) ;
// I2P
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_I2P , proxyaddr , proxyport , status ) ;
ui . hiddenpage_proxyAddress_i2p - > setText ( QString : : fromStdString ( proxyaddr ) ) ;
ui . hiddenpage_proxyPort_i2p - > setValue ( proxyport ) ;
2014-09-28 15:24:03 -04:00
2015-09-07 12:46:19 -04:00
updateOutProxyIndicator ( ) ;
2012-11-25 09:26:32 -05:00
}
2015-05-28 17:44:43 -04:00
void ServerPage : : toggleAutoIncludeFriends ( bool b )
{
rsBanList - > enableIPsFromFriends ( b ) ;
}
void ServerPage : : toggleAutoIncludeDHT ( bool b )
{
rsBanList - > enableIPsFromDHT ( b ) ;
}
2015-05-27 17:30:40 -04:00
void ServerPage : : toggleIpFiltering ( bool b )
{
rsBanList - > enableIPFiltering ( b ) ;
loadFilteredIps ( ) ;
}
void ServerPage : : loadFilteredIps ( )
{
if ( rsBanList - > ipFilteringEnabled ( ) )
{
ui . denyAll_CB - > setChecked ( true ) ;
ui . filteredIpsTable - > setEnabled ( true ) ;
2015-05-28 17:44:43 -04:00
ui . includeFromFriends_CB - > setEnabled ( true ) ;
ui . includeFromDHT_CB - > setEnabled ( true ) ;
2015-05-29 14:03:14 -04:00
ui . ipInput_LE - > setEnabled ( true ) ;
ui . ipInputRange_SB - > setEnabled ( true ) ;
ui . ipInputComment_LE - > setEnabled ( true ) ;
2015-05-30 09:57:10 -04:00
ui . ipInputAddBlackList_PB - > setEnabled ( true ) ;
ui . ipInputAddWhiteList_PB - > setEnabled ( true ) ;
2015-05-28 17:44:43 -04:00
ui . groupIPRanges_CB - > setEnabled ( true ) ;
ui . groupIPRanges_SB - > setEnabled ( true ) ;
2015-05-27 17:30:40 -04:00
}
else
{
ui . denyAll_CB - > setChecked ( false ) ;
ui . filteredIpsTable - > setEnabled ( false ) ;
ui . includeFromFriends_CB - > setEnabled ( false ) ;
ui . includeFromDHT_CB - > setEnabled ( false ) ;
2015-05-28 17:44:43 -04:00
ui . ipInput_LE - > setEnabled ( false ) ;
ui . ipInputRange_SB - > setEnabled ( false ) ;
ui . ipInputComment_LE - > setEnabled ( false ) ;
2015-05-30 09:57:10 -04:00
ui . ipInputAddBlackList_PB - > setEnabled ( false ) ;
ui . ipInputAddWhiteList_PB - > setEnabled ( true ) ;
2015-05-28 17:44:43 -04:00
ui . groupIPRanges_CB - > setEnabled ( false ) ;
ui . groupIPRanges_SB - > setEnabled ( false ) ;
2015-05-27 17:30:40 -04:00
}
2015-05-28 17:44:43 -04:00
ui . includeFromFriends_CB - > setChecked ( rsBanList - > IPsFromFriendsEnabled ( ) ) ;
ui . includeFromDHT_CB - > setChecked ( rsBanList - > iPsFromDHTEnabled ( ) ) ;
ui . groupIPRanges_CB - > setChecked ( rsBanList - > autoRangeEnabled ( ) ) ;
ui . groupIPRanges_SB - > setValue ( rsBanList - > autoRangeLimit ( ) ) ;
2015-06-02 09:02:20 -04:00
ui . whiteListIpsTable - > setColumnHidden ( COLUMN_STATUS , true ) ;
ui . filteredIpsTable - > setColumnHidden ( COLUMN_STATUS , true ) ;
2015-05-27 17:30:40 -04:00
std : : list < BanListPeer > lst ;
2015-05-30 09:57:10 -04:00
rsBanList - > getBannedIps ( lst ) ;
2015-05-27 17:30:40 -04:00
ui . filteredIpsTable - > setRowCount ( lst . size ( ) ) ;
int row = 0 ;
for ( std : : list < BanListPeer > : : const_iterator it ( lst . begin ( ) ) ; it ! = lst . end ( ) ; + + it , + + row )
2015-05-30 09:57:10 -04:00
addPeerToIPTable ( ui . filteredIpsTable , row , * it ) ;
rsBanList - > getWhiteListedIps ( lst ) ;
ui . whiteListIpsTable - > setRowCount ( lst . size ( ) ) ;
row = 0 ;
for ( std : : list < BanListPeer > : : const_iterator it ( lst . begin ( ) ) ; it ! = lst . end ( ) ; + + it , + + row )
addPeerToIPTable ( ui . whiteListIpsTable , row , * it ) ;
}
2015-06-02 09:02:20 -04:00
void ServerPage : : updateSelectedBlackListIP ( int row , int , int , int )
{
2015-06-03 10:35:14 -04:00
QTableWidgetItem * item = ui . filteredIpsTable - > item ( row , COLUMN_RANGE ) ;
if ( ! item ) {
return ;
}
QString addr_string = item - > text ( ) ;
2015-06-02 09:02:20 -04:00
sockaddr_storage addr ;
int masked_bytes ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( addr_string , addr , masked_bytes ) )
2015-06-02 09:02:20 -04:00
{
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 )
{
2015-06-03 10:35:14 -04:00
QTableWidgetItem * item = ui . whiteListIpsTable - > item ( row , COLUMN_RANGE ) ;
if ( ! item ) {
return ;
}
QString addr_string = item - > text ( ) ;
2015-06-02 09:02:20 -04:00
sockaddr_storage addr ;
int masked_bytes ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( addr_string , addr , masked_bytes ) )
2015-06-02 09:02:20 -04:00
{
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 ( ) ) ;
}
2015-05-30 09:57:10 -04:00
void ServerPage : : addPeerToIPTable ( QTableWidget * table , int row , const BanListPeer & blp )
{
2015-06-02 17:36:26 -04:00
table - > setItem ( row , COLUMN_RANGE , new QTableWidgetItem ( RsNetUtil : : printAddrRange ( blp . addr , blp . masked_bytes ) ) ) ;
2015-05-30 09:57:10 -04:00
if ( blp . state )
table - > setItem ( row , COLUMN_STATUS , new QTableWidgetItem ( QString ( " active " ) ) ) ;
else
table - > setItem ( row , COLUMN_STATUS , new QTableWidgetItem ( QString ( " " ) ) ) ;
switch ( blp . level )
{
case RSBANLIST_ORIGIN_FOF : table - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " From friend of a friend " ) ) ) ;
break ;
case RSBANLIST_ORIGIN_FRIEND : table - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " From friend " ) ) ) ;
break ;
2015-06-04 16:26:57 -04:00
case RSBANLIST_ORIGIN_SELF : table - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " Local " ) ) ) ;
2015-05-30 09:57:10 -04:00
break ;
default :
case RSBANLIST_ORIGIN_UNKNOWN : table - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " Unknown " ) ) ) ;
break ;
}
switch ( blp . reason )
2015-05-27 17:30:40 -04:00
{
2015-06-04 16:26:57 -04:00
case RSBANLIST_REASON_DHT : table - > setItem ( row , COLUMN_REASON , new QTableWidgetItem ( QString ( " Masquerading peer " ) ) ) ;
2015-05-30 15:34:30 -04:00
table - > setItem ( row , COLUMN_COMMENT , new QTableWidgetItem ( tr ( " Reported by DHT for IP masquerading " ) ) ) ;
2015-05-30 09:57:10 -04:00
break ;
case RSBANLIST_REASON_USER : table - > setItem ( row , COLUMN_REASON , new QTableWidgetItem ( QString ( " Home-made rule " ) ) ) ;
2015-05-30 15:34:30 -04:00
table - > setItem ( row , COLUMN_COMMENT , new QTableWidgetItem ( QString : : fromStdString ( blp . comment ) ) ) ;
2015-05-30 09:57:10 -04:00
break ;
case RSBANLIST_REASON_AUTO_RANGE : table - > setItem ( row , COLUMN_REASON , new QTableWidgetItem ( QString ( " Auto-generated range " ) ) ) ;
2015-05-30 15:34:30 -04:00
table - > setItem ( row , COLUMN_COMMENT , new QTableWidgetItem ( tr ( " Range made from %1 collected addresses " ) . arg ( QString : : number ( blp . connect_attempts ) ) ) ) ;
2015-05-30 09:57:10 -04:00
break ;
default :
case RSBANLIST_REASON_UNKNOWN : table - > setItem ( row , COLUMN_REASON , new QTableWidgetItem ( QString ( " Unknown " ) ) ) ;
2015-05-30 15:34:30 -04:00
table - > setItem ( row , COLUMN_COMMENT , new QTableWidgetItem ( QString : : fromStdString ( blp . comment ) ) ) ;
2015-05-30 09:57:10 -04:00
break ;
2015-05-27 17:30:40 -04:00
}
2015-06-04 16:26:57 -04:00
table - > item ( row , COLUMN_STATUS ) - > setData ( Qt : : UserRole , QVariant ( blp . state ) ) ;
table - > item ( row , COLUMN_REASON ) - > setData ( Qt : : UserRole , QVariant ( blp . reason ) ) ;
table - > item ( row , COLUMN_ORIGIN ) - > setData ( Qt : : UserRole , QVariant ( blp . level ) ) ;
2015-05-30 09:57:10 -04:00
}
2015-05-27 17:30:40 -04:00
2015-05-28 17:44:43 -04:00
void ServerPage : : toggleGroupIps ( bool b ) { rsBanList - > enableAutoRange ( b ) ; }
void ServerPage : : setGroupIpLimit ( int n ) { rsBanList - > setAutoRangeLimit ( n ) ; }
2016-10-19 09:41:25 -04:00
void ServerPage : : ipFilterContextMenu ( const QPoint & /*point*/ )
2015-05-27 17:30:40 -04:00
{
QMenu contextMenu ( this ) ;
int row = ui . filteredIpsTable - > currentRow ( ) ;
QTableWidgetItem * item = ui . filteredIpsTable - > item ( row , COLUMN_STATUS ) ;
if ( item = = NULL )
return ;
2016-06-05 11:05:52 -04:00
//bool status = item->data(Qt::UserRole).toBool();
2015-05-27 17:30:40 -04:00
2015-06-02 09:02:20 -04:00
uint32_t reason = ui . filteredIpsTable - > item ( row , COLUMN_REASON ) - > data ( Qt : : UserRole ) . toUInt ( ) ;
2015-05-27 17:30:40 -04:00
QString addr_string = ui . filteredIpsTable - > item ( row , COLUMN_RANGE ) - > text ( ) ;
sockaddr_storage addr ;
int masked_bytes ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( addr_string , addr , masked_bytes ) )
2015-05-27 17:30:40 -04:00
{
std : : cerr < < " Cannot parse IP \" " < < addr_string . toStdString ( ) < < " \" " < < std : : endl ;
return ;
}
2015-06-02 17:36:26 -04:00
QString range0 = RsNetUtil : : printAddrRange ( addr , 0 ) ;
QString range1 = RsNetUtil : : printAddrRange ( addr , 1 ) ;
QString range2 = RsNetUtil : : printAddrRange ( addr , 2 ) ;
2015-05-27 17:30:40 -04:00
2015-06-02 09:02:20 -04:00
if ( reason = = RSBANLIST_REASON_USER )
contextMenu . addAction ( tr ( " Remove " ) , this , SLOT ( removeBannedIp ( ) ) ) ;
2015-05-30 09:57:10 -04:00
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 ( range2 ) , this , SLOT ( moveToWhiteList2 ( ) ) ) ;
2015-05-27 17:30:40 -04:00
contextMenu . exec ( QCursor : : pos ( ) ) ;
}
2015-05-30 09:57:10 -04:00
bool ServerPage : : removeCurrentRowFromBlackList ( sockaddr_storage & collected_addr , int & masked_bytes )
{
int row = ui . filteredIpsTable - > currentRow ( ) ;
QTableWidgetItem * item = ui . filteredIpsTable - > item ( row , COLUMN_STATUS ) ;
if ( item = = NULL )
return false ;
QString addr_string = ui . filteredIpsTable - > item ( row , COLUMN_RANGE ) - > text ( ) ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( addr_string , collected_addr , masked_bytes ) )
2015-05-30 09:57:10 -04:00
{
std : : cerr < < " Cannot parse IP \" " < < addr_string . toStdString ( ) < < " \" " < < std : : endl ;
return false ;
}
2015-05-30 17:48:45 -04:00
rsBanList - > removeIpRange ( collected_addr , masked_bytes , RSBANLIST_TYPE_BLACKLIST ) ;
2015-05-30 09:57:10 -04:00
return true ;
}
2015-05-30 16:29:06 -04:00
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 ( ) ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( addr_string , collected_addr , masked_bytes ) )
2015-05-30 16:29:06 -04:00
{
std : : cerr < < " Cannot parse IP \" " < < addr_string . toStdString ( ) < < " \" " < < std : : endl ;
return false ;
}
rsBanList - > removeIpRange ( collected_addr , masked_bytes , RSBANLIST_TYPE_WHITELIST ) ;
return true ;
}
2015-05-30 09:57:10 -04:00
void ServerPage : : moveToWhiteList0 ( )
{
sockaddr_storage addr ;
int bytes ;
2015-05-30 17:48:45 -04:00
if ( ! removeCurrentRowFromBlackList ( addr , bytes ) )
return ;
2015-05-30 09:57:10 -04:00
2015-05-30 16:29:06 -04:00
rsBanList - > addIpRange ( addr , 0 , RSBANLIST_TYPE_WHITELIST , tr ( " Added by you " ) . toStdString ( ) ) ;
2015-05-30 09:57:10 -04:00
}
void ServerPage : : moveToWhiteList1 ( )
{
sockaddr_storage addr ;
int bytes ;
2015-05-30 17:48:45 -04:00
if ( ! removeCurrentRowFromBlackList ( addr , bytes ) )
return ;
2015-05-30 09:57:10 -04:00
2015-05-30 16:29:06 -04:00
rsBanList - > addIpRange ( addr , 1 , RSBANLIST_TYPE_WHITELIST , tr ( " Added by you " ) . toStdString ( ) ) ;
2015-05-30 09:57:10 -04:00
}
void ServerPage : : moveToWhiteList2 ( )
{
sockaddr_storage addr ;
int bytes ;
2015-05-30 17:48:45 -04:00
if ( ! removeCurrentRowFromBlackList ( addr , bytes ) )
return ;
2015-05-30 09:57:10 -04:00
2015-05-30 16:29:06 -04:00
rsBanList - > addIpRange ( addr , 2 , RSBANLIST_TYPE_WHITELIST , tr ( " Added by you " ) . toStdString ( ) ) ;
2015-05-30 09:57:10 -04:00
}
2016-06-05 10:43:57 -04:00
void ServerPage : : ipWhiteListContextMenu ( const QPoint & /* point */ )
2015-05-30 09:57:10 -04:00
{
QMenu contextMenu ( this ) ;
int row = ui . whiteListIpsTable - > currentRow ( ) ;
QTableWidgetItem * item = ui . whiteListIpsTable - > item ( row , COLUMN_STATUS ) ;
if ( item = = NULL )
return ;
2016-10-19 09:41:25 -04:00
//bool status = item->data(Qt::UserRole).toBool();
2015-05-30 09:57:10 -04:00
2015-05-30 16:29:06 -04:00
contextMenu . addAction ( tr ( " Remove " ) , this , SLOT ( removeWhiteListedIp ( ) ) ) ;
2015-05-30 09:57:10 -04:00
QString addr_string = ui . whiteListIpsTable - > item ( row , COLUMN_RANGE ) - > text ( ) ;
sockaddr_storage addr ;
int masked_bytes ;
2015-06-02 17:36:26 -04:00
if ( ! RsNetUtil : : parseAddrFromQString ( addr_string , addr , masked_bytes ) )
2015-05-30 09:57:10 -04:00
{
std : : cerr < < " Cannot parse IP \" " < < addr_string . toStdString ( ) < < " \" " < < std : : endl ;
return ;
}
2015-06-02 17:36:26 -04:00
QString range0 = RsNetUtil : : printAddrRange ( addr , 0 ) ;
QString range1 = RsNetUtil : : printAddrRange ( addr , 1 ) ;
QString range2 = RsNetUtil : : printAddrRange ( addr , 2 ) ;
2015-05-30 09:57:10 -04:00
2015-06-02 09:02:20 -04:00
// 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) ;
2015-05-30 09:57:10 -04:00
contextMenu . exec ( QCursor : : pos ( ) ) ;
}
2015-05-27 17:30:40 -04:00
void ServerPage : : removeBannedIp ( )
{
2015-05-30 16:29:06 -04:00
sockaddr_storage addr ;
int bytes ;
removeCurrentRowFromBlackList ( addr , bytes ) ;
2015-05-27 17:30:40 -04:00
}
2015-05-30 09:57:10 -04:00
void ServerPage : : removeWhiteListedIp ( )
{
2015-05-30 16:29:06 -04:00
sockaddr_storage addr ;
int bytes ;
removeCurrentRowFromWhiteList ( addr , bytes ) ;
2015-05-30 09:57:10 -04:00
}
2009-07-23 13:11:51 -04:00
/** Loads the settings for this page */
void ServerPage : : updateStatus ( )
{
2014-12-23 10:53:36 -05:00
# ifdef SERVER_DEBUG
std : : cerr < < " ServerPage::updateStatus() called " ;
2014-01-17 21:35:06 -05:00
std : : cerr < < std : : endl ;
2014-12-23 10:53:36 -05:00
# endif
2014-01-17 21:35:06 -05:00
2013-07-04 15:22:02 -04:00
if ( RsAutoUpdatePage : : eventsLocked ( ) )
return ;
2010-04-10 10:56:34 -04:00
if ( ! isVisible ( ) )
return ;
2009-07-23 13:11:51 -04:00
2015-05-27 17:30:40 -04:00
loadFilteredIps ( ) ;
2014-01-17 21:35:06 -05:00
if ( mIsHiddenNode )
{
updateStatusHiddenNode ( ) ;
return ;
2015-05-27 17:30:40 -04:00
}
2014-01-17 21:35:06 -05:00
2009-07-23 13:11:51 -04:00
/* load up configuration from rsPeers */
RsPeerDetails detail ;
if ( ! rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , detail ) )
return ;
/* only update if can't edit */
if ( ! ui . localPort - > isEnabled ( ) )
{
/* set local address */
ui . localPort - > setValue ( detail . localPort ) ;
ui . extPort - > setValue ( detail . extPort ) ;
}
/* set local address */
ui . localAddress - > setText ( QString : : fromStdString ( detail . localAddr ) ) ;
/* set the server address */
ui . extAddress - > setText ( QString : : fromStdString ( detail . extAddr ) ) ;
2013-02-22 16:42:27 -05:00
// Now update network bits.
2013-08-21 17:39:40 -04:00
RsConfigNetStatus net_status ;
rsConfig - > getConfigNetStatus ( net_status ) ;
2013-02-22 16:42:27 -05:00
/******* Network Status Tab *******/
2013-08-21 17:39:40 -04:00
if ( net_status . netUpnpOk )
2013-02-22 16:42:27 -05:00
ui . iconlabel_upnp - > setPixmap ( QPixmap ( " :/images/ledon1.png " ) ) ;
else
ui . iconlabel_upnp - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
2013-08-21 17:39:40 -04:00
if ( net_status . netLocalOk )
2013-02-22 16:42:27 -05:00
ui . iconlabel_netLimited - > setPixmap ( QPixmap ( " :/images/ledon1.png " ) ) ;
else
ui . iconlabel_netLimited - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
2013-08-21 17:39:40 -04:00
if ( net_status . netExtAddressOk )
2013-02-22 16:42:27 -05:00
ui . iconlabel_ext - > setPixmap ( QPixmap ( " :/images/ledon1.png " ) ) ;
else
2014-09-28 15:24:03 -04:00
ui . iconlabel_ext - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
2015-06-11 10:30:26 -04:00
// check for Tor
2015-09-07 12:46:19 -04:00
updateOutProxyIndicator ( ) ;
2009-07-23 13:11:51 -04:00
}
void ServerPage : : toggleUPnP ( )
{
/* switch on the radioButton */
bool settingChangeable = false ;
if ( 0 ! = ui . netModeComboBox - > currentIndex ( ) )
{
settingChangeable = true ;
}
if ( settingChangeable )
{
ui . localAddress - > setEnabled ( false ) ;
ui . localPort - > setEnabled ( true ) ;
ui . extAddress - > setEnabled ( false ) ;
ui . extPort - > setEnabled ( true ) ;
}
else
{
ui . localAddress - > setEnabled ( false ) ;
ui . localPort - > setEnabled ( false ) ;
ui . extAddress - > setEnabled ( false ) ;
ui . extPort - > setEnabled ( false ) ;
}
}
void ServerPage : : saveAddresses ( )
{
QString str ;
bool saveAddr = false ;
2014-01-17 21:35:06 -05:00
if ( mIsHiddenNode )
{
saveAddressesHiddenNode ( ) ;
return ;
}
2009-07-23 13:11:51 -04:00
RsPeerDetails detail ;
2014-03-17 16:56:06 -04:00
RsPeerId ownId = rsPeers - > getOwnId ( ) ;
2009-07-23 13:11:51 -04:00
if ( ! rsPeers - > getPeerDetails ( ownId , detail ) )
return ;
int netIndex = ui . netModeComboBox - > currentIndex ( ) ;
/* Check if netMode has changed */
2010-06-10 10:13:20 -04:00
uint32_t netMode = 0 ;
2009-07-23 13:11:51 -04:00
switch ( netIndex )
{
2014-01-17 21:35:06 -05:00
case 3 :
netMode = RS_NETMODE_HIDDEN ;
break ;
2009-07-23 13:11:51 -04:00
case 2 :
netMode = RS_NETMODE_EXT ;
break ;
case 1 :
netMode = RS_NETMODE_UDP ;
break ;
default :
case 0 :
netMode = RS_NETMODE_UPNP ;
break ;
}
2011-07-30 13:13:08 -04:00
if ( detail . netMode ! = netMode )
2009-07-23 13:11:51 -04:00
rsPeers - > setNetworkMode ( ownId , netMode ) ;
2013-09-29 03:10:19 -04:00
uint16_t vs_disc = 0 ;
uint16_t vs_dht = 0 ;
2009-07-23 13:11:51 -04:00
/* Check if vis has changed */
2010-10-31 10:02:33 -04:00
switch ( ui . discComboBox - > currentIndex ( ) )
{
case 0 :
2013-09-29 03:10:19 -04:00
vs_disc = RS_VS_DISC_FULL ;
vs_dht = RS_VS_DHT_FULL ;
2010-10-31 10:02:33 -04:00
break ;
case 1 :
2013-09-29 03:10:19 -04:00
vs_disc = RS_VS_DISC_FULL ;
vs_dht = RS_VS_DHT_OFF ;
2010-10-31 10:02:33 -04:00
break ;
case 2 :
2013-09-29 03:10:19 -04:00
vs_disc = RS_VS_DISC_OFF ;
vs_dht = RS_VS_DHT_FULL ;
2010-10-31 10:02:33 -04:00
break ;
case 3 :
default :
2013-09-29 03:10:19 -04:00
vs_disc = RS_VS_DISC_OFF ;
vs_dht = RS_VS_DHT_OFF ;
2010-10-31 10:02:33 -04:00
break ;
}
2009-07-23 13:11:51 -04:00
2013-09-29 03:10:19 -04:00
if ( ( vs_disc ! = detail . vs_disc ) | | ( vs_dht ! = detail . vs_dht ) )
rsPeers - > setVisState ( ownId , vs_disc , vs_dht ) ;
2009-07-23 13:11:51 -04:00
if ( 0 ! = netIndex )
saveAddr = true ;
if ( saveAddr )
{
2010-10-05 20:08:20 -04:00
rsPeers - > setLocalAddress ( ownId , ui . localAddress - > text ( ) . toStdString ( ) , ui . localPort - > value ( ) ) ;
rsPeers - > setExtAddress ( ownId , ui . extAddress - > text ( ) . toStdString ( ) , ui . extPort - > value ( ) ) ;
2009-07-23 13:11:51 -04:00
}
2010-10-05 20:08:20 -04:00
rsPeers - > setDynDNS ( ownId , ui . dynDNS - > text ( ) . toStdString ( ) ) ;
2010-04-22 14:49:08 -04:00
2014-01-19 01:27:02 -05:00
// HANDLE PROXY SERVER.
2015-09-14 08:56:14 -04:00
std : : string orig_proxyaddr , new_proxyaddr ;
2015-09-07 06:59:21 -04:00
uint16_t orig_proxyport , new_proxyport ;
uint32_t status ;
// Tor
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_TOR , orig_proxyaddr , orig_proxyport , status ) ;
new_proxyaddr = ui . hiddenpage_proxyAddress_tor - > text ( ) . toStdString ( ) ;
new_proxyport = ui . hiddenpage_proxyPort_tor - > value ( ) ;
if ( ( new_proxyaddr ! = orig_proxyaddr ) | | ( new_proxyport ! = orig_proxyport ) )
{
rsPeers - > setProxyServer ( RS_HIDDEN_TYPE_TOR , new_proxyaddr , new_proxyport ) ;
}
// I2P
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_I2P , orig_proxyaddr , orig_proxyport , status ) ;
2014-01-19 01:27:02 -05:00
2015-09-07 06:59:21 -04:00
new_proxyaddr = ui . hiddenpage_proxyAddress_i2p - > text ( ) . toStdString ( ) ;
new_proxyport = ui . hiddenpage_proxyPort_i2p - > value ( ) ;
2014-01-19 01:27:02 -05:00
if ( ( new_proxyaddr ! = orig_proxyaddr ) | | ( new_proxyport ! = orig_proxyport ) )
{
2015-09-07 06:59:21 -04:00
rsPeers - > setProxyServer ( RS_HIDDEN_TYPE_I2P , new_proxyaddr , new_proxyport ) ;
2014-01-19 01:27:02 -05:00
}
2009-07-23 13:11:51 -04:00
load ( ) ;
}
2017-01-29 15:47:13 -05:00
void ServerPage : : saveRates ( )
{
rsConfig - > SetMaxDataRates ( ui . totalDownloadRate - > value ( ) , ui . totalUploadRate - > value ( ) ) ;
}
2014-01-17 21:35:06 -05:00
/***********************************************************************************/
/***********************************************************************************/
/******* ALTERNATIVE VERSION IF HIDDEN NODE ***************************************/
/***********************************************************************************/
/***********************************************************************************/
/** Loads the settings for this page */
void ServerPage : : loadHiddenNode ( )
{
2014-12-23 10:53:36 -05:00
# ifdef SERVER_DEBUG
2014-01-17 21:35:06 -05:00
std : : cerr < < " ServerPage::loadHiddenNode() called " ;
std : : cerr < < std : : endl ;
2014-12-23 10:53:36 -05:00
# endif
2014-01-17 21:35:06 -05:00
/* load up configuration from rsPeers */
RsPeerDetails detail ;
if ( ! rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , detail ) )
{
return ;
}
/* At this point we want to force the Configuration Page to look different
* We will be called multiple times - so cannot just delete bad items .
*
* We want :
* NETMODE : HiddenNode FIXED .
* Disc / DHT : Discovery / No Discovery .
* Local Address : 127.0 .0 .1 , Port : Listening Port . ( listening port changable )
2015-06-11 10:30:26 -04:00
* External Address = = > Tor Address : 17621376587. onion + PORT .
2014-01-17 21:35:06 -05:00
*
* Known / Previous IPs : empty / removed .
* Ask about IP : Disabled .
*/
// FIXED.
2015-04-13 15:00:09 -04:00
//ui.netModeComboBox->setCurrentIndex(3);
ui . netModeComboBox - > hide ( ) ;
2015-10-21 16:39:48 -04:00
ui . textlabel_upnp - > hide ( ) ;
ui . iconlabel_upnp - > hide ( ) ;
ui . label_nat - > hide ( ) ;
2016-10-22 17:48:19 -04:00
ui . textlabel_hiddenMode - > show ( ) ;
2015-10-20 22:16:20 -04:00
ui . iconlabel_hiddenMode - > show ( ) ;
ui . iconlabel_hiddenMode - > setPixmap ( QPixmap ( " :/images/ledon1.png " ) ) ;
2014-01-17 21:35:06 -05:00
// CHANGE OPTIONS ON
ui . discComboBox - > removeItem ( 3 ) ;
ui . discComboBox - > removeItem ( 2 ) ;
ui . discComboBox - > removeItem ( 1 ) ;
ui . discComboBox - > removeItem ( 0 ) ;
ui . discComboBox - > insertItem ( 0 , tr ( " Discovery On (recommended) " ) ) ;
ui . discComboBox - > insertItem ( 1 , tr ( " Discovery Off " ) ) ;
int netIndex = 1 ; // OFF.
if ( detail . vs_disc ! = RS_VS_DISC_OFF )
{
netIndex = 0 ; // DISC ON;
}
ui . discComboBox - > setCurrentIndex ( netIndex ) ;
// Download Rates - Stay the same as before.
int dlrate = 0 ;
int ulrate = 0 ;
rsConfig - > GetMaxDataRates ( dlrate , ulrate ) ;
ui . totalDownloadRate - > setValue ( dlrate ) ;
ui . totalUploadRate - > setValue ( ulrate ) ;
// Addresses.
ui . localAddress - > setEnabled ( false ) ;
2014-01-19 01:27:02 -05:00
ui . localPort - > setEnabled ( false ) ;
ui . extAddress - > setEnabled ( false ) ;
ui . extPort - > setVisible ( false ) ;
ui . label_dynDNS - > setVisible ( false ) ;
ui . dynDNS - > setVisible ( false ) ;
2015-09-07 16:57:54 -04:00
ui . hiddenpage_incoming - > setVisible ( true ) ;
2014-01-17 21:35:06 -05:00
/* Addresses must be set here - otherwise can't edit it */
/* set local address */
ui . localAddress - > setText ( QString : : fromStdString ( detail . localAddr ) ) ;
ui . localPort - > setValue ( detail . localPort ) ;
/* set the server address */
2015-09-07 16:57:54 -04:00
ui . extAddress - > setText ( tr ( " Hidden - See Config " ) ) ;
2014-01-17 21:35:06 -05:00
ui . showDiscStatusBar - > setChecked ( Settings - > getStatusBarFlags ( ) & STATUSBAR_DISC ) ;
2015-05-16 09:59:26 -04:00
ui . showDiscStatusBar - > hide ( ) ; // hidden because not functional at the moment.
2014-01-17 21:35:06 -05:00
2015-05-16 09:59:26 -04:00
//ui._turtle_enabled_CB->setChecked(rsTurtle->enabled()) ;
2014-01-17 21:35:06 -05:00
// show what we have in ipAddresses. (should be nothing!)
ui . ipAddressList - > clear ( ) ;
for ( std : : list < std : : string > : : const_iterator it ( detail . ipAddressList . begin ( ) ) ; it ! = detail . ipAddressList . end ( ) ; + + it )
ui . ipAddressList - > addItem ( QString : : fromStdString ( * it ) ) ;
ui . iconlabel_upnp - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_netLimited - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_ext - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . allowIpDeterminationCB - > setChecked ( false ) ;
ui . allowIpDeterminationCB - > setEnabled ( false ) ;
ui . IPServersLV - > setEnabled ( false ) ;
2014-01-19 01:27:02 -05:00
/* TOR PAGE SETTINGS */
/* set local address */
2015-09-07 16:57:54 -04:00
ui . hiddenpage_localAddress - > setEnabled ( false ) ;
ui . hiddenpage_localAddress - > setText ( QString : : fromStdString ( detail . localAddr ) ) ;
ui . hiddenpage_localPort - > setValue ( detail . localPort ) ;
2014-01-19 01:27:02 -05:00
/* set the server address */
2015-09-07 16:57:54 -04:00
ui . hiddenpage_serviceAddress - > setText ( QString : : fromStdString ( detail . hiddenNodeAddress ) ) ;
ui . hiddenpage_servicePort - > setValue ( detail . hiddenNodePort ) ;
/* in I2P there is no port - there is only the address */
ui . hiddenpage_servicePort - > setEnabled ( detail . hiddenType ! = RS_HIDDEN_TYPE_I2P ) ;
2014-01-19 01:27:02 -05:00
2015-09-07 12:46:19 -04:00
/* out proxy settings */
2014-01-19 01:27:02 -05:00
std : : string proxyaddr ;
2015-09-07 12:46:19 -04:00
uint16_t proxyport ;
uint32_t status ;
// Tor
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_TOR , proxyaddr , proxyport , status ) ;
2015-09-07 06:59:21 -04:00
ui . hiddenpage_proxyAddress_tor - > setText ( QString : : fromStdString ( proxyaddr ) ) ;
ui . hiddenpage_proxyPort_tor - > setValue ( proxyport ) ;
2015-09-07 12:46:19 -04:00
// I2P
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_I2P , proxyaddr , proxyport , status ) ;
ui . hiddenpage_proxyAddress_i2p - > setText ( QString : : fromStdString ( proxyaddr ) ) ;
ui . hiddenpage_proxyPort_i2p - > setValue ( proxyport ) ;
2014-01-19 01:27:02 -05:00
2015-09-07 12:46:19 -04:00
updateOutProxyIndicator ( ) ;
2015-05-18 15:12:15 -04:00
2015-09-14 06:39:46 -04:00
QString expected = " " ;
2015-09-07 16:57:54 -04:00
switch ( mHiddenType ) {
case RS_HIDDEN_TYPE_I2P :
ui . l_serviceAddress - > setText ( tr ( " I2P Address " ) ) ;
ui . l_incomingTestResult - > setText ( tr ( " I2P incoming ok " ) ) ;
2015-09-14 06:39:46 -04:00
expected + = " http://127.0.0.1:7657/i2ptunnelmgr - I2P Hidden Services \n " ;
expected + = tr ( " Points at: " ) ;
expected + = QString : : fromStdString ( detail . localAddr ) ;
expected + = " : " ;
expected + = QString : : number ( detail . localPort ) ;
2015-09-07 16:57:54 -04:00
break ;
case RS_HIDDEN_TYPE_TOR :
ui . l_serviceAddress - > setText ( tr ( " Onion Address " ) ) ;
ui . l_incomingTestResult - > setText ( tr ( " Tor incoming ok " ) ) ;
2015-09-14 06:39:46 -04:00
expected + = " HiddenServiceDir </your/path/to/hidden/directory/service> \n " ;
2015-09-07 16:57:54 -04:00
expected + = " HiddenServicePort " ;
expected + = QString : : number ( detail . hiddenNodePort ) ;
expected + = " " ;
expected + = QString : : fromStdString ( detail . localAddr ) ;
expected + = " : " ;
expected + = QString : : number ( detail . localPort ) ;
2015-09-16 05:48:32 -04:00
break ;
default :
ui . l_serviceAddress - > setText ( tr ( " Service Address " ) ) ;
ui . l_incomingTestResult - > setText ( tr ( " incoming ok " ) ) ;
expected + = " Please fill in a service address " ;
2015-09-07 16:57:54 -04:00
break ;
}
ui . hiddenpage_configuration - > setPlainText ( expected ) ;
2014-01-17 21:35:06 -05:00
}
/** Loads the settings for this page */
void ServerPage : : updateStatusHiddenNode ( )
{
2014-12-23 10:53:36 -05:00
# ifdef SERVER_DEBUG
2014-01-17 21:35:06 -05:00
std : : cerr < < " ServerPage::updateStatusHiddenNode() called " ;
std : : cerr < < std : : endl ;
2014-12-23 10:53:36 -05:00
# endif
2014-01-17 21:35:06 -05:00
// THIS IS DISABLED FOR NOW.
#if 0
/* load up configuration from rsPeers */
RsPeerDetails detail ;
if ( ! rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , detail ) )
return ;
/* only update if can't edit */
if ( ! ui . localPort - > isEnabled ( ) )
{
/* set local address */
ui . localPort - > setValue ( detail . localPort ) ;
ui . extPort - > setValue ( detail . extPort ) ;
}
/* set local address */
ui . localAddress - > setText ( QString : : fromStdString ( detail . localAddr ) ) ;
/* set the server address */
ui . extAddress - > setText ( QString : : fromStdString ( detail . extAddr ) ) ;
// Now update network bits.
RsConfigNetStatus net_status ;
rsConfig - > getConfigNetStatus ( net_status ) ;
/******* Network Status Tab *******/
if ( net_status . netUpnpOk )
ui . iconlabel_upnp - > setPixmap ( QPixmap ( " :/images/ledon1.png " ) ) ;
else
ui . iconlabel_upnp - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
if ( net_status . netLocalOk )
ui . iconlabel_netLimited - > setPixmap ( QPixmap ( " :/images/ledon1.png " ) ) ;
else
ui . iconlabel_netLimited - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
if ( net_status . netExtAddressOk )
ui . iconlabel_ext - > setPixmap ( QPixmap ( " :/images/ledon1.png " ) ) ;
else
ui . iconlabel_ext - > setPixmap ( QPixmap ( " :/images/ledoff1.png " ) ) ;
# endif
2015-09-07 12:46:19 -04:00
updateOutProxyIndicator ( ) ;
2014-01-17 21:35:06 -05:00
}
void ServerPage : : saveAddressesHiddenNode ( )
{
RsPeerDetails detail ;
2014-03-17 16:56:06 -04:00
RsPeerId ownId = rsPeers - > getOwnId ( ) ;
2014-01-17 21:35:06 -05:00
if ( ! rsPeers - > getPeerDetails ( ownId , detail ) )
return ;
// NETMODE IS UNCHANGABLE
uint16_t vs_disc = 0 ;
uint16_t vs_dht = 0 ;
/* Check if vis has changed */
switch ( ui . discComboBox - > currentIndex ( ) )
{
default :
case 0 :
vs_disc = RS_VS_DISC_FULL ;
vs_dht = RS_VS_DHT_OFF ;
break ;
case 1 :
vs_disc = RS_VS_DISC_OFF ;
vs_dht = RS_VS_DHT_OFF ;
break ;
}
if ( ( vs_disc ! = detail . vs_disc ) | | ( vs_dht ! = detail . vs_dht ) )
rsPeers - > setVisState ( ownId , vs_disc , vs_dht ) ;
2015-09-07 16:57:54 -04:00
if ( detail . localPort ! = ui . hiddenpage_localPort - > value ( ) )
2014-01-18 00:05:35 -05:00
{
// Set Local Address - force to 127.0.0.1
2015-09-07 16:57:54 -04:00
rsPeers - > setLocalAddress ( ownId , " 127.0.0.1 " , ui . hiddenpage_localPort - > value ( ) ) ;
2014-01-18 00:05:35 -05:00
}
2015-09-07 16:57:54 -04:00
std : : string hiddenAddr = ui . hiddenpage_serviceAddress - > text ( ) . toStdString ( ) ;
uint16_t hiddenPort = ui . hiddenpage_servicePort - > value ( ) ;
2014-01-17 21:35:06 -05:00
if ( ( hiddenAddr ! = detail . hiddenNodeAddress ) | | ( hiddenPort ! = detail . hiddenNodePort ) )
{
rsPeers - > setHiddenNode ( ownId , hiddenAddr , hiddenPort ) ;
}
// HANDLE PROXY SERVER.
2015-09-07 12:46:19 -04:00
std : : string orig_proxyaddr , new_proxyaddr ;
uint16_t orig_proxyport , new_proxyport ;
uint32_t status ;
// Tor
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_TOR , orig_proxyaddr , orig_proxyport , status ) ;
2014-01-17 21:35:06 -05:00
2015-09-07 12:46:19 -04:00
new_proxyaddr = ui . hiddenpage_proxyAddress_tor - > text ( ) . toStdString ( ) ;
new_proxyport = ui . hiddenpage_proxyPort_tor - > value ( ) ;
2014-01-17 21:35:06 -05:00
if ( ( new_proxyaddr ! = orig_proxyaddr ) | | ( new_proxyport ! = orig_proxyport ) )
{
2015-09-07 06:59:21 -04:00
rsPeers - > setProxyServer ( RS_HIDDEN_TYPE_TOR , new_proxyaddr , new_proxyport ) ;
2014-01-17 21:35:06 -05:00
}
2015-09-07 12:46:19 -04:00
// I2P
rsPeers - > getProxyServer ( RS_HIDDEN_TYPE_I2P , orig_proxyaddr , orig_proxyport , status ) ;
new_proxyaddr = ui . hiddenpage_proxyAddress_i2p - > text ( ) . toStdString ( ) ;
new_proxyport = ui . hiddenpage_proxyPort_i2p - > value ( ) ;
if ( ( new_proxyaddr ! = orig_proxyaddr ) | | ( new_proxyport ! = orig_proxyport ) )
{
rsPeers - > setProxyServer ( RS_HIDDEN_TYPE_I2P , new_proxyaddr , new_proxyport ) ;
}
2014-01-17 21:35:06 -05:00
rsConfig - > SetMaxDataRates ( ui . totalDownloadRate - > value ( ) , ui . totalUploadRate - > value ( ) ) ;
2009-07-23 13:11:51 -04:00
load ( ) ;
}
2015-09-07 12:46:19 -04:00
void ServerPage : : updateOutProxyIndicator ( )
2015-04-02 15:23:01 -04:00
{
2015-05-17 06:00:00 -04:00
QTcpSocket socket ;
2015-09-07 12:46:19 -04:00
// Tor
socket . connectToHost ( ui . hiddenpage_proxyAddress_tor - > text ( ) , ui . hiddenpage_proxyPort_tor - > text ( ) . toInt ( ) ) ;
2015-05-17 06:00:00 -04:00
if ( socket . waitForConnected ( 500 ) )
{
socket . disconnectFromHost ( ) ;
ui . iconlabel_tor_outgoing - > setPixmap ( QPixmap ( ICON_STATUS_OK ) ) ;
ui . iconlabel_tor_outgoing - > setToolTip ( tr ( " Proxy seems to work. " ) ) ;
}
else
{
ui . iconlabel_tor_outgoing - > setPixmap ( QPixmap ( ICON_STATUS_UNKNOWN ) ) ;
2015-06-11 10:30:26 -04:00
ui . iconlabel_tor_outgoing - > setToolTip ( tr ( " Tor proxy is not enabled " ) ) ;
2015-05-17 06:00:00 -04:00
}
2015-09-07 12:46:19 -04:00
// I2P
socket . connectToHost ( ui . hiddenpage_proxyAddress_i2p - > text ( ) , ui . hiddenpage_proxyPort_i2p - > text ( ) . toInt ( ) ) ;
if ( socket . waitForConnected ( 500 ) )
{
socket . disconnectFromHost ( ) ;
ui . iconlabel_i2p_outgoing - > setPixmap ( QPixmap ( ICON_STATUS_OK ) ) ;
ui . iconlabel_i2p_outgoing - > setToolTip ( tr ( " Proxy seems to work. " ) ) ;
}
else
{
ui . iconlabel_i2p_outgoing - > setPixmap ( QPixmap ( ICON_STATUS_UNKNOWN ) ) ;
2015-09-14 08:56:14 -04:00
ui . iconlabel_i2p_outgoing - > setToolTip ( tr ( " I2P proxy is not enabled " ) ) ;
2015-09-07 12:46:19 -04:00
}
2015-05-17 06:00:00 -04:00
}
2015-09-07 12:46:19 -04:00
2015-09-07 16:57:54 -04:00
void ServerPage : : updateInProxyIndicator ( )
2015-05-17 06:00:00 -04:00
{
2015-05-18 15:12:15 -04:00
// need to find a proper way to do this
2015-05-21 17:12:48 -04:00
2015-05-18 15:12:15 -04:00
if ( ! mIsHiddenNode )
return ;
2015-05-21 17:44:29 -04:00
if ( manager = = NULL )
manager = new QNetworkAccessManager ( this ) ;
2015-04-02 15:23:01 -04:00
2015-05-17 06:00:00 -04:00
QNetworkProxy proxy ;
2015-04-02 15:23:01 -04:00
2015-05-21 17:12:48 -04:00
proxy . setType ( QNetworkProxy : : Socks5Proxy ) ;
2015-09-07 16:57:54 -04:00
switch ( mHiddenType ) {
case RS_HIDDEN_TYPE_I2P :
proxy . setHostName ( ui . hiddenpage_proxyAddress_i2p - > text ( ) ) ;
proxy . setPort ( ui . hiddenpage_proxyPort_i2p - > text ( ) . toInt ( ) ) ;
break ;
case RS_HIDDEN_TYPE_TOR :
proxy . setHostName ( ui . hiddenpage_proxyAddress_tor - > text ( ) ) ;
proxy . setPort ( ui . hiddenpage_proxyPort_tor - > text ( ) . toInt ( ) ) ;
break ;
2015-09-16 05:48:32 -04:00
default :
return ;
2015-09-07 16:57:54 -04:00
}
2015-05-18 15:12:15 -04:00
proxy . setCapabilities ( QNetworkProxy : : HostNameLookupCapability | proxy . capabilities ( ) ) ;
2015-05-17 06:00:00 -04:00
2015-09-14 08:56:14 -04:00
//ui.iconlabel_tor_incoming->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ;
//ui.testIncomingTor_PB->setIcon(QIcon(":/loader/circleball-16.gif")) ;
QMovie * movie = new QMovie ( " :/images/loader/circleball-16.gif " ) ;
ui . iconlabel_service_incoming - > setMovie ( movie ) ;
movie - > start ( ) ;
2015-05-21 17:12:48 -04:00
QNetworkProxy : : setApplicationProxy ( proxy ) ;
2015-09-07 16:57:54 -04:00
QUrl url ( " https:// " + ui . hiddenpage_serviceAddress - > text ( ) + " : " + ui . hiddenpage_servicePort - > text ( ) ) ;
2015-05-21 17:12:48 -04:00
2015-09-07 06:59:21 -04:00
std : : cerr < < " Setting proxy hostname+port to " < < std : : dec < < ui . hiddenpage_proxyAddress_tor - > text ( ) . toStdString ( ) < < " : " < < ui . hiddenpage_proxyPort_tor - > text ( ) . toInt ( ) < < std : : endl ;
2015-05-21 17:12:48 -04:00
std : : cerr < < " Connecting to " < < url . toString ( ) . toStdString ( ) < < std : : endl ;
connect ( manager , SIGNAL ( finished ( QNetworkReply * ) ) , this , SLOT ( handleNetworkReply ( QNetworkReply * ) ) ) ;
manager - > get ( QNetworkRequest ( url ) ) ;
2015-04-02 15:23:01 -04:00
2015-05-21 17:12:48 -04:00
QNetworkProxy : : setApplicationProxy ( QNetworkProxy : : NoProxy ) ;
}
2015-05-17 06:00:00 -04:00
2015-05-21 17:12:48 -04:00
void ServerPage : : handleNetworkReply ( QNetworkReply * reply )
{
int error = reply - > error ( ) ;
2015-05-17 06:00:00 -04:00
2015-05-21 17:12:48 -04:00
if ( reply - > isOpen ( ) & & error = = QNetworkReply : : SslHandshakeFailedError )
2015-05-17 06:00:00 -04:00
{
std : : cerr < < " Connected! " < < std : : endl ;
2015-09-07 16:57:54 -04:00
ui . iconlabel_service_incoming - > setPixmap ( QPixmap ( ICON_STATUS_OK ) ) ;
ui . iconlabel_service_incoming - > setToolTip ( tr ( " You are reachable through the hidden service. " ) ) ;
2015-05-21 17:12:48 -04:00
//ui.testIncomingTor_PB->setIcon(QIcon(ICON_STATUS_OK)) ;
}
else
{
2015-05-17 06:00:00 -04:00
std : : cerr < < " Failed! " < < std : : endl ;
2015-05-21 17:12:48 -04:00
//ui.testIncomingTor_PB->setIcon(QIcon(ICON_STATUS_UNKNOWN)) ;
2015-09-07 16:57:54 -04:00
ui . iconlabel_service_incoming - > setPixmap ( QPixmap ( ICON_STATUS_UNKNOWN ) ) ;
2015-09-14 08:56:14 -04:00
ui . iconlabel_service_incoming - > setToolTip ( tr ( " The proxy is not enabled or broken. \n Are all services up and running fine?? \n Also check your ports! " ) ) ;
2015-05-18 15:12:15 -04:00
}
2015-05-21 17:12:48 -04:00
reply - > close ( ) ;
2015-04-02 15:23:01 -04:00
}