mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-25 06:03:51 +03:00
Merge remote-tracking branch 'origin/v1.9'
# Conflicts: # VERSION # actors/linux/build-packages.sh # actors/linux/debian/changelog # actors/linux/debian/files # client/linux/debian/changelog # client/linux/debian/files
This commit is contained in:
commit
b0a6807ea4
@ -87,9 +87,16 @@ class UDSActorSvc(Daemon, CommonService):
|
|||||||
set_proctitle('UDSActorDaemon')
|
set_proctitle('UDSActorDaemon')
|
||||||
|
|
||||||
# Linux daemon will continue running unless something is requested to
|
# Linux daemon will continue running unless something is requested to
|
||||||
if self.interactWithBroker() is False:
|
while True:
|
||||||
logger.debug('Interact with broker returned false, stopping service after a while')
|
brokerConnected = self.interactWithBroker()
|
||||||
return
|
if brokerConnected is False:
|
||||||
|
logger.debug('Interact with broker returned false, stopping service after a while')
|
||||||
|
return
|
||||||
|
elif brokerConnected is True:
|
||||||
|
break
|
||||||
|
|
||||||
|
# If brokerConnected returns None, repeat the cycle
|
||||||
|
self.doWait(16000) # Wait for a looong while
|
||||||
|
|
||||||
if self.isAlive is False:
|
if self.isAlive is False:
|
||||||
logger.debug('The service is not alive after broker interaction, stopping it')
|
logger.debug('The service is not alive after broker interaction, stopping it')
|
||||||
|
@ -127,7 +127,6 @@ class CommonService(object):
|
|||||||
return False # On unmanaged hosts, there is no reason right now to continue running
|
return False # On unmanaged hosts, there is no reason right now to continue running
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug('Exception on network info: retrying')
|
logger.debug('Exception on network info: retrying')
|
||||||
logger.exception()
|
|
||||||
# Any other error is expectable and recoverable, so let's wait a bit and retry again
|
# Any other error is expectable and recoverable, so let's wait a bit and retry again
|
||||||
# but, if too many errors, will log it (one every minute, for
|
# but, if too many errors, will log it (one every minute, for
|
||||||
# example)
|
# example)
|
||||||
@ -164,11 +163,11 @@ class CommonService(object):
|
|||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Error at computer renaming stage: {}'.format(e.message))
|
logger.error('Error at computer renaming stage: {}'.format(e.message))
|
||||||
return False
|
return None # Will retry complete broker connection if this point is reached
|
||||||
elif data[0] == 'domain':
|
elif data[0] == 'domain':
|
||||||
if len(params) != 5:
|
if len(params) != 5:
|
||||||
logger.error('Got invalid parameters for domain message: {}'.format(params))
|
logger.error('Got invalid parameters for domain message: {}'.format(params))
|
||||||
return False
|
return False # Stop running service
|
||||||
self.joinDomain(params[0], params[1], params[2], params[3], params[4])
|
self.joinDomain(params[0], params[1], params[2], params[3], params[4])
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -236,6 +236,19 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
|||||||
# ********************************************************
|
# ********************************************************
|
||||||
# * Ask brokers what to do before proceding to main loop *
|
# * Ask brokers what to do before proceding to main loop *
|
||||||
# ********************************************************
|
# ********************************************************
|
||||||
|
while True:
|
||||||
|
brokerConnected = self.interactWithBroker()
|
||||||
|
if brokerConnected is False:
|
||||||
|
logger.debug('Interact with broker returned false, stopping service after a while')
|
||||||
|
self.notifyStop()
|
||||||
|
win32event.WaitForSingleObject(self.hWaitStop, 5000)
|
||||||
|
return
|
||||||
|
elif brokerConnected is True:
|
||||||
|
break
|
||||||
|
|
||||||
|
# If brokerConnected returns None, repeat the cycle
|
||||||
|
self.doWait(16000) # Wait for a looong while
|
||||||
|
|
||||||
if self.interactWithBroker() is False:
|
if self.interactWithBroker() is False:
|
||||||
logger.debug('Interact with broker returned false, stopping service after a while')
|
logger.debug('Interact with broker returned false, stopping service after a while')
|
||||||
self.notifyStop()
|
self.notifyStop()
|
||||||
|
@ -51,7 +51,7 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
__updated__ = '2016-03-09'
|
__updated__ = '2016-03-14'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -378,6 +378,34 @@ class UserServiceManager(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info('preConnection failed: {}. Check connection on destination machine: {}'.format(e, url))
|
logger.info('preConnection failed: {}. Check connection on destination machine: {}'.format(e, url))
|
||||||
|
|
||||||
|
def checkUuid(self, uService):
|
||||||
|
|
||||||
|
url = uService.getCommsUrl()
|
||||||
|
|
||||||
|
if url is None:
|
||||||
|
logger.debug('No uuid to retrieve because agent does not supports notifications')
|
||||||
|
return True # UUid is valid because it is not supported checking it
|
||||||
|
|
||||||
|
if uService.getProperty('actor_version', '') < '2.0.0': # Just for 2.0 or newer, previous actors will not support this method
|
||||||
|
return True
|
||||||
|
|
||||||
|
url += '/uuid'
|
||||||
|
|
||||||
|
try:
|
||||||
|
r = requests.get(url, verify=False, timeout=2)
|
||||||
|
uuid = json.loads(r.content)
|
||||||
|
if uuid != uService.uuid:
|
||||||
|
logger.info('The requested machine has uuid {} and the expected was {}'.format(uuid, uService.uuid))
|
||||||
|
return False
|
||||||
|
|
||||||
|
logger.debug('Got uuid from machine: {} {} {}'.format(url, uuid, uService.uuid))
|
||||||
|
# In fact we ignore result right now
|
||||||
|
except Exception as e:
|
||||||
|
logger.info('Get uuid failed: {}. Check connection on destination machine: {}'.format(e, url))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def sendScript(self, uService, script):
|
def sendScript(self, uService, script):
|
||||||
'''
|
'''
|
||||||
If allowed, send script to user service
|
If allowed, send script to user service
|
||||||
@ -478,20 +506,26 @@ class UserServiceManager(object):
|
|||||||
# If ready, show transport for this service, if also ready ofc
|
# If ready, show transport for this service, if also ready ofc
|
||||||
iads = userService.getInstance()
|
iads = userService.getInstance()
|
||||||
ip = iads.getIp()
|
ip = iads.getIp()
|
||||||
events.addEvent(userService.deployed_service, events.ET_ACCESS, username=user.name, srcip=srcIp, dstip=ip, uniqueid=userService.unique_id)
|
|
||||||
if ip is not None:
|
if self.checkUuid(userService) is False: # Machine is not what is expected
|
||||||
serviceNotReadyCode = 0x0003
|
serviceNotReadyCode = 0x0004
|
||||||
itrans = trans.getInstance()
|
log.doLog(userService, log.WARN, "User service is not accessible (ip {0})".format(ip), log.TRANSPORT)
|
||||||
if itrans.isAvailableFor(userService, ip):
|
logger.debug('Transport is not ready for user service {0}'.format(userService))
|
||||||
userService.setConnectionSource(srcIp, 'unknown')
|
|
||||||
log.doLog(userService, log.INFO, "User service ready", log.WEB)
|
|
||||||
UserServiceManager.manager().notifyPreconnect(userService, itrans.processedUser(userService, user), itrans.protocol)
|
|
||||||
return (ip, userService, iads, trans, itrans)
|
|
||||||
else:
|
|
||||||
log.doLog(userService, log.WARN, "User service is not accessible (ip {0})".format(ip), log.TRANSPORT)
|
|
||||||
logger.debug('Transport is not ready for user service {0}'.format(userService))
|
|
||||||
else:
|
else:
|
||||||
logger.debug('Ip not available from user service {0}'.format(userService))
|
events.addEvent(userService.deployed_service, events.ET_ACCESS, username=user.name, srcip=srcIp, dstip=ip, uniqueid=userService.unique_id)
|
||||||
|
if ip is not None:
|
||||||
|
serviceNotReadyCode = 0x0003
|
||||||
|
itrans = trans.getInstance()
|
||||||
|
if itrans.isAvailableFor(userService, ip):
|
||||||
|
userService.setConnectionSource(srcIp, 'unknown')
|
||||||
|
log.doLog(userService, log.INFO, "User service ready", log.WEB)
|
||||||
|
self.notifyPreconnect(userService, itrans.processedUser(userService, user), itrans.protocol)
|
||||||
|
return (ip, userService, iads, trans, itrans)
|
||||||
|
else:
|
||||||
|
log.doLog(userService, log.WARN, "User service is not accessible (ip {0})".format(ip), log.TRANSPORT)
|
||||||
|
logger.debug('Transport is not ready for user service {0}'.format(userService))
|
||||||
|
else:
|
||||||
|
logger.debug('Ip not available from user service {0}'.format(userService))
|
||||||
else:
|
else:
|
||||||
log.doLog(userService, log.WARN, "User {0} from {1} tried to access, but service was not ready".format(user.name, srcIp), log.WEB)
|
log.doLog(userService, log.WARN, "User {0} from {1} tried to access, but service was not ready".format(user.name, srcIp), log.WEB)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ import six
|
|||||||
import bitarray
|
import bitarray
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
__updated__ = '2016-03-10'
|
__updated__ = '2016-03-14'
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -109,15 +109,17 @@ class CalendarChecker(object):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def _updateEvents(self, checkFrom):
|
def _updateEvents(self, checkFrom, startEvent=True):
|
||||||
|
|
||||||
next_event = None
|
next_event = None
|
||||||
for rule in self.calendar.rules.all():
|
for rule in self.calendar.rules.all():
|
||||||
event = rule.as_rrule().after(checkFrom)
|
if startEvent:
|
||||||
duration = rule.duration_as_minutes
|
event = rule.as_rrule().after(checkFrom) # At start
|
||||||
|
else:
|
||||||
|
event = rule.as_rrule_end().after(checkFrom) # At end
|
||||||
|
|
||||||
if next_event is None or self.next_event[0] > event:
|
if next_event is None or next_event > event:
|
||||||
next_event = (event, datetime.timedelta(minutes=duration))
|
next_event = event
|
||||||
|
|
||||||
return next_event
|
return next_event
|
||||||
|
|
||||||
@ -147,7 +149,7 @@ class CalendarChecker(object):
|
|||||||
|
|
||||||
return data[dtime.hour * 60 + dtime.minute]
|
return data[dtime.hour * 60 + dtime.minute]
|
||||||
|
|
||||||
def nextEvent(self, checkFrom=None):
|
def nextEvent(self, checkFrom=None, startEvent=True):
|
||||||
'''
|
'''
|
||||||
Returns next event for this interval
|
Returns next event for this interval
|
||||||
Returns a list of two elements. First is datetime of event begining, second is timedelta of duration
|
Returns a list of two elements. First is datetime of event begining, second is timedelta of duration
|
||||||
@ -155,11 +157,12 @@ class CalendarChecker(object):
|
|||||||
if checkFrom is None:
|
if checkFrom is None:
|
||||||
checkFrom = getSqlDatetime()
|
checkFrom = getSqlDatetime()
|
||||||
|
|
||||||
cacheKey = six.text_type(self.calendar.modified.toordinal()) + self.calendar.uuid + six.text_type(checkFrom.toordinal()) + 'event'
|
cacheKey = six.text_type(self.calendar.modified.toordinal()) + self.calendar.uuid + six.text_type(checkFrom.toordinal()) + 'event' + ('x' if startEvent is True else '_')
|
||||||
|
print cacheKey
|
||||||
next_event = CalendarChecker.cache.get(cacheKey, None)
|
next_event = CalendarChecker.cache.get(cacheKey, None)
|
||||||
|
print next_event
|
||||||
if next_event is None:
|
if next_event is None:
|
||||||
next_event = self._updateEvents(checkFrom)
|
next_event = self._updateEvents(checkFrom, startEvent)
|
||||||
CalendarChecker.cache.put(cacheKey, next_event, 3600)
|
CalendarChecker.cache.put(cacheKey, next_event, 3600)
|
||||||
else:
|
else:
|
||||||
CalendarChecker.hits += 1
|
CalendarChecker.hits += 1
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
__updated__ = '2015-09-17'
|
__updated__ = '2016-03-14'
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
@ -124,6 +124,18 @@ class CalendarRule(UUIDModel):
|
|||||||
else:
|
else:
|
||||||
return rules.rrule(frq_to_rrl[self.frequency], interval=self.interval, dtstart=self.start)
|
return rules.rrule(frq_to_rrl[self.frequency], interval=self.interval, dtstart=self.start)
|
||||||
|
|
||||||
|
def as_rrule_end(self):
|
||||||
|
if self.frequency == WEEKDAYS:
|
||||||
|
dw = []
|
||||||
|
l = self.interval
|
||||||
|
for i in range(7):
|
||||||
|
if l & 1 == 1:
|
||||||
|
dw.append(weekdays[i])
|
||||||
|
l >>= 1
|
||||||
|
return rules.rrule(rules.DAILY, byweekday=dw, dtstart=self.start + datetime.timedelta(minutes=self.duration_as_minutes))
|
||||||
|
else:
|
||||||
|
return rules.rrule(frq_to_rrl[self.frequency], interval=self.interval, dtstart=self.start + datetime.timedelta(minutes=self.duration_as_minutes))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def frequency_as_minutes(self):
|
def frequency_as_minutes(self):
|
||||||
if self.frequency != WEEKDAYS:
|
if self.frequency != WEEKDAYS:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user