
commit b129228f3e408b431f3747c918d0a5904e3c297f Author: Tomás Touceda <chiiph@torproject.org> Date: Fri Feb 3 17:18:13 2012 -0300 Remove the HiddenService configuration It should be readded as a plugin, it has some bugs and it isn't structured like the rest of the settings which makes it harder to migrate to the new torrc only approach. --- src/vidalia/CMakeLists.txt | 6 - src/vidalia/config/ConfigDialog.cpp | 7 - src/vidalia/config/Service.cpp | 119 ------ src/vidalia/config/Service.h | 80 ----- src/vidalia/config/ServiceList.cpp | 56 --- src/vidalia/config/ServiceList.h | 51 --- src/vidalia/config/ServicePage.cpp | 613 -------------------------------- src/vidalia/config/ServicePage.h | 79 ---- src/vidalia/config/ServicePage.ui | 173 --------- src/vidalia/config/ServiceSettings.cpp | 167 --------- src/vidalia/config/ServiceSettings.h | 61 ---- 11 files changed, 0 insertions(+), 1412 deletions(-) diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt index 4a28504..3277bf0 100644 --- a/src/vidalia/CMakeLists.txt +++ b/src/vidalia/CMakeLists.txt @@ -122,11 +122,7 @@ set(vidalia_SRCS ${vidalia_SRCS} config/PortValidator.cpp config/ServerPage.cpp config/ServerSettings.cpp - config/Service.cpp - config/ServiceList.cpp - config/ServicePage.cpp config/TorrcDialog.cpp - config/ServiceSettings.cpp config/TorSettings.cpp config/VidaliaSettings.cpp config/VSettings.cpp @@ -150,7 +146,6 @@ qt4_wrap_cpp(vidalia_SRCS config/PortValidator.h config/ServerPage.h config/ServerSettings.h - config/ServicePage.h config/TorrcDialog.h config/TorSettings.h config/VidaliaSettings.h @@ -218,7 +213,6 @@ qt4_wrap_ui(vidalia_SRCS config/GeneralPage.ui config/NetworkPage.ui config/ServerPage.ui - config/ServicePage.ui config/TorrcDialog.ui log/MessageLog.ui help/browser/HelpBrowser.ui diff --git a/src/vidalia/config/ConfigDialog.cpp b/src/vidalia/config/ConfigDialog.cpp index bb711dc..a2debf5 100644 --- a/src/vidalia/config/ConfigDialog.cpp +++ b/src/vidalia/config/ConfigDialog.cpp @@ -19,7 +19,6 @@ #include "ServerPage.h" #include "AdvancedPage.h" #include "AppearancePage.h" -#include "ServicePage.h" #include "VMessageBox.h" #include "ServerSettings.h" #include "NetworkSettings.h" @@ -84,10 +83,6 @@ ConfigDialog::ConfigDialog(QWidget* parent) createPageAction(QIcon(IMAGE_SERVER), tr("Sharing"), "Sharing", grp)); - ui.stackPages->add(new ServicePage(ui.stackPages), - createPageAction(QIcon(IMAGE_SERVICE), - tr("Services"), "Services", grp)); - ui.stackPages->add(new AppearancePage(ui.stackPages), createPageAction(QIcon(IMAGE_APPEARANCE), tr("Appearance"), "Appearance", grp)); @@ -277,8 +272,6 @@ ConfigDialog::help() help("config.appearance"); break; case Advanced: help("config.advanced"); break; - case Service: - help("config.services"); break; default: help("config.general"); break; } diff --git a/src/vidalia/config/Service.cpp b/src/vidalia/config/Service.cpp deleted file mode 100644 index c880529..0000000 --- a/src/vidalia/config/Service.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#include "Service.h" - - -/** Default Constructor */ -Service::Service() -{ -} - -/** Constructor to create a new Service with initial settings */ -Service::Service(QString serviceAddress, QString virtualPort, - QString physicalAddressPort, QString serviceDirectory, bool enabled) -{ - _serviceAddress = serviceAddress; - _virtualPort = virtualPort; - _physicalAddressPort = physicalAddressPort; - _serviceDirectory = serviceDirectory; - _enabled = enabled; -} - -/** Destructor */ -Service::~Service() -{ -} - -/** Sets the deploy status of a service */ -void Service::setEnabled(bool enabled) -{ - _enabled = enabled; -} - -/** Sets the adress of a service */ -void Service::setServiceAddress(QString serviceAddress) -{ - _serviceAddress = serviceAddress; -} - -/** Sets the virtualPort of a service */ -void Service::setVirtualPort(QString virtualPort) -{ - _virtualPort = virtualPort; -} - -/** Sets the physical Adress and the local port of a service */ -void Service::setPhysicalAddressPort(QString physicalAddressPort) -{ - _physicalAddressPort = physicalAddressPort; -} - -/** Sets the service directory of a service */ -void Service::setServiceDirectory(QString serviceDirectory) -{ - _serviceDirectory = serviceDirectory; -} - -/** Sets the additional options of a service e.g. excludeNodes */ -void Service::setAdditionalServiceOptions(QString options) -{ - _additionalServiceOptions = options; -} - -/** Writes service class data from <b>myObj</b> to the QDataStream - * <b>out</b>. */ -QDataStream&operator<<(QDataStream &out, const Service &myObj) -{ - out << myObj.serviceAddress(); - out << myObj.virtualPort(); - out << myObj.physicalAddressPort(); - out << myObj.serviceDirectory(); - out << myObj.enabled(); - out << myObj.additionalServiceOptions(); - - return out; -} - -/** Reads service class data in from the QDataStream <b>in</b> and - populates * the <b>myObj</b> object accordingly. */ -QDataStream&operator>>(QDataStream &in, Service &myObj) -{ - QString serviceAddress; - QString virtualPort; - QString physicalAddressPort; - QString serviceDirectory; - bool enabled; - QString additionalServiceOptions; - - /* Read in from the data stream */ - in >> serviceAddress >> virtualPort >> physicalAddressPort - >> serviceDirectory >> enabled >> additionalServiceOptions; - - /* Set the appropriate class member variables */ - myObj.setServiceAddress(serviceAddress); - myObj.setVirtualPort(virtualPort); - myObj.setPhysicalAddressPort(physicalAddressPort); - myObj.setServiceDirectory(serviceDirectory); - myObj.setEnabled(enabled); - myObj.setAdditionalServiceOptions(additionalServiceOptions); - - /* Return the updated data stream */ - return in; -} - -/** Creates a string by concatenating the values of the service. */ -QString -Service::toString() -{ - return _serviceAddress +"#"+ _virtualPort +"#"+ _physicalAddressPort + - "#"+ _serviceDirectory +"#"+ _enabled + "#"+ _additionalServiceOptions; -} - diff --git a/src/vidalia/config/Service.h b/src/vidalia/config/Service.h deleted file mode 100644 index 6c6a790..0000000 --- a/src/vidalia/config/Service.h +++ /dev/null @@ -1,80 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#ifndef _SERVICE_H -#define _SERVICE_H - -#include <QString> -#include <QList> -#include <QMetaType> - - -class Service -{ -public: - /** Default constructor. */ - Service(); - /** Constructor to create a new Service with initial settings */ - Service(QString serviceAddress, QString virtualPort, - QString physicalAddressPort, QString serviceDirectory, bool enabled); - /** Destructor */ - virtual ~Service(); - /** Returns the service Adress of the service */ - QString serviceAddress() const { return _serviceAddress; } - /** Returns the listeningPort of the service */ - QString virtualPort() const { return _virtualPort; } - /** Returns the physical Adresse and the local Port of the service */ - QString physicalAddressPort() const { return _physicalAddressPort; } - /** Returns the service directory of the service */ - QString serviceDirectory() const { return _serviceDirectory; } - /** Returns the deployed status of a service */ - bool enabled() const { return _enabled; } - /** Returns the additional options of a service e.g. excludeNodes */ - QString additionalServiceOptions() const - { return _additionalServiceOptions; } - /** Sets the adress of a service */ - void setServiceAddress(QString serviceAddress); - /** Sets the listening port of a service */ - void setVirtualPort(QString virtualPort); - /** Sets the physical Adress and the local Port of a service */ - void setPhysicalAddressPort(QString physicalAddressPort); - /** Sets the service directory of a service */ - void setServiceDirectory(QString serviceDirectory); - /** Sets the deployed status a service */ - void setEnabled(bool enabled); - /** Sets the additional options of a service e.g. excludeNodes */ - void setAdditionalServiceOptions(QString options); - /** Writes service class data from <b>myObj</b> to the QDataStream - * <b>out</b>. */ - friend QDataStream& operator<<(QDataStream &out, const Service &myObj); - /** Reads service class data in from the QDataStream <b>in</b> and - populates * the <b>myObj</b> object accordingly. */ - friend QDataStream& operator>>(QDataStream &in, Service &myObj); - /** this method creates a string by concatenating the values of the service */ - QString toString(); - -private: - /** The adress of the service */ - QString _serviceAddress; - /** The listening Port of the service */ - QString _virtualPort; - /** The physical Adress and the local port of teh service */ - QString _physicalAddressPort; - /** the directory of the service */ - QString _serviceDirectory; - /** The Enabled status of the service */ - bool _enabled; - /** Some additional service options, not configured/displayed by Vidalia */ - QString _additionalServiceOptions; - -}; -Q_DECLARE_METATYPE(Service); -#endif /*SERIVCE_H_*/ - diff --git a/src/vidalia/config/ServiceList.cpp b/src/vidalia/config/ServiceList.cpp deleted file mode 100644 index fd644f0..0000000 --- a/src/vidalia/config/ServiceList.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#include "ServiceList.h" - - -/** Default constructor. */ -ServiceList::ServiceList() -{ -} - -/** Constructor to create a new Servicelist with initial settings */ -void ServiceList::addService(Service service) -{ - _services.append(service); -} - -/** Destructor */ -ServiceList::~ServiceList() -{ -} - -/* Sets the serviceList */ -void ServiceList::setServices(QList<Service> services) -{ - _services = services; -} - -/** Writes ServiceList class data from <b>myObj</b> to the QDataStream - * <b>out</b>. */ -QDataStream&operator<<(QDataStream &out, const ServiceList &myObj) -{ - out << myObj.services(); /* Write the services*/ - return out; -} - -/** Reads ServiceList class data in from the QDataStream <b>in</b> and - populates * the <b>myObj</b> object accordingly. */ -QDataStream&operator>>(QDataStream &in, ServiceList &myObj) -{ - QList<Service> services; - /* Read in from the data stream */ - in >> services; - /* Set the appropriate class member variables */ - myObj.setServices(services); - /* Return the updated data stream */ - return in; -} - diff --git a/src/vidalia/config/ServiceList.h b/src/vidalia/config/ServiceList.h deleted file mode 100644 index a5c216d..0000000 --- a/src/vidalia/config/ServiceList.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#ifndef _SERVICELIST_H -#define _SERVICELIST_H - -#include "Service.h" - -#include <QList> - - -class ServiceList -{ -public: - - /** Default constructor. */ - ServiceList(); - /** Destructor */ - virtual ~ServiceList(); - /** Returns the list of services */ - void addService(Service service); - /** Sets the lists of services */ - void setServices(QList<Service> services); - /** Returns the list of services */ - QList<Service> services() const { - return _services; - } - /** Writes ServiceList class data from <b>myObj</b> to the QDataStream - * <b>out</b>. */ - friend QDataStream& operator<<(QDataStream &out, const ServiceList &myObj); - /** Reads ServiceList class data in from the QDataStream <b>in</b> and - populates * the <b>myObj</b> object accordingly. */ - friend QDataStream& operator>>(QDataStream &in, ServiceList &myObj); - -private: - - /** The list of Services */ - QList<Service> _services; - -}; -Q_DECLARE_METATYPE(ServiceList); - -#endif - diff --git a/src/vidalia/config/ServicePage.cpp b/src/vidalia/config/ServicePage.cpp deleted file mode 100644 index ac412f9..0000000 --- a/src/vidalia/config/ServicePage.cpp +++ /dev/null @@ -1,613 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#include "ServicePage.h" -#include "Service.h" -#include "ServiceList.h" -#include "VMessageBox.h" -#include "ConfigDialog.h" -#include "IpValidator.h" -#include "DomainValidator.h" -#include "Vidalia.h" - -#include "stringutil.h" -#include "file.h" - -#include <QHeaderView> -#include <QClipboard> -#include <QFile> -#include <QTextStream> - - -/** Constructor */ -ServicePage::ServicePage(QWidget *parent) -: ConfigPage(parent, "Services") -{ - /* Invoke the Qt Designer generated object setup routine */ - ui.setupUi(this); - /* A QMap, mapping from the row number to the Entity for - * all services */ - _services = new QMap<int, Service>(); - /* A QMap, mapping from the directory path to the Entity for - * all Tor services */ - _torServices = new QMap<QString, Service>(); - - ui.serviceWidget->horizontalHeader()->resizeSection(0, 150); - ui.serviceWidget->horizontalHeader()->resizeSection(1, 89); - ui.serviceWidget->horizontalHeader()->resizeSection(2, 100); - ui.serviceWidget->horizontalHeader()->resizeSection(3, 120); - ui.serviceWidget->horizontalHeader()->resizeSection(4, 60); - ui.serviceWidget->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - ui.serviceWidget->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch); - ui.serviceWidget->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); - ui.serviceWidget->horizontalHeader()->setResizeMode(3, QHeaderView::Stretch); - 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 */ -ServicePage::~ServicePage() -{ - delete _services; - delete _torServices; -} - -/** Called when the user changes the UI translation. */ -void -ServicePage::retranslateUi() -{ - ui.retranslateUi(this); -} - -/** Saves changes made to settings on the Server settings page. */ -bool -ServicePage::save(QString &errmsg) -{ - ServiceSettings serviceSettings(Vidalia::torControl()); - QList<Service> serviceList; - QList<Service> publishedServices; - int index = 0; - - while(index < ui.serviceWidget->rowCount()) { - QString address = ui.serviceWidget->item(index,0)->text(); - QString virtualPort = ui.serviceWidget->item(index,1)->text(); - QString physicalAddress = ui.serviceWidget->item(index,2)->text(); - QString directoryPath = ui.serviceWidget->item(index,3)->text(); - bool enabled = _services->value(index).enabled(); - Service temp(address, virtualPort, physicalAddress, directoryPath, - enabled); - temp.setAdditionalServiceOptions( - _services->value(ui.serviceWidget->currentRow()).additionalServiceOptions()); - serviceList.push_back(temp); - if(enabled) { - publishedServices.push_back(temp); - } - index++; - } - - bool save = checkBeforeSaving(serviceList); - if(save) { - ServiceList sList; - if(serviceList.size() > 0) { - sList.setServices(serviceList); - } else { - _services = new QMap<int, Service>(); - sList.setServices(_services->values()); - } - 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 = tr("Please configure at least a service directory and a virtual " - "port for each service you want to save. Remove the other ones."); - return false; - } -} - -/** this method checks if either all services have minimal - * configuration or not */ -bool -ServicePage::checkBeforeSaving(QList<Service> serviceList) -{ - bool result = true; - foreach(Service s, serviceList) { - if(s.serviceDirectory().isEmpty() || s.virtualPort().isEmpty()) { - result = false; - break; - } - } - return result; -} - -/** this method generates the configuration string for a list of services */ -void -ServicePage::startServicesInTor(QList<Service> services) -{ - ServiceSettings serviceSettings(Vidalia::torControl()); - QString serviceConfString; - QString errmsg = "Error while trying to publish services."; - QListIterator<Service> it(services); - - while(it.hasNext()) { - Service temp = it.next(); - serviceConfString.append("hiddenservicedir=" + - string_escape(temp.serviceDirectory()) + " "); - serviceConfString.append("hiddenserviceport=" + - string_escape(temp.virtualPort() + - (temp.physicalAddressPort().isEmpty() ? "" : " " + - temp.physicalAddressPort()))); - serviceConfString.append(" " + temp.additionalServiceOptions()); - } - serviceSettings.applyServices(serviceConfString, &errmsg); -} - -/** Loads previously saved settings */ -void -ServicePage::load() -{ - ServiceSettings serviceSettings(Vidalia::torControl()); - QList<Service> torServiceList; - - ui.removeButton->setEnabled(false); - ui.copyButton->setEnabled(false); - ui.browseButton->setEnabled(false); - // get all services - _services->clear(); - _torServices->clear(); - - QString torConfigurationString = serviceSettings.getHiddenServiceDirectories(); - torServiceList = extractSingleServices(torConfigurationString); - QList<Service> completeList = torServiceList; - // the services stored with vidalia - ServiceList serviceList = serviceSettings.getServices(); - QList<Service> serviceSettingsList = serviceList.services(); - QListIterator<Service> it(serviceSettingsList); - // check whether a service is already in the list because he is published - while(it.hasNext()) { - Service temp = it.next(); - if(isServicePublished(temp, torServiceList) == false) { - completeList.push_back(temp); - } - } - // generate the _services data structure used during vidalia session - QListIterator<Service> it2(completeList); - int index = 0; - while (it2.hasNext()) { - Service tempService = it2.next(); - _services->insert(index, tempService); - index++; - } - initServiceTable(_services); -} - -/** this method returns a list of services by parsing the configuration - * string given by the tor controller */ -QList<Service> -ServicePage::extractSingleServices(QString conf) -{ - QList<Service> list; - QStringList strList = conf.split("250 HiddenServiceDir"); - strList.removeFirst(); - QListIterator<QString> it(strList); - //for each service directory splitted string = service - while(it.hasNext()) { - QString temp = it.next(); - list.push_back(generateService(temp)); - } - return list; -} - -/** this return a Service by parseing the configuration string - * of Tor and storeing its values into the object */ -Service -ServicePage::generateService(QString s) -{ - QString additionalOptions = s; - // remove directory - int index = additionalOptions.indexOf("250",1); - additionalOptions.remove(0, index+4); - // remove the first appearance of the port - int startindex = additionalOptions.indexOf("hiddenserviceport", 0, - Qt::CaseInsensitive); - int endindex = additionalOptions.indexOf("250", startindex); - if(endindex != -1) { - additionalOptions.remove(startindex, (endindex-startindex)+4); - //remove all appearances of "250" - while(additionalOptions.contains("250")) { - int i = additionalOptions.indexOf("250", 0); - additionalOptions.remove(i, 4); - } - // prepare for correct quotation - if (!additionalOptions.endsWith('\n')) { - additionalOptions.append("\n"); - } - //quote the values - int j = additionalOptions.indexOf("=", 0); - while(j != -1) { - additionalOptions.insert(j+1, "\""); - int end = additionalOptions.indexOf("\n", j); - additionalOptions.insert(end, "\""); - j = additionalOptions.indexOf("=", end); - } - //replace the line brakes with a space and create one single line - additionalOptions.replace(QString("\n"), QString(" ")); - } else { - additionalOptions = ""; - } - - QString address, virtualPort, physAddressPort, serviceDir; - // service directory - QStringList strList = s.split("\n"); - QString tempServiceDir = strList.first().trimmed(); - serviceDir = tempServiceDir.remove(0, 1); - //virtual port - QStringList strList2 = s.split("HiddenServicePort"); - strList2.removeFirst(); - QStringList strList3 = strList2.first().split("\n"); - QStringList strList4 = strList3.first().split(" "); - if(strList4.size() > 0) { - QString tempVirtualPort = strList4.first(); - virtualPort = tempVirtualPort.remove(0, 1); - strList4.removeFirst(); - //physical address:port - if(!strList4.isEmpty()) { - physAddressPort = strList4.first().trimmed(); - } - } else { - QString tempVirtualPort = strList3.first(); - virtualPort = tempVirtualPort.remove(0, 1); - } - //get .onion address - QString serviceHostnameDir = serviceDir; - serviceHostnameDir.append("/"); - serviceHostnameDir.append("hostname"); - QFile file(serviceHostnameDir); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - address = "[Directory not found]"; - } else { - QTextStream in(&file); - QString hostname; - while (!in.atEnd()) { - hostname.append(in.readLine()); - } - address = hostname; - } - Service service(address, virtualPort, physAddressPort, serviceDir, true); - service.setAdditionalServiceOptions(additionalOptions); - _torServices->insert(serviceDir, service); - return service; -} - -/** this method checks either a service is published or not */ -bool -ServicePage::isServicePublished(Service service, QList<Service> torServices) -{ - QListIterator<Service> it(torServices); - while(it.hasNext()) { - Service temp = it.next(); - if(temp.serviceDirectory().compare(service.serviceDirectory()) == 0) { - return true; - } - } - return false; -} - -/** this method creates/displays the values for each service - * shown in the service listing */ -void -ServicePage::initServiceTable(QMap<int, Service>* services) -{ - // clean the widget - int rows = ui.serviceWidget->rowCount(); - for(int i = 0; i < rows; i++) { - ui.serviceWidget->removeRow(0); - } - //for each service - int index = 0; - while(index < services->size()) { - Service tempService = services->value(index); - ui.serviceWidget->insertRow(index); - QTableWidgetItem *cboxitem = new QTableWidgetItem(); - cboxitem->setFlags(Qt::ItemIsSelectable); - QTableWidgetItem *addressitem = new QTableWidgetItem(); - addressitem->setFlags(Qt::ItemIsSelectable); - if(tempService.serviceAddress().length() < 0) { - addressitem->setText(tempService.serviceAddress()); - } else { - QString serviceHostnameDir = tempService.serviceDirectory(); - serviceHostnameDir.append("/"); - serviceHostnameDir.append("hostname"); - QFile file(serviceHostnameDir); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - addressitem->setText("[Directory not found]"); - } else { - QTextStream in(&file); - QString hostname; - while (!in.atEnd()) { - hostname.append(in.readLine()); - } - addressitem->setText(hostname); - tempService.setServiceAddress(hostname); - } - } - addressitem->setData(32, addressitem->text()); - QTableWidgetItem *serviceDir = - new QTableWidgetItem(tempService.serviceDirectory(), 0); - serviceDir->setData(32, tempService.serviceDirectory()); - QTableWidgetItem* virtualportitem = - new QTableWidgetItem(tempService.virtualPort(), 0); - virtualportitem->setData(32, tempService.virtualPort()); - QTableWidgetItem* targetitem = - new QTableWidgetItem(tempService.physicalAddressPort(),0); - targetitem->setData(32, tempService.physicalAddressPort()); - if(tempService.enabled()) { - cboxitem->setCheckState(Qt::Checked); - serviceDir->setFlags(Qt::ItemIsSelectable); - } else { - cboxitem->setCheckState(Qt::Unchecked); - } - cboxitem->setTextAlignment(Qt::AlignCenter); - ui.serviceWidget->setItem(index, 0, addressitem); - ui.serviceWidget->setItem(index, 1, virtualportitem); - ui.serviceWidget->setItem(index, 2, targetitem); - ui.serviceWidget->setItem(index, 3, serviceDir); - ui.serviceWidget->setItem(index, 4, cboxitem); - index++; - } -} - -/** this method is called when the user clicks the "Add"-Button - * it generates a new empty table entrie(row) */ -void -ServicePage::addService() -{ - int rows = ui.serviceWidget->rowCount(); - ui.serviceWidget->insertRow(rows); - QTableWidgetItem *address = new QTableWidgetItem("["+tr("Created by Tor")+"]"); - address->setFlags(Qt::ItemIsSelectable); - QTableWidgetItem *dummy = new QTableWidgetItem(); - QTableWidgetItem *dummy2 = new QTableWidgetItem(); - QTableWidgetItem *dummy3 = new QTableWidgetItem(); - QTableWidgetItem *cboxitem = new QTableWidgetItem(); - cboxitem->setFlags(Qt::ItemIsSelectable); - cboxitem->setCheckState(Qt::Checked); - ui.serviceWidget->setItem(rows, 0, address); - ui.serviceWidget->setItem(rows, 1, dummy); - ui.serviceWidget->setItem(rows, 2, dummy2); - ui.serviceWidget->setItem(rows, 3, dummy3); - ui.serviceWidget->setItem(rows, 4, cboxitem); - Service s; - s.setEnabled(true); - _services->insert(rows, s); -} - -/** this method is called when the user clicks the "Remove"-Button - * it removes a service/row of the service listing */ -void -ServicePage::removeService() -{ - int rows = 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; - } else { - ui.serviceWidget->removeRow(selrow); - //decrease all other service keys - for(int i = 0; i < (rows-selrow-1); i++) { - int index = i+selrow; - Service s = _services->take(index+1); - _services->insert(index, s); - } - } - serviceSelectionChanged(); -} - -/** this method is called when the user clicks on the "Copy"-Button, it - * copies the .onion-Address of the selected service into the clipboard */ -void -ServicePage::copyToClipboard() -{ - int selrow = ui.serviceWidget->currentRow(); - if(selrow < 0 || selrow >= _services->size()) { - 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); - } -} - -/** this method is called when the user clicks on the "Brows"-Button it opens - * a QFileDialog to choose a service directory */ -void -ServicePage::browseDirectory() -{ - int selrow = ui.serviceWidget->currentRow(); - if(selrow < 0 || selrow >= _services->size()) { - VMessageBox::warning(this, tr("Error"), tr("Please select a Service."), - VMessageBox::Ok); - return; - } else { - QString dirname = - QFileDialog::getExistingDirectory(this, - tr("Select Service Directory"), "", - QFileDialog::ShowDirsOnly - | QFileDialog::DontResolveSymlinks); - - if (dirname.isEmpty()) { - return; - } - ui.serviceWidget->item(selrow,3)->setText(dirname); - Service s = _services->take(selrow); - s.setServiceDirectory(dirname); - _services->insert(selrow, s); - } -} - -/** this method is called when the selects an other tablewidgetitem */ -void -ServicePage::serviceSelectionChanged() -{ - bool emptyTable = false; - if(ui.serviceWidget->rowCount() > 0) { - ui.removeButton->setEnabled(true); - ui.copyButton->setEnabled(true); - ui.browseButton->setEnabled(true); - } else { - ui.removeButton->setEnabled(false); - ui.copyButton->setEnabled(false); - ui.browseButton->setEnabled(false); - emptyTable = true; - } - int currentRow = ui.serviceWidget->currentRow(); - if(emptyTable == false) { - QTableWidgetItem* item = ui.serviceWidget->item(currentRow, 0); - if(item != NULL) { - bool b = item->text().contains(".onion"); - ui.copyButton->setEnabled(b); - } - } - - QString selDir = _services->value(ui.serviceWidget->currentRow()). - serviceDirectory(); - QList<QString> strList = _torServices->keys(); - if(selDir.length() > 0) { - QListIterator<QString> it(strList); - while(it.hasNext()) { - QString temp = it.next(); - if(selDir.compare(temp) == 0) { - ui.browseButton->setEnabled(false); - break; - } - } - } - // 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); - if(service.enabled()) { - item->setCheckState(Qt::Unchecked); - service.setEnabled(false); - } else { - item->setCheckState(Qt::Checked); - service.setEnabled(true); - } - _services->insert(currentRow, service); - } -} - -/** 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* portValidator = new QIntValidator(1, 65535, this); - DomainValidator* domainValidator = new DomainValidator(this); - IpValidator* ipValidator = new IpValidator(this); - QTableWidgetItem* item = ui.serviceWidget->currentItem(); - if (item == NULL || item->text() == NULL || item->text().length() == 0) { - // nothing to validate here - return; - } - QString text = item->text(); - switch (item->column()) { - case 1: // virtual port - if(portValidator->validate(text, pos) == QValidator::Acceptable) { - // correct data; buffer value in user role 32 - item->setData(32, text); - } else { - //incorrect data; restore value from user role 32 - VMessageBox::warning(this, tr("Error"), - tr("Virtual Port may only contain valid port numbers [1..65535]."), - VMessageBox::Ok); - item->setText(item->data(32).toString()); - } - break; - case 2: // target - if(text.contains(":")) { - // check for <address>:<port> - QStringList strList = text.split(":"); - if (strList.size() != 2) { - goto invalid; - } - QString address = strList.at(0); - QString port = strList.at(1); - if((address.compare("localhost") != 0 && - ipValidator->validate(address, pos) != QValidator::Acceptable && - domainValidator->validate(address, pos) != QValidator::Acceptable) || - portValidator->validate(port, pos) != QValidator::Acceptable) { - goto invalid; - } - } else { // either <address> or <port> - if (text.compare("localhost") != 0 && - ipValidator->validate(text, pos) != QValidator::Acceptable && - domainValidator->validate(text, pos) != QValidator::Acceptable && - portValidator->validate(text, pos) != QValidator::Acceptable) { - goto invalid; - } - } - goto valid; - invalid: - VMessageBox::warning(this, tr("Error"), - tr("Target may only contain address:port, address, or port."), - VMessageBox::Ok); - item->setText(item->data(32).toString()); - break; - valid: - item->setData(32, text); - break; - case 3: // service directory - // compare with directories of other enabled services - for (int index = 0; index < ui.serviceWidget->rowCount(); index++) { - // skip own row - if(index == item->row()) { - continue; - } - QTableWidgetItem* compareWith = ui.serviceWidget->item(index, 3); - if(compareWith != NULL) { - QString actualDir = compareWith->text(); - if(actualDir.length() > 0 && text.compare(actualDir) == 0) { - // service directory already in use - VMessageBox::warning(this, tr("Error"), - tr("Directory already in use by another service."), - VMessageBox::Ok); - item->setText(item->data(32).toString()); - return; - } - } - } - // correct data; buffer value in user role 32 - item->setData(32, text); - break; - } -} - diff --git a/src/vidalia/config/ServicePage.h b/src/vidalia/config/ServicePage.h deleted file mode 100644 index 622673f..0000000 --- a/src/vidalia/config/ServicePage.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#ifndef _SERVICEPAGE_H -#define _SERVICEPAGE_H - -#include "ui_ServicePage.h" -#include "ConfigPage.h" -#include "TorSettings.h" -#include "ServiceSettings.h" -#include "ExitPolicy.h" - -#include "TorControl.h" - - -class ServicePage : public ConfigPage -{ - Q_OBJECT - -public: - /** Default Constructor */ - ServicePage(QWidget *parent = 0); - /** Default Destructor */ - ~ServicePage(); - /** Saves the changes on this page */ - bool save(QString &errmsg); - /** Loads the settings for this page */ - void load(); - /** Initialize the service table */ - void initServiceTable(QMap<int, Service>* _services); - /** Called when the user changes the UI translation. */ - virtual void retranslateUi(); - -private slots: - /** Called whenever the user clicks on the 'add' button. */ - void addService(); - /** Called whenever the user clicks on the 'remove' button. */ - void removeService(); - /** Called whenever the user clicks on the 'copy' button. */ - void copyToClipboard(); - /** Called whenever the user clicks on the 'browse' button. */ - void browseDirectory(); - /** Called whenever the user selects a different service. */ - void serviceSelectionChanged(); - /** Returns a list of services by parsing the configuration string given - * by the Tor controller. */ - QList<Service> extractSingleServices(QString conf); - /** Returns a Service by parsing the configuration string from Tor and - * storing its values into the Service object. */ - Service generateService(QString serviceString); - /** Starts all services in <b>services</b>, with Tor. */ - void startServicesInTor(QList<Service> services); - /** Returns true if <b>service</b> is published. */ - bool isServicePublished(Service service, QList<Service> torServices); - /** Returns true if all services have the required minimal configuration. */ - bool checkBeforeSaving(QList<Service> services); - /** Called when the user finished editing a cell and checks that only valid - * values are set. */ - void valueChanged(); - -private: - /** A QMap, mapping from the row number in the table to the service Entity */ - QMap<int, Service>* _services; - /** A QList, consisting of all running services before vidalia starts */ - QMap<QString, Service>* _torServices; - - /** Qt Designer generated object */ - Ui::ServicePage ui; -}; - -#endif - diff --git a/src/vidalia/config/ServicePage.ui b/src/vidalia/config/ServicePage.ui deleted file mode 100644 index 8fc6c57..0000000 --- a/src/vidalia/config/ServicePage.ui +++ /dev/null @@ -1,173 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>ServicePage</class> - <widget class="QWidget" name="ServicePage"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>600</width> - <height>400</height> - </rect> - </property> - <property name="minimumSize"> - <size> - <width>600</width> - <height>400</height> - </size> - </property> - <property name="windowTitle"> - <string notr="true"/> - </property> - <layout class="QVBoxLayout"> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="title"> - <string>Provided Hidden Services</string> - </property> - <layout class="QGridLayout"> - <item row="0" column="0" rowspan="5"> - <widget class="QTableWidget" name="serviceWidget"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::SingleSelection</enum> - </property> - <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>Onion Address</string> - </property> - </column> - <column> - <property name="text"> - <string>Virtual Port</string> - </property> - </column> - <column> - <property name="text"> - <string>Target</string> - </property> - </column> - <column> - <property name="text"> - <string>Directory Path</string> - </property> - </column> - <column> - <property name="text"> - <string>Enabled</string> - </property> - </column> - </widget> - </item> - <item row="0" column="1"> - <widget class="QToolButton" name="addButton"> - <property name="toolTip"> - <string>Add new service to list</string> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="../res/vidalia.qrc"> - <normaloff>:/images/22x22/list-add.png</normaloff>:/images/22x22/list-add.png</iconset> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QToolButton" name="removeButton"> - <property name="toolTip"> - <string>Remove selected service from list</string> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="../res/vidalia.qrc"> - <normaloff>:/images/22x22/list-remove.png</normaloff>:/images/22x22/list-remove.png</iconset> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QToolButton" name="copyButton"> - <property name="toolTip"> - <string>Copy onion address of selected service to clipboard</string> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="../res/vidalia.qrc"> - <normaloff>:/images/22x22/edit-copy.png</normaloff>:/images/22x22/edit-copy.png</iconset> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QToolButton" name="browseButton"> - <property name="toolTip"> - <string>Browse in local file system and choose directory for selected service</string> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="../res/vidalia.qrc"> - <normaloff>:/images/22x22/folder.png</normaloff>:/images/22x22/folder.png</iconset> - </property> - </widget> - </item> - <item row="4" column="1"> - <spacer> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>21</width> - <height>46</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> - <item> - <spacer> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>141</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <resources> - <include location="../res/vidalia.qrc"/> - </resources> - <connections/> -</ui> diff --git a/src/vidalia/config/ServiceSettings.cpp b/src/vidalia/config/ServiceSettings.cpp deleted file mode 100644 index 3c6fa91..0000000 --- a/src/vidalia/config/ServiceSettings.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#include "ServiceSettings.h" -#include "TorSettings.h" - -#include "stringutil.h" - -/* Service Settings */ -#define SETTING_SERVICE_VIRTUAL_PORT "Service/VirtualPort" -#define SETTING_SERVICE_ADDRESS "Service/ServiceAddress" -#define SETTING_SERVICE_PHYSICAL_ADDRESS "Service/ServicePhysicalAddress" -#define SETTING_SERVICE_ENABLED "Service/Enabled" -#define SETTING_TOR_SERVICES "Service/Services" - -/** Constructor. - * \param torControl a TorControl object used to read and apply the Service - * configuration settings. - */ -ServiceSettings::ServiceSettings(TorControl *torControl) -{ - _torControl = torControl; - setDefault(SETTING_SERVICE_VIRTUAL_PORT , 0); - setDefault(SETTING_SERVICE_PHYSICAL_ADDRESS, "127.0.0.1:0"); - setDefault(SETTING_SERVICE_ENABLED, "true"); -} - -/** Set ServiceList to serialise it */ -void -ServiceSettings::setServices(ServiceList service) -{ - QStringList serviceList; - if(service.services().size() > 0) { - QList<Service> services = service.services(); - foreach (Service tempService, services) { - serviceList << tempService.toString(); - } - } - setValue(SETTING_TOR_SERVICES, serviceList); -} - -/** Get serialised ServiceList */ -ServiceList -ServiceSettings::getServices() -{ - QString address,virtualPort,physAddrPort,serviceDir,enabledS,additionalData; - bool enabled = false; - QStringList stringList; - ServiceList services; - - stringList = value(SETTING_TOR_SERVICES).toStringList(); - foreach (QString s, stringList) { - QStringList skippedList = s.split("#"); - address = skippedList.first(); - skippedList.removeFirst(); - virtualPort = skippedList.first(); - skippedList.removeFirst(); - physAddrPort = skippedList.first(); - skippedList.removeFirst(); - serviceDir = skippedList.first(); - skippedList.removeFirst(); - enabledS = skippedList.first(); - skippedList.removeFirst(); - additionalData = skippedList.first(); - if(enabledS.compare("x1") == 0) { - enabled = true; - } - Service service(address, virtualPort, physAddrPort, serviceDir, enabled); - service.setAdditionalServiceOptions(additionalData); - services.addService(service); - } - return services; -} - -/** Returns the virtual port for a specific service*/ -QString -ServiceSettings::getVirtualPort() -{ - QString port = value(SETTING_SERVICE_VIRTUAL_PORT).toString(); - return port; -} - -/** Set the virtual port for a specific service*/ -void -ServiceSettings::setVirtualPort(QString servicePort) -{ - setValue(SETTING_SERVICE_VIRTUAL_PORT, servicePort); -} - -/** Returns the .onion - service address for a specific service */ -QString -ServiceSettings::getServiceAddress() -{ - QString addr = value(SETTING_SERVICE_ADDRESS).toString(); - return addr; -} - -/** Set the .onion - service address or hostname for a specific service */ -void -ServiceSettings::setServiceAddress(QString addr) -{ - setValue(SETTING_SERVICE_ADDRESS, addr); -} - -/** Returns the physical address for a specific service */ -QString -ServiceSettings::getPhysicalAddressPort() -{ - QString addr = value(SETTING_SERVICE_PHYSICAL_ADDRESS).toString(); - return addr; -} - -/** Set the physical address or hostname for a specific service */ -void -ServiceSettings::setPhysicalAddressPort(QString addr) -{ - setValue(SETTING_SERVICE_PHYSICAL_ADDRESS, addr); -} - -/** Returns if the Service is enabled */ -bool -ServiceSettings::isEnabled() -{ - return value(SETTING_SERVICE_ENABLED).toBool(); -} - -/** Set the service enabled */ -void -ServiceSettings::setEnabled(bool boolean) -{ - setValue(SETTING_SERVICE_ENABLED, boolean); -} - -/** Get all service directories from Tor */ -QString -ServiceSettings::getHiddenServiceDirectories() -{ - /*XXX: Domenik: Why does this always try to getconf hiddenserviceoptions - * even if the socket is not connected? */ - QString value = _torControl->getHiddenServiceConf("hiddenserviceoptions"); - return value; -} - -/** Set all services the user wants to start and send it to the - * Tor Controller*/ -void -ServiceSettings::applyServices(QString value, QString *errmsg) -{ - _torControl->setConf(value, errmsg); - _torControl->saveConf(errmsg); -} - -/** Unpublish all HiddenServices */ -void -ServiceSettings::unpublishAllServices(QString *errmsg) -{ - _torControl->resetConf("HiddenServiceDir", errmsg); - _torControl->saveConf(errmsg); -} - diff --git a/src/vidalia/config/ServiceSettings.h b/src/vidalia/config/ServiceSettings.h deleted file mode 100644 index 946dc62..0000000 --- a/src/vidalia/config/ServiceSettings.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -** This file is part of Vidalia, and is subject to the license terms in the -** LICENSE file, found in the top level directory of this distribution. If you -** did not receive the LICENSE file with this file, you may obtain it from the -** Vidalia source package distributed by the Vidalia Project at -** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, -** including this file, may be copied, modified, propagated, or distributed -** except according to the terms described in the LICENSE file. -*/ - -#ifndef _SERVICESETTINGS_H -#define _SERVICESETTINGS_H - -#include <TorControl.h> -#include <ServiceList.h> -#include <VidaliaSettings.h> -#include <ExitPolicy.h> - - -/* XXX: Domenik: Shouldn't this inherit AbstractTorSettings like the rest of - * the settings classes? */ -class ServiceSettings : private VidaliaSettings -{ -public: - /** Constructor */ - ServiceSettings(TorControl *torControl); - /** Returns the service port for a specific service*/ - QString getVirtualPort(); - /** Set the service port for a specific service*/ - void setVirtualPort(QString servicePort); - /** Returns the .onion - service address for a specific service */ - QString getServiceAddress(); - /** Set the .onion - service address for a specific service */ - void setServiceAddress(QString serviceAddress); - /** Returns the service address or hostname for a specific service */ - QString getPhysicalAddressPort(); - /** Set the service address or hostname for a specific service */ - void setPhysicalAddressPort(QString physicalAddress); - /** Returns if the Service is enabled */ - bool isEnabled(); - /** Set the service enabled */ - void setEnabled(bool enabled); - /** Returns a ServiceList containing all services */ - ServiceList getServices(); - /** Set ServiceList to serialise it */ - void setServices(ServiceList services); - /** Get Service Directories */ - QString getHiddenServiceDirectories(); - /** 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: - /** A TorControl object used to talk to Tor. */ - TorControl* _torControl; -}; - -#endif -