mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-25 22:52:24 +03:00
register unregister changes to remote installation and ad home directory changes
This commit is contained in:
parent
2875258147
commit
5186c4f936
8 changed files with 92 additions and 54 deletions
|
@ -147,7 +147,7 @@ class AhenkDaemon(BaseDaemon):
|
||||||
def check_registration(self):
|
def check_registration(self):
|
||||||
""" docstring"""
|
""" docstring"""
|
||||||
# max_attempt_number = int(System.Hardware.Network.interface_size()) * 3
|
# max_attempt_number = int(System.Hardware.Network.interface_size()) * 3
|
||||||
max_attempt_number = 1
|
max_attempt_number = 4
|
||||||
# self.logger.debug()
|
# self.logger.debug()
|
||||||
# logger = Scope.getInstance().getLogger()
|
# logger = Scope.getInstance().getLogger()
|
||||||
registration = Scope.get_instance().get_registration()
|
registration = Scope.get_instance().get_registration()
|
||||||
|
@ -158,12 +158,15 @@ class AhenkDaemon(BaseDaemon):
|
||||||
# if registration.registration_request() == False:
|
# if registration.registration_request() == False:
|
||||||
# self.registration_failed()
|
# self.registration_failed()
|
||||||
|
|
||||||
if registration.is_registered() is False:
|
while registration.is_registered() is False:
|
||||||
print("Registration attemp")
|
print("Registration attemp")
|
||||||
max_attempt_number -= 1
|
max_attempt_number -= 1
|
||||||
self.logger.debug('Ahenk is not registered. Attempting for registration')
|
self.logger.debug('Ahenk is not registered. Attempting for registration')
|
||||||
registration.registration_request(self.register_hostname,self.register_user_name,self.register_user_password)
|
registration.registration_request(self.register_hostname,self.register_user_name,self.register_user_password,self.register_directory_server)
|
||||||
|
if max_attempt_number < 0:
|
||||||
|
self.logger.warning('Number of Attempting for registration is over')
|
||||||
|
Util.execute("/etc/init.d/ahenk stop")
|
||||||
|
break
|
||||||
#if max_attempt_number < 0:
|
#if max_attempt_number < 0:
|
||||||
# self.logger.warning('Number of Attempting for registration is over')
|
# self.logger.warning('Number of Attempting for registration is over')
|
||||||
# self.registration_failed()
|
# self.registration_failed()
|
||||||
|
@ -240,10 +243,11 @@ 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 set_register_user(self, hostName, username, password):
|
def set_register_user(self, hostName, username, password,directoryServer):
|
||||||
self.register_hostname=hostName
|
self.register_hostname=hostName
|
||||||
self.register_user_name=username
|
self.register_user_name=username
|
||||||
self.register_user_password=password
|
self.register_user_password=password
|
||||||
|
self.register_directory_server = directoryServer
|
||||||
|
|
||||||
# if user_disabled is when ahenk service restarted TRUE disabled local users
|
# if user_disabled is when ahenk service restarted TRUE disabled local users
|
||||||
def disable_local_users(self):
|
def disable_local_users(self):
|
||||||
|
@ -349,7 +353,7 @@ if __name__ == '__main__':
|
||||||
ahenk_daemon = AhenkDaemon(System.Ahenk.pid_path())
|
ahenk_daemon = AhenkDaemon(System.Ahenk.pid_path())
|
||||||
try:
|
try:
|
||||||
if len(sys.argv) == 2 and (sys.argv[1] in ('start', 'stop', 'restart', 'status')):
|
if len(sys.argv) == 2 and (sys.argv[1] in ('start', 'stop', 'restart', 'status')):
|
||||||
ahenk_daemon.set_register_user(None, None, None)
|
ahenk_daemon.set_register_user(None, None, None, None)
|
||||||
if sys.argv[1] == 'start':
|
if sys.argv[1] == 'start':
|
||||||
if System.Ahenk.is_running() is True:
|
if System.Ahenk.is_running() is True:
|
||||||
print('There is already running Ahenk service. It will be killed.[{0}]'.format(
|
print('There is already running Ahenk service. It will be killed.[{0}]'.format(
|
||||||
|
@ -375,12 +379,13 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
print('Unknown command. Usage : %s start|stop|restart|status|clean' % sys.argv[0])
|
print('Unknown command. Usage : %s start|stop|restart|status|clean' % sys.argv[0])
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
elif len(sys.argv) > 2 and (sys.argv[1] in ('register')):
|
elif len(sys.argv) > 2 and (sys.argv[1] in ('start')):
|
||||||
params = sys.argv[1]
|
params = sys.argv[1]
|
||||||
hostName = sys.argv[2]
|
hostName = sys.argv[2]
|
||||||
userName = sys.argv[3]
|
userName = sys.argv[3]
|
||||||
password = sys.argv[4]
|
password = sys.argv[4]
|
||||||
ahenk_daemon.set_register_user(hostName,userName,password)
|
directoryServer = sys.argv[5]
|
||||||
|
ahenk_daemon.set_register_user(hostName,userName,password,directoryServer)
|
||||||
ahenk_daemon.run()
|
ahenk_daemon.run()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -73,9 +73,13 @@ class Commander(object):
|
||||||
data['event'] = 'remove'
|
data['event'] = 'remove'
|
||||||
data['plugins'] = params[3]
|
data['plugins'] = params[3]
|
||||||
|
|
||||||
elif len(params) > 1 and params[1] == 'unregister':
|
elif len(params) == 2 and params[1] == 'unregister':
|
||||||
data['event'] = params[1]
|
data['event'] = params[1]
|
||||||
|
|
||||||
|
elif len(params) == 4 and params[1] == 'unregister':
|
||||||
|
data['event'] = params[1]
|
||||||
|
data['userName'] = params[2]
|
||||||
|
data['password'] = params[3]
|
||||||
|
|
||||||
elif len(params) > 5 and params[1] == 'send':
|
elif len(params) > 5 and params[1] == 'send':
|
||||||
data['event'] = params[1]
|
data['event'] = params[1]
|
||||||
|
|
|
@ -181,12 +181,24 @@ class CommandRunner(object):
|
||||||
message = json.dumps(json_data['message'])
|
message = json.dumps(json_data['message'])
|
||||||
self.messenger.send_direct_message(message)
|
self.messenger.send_direct_message(message)
|
||||||
|
|
||||||
elif str(json_data['event']) == 'unregister':
|
elif str(json_data['event']) == 'unregister' and len(json_data)==1:
|
||||||
self.logger.info('Unregistering..')
|
self.logger.info('Unregistering..')
|
||||||
|
self.execute_manager.set_unregister_credential_params(None, None)
|
||||||
unregister_message = self.message_manager.unregister_msg()
|
unregister_message = self.message_manager.unregister_msg()
|
||||||
if unregister_message is not None:
|
if unregister_message is not None:
|
||||||
self.messenger.send_direct_message(unregister_message)
|
self.messenger.send_direct_message(unregister_message)
|
||||||
|
|
||||||
|
elif str(json_data['event']) == 'unregister' and len(json_data)==3:
|
||||||
|
self.logger.info('Unregistering..')
|
||||||
|
usernameForCheck = json_data['userName']
|
||||||
|
passwordForCheck = json_data['password']
|
||||||
|
## send user credential info to execution manager for hide user notify when remote unregister
|
||||||
|
self.execute_manager.set_unregister_credential_params(usernameForCheck,usernameForCheck)
|
||||||
|
self.logger.info('Unregistering by username+'+str(usernameForCheck))
|
||||||
|
unregister_message = self.message_manager.unregister_msg(usernameForCheck,passwordForCheck)
|
||||||
|
if unregister_message is not None:
|
||||||
|
self.messenger.send_direct_message(unregister_message)
|
||||||
|
|
||||||
elif str(json_data['event']) == 'load':
|
elif str(json_data['event']) == 'load':
|
||||||
plugin_name = str(json_data['plugins'])
|
plugin_name = str(json_data['plugins'])
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
||||||
|
import os
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -18,6 +18,7 @@ from base.scheduler.custom.schedule_job import ScheduleTaskJob
|
||||||
from base.scope import Scope
|
from base.scope import Scope
|
||||||
from base.system.system import System
|
from base.system.system import System
|
||||||
from base.util.util import Util
|
from base.util.util import Util
|
||||||
|
|
||||||
from easygui import *
|
from easygui import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -404,17 +405,27 @@ class ExecutionManager(object):
|
||||||
def unregister(self, msg):
|
def unregister(self, msg):
|
||||||
j = json.loads(msg)
|
j = json.loads(msg)
|
||||||
status = str(j['status']).lower()
|
status = str(j['status']).lower()
|
||||||
|
# user_name = self.db_service.select_one_result('session', 'username', " 1=1 order by id desc ")
|
||||||
user_name = self.db_service.select_one_result('session', 'username', " 1=1 order by id desc ")
|
# display = self.db_service.select_one_result('session', 'display', " 1=1 order by id desc ")
|
||||||
display = self.db_service.select_one_result('session', 'display', " 1=1 order by id desc ")
|
|
||||||
|
|
||||||
if 'not_authorized' == str(status):
|
if 'not_authorized' == str(status):
|
||||||
self.logger.info('Registration is failed. User not authorized')
|
self.logger.info('UnRegistration is failed. User not authorized')
|
||||||
Util.show_message(user_name,display,'Ahenk Lider MYS sisteminden çıkarmak için yetkili kullanıcı haklarına sahip olmanız gerekmektedir.',
|
if self.unregister_user_name is None:
|
||||||
|
user_name = os.getlogin()
|
||||||
|
display = Util.get_username_display()
|
||||||
|
Util.show_message(user_name, display,
|
||||||
|
'Ahenk Lider MYS sisteminden çıkarmak için yetkili kullanıcı haklarına sahip olmanız gerekmektedir.',
|
||||||
'Kullanıcı Yetkilendirme Hatası')
|
'Kullanıcı Yetkilendirme Hatası')
|
||||||
else:
|
else:
|
||||||
|
if self.unregister_user_name is None:
|
||||||
|
user_name = os.getlogin()
|
||||||
|
display = Util.get_username_display()
|
||||||
Util.show_message(user_name, display, "Ahenk Lider MYS sisteminden çıkarılmıştır.", "")
|
Util.show_message(user_name, display, "Ahenk Lider MYS sisteminden çıkarılmıştır.", "")
|
||||||
if Util.show_message(user_name, display, "Değişikliklerin etkili olması için sistem yeniden başlatılacaktır. Lütfen bekleyiniz...", "") :
|
if Util.show_message(user_name, display,
|
||||||
|
"Değişikliklerin etkili olması için sistem yeniden başlatılacaktır. Lütfen bekleyiniz...",
|
||||||
|
""):
|
||||||
|
registration = Scope.get_instance().get_registration()
|
||||||
|
registration.purge_and_unregister()
|
||||||
|
else:
|
||||||
registration = Scope.get_instance().get_registration()
|
registration = Scope.get_instance().get_registration()
|
||||||
registration.purge_and_unregister()
|
registration.purge_and_unregister()
|
||||||
|
|
||||||
|
@ -557,3 +568,7 @@ class ExecutionManager(object):
|
||||||
Util.delete_file(ahenk_policy_file)
|
Util.delete_file(ahenk_policy_file)
|
||||||
Util.create_file(ahenk_policy_file)
|
Util.create_file(ahenk_policy_file)
|
||||||
Util.write_file(ahenk_policy_file, content)
|
Util.write_file(ahenk_policy_file, content)
|
||||||
|
|
||||||
|
def set_unregister_credential_params(self, user_name=None, passwd=None):
|
||||||
|
self.unregister_user_name=user_name
|
||||||
|
self.unregister_passwd=passwd
|
||||||
|
|
|
@ -105,14 +105,15 @@ 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')
|
||||||
|
if self.registration.showUserNotify == True:
|
||||||
Util.show_message(os.getlogin(), ':0','Ahenk Lider MYS sistemine alınamadı !! Sadece yetkili kullanıcılar kayıt yapabilir.', 'Kullanıcı Yetkilendirme Hatası')
|
Util.show_message(os.getlogin(), ':0','Ahenk Lider MYS sistemine alınamadı !! Sadece yetkili kullanıcılar kayıt yapabilir.', 'Kullanıcı Yetkilendirme Hatası')
|
||||||
self.logger.debug('Disconnecting...')
|
self.logger.debug('Disconnecting...')
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
elif 'already_exists' == str(status) or 'registered' == str(status) or 'registered_without_ldap' == str(status):
|
elif 'already_exists' == str(status) or 'registered' == str(status) or 'registered_without_ldap' == str(status):
|
||||||
try:
|
try:
|
||||||
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)
|
||||||
|
if self.registration.showUserNotify == True:
|
||||||
msg = str(self.host) + " Etki Alanına hoş geldiniz."
|
msg = str(self.host) + " Etki Alanına hoş geldiniz."
|
||||||
Util.show_message(os.getlogin(), ':0' ,msg, "UYARI")
|
Util.show_message(os.getlogin(), ':0' ,msg, "UYARI")
|
||||||
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...."
|
||||||
|
@ -124,17 +125,16 @@ class AnonymousMessenger(ClientXMPP):
|
||||||
#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)
|
||||||
Util.shutdown();
|
Util.shutdown();
|
||||||
|
|
||||||
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)))
|
||||||
|
if self.registration.showUserNotify == True:
|
||||||
Util.show_message(os.getlogin(), ':0',str(e))
|
Util.show_message(os.getlogin(), ':0',str(e))
|
||||||
self.logger.debug('Disconnecting...')
|
self.logger.debug('Disconnecting...')
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
|
|
||||||
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))
|
||||||
|
if self.registration.showUserNotify == True:
|
||||||
Util.show_message(os.getlogin(), ':0','Ahenk Lider MYS sistemine alınamadı !! Kayıt esnasında hata oluştu. Lütfen sistem yöneticinize başvurunuz.',
|
Util.show_message(os.getlogin(), ':0','Ahenk Lider MYS sistemine 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...')
|
||||||
|
|
|
@ -164,30 +164,29 @@ class Messaging(object):
|
||||||
self.logger.debug('LDAP Registration message was created')
|
self.logger.debug('LDAP Registration message was created')
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
def unregister_msg(self):
|
def unregister_msg(self,usernameForCheck,passwordForCheck):
|
||||||
|
|
||||||
user_name = self.db_service.select_one_result('session', 'username')
|
|
||||||
display = self.db_service.select_one_result('session', 'display')
|
|
||||||
|
|
||||||
self.logger.debug('User : ' + str(user_name))
|
|
||||||
|
|
||||||
pout = Util.show_unregistration_message(user_name,display,
|
|
||||||
'Makineyi etki alanından çıkarmak için zorunlu alanları giriniz. Lütfen DEVAM EDEN İŞLEMLERİNİZİ sonlandırdığınıza emin olunuz !',
|
|
||||||
'ETKI ALANINDAN ÇIKARMA')
|
|
||||||
|
|
||||||
self.logger.debug('pout : ' + str(pout))
|
|
||||||
|
|
||||||
field_values = pout.split(' ')
|
|
||||||
|
|
||||||
user_registration_info = list(field_values)
|
|
||||||
|
|
||||||
data = dict()
|
data = dict()
|
||||||
data['type'] = 'UNREGISTER'
|
data['type'] = 'UNREGISTER'
|
||||||
data['from'] = str(self.conf_manager.get('CONNECTION', 'uid'))
|
data['from'] = str(self.conf_manager.get('CONNECTION', 'uid'))
|
||||||
data['password'] = str(self.conf_manager.get('CONNECTION', 'password'))
|
data['password'] = str(self.conf_manager.get('CONNECTION', 'password'))
|
||||||
|
# unregistration from commandline..
|
||||||
|
if(usernameForCheck==None and passwordForCheck==None):
|
||||||
|
#user_name = self.db_service.select_one_result('session', 'username')
|
||||||
|
#display = self.db_service.select_one_result('session', 'display')
|
||||||
|
user_name = os.getlogin()
|
||||||
|
display = Util.get_username_display()
|
||||||
|
self.logger.debug('User : ' + str(user_name))
|
||||||
|
pout = Util.show_unregistration_message(user_name,display,
|
||||||
|
'Makineyi etki alanından çıkarmak için zorunlu alanları giriniz. Lütfen DEVAM EDEN İŞLEMLERİNİZİ sonlandırdığınıza emin olunuz !',
|
||||||
|
'ETKI ALANINDAN ÇIKARMA')
|
||||||
|
self.logger.debug('pout : ' + str(pout))
|
||||||
|
field_values = pout.split(' ')
|
||||||
|
user_registration_info = list(field_values)
|
||||||
data['userName'] = user_registration_info[0];
|
data['userName'] = user_registration_info[0];
|
||||||
data['userPassword'] = user_registration_info[1];
|
data['userPassword'] = user_registration_info[1];
|
||||||
|
else:
|
||||||
|
data['userName'] = usernameForCheck;
|
||||||
|
data['userPassword'] = passwordForCheck;
|
||||||
|
|
||||||
#data['macAddresses'] = str(self.conf_manager.get('REGISTRATION', 'macAddresses'))
|
#data['macAddresses'] = str(self.conf_manager.get('REGISTRATION', 'macAddresses'))
|
||||||
#data['ipAddresses'] = str(self.conf_manager.get('REGISTRATION', 'ipAddresses'))
|
#data['ipAddresses'] = str(self.conf_manager.get('REGISTRATION', 'ipAddresses'))
|
||||||
|
|
|
@ -21,5 +21,5 @@ krb5_store_password_if_offline = True
|
||||||
default_shell = /bin/bash
|
default_shell = /bin/bash
|
||||||
ldap_id_mapping = True
|
ldap_id_mapping = True
|
||||||
use_fully_qualified_names = False
|
use_fully_qualified_names = False
|
||||||
fallback_homedir = /home/%u@%d
|
fallback_homedir = /home/%u
|
||||||
access_provider = ad
|
access_provider = ad
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Registration:
|
||||||
else:
|
else:
|
||||||
self.register(True)
|
self.register(True)
|
||||||
|
|
||||||
def registration_request(self, hostname,username,password):
|
def registration_request(self, hostname,username,password,directoryserver):
|
||||||
|
|
||||||
self.logger.debug('Requesting registration')
|
self.logger.debug('Requesting registration')
|
||||||
# SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,checker_func=self.is_registered, kwargs=None))
|
# SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,checker_func=self.is_registered, kwargs=None))
|
||||||
|
@ -60,9 +60,11 @@ class Registration:
|
||||||
self.host = hostname
|
self.host = hostname
|
||||||
self.user_name = username
|
self.user_name = username
|
||||||
self.user_password= password
|
self.user_password= password
|
||||||
|
self.directory_server = directoryserver
|
||||||
|
self.showUserNotify = False;
|
||||||
|
|
||||||
if(username is None and password is None and self.host is None ):
|
if(username is None and password is None and self.host is None ):
|
||||||
|
self.showUserNotify = True;
|
||||||
self.host = self.conf_manager.get("CONNECTION", "host")
|
self.host = self.conf_manager.get("CONNECTION", "host")
|
||||||
|
|
||||||
user_name= os.getlogin()
|
user_name= os.getlogin()
|
||||||
|
@ -490,6 +492,7 @@ class Registration:
|
||||||
|
|
||||||
config.set('CONNECTION', 'uid', '')
|
config.set('CONNECTION', 'uid', '')
|
||||||
config.set('CONNECTION', 'password', '')
|
config.set('CONNECTION', 'password', '')
|
||||||
|
config.set('CONNECTION', 'host', '')
|
||||||
config.set('MACHINE', 'user_disabled', 'false')
|
config.set('MACHINE', 'user_disabled', 'false')
|
||||||
|
|
||||||
with open(System.Ahenk.config_path(), 'w') as file:
|
with open(System.Ahenk.config_path(), 'w') as file:
|
||||||
|
|
Loading…
Reference in a new issue