[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [vidalia/alpha] Add an autoconfiguration for ControlPort
commit 438113de5bc9288fbaa25f5c11a8ba7af9d7f10f
Author: Tomas Touceda <chiiph@xxxxxxxxxx>
Date: Wed Jun 29 16:02:37 2011 -0300
Add an autoconfiguration for ControlPort
---
src/vidalia/MainWindow.cpp | 56 ++++++++++++++++++++++++++--------
src/vidalia/config/AdvancedPage.cpp | 12 +++++++
src/vidalia/config/AdvancedPage.h | 3 ++
src/vidalia/config/AdvancedPage.ui | 19 ++++++++----
src/vidalia/config/TorSettings.cpp | 14 +++++++++
src/vidalia/config/TorSettings.h | 7 ++++
6 files changed, 92 insertions(+), 19 deletions(-)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 46cd0db..a6c9fa4 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -528,8 +528,8 @@ MainWindow::start()
/* Check if Tor is already running separately */
if(settings.getControlMethod() == ControlMethod::Port) {
- if (net_test_connect(settings.getControlAddress(),
- settings.getControlPort())) {
+ if(!settings.autoControlPort() && net_test_connect(settings.getControlAddress(),
+ settings.getControlPort())) {
started();
return;
}
@@ -562,14 +562,21 @@ MainWindow::start()
/* Specify Tor's data directory, if different from the default */
QString dataDirectory = settings.getDataDirectory();
+ QString expDataDirectory = expand_filename(dataDirectory);
if (!dataDirectory.isEmpty())
- args << "DataDirectory" << expand_filename(dataDirectory);
+ args << "DataDirectory" << expDataDirectory;
if(settings.getControlMethod() == ControlMethod::Port) {
- /* Add the intended control port value */
- quint16 controlPort = settings.getControlPort();
- if (controlPort)
- args << "ControlPort" << QString::number(controlPort);
+ if(settings.autoControlPort()) {
+ args << "ControlPort" << "auto";
+ args << "SocksPort" << "auto";
+ args << "ControlPortWriteToFile" << QString("%1/port.conf").arg(expDataDirectory);
+ } else {
+ /* Add the intended control port value */
+ quint16 controlPort = settings.getControlPort();
+ if (controlPort)
+ args << "ControlPort" << QString::number(controlPort);
+ }
} else {
QString path = settings.getSocketPath();
args << "ControlSocket" << path;
@@ -622,12 +629,35 @@ MainWindow::started()
_delayedShutdownStarted = false;
/* Remember whether we started Tor or not */
_isVidaliaRunningTor = _torControl->isVidaliaRunningTor();
- /* Try to connect to Tor's control port */
- if(settings.getControlMethod() == ControlMethod::Port)
- _torControl->connect(settings.getControlAddress(),
- settings.getControlPort());
- else
- _torControl->connect(settings.getSocketPath());
+
+ if(settings.autoControlPort()) {
+ QString dataDirectory = settings.getDataDirectory();
+ QFile file(QString("%1/port.conf").arg(expand_filename(dataDirectory)));
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return;
+
+ QTextStream in(&file);
+ if(!in.atEnd()) {
+ QString line = in.readLine();
+ QStringList parts = line.split("=");
+ if(parts.size() != 2) return;
+ if(parts[0].trimmed() != "PORT") return;
+
+ QStringList addrPort = parts[1].split(":");
+ if(addrPort.size() != 2) return;
+
+ QHostAddress addr(addrPort.at(0));
+ quint16 port = addrPort.at(1).toInt();
+ _torControl->connect(addr, port);
+ }
+ } else {
+ /* Try to connect to Tor's control port */
+ if(settings.getControlMethod() == ControlMethod::Port)
+ _torControl->connect(settings.getControlAddress(),
+ settings.getControlPort());
+ else
+ _torControl->connect(settings.getSocketPath());
+ }
setStartupProgress(STARTUP_PROGRESS_CONNECTING, tr("Connecting to Tor"));
}
diff --git a/src/vidalia/config/AdvancedPage.cpp b/src/vidalia/config/AdvancedPage.cpp
index a879ecc..4e7c3f6 100644
--- a/src/vidalia/config/AdvancedPage.cpp
+++ b/src/vidalia/config/AdvancedPage.cpp
@@ -64,6 +64,7 @@ AdvancedPage::AdvancedPage(QWidget *parent)
this, SLOT(displayTorrcDialog()));
connect(ui.rdoControlPort, SIGNAL(toggled(bool)), this, SLOT(toggleControl(bool)));
connect(ui.btnBrowseSocketPath, SIGNAL(clicked()), this, SLOT(browseSocketPath()));
+ connect(ui.chkAuto, SIGNAL(toggled(bool)), this, SLOT(toggleAuto(bool)));
/* Hide platform specific features */
#if defined(Q_WS_WIN)
@@ -187,6 +188,7 @@ AdvancedPage::save(QString &errmsg)
_settings->setControlAddress(controlAddress);
_settings->setControlPort(ui.lineControlPort->text().toUShort());
_settings->setSocketPath(ui.lineSocketPath->text());
+ _settings->setAutoControlPort(ui.chkAuto->isChecked());
_settings->setAuthenticationMethod(authMethod);
_settings->setUseRandomPassword(ui.chkRandomPassword->isChecked());
@@ -212,6 +214,7 @@ AdvancedPage::load()
ui.lineControlPort->setText(QString::number(_settings->getControlPort()));
ui.lineTorConfig->setText(_settings->getTorrc());
ui.lineTorDataDirectory->setText(_settings->getDataDirectory());
+ ui.chkAuto->setChecked(_settings->autoControlPort());
ui.cmbAuthMethod->setCurrentIndex(
authMethodToIndex(_settings->getAuthenticationMethod()));
@@ -402,3 +405,12 @@ AdvancedPage::toggleControl(bool)
#endif
}
}
+
+void
+AdvancedPage::toggleAuto(bool)
+{
+ ui.lblAddress->setEnabled(!ui.chkAuto->isChecked());
+ ui.lineControlAddress->setEnabled(!ui.chkAuto->isChecked());
+ ui.label->setEnabled(!ui.chkAuto->isChecked());
+ ui.lineControlPort->setEnabled(!ui.chkAuto->isChecked());
+}
diff --git a/src/vidalia/config/AdvancedPage.h b/src/vidalia/config/AdvancedPage.h
index 4ba26cc..4510310 100644
--- a/src/vidalia/config/AdvancedPage.h
+++ b/src/vidalia/config/AdvancedPage.h
@@ -75,6 +75,9 @@ private slots:
* a more advanced way */
void displayTorrcDialog();
+ /** Called when the user checks "Configure ControlPort automatically" */
+ void toggleAuto(bool);
+
private:
/** Returns the authentication method for the given <b>index</b>. */
TorSettings::AuthenticationMethod indexToAuthMethod(int index);
diff --git a/src/vidalia/config/AdvancedPage.ui b/src/vidalia/config/AdvancedPage.ui
index ed17c1d..3600cbc 100644
--- a/src/vidalia/config/AdvancedPage.ui
+++ b/src/vidalia/config/AdvancedPage.ui
@@ -37,7 +37,7 @@
<property name="verticalSpacing">
<number>5</number>
</property>
- <item row="5" column="0">
+ <item row="6" column="0">
<widget class="QLabel" name="lblAuth">
<property name="text">
<string>Authentication:</string>
@@ -57,7 +57,7 @@
</property>
</widget>
</item>
- <item row="5" column="2" colspan="3">
+ <item row="6" column="2" colspan="3">
<layout class="QHBoxLayout">
<property name="spacing">
<number>2</number>
@@ -197,7 +197,7 @@
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="5" column="0">
<widget class="QLabel" name="lblPath">
<property name="enabled">
<bool>false</bool>
@@ -210,14 +210,14 @@
</property>
</widget>
</item>
- <item row="4" column="1" colspan="2">
+ <item row="5" column="1" colspan="2">
<widget class="QLineEdit" name="lineSocketPath">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
- <item row="3" column="2">
+ <item row="4" column="2">
<widget class="QRadioButton" name="rdoControlSocket">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
@@ -230,7 +230,7 @@
</property>
</widget>
</item>
- <item row="4" column="3">
+ <item row="5" column="3">
<widget class="QPushButton" name="btnBrowseSocketPath">
<property name="enabled">
<bool>false</bool>
@@ -240,6 +240,13 @@
</property>
</widget>
</item>
+ <item row="3" column="2">
+ <widget class="QCheckBox" name="chkAuto">
+ <property name="text">
+ <string>Configure ControlPort automatically</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>
diff --git a/src/vidalia/config/TorSettings.cpp b/src/vidalia/config/TorSettings.cpp
index b05b428..42e036f 100644
--- a/src/vidalia/config/TorSettings.cpp
+++ b/src/vidalia/config/TorSettings.cpp
@@ -44,6 +44,7 @@
#define SETTING_REJECT_PLAINTEXT_PORTS "RejectPlaintextPorts"
#define SETTING_BOOTSTRAP "Bootstrap"
#define SETTING_BOOTSTRAP_FROM "BootstrapFrom"
+#define SETTING_AUTOCONTROL "AutoControl"
/** Default to using hashed password authentication */
#define DEFAULT_AUTH_METHOD PasswordAuth
@@ -92,6 +93,7 @@ TorSettings::TorSettings(TorControl *torControl)
setDefault(SETTING_REJECT_PLAINTEXT_PORTS, QList<QVariant>());
setDefault(SETTING_BOOTSTRAP, false);
setDefault(SETTING_BOOTSTRAP_FROM, "");
+ setDefault(SETTING_AUTOCONTROL, true);
}
/** Applies any changes to Tor's control port or authentication settings. */
@@ -450,3 +452,15 @@ TorSettings::bootstrapFrom() const
{
return QDir::convertSeparators(value(SETTING_BOOTSTRAP_FROM).toString());
}
+
+bool
+TorSettings::autoControlPort() const
+{
+ return value(SETTING_AUTOCONTROL).toBool();
+}
+
+void
+TorSettings::setAutoControlPort(const bool autoControl)
+{
+ setValue(SETTING_AUTOCONTROL, autoControl);
+}
diff --git a/src/vidalia/config/TorSettings.h b/src/vidalia/config/TorSettings.h
index a4f8ec9..5038c3d 100644
--- a/src/vidalia/config/TorSettings.h
+++ b/src/vidalia/config/TorSettings.h
@@ -72,6 +72,13 @@ public:
/** Get the current control method */
ControlMethod::Method getControlMethod() const;
+ /** Returns true if Vidalia will get the ControlPort automatically from
+ * Tor */
+ bool autoControlPort() const;
+
+ /** Sets whether Vidalia should get the ControlPort from Tor */
+ void setAutoControlPort(const bool auto);
+
/** Set the control method */
void setControlMethod(ControlMethod::Method method);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits