Syncing /usr/share/ahenk to src and recreating ahenk.install

This commit is contained in:
Tuncay ÇOLAK 2020-10-27 14:40:52 +03:00
parent 5cb3ae46f5
commit 0a655e5441
10 changed files with 121 additions and 24 deletions

View file

@ -166,6 +166,8 @@ usr/share/ahenk/plugins/service/service_list.py
usr/share/ahenk/plugins/service/main.py usr/share/ahenk/plugins/service/main.py
usr/share/ahenk/plugins/service/get_services.py usr/share/ahenk/plugins/service/get_services.py
usr/share/ahenk/plugins/service usr/share/ahenk/plugins/service
usr/share/ahenk/plugins/resource-usage/agent_info.py
usr/share/ahenk/plugins/resource-usage/agent_info
usr/share/ahenk/plugins/resource-usage/main.py usr/share/ahenk/plugins/resource-usage/main.py
usr/share/ahenk/plugins/resource-usage/resource_info_alert.py usr/share/ahenk/plugins/resource-usage/resource_info_alert.py
usr/share/ahenk/plugins/resource-usage/send_mail.py usr/share/ahenk/plugins/resource-usage/send_mail.py

View file

@ -45,8 +45,9 @@ class CommandRunner(object):
self.logger.info('Ahenk polkit file not found') self.logger.info('Ahenk polkit file not found')
else: else:
Util.delete_file(ahenk_policy_file) Util.delete_file(ahenk_policy_file)
Util.write_file(ahenk_policy_file, content) self.logger.info("Delete polkit file")
self.logger.info('Root added ahenk polkit file') # Util.write_file(ahenk_policy_file, content)
# self.logger.info('Root added ahenk polkit file')
def run_command_from_fifo(self, num, stack): def run_command_from_fifo(self, num, stack):
""" docstring""" """ docstring"""

View file

@ -78,6 +78,7 @@ class Messaging(object):
data['diskFree'] = System.Hardware.Disk.free() data['diskFree'] = System.Hardware.Disk.free()
data['memory'] = System.Hardware.Memory.total() data['memory'] = System.Hardware.Memory.total()
data['hostname'] = str(System.Os.hostname()) data['hostname'] = str(System.Os.hostname())
data['agentVersion'] = str(Util.get_agent_version())
self.logger.debug('USER IP : '+ str(ip)+ ' IPADDRESSES : '+ str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', '')) self.logger.debug('USER IP : '+ str(ip)+ ' IPADDRESSES : '+ str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''))

View file

@ -281,6 +281,7 @@ class Registration:
'hardware.baseboard.serialNumber': System.Hardware.BaseBoard.serial_number()[1].replace('\n', '') if 'hardware.baseboard.serialNumber': System.Hardware.BaseBoard.serial_number()[1].replace('\n', '') if
System.Hardware.BaseBoard.serial_number()[0] == 0 else 'n/a', System.Hardware.BaseBoard.serial_number()[0] == 0 else 'n/a',
'processor': System.Hardware.Cpu.brand(), 'processor': System.Hardware.Cpu.brand(),
'agentVersion': Util.get_agent_version(),
} }
return json.dumps(params) return json.dumps(params)

View file

@ -7,8 +7,8 @@ ad_host_name=$2
echo "samba-common samba-common/workgroup string WORKGROUP" | sudo debconf-set-selections echo "samba-common samba-common/workgroup string WORKGROUP" | sudo debconf-set-selections
echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections
echo "samba-common samba-common/do_debconf boolean true" | sudo debconf-set-selections echo "samba-common samba-common/do_debconf boolean true" | sudo debconf-set-selections
apt-get -y install samba-common #apt-get -y install samba-common
DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" samba-common
cat > /root/debconf-krb5.conf <<EOF cat > /root/debconf-krb5.conf <<EOF

View file

@ -488,3 +488,13 @@ class Util:
return pwd.getpwnam(username).pw_gid return pwd.getpwnam(username).pw_gid
except: except:
raise raise
@staticmethod
def get_agent_version():
result_code, result, p_err = Util.execute('dpkg -s {} | grep Version'.format("ahenk"))
data = result.split(': ')
if data[0] == 'Version':
version = data[1].strip('\n')
return version
else:
return None

View file

