mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
Syncing /usr/share/ahenk to src and recreating ahenk.install
This commit is contained in:
parent
2b1591e74e
commit
4a0abf633b
9 changed files with 71 additions and 90 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 = 4
|
max_attempt_number = 2
|
||||||
# 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()
|
||||||
|
|
|
@ -31,11 +31,12 @@ class AskRegister():
|
||||||
|
|
||||||
tk.Label(self.master, text="* Yetkili Kullanıcı : ").grid(row=1)
|
tk.Label(self.master, text="* Yetkili Kullanıcı : ").grid(row=1)
|
||||||
tk.Label(self.master, text="* Parola : ").grid(row=2)
|
tk.Label(self.master, text="* Parola : ").grid(row=2)
|
||||||
tk.Label(self.master, textvariable= self.text, fg="red").grid(row=3,columnspan=2)
|
|
||||||
|
|
||||||
self.e2 = tk.Entry(self.master)
|
self.e2 = tk.Entry(self.master)
|
||||||
self.e3 = tk.Entry(show="*")
|
self.e3 = tk.Entry(show="*")
|
||||||
|
|
||||||
|
tk.Label(self.master, textvariable=self.text, fg="red").grid(row=3, columnspan=2)
|
||||||
# self.var1 = IntVar()
|
# self.var1 = IntVar()
|
||||||
# Checkbutton(self.master, text="Active Directory", variable=self.var1, command=self.check1).grid(row=3, column=0, stick=tk.W,
|
# Checkbutton(self.master, text="Active Directory", variable=self.var1, command=self.check1).grid(row=3, column=0, stick=tk.W,
|
||||||
# pady=4)
|
# pady=4)
|
||||||
|
|
|
@ -130,7 +130,7 @@ class CommandRunner(object):
|
||||||
agreement_choice = True
|
agreement_choice = True
|
||||||
|
|
||||||
if agreement_choice is True or System.Ahenk.agreement() != '1':
|
if agreement_choice is True or System.Ahenk.agreement() != '1':
|
||||||
self.db_service.delete('session', 'username=\'{0}\''.format(username))
|
self.db_service.delete('session', '1=1')
|
||||||
|
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
'Display is {0}, desktop env is {1} for {2}'.format(display, desktop,
|
'Display is {0}, desktop env is {1} for {2}'.format(display, desktop,
|
||||||
|
|
|
@ -405,6 +405,7 @@ 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()
|
||||||
|
directory_server = str(j['directoryServer'])
|
||||||
# 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):
|
||||||
|
@ -428,10 +429,10 @@ class ExecutionManager(object):
|
||||||
"Değişikliklerin etkili olması için sistem yeniden başlatılacaktır. Lütfen bekleyiniz...",
|
"Değişikliklerin etkili olması için sistem yeniden başlatılacaktır. Lütfen bekleyiniz...",
|
||||||
""):
|
""):
|
||||||
registration = Scope.get_instance().get_registration()
|
registration = Scope.get_instance().get_registration()
|
||||||
registration.purge_and_unregister()
|
registration.purge_and_unregister(directory_server)
|
||||||
else:
|
else:
|
||||||
registration = Scope.get_instance().get_registration()
|
registration = Scope.get_instance().get_registration()
|
||||||
registration.purge_and_unregister()
|
registration.purge_and_unregister(directory_server)
|
||||||
|
|
||||||
|
|
||||||
def json_to_task_bean(self, json_data, file_server_conf=None):
|
def json_to_task_bean(self, json_data, file_server_conf=None):
|
||||||
|
|
|
@ -187,8 +187,11 @@ class Messaging(object):
|
||||||
self.logger.debug('pout : ' + str(pout))
|
self.logger.debug('pout : ' + str(pout))
|
||||||
field_values = pout.split(' ')
|
field_values = pout.split(' ')
|
||||||
user_registration_info = list(field_values)
|
user_registration_info = list(field_values)
|
||||||
data['userName'] = user_registration_info[0];
|
if len(user_registration_info) > 1 :
|
||||||
data['userPassword'] = user_registration_info[1];
|
data['userName'] = user_registration_info[0];
|
||||||
|
data['userPassword'] = user_registration_info[1];
|
||||||
|
else:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
data['userName'] = usernameForCheck;
|
data['userName'] = usernameForCheck;
|
||||||
data['userPassword'] = passwordForCheck;
|
data['userPassword'] = passwordForCheck;
|
||||||
|
|
|
@ -534,6 +534,7 @@ class Registration:
|
||||||
self.util.execute(change_home.format(new_home_dir, new_username))
|
self.util.execute(change_home.format(new_home_dir, new_username))
|
||||||
self.logger.debug("User: '{0}' will be enabled and changed username and home directory of username".format(p.pw_name))
|
self.logger.debug("User: '{0}' will be enabled and changed username and home directory of username".format(p.pw_name))
|
||||||
|
|
||||||
|
|
||||||
def disable_local_users(self):
|
def disable_local_users(self):
|
||||||
passwd_cmd = 'passwd -l {}'
|
passwd_cmd = 'passwd -l {}'
|
||||||
change_home = 'usermod -m -d {0} {1}'
|
change_home = 'usermod -m -d {0} {1}'
|
||||||
|
@ -557,7 +558,6 @@ class Registration:
|
||||||
Util.execute(change_home.format(new_home_dir, new_username))
|
Util.execute(change_home.format(new_home_dir, new_username))
|
||||||
Util.execute(change_permisson.format(new_home_dir))
|
Util.execute(change_permisson.format(new_home_dir))
|
||||||
|
|
||||||
|
|
||||||
def change_permissions_for_local_users(self):
|
def change_permissions_for_local_users(self):
|
||||||
add_user_conf_file = "/etc/adduser.conf"
|
add_user_conf_file = "/etc/adduser.conf"
|
||||||
file_dir_mode = open(add_user_conf_file, 'r')
|
file_dir_mode = open(add_user_conf_file, 'r')
|
||||||
|
|
|
@ -339,7 +339,6 @@ class Util:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def send_notify(title, body, display, user, icon=None, timeout=5000):
|
def send_notify(title, body, display, user, icon=None, timeout=5000):
|
||||||
|
|
||||||
inner_command = 'notify-send "{0}" "{1}" -t {2}'.format(title, body, timeout)
|
inner_command = 'notify-send "{0}" "{1}" -t {2}'.format(title, body, timeout)
|
||||||
if icon:
|
if icon:
|
||||||
inner_command += ' -i {0}'.format(icon)
|
inner_command += ' -i {0}'.format(icon)
|
||||||
|
@ -350,15 +349,14 @@ class Util:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def show_message(username, display, message='', title=''):
|
def show_message(username, display, message='', title=''):
|
||||||
ask_path = Util.get_ask_path_file()+ 'confirm.py'
|
ask_path = Util.get_ask_path_file()+ 'confirm.py'
|
||||||
|
|
||||||
Scope.get_instance().get_logger().debug('DISPLAYYYY --------->>>>>>>>: ' + str(display))
|
Scope.get_instance().get_logger().debug('DISPLAYYYY --------->>>>>>>>: ' + str(display))
|
||||||
|
|
||||||
if display is None:
|
if display is None:
|
||||||
display_number = Util.get_username_display()
|
display_number = Util.get_username_display()
|
||||||
else:
|
else:
|
||||||
display_number = display
|
display_number = display
|
||||||
try:
|
try:
|
||||||
|
if Util.get_desktop_env() == "gnome":
|
||||||
|
display_number = Util.get_username_display_gnome(username)
|
||||||
if username is not None:
|
if username is not None:
|
||||||
command = 'su - {0} -c \'python3 {1} \"{2}\" \"{3}\" \"{4}\"\''.format(username, ask_path, message,
|
command = 'su - {0} -c \'python3 {1} \"{2}\" \"{3}\" \"{4}\"\''.format(username, ask_path, message,
|
||||||
title, display_number)
|
title, display_number)
|
||||||
|
@ -370,24 +368,21 @@ class Util:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
print("Error when showing message " + str(e))
|
print("Error when showing message " + str(e))
|
||||||
|
|
||||||
return None
|
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 = Util.get_ask_path_file() + 'ahenkmessage.py'
|
||||||
ask_path = Util.get_ask_path_file()+ 'ahenkmessage.py'
|
|
||||||
|
|
||||||
# display_number = ":0"
|
# display_number = ":0"
|
||||||
display_number = Util.get_username_display()
|
display_number = Util.get_username_display()
|
||||||
|
|
||||||
|
if Util.get_desktop_env() == "gnome":
|
||||||
|
display_number = Util.get_username_display_gnome(login_user_name)
|
||||||
|
|
||||||
if host is None:
|
if host is None:
|
||||||
command = 'su - {0} -c \"python3 {1} \'{2}\' \'{3}\' \'{4}\' \"'.format(login_user_name,
|
command = 'su - {0} -c \"python3 {1} \'{2}\' \'{3}\' \'{4}\' \"'.format(login_user_name,
|
||||||
ask_path, message, title, display_number)
|
ask_path, message, title, display_number)
|
||||||
|
@ -397,27 +392,23 @@ class Util:
|
||||||
message, title,
|
message, title,
|
||||||
host, display_number)
|
host, display_number)
|
||||||
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', '')
|
||||||
|
|
||||||
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):
|
||||||
|
|
||||||
ask_path = Util.get_ask_path_file()+ 'unregistrationmessage.py'
|
ask_path = Util.get_ask_path_file()+ 'unregistrationmessage.py'
|
||||||
|
if Util.get_desktop_env() == "gnome":
|
||||||
|
display_number = Util.get_username_display_gnome(login_user_name)
|
||||||
|
|
||||||
command = 'su - {0} -c \"python3 {1} \'{2}\' \'{3}\' \'{4}\' \"'.format(login_user_name, ask_path, message, title, display_number)
|
command = 'su - {0} -c \"python3 {1} \'{2}\' \'{3}\' \'{4}\' \"'.format(login_user_name, ask_path, message, title, display_number)
|
||||||
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', '')
|
||||||
|
|
||||||
return pout
|
return pout
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_username_display():
|
def get_username_display():
|
||||||
result_code, p_out, p_err = Util.execute("who | awk '{print $1, $5}' | sed 's/(://' | sed 's/)//'", result=True)
|
result_code, p_out, p_err = Util.execute("who | awk '{print $1, $5}' | sed 's/(://' | sed 's/)//'", result=True)
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
lines = str(p_out).split('\n')
|
lines = str(p_out).split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|
|
@ -1,66 +1,44 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: Edip YILDIZ
|
# Author: Hasan Kara <hasankara@pardus.org.tr>
|
||||||
# Author: Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
|
|
||||||
|
|
||||||
|
|
||||||
from base.model.enum.content_type import ContentType
|
from base.model.enum.content_type import ContentType
|
||||||
import json, threading
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from base.scope import Scope
|
||||||
from base.plugin.abstract_plugin import AbstractPlugin
|
from base.plugin.abstract_plugin import AbstractPlugin
|
||||||
|
from base.registration.registration import Registration
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
class MoveAgent(AbstractPlugin):
|
class DeleteAgent(AbstractPlugin):
|
||||||
def __init__(self, data, context):
|
def __init__(self, data, context):
|
||||||
super(AbstractPlugin, self).__init__()
|
super(AbstractPlugin, self).__init__()
|
||||||
|
scope = Scope.get_instance()
|
||||||
self.data = data
|
self.data = data
|
||||||
self.context = context
|
self.context = context
|
||||||
self.logger = self.get_logger()
|
self.logger = self.get_logger()
|
||||||
self.message_code = self.get_message_code()
|
self.message_code = self.get_message_code()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_dn(self, jid, newDn):
|
|
||||||
cols = ['dn'];
|
|
||||||
values = [newDn]
|
|
||||||
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getCnFromDn(self,dn):
|
|
||||||
if dn !=None and str(dn) !="":
|
|
||||||
dnStrArr = str(dn).split(",")
|
|
||||||
if len(dnStrArr)>0:
|
|
||||||
return dnStrArr[0]
|
|
||||||
|
|
||||||
|
|
||||||
def handle_task(self):
|
def handle_task(self):
|
||||||
try:
|
try:
|
||||||
dn = self.data['dn']
|
dn = self.data['dn']
|
||||||
newParentDn = self.data['newParentDn']
|
directory_server = self.data['directory_server']
|
||||||
|
registration = Scope.get_instance().get_registration()
|
||||||
jid= self.db_service.select_one_result('registration','jid','registered = 1')
|
registration.purge_and_unregister(directory_server)
|
||||||
|
|
||||||
newDn=str(dn).replace(dn, self.getCnFromDn(dn)+ str(newParentDn))
|
|
||||||
|
|
||||||
self.update_dn(jid,newDn)
|
|
||||||
|
|
||||||
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
||||||
message='Ahenk başarı ile taşındı.',
|
message='Ahenk başarı ile silindi.',
|
||||||
data=json.dumps({'Dn': newDn}),
|
data=json.dumps({'Dn': dn}),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(" error on handle xmessage task. Error: " + str(e))
|
self.logger.error(" error on handle deleting agent. Error: " + str(e))
|
||||||
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
||||||
message='Ahenk taşınırken hata olustu' + str(e),
|
message='Ahenk silinirken hata olustu' + str(e),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
def handle_task(task, context):
|
def handle_task(task, context):
|
||||||
cls = MoveAgent(task, context)
|
cls = DeleteAgent(task, context)
|
||||||
cls.handle_task()
|
cls.handle_task()
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: Edip YILDIZ
|
# Author: Hasan Kara <hasankara@pardus.org.tr>
|
||||||
# Author: Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
|
|
||||||
|
|
||||||
|
|
||||||
from base.model.enum.content_type import ContentType
|
from base.model.enum.content_type import ContentType
|
||||||
import json, threading
|
import json
|
||||||
|
|
||||||
|
|
||||||
from base.plugin.abstract_plugin import AbstractPlugin
|
from base.plugin.abstract_plugin import AbstractPlugin
|
||||||
|
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
class MoveAgent(AbstractPlugin):
|
class MoveAgent(AbstractPlugin):
|
||||||
def __init__(self, data, context):
|
def __init__(self, data, context):
|
||||||
|
@ -21,46 +17,57 @@ class MoveAgent(AbstractPlugin):
|
||||||
self.logger = self.get_logger()
|
self.logger = self.get_logger()
|
||||||
self.message_code = self.get_message_code()
|
self.message_code = self.get_message_code()
|
||||||
|
|
||||||
|
def update_dn(self, jid, new_dn):
|
||||||
|
cols = ['dn']
|
||||||
def update_dn(self, jid, newDn):
|
values = [new_dn]
|
||||||
cols = ['dn'];
|
|
||||||
values = [newDn]
|
|
||||||
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
return self.db_service.update('registration', cols, values, 'jid=\''+jid+'\'')
|
||||||
|
|
||||||
|
def get_cn_from_dn(self, dn):
|
||||||
|
if dn != None and str(dn) != "":
|
||||||
def getCnFromDn(self,dn):
|
dn_str_arr = str(dn).split(",")
|
||||||
if dn !=None and str(dn) !="":
|
if len(dn_str_arr) > 0:
|
||||||
dnStrArr = str(dn).split(",")
|
return dn_str_arr[0]
|
||||||
if len(dnStrArr)>0:
|
|
||||||
return dnStrArr[0]
|
|
||||||
|
|
||||||
|
|
||||||
def handle_task(self):
|
def handle_task(self):
|
||||||
try:
|
try:
|
||||||
dn = self.data['dn']
|
dn = self.data['dn']
|
||||||
newParentDn = self.data['newParentDn']
|
new_parent_dn = self.data['new_parent_dn']
|
||||||
|
directory_server = self.data['directory_server']
|
||||||
|
|
||||||
jid= self.db_service.select_one_result('registration','jid','registered = 1')
|
jid = self.db_service.select_one_result('registration', 'jid', 'registered = 1')
|
||||||
|
new_dn = str(dn).replace(dn, self.get_cn_from_dn(dn) + ',' + str(new_parent_dn))
|
||||||
|
self.update_dn(jid, new_dn)
|
||||||
|
|
||||||
newDn=str(dn).replace(dn, self.getCnFromDn(dn)+ str(newParentDn))
|
if directory_server == "LDAP":
|
||||||
|
# update SSSD conf agent DN
|
||||||
|
sssd_config_file_path = "/etc/sssd/sssd.conf"
|
||||||
|
file_sssd = open(sssd_config_file_path, 'r')
|
||||||
|
file_data = file_sssd.read()
|
||||||
|
old_dn_in_sssd = ""
|
||||||
|
new_dn_in_sssd = "ldap_default_bind_dn = " + new_dn + "\n"
|
||||||
|
with open(sssd_config_file_path) as fp:
|
||||||
|
for line in fp:
|
||||||
|
if line.startswith('ldap_default_bind_dn'):
|
||||||
|
old_dn_in_sssd = line
|
||||||
|
file_data = file_data.replace(old_dn_in_sssd, new_dn_in_sssd)
|
||||||
|
|
||||||
self.update_dn(jid,newDn)
|
file_sssd.close()
|
||||||
|
file_sssd = open(sssd_config_file_path, 'w')
|
||||||
|
file_sssd.write(file_data)
|
||||||
|
file_sssd.close()
|
||||||
|
|
||||||
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
|
||||||
message='Ahenk başarı ile taşındı.',
|
message='Ahenk başarı ile taşındı.',
|
||||||
data=json.dumps({'Dn': newDn}),
|
data=json.dumps({'Dn': new_dn}),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(" error on handle xmessage task. Error: " + str(e))
|
self.logger.error("Error occured while moving agent. Error: " + str(e))
|
||||||
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
self.context.create_response(code=self.message_code.TASK_ERROR.value,
|
||||||
message='Ahenk taşınırken hata olustu' + str(e),
|
message='Ahenk taşınırken hata olustu' + str(e),
|
||||||
content_type=ContentType.APPLICATION_JSON.value)
|
content_type=ContentType.APPLICATION_JSON.value)
|
||||||
|
|
||||||
|
|
||||||
def handle_task(task, context):
|
def handle_task(task, context):
|
||||||
cls = MoveAgent(task, context)
|
cls = MoveAgent(task, context)
|
||||||
cls.handle_task()
|
cls.handle_task()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue