expiration date bug fixed

This commit is contained in:
volkansahin 2017-07-18 16:16:22 +03:00
parent 7780225f91
commit f68b49de38

View file

@ -211,6 +211,7 @@ class ExecutionManager(object):
return plugin return plugin
def execute_policy(self, arg): def execute_policy(self, arg):
try:
self.logger.debug('Updating policies...') self.logger.debug('Updating policies...')
policy = self.json_to_PolicyBean(json.loads(arg)) policy = self.json_to_PolicyBean(json.loads(arg))
self.policy_executed[policy.get_username()] = True self.policy_executed[policy.get_username()] = True
@ -231,7 +232,7 @@ class ExecutionManager(object):
self.db_service.delete('plugin', 'id=' + str(ahenk_policy_id)) self.db_service.delete('plugin', 'id=' + str(ahenk_policy_id))
self.db_service.update('policy', ['version', 'execution_id', 'expiration_date'], self.db_service.update('policy', ['version', 'execution_id', 'expiration_date'],
[str(policy.get_ahenk_policy_version()), policy.agent_execution_id, [str(policy.get_ahenk_policy_version()), policy.agent_execution_id,
policy.agent_expiration_date], 'type=\'A\'') str(policy.agent_expiration_date)], 'type=\'A\'')
else: else:
self.db_service.update('policy', ['type', 'version', 'name', 'execution_id', 'expiration_date'], self.db_service.update('policy', ['type', 'version', 'name', 'execution_id', 'expiration_date'],
['A', str(policy.get_ahenk_policy_version()), machine_uid, ['A', str(policy.get_ahenk_policy_version()), machine_uid,
@ -254,9 +255,11 @@ class ExecutionManager(object):
str(profile.get_profile_data()), plugin_id] str(profile.get_profile_data()), plugin_id]
self.db_service.update('profile', profile_columns, profile_args) self.db_service.update('profile', profile_columns, profile_args)
else: elif ahenk_policy_ver:
self.logger.debug('Already there is ahenk policy. Command Execution Id is updating') self.logger.debug('Already there is ahenk policy. Command Execution Id is updating')
self.db_service.update('policy', ['execution_id'], [policy.get_agent_execution_id()], 'type = \'A\'') self.db_service.update('policy', ['execution_id'], [policy.get_agent_execution_id()], 'type = \'A\'')
else:
self.logger.debug('There is no any Ahenk policy.')
if policy.get_user_policy_version() != user_policy_version: if policy.get_user_policy_version() != user_policy_version:
user_policy_id = self.db_service.select_one_result('policy', 'id', user_policy_id = self.db_service.select_one_result('policy', 'id',
@ -267,10 +270,10 @@ class ExecutionManager(object):
self.db_service.delete('plugin', 'id=' + str(user_policy_id)) self.db_service.delete('plugin', 'id=' + str(user_policy_id))
self.db_service.update('policy', ['version', 'execution_id', 'expiration_date'], self.db_service.update('policy', ['version', 'execution_id', 'expiration_date'],
[str(policy.get_user_policy_version()), policy.user_execution_id, [str(policy.get_user_policy_version()), policy.user_execution_id,
policy.user_expiration_date], str(policy.user_expiration_date)],
'type=\'U\' and name=\'' + policy.get_username() + '\'') 'type=\'U\' and name=\'' + policy.get_username() + '\'')
else: else:
self.db_service.update('policy', ['type', 'version', 'name', 'execution_id'], self.db_service.update('policy', ['type', 'version', 'name', 'execution_id', 'expiration_date'],
['U', str(policy.get_user_policy_version()), policy.get_username(), ['U', str(policy.get_user_policy_version()), policy.get_username(),
policy.get_user_execution_id(), policy.user_expiration_date]) policy.get_user_execution_id(), policy.user_expiration_date])
user_policy_id = self.db_service.select_one_result('policy', 'id', user_policy_id = self.db_service.select_one_result('policy', 'id',
@ -292,16 +295,21 @@ class ExecutionManager(object):
str(profile.get_profile_data()), plugin_id] str(profile.get_profile_data()), plugin_id]
self.db_service.update('profile', profile_columns, profile_args) self.db_service.update('profile', profile_columns, profile_args)
else: elif user_policy_version:
self.logger.debug('Already there is user policy. . Command Execution Id is updating') self.logger.debug('Already there is user policy. . Command Execution Id is updating')
self.db_service.update('policy', ['execution_id'], [policy.get_user_execution_id()], 'type = \'U\'') self.db_service.update('policy', ['execution_id'], [policy.get_user_execution_id()], 'type = \'U\'')
else:
self.logger.debug('There is no any user policy')
policy = self.get_active_policies(policy.get_username()) policy = self.get_active_policies(policy.get_username())
# TODO check is null # TODO check is null
self.task_manager.addPolicy(policy) self.task_manager.addPolicy(policy)
except Exception as e:
self.logger.error('A problem occurred while executing policy. Erroe Message: {0}:'.format(str(e)))
def get_active_policies(self, username): def get_active_policies(self, username):
try:
# TODO vt den gecerli son tarihi olani cek # TODO vt den gecerli son tarihi olani cek
user_policy = self.db_service.select('policy', ['id', 'version', 'name', 'expiration_date'], user_policy = self.db_service.select('policy', ['id', 'version', 'name', 'expiration_date'],
' type=\'U\' and name=\'' + username + '\'') ' type=\'U\' and name=\'' + username + '\'')
@ -316,7 +324,7 @@ class ExecutionManager(object):
policy = PolicyBean(username=username) policy = PolicyBean(username=username)
if len(user_policy) > 0 and int(user_policy[0][3]) > current_timestamp: if len(user_policy) > 0 and (user_policy[0][3] is None or int(user_policy[0][3]) > current_timestamp):
user_policy_version = user_policy[0][0] user_policy_version = user_policy[0][0]
policy.set_user_policy_version(user_policy_version) policy.set_user_policy_version(user_policy_version)
@ -335,7 +343,7 @@ class ExecutionManager(object):
profile[7], profile[8], plugin, policy.get_username())) profile[7], profile[8], plugin, policy.get_username()))
policy.set_user_profiles(arr_profiles) policy.set_user_profiles(arr_profiles)
if len(ahenk_policy) > 0 and int(ahenk_policy[0][2]) > current_timestamp: if len(ahenk_policy) > 0 and ( ahenk_policy[0][2] is None or int(ahenk_policy[0][2]) > current_timestamp):
ahenk_policy_version = ahenk_policy[0][0] ahenk_policy_version = ahenk_policy[0][0]
policy.set_ahenk_policy_version(ahenk_policy_version) policy.set_ahenk_policy_version(ahenk_policy_version)
ahenk_profiles = self.db_service.select('profile', profile_columns, ahenk_profiles = self.db_service.select('profile', profile_columns,
@ -355,6 +363,8 @@ class ExecutionManager(object):
policy.set_ahenk_profiles(arr_profiles) policy.set_ahenk_profiles(arr_profiles)
return policy return policy
except Exception as e:
self.logger.error('A problem occurred while getting active policies. Error Message : {0}'.format(str(e)))
def execute_task(self, arg): def execute_task(self, arg):