register and unregister from user gui

This commit is contained in:
edip 2018-11-10 22:28:32 +03:00
parent e1b30b3444
commit f83e182c8c
8 changed files with 123 additions and 65 deletions

View file

@ -294,7 +294,7 @@ class AhenkDaemon(BaseDaemon):
self.is_registered() self.is_registered()
self.logger.info('Ahenk was registered') #self.logger.info('Ahenk was registered')
self.messenger = self.init_messenger() self.messenger = self.init_messenger()
self.logger.info('Messenger was set') self.logger.info('Messenger was set')

View file

@ -68,6 +68,7 @@ class Agreement:
agreement_path, agreement_path,
title) title)
result_code, p_out, p_err = Util.execute(command) result_code, p_out, p_err = Util.execute(command)
pout = str(p_out).replace('\n', '') pout = str(p_out).replace('\n', '')
if pout != 'Error': if pout != 'Error':
if pout == 'Y': if pout == 'Y':

View file

@ -0,0 +1,47 @@
import sys
from easygui import multpasswordbox, msgbox
def ask(message, title, host):
field_names=[]
if host =='':
field_names.append("Etki Alanı Sunucusu:")
field_names.append("Yetkili Kullanıcı")
field_names.append("Parola")
field_values = multpasswordbox(
msg=message,
title=title, fields=(field_names))
if field_values is None:
return print('N');
is_fieldvalue_empty = False;
for value in field_values:
if value == '':
is_fieldvalue_empty = True;
if is_fieldvalue_empty:
msgbox("Lütfen zorunlu alanları giriniz.", ok_button="Tamam")
return print('Z');
if host =='':
print(field_values[0],field_values[1],field_values[2])
else:
print(field_values[0], field_values[1])
if __name__ == '__main__':
if len(sys.argv) > 1:
try:
message=sys.argv[1]
title=sys.argv[2]
host=sys.argv[3]
ask(message,title, host)
except Exception as e:
print(str(e))
else:
print('Argument fault. Check your parameters or content of parameters. Parameters: ' + str(sys.argv))

View file

@ -7,7 +7,8 @@ import easygui
def confirm(message, title): def confirm(message, title):
choice = easygui.ccbox(msg=message, title=title, choices=("Evet", "Hayır")) choice = easygui.buttonbox(msg=message, title=title, choices=["Tamam"])
if choice: if choice:
print('Y') print('Y')
else: else:

View file

@ -405,7 +405,7 @@ class ExecutionManager(object):
if 'not_authorized' == str(status): if 'not_authorized' == str(status):
self.logger.info('Registration is failed. User not authorized') self.logger.info('Registration is failed. User not authorized')
msgbox('Ahenk etki alanından çıkarmak için yetkili kullanıcı haklarına sahip olmanız gerekmektedir.', Util.show_message('Ahenk etki alanından çıkarmak için yetkili kullanıcı haklarına sahip olmanız gerekmektedir.',
'Kullanıcı Yetkilendirme Hatası') 'Kullanıcı Yetkilendirme Hatası')
else : else :
registration= Scope.get_instance().get_registration() registration= Scope.get_instance().get_registration()

View file

