1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +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:
Adolfo Gómez García 2016-03-14 12:16:52 +01:00
commit b0a6807ea4
7 changed files with 281 additions and 213 deletions

View File

@ -87,9 +87,16 @@ class UDSActorSvc(Daemon, CommonService):
set_proctitle('UDSActorDaemon')
# Linux daemon will continue running unless something is requested to
if self.interactWithBroker() is False:
while True:
brokerConnected = self.interactWithBroker()
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:
logger.debug('The service is not alive after broker interaction, stopping it')

View File

@ -127,7 +127,6 @@ class CommonService(object):
return False # On unmanaged hosts, there is no reason right now to continue running
except Exception as e:
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
# but, if too many errors, will log it (one every minute, for
# example)
@ -164,11 +163,11 @@ class CommonService(object):
break
except Exception as e:
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':
if len(params) != 5:
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])
break
else:

View File

@ -236,6 +236,19 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
# ********************************************************
# * 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:
logger.debug('Interact with broker returned false, stopping service after a while')
self.notifyStop()

View File

@ -51,7 +51,7 @@ import requests
import json
import logging
__updated__ = '2016-03-09'
__updated__ = '2016-03-14'
logger = logging.getLogger(__name__)
@ -378,6 +378,34 @@ class UserServiceManager(object):
except Exception as e:
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):
'''
If allowed, send script to user service
@ -478,6 +506,12 @@ class UserServiceManager(object):
# If ready, show transport for this service, if also ready ofc
iads = userService.getInstance()
ip = iads.getIp()
if self.checkUuid(userService) is False: # Machine is not what is expected
serviceNotReadyCode = 0x0004
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:
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
@ -485,7 +519,7 @@ class UserServiceManager(object):
if itrans.isAvailableFor(userService, ip):
userService.setConnectionSource(srcIp, 'unknown')
log.doLog(userService, log.INFO, "User service ready", log.WEB)
UserServiceManager.manager().notifyPreconnect(userService, itrans.processedUser(userService, user), itrans.protocol)
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)

View File

@ -45,7 +45,7 @@ import six
import bitarray
import logging
__updated__ = '2016-03-10'
__updated__ = '2016-03-14'
logger = logging.getLogger(__name__)
@ -109,15 +109,17 @@ class CalendarChecker(object):
return data
def _updateEvents(self, checkFrom):
def _updateEvents(self, checkFrom, startEvent=True):
next_event = None
for rule in self.calendar.rules.all():
event = rule.as_rrule().after(checkFrom)
duration = rule.duration_as_minutes
if startEvent:
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:
next_event = (event, datetime.timedelta(minutes=duration))
if next_event is None or next_event > event:
next_event = event
return next_event
@ -147,7 +149,7 @@ class CalendarChecker(object):
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 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:
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)
print next_event
if next_event is None:
next_event = self._updateEvents(checkFrom)
next_event = self._updateEvents(checkFrom, startEvent)
CalendarChecker.cache.put(cacheKey, next_event, 3600)
else:
CalendarChecker.hits += 1

View File

@ -33,7 +33,7 @@
from __future__ import unicode_literals
__updated__ = '2015-09-17'
__updated__ = '2016-03-14'
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@ -124,6 +124,18 @@ class CalendarRule(UUIDModel):
else:
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
def frequency_as_minutes(self):
if self.frequency != WEEKDAYS: