From 58e77aa4f3953bceb8efb503dce77cb02b24e468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Wed, 19 Nov 2014 06:48:52 +0100 Subject: [PATCH] Some more fixes to add UDS User space tool at session startup under gnome & kde (more tests to go) --- actors/linux/Makefile | 25 ++++++++-- actors/linux/desktop/UDSActorTool.desktop | 8 ++++ .../UDS_Actor_Configuration.desktop | 0 .../org.openuds.pkexec.UDSActorConfig.policy | 0 .../linux/{ => scripts}/UDSActorConfig-pkexec | 0 actors/linux/scripts/UDSActorTool-startup | 4 ++ actors/linux/{ => scripts}/udsactor | 0 actors/src/UDSActorUser.py | 6 +-- actors/src/udsactor/certs.py | 4 +- actors/src/udsactor/linux/CheckSystray.py | 46 +++++++++++++++++++ 10 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 actors/linux/desktop/UDSActorTool.desktop rename actors/linux/{ => desktop}/UDS_Actor_Configuration.desktop (100%) rename actors/linux/{ => policy}/org.openuds.pkexec.UDSActorConfig.policy (100%) rename actors/linux/{ => scripts}/UDSActorConfig-pkexec (100%) create mode 100644 actors/linux/scripts/UDSActorTool-startup rename actors/linux/{ => scripts}/udsactor (100%) create mode 100644 actors/src/udsactor/linux/CheckSystray.py diff --git a/actors/linux/Makefile b/actors/linux/Makefile index f8ffcdb1..712eaf07 100644 --- a/actors/linux/Makefile +++ b/actors/linux/Makefile @@ -1,6 +1,7 @@ #!/usr/bin/make -f # -*- makefile -*- +# Directories SOURCEDIR := ../src LIBDIR := $(DESTDIR)/usr/share/pyshared/UDSActor BINDIR := $(DESTDIR)/usr/bin @@ -8,6 +9,9 @@ SBINDIR = $(DESTDIR)/usr/sbin APPSDIR := $(DESTDIR)/usr/share/applications CFGDIR := $(DESTDIR)/etc/udsactor POLKITDIR := $(DESTDIR)/usr/share/polkit-1/actions/ +XDGAUTOSTARTDIR := $(DESTDIR)/etc/xdg/autostart +KDEAUTOSTARTDIR := $(DESTDIR)/usr/share/autostart + PYC := $(shell find $(SOURCEDIR) -name '*.py[co]') CACHES := $(shell find $(SOURCEDIR) -name '__pycache__') @@ -20,10 +24,14 @@ install: mkdir -p $(APPSDIR) mkdir -p $(CFGDIR) mkdir -p $(POLKITDIR) + mkdir -p $(XDGAUTOSTARTDIR) + mkdir -p $(KDEAUTOSTARTDIR) mkdir $(LIBDIR)/img + # Cleans up .pyc and cache folders rm -f $(PYC) $(CACHES) + cp -r $(SOURCEDIR)/udsactor $(LIBDIR)/udsactor cp $(SOURCEDIR)/img/uds.png $(LIBDIR)/img @@ -32,16 +40,23 @@ install: cp $(SOURCEDIR)/setup_dialog_ui.py $(LIBDIR) # Menu GUI app - cp UDS_Actor_Configuration.desktop $(APPSDIR) - # binaries - cp udsactor $(BINDIR) - cp UDSActorConfig-pkexec $(SBINDIR) + cp desktop/UDS_Actor_Configuration.desktop $(APPSDIR) + + # Autostart elements for gnome/kde + cp desktop/UDSActorTool.desktop $(XDGAUTOSTARTDIR) + cp desktop/UDSActorTool.desktop $(KDEAUTOSTARTDIR) + + # scripts + cp scripts/udsactor $(BINDIR) + cp scripts/UDSActorConfig-pkexec $(SBINDIR) + cp scripts/UDSActorTool-startup $(BINDIR) # Policy to run as administrator - cp org.openuds.pkexec.UDSActorConfig.policy $(POLKITDIR) + cp policy/org.openuds.pkexec.UDSActorConfig.policy $(POLKITDIR) # Fix permissions chmod 755 $(BINDIR)/udsactor + chmod 755 $(BINDIR)/UDSActorTool-startup chmod 755 $(LIBDIR)/UDSActorConfig.py chmod 755 $(LIBDIR)/UDSActorUser.py chmod 644 $(POLKITDIR)/org.openuds.pkexec.UDSActorConfig.policy diff --git a/actors/linux/desktop/UDSActorTool.desktop b/actors/linux/desktop/UDSActorTool.desktop new file mode 100644 index 00000000..57f2c1fb --- /dev/null +++ b/actors/linux/desktop/UDSActorTool.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=UDS Actor Tool +Comment=UDS Actor Userspace tools +Exec=/usr/bin/UDSActorTool-startup +Icon=/usr/share/pyshared/UDSActor/img/uds.png +Terminal=false +Type=Application +NoDisplay=true \ No newline at end of file diff --git a/actors/linux/UDS_Actor_Configuration.desktop b/actors/linux/desktop/UDS_Actor_Configuration.desktop similarity index 100% rename from actors/linux/UDS_Actor_Configuration.desktop rename to actors/linux/desktop/UDS_Actor_Configuration.desktop diff --git a/actors/linux/org.openuds.pkexec.UDSActorConfig.policy b/actors/linux/policy/org.openuds.pkexec.UDSActorConfig.policy similarity index 100% rename from actors/linux/org.openuds.pkexec.UDSActorConfig.policy rename to actors/linux/policy/org.openuds.pkexec.UDSActorConfig.policy diff --git a/actors/linux/UDSActorConfig-pkexec b/actors/linux/scripts/UDSActorConfig-pkexec similarity index 100% rename from actors/linux/UDSActorConfig-pkexec rename to actors/linux/scripts/UDSActorConfig-pkexec diff --git a/actors/linux/scripts/UDSActorTool-startup b/actors/linux/scripts/UDSActorTool-startup new file mode 100644 index 00000000..11cd14aa --- /dev/null +++ b/actors/linux/scripts/UDSActorTool-startup @@ -0,0 +1,4 @@ +#!/bin/sh + +sleep 5 +/usr/bin/UDSActorTool \ No newline at end of file diff --git a/actors/linux/udsactor b/actors/linux/scripts/udsactor similarity index 100% rename from actors/linux/udsactor rename to actors/linux/scripts/udsactor diff --git a/actors/src/UDSActorUser.py b/actors/src/UDSActorUser.py index f075432e..23c454f6 100644 --- a/actors/src/UDSActorUser.py +++ b/actors/src/UDSActorUser.py @@ -35,7 +35,7 @@ from __future__ import unicode_literals import sys from PyQt4 import QtGui from PyQt4 import QtCore -import cPickle +import pickle from udsactor import ipc from udsactor import utils from udsactor.log import logger @@ -88,7 +88,7 @@ class MessagesProcessor(QtCore.QThread): elif msgId == ipc.MSG_SCRIPT: self.script.emit(QtCore.QString.fromUtf8(data)) elif msgId == ipc.MSG_INFORMATION: - self.information.emit(cPickle.loads(data)) + self.information.emit(pickle.loads(data)) except Exception as e: try: logger.error('Got error on IPC thread {}'.format(utils.exceptionToMessage(e))) @@ -152,7 +152,7 @@ if __name__ == '__main__': app = QtGui.QApplication(sys.argv) if not QtGui.QSystemTrayIcon.isSystemTrayAvailable(): - QtGui.QMessageBox.critical(None, "Systray", "I couldn't detect any system tray on this system.") + # QtGui.QMessageBox.critical(None, "Systray", "I couldn't detect any system tray on this system.") sys.exit(1) trayIcon = UDSSystemTray(app) diff --git a/actors/src/udsactor/certs.py b/actors/src/udsactor/certs.py index d98dc8eb..14f7d814 100644 --- a/actors/src/udsactor/certs.py +++ b/actors/src/udsactor/certs.py @@ -35,6 +35,7 @@ from os.path import exists, join CERTFILE = 'UDSActor.pem' + def createSelfSignedCert(force=False): certFile = join(gettempdir(), CERTFILE) @@ -98,6 +99,3 @@ xtvM f.write(certData) return certFile - -# At beginning, force certificate creation -createSelfSignedCert(force=True) diff --git a/actors/src/udsactor/linux/CheckSystray.py b/actors/src/udsactor/linux/CheckSystray.py new file mode 100644 index 00000000..25658c8d --- /dev/null +++ b/actors/src/udsactor/linux/CheckSystray.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2014 Virtual Cable S.L. +# All rights reserved. +# +# 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 Virtual Cable S.L. 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 HOLDER 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. + +''' +@author: Adolfo Gómez, dkmaster at dkmon dot com +''' +from __future__ import unicode_literals + +import sys +from PyQt4 import QtGui + +# Simple systray checker +# On startup, if our user app will need systray to be present, so we may give some time +if __name__ == '__main__': + app = QtGui.QApplication(sys.argv) + + if not QtGui.QSystemTrayIcon.isSystemTrayAvailable(): + sys.exit(1) + + sys.exit(0)