@ -9,11 +9,13 @@ from base.util.util import Util
import time import time
from base.system.system import System from base.system.system import System
import pwd
from helper import system as sysx
from sleekxmpp import ClientXMPP from sleekxmpp import ClientXMPP
from base.scope import Scope from base.scope import Scope
from easygui import msgbox
sys.path.append('../..') sys.path.append('../..')
@ -102,7 +104,7 @@ class AnonymousMessenger(ClientXMPP):
if 'not_authorized' == str(status): if 'not_authorized' == str(status):
self.logger.info('Registration is failed. User not authorized') self.logger.info('Registration is failed. User not authorized')
msgbox('Ahenk etki alanına alınamadı !! Sadece yetkili kullanıcılar etki alanına kayıt yapabilir.', 'Kullanıcı Yetkilendirme Hatası') Util.show_message('Ahenk etki alanına alınamadı !! Sadece yetkili kullanıcılar etki alanına kayıt yapabilir.', 'Kullanıcı Yetkilendirme Hatası')
self.logger.debug('Disconnecting...') self.logger.debug('Disconnecting...')
self.disconnect() self.disconnect()
@ -111,14 +113,14 @@ class AnonymousMessenger(ClientXMPP):
self.logger.info('Registred from server. Registration process starting.') self.logger.info('Registred from server. Registration process starting.')
self.event_manager.fireEvent('REGISTRATION_SUCCESS', j) self.event_manager.fireEvent('REGISTRATION_SUCCESS', j)
msg = str(self.host) + " Etki Alanına hoş geldiniz." msg = str(self.host) + " Etki Alanına hoş geldiniz."
msgbox(msg, "") Util.show_message(msg, "")
msg = "Değişikliklerin etkili olması için sistem yeniden başlayacaktır. Sistem yeniden başlatılıyor...." msg = "Değişikliklerin etkili olması için sistem yeniden başlayacaktır. Sistem yeniden başlatılıyor...."
msgbox(msg, "") Util.show_message(msg, "")
time.sleep(5) time.sleep(5)
self.logger.info('Disconnecting...') self.logger.info('Disconnecting...')
self.disconnect() self.disconnect()
self.logger.info('Rebooting...') self.logger.info('Rebooting...')
self.disable_local_users()
Util.shutdown(); 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)
@ -126,7 +128,7 @@ class AnonymousMessenger(ClientXMPP):
except Exception as e: except Exception as e:
self.logger.error('Error Message: {0}.'.format(str(e))) self.logger.error('Error Message: {0}.'.format(str(e)))
msgbox(str(e)) Util.show_message(str(e))
self.logger.debug('Disconnecting...') self.logger.debug('Disconnecting...')
self.disconnect() self.disconnect()
@ -134,7 +136,7 @@ class AnonymousMessenger(ClientXMPP):
elif 'registration_error' == str(status): elif 'registration_error' == str(status):
self.logger.info('Registration is failed. New registration request will send') self.logger.info('Registration is failed. New registration request will send')
#self.event_manager.fireEvent('REGISTRATION_ERROR', str(j)) #self.event_manager.fireEvent('REGISTRATION_ERROR', str(j))
msgbox('Ahenk etki alanına alınamadı !! Kayıt esnasında hata oluştu. Lütfen sistem yöneticinize başvurunuz.', Util.show_message('Ahenk etki alanına alınamadı !! Kayıt esnasında hata oluştu. Lütfen sistem yöneticinize başvurunuz.',
'Sistem Hatası') 'Sistem Hatası')
self.logger.debug('Disconnecting...') self.logger.debug('Disconnecting...')
self.disconnect() self.disconnect()
@ -145,3 +147,24 @@ class AnonymousMessenger(ClientXMPP):
def send_direct_message(self, msg): def send_direct_message(self, msg):
self.logger.debug('<<--------Sending message: {0}'.format(msg)) self.logger.debug('<<--------Sending message: {0}'.format(msg))
self.send_message(mto=self.receiver, mbody=msg, mtype='normal') self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
def disable_local_users(self):
passwd_cmd = 'passwd -l {}'
change_home = 'usermod -m -d {0} {1}'
change_username = 'usermod -l {0} {1}'
content = Util.read_file('/etc/passwd')
kill_all_process = 'killall -KILL -u {}'
for p in pwd.getpwall():
self.logger.info("User: '{0}' will be disabled and changed username and home directory of username".format(p.pw_name))
if not sysx.shell_is_interactive(p.pw_shell):
continue
if p.pw_uid == 0:
continue
if p.pw_name in content:
new_home_dir = p.pw_dir.rstrip('/') + '-local/'
new_username = p.pw_name+'-local'
Util.execute(kill_all_process.format(p.pw_name))
Util.execute(passwd_cmd.format(p.pw_name))
Util.execute(change_username.format(new_username, p.pw_name))
Util.execute(change_home.format(new_home_dir, new_username))

View file