@ -20,6 +20,7 @@ class RenameEntry(AbstractPlugin):
self.message_code = self.get_message_code() self.message_code = self.get_message_code()
self.conf_manager = scope.get_configuration_manager() self.conf_manager = scope.get_configuration_manager()
self.hostname_file = '/etc/hostname' self.hostname_file = '/etc/hostname'
self.hosts_file = '/etc/hosts'
def update_dn(self, old_cn, new_cn, new_dn): def update_dn(self, old_cn, new_cn, new_dn):
return self.db_service.update('registration', ['jid', 'dn'], [new_cn, new_dn], ' jid = ' + '\'' + old_cn + '\'') return self.db_service.update('registration', ['jid', 'dn'], [new_cn, new_dn], ' jid = ' + '\'' + old_cn + '\'')
@ -32,14 +33,37 @@ class RenameEntry(AbstractPlugin):
new_cn = self.data['new_cn'] new_cn = self.data['new_cn']
directory_server = self.data['directory_server'] directory_server = self.data['directory_server']
new_dn = str(old_dn).replace(old_cn, new_cn) new_dn = str(old_dn).replace(old_cn, new_cn)
self.logger.debug('Renaming hostname from: ' + old_cn + " to: " + new_cn) self.logger.debug('Renaming hostname from: ' + old_cn + " to: " + new_cn)
self.write_file(self.hostname_file, new_cn) self.write_file(self.hostname_file, new_cn)
## update agent db ## update /etc/hosts file
hosts_file = open (self.hosts_file, 'r')
file_data = hosts_file.read()
old_hostname_line = ""
new_hostname_line = ""
with open(self.hosts_file) as fp:
line = fp.readline()
while line:
if line.strip().startswith("127.0.1.1"):
old_hostname_line = line
new_hostname_line = line.replace(old_cn, new_cn)
break
line = fp.readline()
file_data = file_data.replace(old_hostname_line, new_hostname_line)
hosts_file.close()
hosts_file = open(self.hosts_file, 'w')
hosts_file.write(file_data)
hosts_file.close()
self.logger.info("/etc/hosts file is updated.")
## update agent db
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(old_dn).replace(old_cn, new_cn) new_dn = str(old_dn).replace(old_cn, new_cn)
self.update_dn(old_cn, new_cn, new_dn) self.update_dn(old_cn, new_cn, new_dn)
if directory_server == "LDAP": if directory_server == "LDAP":
# update SSSD conf agent DN # update SSSD conf agent DN
@ -63,7 +87,7 @@ class RenameEntry(AbstractPlugin):
self.conf_manager.set('CONNECTION', 'uid', new_cn) self.conf_manager.set('CONNECTION', 'uid', new_cn)
with open('/etc/ahenk/ahenk.conf', 'w') as configfile: with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
self.conf_manager.write(configfile) self.conf_manager.write(configfile)
self.context.create_response(code=self.message_code.TASK_PROCESSED.value, self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='Ahenk adı başarı ile değiştirildi.', message='Ahenk adı başarı ile değiştirildi.',
data=json.dumps({'Dn': new_dn}), data=json.dumps({'Dn': new_dn}),

View file

@ -68,38 +68,40 @@ class SetupVnc(AbstractPlugin):
if desktop_env == "gnome": if desktop_env == "gnome":
display_number = self.get_username_display_gnome(user_name) display_number = self.get_username_display_gnome(user_name)
self.logger.info("Get display of {0} is {1}".format(user_name, display_number)) self.logger.info("Get display of {0} is {1}".format(user_name, display_number))
homedir = self.get_homedir(user_name) #homedir = self.get_homedir(user_name)
self.logger.info("Get home directory of {0} is {1}".format(user_name, homedir)) #self.logger.info("Get home directory of {0} is {1}".format(user_name, homedir))
# this user_name for execute method # this user_name for execute method
user_name = self.get_as_user() user_name = self.get_as_user()
self.logger.debug('Username:{0} Display:{1}'.format(user_name, display_number)) self.logger.debug('Username:{0} Display:{1}'.format(user_name, display_number))
if self.is_exist('{0}/.vncahenk{1}'.format(homedir, user_name)) is True: #if self.is_exist('{0}/.vncahenk{1}'.format(homedir, user_name)) is True:
self.delete_folder('{0}/.vncahenk{1}'.format(homedir, user_name)) # self.delete_folder('{0}/.vncahenk{1}'.format(homedir, user_name))
self.logger.debug('Cleaning previous configurations.') # self.logger.debug('Cleaning previous configurations.')
self.logger.debug('Creating user VNC conf file as user') #self.logger.debug('Creating user VNC conf file as user')
self.execute('su - {0} -c "mkdir -p {1}/.vncahenk{0}"'.format(user_name, homedir), result=False) #self.execute('su - {0} -c "mkdir -p {1}/.vncahenk{0}"'.format(user_name, homedir), result=False)
self.logger.debug('Creating password as user') #self.logger.debug('Creating password as user')
self.execute('su - {0} -c "x11vnc -storepasswd {1} {2}/.vncahenk{3}/x11vncpasswd"'.format(user_name, self.password, homedir, #self.execute('su - {0} -c "x11vnc -storepasswd {1} {2}/.vncahenk{3}/x11vncpasswd"'.format(user_name, self.password, homedir,user_name), result=False)
user_name), result=False)
self.logger.debug('Running VNC server as user.') self.logger.debug('Running VNC server as user.')
if self.data['permission'] == "yes": if self.data['permission'] == "yes":
self.send_notify("Liderahenk", self.send_notify("Liderahenk",
"Lider Ahenk Sistem Yoneticisi tarafindan\n5 sn sonra bilgisayarınıza uzak erişim sağlanacaktır.\nBağlantı kapatıldıktan sonra ayrıca bilgilendirilecektir.", "Lider Ahenk Sistem Yoneticisi tarafindan\n5 sn sonra bilgisayarınıza uzak erişim sağlanacaktır.\nBağlantı kapatıldıktan sonra ayrıca bilgilendirilecektir.",
display_number, user_name, timeout=50000) display_number, user_name, timeout=50000)
time.sleep(5) time.sleep(5)
self.execute('su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -rfbauth {2}/.vncahenk{0}/x11vncpasswd -o {2}/.vncahenk{3}/vnc.log -display {4}"'.format( # self.execute('su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -o {2}/.vncahenk{3}/vnc.log -display {4}"'.format(
user_name, self.port, homedir, user_name, display_number), result=False) # user_name, self.port, user_name, display_number), result=False)
self.execute(
'su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -display {3}"'.format(
user_name, self.port, self.password, display_number), result=False)
elif self.data["permission"] == "no": elif self.data["permission"] == "no":
self.logger.info("Lider Ahenk sistem yöneticisi 5 sn sonra bilgisayarınıza uzak erişim sağlayacaktır. ") self.logger.info("Lider Ahenk sistem yöneticisi 5 sn sonra bilgisayarınıza uzak erişim sağlayacaktır. ")
self.send_notify("Liderahenk", self.send_notify("Liderahenk",
"Lider Ahenk Sistem Yoneticisi tarafindan\n5 sn sonra bilgisayarınıza uzak erişim sağlanacaktır.\nBağlantı kapatıldıktan sonra ayrıca bilgilendirilecektir.", "Lider Ahenk Sistem Yoneticisi tarafindan\n5 sn sonra bilgisayarınıza uzak erişim sağlanacaktır.\nBağlantı kapatıldıktan sonra ayrıca bilgilendirilecektir.",
display_number, user_name, timeout=50000) display_number, user_name, timeout=50000)
time.sleep(5) time.sleep(2)
self.execute('su - {0} -c "x11vnc -gone \'popup\' -rfbport {1} -rfbauth {2}/.vncahenk{0}/x11vncpasswd -o {2}/.vncahenk{3}/vnc.log -display {4}"'.format( self.execute('su - {0} -c "x11vnc -gone \'popup\' -rfbport {1} -passwd {2} -display {3}"'.format(
user_name, self.port, homedir, user_name, display_number), result=False) user_name, self.port, self.password, display_number), result=False)
else: else:
self.execute('su - {0} -c "x11vnc -rfbport {1} -rfbauth {2}/.vncahenk{0}/x11vncpasswd -o {2}/.vncahenk{3}/vnc.log -display {4}"'.format( self.execute('su - {0} -c "x11vnc -rfbport {1} -passwd {2} -display {3}"'.format(
user_name, self.port, homedir, user_name, display_number), result=False) user_name, self.port, self.password, display_number), result=False)
self.logger.info("Lider Ahenk sistem yöneticisi tarafından kullanıcı izni ve bildirim gerektirmeksizin uzak erişim sağlanmıştır") self.logger.info("Lider Ahenk sistem yöneticisi tarafından kullanıcı izni ve bildirim gerektirmeksizin uzak erişim sağlanmıştır")
def create_password(self, pass_range): def create_password(self, pass_range):

View file

@ -0,0 +1,56 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
from base.plugin.abstract_plugin import AbstractPlugin
import json
class AgentInfo(AbstractPlugin):
def __init__(self, data, context):
super(AbstractPlugin, self).__init__()
self.data = data
self.context = context
self.logger = self.get_logger()
self.message_code = self.get_message_code()
def handle_task(self):
try:
device = ""
self.logger.debug("Gathering resource usage for disk, memory and CPU.")
for part in self.Hardware.Disk.partitions():
if len(device) != 0:
device += ", "
device = device + part.device
data = {'System': self.Os.name(), 'Release': self.Os.kernel_release(),
'agentVersion': self.get_agent_version(),
'hostname': self.Os.hostname(),
'ipAddresses': str(self.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''),
'os.name': self.Os.name(),
'osVersion': self.Os.version(),
'macAddresses': str(self.Hardware.Network.mac_addresses()).replace('[', '').replace(']', ''),
'hardware.systemDefinitions': self.Hardware.system_definitions(),
'hardware.monitors': self.Hardware.monitors(),
'hardware.screens': self.Hardware.screens(),
'hardware.usbDevices': self.Hardware.usb_devices(),
'hardware.printers': self.Hardware.printers(),
'diskTotal': self.Hardware.Disk.total(),
'diskUsed': self.Hardware.Disk.used(),
'diskFree': self.Hardware.Disk.free(),
'memory': self.Hardware.Memory.total(),
'Device': device,
}
self.logger.debug("Agent info gathered.")
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='Ahenk bilgileri başarıyla güncellendi.',
data=json.dumps(data), content_type=self.get_content_type().APPLICATION_JSON.value)
except Exception as e:
self.logger.error(str(e))
self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='Ahenk bilgileri güncellenirken hata oluştu: {0}'.format(str(e)))
def handle_task(task, context):
plugin = AgentInfo(task, context)
plugin.handle_task()