From 10369afda0d29c3634b68b9a593a1dd085288bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuncay=20=C3=87OLAK?= Date: Wed, 29 Sep 2021 15:41:42 +0300 Subject: [PATCH] added default config class for sssd settings --- debian/ahenk.postinst | 34 +++++++-------- src/ahenkd.py | 8 +++- src/base/default_config/__init__.py | 0 src/base/default_config/default_config.py | 53 +++++++++++++++++++++++ 4 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 src/base/default_config/__init__.py create mode 100644 src/base/default_config/default_config.py diff --git a/debian/ahenk.postinst b/debian/ahenk.postinst index 1842259..8983c72 100644 --- a/debian/ahenk.postinst +++ b/debian/ahenk.postinst @@ -12,23 +12,23 @@ if [ ! -d /etc/ahenk ]; then fi -# update pardus21 sssd conf changes when update pardus from 24 to 25 -if [ -d /etc/ahenk ]; then - if [ -f /etc/default/sssd ]; then - if ! grep -Fxq 'LC_ALL="tr_CY.UTF-8"' /etc/default/sssd - then - echo 'LC_ALL="tr_CY.UTF-8"' >> /etc/default/sssd - systemctl restart sssd.service - fi - fi - - if [ -f /etc/ahenk/ad_info ]; then - if [ -f /etc/sssd/sssd.conf ]; then - sed -i 's/ad_domain/ad_server/g' /etc/sssd/sssd.conf - systemctl restart sssd.service - fi - fi -fi +## update pardus21 sssd conf changes when update pardus from 24 to 25 +#if [ -d /etc/ahenk ]; then +# if [ -f /etc/default/sssd ]; then +# if ! grep -Fxq 'LC_ALL="tr_CY.UTF-8"' /etc/default/sssd +# then +# echo 'LC_ALL="tr_CY.UTF-8"' >> /etc/default/sssd +# systemctl restart sssd.service +# fi +# fi +# +# if [ -f /etc/ahenk/ad_info ]; then +# if [ -f /etc/sssd/sssd.conf ]; then +# sed -i 's/ad_domain/ad_server/g' /etc/sssd/sssd.conf +# systemctl restart sssd.service +# fi +# fi +#fi systemctl enable ahenk systemctl start ahenk diff --git a/src/ahenkd.py b/src/ahenkd.py index ebcef46..80126fd 100644 --- a/src/ahenkd.py +++ b/src/ahenkd.py @@ -30,6 +30,7 @@ from base.scope import Scope from base.system.system import System from base.task.task_manager import TaskManager from base.util.util import Util +from base.default_config.default_config import DefaultConfig from easygui import msgbox sys.path.append('../..') @@ -274,6 +275,10 @@ class AhenkDaemon(BaseDaemon): else: self.logger.info('local users will not be disabled because local_user_paramater is FALSE') + def default_settings(self): + default_config = DefaultConfig() + default_config.check_sssd_settings() + def run(self): """ docstring""" print('Ahenk running...') @@ -319,6 +324,8 @@ class AhenkDaemon(BaseDaemon): self.init_execution_manager() self.logger.info('Execution Manager was set') + self.default_settings() + self.check_registration() self.is_registered() @@ -341,7 +348,6 @@ class AhenkDaemon(BaseDaemon): # if registration.is_ldap_registered() is False: # logger.debug('Attempting to registering ldap') # registration.ldap_registration_request() #TODO work on message - self.logger.info('LDAP registration of Ahenk is completed') self.messenger.send_direct_message('test') diff --git a/src/base/default_config/__init__.py b/src/base/default_config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/base/default_config/default_config.py b/src/base/default_config/default_config.py new file mode 100644 index 0000000..8e55ab0 --- /dev/null +++ b/src/base/default_config/default_config.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# checked config when restarted agent service. Example, sssd language settings.. + +from base.scope import Scope +from base.util.util import Util + + +class DefaultConfig: + + def __init__(self): + scope = Scope().get_instance() + self.logger = scope.get_logger() + + def check_sssd_settings(self): + # configure sssd for language environment + sssd_language_conf = "/etc/default/sssd" + sssd_conf_path = "/etc/sssd/sssd.conf" + ad_info = "/etc/ahenk/ad_info" + registration = Scope.get_instance().get_registration() + if registration.is_registered() and Util.is_exist(sssd_language_conf): + file_default_sssd = open(sssd_language_conf, 'r') + file_data = file_default_sssd.read() + file_default_sssd.close() + + if "LC_ALL=\"tr_CY.UTF-8\"" not in file_data: + file_data = file_data + "\n" + "LC_ALL=\"tr_CY.UTF-8\"" + self.logger.info("added language environment for sssd") + file_default_sssd = open(sssd_language_conf, 'w') + file_default_sssd.write(file_data) + file_default_sssd.close() + Util.execute("systemctl restart sssd.service") + + if registration.is_registered() and Util.is_exist(sssd_conf_path) and Util.is_exist(ad_info): + sssd_conf_data = Util.read_file_by_line(sssd_conf_path) + + isExist = False + for line in sssd_conf_data: + if "ad_domain" in line: + isExist = True + if isExist: + sssd_conf_temp = open(sssd_conf_path, 'w') + for line in sssd_conf_data: + if "ad_domain" in line: + line = line.replace("ad_domain", "ad_server") + sssd_conf_temp.write(line) + sssd_conf_temp.close() + Util.execute("systemctl restart sssd.service") + self.logger.info("replaced ad_domain parameter with ad_server") + sssd_conf_temp.close() + +