From f86fd1a8915f524c6ba62525568d9e3e6c69843f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuncay=20=C3=87OLAK?= Date: Wed, 6 Jan 2021 11:01:08 +0300 Subject: [PATCH] Syncing /usr/share/ahenk to src and recreating ahenk.install --- usr/share/ahenk/base/system/system.py | 6 ++--- .../plugins/network-manager/add_network.py | 8 +++--- .../plugins/network-manager/delete_network.py | 26 ++++++++++++------- .../ahenk/plugins/package-manager/packages.py | 16 +++++++++++- .../plugins/remote-access/setup-vnc-server.py | 6 ++--- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/usr/share/ahenk/base/system/system.py b/usr/share/ahenk/base/system/system.py index 3228235..2655fa3 100644 --- a/usr/share/ahenk/base/system/system.py +++ b/usr/share/ahenk/base/system/system.py @@ -429,15 +429,15 @@ class System: @staticmethod def total(): - return int(int(psutil.disk_usage('/')[0]) / (1024 * 1024)) + return int(int(psutil.disk_usage('/')[0]) / (1000 * 1000)) @staticmethod def used(): - return int(int(psutil.disk_usage('/')[1]) / (1024 * 1024)) + return int(int(psutil.disk_usage('/')[1]) / (1000 * 1000)) @staticmethod def free(): - return int(int(psutil.disk_usage('/')[2]) / (1024 * 1024)) + return int(int(psutil.disk_usage('/')[2]) / (1000 * 1000)) @staticmethod def percent(): diff --git a/usr/share/ahenk/plugins/network-manager/add_network.py b/usr/share/ahenk/plugins/network-manager/add_network.py index 783d7c5..c7ceb0a 100644 --- a/usr/share/ahenk/plugins/network-manager/add_network.py +++ b/usr/share/ahenk/plugins/network-manager/add_network.py @@ -32,22 +32,22 @@ class AddNetwork(AbstractPlugin): try: if self.type == 'STATIC': if self.is_active is True: - self.content = 'iface {0} inet static\n address {1}\n netmask {2}\n gateway {3}\n'.format(self.name, + self.content = 'auto {0}\niface {0} inet static\naddress {1}\nnetmask {2}\ngateway {3}\n'.format(self.name, self.ip, self.netmask, self.gateway) else: - self.content = 'iface {0} inet static\n#address {1}\n#netmask {2}\n#gateway {3}\n'.format(self.name, + self.content = 'auto {0}\niface {0} inet static\n#address {1}\n#netmask {2}\n#gateway {3}\n'.format(self.name, self.ip, self.netmask, self.gateway) self.logger.debug('Created content for STATIC type.') elif self.type == 'DHCP': - self.content = 'iface {} inet dhcp\n'.format(self.name) + self.content = 'auto {0}\niface {0} inet dhcp\n'.format(self.name) self.logger.debug('Created content for DHCP type.') elif self.type == 'LOOPBACK': - self.content = 'iface {} inet loopback\n'.format(self.name) + self.content = 'auto {0}\niface {0} inet loopback\n'.format(self.name) self.logger.debug('Created content for LOOPBACK type.') if self.is_active is False: diff --git a/usr/share/ahenk/plugins/network-manager/delete_network.py b/usr/share/ahenk/plugins/network-manager/delete_network.py index 762a0da..96ddb9c 100644 --- a/usr/share/ahenk/plugins/network-manager/delete_network.py +++ b/usr/share/ahenk/plugins/network-manager/delete_network.py @@ -42,32 +42,40 @@ class DeleteNetwork(AbstractPlugin): if not counter: if self.type == 'static': if self.is_active is True: - self.content = 'iface {0} inet static\n'.format(self.name) + self.content = 'auto {0}\n'.format(self.name) else: - self.content = '#iface {0} inet static\n'.format(self.name) + self.content = '#auto {0}\n'.format(self.name) if line.startswith(self.content): - counter = 3 + counter = 4 else: print(str(line).strip()) elif self.type == 'dhcp': if self.is_active is True: - self.content = 'iface {} inet dhcp\n'.format(self.name) + self.content = 'auto {0}\n'.format(self.name) else: - self.content = '#iface {} inet dhcp\n'.format(self.name) + self.content = '#auto {0}\n'.format(self.name) - if not line.startswith(self.content): + if line.startswith(self.content): + counter = 1 + else: print(str(line).strip()) + # if not line.startswith(self.content): + # print(str(line).strip()) + elif self.type == 'loopback': if self.is_active is True: - self.content = 'iface {} inet loopback\n'.format(self.name) + self.content = 'auto {0}\n'.format(self.name) else: - self.content = '#iface {} inet loopback\n'.format(self.name) + self.content = 'auto {0}\n'.format(self.name) - if not line.startswith(self.content): + if line.startswith(self.content): + counter = 1 + else: print(str(line).strip()) + else: counter -= 1 diff --git a/usr/share/ahenk/plugins/package-manager/packages.py b/usr/share/ahenk/plugins/package-manager/packages.py index 8e13342..037481b 100644 --- a/usr/share/ahenk/plugins/package-manager/packages.py +++ b/usr/share/ahenk/plugins/package-manager/packages.py @@ -22,6 +22,7 @@ class Packages(AbstractPlugin): cn = '{0}\r\n'.format(self.Ahenk.dn().split(',')[0]) items = (self.data)['packageInfoList'] + packages = [] for item in items: try: if self.has_attr_json(item, 'tag') and self.has_attr_json(item, 'source'): @@ -61,6 +62,9 @@ class Packages(AbstractPlugin): ## INSTALL/REMOVE PACKAGE + p_item = {'packageName': '{0}'.format(item['packageName']), + 'tag': '{0}'.format(item['tag'])} + packages.append(p_item) if item['tag'] == 'Yükle' or item['tag'] == 'Install': self.logger.debug( "Installing new package... {0}".format(item['packageName'])) @@ -97,18 +101,23 @@ class Packages(AbstractPlugin): message='{0}\n Paket kaldırılırken ' 'hata oluştu. Hata Mesajı: {1}'.format( cn, str(p_err))) + + except Exception as e: self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e))) + self.delete_source_file() self.context.create_response(code=self.message_code.TASK_ERROR.value, message='{0}.\nÖngörülemeyen bir hata oluştu.Hata mesajı:{1}'.format( cn, str(e))) return + self.delete_source_file() self.logger.debug('Task handled successfully') self.context.create_response(code=self.message_code.TASK_PROCESSED.value, - message='{0} ahenginde, {1} paketi({2}) {3} işlemi başarı ile gerçekleştirildi.'.format(cn,item['packageName'], item['version'], item['tag'])) + message='{0} paket kur/kaldır işlemleri başarı ile gerçekleştirildi.'.format(packages)) except Exception as e: self.logger.error('Unpredictable error exists. Error Message: {0}'.format(str(e))) + self.delete_source_file() self.context.create_response(code=self.message_code.TASK_ERROR.value, message='{0}\nGörev çalıştırılırken beklenmedik bir hata oluştu. Hata Mesajı: {1}'.format( cn, @@ -127,6 +136,11 @@ class Packages(AbstractPlugin): def add_source(self, source): self.write_file('/etc/apt/sources.list.d/ahenk.list', source+'\n', 'a+') + def delete_source_file(self): + if self.is_exist('/etc/apt/sources.list.d/ahenk.list'): + self.delete_file('/etc/apt/sources.list.d/ahenk.list') + self.logger.info("Delete ahenk.list source file") + def handle_task(task, context): plugin = Packages(task, context) diff --git a/usr/share/ahenk/plugins/remote-access/setup-vnc-server.py b/usr/share/ahenk/plugins/remote-access/setup-vnc-server.py index 4111976..6d3ee07 100644 --- a/usr/share/ahenk/plugins/remote-access/setup-vnc-server.py +++ b/usr/share/ahenk/plugins/remote-access/setup-vnc-server.py @@ -89,7 +89,7 @@ class SetupVnc(AbstractPlugin): # 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, user_name, display_number), result=False) self.execute( - 'su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -display {3}"'.format( + 'su - {0} -c "x11vnc -accept \'popup\' -gone \'popup\' -rfbport {1} -passwd {2} -capslock -display {3}"'.format( user_name, self.port, self.password, display_number), result=False) 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. ") @@ -97,10 +97,10 @@ class SetupVnc(AbstractPlugin): "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) time.sleep(2) - self.execute('su - {0} -c "x11vnc -gone \'popup\' -rfbport {1} -passwd {2} -display {3}"'.format( + self.execute('su - {0} -c "x11vnc -gone \'popup\' -rfbport {1} -passwd {2} -capslock -display {3}"'.format( user_name, self.port, self.password, display_number), result=False) else: - self.execute('su - {0} -c "x11vnc -rfbport {1} -passwd {2} -display {3}"'.format( + self.execute('su - {0} -c "x11vnc -rfbport {1} -passwd {2} -capslock -display {3}"'.format( 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")