X-Git-Url: https://www.flypig.org.uk/git/?a=blobdiff_plain;f=src%2Fvpncontrol.cpp;h=d0d411b3b02bd514f00fcb4df718f4e174abab46;hb=998d9a10d91bc558ba91c3f35c1c9e19ef788c63;hp=057cb365941c81d4dccc66446c8689e77db0b71f;hpb=e24363e314aca32e7bee952f02f517a04a8dc5f2;p=openvpnui.git diff --git a/src/vpncontrol.cpp b/src/vpncontrol.cpp index 057cb36..d0d411b 100644 --- a/src/vpncontrol.cpp +++ b/src/vpncontrol.cpp @@ -15,13 +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(); - settings.setValue("showAll", false); + caCertFile = settings.value("caCertFile", "").toString(); + clientCertFile = settings.value("clientCertFile", "").toString(); + clientKeyFile = settings.value("clientKeyFile", "").toString(); + tlsKeyFile = settings.value("tlsKeyFile", "").toString(); + configFile = settings.value("configFile", "").toString(); } void VPNControl::initialise() @@ -106,6 +112,76 @@ void VPNControl::setServer(const QString &value) } } +QString VPNControl::getCaCertFile () const +{ + return caCertFile; +} + +void VPNControl::setCaCertFile(const QString &value) +{ + if (value != caCertFile) { + caCertFile = value; + settingsSetValue("caCertFile", value); + emit caCertFileChanged(caCertFile); + } +} + +void VPNControl::setClientCertFile(const QString &value) +{ + if (value != clientCertFile) { + clientCertFile = value; + settingsSetValue("clientCertFile", value); + emit clientCertFileChanged(clientCertFile); + } +} + +void VPNControl::setClientKeyFile(const QString &value) +{ + if (value != clientKeyFile) { + clientKeyFile = value; + settingsSetValue("clientKeyFile", value); + emit clientKeyFileChanged(clientKeyFile); + } +} + +void VPNControl::setTlsKeyFile(const QString &value) +{ + if (value != tlsKeyFile) { + tlsKeyFile = value; + settingsSetValue("tlsKeyFile", value); + emit tlsKeyFileChanged(tlsKeyFile); + } +} + +void VPNControl::setConfigFile(const QString &value) +{ + if (value != configFile) { + configFile = value; + settingsSetValue("configFile", value); + emit tlsKeyFileChanged(configFile); + } +} + +QString VPNControl::getClientCertFile () const +{ + return clientCertFile; +} + +QString VPNControl::getClientKeyFile () const +{ + return clientKeyFile; +} + +QString VPNControl::getTlsKeyFile () const +{ + return tlsKeyFile; +} + +QString VPNControl::getConfigFile () const +{ + return configFile; +} + QString VPNControl::getLogText() const { return logText; @@ -114,7 +190,7 @@ QString VPNControl::getLogText() const void VPNControl::setLogText(const QString &value) { logText = value; - emit logTextChanged(value); + emit logTextChanged(logText); } void VPNControl::settingsSetValue (QString key, QString value) { @@ -135,7 +211,7 @@ void VPNControl::vpnConnect() { } else { vpnProcess = new QProcess(); - QString program = "openvpn"; + QString program = "/usr/share/OpenVPNUI/bin/ovpnpermit"; collectArguments (); vpnProcess->setReadChannel(QProcess::StandardOutput); connect(vpnProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(readError(QProcess::ProcessError))); @@ -153,17 +229,27 @@ void VPNControl::vpnConnect() { void VPNControl::collectArguments () { arguments.clear(); - addArgument("config", "/home/nemo/Documents/Configure/OpenVPN/config.ovpn"); - addArgument("remote", server); - addArgument("port", QString::number(port)); + 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); - if (useTLS) { - addArgument("tls-auth", "/home/nemo/Documents/Configure/OpenVPN/ta.key"); + if ((useTLS) && (!tlsKeyFile.isEmpty())) { + addArgument("tls-auth", tlsKeyFile); addValue(QString::number(tlsDirection)); } - addArgument("ca", "/home/nemo/Documents/Configure/OpenVPN/ca.crt"); - addArgument("cert", "/home/nemo/Documents/Configure/OpenVPN/Jolla.crt"); - addArgument("key", "/home/nemo/Documents/Configure/OpenVPN/Jolla.key"); + addArgumentNonempty("ca", caCertFile); + addArgumentNonempty("cert", clientCertFile); + addArgumentNonempty("key", clientKeyFile); } void VPNControl::addArgument (QString key, QString value) { @@ -171,7 +257,17 @@ void VPNControl::addArgument (QString key, QString value) { argument = "--" + key; arguments.append(argument); - if (value != "") { + if (!value.isEmpty()) { + arguments.append(value); + } +} + +void VPNControl::addArgumentNonempty (QString key, QString value) { + QString argument; + + if (!value.isEmpty()) { + argument = "--" + key; + arguments.append(argument); arguments.append(value); } } @@ -249,22 +345,28 @@ 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; + int removeLines = currentLines + newLines - 24; - // Remove excess lines + // Remove excess lines from the top while (removeLines > 0) { - int nextLine = logText.lastIndexOf('\n'); + int nextLine = logText.indexOf('\n'); if (nextLine > 0) { - logText = logText.left(nextLine); + logText = logText.mid(nextLine + 1); } removeLines--; } // Add new lines - logText.prepend(text); + logText.append(append); emit logTextChanged(logText); } } +