unregister show message fixed

This commit is contained in:
edip 2018-11-19 13:57:35 +03:00
parent 9232b6439f
commit 8991f8d768
3 changed files with 58 additions and 46 deletions

View file

@ -240,6 +240,29 @@ class AhenkDaemon(BaseDaemon):
Util.create_file(System.Ahenk.fifo_file()) Util.create_file(System.Ahenk.fifo_file())
Util.set_permission(System.Ahenk.fifo_file(), '600') 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): def run(self):
""" docstring""" """ docstring"""
print('Ahenk running...') print('Ahenk running...')
@ -287,27 +310,9 @@ class AhenkDaemon(BaseDaemon):
self.check_registration() self.check_registration()
self.is_registered() #self.is_registered()
conf_manager= global_scope.get_configuration_manager() self.disable_local_users()
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.logger.info('Ahenk was registered') #self.logger.info('Ahenk was registered')

View file

@ -352,30 +352,36 @@ class Registration:
def purge_and_unregister(self): def purge_and_unregister(self):
self.logger.info('Ahenk conf cleaned') try:
self.logger.info('Ahenk conf cleaning from db') user_name = self.db_service.select_one_result('session', 'username')
self.unregister() display = self.db_service.select_one_result('session', 'display')
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()
self.logger.info('Ahenk conf cleaned from db') self.logger.info('Ahenk conf cleaned')
self.logger.info('Enable Users') self.logger.info('Ahenk conf cleaning from db')
self.enable_local_users() 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') self.logger.info('Ahenk conf cleaned from db')
display = self.db_service.select_one_result('session', 'display') 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())) #System.Process.kill_by_pid(int(System.Ahenk.get_pid_number()))
#sys.exit(2) #sys.exit(2)
@ -475,6 +481,7 @@ class Registration:
file.close() file.close()
print('Ahenk cleaned.') print('Ahenk cleaned.')
except Exception as e: 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))) print('Error while running clean command. Error Message {0}'.format(str(e)))
def enable_local_users(self): def enable_local_users(self):

View file

@ -332,7 +332,7 @@ class Util:
Util.execute('export DISPLAY={0}; su - {1} -c \'{2}\''.format(display, user, inner_command)) Util.execute('export DISPLAY={0}; su - {1} -c \'{2}\''.format(display, user, inner_command))
@staticmethod @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' ask_path = '/usr/share/ahenk/base/agreement/confirm.py'
try: try:
@ -352,14 +352,14 @@ class Util:
else: else:
return None return None
except Exception: except Exception as e :
return None print("Error when showing message " + str(e))
return None;
@staticmethod @staticmethod
def show_registration_message(login_user_name,message,title,host=None): def show_registration_message(login_user_name,message,title,host=None):
ask_path = '/usr/share/ahenk/base/agreement/ahenkmessage.py' ask_path = '/usr/share/ahenk/base/agreement/ahenkmessage.py'
display_number = ":0" display_number = ":0"
if host is None: if host is None:
@ -375,7 +375,7 @@ class Util:
pout = str(p_out).replace('\n', '') pout = str(p_out).replace('\n', '')
return pout\ return pout
@staticmethod @staticmethod
def show_unregistration_message(login_user_name,display_number,message,title): def show_unregistration_message(login_user_name,display_number,message,title):