From d7399a01305228e0d1cd9678591f47efa99839de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuncay=20=C3=87OLAK?= Date: Mon, 24 Aug 2020 11:24:20 +0300 Subject: [PATCH] Syncing /usr/share/ahenk to src and recreating ahenk.install --- debian/ahenk.install | 1 + .../ahenk/base/registration/registration.py | 13 +++++ usr/share/ahenk/plugins/conky/ask.py | 4 +- .../ahenk/plugins/conky/execute_conky.py | 18 ------ usr/share/ahenk/plugins/conky/policy.py | 55 ++++++------------- usr/share/ahenk/plugins/conky/safe.py | 36 ++++++++++++ .../ahenk/plugins/local-user/add_user.py | 2 +- .../ahenk/plugins/local-user/edit_user.py | 2 +- 8 files changed, 69 insertions(+), 62 deletions(-) create mode 100644 usr/share/ahenk/plugins/conky/safe.py diff --git a/debian/ahenk.install b/debian/ahenk.install index 4a3f824..d7b0462 100644 --- a/debian/ahenk.install +++ b/debian/ahenk.install @@ -195,6 +195,7 @@ usr/share/ahenk/plugins/network-inventory/multiple-file-transfer.py usr/share/ahenk/plugins/network-inventory/scannetwork.py usr/share/ahenk/plugins/network-inventory/installahenk.py usr/share/ahenk/plugins/network-inventory +usr/share/ahenk/plugins/conky/safe.py usr/share/ahenk/plugins/conky/main.py usr/share/ahenk/plugins/conky/policy.py usr/share/ahenk/plugins/conky/execute_conky.py diff --git a/usr/share/ahenk/base/registration/registration.py b/usr/share/ahenk/base/registration/registration.py index aa3c59b..690a3dc 100644 --- a/usr/share/ahenk/base/registration/registration.py +++ b/usr/share/ahenk/base/registration/registration.py @@ -559,6 +559,19 @@ class Registration: Util.execute(change_permisson.format(new_home_dir)) def change_permissions_for_local_users(self): + if self.disable_local_users is False: + content = Util.read_file('/etc/passwd') + change_permisson = "chmod -R 700 {}" + for p in pwd.getpwall(): + self.logger.info( + "User: '{0}' will change 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: + Util.execute(change_permisson.format(p.pw_dir)) + add_user_conf_file = "/etc/adduser.conf" file_dir_mode = open(add_user_conf_file, 'r') file_data = file_dir_mode.read() diff --git a/usr/share/ahenk/plugins/conky/ask.py b/usr/share/ahenk/plugins/conky/ask.py index 4820def..318f82c 100644 --- a/usr/share/ahenk/plugins/conky/ask.py +++ b/usr/share/ahenk/plugins/conky/ask.py @@ -6,7 +6,6 @@ import sys import easygui - def ask(content, title): choice = easygui.buttonbox(msg=title, title=content, choices=['TAMAM']) #choice = easygui.textbox(msg=title, text=content) @@ -15,7 +14,6 @@ def ask(content, title): else: print('N') - if __name__ == '__main__': if len(sys.argv) == 3: @@ -24,4 +22,4 @@ if __name__ == '__main__': except Exception as e: print(str(e)) else: - print('Argument fault. Check your parameters or content of parameters. Parameters: ' + str(sys.argv)) \ No newline at end of file + print('Argument fault. Check your parameters or content of parameters. Parameters: ' + str(sys.argv)) diff --git a/usr/share/ahenk/plugins/conky/execute_conky.py b/usr/share/ahenk/plugins/conky/execute_conky.py index 74184d3..08abebd 100644 --- a/usr/share/ahenk/plugins/conky/execute_conky.py +++ b/usr/share/ahenk/plugins/conky/execute_conky.py @@ -2,13 +2,10 @@ # -*- coding: utf-8 -*- # Author: Edip YILDIZ - from base.model.enum.content_type import ContentType import json - from base.plugin.abstract_plugin import AbstractPlugin - class RunConkyCommand(AbstractPlugin): def __init__(self, data, context): super(AbstractPlugin, self).__init__() @@ -51,12 +48,10 @@ class RunConkyCommand(AbstractPlugin): self.execute("killall conky") if self.is_exist(self.conky_config_global_autorun_file) == True: self.delete_file(self.conky_config_global_autorun_file) - self.context.create_response(code=self.message_code.TASK_PROCESSED.value, message='Conky measajları kaldırıldı', content_type=ContentType.APPLICATION_JSON.value) - def execute_conky(self, conky_message): self.logger.debug("[CONKY] Executing conky.") try: @@ -68,11 +63,9 @@ class RunConkyCommand(AbstractPlugin): self.logger.debug('[Conky] Some processes found which names are conky. They will be killed.') self.execute('killall conky') - except: self.logger.error('[Conky] Conky install-kill problem.') raise - if self.is_exist(self.conky_config_file_dir) == False: self.logger.debug('[Conky] Creating directory for conky config at ' + self.conky_config_file_dir) self.create_directory(self.conky_config_file_dir) @@ -86,7 +79,6 @@ class RunConkyCommand(AbstractPlugin): self.write_file(self.conky_config_file_path, conky_message) self.logger.debug('[Conky] Config file was filled by context.') - # creating wrapper file if is not exist. wrapper for using conky command..its need for ETA if self.is_exist(self.conky_wrapper_file) == False: self.logger.debug('[Conky] Creating directory for conky wrapper file at ' + self.conky_wrapper_file) @@ -101,16 +93,13 @@ class RunConkyCommand(AbstractPlugin): self.logger.debug('[Conky] Creating directory for conky autorun file at ' + self.conky_config_global_autorun_file) self.create_file(self.conky_config_global_autorun_file) self.write_file(self.conky_config_global_autorun_file, self.conky_autorun_content) - users = self.Sessions.user_name() desktop_env = self.get_desktop_env() self.logger.info("Get desktop environment is {0}".format(desktop_env)) - for user in users: user_display = self.Sessions.display(user) if desktop_env == "gnome": user_display = self.get_username_display_gnome(user) - if user_display is None: self.logger.debug('[Conky] executing for display none for user '+ str(user)) self.execute('conky -q', result=False) @@ -119,10 +108,7 @@ class RunConkyCommand(AbstractPlugin): conky_cmd = 'su ' + str(user) + ' -c ' + ' "conky --display=' + str(user_display) + ' " ' self.logger.debug('[Conky] executing command: ' + str(conky_cmd)) self.execute(conky_cmd, result=False) - - #self.execute('conky ', result=False) - self.context.create_response(code=self.message_code.TASK_PROCESSED.value, message='Conky başarıyla oluşturuldu.', data=json.dumps({'Result': conky_message}), @@ -132,20 +118,16 @@ class RunConkyCommand(AbstractPlugin): try: conky_message = self.data['conkyMessage'] remove_conky_message = self.data['removeConkyMessage'] - if remove_conky_message: self.remove_conky_message() - else: self.execute_conky(conky_message) - except Exception as e: self.logger.error(" error on handle conky task. Error: " + str(e)) self.context.create_response(code=self.message_code.TASK_ERROR.value, message='Conky mesajı olusturulurken hata oluştu:' + str(e), content_type=ContentType.APPLICATION_JSON.value) - def handle_task(task, context): cls = RunConkyCommand(task, context) cls.handle_task() diff --git a/usr/share/ahenk/plugins/conky/policy.py b/usr/share/ahenk/plugins/conky/policy.py index fad11ac..adc286e 100644 --- a/usr/share/ahenk/plugins/conky/policy.py +++ b/usr/share/ahenk/plugins/conky/policy.py @@ -3,10 +3,8 @@ # Author: Volkan Şahin import json - from base.plugin.abstract_plugin import AbstractPlugin - class Conky(AbstractPlugin): def __init__(self, data, context): super(Conky, self).__init__() @@ -24,13 +22,11 @@ class Conky(AbstractPlugin): def handle_policy(self): try: - # Checking dependecies if self.check_dependencies(['conky', 'conky-all']) is True: self.logger.debug('Dependencies checked.') else: return - # Killing conky processes self.logger.debug('Conky named processes will be killed.') self.execute('killall -9 conky') @@ -49,8 +45,7 @@ class Conky(AbstractPlugin): self.logger.debug('Old config file will be deleted.') self.delete_file(self.conky_config_file_path) else: - self.logger.debug( - 'Creating directory for conky config at {0}'.format(self.conky_config_file_dir)) + self.logger.debug('Creating directory for conky config at {0}'.format(self.conky_config_file_dir)) self.create_directory(self.conky_config_file_dir) if self.create_file(self.conky_config_file_path): @@ -66,28 +61,26 @@ class Conky(AbstractPlugin): self.initialize_auto_run() if self.machine_profile is False: - self.execute( - self.command_autorun_conky.format('--display=' + self.Sessions.display(self.username), - self.conky_config_file_path), - as_user=self.username, result=False) - + user_display = self.Sessions.display(self.username) + desktop_env = self.get_desktop_env() + if desktop_env == "gnome": + user_display = self.get_username_display_gnome(self.username) + self.logger.info("Get desktop environment is {0}".format(desktop_env)) + self.execute(self.command_autorun_conky.format('--display=' + user_display, self.conky_config_file_path), as_user=self.username, result=False) self.execute('chown -hR ' + self.username + ':' + self.username + ' ' + self.conky_config_file_dir) self.logger.debug('Owner of Conky config file was changed.') else: self.execute(self.command_autorun_conky.format('', self.conky_config_file_path), result=False) - self.logger.debug('Autorun command executed successfully') self.context.create_response(code=self.get_message_code().POLICY_PROCESSED.value, message='Conky politikası başarıyla çalıştırıldı.') except Exception as e: - self.logger.error( - 'A problem occurred while handling Conky policy. Error Message: {}'.format(str(e))) + self.logger.error('A problem occurred while handling Conky policy. Error Message: {}'.format(str(e))) self.context.create_response(code=self.get_message_code().POLICY_ERROR.value, message='Conky politikası uygulanırken bir hata oluştu.') def check_dependencies(self, packages): - self.logger.debug('Checking dependencies') for package in packages: if self.is_installed(package) is False: @@ -96,47 +89,33 @@ class Conky(AbstractPlugin): if result_code == 0: self.logger.debug('{0} installed successfully'.format(package)) else: - self.logger.error( - 'A problem occurred while installing {0} package. Error Message: {1}'.format(package, - str( - p_err))) + self.logger.error('A problem occurred while installing {0} package. Error Message: {1}'.format(package, str(p_err))) self.context.create_response(code=self.get_message_code().POLICY_ERROR.value, message='Bağımlılıklardan {0} paketi kurulurken hata oluştu.') return False - return True def initialize_auto_run(self): - if self.machine_profile is True: self.logger.debug('All users conky configuration files will be removed because of machine profile') if self.Sessions.user_name() is not None and len(self.Sessions.user_name()) > 0: for username in self.Sessions.user_name(): - self.logger.debug( - 'Removing conf file of user {0}'.format(username)) - self.delete_file( - self.autorun_file_path.format( - self.autostart_dir_path.format(self.Sessions.user_home_path(username)))) + self.logger.debug('Removing conf file of user {0}'.format(username)) + self.delete_file(self.autorun_file_path.format( self.autostart_dir_path.format(self.Sessions.user_home_path(username)))) else: - self.logger.debug( - 'There are no user') - + self.logger.debug('There are no user') else: home_path = self.Sessions.user_home_path(self.username) - self.logger.debug( - 'Creating autorun file for user {0}'.format(self.username)) + self.logger.debug('Creating autorun file for user {0}'.format(self.username)) self.create_autorun_file(self.autostart_dir_path.format(home_path), self.conky_config_file_path, self.autorun_file_path.format(self.autostart_dir_path.format(home_path))) - self.logger.debug( - 'Autorun created') + self.logger.debug('Autorun created') def create_autorun_file(self, autostart_path, conky_config_file_path, autorun_file_path): if not self.is_exist(autostart_path): - self.logger.debug( - 'Creating file: {0}'.format(autostart_path)) + self.logger.debug('Creating file: {0}'.format(autostart_path)) self.create_directory(autostart_path) - file_content = '[Desktop Entry]\n' \ 'Encoding=UTF-8 \n' \ 'Type=Application \n' \ @@ -145,11 +124,9 @@ class Conky(AbstractPlugin): 'Exec=conky -d -c ' + conky_config_file_path + '\n' \ 'StartupNotify=false \n' \ 'Terminal=false \n' - self.logger.debug( - 'Writing content to autorun file.') + self.logger.debug('Writing content to autorun file.') self.write_file(autorun_file_path, file_content, 'w') - def handle_policy(profile_data, context): plugin = Conky(profile_data, context) plugin.handle_policy() diff --git a/usr/share/ahenk/plugins/conky/safe.py b/usr/share/ahenk/plugins/conky/safe.py new file mode 100644 index 0000000..8429d9d --- /dev/null +++ b/usr/share/ahenk/plugins/conky/safe.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author:Tuncay ÇOLAK + +from base.plugin.abstract_plugin import AbstractPlugin + +class Safe(AbstractPlugin): + def __init__(self, context): + super(Safe, self).__init__() + self.context = context + self.username = str(context.get_username()) + self.logger = self.get_logger() + self.logger.debug('Parameters were initialized.') + + def handle_safe_mode(self): + # Killing conky processes + self.logger.debug('Conky named processes will be killed.') + self.execute('killall -9 conky') + # delete autostart and conky config file of logout username + self.conky_config_file_dir = '{0}.conky/'.format(self.Sessions.user_home_path(self.username)) + self.conky_config_file_path = '{0}conky.conf'.format(self.conky_config_file_dir) + if self.is_exist(self.conky_config_file_dir): + self.logger.debug('Conky config file will be deleted of {0}.'.format(self.username)) + self.delete_file(self.conky_config_file_path) + + self.autostart_dir_path = '{0}.config/autostart/' + self.autorun_file_path = '{0}conky.desktop' + home_path = self.Sessions.user_home_path(self.username) + auto_start_file = self.autorun_file_path.format(self.autostart_dir_path.format(home_path)) + if self.is_exist(auto_start_file): + self.delete_file(auto_start_file) + self.logger.debug('Removing autostart file of user {0}'.format(self.username)) + +def handle_mode(context): + safe = Safe(context) + safe.handle_safe_mode() diff --git a/usr/share/ahenk/plugins/local-user/add_user.py b/usr/share/ahenk/plugins/local-user/add_user.py index 252bcb4..db0fd75 100644 --- a/usr/share/ahenk/plugins/local-user/add_user.py +++ b/usr/share/ahenk/plugins/local-user/add_user.py @@ -33,7 +33,7 @@ class AddUser(AbstractPlugin): self.change_password = 'usermod -p {0} {1}' self.change_shell = 'usermod -s /bin/bash {}' self.change_owner = 'chown {0}.{0} {1}' - self.change_permission = 'chmod 755 {}' + self.change_permission = 'chmod 700 {}' self.desktop_path = '' self.xfce4_session = "/usr/bin/xfce4-session" diff --git a/usr/share/ahenk/plugins/local-user/edit_user.py b/usr/share/ahenk/plugins/local-user/edit_user.py index f55f799..a5aef24 100644 --- a/usr/share/ahenk/plugins/local-user/edit_user.py +++ b/usr/share/ahenk/plugins/local-user/edit_user.py @@ -36,7 +36,7 @@ class EditUser(AbstractPlugin): self.change_groups = 'usermod -G {0} {1}' self.remove_all_groups = 'usermod -G "" {}' self.change_owner = 'chown {0}.{0} {1}' - self.change_permission = 'chmod 755 {}' + self.change_permission = 'chmod 700 {}' self.logout_user = 'pkill -u {}' self.kill_all_process = 'killall -KILL -u {}'