@ -14,9 +14,9 @@ from helper import system as sysx
import pwd import pwd
from base.timer.setup_timer import SetupTimer from base.timer.setup_timer import SetupTimer
from base.timer.timer import Timer from base.timer.timer import Timer
from easygui import multpasswordbox, msgbox
import re import re
import sys import sys
import os
class Registration: class Registration:
def __init__(self): def __init__(self):
@ -47,37 +47,18 @@ class Registration:
self.host = self.conf_manager.get("CONNECTION", "host") self.host = self.conf_manager.get("CONNECTION", "host")
self.servicename = self.conf_manager.get("CONNECTION", "servicename") self.servicename = self.conf_manager.get("CONNECTION", "servicename")
self.user_name ='' self.user_name = ''
self.user_password='' self.user_password= ''
field_names = [] pout = Util.show_registration_message('Makineyi etki alanına almak için bilgileri ilgili alanlara giriniz. LÜTFEN DEVAM EDEN İŞLEMLERİ SONLANDIRDIĞINZA EMİN OLUNUZ !',
if self.host == '': 'ETKI ALANINA KAYIT', self.host)
field_names.append("Sunucu Adresi")
field_values = pout.split(' ')
field_names.append("Yetkili Kullanıcı")
field_names.append("Parola")
field_values = multpasswordbox(msg='Makineyi etki alanına almak için bilgileri ilgili alanlara giriniz. LÜTFEN DEVAM EDEN İŞLEMLERİ SONLANDIRDIĞINZA EMİN OLUNUZ !',
title='ETKI ALANINA KAYIT', fields=(field_names))
if field_values is None:
return False;
is_fieldvalue_empty= False;
for value in field_values :
if value == '' :
is_fieldvalue_empty = True;
if is_fieldvalue_empty:
msgbox("Lütfen zorunlu alanları giriniz.", ok_button="Tamam")
return False;
user_registration_info = list(field_values) user_registration_info = list(field_values)
if self.host == '' : if self.host == '' :
self.host = user_registration_info[0]; self.host = user_registration_info[0]
self.user_name = user_registration_info[1]; self.user_name = user_registration_info[1];
self.user_password = user_registration_info[2]; self.user_password = user_registration_info[2];
else: else:
@ -359,33 +340,14 @@ class Registration:
'and it is connected to XMPP server! Check your Ahenk configuration file (/etc/ahenk/ahenk.conf)') 'and it is connected to XMPP server! Check your Ahenk configuration file (/etc/ahenk/ahenk.conf)')
self.logger.error('Ahenk is shutting down...') self.logger.error('Ahenk is shutting down...')
print('Ahenk is shutting down...') print('Ahenk is shutting down...')
msgbox('Etki alanı sunucusuna ulaşılamadı. Lütfen sunucu adresini kontrol ediniz....','HATA')
Util.show_message("Etki alanı sunucusuna ulaşılamadı. Lütfen sunucu adresini kontrol ediniz....","HATA")
System.Process.kill_by_pid(int(System.Ahenk.get_pid_number())) System.Process.kill_by_pid(int(System.Ahenk.get_pid_number()))
def disable_local_users(self):
passwd_cmd = 'passwd -l {}'
change_home = 'usermod -m -d {0} {1}'
change_username = 'usermod -l {0} {1}'
content = self.util.read_file('/etc/passwd')
kill_all_process = 'killall -KILL -u {}'
for p in pwd.getpwall():
if not sysx.shell_is_interactive(p.pw_shell):
continue
if p.pw_uid == 0:
continue
if p.pw_name in content:
new_home_dir = p.pw_dir.rstrip('/') + '-local/'
new_username = p.pw_name+'-local'
self.util.execute(kill_all_process.format(p.pw_name))
self.util.execute(passwd_cmd.format(p.pw_name))
self.util.execute(change_username.format(new_username, p.pw_name))
self.util.execute(change_home.format(new_home_dir, new_username))
self.logger.debug("User: '{0}' will be disabled and changed username and home directory of username".format(p.pw_name))
def purge_and_unregister(self): def purge_and_unregister(self):
from easygui import msgbox,boolbox
self.logger.info('Ahenk conf cleaned') self.logger.info('Ahenk conf cleaned')
self.logger.info('Ahenk conf cleaning from db') self.logger.info('Ahenk conf cleaning from db')
self.unregister() self.unregister()
@ -401,11 +363,9 @@ class Registration:
self.logger.info('Enable Users') self.logger.info('Enable Users')
self.enable_local_users() self.enable_local_users()
Util.show_message("Ahenk etki alanından çıkarılmıştır.", "")
if Util.show_message("Değişikliklerin etkili olması için sistem yeniden başlatmanız gerekmektedir.",""):
msgbox("Ahenk etki alanından çıkarılmıştır.")
if boolbox("Değişikliklerin etkili olması için sistem yeniden başlatmanız gerekmektedir.","",["Yeniden Başlat", "Vazgeç"]):
Util.shutdown() Util.shutdown()
System.Process.kill_by_pid(int(System.Ahenk.get_pid_number())) System.Process.kill_by_pid(int(System.Ahenk.get_pid_number()))

View file

@ -332,8 +332,10 @@ 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 ask_permission(display, username, message, title): def show_message(message, title=""):
ask_path = '/usr/share/ahenk/base/agreement/confirm.py' ask_path = '/usr/share/ahenk/src/base/agreement/confirm.py'
display= ":0"
username= os.getlogin()
try: try:
if username is not None: if username is not None:
@ -354,3 +356,27 @@ class Util:
return None return None
except Exception: except Exception:
return None return None
@staticmethod
def show_registration_message(message,title,host=None):
login_user_name = os.getlogin()
ask_path = '/usr/share/ahenk/src/base/agreement/ahenkmessage.py'
display_number = ":0"
if host is None:
command = 'export DISPLAY={0}; su - {1} -c \"python3 {2} \'{3}\' \'{4}\' \"'.format(display_number, login_user_name,
ask_path, message, title)
else:
command = 'export DISPLAY={0}; su - {1} -c \"python3 {2} \'{3}\' \'{4}\' \'{5}\' \"'.format(display_number,
login_user_name,
ask_path,
message, title,
host)
result_code, p_out, p_err = Util.execute(command)
pout = str(p_out).replace('\n', '')
return pout