Added About page.
[openvpnui.git] / src / vpncontrol.cpp
index 3588f7b..d3ec771 100644 (file)
@@ -15,18 +15,19 @@ VPNControl::VPNControl(QObject *parent) :
 {
     // Read in the settings
     QSettings settings;
+    settings.setValue("showAll", false);
 
+    // Read configuration settings
     server = settings.value("server", "127.0.0.1").toString();
     port = settings.value("port", 1194).toInt();
     compressed = settings.value("compressed", true).toBool();
     useTLS = settings.value("useTLS", true).toBool();
     tlsDirection = settings.value("tlsDirection", 1).toInt();
     caCertFile = settings.value("caCertFile", "").toString();
-    clientCertFile = settings.value("clientCertFile", "").toString();;
-    clientKeyFile = settings.value("clientKeyFile", "").toString();;
-    tlsKeyFile = settings.value("tlsKeyFile", "").toString();;
-
-    settings.setValue("showAll", false);
+    clientCertFile = settings.value("clientCertFile", "").toString();
+    clientKeyFile = settings.value("clientKeyFile", "").toString();
+    tlsKeyFile = settings.value("tlsKeyFile", "").toString();
+    configFile = settings.value("configFile", "").toString();
 }
 
 void VPNControl::initialise()
@@ -152,6 +153,15 @@ void VPNControl::setTlsKeyFile(const QString &value)
     }
 }
 
+void VPNControl::setConfigFile(const QString &value)
+{
+    if (value != configFile) {
+        configFile = value;
+        settingsSetValue("configFile", value);
+        emit tlsKeyFileChanged(configFile);
+    }
+}
+
 QString VPNControl::getClientCertFile () const
 {
     return clientCertFile;
@@ -167,6 +177,11 @@ QString VPNControl::getTlsKeyFile () const
     return tlsKeyFile;
 }
 
+QString VPNControl::getConfigFile () const
+{
+    return configFile;
+}
+
 QString VPNControl::getLogText() const
 {
     return logText;
@@ -196,7 +211,7 @@ void VPNControl::vpnConnect() {
     }
     else {
         vpnProcess = new QProcess();
-        QString program = "openvpn";
+        QString program = "/usr/share/harbour-openvpn-rig/bin/ovpnpermit";
         collectArguments ();
         vpnProcess->setReadChannel(QProcess::StandardOutput);
         connect(vpnProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(readError(QProcess::ProcessError)));
@@ -214,7 +229,17 @@ void VPNControl::vpnConnect() {
 void VPNControl::collectArguments () {
     arguments.clear();
 
-    addArgumentNonempty("config", "/home/nemo/Documents/Configure/OpenVPN/config.ovpn");
+    addArgumentNonempty("config", configFile);
+    addOption("client", true);
+    addOption("persist-key", true);
+    addOption("persist-tun", true);
+    addOption("nobind", true);
+    addArgument("resolv-retry", "infinite");
+    addArgument("dev", "tun");
+    addArgument("verb", "3");
+    addArgument("proto", "udp");
+    addArgument("user", "nemo");
+    addArgument("group", "nemo");
     addArgumentNonempty("remote", server);
     addArgumentNonempty("port", QString::number(port));
     addOption("comp-lzo", compressed);
@@ -294,6 +319,7 @@ void VPNControl::finished(int code) {
         //delete vpnProcess;
         vpnProcess = NULL;
     }
+    logAppend("Finished with code " + QString::number(code));
     setStatus(VPNSTATUS_UNINITIALISED);
 }
 
@@ -320,22 +346,27 @@ void VPNControl::updateConfiguration()
 void VPNControl::logAppend(const QString &text)
 {
     if (!text.isEmpty()) {
+        QString append = text;
+        // Ensure we end with a newline
+        if (!append.endsWith('\n')) {
+            append += '\n';
+        }
         // How many lines to add
-        int newLines = text.count('\n');
+        int newLines = append.count('\n');
         int currentLines = logText.count('\n');
-        int removeLines = currentLines + newLines - 18;
-
-        // Remove excess lines
-//        while (removeLines > 0) {
-//            int nextLine = logText.indexOf('\n');
-//            if (nextLine > 0) {
-//                logText = logText.right(nextLine);
-//            }
-//            removeLines--;
-//        }
+        int removeLines = currentLines + newLines - 24;
+
+        // Remove excess lines from the top
+        while (removeLines > 0) {
+            int nextLine = logText.indexOf('\n');
+            if (nextLine > 0) {
+                logText = logText.mid(nextLine + 1);
+            }
+            removeLines--;
+        }
 
         // Add new lines
-        logText.append(text);
+        logText.append(append);
         emit logTextChanged(logText);
     }
 }