Linked key and ca file configuration to vpn execution. Added option to
[openvpnui.git] / src / vpncontrol.h
1 #ifndef VPNCONTROL_H
2 #define VPNCONTROL_H
3
4 #include <QObject>
5 #include <QProcess>
6
7 enum VPNSTATUS {
8 VPNSTATUS_INVALID = -1,
9
10 VPNSTATUS_UNINITIALISED,
11 VPNSTATUS_INITIALISING,
12 VPNSTATUS_CONNECTING,
13 VPNSTATUS_CONNECTED,
14 VPNSTATUS_DISCONNECTING,
15
16 VPNSTATUS_NUM
17 };
18
19 class VPNControl : public QObject
20 {
21 Q_OBJECT
22
23 Q_PROPERTY (QString server READ getServer WRITE setServer NOTIFY serverChanged)
24 Q_PROPERTY (unsigned int port READ getPort WRITE setPort NOTIFY portChanged)
25 Q_PROPERTY (bool compressed READ getCompressed WRITE setCompressed NOTIFY compressedChanged)
26 Q_PROPERTY (bool useTLS READ getUseTLS WRITE setUseTLS NOTIFY useTLSChanged)
27 Q_PROPERTY (int tlsDirection READ getTlsDirection WRITE setTlsDirection NOTIFY tlsDirectionChanged)
28 Q_PROPERTY (QString caCertFile READ getCaCertFile WRITE setCaCertFile NOTIFY caCertFileChanged)
29 Q_PROPERTY (QString clientCertFile READ getClientCertFile WRITE setClientCertFile NOTIFY clientCertFileChanged)
30 Q_PROPERTY (QString clientKeyFile READ getClientKeyFile WRITE setClientKeyFile NOTIFY clientKeyFileChanged)
31 Q_PROPERTY (QString tlsKeyFile READ getTlsKeyFile WRITE setTlsKeyFile NOTIFY tlsKeyFileChanged)
32
33 Q_PROPERTY (QString logText READ getLogText WRITE setLogText NOTIFY logTextChanged)
34
35 private:
36 QProcess * vpnProcess;
37 VPNSTATUS vpnStatus;
38 QStringList arguments;
39 QString logText;
40
41 // Configuration options
42 QString server;
43 unsigned int port;
44 bool compressed;
45 bool useTLS;
46 int tlsDirection;
47 QString caCertFile;
48 QString clientCertFile;
49 QString clientKeyFile;
50 QString tlsKeyFile;
51
52 void collectArguments ();
53 void setStatus (VPNSTATUS newStatus);
54 void addArgument (QString key, QString value);
55 void addArgument (QString key);
56 void addArgumentNonempty (QString key, QString value);
57 void addOption (QString key, bool add);
58 void addValue (QString key);
59 void settingsSetValue (QString key, QString value);
60 void settingsSetValue (QString key, int value);
61
62 public:
63 explicit VPNControl(QObject *parent = 0);
64 void initialise();
65 QString getServer() const;
66 unsigned int getPort() const;
67 bool getCompressed() const;
68 bool getUseTLS() const;
69 int getTlsDirection() const;
70 QString getCaCertFile () const;
71 QString getClientCertFile () const;
72 QString getClientKeyFile () const;
73 QString getTlsKeyFile () const;
74
75 QString getLogText() const;
76
77 signals:
78 void statusChanged(int status);
79 void serverChanged(QString &server);
80 void portChanged(unsigned int port);
81 void compressedChanged(bool compressed);
82 void useTLSChanged(bool useTLS);
83 void tlsDirectionChanged(int direction);
84 void caCertFileChanged(QString &caCertFile);
85 void clientCertFileChanged(QString &clientCertFile);
86 void clientKeyFileChanged(QString &clientKeyFile);
87 void tlsKeyFileChanged(QString &tlsKeyFile);
88
89 void logTextChanged (QString &logText);
90
91 public slots:
92 void vpnConnect ();
93 void vpnDisconnect ();
94 void readData ();
95 void started ();
96 void finished (int code);
97 void readError (QProcess::ProcessError error);
98 void updateConfiguration ();
99 void setServer(const QString &value);
100 void setPort(unsigned int value);
101 void setCompressed(bool value);
102 void setUseTLS(bool value);
103 void setTlsDirection(int value);
104 void setCaCertFile(const QString &value);
105 void setClientCertFile(const QString &value);
106 void setClientKeyFile(const QString &value);
107 void setTlsKeyFile(const QString &value);
108
109 void setLogText(const QString &value);
110 void logAppend(const QString &text);
111 };
112
113 #endif // VPNCONTROL_H