[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2422: Bugfixing: - Communication Vidalia <-> Tor - Integration of (vidalia/branches/hidden-services/src/vidalia/config)
Author: borkdomenik
Date: 2008-03-18 17:05:16 -0400 (Tue, 18 Mar 2008)
New Revision: 2422
Modified:
vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp
vidalia/branches/hidden-services/src/vidalia/config/servicepage.h
vidalia/branches/hidden-services/src/vidalia/config/servicepage.ui
vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp
vidalia/branches/hidden-services/src/vidalia/config/servicesettings.h
Log:
Bugfixing:
- Communication Vidalia <-> Tor
- Integration of icons for the buttons
- Ensure that only valid values are able to be set
- get .onion address of published services when Vidalia starts
- some more smaller features and bugfixes
Modified: vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp 2008-03-18 04:16:02 UTC (rev 2421)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp 2008-03-18 21:05:16 UTC (rev 2422)
@@ -16,15 +16,12 @@
#include <QTextStream>
#include <file.h>
#include "configdialog.h"
+#include "ipvalidator.h"
#include "service.h"
#include "servicelist.h"
/** TODO
- * size of the window exoanding
- * communication with tor controller seems not to work, yet
- * ensure that every serviced has a unique directory path*/
+ * size of the window expanding */
-
-
/** Constructor */
ServicePage::ServicePage(QWidget *parent)
: ConfigPage(parent, tr("Services"))
@@ -33,6 +30,8 @@
ui.setupUi(this);
/* Keep a pointer to the TorControl object used to talk to Tor */
_torControl = Vidalia::torControl();
+ /* Create Tor settings objects */
+ _torSettings = new TorSettings;
/* Keep a pointer to the ServiceSettings object used to store the configuration */
_serviceSettings = new ServiceSettings(_torControl);
/* A QMap, mapping from the row number to the Entity for all services */
@@ -49,12 +48,14 @@
ui.serviceWidget->horizontalHeader()->resizeSection(2, 125);
ui.serviceWidget->horizontalHeader()->resizeSection(3, 155);
ui.serviceWidget->horizontalHeader()->resizeSection(4, 60);
+ ui.serviceWidget->verticalHeader()->hide();
connect(ui.addButton, SIGNAL(clicked()), this, SLOT(addService()));
connect(ui.removeButton, SIGNAL(clicked()), this, SLOT(removeService()));
connect(ui.copyButton, SIGNAL(clicked()), this, SLOT(copyToClipboard()));
connect(ui.browseButton, SIGNAL(clicked()), this, SLOT(browseDirectory()));
connect(ui.serviceWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(serviceSelectionChanged()));
+ connect(ui.serviceWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(valueChanged()));
}
/** Destructor */
@@ -96,7 +97,11 @@
_serviceSettings->setServices(sList);
if(publishedServices.size() > 0) {
startServicesInTor(publishedServices);
- }
+ } else {
+ QString errmsg1 = tr("Error while trying to unpublish all services");
+ QString &errmsg = errmsg1;
+ _serviceSettings->unpublishAllServices(&errmsg);
+ }
return true;
} else {
errmsg = "Please configure at least a service directory and a virtual port for each service you want to save. Remove the other ones.";
@@ -129,7 +134,7 @@
Service temp = it.next();
serviceConfString.append(createServiceConfString(temp));
}
- _serviceSettings->applyServices(serviceConfString, &errmsg);
+ _serviceSettings->apply(serviceConfString, &errmsg);
}
/** this method generates the configuration string for a service */
@@ -137,11 +142,13 @@
ServicePage::createServiceConfString(Service temp)
{
QString s;
- s.append("hiddenservicedir "+temp.serviceDirectory()+"\n");
+ s.append(temp.serviceDirectory()+"\n");
s.append("hiddenserviceport "+temp.virtualPort());
if(temp.physicalAddressPort().isEmpty() == false) {
s.append(" "+temp.physicalAddressPort());
}
+ s.append("\n");
+ s.append("hiddenservicedir ");
return s;
}
@@ -150,15 +157,24 @@
void
ServicePage::load()
{
- // disable the buttons whil no service is selected
ui.removeButton->setEnabled(false);
ui.copyButton->setEnabled(false);
ui.browseButton->setEnabled(false);
// get all services
- _services = new QMap<int, Service>();
+ _services = new QMap<int, Service>();
QList<Service> _torServices;
- // all service from tor
- QString conf = _serviceSettings->getHiddenServiceDirectories();
+ QString conf = "";
+ QString directory = _torSettings->getTorrc();
+ QFile file(directory);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ VMessageBox::warning(this, tr("Error"), tr("Trying to read torrc file failed."), VMessageBox::Ok);
+ } else {
+ QTextStream in(&file);
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ conf.append(line+"\n");
+ }
+ }
_torServices = extractSingleServices(conf);
QList<Service> completeList = _torServices;
// the services stored with vidalia
@@ -168,7 +184,7 @@
// check whether a service is already in the list because he is published
while(it.hasNext()) {
Service temp = it.next();
- if(!isServicePublished(temp)) {
+ if(isServicePublished(temp, _torServices) == false) {
completeList.push_back(temp);
}
}
@@ -189,7 +205,7 @@
ServicePage::extractSingleServices(QString conf)
{
QList<Service> list;
- QStringList strList = conf.split("hiddenservicedir");
+ QStringList strList = conf.split("HiddenServiceDir");
strList.removeFirst();
QListIterator<QString> it(strList);
//for each service directory splitted string = service
@@ -210,7 +226,7 @@
QStringList strList = s.split("\n");
serviceDir = strList.first().trimmed();
//virtual port
- QStringList strList2 = s.split("hiddenserviceport");
+ QStringList strList2 = s.split("HiddenServicePort");
strList2.removeFirst();
QStringList strList3 = strList2.first().split("\n");
QStringList strList4 = strList3.first().split(" ");
@@ -223,10 +239,11 @@
}
//get .onion address
QString serviceHostnameDir = serviceDir;
- serviceHostnameDir.append("/hostname");
+ serviceHostnameDir.append("/");
+ serviceHostnameDir.append("hostname");
QFile file(serviceHostnameDir);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- address = "[Created by Tor]";
+ address = "[Directory not found]";
} else {
QTextStream in(&file);
QString hostname;
@@ -241,18 +258,16 @@
/** this method checks either a service is published or not */
bool
-ServicePage::isServicePublished(Service service)
+ServicePage::isServicePublished(Service service, QList<Service> _torServices)
{
- bool result = false;
QListIterator<Service> it(_torServices);
while(it.hasNext()) {
Service temp = it.next();
if(temp.serviceDirectory().compare(service.serviceDirectory()) == 0) {
- result = true;
- break;
+ return true;
}
}
- return result;
+ return false;
}
/** this method creates/displays the values for each service
@@ -274,18 +289,19 @@
cboxitem->setFlags(Qt::ItemIsSelectable);
QTableWidgetItem *addressitem = new QTableWidgetItem();
addressitem->setFlags(Qt::ItemIsSelectable);
+ addressitem->setText(tempService.serviceAddress());
+ QTableWidgetItem *serviceDir = new QTableWidgetItem(tempService.serviceDirectory(),0);
if(tempService.enabled()) {
cboxitem->setCheckState(Qt::Checked);
- addressitem->setText(tempService.serviceAddress());
+ serviceDir->setFlags(Qt::ItemIsSelectable);
} else {
cboxitem->setCheckState(Qt::Unchecked);
- addressitem->setText("[Created by Tor]");
}
cboxitem->setTextAlignment(Qt::AlignCenter);
ui.serviceWidget->setItem(index, 0, addressitem);
ui.serviceWidget->setItem(index, 1, new QTableWidgetItem(tempService.virtualPort(),0));
ui.serviceWidget->setItem(index, 2, new QTableWidgetItem(tempService.physicalAddressPort(),0));
- ui.serviceWidget->setItem(index, 3, new QTableWidgetItem(tempService.serviceDirectory(),0));
+ ui.serviceWidget->setItem(index, 3, serviceDir);
ui.serviceWidget->setItem(index, 4, cboxitem);
index++;
}
@@ -306,7 +322,6 @@
QTableWidgetItem *cboxitem = new QTableWidgetItem();
cboxitem->setFlags(Qt::ItemIsSelectable);
cboxitem->setCheckState(Qt::Checked);
- cboxitem->setTextAlignment(Qt::AlignCenter);
ui.serviceWidget->setItem(rows, 0, address);
ui.serviceWidget->setItem(rows, 1, dummy);
ui.serviceWidget->setItem(rows, 2, dummy2);
@@ -349,11 +364,12 @@
VMessageBox::warning(this, tr("Error"), tr("Please select a Service."), VMessageBox::Ok);
return;
} else {
+ QString onionAddress = ui.serviceWidget->item(selrow,0)->text();
QClipboard *clipboard = QApplication::clipboard();
QString clipboardText;
QTableWidgetItem* selectedItem = ui.serviceWidget->item(selrow,0);
clipboardText.append(selectedItem->text());
- clipboard->setText(clipboardText);
+ clipboard->setText(clipboardText);
}
}
@@ -362,7 +378,7 @@
void
ServicePage::browseDirectory()
{
- int selrow = ui.serviceWidget->rowCount();
+ int selrow = ui.serviceWidget->currentRow();
if(selrow < 0 || selrow >= _services->size()) {
VMessageBox::warning(this, tr("Error"), tr("Please select a Service."), VMessageBox::Ok);
return;
@@ -380,11 +396,11 @@
}
}
-/** this method is called when the user selection of the service listing changed */
+/** this method is called when the selects an other tablewidgetitem */
void
ServicePage::serviceSelectionChanged()
{
- // enable the buttons because now a service is selected if there is at least one left
+ bool emptyTable = false;
if(ui.serviceWidget->rowCount() > 0) {
ui.removeButton->setEnabled(true);
ui.copyButton->setEnabled(true);
@@ -393,9 +409,17 @@
ui.removeButton->setEnabled(false);
ui.copyButton->setEnabled(false);
ui.browseButton->setEnabled(false);
+ emptyTable = true;
}
- // if the user has clicked on the checkbox cell
- int currentRow = ui.serviceWidget->currentRow();
+ int currentRow = ui.serviceWidget->currentRow();
+ if(emptyTable == true || ui.serviceWidget->item(currentRow,0)->text().contains(".onion")) {
+ ui.browseButton->setEnabled(false);
+ ui.copyButton->setEnabled(true);
+ } else {
+ ui.browseButton->setEnabled(true);
+ ui.copyButton->setEnabled(false);
+ }
+ // if the user has clicked on the checkbox cell
if(ui.serviceWidget->currentColumn() == 4) {
Service service = _services->take(currentRow);
QTableWidgetItem* item = ui.serviceWidget->item(currentRow,4);
@@ -410,8 +434,68 @@
}
}
+/** this method is called when the user finished editing a cell and it provides
+ * that only valid values are set */
+void
+ServicePage::valueChanged()
+{
+ int pos = 0;
+ QIntValidator* v = new QIntValidator(1,65535, this);
+ IPValidator* vip = new IPValidator(this);
+ int currentRow = ui.serviceWidget->currentRow();
+ if(ui.serviceWidget->currentColumn() == 3) {
+ QString eingabe = ui.serviceWidget->item(currentRow,3)->text();
+ if(eingabe.length() > 0) {
+ int index = 0;
+ while(index < ui.serviceWidget->rowCount()) {
+ if(index != currentRow) {
+ QTableWidgetItem* item = ui.serviceWidget->item(index,3);
+ if(item != NULL) {
+ QString actualDir = item->text();
+ if(actualDir.length() > 0 && eingabe.compare(actualDir) == 0) {
+ //data directory already in use
+ ui.serviceWidget->item(currentRow,3)->setText("");
+ VMessageBox::warning(this, tr("Error"), tr("Directory already in use."), VMessageBox::Ok);
+ break;
+ }
+ }
+ }
+ index++;
+ }
+ }
+ } else if(ui.serviceWidget->currentColumn() == 2) {
+ QTableWidgetItem* item = ui.serviceWidget->item(currentRow,2);
+ if(item != NULL) {
+ QString eingabe = item->text();
+ if(eingabe.length() > 0) {
+ if(eingabe.contains(":")) {
+ QStringList strList = eingabe.split(":");
+ QString ip = strList.first();
+ strList.removeFirst();
+ QString port = strList.first();
+ if((vip->validate(ip) != QValidator::Acceptable) || (v->validate(port, pos) != QValidator::Acceptable)) {
+ //incorrect data
+ ui.serviceWidget->item(currentRow,2)->setText("");
+ VMessageBox::warning(this, tr("Error"), tr("Only [IP-Address:Port] accepted here."), VMessageBox::Ok);
+ }
+ } else {
+ ui.serviceWidget->item(currentRow,2)->setText("");
+ VMessageBox::warning(this, tr("Error"), tr("Only [IP-Address:Port] accepted here."), VMessageBox::Ok);
+ }
+ }
+ }
+ } else if(ui.serviceWidget->currentColumn() == 1) {
+ QString eingabe = ui.serviceWidget->item(currentRow,1)->text();
+ if(eingabe.length() > 0) {
+ if(v->validate(eingabe,pos) != QValidator::Acceptable) {
+ //incorrect data
+ ui.serviceWidget->item(currentRow,1)->setText("");
+ VMessageBox::warning(this, tr("Error"), tr("Only valid port numbers allowed [1..65535]."), VMessageBox::Ok);
+ }
+ }
+ }
+}
-
Modified: vidalia/branches/hidden-services/src/vidalia/config/servicepage.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.h 2008-03-18 04:16:02 UTC (rev 2421)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.h 2008-03-18 21:05:16 UTC (rev 2422)
@@ -13,6 +13,7 @@
#define _SERVICEPAGE_H
#include <torcontrol.h>
+#include <torsettings.h>
#include <servicesettings.h>
#include <exitpolicy.h>
#include <helpbrowser.h>
@@ -56,14 +57,18 @@
QString createServiceConfString(Service temp);
- bool isServicePublished(Service service);
+ bool isServicePublished(Service service, QList<Service> _torServices);
bool checkBeforeSaving(QList<Service> services);
+
+ void valueChanged();
private:
/** A TorControl object used to talk to Tor. */
TorControl* _torControl;
+ /** A TorSettings object used for saving/loading the Tor settings */
+ TorSettings *_torSettings;
/** A ServiceSettings object used to load/save the services. */
ServiceSettings* _serviceSettings;
/* A QMap, mapping from QString servicename to the Entity service */
Modified: vidalia/branches/hidden-services/src/vidalia/config/servicepage.ui
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.ui 2008-03-18 04:16:02 UTC (rev 2421)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.ui 2008-03-18 21:05:16 UTC (rev 2422)
@@ -5,14 +5,14 @@
<rect>
<x>0</x>
<y>0</y>
- <width>727</width>
+ <width>693</width>
<height>581</height>
</rect>
</property>
<property name="minimumSize" >
<size>
- <width>581</width>
- <height>581</height>
+ <width>600</width>
+ <height>400</height>
</size>
</property>
<property name="windowTitle" >
@@ -22,8 +22,8 @@
<property name="geometry" >
<rect>
<x>10</x>
- <y>20</y>
- <width>701</width>
+ <y>10</y>
+ <width>671</width>
<height>281</height>
</rect>
</property>
@@ -36,25 +36,12 @@
</sizepolicy>
</property>
<property name="title" >
- <string>Service Listing</string>
+ <string>Hidden Services</string>
</property>
- <widget class="QLabel" name="serviceListingDescription" >
- <property name="geometry" >
- <rect>
- <x>10</x>
- <y>30</y>
- <width>511</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text" >
- <string>Configure hidden services to be provided by this Tor client or relay.</string>
- </property>
- </widget>
<widget class="QWidget" name="layoutWidget_2" >
<property name="geometry" >
<rect>
- <x>660</x>
+ <x>630</x>
<y>70</y>
<width>28</width>
<height>201</height>
@@ -142,12 +129,63 @@
</item>
</layout>
</widget>
+ <widget class="QWidget" name="layoutWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>30</y>
+ <width>651</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="lblAddBridge" >
+ <property name="text" >
+ <string>Configure hidden services to be provided by this Tor client or relay.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="lblHelpFindBridges" >
+ <property name="cursor" >
+ <cursor>13</cursor>
+ </property>
+ <property name="text" >
+ <string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="bridges.finding"><span style=" text-decoration: underline; color:#0000ff;">How does all this work?</span></a></p></body></html></string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
<widget class="QTableWidget" name="serviceWidget" >
<property name="geometry" >
<rect>
<x>10</x>
<y>70</y>
- <width>631</width>
+ <width>611</width>
<height>199</height>
</rect>
</property>
@@ -165,9 +203,15 @@
<property name="selectionBehavior" >
<enum>QAbstractItemView::SelectRows</enum>
</property>
+ <property name="textElideMode" >
+ <enum>Qt::ElideLeft</enum>
+ </property>
+ <property name="showGrid" >
+ <bool>true</bool>
+ </property>
<column>
<property name="text" >
- <string>Service Address</string>
+ <string>Onion Address</string>
</property>
</column>
<column>
@@ -177,12 +221,12 @@
</column>
<column>
<property name="text" >
- <string>Physical Addr.:Port</string>
+ <string>Phys. Address:Port</string>
</property>
</column>
<column>
<property name="text" >
- <string>Service Directory</string>
+ <string>Directory Path</string>
</property>
</column>
<column>
Modified: vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp 2008-03-18 04:16:02 UTC (rev 2421)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp 2008-03-18 21:05:16 UTC (rev 2422)
@@ -109,7 +109,7 @@
void
ServiceSettings::apply(QString value, QString *errmsg)
{
- _torControl->setConf("ServiceDir", value, errmsg);
+ _torControl->setConf("HiddenServiceDir", value, errmsg);
_torControl->saveConf(errmsg);
}
@@ -125,9 +125,17 @@
void
ServiceSettings::applyServices(QString value, QString *errmsg)
{
- _torControl->setConf("hiddenserviceoptions", value, errmsg);
+ _torControl->setConf("HiddenServiceDir", value, errmsg);
_torControl->saveConf(errmsg);
}
+/** Unpublish all HiddenServices */
+void
+ServiceSettings::unpublishAllServices(QString *errmsg)
+{
+ _torControl->resetConf("HiddenServiceDir", errmsg);
+ _torControl->saveConf(errmsg);
+}
+
Modified: vidalia/branches/hidden-services/src/vidalia/config/servicesettings.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicesettings.h 2008-03-18 04:16:02 UTC (rev 2421)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicesettings.h 2008-03-18 21:05:16 UTC (rev 2422)
@@ -52,6 +52,9 @@
/** Set all services the user wants to start and send it to the Tor Controller */
void applyServices(QString value, QString *errmsg);
+
+ /** Unpublish all services */
+ void unpublishAllServices(QString *errmsg);
private: