Commit 5a18673d authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb41460' into 'master'

Allow only one active vpn at once

See merge request mer-core/nemo-qml-plugin-systemsettings!49
parents 66f88138 3ab5248a
<?xml version="1.0"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="net.connman.Service">
<method name="GetProperties">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
<arg name="properties" type="a{sv}" direction="out"/>
</method>
<method name="SetProperty">
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="ClearProperty">
<arg name="name" type="s" direction="in"/>
</method>
<method name="Connect"/>
<method name="Disconnect"/>
<method name="Remove"/>
<method name="MoveBefore">
<arg name="service" type="o" direction="in"/>
</method>
<method name="MoveAfter">
<arg name="service" type="o" direction="in"/>
</method>
<method name="ResetCounters"/>
<signal name="PropertyChanged">
<arg name="name" type="s"/>
<arg name="value" type="v"/>
</signal>
<property name="State" type="s" access="read"/>
<property name="Error" type="s" access="read"/>
<property name="AutoConnect" type="b" access="readwrite"/>
</interface>
</node>
......@@ -56,7 +56,6 @@ make %{?_smp_mflags}
%install
rm -rf %{buildroot}
%qmake5_install
chmod +x %{buildroot}/%{_bindir}/vpn-updown.sh
%post -p /sbin/ldconfig
......@@ -67,8 +66,6 @@ chmod +x %{buildroot}/%{_bindir}/vpn-updown.sh
%{_libdir}/qt5/qml/org/nemomobile/systemsettings/libnemosystemsettings.so
%{_libdir}/qt5/qml/org/nemomobile/systemsettings/qmldir
%{_libdir}/libsystemsettings.so.*
%{_libdir}/systemd/user/vpn-updown.service
%{_bindir}/vpn-updown.sh
%dir %attr(0775, root, privileged) /etc/location
%config %attr(0664, root, privileged) /etc/location/location.conf
......
/*
* Copyright (C) 2018 Jolla Ltd. <raine.makelainen@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#include "logging_p.h"
Q_LOGGING_CATEGORY(lcVpnLog, "org.sailfishos.settings.vpn", QtWarningMsg)
/*
* Copyright (C) 2018 Jolla Ltd. <raine.makelainen@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef SETTINGS_LOGGING_H
#define SETTINGS_LOGGING_H
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(lcVpnLog)
#endif
......@@ -12,9 +12,11 @@ PKGCONFIG += ssu-sysinfo nemodbus
system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml)
system(qdbusxml2cpp -c ConnmanVpnProxy -p connmanvpnproxy ../dbus/net.connman.vpn.xml -i qdbusxml2cpp_dbus_types.h)
system(qdbusxml2cpp -c ConnmanVpnConnectionProxy -p connmanvpnconnectionproxy ../dbus/net.connman.vpn.Connection.xml -i qdbusxml2cpp_dbus_types.h)
system(qdbusxml2cpp -c ConnmanServiceProxy -p connmanserviceproxy ../dbus/net.connman.service.xml -i qdbusxml2cpp_dbus_types.h)
SOURCES += \
languagemodel.cpp \
logging.cpp \
datetimesettings.cpp \
profilecontrol.cpp \
alarmtonemodel.cpp \
......@@ -23,6 +25,7 @@ SOURCES += \
aboutsettings.cpp \
certificatemodel.cpp \
vpnmodel.cpp \
connmanserviceproxy.cpp \
connmanvpnproxy.cpp \
connmanvpnconnectionproxy.cpp \
developermodesettings.cpp \
......@@ -48,6 +51,7 @@ PUBLIC_HEADERS = \
aboutsettings.h \
certificatemodel.h \
vpnmodel.h \
connmanserviceproxy.h \
connmanvpnproxy.h \
connmanvpnconnectionproxy.h \
developermodesettings.h \
......@@ -67,6 +71,7 @@ HEADERS += \
batterystatus_p.h \
diskusage_p.h \
locationsettings_p.h \
logging_p.h \
partition_p.h \
partitionmanager_p.h \
udisks2defines.h \
......@@ -86,12 +91,6 @@ pkgconfig.path = $$target.path/pkgconfig
locationconfig.files = $$PWD/location.conf
locationconfig.path = /etc/location
scripts.path = /usr/bin/
scripts.files = vpn-updown.sh
servicefiles.path = /usr/lib/systemd/user/
servicefiles.files = vpn-updown.service
QMAKE_PKGCONFIG_NAME = lib$$TARGET
QMAKE_PKGCONFIG_VERSION = $$VERSION
QMAKE_PKGCONFIG_DESCRIPTION = System settings application development files
......@@ -100,4 +99,4 @@ QMAKE_PKGCONFIG_INCDIR = $$develheaders.path
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
QMAKE_PKGCONFIG_REQUIRES = Qt5Core Qt5DBus profile nemomodels-qt5 libsailfishkeyprovider connman-qt5
INSTALLS += target develheaders pkgconfig scripts servicefiles locationconfig
INSTALLS += target develheaders pkgconfig locationconfig
[Unit]
Description=Automatic up/down for configured VPN connections
[Service]
Type=oneshot
ExecStart=/usr/bin/vpn-updown.sh up
ExecStop=/usr/bin/vpn-updown.sh down
RemainAfterExit=yes
#!/bin/sh
if [ $# -lt 1 ]; then
echo "Usage: $0 up|down"
exit 1
fi
METHOD=
if [ "$1" = "up" ]; then
METHOD=net.connman.vpn.Connection.Connect
elif [ "$1" = "down" ]; then
METHOD=net.connman.vpn.Connection.Disconnect
else
echo "Usage: $0 up|down"
exit 2
fi
logger "$0 $1"
for FILE in $(find /home/nemo/.local/share/system/vpn -mindepth 1 -maxdepth 1); do
TOKEN=$(basename $FILE)
OBJECTPATH=/net/connman/vpn/connection/$TOKEN
/bin/dbus-send --system --dest=net.connman.vpn --print-reply $OBJECTPATH $METHOD
logger "Invoked $METHOD for $OBJECTPATH"
done
exit 0
This diff is collapsed.
......@@ -34,22 +34,21 @@
#define VPNMODEL_H
#include "connmanvpnproxy.h"
#include "connmanvpnconnectionproxy.h"
#include <systemsettingsglobal.h>
#include <objectlistmodel.h>
#include <QDir>
#include <QVariantMap>
class ConnmanServiceProxy;
class ConnmanVpnConnectionProxy;
class SYSTEMSETTINGS_EXPORT VpnConnection;
class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
{
Q_OBJECT
Q_ENUMS(ConnectionState)
Q_PROPERTY(int bestState READ bestState NOTIFY bestStateChanged)
......@@ -61,6 +60,7 @@ public:
Ready,
Disconnect,
};
Q_ENUM(ConnectionState)
explicit VpnModel(QObject *parent = 0);
virtual ~VpnModel();
......@@ -92,6 +92,9 @@ signals:
void bestStateChanged();
void connectionStateChanged(const QString &path, int state);
private slots:
void updatePendingDisconnectState();
private:
void fetchVpnList();
......@@ -142,6 +145,9 @@ private:
ConnmanVpnProxy connmanVpn_;
QHash<QString, ConnmanVpnConnectionProxy *> connections_;
QHash<QString, ConnmanServiceProxy *> vpnServices_;
QMap<QString, VpnConnection*> pendingDisconnects_;
QString pendingConnect_;
TokenFileRepository tokenFiles_;
CredentialsRepository credentials_;
ConnectionState bestState_;
......@@ -155,6 +161,7 @@ class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)
Q_PROPERTY(QString networks READ networks WRITE setNetworks NOTIFY networksChanged)
Q_PROPERTY(bool autoConnect READ autoConnect WRITE setAutoConnect NOTIFY autoConnectChanged)
Q_PROPERTY(bool automaticUpDown READ automaticUpDown WRITE setAutomaticUpDown NOTIFY automaticUpDownChanged)
Q_PROPERTY(bool storeCredentials READ storeCredentials WRITE setStoreCredentials NOTIFY storeCredentialsChanged)
Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)
......@@ -185,6 +192,9 @@ public:
QString networks() const { return networks_; }
void setNetworks(const QString &networks) { updateMember(&VpnConnection::networks_, networks, &VpnConnection::networksChanged); }
bool autoConnect() const { return autoConnect_; }
void setAutoConnect(bool autoConnect) { updateMember(&VpnConnection::autoConnect_, autoConnect, &VpnConnection::autoConnectChanged); }
bool automaticUpDown() const { return automaticUpDown_; }
void setAutomaticUpDown(bool automaticUpDown) { updateMember(&VpnConnection::automaticUpDown_, automaticUpDown, &VpnConnection::automaticUpDownChanged); }
......@@ -228,6 +238,7 @@ signals:
void hostChanged();
void domainChanged();
void networksChanged();
void autoConnectChanged();
void automaticUpDownChanged();
void storeCredentialsChanged();
void immutableChanged();
......@@ -257,6 +268,7 @@ private:
QString host_;
QString domain_;
QString networks_;
bool autoConnect_;
bool automaticUpDown_;
bool storeCredentials_;
bool immutable_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment