diff --git a/actors/linux/debian/control b/actors/linux/debian/control index cb7af4d4..6c65d7a8 100644 --- a/actors/linux/debian/control +++ b/actors/linux/debian/control @@ -10,7 +10,7 @@ Package: udsactor Section: admin Priority: optional Architecture: all -Depends: policykit-1(>=0.100), python-requests (>=0.8.2), python-qt4 (>=4.9), python-six(>=1.1), python-prctl(>=1.1.1), python (>=2.7), ${misc:Depends} +Depends: policykit-1(>=0.100), python-requests (>=0.8.2), python-qt4 (>=4.9), python-six(>=1.1), python-prctl(>=1.1.1), python (>=2.7), libxss1, ${misc:Depends} Description: Actor for Universal Desktop Services (UDS) Broker This package provides the required components to allow this machine to work on an environment managed by UDS Broker. diff --git a/actors/src/udsactor/linux/CheckSystray.py b/actors/src/udsactor/linux/CheckSystray.py deleted file mode 100644 index 25658c8d..00000000 --- a/actors/src/udsactor/linux/CheckSystray.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/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) diff --git a/actors/src/udsactor/linux/operations.py b/actors/src/udsactor/linux/operations.py index fadfff3c..60766cfa 100644 --- a/actors/src/udsactor/linux/operations.py +++ b/actors/src/udsactor/linux/operations.py @@ -35,10 +35,13 @@ import socket import platform import fcntl import os +import ctypes +import ctypes.util import struct import array import six from udsactor import utils +from .renamer import rename def _getMacAddr(ifname): @@ -143,7 +146,7 @@ def loggoff(): def renameComputer(newName): - pass + rename(newName) def joinDomain(domain, ou, account, password, executeInOneStep=False): @@ -157,5 +160,46 @@ def changeUserPassword(user, oldPassword, newPassword): os.system('echo "{1}\n{1}" | /usr/bin/passwd {0} 2> /dev/null'.format(user, newPassword)) +class XScreenSaverInfo(ctypes.Structure): + _fields_ = [('window', ctypes.c_long), + ('state', ctypes.c_int), + ('kind', ctypes.c_int), + ('til_or_since', ctypes.c_ulong), + ('idle', ctypes.c_ulong), + ('eventMask', ctypes.c_ulong)] + +# Initialize xlib & xss +try: + xlibPath = ctypes.util.find_library('X11') + xssPath = ctypes.util.find_library('Xss') + xlib = ctypes.cdll.LoadLibrary(xlibPath) + xss = ctypes.cdll.LoadLibrary(xssPath) + + # Fix result type to XScreenSaverInfo Structure + xss.XScreenSaverQueryExtension.restype = ctypes.c_int + xss.XScreenSaverAllocInfo.restype = ctypes.POINTER(XScreenSaverInfo) # Result in a XScreenSaverInfo structure + +except Exception: # Libraries not accesible, not found or whatever.. + xlib = xss = None + + def getIdleDuration(): - return 0 + ''' + Returns idle duration, in seconds + ''' + if xlib is None or xss is None: + return 0 # Libraries not available + + # production code might want to not hardcode the offset 16... + display = xlib.XOpenDisplay(None) + + event_base = ctypes.c_int() + error_base = ctypes.c_int() + + available = xss.XScreenSaverQueryExtension(display, ctypes.byref(event_base), ctypes.byref(error_base)) + if available != 1: + return 0 + + info = xss.XScreenSaverAllocInfo() + xss.XScreenSaverQueryInfo(display, xlib.XDefaultRootWindow(display), info) + return info.contents.idle / 1000.0