mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 08:32:16 +03:00
policy for gnome desktop env and safe mode has been added
This commit is contained in:
parent
f208a83d37
commit
68cef4e7f2
4 changed files with 53 additions and 60 deletions
|
@ -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))
|
||||
print('Argument fault. Check your parameters or content of parameters. Parameters: ' + str(sys.argv))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
||||
|
||||
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()
|
||||
|
|
36
src/plugins/conky/safe.py
Normal file
36
src/plugins/conky/safe.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author:Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
|
||||
|
||||
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()
|
Loading…
Reference in a new issue