Vidalia  0.2.17
TorSettings.h
Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file TorSettings.h
00013 ** \brief Settings used for starting and running Tor
00014 */
00015 
00016 #ifndef _TORSETTINGS_H
00017 #define _TORSETTINGS_H
00018 
00019 #include "AbstractTorSettings.h"
00020 
00021 #include <QHostAddress>
00022 
00023 
00024 /** Manages Tor-specific settings, such as location, command-line arguments,
00025  * and control interface information. */
00026 class TorSettings : public AbstractTorSettings
00027 {
00028   Q_OBJECT
00029 
00030 public:
00031   /** Available Tor authentication methods. */
00032   enum AuthenticationMethod {
00033     NullAuth,      /**< No authentication. */
00034     CookieAuth,    /**< Use a "magic" cookie for authentication. */
00035     PasswordAuth,  /**< Use a hashed password for authentication. */
00036     UnknownAuth    /**< Unknown authentication method. */
00037   };
00038   
00039   /** Default constructor. */
00040   TorSettings(TorControl *torControl = 0);
00041   /** Applies any changes to Tor's control port or authentication settings. */ 
00042   bool apply(QString *errmsg = 0);
00043 
00044   /** Gets the name and path of Tor's executable. */
00045   QString getExecutable() const;
00046   /** Sets the name and path of Tor's executable. */
00047   void setExecutable(const QString &torExecutable);
00048  
00049   /** Gets the location of Tor's data directory. */
00050   QString getDataDirectory() const;
00051   /** Sets the location to use for Tor's data directory. */
00052   void setDataDirectory(const QString &dataDir);
00053   
00054   /** Gets the torrc to use when starting Tor. */
00055   QString getTorrc() const;
00056   /** Sets the torrc to use when starting Tor. */
00057   void setTorrc(const QString &torrc);
00058   
00059   /** Get Tor's control interface address. */
00060   QHostAddress getControlAddress() const;
00061   /** Set Tor's control interface address. */
00062   void setControlAddress(const QHostAddress &addr);
00063   
00064   /** Get the control port. */
00065   quint16 getControlPort() const;
00066   /** Set the control port. */
00067   void setControlPort(quint16 port);
00068 
00069   /** Get the path for ControlSocket */
00070   QString getSocketPath() const;
00071 
00072   /** Get the current control method */
00073   ControlMethod::Method getControlMethod() const;
00074 
00075   /** Returns true if Vidalia will get the ControlPort automatically from
00076    * Tor */
00077   bool autoControlPort() const;
00078 
00079   /** Sets whether Vidalia should get the ControlPort from Tor */
00080   void setAutoControlPort(const bool auto);
00081 
00082   /** Set the control method */
00083   void setControlMethod(ControlMethod::Method method);
00084 
00085   /** Set the path for ControlSocket */
00086   void setSocketPath(const QString &path);
00087   
00088   /** Returns the plaintext (i.e., not hashed) control password used when
00089    * authenticating to Tor. */
00090   QString getControlPassword() const;
00091   /** Sets the control password used when starting Tor with
00092    * HashedControlPassword to <b>password</b>. */
00093   void setControlPassword(const QString &password);
00094 
00095  /** Returns true if a new, random control password is to be used each time
00096   * Tor is started. */
00097   bool useRandomPassword() const;
00098   /** Sets whether or not to generate and use a random control password each
00099    * time Tor is started. */
00100   void setUseRandomPassword(bool useRandomPassword);
00101 
00102   /** Returns the current authentication method used when connecting to Tor.*/
00103   AuthenticationMethod getAuthenticationMethod() const;
00104   /** Sets the authentication method used when starting Tor to <b>method</b>.*/
00105   void setAuthenticationMethod(AuthenticationMethod method);
00106 
00107   /** Returns the current list of ports that will cause Tor to issue a warning
00108    * when the user tries to connect to one of them. */
00109   QList<quint16> getWarnPlaintextPorts() const;
00110   /** Sets the list of ports that will cause Tor to issue a warning when the
00111    * user tries to connect to one of them. */
00112   void setWarnPlaintextPorts(const QList<quint16> &ports);
00113 
00114   /** Returns the current list of ports that will cause Tor to reject the
00115    * connection when the user tries to connect to one of them. */
00116   QList<quint16> getRejectPlaintextPorts() const;
00117   /** Sets the list of ports that will cause Tor to reject the connection
00118    * when the user tries to connect to one of them. */
00119   void setRejectPlaintextPorts(const QList<quint16> &ports);
00120 
00121   /** Generates a random control password consisting of PASSWORD_LEN
00122    * characters. */
00123   static QString randomPassword();
00124   /** Returns the hash of <b>password</b> as given by the command 
00125    * "tor --hash-password foo". */
00126   static QString hashPassword(const QString &password);
00127 
00128   /** Returns true if Vidalia needs to bootstrap the torrc file */
00129   bool bootstrap() const;
00130   /** Enables or disables bootstrap */
00131   void setBootstrap(bool enabled);
00132   /** Returns the path of the bootstrap torrc file */
00133   QString bootstrapFrom() const;
00134   /** Sets the location of the bootstrap torrc file */
00135   void setBootstrapFrom(const QString &from);
00136 
00137 private:
00138   /** Returns the AuthenticationMethod enum value for the string
00139    * description of the authentication method given in <b>authMethod</b>. */
00140   AuthenticationMethod toAuthenticationMethod(const QString &authMethod) const;
00141   /** Returns the string description of the authentication method specified by
00142    * <b>method</b>. The authentication method string is stored in  Vidalia's
00143    * configuration file. */
00144   QString toString(AuthenticationMethod type) const;
00145 };
00146 
00147 #endif
00148