commit bb16e81f0906a209340533c1a38bbec0b2774de3 Author: Tomás Touceda chiiph@torproject.org Date: Thu Sep 1 13:51:24 2011 -0300
Backport the new ServerPage to master --- src/vidalia/config/ServerPage.cpp | 99 ++++++++++++++++++++------------- src/vidalia/config/ServerPage.ui | 17 ++++-- src/vidalia/config/ServerSettings.cpp | 18 ++++++- src/vidalia/config/ServerSettings.h | 6 ++ 4 files changed, 96 insertions(+), 44 deletions(-)
diff --git a/src/vidalia/config/ServerPage.cpp b/src/vidalia/config/ServerPage.cpp index 5e8e2b6..f15dd96 100644 --- a/src/vidalia/config/ServerPage.cpp +++ b/src/vidalia/config/ServerPage.cpp @@ -89,6 +89,8 @@ ServerPage::ServerPage(QWidget *parent) this, SLOT(customRateChanged())); connect(ui.rdoClientMode, SIGNAL(toggled(bool)), this, SLOT(serverModeChanged(bool))); + connect(ui.rdoNonExitMode, SIGNAL(toggled(bool)), + this, SLOT(serverModeChanged(bool))); connect(ui.rdoServerMode, SIGNAL(toggled(bool)), this, SLOT(serverModeChanged(bool))); connect(ui.rdoBridgeMode, SIGNAL(toggled(bool)), @@ -220,10 +222,12 @@ ServerPage::serverModeChanged(bool enabled) { Q_UNUSED(enabled); bool bridgeEnabled = ui.rdoBridgeMode->isChecked(); + bool relayEnabled = ui.rdoServerMode->isChecked() || + ui.rdoNonExitMode->isChecked();
/* Show the tab menu only if the user is running a normal relay or a bridge * relay. */ - ui.tabsMenu->setVisible(ui.rdoServerMode->isChecked() || bridgeEnabled); + ui.tabsMenu->setVisible(relayEnabled || bridgeEnabled);
/* Disable the Exit Policies tab when bridge relay mode is selected */ ui.tabsMenu->setTabEnabled(2, !bridgeEnabled); @@ -254,6 +258,13 @@ ServerPage::serverModeChanged(bool enabled) ui.lblDirPort->setEnabled(!bridgeEnabled); ui.lineDirPort->setEnabled(!bridgeEnabled); } + + ui.chkWebsites->setEnabled(!ui.rdoNonExitMode->isChecked()); + ui.chkSecWebsites->setEnabled(!ui.rdoNonExitMode->isChecked()); + ui.chkMail->setEnabled(!ui.rdoNonExitMode->isChecked()); + ui.chkIRC->setEnabled(!ui.rdoNonExitMode->isChecked()); + ui.chkIM->setEnabled(!ui.rdoNonExitMode->isChecked()); + ui.chkMisc->setEnabled(!ui.rdoNonExitMode->isChecked()); }
/** Returns true if the user has changed their server settings since the @@ -287,8 +298,10 @@ ServerPage::save(QString &errmsg) { /* Force the bandwidth rate limits to validate */ customRateChanged(); - - if (ui.rdoServerMode->isChecked() || ui.rdoBridgeMode->isChecked()) { + + if (ui.rdoServerMode->isChecked() || + ui.rdoNonExitMode->isChecked() || + ui.rdoBridgeMode->isChecked()) { /* A server must have an ORPort and a nickname */ if (ui.lineServerPort->text().isEmpty() || ui.lineServerNickname->text().isEmpty()) { @@ -307,7 +320,9 @@ ServerPage::save(QString &errmsg) /* "Server" is enabled whether we're a bridge or normal relay. "Bridge" is * only enabled if we're a bridge (obviously). */ _settings->setServerEnabled(ui.rdoServerMode->isChecked() - || ui.rdoBridgeMode->isChecked()); + || ui.rdoNonExitMode->isChecked() + || ui.rdoBridgeMode->isChecked()); + _settings->setNonExitEnabled(ui.rdoNonExitMode->isChecked()); _settings->setBridgeEnabled(ui.rdoBridgeMode->isChecked()); if (ui.rdoBridgeMode->isChecked()) _settings->setPublishServerDescriptor(ui.chkPublishBridgeAddress->isChecked()); @@ -338,6 +353,8 @@ ServerPage::load() { if (_settings->isBridgeEnabled()) ui.rdoBridgeMode->setChecked(true); + else if (_settings->isNonExitEnabled()) + ui.rdoNonExitMode->setChecked(true); else if (_settings->isServerEnabled()) ui.rdoServerMode->setChecked(true); else @@ -478,41 +495,47 @@ ServerPage::loadExitPolicies() void ServerPage::saveExitPolicies() { - ExitPolicy exitPolicy; - bool rejectUnchecked = ui.chkMisc->isChecked(); - - /* If misc is checked, then reject unchecked items and leave the default exit - * policy alone. Else, accept only checked items and end with reject *:*, - * replacing the default exit policy. */ - if (ui.chkWebsites->isChecked() && !rejectUnchecked) { - exitPolicy.addAcceptedPorts(PORTS_HTTP); - } else if (!ui.chkWebsites->isChecked() && rejectUnchecked) { - exitPolicy.addRejectedPorts(PORTS_HTTP); - } - if (ui.chkSecWebsites->isChecked() && !rejectUnchecked) { - exitPolicy.addAcceptedPorts(PORTS_HTTPS); - } else if (!ui.chkSecWebsites->isChecked() && rejectUnchecked) { - exitPolicy.addRejectedPorts(PORTS_HTTPS); - } - if (ui.chkMail->isChecked() && !rejectUnchecked) { - exitPolicy.addAcceptedPorts(PORTS_MAIL); - } else if (!ui.chkMail->isChecked() && rejectUnchecked) { - exitPolicy.addRejectedPorts(PORTS_MAIL); - } - if (ui.chkIRC->isChecked() && !rejectUnchecked) { - exitPolicy.addAcceptedPorts(PORTS_IRC); - } else if (!ui.chkIRC->isChecked() && rejectUnchecked) { - exitPolicy.addRejectedPorts(PORTS_IRC); - } - if (ui.chkIM->isChecked() && !rejectUnchecked) { - exitPolicy.addAcceptedPorts(PORTS_IM); - } else if (!ui.chkIM->isChecked() && rejectUnchecked) { - exitPolicy.addRejectedPorts(PORTS_IM); - } - if (!ui.chkMisc->isChecked()) { - exitPolicy.addPolicy(Policy(Policy::RejectAll)); + ExitPolicy *exitPolicy; + if(ui.rdoNonExitMode->isChecked()) { + exitPolicy = new ExitPolicy(ExitPolicy::Middleman); + } else { + exitPolicy = new ExitPolicy(); + bool rejectUnchecked = ui.chkMisc->isChecked(); + + /* If misc is checked, then reject unchecked items and leave the default exit + * policy alone. Else, accept only checked items and end with reject *:*, + * replacing the default exit policy. */ + if (ui.chkWebsites->isChecked() && !rejectUnchecked) { + exitPolicy->addAcceptedPorts(PORTS_HTTP); + } else if (!ui.chkWebsites->isChecked() && rejectUnchecked) { + exitPolicy->addRejectedPorts(PORTS_HTTP); + } + if (ui.chkSecWebsites->isChecked() && !rejectUnchecked) { + exitPolicy->addAcceptedPorts(PORTS_HTTPS); + } else if (!ui.chkSecWebsites->isChecked() && rejectUnchecked) { + exitPolicy->addRejectedPorts(PORTS_HTTPS); + } + if (ui.chkMail->isChecked() && !rejectUnchecked) { + exitPolicy->addAcceptedPorts(PORTS_MAIL); + } else if (!ui.chkMail->isChecked() && rejectUnchecked) { + exitPolicy->addRejectedPorts(PORTS_MAIL); + } + if (ui.chkIRC->isChecked() && !rejectUnchecked) { + exitPolicy->addAcceptedPorts(PORTS_IRC); + } else if (!ui.chkIRC->isChecked() && rejectUnchecked) { + exitPolicy->addRejectedPorts(PORTS_IRC); + } + if (ui.chkIM->isChecked() && !rejectUnchecked) { + exitPolicy->addAcceptedPorts(PORTS_IM); + } else if (!ui.chkIM->isChecked() && rejectUnchecked) { + exitPolicy->addRejectedPorts(PORTS_IM); + } + if (!ui.chkMisc->isChecked()) { + exitPolicy->addPolicy(Policy(Policy::RejectAll)); + } } - _settings->setExitPolicy(exitPolicy); + + _settings->setExitPolicy(*exitPolicy); }
/** Called when the user selects a new value from the rate combo box. */ diff --git a/src/vidalia/config/ServerPage.ui b/src/vidalia/config/ServerPage.ui index a642471..cfb3251 100644 --- a/src/vidalia/config/ServerPage.ui +++ b/src/vidalia/config/ServerPage.ui @@ -23,28 +23,28 @@ </property> </widget> </item> - <item row="1" column="0" colspan="3"> + <item row="2" column="0" colspan="3"> <widget class="QRadioButton" name="rdoServerMode"> <property name="text"> - <string>Relay traffic for the Tor network</string> + <string>Relay traffic for the Tor network (exit relay)</string> </property> </widget> </item> - <item row="2" column="0"> + <item row="3" column="0"> <widget class="QRadioButton" name="rdoBridgeMode"> <property name="text"> <string>Help censored users reach the Tor network</string> </property> </widget> </item> - <item row="2" column="1"> + <item row="3" column="1"> <widget class="QLabel" name="lblWhatsThis"> <property name="text"> <string><a href="#bridgeHelp">What's this?</a></string> </property> </widget> </item> - <item row="2" column="2" colspan="2"> + <item row="3" column="2" colspan="2"> <spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -57,6 +57,13 @@ </property> </spacer> </item> + <item row="1" column="0" colspan="3"> + <widget class="QRadioButton" name="rdoNonExitMode"> + <property name="text"> + <string>Relay traffic inside the Tor network (non-exit relay)</string> + </property> + </widget> + </item> </layout> </item> <item> diff --git a/src/vidalia/config/ServerSettings.cpp b/src/vidalia/config/ServerSettings.cpp index 91f8600..f1caa53 100644 --- a/src/vidalia/config/ServerSettings.cpp +++ b/src/vidalia/config/ServerSettings.cpp @@ -43,6 +43,7 @@ #define SETTING_BANDWIDTH_RATE "BandwidthRate" #define SETTING_BANDWIDTH_BURST "BandwidthBurst" #define SETTING_BRIDGE_RELAY "BridgeRelay" +#define SETTING_NONEXIT_RELAY "NonExitRelay" #define SETTING_ENABLE_UPNP "EnableUPnP" #define SETTING_RELAY_BANDWIDTH_RATE "RelayBandwidthRate" #define SETTING_RELAY_BANDWIDTH_BURST "RelayBandwidthBurst" @@ -71,7 +72,7 @@ ServerSettings::ServerSettings(TorControl *torControl) setDefault(SETTING_BANDWIDTH_BURST, 10485760); setDefault(SETTING_RELAY_BANDWIDTH_BURST, 10485760); setDefault(SETTING_EXITPOLICY, - ExitPolicy(ExitPolicy::Default).toString()); + ExitPolicy(ExitPolicy::Middleman).toString()); setDefault(SETTING_ENABLE_UPNP, false); setDefault(SETTING_BRIDGE_RELAY, false); setDefault(SETTING_PUBLISH_SERVER_DESCRIPTOR, "1"); @@ -257,6 +258,21 @@ ServerSettings::isBridgeEnabled() { return value(SETTING_BRIDGE_RELAY).toBool() && isServerEnabled(); } + +/** Sets to <b>enabled</b> whether Tor should be a non-exit node when acting as + * a server. */ +void +ServerSettings::setNonExitEnabled(bool enabled) +{ + setValue(SETTING_NONEXIT_RELAY, enabled); +} + +/** Returns true if Tor is configured to act as a non-exit node. */ +bool +ServerSettings::isNonExitEnabled() +{ + return value(SETTING_NONEXIT_RELAY).toBool() && isServerEnabled(); +}
/** Sets the server's ORPort. */ void diff --git a/src/vidalia/config/ServerSettings.h b/src/vidalia/config/ServerSettings.h index 775c92d..9479c5a 100644 --- a/src/vidalia/config/ServerSettings.h +++ b/src/vidalia/config/ServerSettings.h @@ -42,6 +42,12 @@ public: /** Returns true if Tor is configured to act as a bridge node. */ bool isBridgeEnabled();
+ /** Sets to <b>enabled</b> whether Tor should be a non-exit node when acting + * as a server. */ + void setNonExitEnabled(bool enable); + /** Returns true if Tor is configured to act as a non-exit node. */ + bool isNonExitEnabled(); + /** Sets the server's ORPort value. */ void setORPort(quint16 orPort); /** Gets the server's ORPort value. */