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"
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 )
2014-01-17 21:35:06 -05:00
: ConfigPage ( parent , flags ) , mIsHiddenNode ( false )
2009-07-23 13:11:51 -04:00
{
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
connect ( ui . netModeComboBox , SIGNAL ( activated ( int ) ) , this , SLOT ( toggleUPnP ( ) ) ) ;
connect ( ui . allowIpDeterminationCB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleIpDetermination ( bool ) ) ) ;
2015-05-17 06:00:00 -04:00
connect ( ui . cleanKnownIPs_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( clearKnownAddressList ( ) ) ) ;
2015-05-21 17:12:48 -04:00
connect ( ui . testIncomingTor_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( updateTorInProxyIndicator ( ) ) ) ;
2009-07-23 13:11:51 -04:00
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 " ) ) ) ;
ui . filteredIpsTable - > verticalHeader ( ) - > hide ( ) ;
QObject : : connect ( ui . filteredIpsTable , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( ipFilterContextMenu ( const QPoint & ) ) ) ;
QObject : : connect ( ui . denyAll_CB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( toggleIpFiltering ( bool ) ) ) ;
2009-07-23 13:11:51 -04:00
QTimer * timer = new QTimer ( this ) ;
timer - > connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateStatus ( ) ) ) ;
timer - > start ( 1000 ) ;
2013-02-22 16:42:27 -05:00
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 ) ) ;
2014-01-19 01:27:02 -05:00
ui . torpage_incoming - > setVisible ( false ) ;
2009-07-23 13:11:51 -04:00
/* Hide platform specific features */
# ifdef Q_WS_WIN
# endif
2014-01-17 21:35:06 -05:00
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
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
}
2009-07-23 13:11:51 -04:00
/** Saves the changes on this page */
bool
2011-08-12 10:06:29 -04:00
ServerPage : : save ( QString & /*errmsg*/ )
2009-07-23 13:11:51 -04:00
{
2011-01-07 11:56:57 -05:00
Settings - > setStatusBarFlag ( STATUSBAR_DISC , ui . showDiscStatusBar - > isChecked ( ) ) ;
2009-07-23 13:11:51 -04:00
/* save the server address */
/* save local address */
/* save the url for DNS access */
/* restart server */
/* save all? */
saveAddresses ( ) ;
return true ;
}
/** 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
}
loadFilteredIps ( ) ;
mIsHiddenNode = ( detail . netMode = = RS_NETMODE_HIDDEN ) ;
2009-07-23 13:11:51 -04:00
2014-01-17 21:35:06 -05:00
if ( mIsHiddenNode )
{
loadHiddenNode ( ) ;
return ;
}
2015-04-13 15:00:09 -04:00
ui . netModeComboBox - > show ( ) ;
ui . hiddenMode_LB - > hide ( ) ;
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.
2013-09-29 03:10:19 -04:00
if ( detail . vs_dht ! = RS_VS_DISC_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
/* TOR PAGE SETTINGS - only Proxy (outgoing) */
std : : string proxyaddr ;
2014-09-28 15:24:03 -04:00
uint16_t proxyport ;
uint32_t status ;
rsPeers - > getProxyServer ( proxyaddr , proxyport , status ) ;
2014-01-19 01:27:02 -05:00
ui . torpage_proxyAddress - > setText ( QString : : fromStdString ( proxyaddr ) ) ;
2014-09-28 15:24:03 -04:00
ui . torpage_proxyPort - > setValue ( proxyport ) ;
2015-05-18 15:12:15 -04:00
updateTorOutProxyIndicator ( ) ;
2012-11-25 09:26:32 -05:00
}
2015-05-27 17:30:40 -04:00
static std : : string print_addr ( const struct sockaddr_storage & addr )
{
const sockaddr_in * in = ( const sockaddr_in * ) & addr ;
char str [ 100 ] ;
uint8_t * bytes = ( uint8_t * ) & ( in - > sin_addr . s_addr ) ;
sprintf ( str , " %u.%u.%u.%u " , ( int ) bytes [ 0 ] , ( int ) bytes [ 1 ] , ( int ) bytes [ 2 ] , ( int ) bytes [ 3 ] ) ;
return std : : string ( str ) ;
}
std : : string print_addr_range ( const struct sockaddr_storage & addr , uint8_t masked_bytes )
{
const sockaddr_in * in = ( const sockaddr_in * ) & addr ;
char str [ 100 ] ;
uint8_t * bytes = ( uint8_t * ) & ( in - > sin_addr . s_addr ) ;
str [ 0 ] = 0 ;
switch ( masked_bytes )
{
case 0 : sprintf ( str , " %u.%u.%u.%u " , ( int ) bytes [ 0 ] , ( int ) bytes [ 1 ] , ( int ) bytes [ 2 ] , ( int ) bytes [ 3 ] ) ;
break ;
case 1 : sprintf ( str , " %u.%u.%u.255/24 " , ( int ) bytes [ 0 ] , ( int ) bytes [ 1 ] , ( int ) bytes [ 2 ] ) ;
break ;
case 2 : sprintf ( str , " %u.%u.255.255/16 " , ( int ) bytes [ 0 ] , ( int ) bytes [ 1 ] ) ;
break ;
default :
std : : cerr < < " ERROR: Wrong format : masked_bytes = " < < masked_bytes < < std : : endl ;
return std : : string ( " Invalid format " ) ;
}
return std : : string ( str ) ;
}
void ServerPage : : toggleIpFiltering ( bool b )
{
rsBanList - > enableIPFiltering ( b ) ;
loadFilteredIps ( ) ;
}
void ServerPage : : loadFilteredIps ( )
{
ui . includeFromFriends_CB - > setChecked ( false ) ;
ui . includeFromDHT_CB - > setChecked ( true ) ;
ui . ipInput_LE - > setEnabled ( false ) ;
ui . ipInputRange_SB - > setEnabled ( false ) ;
ui . ipInputComment_LE - > setEnabled ( false ) ;
ui . ipInputAdd_PB - > setEnabled ( false ) ;
if ( rsBanList - > ipFilteringEnabled ( ) )
{
ui . denyAll_CB - > setChecked ( true ) ;
ui . filteredIpsTable - > setEnabled ( true ) ;
ui . includeFromFriends_CB - > setEnabled ( false ) ;
ui . includeFromDHT_CB - > setEnabled ( false ) ;
}
else
{
ui . denyAll_CB - > setChecked ( false ) ;
ui . filteredIpsTable - > setEnabled ( false ) ;
ui . includeFromFriends_CB - > setEnabled ( false ) ;
ui . includeFromDHT_CB - > setEnabled ( false ) ;
}
std : : list < BanListPeer > lst ;
rsBanList - > getListOfBannedIps ( lst ) ;
ui . filteredIpsTable - > setRowCount ( lst . size ( ) ) ;
//std::cerr << "Adding " << lst.size() << " entries to table." << std::endl;
int row = 0 ;
for ( std : : list < BanListPeer > : : const_iterator it ( lst . begin ( ) ) ; it ! = lst . end ( ) ; + + it , + + row )
{
//std::cerr << " adding banned lst peer: " << print_addr((*it).addr) << std::endl;
ui . filteredIpsTable - > setItem ( row , COLUMN_RANGE , new QTableWidgetItem ( QString : : fromStdString ( print_addr_range ( ( * it ) . addr , ( * it ) . masked_bytes ) ) ) ) ;
if ( ( * it ) . state )
ui . filteredIpsTable - > setItem ( row , COLUMN_STATUS , new QTableWidgetItem ( QString ( " active " ) ) ) ;
else
ui . filteredIpsTable - > setItem ( row , COLUMN_STATUS , new QTableWidgetItem ( QString ( " " ) ) ) ;
ui . filteredIpsTable - > item ( row , COLUMN_STATUS ) - > setData ( Qt : : UserRole , QVariant ( ( * it ) . state ) ) ;
switch ( ( * it ) . level )
{
default :
case RSBANLIST_ORIGIN_UNKNOWN : ui . filteredIpsTable - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " Unknown " ) ) ) ;
break ;
case RSBANLIST_ORIGIN_FOF : ui . filteredIpsTable - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " From friend of a friend " ) ) ) ;
break ;
case RSBANLIST_ORIGIN_FRIEND : ui . filteredIpsTable - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " From friend " ) ) ) ;
break ;
case RSBANLIST_ORIGIN_SELF : ui . filteredIpsTable - > setItem ( row , COLUMN_ORIGIN , new QTableWidgetItem ( QString ( " From you " ) ) ) ;
break ;
}
switch ( ( * it ) . reason )
{
case RSBANLIST_REASON_DHT : ui . filteredIpsTable - > setItem ( row , COLUMN_REASON , new QTableWidgetItem ( QString ( " Bad peer (DHT) " ) ) ) ;
break ;
case RSBANLIST_REASON_USER : ui . filteredIpsTable - > setItem ( row , COLUMN_REASON , new QTableWidgetItem ( QString ( " Home-made rule " ) ) ) ;
break ;
default :
case RSBANLIST_REASON_UNKNOWN : ui . filteredIpsTable - > setItem ( row , COLUMN_REASON , new QTableWidgetItem ( QString ( " Unknown " ) ) ) ;
break ;
}
ui . filteredIpsTable - > setItem ( row , COLUMN_COMMENT , new QTableWidgetItem ( QString : : fromStdString ( ( * it ) . comment ) ) ) ;
}
}
static bool parseAddrFromQString ( const QString & s , struct sockaddr_storage & addr , int & bytes )
{
QStringList lst = s . split ( " . " ) ;
QStringList : : const_iterator it = lst . begin ( ) ;
bool ok ;
uint32_t s1 = ( * it ) . toInt ( & ok ) ; + + it ; if ( ! ok ) return false ;
uint32_t s2 = ( * it ) . toInt ( & ok ) ; + + it ; if ( ! ok ) return false ;
uint32_t s3 = ( * it ) . toInt ( & ok ) ; + + it ; if ( ! ok ) return false ;
QStringList lst2 = ( * it ) . split ( " / " ) ;
it = lst2 . begin ( ) ;
uint32_t s4 ;
s4 = ( * it ) . toInt ( & ok ) ; + + it ; if ( ! ok ) return false ;
if ( it ! = lst2 . end ( ) )
{
uint32_t x = ( * it ) . toInt ( & ok ) ; if ( ! ok ) return false ;
if ( x % 8 ! = 0 )
return false ;
if ( x ! = 16 & & x ! = 24 )
return false ;
bytes = 4 - x / 8 ;
}
const sockaddr_in * in = ( const sockaddr_in * ) & addr ;
( ( uint8_t * ) & in - > sin_addr . s_addr ) [ 0 ] = s1 ;
( ( uint8_t * ) & in - > sin_addr . s_addr ) [ 1 ] = s2 ;
( ( uint8_t * ) & in - > sin_addr . s_addr ) [ 2 ] = s3 ;
( ( uint8_t * ) & in - > sin_addr . s_addr ) [ 3 ] = s4 ;
return ok ;
}
void ServerPage : : ipFilterContextMenu ( const QPoint & point )
{
QMenu contextMenu ( this ) ;
int row = ui . filteredIpsTable - > currentRow ( ) ;
QTableWidgetItem * item = ui . filteredIpsTable - > item ( row , COLUMN_STATUS ) ;
if ( item = = NULL )
return ;
bool status = item - > data ( Qt : : UserRole ) . toBool ( ) ;
if ( ! status )
contextMenu . addAction ( tr ( " Disable/remove " ) , this , SLOT ( removeBannedIp ( ) ) ) - > setEnabled ( false ) ;
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 ;
}
QString range0 = QString : : fromStdString ( print_addr_range ( addr , 0 ) ) ;
QString range1 = QString : : fromStdString ( print_addr_range ( addr , 1 ) ) ;
QString range2 = QString : : fromStdString ( print_addr_range ( addr , 2 ) ) ;
contextMenu . addAction ( QObject : : tr ( " Filter IP " ) + range0 , this , SLOT ( enableBannedIp ( ) ) ) - > setEnabled ( false ) ;
# warning UNIMPLEMENTED CODE
contextMenu . addAction ( QObject : : tr ( " Filter entire range " ) + range1 , this , SLOT ( enableBannedIp ( ) ) ) - > setEnabled ( false ) ;
contextMenu . addAction ( QObject : : tr ( " Filter entire range " ) + range2 , this , SLOT ( enableBannedIp ( ) ) ) - > setEnabled ( false ) ;
contextMenu . exec ( QCursor : : pos ( ) ) ;
}
void ServerPage : : removeBannedIp ( )
{
# warning UNIMPLEMENTED CODE
std : : cerr < < " Removing banned IP " < < std : : endl ;
}
void ServerPage : : enableBannedIp ( )
{
# warning UNIMPLEMENTED CODE
std : : cerr < < " Removing banned IP " < < std : : endl ;
}
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 " ) ) ;
// check for TOR
2015-05-18 15:12:15 -04:00
updateTorOutProxyIndicator ( ) ;
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 ( ) ) ;
2012-11-25 15:26:32 -05:00
rsConfig - > SetMaxDataRates ( ui . totalDownloadRate - > value ( ) , ui . totalUploadRate - > value ( ) ) ;
2010-04-22 14:49:08 -04:00
2014-01-19 01:27:02 -05:00
// HANDLE PROXY SERVER.
std : : string orig_proxyaddr ;
2014-09-28 15:24:03 -04:00
uint16_t orig_proxyport ;
uint32_t status ;
rsPeers - > getProxyServer ( orig_proxyaddr , orig_proxyport , status ) ;
2014-01-19 01:27:02 -05:00
std : : string new_proxyaddr = ui . torpage_proxyAddress - > text ( ) . toStdString ( ) ;
uint16_t new_proxyport = ui . torpage_proxyPort - > value ( ) ;
if ( ( new_proxyaddr ! = orig_proxyaddr ) | | ( new_proxyport ! = orig_proxyport ) )
{
rsPeers - > setProxyServer ( new_proxyaddr , new_proxyport ) ;
}
2009-07-23 13:11:51 -04:00
load ( ) ;
}
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 )
* External Address = = > TOR Address : 17621376587. onion + PORT .
*
* 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 ( ) ;
ui . hiddenMode_LB - > show ( ) ;
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 ) ;
ui . torpage_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 */
2014-01-19 01:27:02 -05:00
ui . extAddress - > setText ( tr ( " Hidden - See TOR 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 */
ui . torpage_localAddress - > setEnabled ( false ) ;
ui . torpage_localAddress - > setText ( QString : : fromStdString ( detail . localAddr ) ) ;
ui . torpage_localPort - > setValue ( detail . localPort ) ;
/* set the server address */
ui . torpage_onionAddress - > setText ( QString : : fromStdString ( detail . hiddenNodeAddress ) ) ;
ui . torpage_onionPort - > setValue ( detail . hiddenNodePort ) ;
std : : string proxyaddr ;
2014-09-28 15:24:03 -04:00
uint16_t proxyport ;
uint32_t proxy_state_flags ;
rsPeers - > getProxyServer ( proxyaddr , proxyport , proxy_state_flags ) ;
2014-01-19 01:27:02 -05:00
ui . torpage_proxyAddress - > setText ( QString : : fromStdString ( proxyaddr ) ) ;
ui . torpage_proxyPort - > setValue ( proxyport ) ;
2015-05-18 15:12:15 -04:00
updateTorOutProxyIndicator ( ) ;
2014-01-19 01:27:02 -05:00
QString expected = " HiddenServiceDir </your/path/to/hidden/directory/service> \n " ;
expected + = " HiddenServicePort " ;
expected + = QString : : number ( detail . hiddenNodePort ) ;
expected + = " " ;
expected + = QString : : fromStdString ( detail . localAddr ) ;
expected + = " : " ;
expected + = QString : : number ( detail . localPort ) ;
ui . torpage_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-05-18 15:12:15 -04:00
updateTorOutProxyIndicator ( ) ;
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 ) ;
2014-01-19 01:27:02 -05:00
if ( detail . localPort ! = ui . torpage_localPort - > value ( ) )
2014-01-18 00:05:35 -05:00
{
// Set Local Address - force to 127.0.0.1
2014-01-19 01:27:02 -05:00
rsPeers - > setLocalAddress ( ownId , " 127.0.0.1 " , ui . torpage_localPort - > value ( ) ) ;
2014-01-18 00:05:35 -05:00
}
2014-01-19 01:27:02 -05:00
std : : string hiddenAddr = ui . torpage_onionAddress - > text ( ) . toStdString ( ) ;
uint16_t hiddenPort = ui . torpage_onionPort - > value ( ) ;
2014-01-17 21:35:06 -05:00
if ( ( hiddenAddr ! = detail . hiddenNodeAddress ) | | ( hiddenPort ! = detail . hiddenNodePort ) )
{
rsPeers - > setHiddenNode ( ownId , hiddenAddr , hiddenPort ) ;
}
// HANDLE PROXY SERVER.
std : : string orig_proxyaddr ;
2014-09-28 15:24:03 -04:00
uint16_t orig_proxyport ;
uint32_t state_flags ;
rsPeers - > getProxyServer ( orig_proxyaddr , orig_proxyport , state_flags ) ;
2014-01-17 21:35:06 -05:00
2014-01-19 01:27:02 -05:00
std : : string new_proxyaddr = ui . torpage_proxyAddress - > text ( ) . toStdString ( ) ;
uint16_t new_proxyport = ui . torpage_proxyPort - > value ( ) ;
2014-01-17 21:35:06 -05:00
if ( ( new_proxyaddr ! = orig_proxyaddr ) | | ( new_proxyport ! = orig_proxyport ) )
{
rsPeers - > setProxyServer ( new_proxyaddr , new_proxyport ) ;
}
rsConfig - > SetMaxDataRates ( ui . totalDownloadRate - > value ( ) , ui . totalUploadRate - > value ( ) ) ;
2009-07-23 13:11:51 -04:00
load ( ) ;
}
2015-04-02 15:23:01 -04:00
void ServerPage : : updateTorOutProxyIndicator ( )
{
2015-05-17 06:00:00 -04:00
QTcpSocket socket ;
socket . connectToHost ( ui . torpage_proxyAddress - > text ( ) , ui . torpage_proxyPort - > text ( ) . toInt ( ) ) ;
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 ) ) ;
ui . iconlabel_tor_outgoing - > setToolTip ( tr ( " TOR proxy is not enabled " ) ) ;
}
}
void ServerPage : : updateLocInProxyIndicator ( )
{
QTcpSocket socket ;
socket . connectToHost ( ui . torpage_localAddress - > text ( ) , ui . torpage_localPort - > text ( ) . toInt ( ) ) ;
if ( socket . waitForConnected ( 1000 ) )
{
socket . disconnectFromHost ( ) ;
2015-05-21 17:12:48 -04:00
ui . iconlabel_tor_incoming - > setPixmap ( QPixmap ( ICON_STATUS_OK ) ) ;
ui . iconlabel_tor_incoming - > setToolTip ( tr ( " You are reachable through TOR. " ) ) ;
2015-05-17 06:00:00 -04:00
}
else
{
2015-05-21 17:12:48 -04:00
ui . iconlabel_tor_incoming - > setPixmap ( QPixmap ( ICON_STATUS_UNKNOWN ) ) ;
ui . iconlabel_tor_incoming - > setToolTip ( tr ( " TOR proxy is not enabled or broken. \n Are you running a TOR hidden service? \n Check your ports! " ) ) ;
2015-05-17 06:00:00 -04:00
}
}
void ServerPage : : updateTorInProxyIndicator ( )
{
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-05-17 06:00:00 -04:00
proxy . setHostName ( ui . torpage_proxyAddress - > text ( ) ) ;
proxy . setPort ( ui . torpage_proxyPort - > text ( ) . toInt ( ) ) ;
2015-05-18 15:12:15 -04:00
proxy . setCapabilities ( QNetworkProxy : : HostNameLookupCapability | proxy . capabilities ( ) ) ;
2015-05-17 06:00:00 -04:00
2015-05-21 17:12:48 -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_tor_incoming - > setMovie ( movie ) ;
movie - > start ( ) ;
QNetworkProxy : : setApplicationProxy ( proxy ) ;
QUrl url ( " https:// " + ui . torpage_onionAddress - > text ( ) + " : " + ui . torpage_onionPort - > text ( ) ) ;
2015-05-18 15:12:15 -04:00
std : : cerr < < " Setting proxy hostname+port to " < < std : : dec < < ui . torpage_proxyAddress - > text ( ) . toStdString ( ) < < " : " < < ui . torpage_proxyPort - > 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 ;
ui . iconlabel_tor_incoming - > setPixmap ( QPixmap ( ICON_STATUS_OK ) ) ;
ui . iconlabel_tor_incoming - > setToolTip ( tr ( " You are reachable through TOR. " ) ) ;
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-05-17 06:00:00 -04:00
ui . iconlabel_tor_incoming - > setPixmap ( QPixmap ( ICON_STATUS_UNKNOWN ) ) ;
ui . iconlabel_tor_incoming - > setToolTip ( tr ( " TOR proxy is not enabled or broken. \n Are you running a TOR hidden service? \n 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
}