mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-11 05:17:55 +03:00
Removed SENS from uds actor 3.0. Not needed
This commit is contained in:
parent
668c26dd8f
commit
4e3dce37f7
@ -35,6 +35,7 @@ import os
|
||||
|
||||
import PyQt5 # pylint: disable=unused-import
|
||||
from PyQt5.QtCore import QTimer
|
||||
from PyQt5.QtWidgets import QMainWindow
|
||||
|
||||
from udsactor.log import logger, INFO
|
||||
from udsactor.client import UDSClientQApp
|
||||
@ -53,9 +54,16 @@ if __name__ == "__main__":
|
||||
|
||||
qApp = UDSClientQApp(sys.argv)
|
||||
|
||||
if 'linux' not in sys.platform:
|
||||
# The "hidden window" is only needed to process events on Windows
|
||||
# Not needed on Linux
|
||||
mw = QMainWindow()
|
||||
mw.showMinimized() # Start minimized, will be hidden (not destroyed) as soon as qApp.init is invoked
|
||||
qApp.setMainWindow(mw)
|
||||
|
||||
qApp.init()
|
||||
|
||||
# Crate a timer, so we can check signals from time to time by executing python interpreter
|
||||
# Crate a timer to a "dummy" function, so python can check signals from time to time by executing the python interpreter
|
||||
# Note: Signals are only checked on python code execution, so we create a timer to force call back to python
|
||||
timer = QTimer(qApp)
|
||||
timer.start(1000)
|
||||
@ -63,7 +71,7 @@ if __name__ == "__main__":
|
||||
|
||||
qApp.exec_()
|
||||
|
||||
# On windows, this point will never be reached :)
|
||||
# On windows, if no window is created, this point will never be reached.
|
||||
qApp.end()
|
||||
|
||||
logger.debug('Exiting...')
|
||||
|
@ -34,7 +34,7 @@ import datetime
|
||||
import signal
|
||||
import typing
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QMessageBox
|
||||
from PyQt5.QtWidgets import QApplication, QMessageBox, QMainWindow
|
||||
from PyQt5.QtCore import QByteArray, QBuffer, QIODevice, pyqtSignal
|
||||
|
||||
from . import rest
|
||||
@ -53,14 +53,19 @@ if typing.TYPE_CHECKING:
|
||||
class UDSClientQApp(QApplication):
|
||||
_app: 'UDSActorClient'
|
||||
_initialized: bool
|
||||
_mainWindow: typing.Optional['QMainWindow']
|
||||
|
||||
message = pyqtSignal(str, name='message')
|
||||
|
||||
def __init__(self, args) -> None:
|
||||
super().__init__(args)
|
||||
|
||||
self._mainWindow = None
|
||||
self._initialized = False
|
||||
|
||||
# This will be invoked on session close
|
||||
self.commitDataRequest.connect(self.end) # Will be invoked on session close, to gracely close app
|
||||
# self.aboutToQuit.connect(self.end)
|
||||
self.message.connect(self.showMessage)
|
||||
|
||||
# Execute backgroup thread for actions
|
||||
@ -69,6 +74,10 @@ class UDSClientQApp(QApplication):
|
||||
def init(self) -> None:
|
||||
# Notify loging and mark it
|
||||
logger.debug('Starting APP')
|
||||
|
||||
if self._mainWindow:
|
||||
self._mainWindow.hide()
|
||||
|
||||
self._app.start()
|
||||
self._initialized = True
|
||||
|
||||
@ -86,6 +95,9 @@ class UDSClientQApp(QApplication):
|
||||
def showMessage(self, message: str) -> None:
|
||||
QMessageBox.information(None, 'Message', message)
|
||||
|
||||
def setMainWindow(self, mw: 'QMainWindow'):
|
||||
self._mainWindow = mw
|
||||
|
||||
|
||||
class UDSActorClient(threading.Thread): # pylint: disable=too-many-instance-attributes
|
||||
_running: bool
|
||||
@ -176,12 +188,12 @@ class UDSActorClient(threading.Thread): # pylint: disable=too-many-instance-att
|
||||
platform.operations.initIdleDuration(self._loginInfo.max_idle)
|
||||
|
||||
while self._running:
|
||||
time.sleep(1.3) # Sleeps between loop iterations
|
||||
|
||||
# Check Idle & dead line
|
||||
self.checkIdle()
|
||||
self.checkDeadLine()
|
||||
|
||||
time.sleep(1.3) # Sleeps between loop iterations
|
||||
|
||||
self._loginInfo = None
|
||||
self.api.logout(platform.operations.getCurrentUser() + self._extraLogoff)
|
||||
except Exception as e:
|
||||
|
@ -1,129 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2014-2019 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
|
||||
'''
|
||||
import typing
|
||||
|
||||
import win32com.client # @UnresolvedImport, pylint: disable=import-error
|
||||
import win32com.server.policy # @UnresolvedImport, pylint: disable=import-error
|
||||
|
||||
from ..log import logger
|
||||
|
||||
# based on python SENS example from
|
||||
# http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html
|
||||
|
||||
# from Sens.h
|
||||
SENSGUID_PUBLISHER = "{5fee1bd6-5b9b-11d1-8dd2-00aa004abd5e}"
|
||||
SENSGUID_EVENTCLASS_LOGON = "{d5978630-5b9f-11d1-8dd2-00aa004abd5e}"
|
||||
|
||||
# from EventSys.h
|
||||
PROGID_EventSystem = "EventSystem.EventSystem"
|
||||
PROGID_EventSubscription = "EventSystem.EventSubscription"
|
||||
|
||||
IID_ISensLogon = "{d597bab3-5b9f-11d1-8dd2-00aa004abd5e}"
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from ..service import CommonService
|
||||
|
||||
class SensLogon(win32com.server.policy.DesignatedWrapPolicy):
|
||||
_com_interfaces_ = [IID_ISensLogon]
|
||||
_public_methods_ = [
|
||||
'Logon',
|
||||
'Logoff',
|
||||
'StartShell',
|
||||
'DisplayLock',
|
||||
'DisplayUnlock',
|
||||
'StartScreenSaver',
|
||||
'StopScreenSaver'
|
||||
]
|
||||
|
||||
_service: 'CommonService'
|
||||
|
||||
def __init__(self, service: 'CommonService'): # pylint: disable=super-init-not-called
|
||||
self._wrap_(self)
|
||||
self._service = service
|
||||
|
||||
def Logon(self, *args):
|
||||
self._service.login(args[0] or '')
|
||||
logger.debug('Logon event: {}'.format(args))
|
||||
|
||||
def Logoff(self, *args):
|
||||
logger.debug('Logoff event: arguments: {}'.format(args))
|
||||
self._service.logout(args[0] or '')
|
||||
|
||||
def StartShell(self, *args):
|
||||
# logevent('StartShell : %s' % [args])
|
||||
pass
|
||||
|
||||
def DisplayLock(self, *args):
|
||||
# logevent('DisplayLock : %s' % [args])
|
||||
pass
|
||||
|
||||
def DisplayUnlock(self, *args):
|
||||
# logevent('DisplayUnlock : %s' % [args])
|
||||
pass
|
||||
|
||||
def StartScreenSaver(self, *args):
|
||||
# When finished basic actor, we will use this to provide a new parameter: logout on screensaver
|
||||
# This will allow to easily close sessions of idle users
|
||||
# logevent('StartScreenSaver : %s' % [args])
|
||||
pass
|
||||
|
||||
def StopScreenSaver(self, *args):
|
||||
# logevent('StopScreenSaver : %s' % [args])
|
||||
pass
|
||||
|
||||
|
||||
def logevent(msg):
|
||||
logger.debug(msg)
|
||||
|
||||
# def register():
|
||||
# call the CoInitialize to allow the registration to run in an other
|
||||
# thread
|
||||
# pythoncom.CoInitialize()
|
||||
|
||||
# logevent('Registring ISensLogon')
|
||||
|
||||
# sl=SensLogon()
|
||||
# subscription_interface=pythoncom.WrapObject(sl)
|
||||
|
||||
# event_system=win32com.client.Dispatch(PROGID_EventSystem)
|
||||
|
||||
# event_subscription=win32com.client.Dispatch(PROGID_EventSubscription)
|
||||
# event_subscription.EventClassID=SENSGUID_EVENTCLASS_LOGON
|
||||
# event_subscription.PublisherID=SENSGUID_PUBLISHER
|
||||
# event_subscription.SubscriptionName='Python subscription'
|
||||
# event_subscription.SubscriberInterface=subscription_interface
|
||||
|
||||
# event_system.Store(PROGID_EventSubscription, event_subscription)
|
||||
|
||||
# pythoncom.PumpMessages()
|
||||
# #logevent('ISensLogon stopped')
|
@ -37,7 +37,6 @@ import win32service
|
||||
import win32security
|
||||
import win32net
|
||||
import win32event
|
||||
import win32com.client
|
||||
import pythoncom
|
||||
import servicemanager
|
||||
|
||||
@ -47,13 +46,6 @@ from ..service import CommonService
|
||||
|
||||
from ..log import logger
|
||||
|
||||
from .SENS import SensLogon
|
||||
# from .SENS import logevent
|
||||
from .SENS import SENSGUID_EVENTCLASS_LOGON
|
||||
from .SENS import SENSGUID_PUBLISHER
|
||||
from .SENS import PROGID_EventSubscription
|
||||
from .SENS import PROGID_EventSystem
|
||||
|
||||
REMOTE_USERS_SID = 'S-1-5-32-555' # Well nown sid for remote desktop users
|
||||
|
||||
class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
||||
@ -65,8 +57,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
||||
_svc_name_ = "UDSActorNG"
|
||||
_svc_display_name_ = "UDS Actor Service"
|
||||
_svc_description_ = "UDS Actor Management Service"
|
||||
# 'System Event Notification' is the SENS service
|
||||
_svc_deps_ = ['EventLog', 'SENS']
|
||||
_svc_deps_ = ['EventLog']
|
||||
|
||||
_user: typing.Optional[str]
|
||||
_hWaitStop: typing.Any
|
||||
@ -236,28 +227,6 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
||||
# Start listening for petitions
|
||||
self.startHttpServer()
|
||||
|
||||
# # ********************************
|
||||
# # * Registers SENS subscriptions *
|
||||
# # ********************************
|
||||
logger.debug('Registering isens logon')
|
||||
subscription_guid = '{41099152-498E-11E4-8FD3-10FEED05884B}'
|
||||
sl = SensLogon(self)
|
||||
subscription_interface = pythoncom.WrapObject(sl) # pylint: disable=no-member
|
||||
|
||||
event_system = win32com.client.Dispatch(PROGID_EventSystem)
|
||||
|
||||
event_subscription = win32com.client.Dispatch(PROGID_EventSubscription)
|
||||
event_subscription.EventClassID = SENSGUID_EVENTCLASS_LOGON
|
||||
event_subscription.PublisherID = SENSGUID_PUBLISHER
|
||||
event_subscription.SubscriptionName = 'UDS Actor subscription'
|
||||
event_subscription.SubscriptionID = subscription_guid
|
||||
event_subscription.SubscriberInterface = subscription_interface
|
||||
|
||||
event_system.Store(PROGID_EventSubscription, event_subscription)
|
||||
|
||||
# logger.debug('Registered SENS')
|
||||
# logger.debug('Initialized, setting ready')
|
||||
|
||||
# *********************
|
||||
# * Main Service loop *
|
||||
# *********************
|
||||
@ -266,7 +235,6 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
||||
while self._isAlive:
|
||||
counter += 1
|
||||
try:
|
||||
# Process SENS messages, This will be a bit asyncronous (1 second delay)
|
||||
pythoncom.PumpWaitingMessages() # pylint: disable=no-member
|
||||
|
||||
if counter % 5 == 0: # Once every 5 seconds
|
||||
@ -279,11 +247,6 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
||||
# In milliseconds, will break if event hWaitStop is set
|
||||
win32event.WaitForSingleObject(self._hWaitStop, 1000)
|
||||
|
||||
logger.debug('Exited main loop, deregistering SENS')
|
||||
|
||||
# *******************************************
|
||||
# * Remove SENS subscription before exiting *
|
||||
# *******************************************
|
||||
event_system.Remove(PROGID_EventSubscription, "SubscriptionID == " + subscription_guid)
|
||||
logger.debug('Exited main loop')
|
||||
|
||||
self.finish()
|
||||
|
Loading…
Reference in New Issue
Block a user