From 8991f8d76877eb8c74462463a4afadb2189dac36 Mon Sep 17 00:00:00 2001 From: edip Date: Mon, 19 Nov 2018 13:57:35 +0300 Subject: [PATCH] unregister show message fixed --- src/ahenkd.py | 45 +++++++++++++------------ src/base/registration/registration.py | 47 +++++++++++++++------------ src/base/util/util.py | 12 +++---- 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/ahenkd.py b/src/ahenkd.py index 919b60f..33721bb 100644 --- a/src/ahenkd.py +++ b/src/ahenkd.py @@ -240,6 +240,29 @@ class AhenkDaemon(BaseDaemon): Util.create_file(System.Ahenk.fifo_file()) Util.set_permission(System.Ahenk.fifo_file(), '600') + def disable_local_users(self): + + self.logger.info('Local users disable action start..') + conf_manager = Scope.get_instance().get_configuration_manager() + + if conf_manager.has_section('MACHINE'): + user_disabled = conf_manager.get("MACHINE", "user_disabled") + self.logger.info('User disabled value=' + str(user_disabled)) + if user_disabled == '0': + self.logger.info('local user disabling') + Scope.get_instance().get_registration().disable_local_users() + + conf_manager.set('MACHINE', 'user_disabled', '1') + + with open('/etc/ahenk/ahenk.conf', 'w') as configfile: + self.logger.info('oepning config file ') + conf_manager.write(configfile) + + user_disabled = conf_manager.get("MACHINE", "user_disabled") + self.logger.info('User succesfully disabled value=' + str(user_disabled)) + else: + self.logger.info('users already disabled') + def run(self): """ docstring""" print('Ahenk running...') @@ -287,27 +310,9 @@ class AhenkDaemon(BaseDaemon): self.check_registration() - self.is_registered() + #self.is_registered() - conf_manager= global_scope.get_configuration_manager() - - if conf_manager.has_section('MACHINE'): - user_disabled = conf_manager.get("MACHINE", "user_disabled") - self.logger.info('User disabled value='+ str(user_disabled)) - if user_disabled == '0': - self.logger.info('local user disabling') - global_scope.get_registration().disable_local_users() - - conf_manager.set('MACHINE', 'user_disabled', '1') - - with open('/etc/ahenk/ahenk.conf', 'w') as configfile: - self.logger.info('oepning config file ') - conf_manager.write(configfile) - - user_disabled = conf_manager.get("MACHINE", "user_disabled") - self.logger.info('User succesfully disabled value=' + str(user_disabled)) - else : - self.logger.info('users already disabled') + self.disable_local_users() #self.logger.info('Ahenk was registered') diff --git a/src/base/registration/registration.py b/src/base/registration/registration.py index 064d21e..f0e6ae9 100644 --- a/src/base/registration/registration.py +++ b/src/base/registration/registration.py @@ -352,30 +352,36 @@ class Registration: def purge_and_unregister(self): - self.logger.info('Ahenk conf cleaned') - self.logger.info('Ahenk conf cleaning from db') - self.unregister() - self.logger.info('Purge ldap packages') - Util.execute("sudo apt purge libpam-ldap libnss-ldap ldap-utils -y") - #self.logger.info('Purge ahenk packages') - #Util.execute("sudo apt purge ahenk ahenk-* -y") - Util.execute("sudo apt autoremove -y") - self.change_configs_after_purge() - self.logger.info('purging successfull') - self.logger.info('Cleaning ahenk conf..') - self.clean() + try: + user_name = self.db_service.select_one_result('session', 'username') + display = self.db_service.select_one_result('session', 'display') - self.logger.info('Ahenk conf cleaned from db') - self.logger.info('Enable Users') - self.enable_local_users() + self.logger.info('Ahenk conf cleaned') + self.logger.info('Ahenk conf cleaning from db') + self.unregister() + self.logger.info('Purge ldap packages') + Util.execute("sudo apt purge libpam-ldap libnss-ldap ldap-utils -y") + # self.logger.info('Purge ahenk packages') + # Util.execute("sudo apt purge ahenk ahenk-* -y") + Util.execute("sudo apt autoremove -y") + self.change_configs_after_purge() + self.logger.info('purging successfull') + self.logger.info('Cleaning ahenk conf..') + self.clean() - user_name = self.db_service.select_one_result('session', 'username') - display = self.db_service.select_one_result('session', 'display') + self.logger.info('Ahenk conf cleaned from db') + self.logger.info('Enable Users') + self.enable_local_users() - Util.show_message(user_name,display,"Ahenk etki alanından çıkarılmıştır.", "") + Util.show_message(user_name, display, "Ahenk etki alanından çıkarılmıştır.", "") + + if Util.show_message(user_name, display, + "Değişikliklerin etkili olması için sistem yeniden başlatmanız gerekmektedir.", ""): + Util.shutdown() + + except Exception as e: + self.logger.error("Error while running purge_and_unregister process.. Error Message " + str(e)) - if Util.show_message(user_name,display,"Değişikliklerin etkili olması için sistem yeniden başlatmanız gerekmektedir.",""): - Util.shutdown() #System.Process.kill_by_pid(int(System.Ahenk.get_pid_number())) #sys.exit(2) @@ -475,6 +481,7 @@ class Registration: file.close() print('Ahenk cleaned.') except Exception as e: + self.logger.error("Error while running clean command. Error Message " + str(e)) print('Error while running clean command. Error Message {0}'.format(str(e))) def enable_local_users(self): diff --git a/src/base/util/util.py b/src/base/util/util.py index 706a53b..4404aa5 100644 --- a/src/base/util/util.py +++ b/src/base/util/util.py @@ -332,7 +332,7 @@ class Util: Util.execute('export DISPLAY={0}; su - {1} -c \'{2}\''.format(display, user, inner_command)) @staticmethod - def show_message(username,display=':0',message="", title=""): + def show_message(username,display=':0',message='', title=''): ask_path = '/usr/share/ahenk/base/agreement/confirm.py' try: @@ -352,14 +352,14 @@ class Util: else: return None - except Exception: - return None + except Exception as e : + print("Error when showing message " + str(e)) + + return None; @staticmethod def show_registration_message(login_user_name,message,title,host=None): - ask_path = '/usr/share/ahenk/base/agreement/ahenkmessage.py' - display_number = ":0" if host is None: @@ -375,7 +375,7 @@ class Util: pout = str(p_out).replace('\n', '') - return pout\ + return pout @staticmethod def show_unregistration_message(login_user_name,display_number,message,title):