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>
2009-07-23 13:11:51 -04:00
2015-05-21 17:12:48 -04:00
# include <QMovie>
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"
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 ;
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 ;
}
2014-01-17 21:35:06 -05:00
mIsHiddenNode = ( detail . netMode = = RS_NETMODE_HIDDEN ) ;
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-16 09:59:26 -04:00
//void ServerPage::toggleTurtleRouting(bool b)
//{
// ui._max_tr_up_per_sec_SB->setEnabled(b) ;
//
// rsTurtle->setEnabled(b) ;
//}
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
2014-01-17 21:35:06 -05:00
if ( mIsHiddenNode )
{
updateStatusHiddenNode ( ) ;
return ;
}
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
}