mirror of
				https://github.com/arcan1s/netctl-gui.git
				synced 2025-11-04 07:23:40 +00:00 
			
		
		
		
	some improvements in helper and gui APIs and replacement and restoring
sessions
This commit is contained in:
		@ -58,7 +58,7 @@ th.sub {
 | 
			
		||||
  <!-- helper actions -->
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>bool Active()</td>
 | 
			
		||||
    <td><code>true</code> if helper is active</td>
 | 
			
		||||
    <td><code>true</code> if the helper is active</td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
@ -91,9 +91,14 @@ th.sub {
 | 
			
		||||
    <td>current helper settings <code>KEY==VALUE</code></td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>QStringList UIDs()</td>
 | 
			
		||||
    <td>returns the helper process UIDs <code>[UID, EUID]</code></td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>bool Update()</td>
 | 
			
		||||
    <td>calls update helper configuration. Returns <code>true</code></td>
 | 
			
		||||
    <td>calls update the helper configuration. Returns <code>true</code></td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <!-- netctl actions -->
 | 
			
		||||
@ -257,6 +262,11 @@ th.sub {
 | 
			
		||||
    <th colspan="3" class="sub"><a href="#netctlgui" class="anchor" name="netctlgui"></a><code>/netctlgui</code> path</th>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <!-- gui actions -->
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>bool Active()</td>
 | 
			
		||||
    <td><code>true</code> if the application is active</td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>void ApiDocs()</td>
 | 
			
		||||
    <td>opens this API documentation</td>
 | 
			
		||||
@ -269,7 +279,7 @@ th.sub {
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>QString Information()</td>
 | 
			
		||||
    <td>the same as <code>org.netctlgui.helper /netctl Information</code></td>
 | 
			
		||||
    <td>returns general information in format <code>[ActiveProfile, ActiveProfileStatus]</code></td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
@ -317,11 +327,15 @@ th.sub {
 | 
			
		||||
    <td><code>true</code> and shows settings window</td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>QStringList UIDs()</td>
 | 
			
		||||
    <td>returns the application process UIDs <code>[UID, EUID]</code></td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>QStringList VerboseInformation()</td>
 | 
			
		||||
    <td>returns information in format <code>[isNetctlAutoActive, ProfileList, ActiveProfile, isProfileEnabled/autoIsProfileEnabled]</code></td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
    <td>no</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -34,11 +34,11 @@
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool restoreExistSession()
 | 
			
		||||
bool existingSessionOperation(const QString operation)
 | 
			
		||||
{
 | 
			
		||||
    QDBusConnection bus = QDBusConnection::sessionBus();
 | 
			
		||||
    QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, DBUS_OBJECT_PATH,
 | 
			
		||||
                                                          DBUS_INTERFACE, QString("Restore"));
 | 
			
		||||
                                                          DBUS_INTERFACE, operation);
 | 
			
		||||
    QDBusMessage response = bus.call(request);
 | 
			
		||||
    QList<QVariant> arguments = response.arguments();
 | 
			
		||||
 | 
			
		||||
@ -46,6 +46,18 @@ bool restoreExistSession()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
unsigned int getUidFromSession(const int type = 0)
 | 
			
		||||
{
 | 
			
		||||
    QDBusConnection bus = QDBusConnection::sessionBus();
 | 
			
		||||
    QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, DBUS_OBJECT_PATH,
 | 
			
		||||
                                                          DBUS_INTERFACE, QString("UIDs"));
 | 
			
		||||
    QDBusMessage response = bus.call(request);
 | 
			
		||||
    QList<QVariant> arguments = response.arguments();
 | 
			
		||||
 | 
			
		||||
    return arguments[0].toStringList()[type].toUInt();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    QMap<QString, QVariant> args = getArgs();
 | 
			
		||||
@ -164,8 +176,20 @@ int main(int argc, char *argv[])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // check if exists
 | 
			
		||||
    if (restoreExistSession())
 | 
			
		||||
        return 0;
 | 
			
		||||
    if (existingSessionOperation(QString("Active"))) {
 | 
			
		||||
        if ((getuid() == getUidFromSession(0)) && (geteuid() == getUidFromSession(1))) {
 | 
			
		||||
            // restore session
 | 
			
		||||
            cout << QCoreApplication::translate("MainWindow", "Restore existing session.")
 | 
			
		||||
                    .toUtf8().data() << endl;
 | 
			
		||||
            existingSessionOperation(QString("Restore"));
 | 
			
		||||
            return 0;
 | 
			
		||||
        } else if ((getuid() == getUidFromSession(0)) && (geteuid() != getUidFromSession(1))) {
 | 
			
		||||
            cout << QCoreApplication::translate("MainWindow", "Close existing session.")
 | 
			
		||||
                    .toUtf8().data() << endl;
 | 
			
		||||
            existingSessionOperation(QString("Restore"));
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    MainWindow w(0, args, &qtTranslator, &translator);
 | 
			
		||||
    return a.exec();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@
 | 
			
		||||
#include "netctlguiadaptor.h"
 | 
			
		||||
 | 
			
		||||
#include <QTextCodec>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include "mainwindow.h"
 | 
			
		||||
 | 
			
		||||
@ -34,6 +35,12 @@ NetctlGuiAdaptor::~NetctlGuiAdaptor()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool NetctlGuiAdaptor::Active()
 | 
			
		||||
{
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void NetctlGuiAdaptor::ApiDocs()
 | 
			
		||||
{
 | 
			
		||||
    return mainWindow->showApi();
 | 
			
		||||
@ -119,6 +126,16 @@ bool NetctlGuiAdaptor::ShowSettings()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QStringList NetctlGuiAdaptor::UIDs()
 | 
			
		||||
{
 | 
			
		||||
    QStringList uids;
 | 
			
		||||
    uids.append(QString::number(getuid()));
 | 
			
		||||
    uids.append(QString::number(geteuid()));
 | 
			
		||||
 | 
			
		||||
    return uids;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QStringList NetctlGuiAdaptor::VerboseInformation()
 | 
			
		||||
{
 | 
			
		||||
    return mainWindow->printTrayInformation();
 | 
			
		||||
 | 
			
		||||
@ -34,6 +34,7 @@ public:
 | 
			
		||||
    ~NetctlGuiAdaptor();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    bool Active();
 | 
			
		||||
    void ApiDocs();
 | 
			
		||||
    bool Close();
 | 
			
		||||
    QStringList Information();
 | 
			
		||||
@ -46,6 +47,7 @@ public slots:
 | 
			
		||||
    bool ShowMain();
 | 
			
		||||
    bool ShowNetctlAuto();
 | 
			
		||||
    bool ShowSettings();
 | 
			
		||||
    QStringList UIDs();
 | 
			
		||||
    QStringList VerboseInformation();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
@ -18,11 +18,13 @@
 | 
			
		||||
 | 
			
		||||
# variables
 | 
			
		||||
_netctlgui_helper_arglist=(
 | 
			
		||||
    '--nodaemon'
 | 
			
		||||
    '-c'
 | 
			
		||||
    '--config'
 | 
			
		||||
    '-d'
 | 
			
		||||
    '--debug'
 | 
			
		||||
    '--nodaemon'
 | 
			
		||||
    '--replace'
 | 
			
		||||
    '--restore'
 | 
			
		||||
    '-v'
 | 
			
		||||
    '--version'
 | 
			
		||||
    '-i'
 | 
			
		||||
 | 
			
		||||
@ -11,13 +11,17 @@ is a Qt based helper daemon which provides a DBus interface for interaction with
 | 
			
		||||
without any additional permissions. To have access to DBus interface user should have group
 | 
			
		||||
.B network
 | 
			
		||||
.SH OPTIONS
 | 
			
		||||
.IP "--nodaemon"
 | 
			
		||||
do not run as daemon
 | 
			
		||||
.IP "-c, --config FILE"
 | 
			
		||||
read configuration from file
 | 
			
		||||
.I FILE
 | 
			
		||||
.IP "-d, --debug"
 | 
			
		||||
print debug information
 | 
			
		||||
.IP "--nodaemon"
 | 
			
		||||
do not run as daemon
 | 
			
		||||
.IP "--replace"
 | 
			
		||||
force replace the existing session
 | 
			
		||||
.IP "--restore"
 | 
			
		||||
force restore the existing session
 | 
			
		||||
.IP "-v, --version"
 | 
			
		||||
show version and exit
 | 
			
		||||
.IP "-i, --info"
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@
 | 
			
		||||
#include "controladaptor.h"
 | 
			
		||||
 | 
			
		||||
#include <QTextCodec>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include "netctlhelper.h"
 | 
			
		||||
#include "version.h"
 | 
			
		||||
@ -93,6 +94,16 @@ QStringList ControlAdaptor::Settings()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QStringList ControlAdaptor::UIDs()
 | 
			
		||||
{
 | 
			
		||||
    QStringList uids;
 | 
			
		||||
    uids.append(QString::number(getuid()));
 | 
			
		||||
    uids.append(QString::number(geteuid()));
 | 
			
		||||
 | 
			
		||||
    return uids;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool ControlAdaptor::Update()
 | 
			
		||||
{
 | 
			
		||||
    helper->updateConfiguration();
 | 
			
		||||
 | 
			
		||||
@ -44,6 +44,7 @@ public slots:
 | 
			
		||||
    QString Pony();
 | 
			
		||||
    QString SecurityDocs();
 | 
			
		||||
    QStringList Settings();
 | 
			
		||||
    QStringList UIDs();
 | 
			
		||||
    bool Update();
 | 
			
		||||
    // netctlCommand
 | 
			
		||||
    bool autoDisableAll();
 | 
			
		||||
 | 
			
		||||
@ -34,13 +34,14 @@
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool checkExistSession()
 | 
			
		||||
bool existingSessionOperation(const QString operation)
 | 
			
		||||
{
 | 
			
		||||
    QDBusConnection bus = QDBusConnection::systemBus();
 | 
			
		||||
    QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
 | 
			
		||||
                                                          DBUS_HELPER_INTERFACE, QString("Active"));
 | 
			
		||||
                                                          DBUS_HELPER_INTERFACE, operation);
 | 
			
		||||
    QDBusMessage response = bus.call(request);
 | 
			
		||||
    QList<QVariant> arguments = response.arguments();
 | 
			
		||||
 | 
			
		||||
    return !arguments.isEmpty();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -60,6 +61,12 @@ int main(int argc, char *argv[])
 | 
			
		||||
        } else if (QString(argv[i]) == QString("--nodaemon")) {
 | 
			
		||||
            // daemonized
 | 
			
		||||
            args[QString("nodaemon")] = true;
 | 
			
		||||
        } else if (QString(argv[i]) == QString("--replace")) {
 | 
			
		||||
            // replace
 | 
			
		||||
            args[QString("state")] = (int) 1;
 | 
			
		||||
        } else if (QString(argv[i]) == QString("--restore")) {
 | 
			
		||||
            // restore
 | 
			
		||||
            args[QString("state")] = (int) 2;
 | 
			
		||||
        } else if ((QString(argv[i]) == QString("-h")) || (QString(argv[i]) == QString("--help"))) {
 | 
			
		||||
            // help message
 | 
			
		||||
            args[QString("help")] = true;
 | 
			
		||||
@ -119,8 +126,31 @@ int main(int argc, char *argv[])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // check if exists
 | 
			
		||||
    if (checkExistSession())
 | 
			
		||||
        return 0;
 | 
			
		||||
    if (existingSessionOperation(QString("Active"))) {
 | 
			
		||||
        if (args[QString("state")].toInt() == 1) {
 | 
			
		||||
            // replace session
 | 
			
		||||
            cout << QCoreApplication::translate("NetctlHelper", "Replace existing session.")
 | 
			
		||||
                    .toUtf8().data() << endl;
 | 
			
		||||
            existingSessionOperation(QString("Close"));
 | 
			
		||||
        } else if (args[QString("state")].toInt() == 2) {
 | 
			
		||||
            // restore session
 | 
			
		||||
            cout << QCoreApplication::translate("NetctlHelper", "Restore existing session.")
 | 
			
		||||
                    .toUtf8().data() << endl;
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else if (geteuid() == 0) {
 | 
			
		||||
            // replace if running as root
 | 
			
		||||
            cout << QCoreApplication::translate("NetctlHelper", "Replace existing session.")
 | 
			
		||||
                    .toUtf8().data() << endl;
 | 
			
		||||
            existingSessionOperation(QString("Close"));
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            // restore if running as non-root
 | 
			
		||||
            cout << QCoreApplication::translate("NetctlHelper", "Restore existing session.")
 | 
			
		||||
                    .toUtf8().data() << endl;
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    NetctlHelper w(0, args);
 | 
			
		||||
    return a.exec();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -37,6 +37,7 @@ QMap<QString, QVariant> getArgs()
 | 
			
		||||
    args[QString("config")] = QString(QDir::homePath() + QString("/.config/netctl-gui.conf"));
 | 
			
		||||
    args[QString("debug")] = false;
 | 
			
		||||
    args[QString("nodaemon")] = false;
 | 
			
		||||
    args[QString("state")] = (int) 0;
 | 
			
		||||
    args[QString("help")] = false;
 | 
			
		||||
    args[QString("info")] = false;
 | 
			
		||||
    args[QString("version")] = false;
 | 
			
		||||
@ -59,6 +60,10 @@ QString helpMessage()
 | 
			
		||||
            .arg(QCoreApplication::translate("NetctlHelper", "print debug information"));
 | 
			
		||||
    helpMessage += QString("       --nodaemon        - %1\n")
 | 
			
		||||
            .arg(QCoreApplication::translate("NetctlHelper", "do not start as daemon"));
 | 
			
		||||
    helpMessage += QString("       --replace         - %1\n")
 | 
			
		||||
            .arg(QCoreApplication::translate("NetctlHelper", "force replace the existing session"));
 | 
			
		||||
    helpMessage += QString("       --restore         - %1\n")
 | 
			
		||||
            .arg(QCoreApplication::translate("NetctlHelper", "force restore the existing session"));
 | 
			
		||||
    helpMessage += QString(" %1\n").arg(QCoreApplication::translate("NetctlHelper", "Show messages:"));
 | 
			
		||||
    helpMessage += QString("   -v, --version         - %1\n")
 | 
			
		||||
            .arg(QCoreApplication::translate("NetctlHelper", "show version and exit"));
 | 
			
		||||
 | 
			
		||||
@ -19,9 +19,11 @@
 | 
			
		||||
 | 
			
		||||
# variables
 | 
			
		||||
_netctlgui_helper_arglist=(
 | 
			
		||||
    {'--nodaemon','--nodaemon'}'[do not start as daemon]'
 | 
			
		||||
    {'(--config)-c','(-c)--config'}'[read configuration from this file]:select file:->files'
 | 
			
		||||
    {'(--debug)-d','(-d)--debug'}'[print debug information]'
 | 
			
		||||
    {'--nodaemon','--nodaemon'}'[do not start as daemon]'
 | 
			
		||||
    {'--replace','--replace'}'[force replace the existing session]'
 | 
			
		||||
    {'--restore','--restore'}'[force restore the existing session]'
 | 
			
		||||
    {'(--version)-v','(-v)--version'}'[show version and exit]'
 | 
			
		||||
    {'(--info)-i','(-i)--info'}'[show build information and exit]'
 | 
			
		||||
    {'(--help)-h','(-h)--help'}'[show help and exit]'
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user