mirror of
https://github.com/dkmstr/openuds.git
synced 2025-02-12 21:57:57 +03:00
working service with SENS
This commit is contained in:
parent
9451803ef7
commit
cde89f1839
89
windowsActor/SENS/__init__.py
Normal file
89
windowsActor/SENS/__init__.py
Normal file
@ -0,0 +1,89 @@
|
||||
# _*_ coding: iso-8859-1 _*_
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import servicemanager
|
||||
import win32com.client
|
||||
import win32com.server.policy
|
||||
import pythoncom
|
||||
|
||||
# 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}"
|
||||
|
||||
class SensLogon(win32com.server.policy.DesignatedWrapPolicy):
|
||||
_com_interfaces_=[IID_ISensLogon]
|
||||
_public_methods_=[
|
||||
'Logon',
|
||||
'Logoff',
|
||||
'StartShell',
|
||||
'DisplayLock',
|
||||
'DisplayUnlock',
|
||||
'StartScreenSaver',
|
||||
'StopScreenSaver'
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self._wrap_(self)
|
||||
|
||||
def Logon(self, *args):
|
||||
logevent('Logon : %s'%[args])
|
||||
|
||||
def Logoff(self, *args):
|
||||
logevent('Logoff : %s'%[args])
|
||||
|
||||
def StartShell(self, *args):
|
||||
logevent('StartShell : %s'%[args])
|
||||
|
||||
def DisplayLock(self, *args):
|
||||
logevent('DisplayLock : %s'%[args])
|
||||
|
||||
def DisplayUnlock(self, *args):
|
||||
logevent('DisplayUnlock : %s'%[args])
|
||||
|
||||
def StartScreenSaver(self, *args):
|
||||
logevent('StartScreenSaver : %s'%[args])
|
||||
|
||||
def StopScreenSaver(self, *args):
|
||||
logevent('StopScreenSaver : %s'%[args])
|
||||
|
||||
|
||||
def logevent(msg, evtid=0xF000):
|
||||
"""log into windows event manager
|
||||
"""
|
||||
servicemanager.LogMsg(
|
||||
servicemanager.EVENTLOG_INFORMATION_TYPE,
|
||||
evtid, # generic message
|
||||
(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')
|
@ -1,8 +1,13 @@
|
||||
import pythoncom
|
||||
import win32serviceutil
|
||||
import win32service
|
||||
import win32api
|
||||
import win32event
|
||||
|
||||
import pythoncom
|
||||
import win32com.client
|
||||
|
||||
import servicemanager
|
||||
from SENS import *
|
||||
import socket
|
||||
|
||||
|
||||
@ -10,6 +15,7 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
|
||||
_svc_name_ = "UDSActor"
|
||||
_svc_display_name_ = "UDS Actor Service"
|
||||
_svc_description_ = "UDS Actor for machines managed by UDS Broker"
|
||||
_svc_deps_ = ['EventLog','SENS'] # 'System Event Notification' is the SENS service
|
||||
|
||||
def __init__(self,args):
|
||||
win32serviceutil.ServiceFramework.__init__(self,args)
|
||||
@ -22,20 +28,72 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
|
||||
self.isAlive = False
|
||||
win32event.SetEvent(self.hWaitStop)
|
||||
|
||||
SvcShutdown = SvcStop
|
||||
|
||||
def interactWithBroker(self):
|
||||
'''
|
||||
Returns True to continue to main loop, false to stop & exit service
|
||||
'''
|
||||
return True
|
||||
|
||||
def SvcDoRun(self):
|
||||
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
|
||||
servicemanager.PYS_SERVICE_STARTED,
|
||||
(self._svc_name_,''))
|
||||
|
||||
# ********************************************************
|
||||
# * Ask brokers what to do before proceding to main loop *
|
||||
# ********************************************************
|
||||
if self.interactWithBroker() is False:
|
||||
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
|
||||
return
|
||||
|
||||
# ********************************
|
||||
# * Registers SENS subscriptions *
|
||||
# ********************************
|
||||
|
||||
# call the CoInitialize to allow the registration to run in an other
|
||||
# thread
|
||||
pythoncom.CoInitialize()
|
||||
|
||||
logevent('Registring ISensLogon')
|
||||
subscription_guid = '{41099152-498E-11E4-8FD3-10FEED05884B}'
|
||||
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='UDS Actor subscription'
|
||||
event_subscription.SubscriptionID = subscription_guid
|
||||
event_subscription.SubscriberInterface=subscription_interface
|
||||
|
||||
event_system.Store(PROGID_EventSubscription, event_subscription)
|
||||
|
||||
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 0xF000, ('Running Service Main Loop', ''))
|
||||
|
||||
# *********************
|
||||
# * Main Service loop *
|
||||
# *********************
|
||||
while self.isAlive:
|
||||
pythoncom.PumpWaitingMessages() # Process SENS messages, This will be a bit asyncronous (1 second delay)
|
||||
win32event.WaitForSingleObject(self.hWaitStop, 1000) # In milliseconds
|
||||
|
||||
# *******************************************
|
||||
# * Remove SENS subscription before exiting *
|
||||
# *******************************************
|
||||
event_system.Remove(PROGID_EventSubscription, "SubscriptionID == " + subscription_guid)
|
||||
|
||||
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
|
||||
servicemanager.PYS_SERVICE_STOPPED,
|
||||
(self._svc_name_,''))
|
||||
|
||||
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
|
||||
try:
|
||||
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user