[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2400: Source Files of Prototyp 1 including: - the service entities (vidalia/branches/hidden-services/src/vidalia/config)
Author: borkdomenik
Date: 2008-03-12 23:28:42 -0400 (Wed, 12 Mar 2008)
New Revision: 2400
Added:
vidalia/branches/hidden-services/src/vidalia/config/service.cpp
vidalia/branches/hidden-services/src/vidalia/config/service.h
vidalia/branches/hidden-services/src/vidalia/config/servicelist.cpp
vidalia/branches/hidden-services/src/vidalia/config/servicelist.h
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
Modified:
vidalia/branches/hidden-services/src/vidalia/config/configdialog.cpp
vidalia/branches/hidden-services/src/vidalia/config/configdialog.h
vidalia/branches/hidden-services/src/vidalia/config/vidaliasettings.cpp
Log:
Source Files of Prototyp 1 including:
- the service entities
- the service settings
- the qt designer file
Modified: vidalia/branches/hidden-services/src/vidalia/config/configdialog.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/configdialog.cpp 2008-03-13 03:24:53 UTC (rev 2399)
+++ vidalia/branches/hidden-services/src/vidalia/config/configdialog.cpp 2008-03-13 03:28:42 UTC (rev 2400)
@@ -42,6 +42,7 @@
#define IMAGE_SAVE ":/images/22x22/media-floppy.png"
#define IMAGE_CANCEL ":/images/22x22/emblem-unreadable.png"
#define IMAGE_HELP ":/images/22x22/help-browser.png"
+#define IMAGE_SERVICE ":/images/22x22/service.png"
/** Constructor */
@@ -88,6 +89,10 @@
ui.stackPages->add(new AdvancedPage(ui.stackPages),
createPageAction(QIcon(IMAGE_ADVANCED),
tr("Advanced"), grp));
+
+ ui.stackPages->add(new ServicePage(ui.stackPages),
+ createPageAction(QIcon(IMAGE_SERVICE),
+ tr("Services"), grp));
foreach (ConfigPage *page, ui.stackPages->pages()) {
connect(page, SIGNAL(helpRequested(QString)),
this, SLOT(help(QString)));
Modified: vidalia/branches/hidden-services/src/vidalia/config/configdialog.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/configdialog.h 2008-03-13 03:24:53 UTC (rev 2399)
+++ vidalia/branches/hidden-services/src/vidalia/config/configdialog.h 2008-03-13 03:28:42 UTC (rev 2400)
@@ -26,6 +26,7 @@
#include "serverpage.h"
#include "advancedpage.h"
#include "appearancepage.h"
+#include "servicepage.h"
#include "ui_configdialog.h"
@@ -41,7 +42,8 @@
Network, /** Network configuration page. */
Server, /** Server configuration page. */
Appearance, /** Appearance configuration page. */
- Advanced /** Advanced configuration page. */
+ Advanced, /** Advanced configuration page. */
+ Service /** Service Configuration page */
};
/** Default Constructor */
Added: vidalia/branches/hidden-services/src/vidalia/config/service.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/service.cpp (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/service.cpp 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,101 @@
+/*
+** 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.vidalia-project.net/. 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;
+}
+
+
+/** 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();
+ if(myObj.enabled()) {
+ out << "True";
+ } else {
+ out << "False";
+ }
+ 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;
+ QString enabledS;
+
+ /* Read in from the data stream */
+ in >> serviceAddress >> virtualPort >> physicalAddressPort >> serviceDirectory >> enabledS;
+
+ /* Set the appropriate class member variables */
+ myObj.setServiceAddress(serviceAddress);
+ myObj.setVirtualPort(virtualPort);
+ myObj.setPhysicalAddressPort(physicalAddressPort);
+ myObj.setServiceDirectory(serviceDirectory);
+ if(enabledS.compare("True") == 0) {
+ myObj.setEnabled(true);
+ } else {
+ myObj.setEnabled(false);
+ }
+
+ /* Return the updated data stream */
+ return in;
+}
+
+
Added: vidalia/branches/hidden-services/src/vidalia/config/service.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/service.h (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/service.h 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,86 @@
+/*
+** 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.vidalia-project.net/. 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; }
+
+ /** 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);
+
+ /** 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);
+
+
+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;
+
+};
+Q_DECLARE_METATYPE(Service);
+#endif /*SERIVCE_H_*/
+
Added: vidalia/branches/hidden-services/src/vidalia/config/servicelist.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicelist.cpp (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicelist.cpp 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,56 @@
+/*
+** 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.vidalia-project.net/. 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;
+}
Added: vidalia/branches/hidden-services/src/vidalia/config/servicelist.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicelist.h (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicelist.h 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,51 @@
+/*
+** 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.vidalia-project.net/. 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 <QList>
+#include <service.h>
+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 /*SERVICELIST_H_*/
+
Added: vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.cpp 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,438 @@
+/*
+** 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.vidalia-project.net/. 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 <util/stringutil.h>
+#include <vmessagebox.h>
+#include <qheaderview.h>
+#include <qclipboard.h>
+#include <QFile>
+#include <QTextStream>
+#include <file.h>
+#include "configdialog.h"
+#include "service.h"
+#include "servicelist.h"
+/** TODO
+ * size of the window exoanding
+ * communikation with tor controller seems not to work, yet */
+ /** FIXME
+ * bug when the first service should be published, the other values of the other service are
+ * missing when the service window appears next time */
+
+
+/** Constructor */
+ServicePage::ServicePage(QWidget *parent)
+: ConfigPage(parent, tr("Services"))
+{
+ /* Invoke the Qt Designer generated object setup routine */
+ ui.setupUi(this);
+ /* Keep a pointer to the TorControl object used to talk to Tor */
+ _torControl = Vidalia::torControl();
+ /* 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 */
+ _services = new QMap<int, Service>();
+ /* A QList, consisting of all running services before vidalia starts*/
+ QList<Service> _torServices;
+
+ ui.serviceWidget->horizontalHeader()->setResizeMode(0,QHeaderView::Stretch);
+ ui.serviceWidget->horizontalHeader()->setResizeMode(1,QHeaderView::Custom);
+ ui.serviceWidget->horizontalHeader()->setResizeMode(2,QHeaderView::Custom);
+ ui.serviceWidget->horizontalHeader()->setResizeMode(3,QHeaderView::Custom);
+ ui.serviceWidget->horizontalHeader()->resizeSection(1, 100);
+ ui.serviceWidget->horizontalHeader()->resizeSection(2, 125);
+ ui.serviceWidget->horizontalHeader()->resizeSection(3, 60);
+
+ 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.hiddenServiceDirLineEdit, SIGNAL(editingFinished()), this, SLOT(storeServiceDir()));
+ connect(ui.serviceWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(serviceSelectionChanged()));
+}
+
+/** Destructor */
+ServicePage::~ServicePage()
+{
+ delete _torControl;
+ delete _serviceSettings;
+}
+
+/** Saves changes made to settings on the Server settings page. */
+bool
+ServicePage::save(QString &errmsg)
+{
+ 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 = _services->value(index).serviceDirectory();
+ bool enabled = _services->value(index).enabled();
+ Service temp(address, virtualPort, physicalAddress, directoryPath, enabled);
+ serviceList.push_back(temp);
+ if(enabled) {
+ publishedServices.push_back(temp);
+ }
+ index++;
+ }
+ bool save;
+ 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);
+ //VMessageBox::warning(this, tr("Tor Services:"), QString::number(publishedServices.size()), VMessageBox::Ok);
+ }
+ 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.";
+ return false;
+ }
+}
+
+/** this method checks either all services have minimal configuration or not s*/
+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)
+{
+ QString serviceConfString;
+ QString errmsg = "Error while trying to publish services.";
+ QListIterator<Service> it(services);
+ while(it.hasNext()) {
+ Service temp = it.next();
+ serviceConfString.append(createServiceConfString(temp));
+ }
+ _serviceSettings->applyServices(serviceConfString, &errmsg);
+}
+
+/** this method generates the configuration string for a service */
+QString
+ServicePage::createServiceConfString(Service temp)
+{
+ QString s;
+ s.append("hiddenservicedir "+temp.serviceDirectory()+"\n");
+ s.append("hiddenserviceport "+temp.virtualPort());
+ if(temp.physicalAddressPort().isEmpty() == false) {
+ s.append(" "+temp.physicalAddressPort());
+ }
+ return s;
+}
+
+
+/** Loads previously saved settings */
+void
+ServicePage::load()
+{
+ _services = new QMap<int, Service>();
+ QList<Service> _torServices;
+
+ QString conf = _serviceSettings->getHiddenServiceDirectories();
+ _torServices = extractSingleServices(conf);
+ QList<Service> completeList = _torServices;
+ //VMessageBox::warning(this, tr("Tor Services:"), QString::number(completeList.size()), VMessageBox::Ok);
+
+ 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)) {
+ 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;
+
+// QString teststr = "some kind of data\n and another kind of\n";
+// teststr.append("hiddenservicedir /home/jars/workspace/testingtor/1/\n");
+// teststr.append("hiddenserviceport 9053\n");
+// teststr.append("hiddenservicenodes someNodeName\n");
+// teststr.append("hiddenserviceexcludenodes anotherNode\n");
+// teststr.append("hiddenservicedir /home/jars/workspace/testingtor/2/\n");
+// teststr.append("hiddenserviceport 9054\n");
+// teststr.append("hiddenservicedir /home/jars/workspace/testingtor/3/\n");
+// teststr.append("hiddenserviceport 9055 127.0.0.1:9056");
+
+ QStringList strList = conf.split("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 address, virtualPort, physAddressPort, serviceDir;
+ // service directory
+ QStringList strList = s.split("\n");
+ serviceDir = strList.first().trimmed();
+ //virtual port
+ QStringList strList2 = s.split("hiddenserviceport");
+ strList2.removeFirst();
+ QStringList strList3 = strList2.first().split("\n");
+ QStringList strList4 = strList3.first().split(" ");
+ strList4.removeFirst();
+ virtualPort = strList4.first().trimmed();
+ strList4.removeFirst();
+ //physical address:port
+ if(!strList4.isEmpty()) {
+ physAddressPort = strList4.first().trimmed();
+ }
+ //get .onion address
+ QString serviceHostnameDir = serviceDir;
+ serviceHostnameDir.append("/hostname");
+ QFile file(serviceHostnameDir);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ address = "[Created by Tor]";
+ } else {
+ QTextStream in(&file);
+ QString hostname;
+ while (!in.atEnd()) {
+ hostname.append(in.readLine());
+ }
+ address = hostname;
+ }
+ Service service(address, virtualPort, physAddressPort, serviceDir, true);
+ return service;
+}
+
+/** this method checks either a service is published or not */
+bool
+ServicePage::isServicePublished(Service service)
+{
+ 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 result;
+}
+
+/** 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();
+ if(tempService.enabled()) {
+ cboxitem->setCheckState(Qt::Checked);
+ addressitem->setText(tempService.serviceAddress());
+ } 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, cboxitem);
+ index++;
+ }
+}
+
+/** this method is called when the user clicks the "Add"-Button
+ * it generates a new empty table entrie(row) */
+void
+ServicePage::addService()
+{
+ ui.hiddenServiceDirLineEdit->setText("");
+ int rows = ui.serviceWidget->rowCount();
+ ui.serviceWidget->insertRow(rows);
+ QTableWidgetItem *address = new QTableWidgetItem("[Created by Tor]");
+ QTableWidgetItem *dummy = new QTableWidgetItem();
+ QTableWidgetItem *dummy2 = new QTableWidgetItem();
+ QTableWidgetItem *cboxitem = new QTableWidgetItem();
+ cboxitem->setFlags(Qt::ItemIsSelectable);
+ cboxitem->setCheckState(Qt::Unchecked);
+ cboxitem->setTextAlignment(Qt::AlignCenter);
+ ui.serviceWidget->setItem(rows, 0, address);
+ ui.serviceWidget->setItem(rows, 1, dummy);
+ ui.serviceWidget->setItem(rows, 2, dummy2);
+ ui.serviceWidget->setItem(rows, 3, cboxitem);
+ Service s;
+ _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();
+ if(rows < 1) {
+ VMessageBox::warning(this, tr("Error"), tr("Please select a Service."), VMessageBox::Ok);
+ return;
+ } else {
+ int selrow = ui.serviceWidget->currentRow();
+ 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 rows = ui.serviceWidget->rowCount();
+ if(rows < 1) {
+ VMessageBox::warning(this, tr("Error"), tr("Please select a Service."), VMessageBox::Ok);
+ return;
+ } else {
+ int selrow = ui.serviceWidget->currentRow();
+ if (selrow >= 0) {
+ 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 rows = ui.serviceWidget->rowCount();
+ if(rows < 1) {
+ VMessageBox::warning(this, tr("Error"), tr("Please select a Service."), VMessageBox::Ok);
+ return;
+ } else {
+ int selrow = ui.serviceWidget->currentRow();
+ if (selrow >= 0) {
+ QString dirname = QFileDialog::getExistingDirectory(this, tr("Select Service Directory"),
+ "", QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
+
+ if (dirname.isEmpty()) {
+ return;
+ }
+ ui.hiddenServiceDirLineEdit->setText(dirname);
+ Service s = _services->take(selrow);
+ s.setServiceDirectory(dirname);
+ _services->insert(selrow, s);
+ }
+ }
+}
+
+/** this method is called when the user finished editing the service driectory line edit*/
+void
+ServicePage::storeServiceDir()
+{
+ QString dir = ui.hiddenServiceDirLineEdit->text();
+ int row = ui.serviceWidget->currentRow();
+ if(row >= 0 && dir.isEmpty() == false) {
+ if(_services->contains(row)) {
+ Service s = _services->take(row);
+ s.setServiceDirectory(dir);
+ _services->insert(row, s);
+ ui.hiddenServiceDirLineEdit->setText(dir);
+ }
+ }
+}
+
+/** this method is called when the user selection of the service listing changed */
+void
+ServicePage::serviceSelectionChanged()
+{
+ int currentRow = ui.serviceWidget->currentRow();
+ if(_services->contains(currentRow)) {
+ ui.hiddenServiceDirLineEdit->setText(_services->value(currentRow).serviceDirectory());
+ } else {
+ ui.hiddenServiceDirLineEdit->setText("");
+ }
+ // if the user has clicked on the checkbox cell
+ if(ui.serviceWidget->currentColumn() == 3) {
+ Service service = _services->take(currentRow);
+ QTableWidgetItem* item = ui.serviceWidget->item(currentRow,3);
+ if(service.enabled()) {
+ item->setCheckState(Qt::Unchecked);
+ service.setEnabled(false);
+ } else {
+ item->setCheckState(Qt::Checked);
+ service.setEnabled(true);
+ }
+ _services->insert(currentRow, service);
+ }
+}
+
+
+
+
+
+
Added: vidalia/branches/hidden-services/src/vidalia/config/servicepage.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.h (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.h 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,81 @@
+/*
+** 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.vidalia-project.net/. 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 <torcontrol.h>
+#include <servicesettings.h>
+#include <exitpolicy.h>
+#include <helpbrowser.h>
+
+#include "configpage.h"
+#include "ui_servicepage.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);
+
+private slots:
+ void addService();
+
+ void removeService();
+
+ void copyToClipboard();
+
+ void browseDirectory();
+
+ void storeServiceDir();
+
+ void serviceSelectionChanged();
+
+ QList<Service> extractSingleServices(QString conf);
+
+ Service generateService(QString serviceString);
+
+ void startServicesInTor(QList<Service> services);
+
+ QString createServiceConfString(Service temp);
+
+ bool isServicePublished(Service service);
+
+ bool checkBeforeSaving(QList<Service> services);
+
+
+private:
+ /** A TorControl object used to talk to Tor. */
+ TorControl* _torControl;
+ /** A ServiceSettings object used to load/save the services. */
+ ServiceSettings* _serviceSettings;
+ /* A QMap, mapping from QString servicename to the Entity service */
+ QMap<int, Service>* _services;
+ /* A QList, consisting of all running services before vidalia starts*/
+ QList<Service> _torServices;
+ /** Qt Designer generated object */
+ Ui::ServicePage ui;
+};
+
+#endif
+
+
Added: vidalia/branches/hidden-services/src/vidalia/config/servicepage.ui
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicepage.ui (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicepage.ui 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,184 @@
+<ui version="4.0" >
+ <class>ServicePage</class>
+ <widget class="QWidget" name="ServicePage" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>652</width>
+ <height>581</height>
+ </rect>
+ </property>
+ <property name="minimumSize" >
+ <size>
+ <width>581</width>
+ <height>581</height>
+ </size>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <widget class="QGroupBox" name="groupBox_2" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>280</y>
+ <width>631</width>
+ <height>101</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title" >
+ <string>Service Directory</string>
+ </property>
+ <widget class="QWidget" name="" >
+ <property name="geometry" >
+ <rect>
+ <x>20</x>
+ <y>40</y>
+ <width>591</width>
+ <height>29</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="label" >
+ <property name="text" >
+ <string>Service Directory Path</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="hiddenServiceDirLineEdit" />
+ </item>
+ <item>
+ <widget class="QPushButton" name="browseButton" >
+ <property name="text" >
+ <string>Browse</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>40</y>
+ <width>631</width>
+ <height>231</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title" >
+ <string>Service Listing</string>
+ </property>
+ <widget class="QTableWidget" name="serviceWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>11</x>
+ <y>21</y>
+ <width>511</width>
+ <height>199</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ <property name="selectionBehavior" >
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
+ <column>
+ <property name="text" >
+ <string>Service Address</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>Virtual Port</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>Physical Addr.:Port</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>Enabled</string>
+ </property>
+ </column>
+ </widget>
+ <widget class="QWidget" name="" >
+ <property name="geometry" >
+ <rect>
+ <x>539</x>
+ <y>21</y>
+ <width>81</width>
+ <height>131</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QPushButton" name="addButton" >
+ <property name="text" >
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="removeButton" >
+ <property name="text" >
+ <string>Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="copyButton" >
+ <property name="text" >
+ <string>Copy</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
Added: vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicesettings.cpp 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,142 @@
+/** header */
+
+#include <stringutil.h>
+#include "servicesettings.h"
+#include "torsettings.h"
+
+/* Server-related torrc configuration parameters */
+#define SERVER_SERVICE_DIR "ServiceDir"
+
+/* 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)
+{
+ QVariant v = new QVariant();
+ v.setValue(service);
+ setValue(SETTING_TOR_SERVICES, v);
+}
+
+
+/** Get serialised ServiceList */
+ServiceList
+ServiceSettings::getServices()
+{
+ QVariant v = value(SETTING_TOR_SERVICES);
+ ServiceList services = v.value<ServiceList>();
+ return services;
+}
+
+/** Returns the virtual port for a specififc service*/
+QString
+ServiceSettings::getVirtualPort()
+{
+ QString port = value(SETTING_SERVICE_VIRTUAL_PORT).toString();
+ return port;
+}
+
+/** Set the virtual port for a specififc 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);
+}
+
+bool
+ServiceSettings::isEnabled()
+{
+ QString boolean = value(SETTING_SERVICE_ADDRESS).toString();
+ if(boolean=="True") {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void
+ServiceSettings::setEnabled(bool boolean)
+{
+ if(boolean) {
+ setValue(SETTING_SERVICE_ENABLED, "True");
+ } else {
+ setValue(SETTING_SERVICE_ENABLED, "False");
+ }
+}
+
+
+/** Set ServiceDirectory and send it to the Tor Controller */
+void
+ServiceSettings::apply(QString value, QString *errmsg)
+{
+ _torControl->setConf("ServiceDir", value, errmsg);
+ _torControl->saveConf(errmsg);
+}
+
+/** Get all service directories from Tor */
+QString
+ServiceSettings::getHiddenServiceDirectories()
+{
+ QString value;
+ _torControl->getConf("hiddenserviceoptions", value);
+ return value;
+}
+
+void
+ServiceSettings::applyServices(QString value, QString *errmsg)
+{
+ _torControl->setConf("hiddenserviceoptions", value, errmsg);
+ _torControl->saveConf(errmsg);
+}
+
+
+
Added: vidalia/branches/hidden-services/src/vidalia/config/servicesettings.h
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/servicesettings.h (rev 0)
+++ vidalia/branches/hidden-services/src/vidalia/config/servicesettings.h 2008-03-13 03:28:42 UTC (rev 2400)
@@ -0,0 +1,65 @@
+/** header */
+
+
+#ifndef _SERVICESETTINGS_H
+#define _SERVICESETTINGS_H
+
+#include <torcontrol.h>
+#include <servicelist.h>
+#include "vidaliasettings.h"
+#include "exitpolicy.h"
+
+class ServiceSettings : private VidaliaSettings {
+
+public:
+ /** Constructor */
+ ServiceSettings(TorControl *torControl);
+
+ /** Returns the service port for a specififc service*/
+ QString getVirtualPort();
+
+ /** Set the service port for a specififc 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);
+
+ ServiceList getServices();
+
+ /** Set ServiceList to serialise it */
+ void setServices(ServiceList services);
+
+ /** Set ServiceDirectory and send it to the Tor Controller */
+ void apply(QString value, QString *errmsg = 0);
+
+ /** 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);
+
+private:
+
+ /** A TorControl object used to talk to Tor. */
+ TorControl* _torControl;
+};
+
+#endif
+
+
+
Modified: vidalia/branches/hidden-services/src/vidalia/config/vidaliasettings.cpp
===================================================================
--- vidalia/branches/hidden-services/src/vidalia/config/vidaliasettings.cpp 2008-03-13 03:24:53 UTC (rev 2399)
+++ vidalia/branches/hidden-services/src/vidalia/config/vidaliasettings.cpp 2008-03-13 03:28:42 UTC (rev 2400)
@@ -19,6 +19,7 @@
#include <QStyleFactory>
#include <languagesupport.h>
#include <vidalia.h>
+#include <servicelist.h>
#include "vidaliasettings.h"
@@ -44,6 +45,11 @@
/** Default Constructor */
VidaliaSettings::VidaliaSettings()
{
+ qRegisterMetaType<Service>("Service");
+ qRegisterMetaTypeStreamOperators<Service>("Service");
+ qRegisterMetaType<ServiceList>("ServiceList");
+ qRegisterMetaTypeStreamOperators<ServiceList>("ServiceList");
+
#if defined(Q_WS_MAC)
setDefault(SETTING_STYLE, "macintosh (aqua)");
#else