mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-24 15:22:16 +03:00
expiration date bug fixed
This commit is contained in:
parent
7780225f91
commit
f68b49de38
1 changed files with 127 additions and 117 deletions
|
@ -211,6 +211,7 @@ class ExecutionManager(object):
|
|||
return plugin
|
||||
|
||||
def execute_policy(self, arg):
|
||||
try:
|
||||
self.logger.debug('Updating policies...')
|
||||
policy = self.json_to_PolicyBean(json.loads(arg))
|
||||
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.update('policy', ['version', 'execution_id', 'expiration_date'],
|
||||
[str(policy.get_ahenk_policy_version()), policy.agent_execution_id,
|
||||
policy.agent_expiration_date], 'type=\'A\'')
|
||||
str(policy.agent_expiration_date)], 'type=\'A\'')
|
||||
else:
|
||||
self.db_service.update('policy', ['type', 'version', 'name', 'execution_id', 'expiration_date'],
|
||||
['A', str(policy.get_ahenk_policy_version()), machine_uid,
|
||||
|
@ -254,9 +255,11 @@ class ExecutionManager(object):
|
|||
str(profile.get_profile_data()), plugin_id]
|
||||
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.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:
|
||||
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.update('policy', ['version', 'execution_id', 'expiration_date'],
|
||||
[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() + '\'')
|
||||
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(),
|
||||
policy.get_user_execution_id(), policy.user_expiration_date])
|
||||
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]
|
||||
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.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())
|
||||
# TODO check is null
|
||||
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):
|
||||
|
||||
try:
|
||||
# TODO vt den gecerli son tarihi olani cek
|
||||
user_policy = self.db_service.select('policy', ['id', 'version', 'name', 'expiration_date'],
|
||||
' type=\'U\' and name=\'' + username + '\'')
|
||||
|
@ -316,7 +324,7 @@ class ExecutionManager(object):
|
|||
|
||||
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]
|
||||
policy.set_user_policy_version(user_policy_version)
|
||||
|
||||
|
@ -335,7 +343,7 @@ class ExecutionManager(object):
|
|||
profile[7], profile[8], plugin, policy.get_username()))
|
||||
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]
|
||||
policy.set_ahenk_policy_version(ahenk_policy_version)
|
||||
ahenk_profiles = self.db_service.select('profile', profile_columns,
|
||||
|
@ -355,6 +363,8 @@ class ExecutionManager(object):
|
|||
policy.set_ahenk_profiles(arr_profiles)
|
||||
|
||||
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):
|
||||
|
||||
|
|
Loading…
Reference in a new issue