mirror of
https://github.com/altlinux/gpupdate.git
synced 2025-03-21 18:50:38 +03:00
Merge remote-tracking branch 'github/kde_applier' into userMode_fix
This commit is contained in:
commit
de6db7ad2b
@ -68,6 +68,11 @@ from .ini_applier import (
|
||||
, ini_applier_user
|
||||
)
|
||||
|
||||
from .kde_applier import (
|
||||
kde_applier
|
||||
, kde_applier_user
|
||||
)
|
||||
|
||||
from .networkshare_applier import networkshare_applier
|
||||
from .yandex_browser_applier import yandex_browser_applier
|
||||
|
||||
@ -163,6 +168,7 @@ class frontend_manager:
|
||||
self.machine_appliers['scripts'] = scripts_applier(self.storage, self.sid)
|
||||
self.machine_appliers['files'] = file_applier(self.storage, self.file_cache, self.sid)
|
||||
self.machine_appliers['ini'] = ini_applier(self.storage, self.sid)
|
||||
self.machine_appliers['kde'] = kde_applier(self.storage)
|
||||
|
||||
def _init_user_appliers(self):
|
||||
# User appliers are expected to work with user-writable
|
||||
@ -184,6 +190,7 @@ class frontend_manager:
|
||||
self.user_appliers['scripts'] = scripts_applier_user(self.storage, self.sid, self.username)
|
||||
self.user_appliers['files'] = file_applier_user(self.storage, self.file_cache, self.sid, self.username)
|
||||
self.user_appliers['ini'] = ini_applier_user(self.storage, self.sid, self.username)
|
||||
self.user_appliers['kde'] = kde_applier_user(self.storage, self.sid, self.username)
|
||||
|
||||
def machine_apply(self):
|
||||
'''
|
||||
|
223
gpoa/frontend/kde_applier.py
Normal file
223
gpoa/frontend/kde_applier.py
Normal file
@ -0,0 +1,223 @@
|
||||
#
|
||||
# GPOA - GPO Applier for Linux
|
||||
#
|
||||
# Copyright (C) 2019-2023 BaseALT Ltd.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .applier_frontend import applier_frontend, check_enabled
|
||||
from util.logging import log
|
||||
from util.util import get_homedir
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
widget_utilities = {
|
||||
'colorscheme': 'plasma-apply-colorscheme',
|
||||
'cursortheme': 'plasma-apply-cursortheme',
|
||||
'desktoptheme': 'plasma-apply-desktoptheme',
|
||||
'wallpaperimage': 'plasma-apply-wallpaperimage'
|
||||
}
|
||||
|
||||
class kde_applier(applier_frontend):
|
||||
__module_name = 'KdeApplier'
|
||||
__module_experimental = True
|
||||
__module_enabled = False
|
||||
__hklm_branch = 'Software\\BaseALT\\Policies\\KDE\\'
|
||||
__hklm_lock_branch = 'Software\\BaseALT\\Policies\\KDELocks\\'
|
||||
|
||||
def __init__(self, storage):
|
||||
self.storage = storage
|
||||
self.locks_dict = {}
|
||||
self.locks_data_dict = {}
|
||||
self.all_kde_settings = {}
|
||||
kde_filter = '{}%'.format(self.__hklm_branch)
|
||||
locks_filter = '{}%'.format(self.__hklm_lock_branch)
|
||||
self.locks_settings = self.storage.filter_hklm_entries(locks_filter)
|
||||
self.kde_settings = self.storage.filter_hklm_entries(kde_filter)
|
||||
self.all_kde_settings = {}
|
||||
|
||||
self.__module_enabled = check_enabled(
|
||||
self.storage,
|
||||
self.__module_name,
|
||||
self.__module_experimental
|
||||
)
|
||||
|
||||
def apply(self):
|
||||
if self.__module_enabled:
|
||||
log('D198')
|
||||
create_dict(self.kde_settings, self.all_kde_settings, self.locks_settings, self.locks_dict)
|
||||
apply(self.all_kde_settings, self.locks_dict)
|
||||
else:
|
||||
log('D199')
|
||||
|
||||
class kde_applier_user(applier_frontend):
|
||||
__module_name = 'KdeApplierUser'
|
||||
__module_experimental = True
|
||||
__module_enabled = False
|
||||
__hkcu_branch = 'Software\\BaseALT\\Policies\\KDE\\'
|
||||
__hkcu_lock_branch = 'Software\\BaseALT\\Policies\\KDELocks\\'
|
||||
widget_utilities = {
|
||||
'colorscheme': 'plasma-apply-colorscheme',
|
||||
'cursortheme': 'plasma-apply-cursortheme',
|
||||
'desktoptheme': 'plasma-apply-desktoptheme',
|
||||
'wallpaperimage': 'plasma-apply-wallpaperimage'
|
||||
}
|
||||
|
||||
def __init__(self, storage, sid=None, username=None):
|
||||
self.storage = storage
|
||||
self.username = username
|
||||
self.sid = sid
|
||||
self.locks_dict = {}
|
||||
self.locks_data_dict = {}
|
||||
self.all_kde_settings = {}
|
||||
kde_filter = '{}%'.format(self.__hkcu_branch)
|
||||
locks_filter = '{}%'.format(self.__hkcu_lock_branch)
|
||||
self.locks_settings = self.storage.filter_hkcu_entries(self.sid, locks_filter)
|
||||
self.kde_settings = self.storage.filter_hkcu_entries(self.sid, kde_filter)
|
||||
self.__module_enabled = check_enabled(
|
||||
self.storage,
|
||||
self.__module_name,
|
||||
self.__module_experimental
|
||||
)
|
||||
|
||||
def admin_context_apply(self):
|
||||
pass
|
||||
|
||||
def user_context_apply(self):
|
||||
'''
|
||||
Change settings applied in user context
|
||||
'''
|
||||
if self.__module_enabled:
|
||||
log('D200')
|
||||
create_dict(self.kde_settings, self.all_kde_settings, self.locks_settings, self.locks_dict, self.username)
|
||||
apply(self.all_kde_settings, self.locks_dict, self.username)
|
||||
else:
|
||||
log('D201')
|
||||
|
||||
def create_dict(kde_settings, all_kde_settings, locks_settings, locks_dict, username = None):
|
||||
for locks in locks_settings:
|
||||
locks_dict[locks.valuename] = locks.data
|
||||
for setting in kde_settings:
|
||||
try:
|
||||
file_name, section, value = setting.keyname.split("\\")[-2], setting.keyname.split("\\")[-1], setting.valuename
|
||||
data = setting.data
|
||||
if file_name == 'plasma':
|
||||
apply_for_widget(section, data)
|
||||
if file_name not in all_kde_settings:
|
||||
all_kde_settings[file_name] = {}
|
||||
if section not in all_kde_settings[file_name]:
|
||||
all_kde_settings[file_name][section] = {}
|
||||
all_kde_settings[file_name][section][value] = data
|
||||
|
||||
except Exception as exc:
|
||||
logdata = dict()
|
||||
logdata['Exception'] = exc
|
||||
logdata['Exception'] = setting
|
||||
log('W16', logdata)
|
||||
|
||||
def apply(all_kde_settings, locks_dict, username = None):
|
||||
if username is None:
|
||||
for file_name, sections in all_kde_settings.items():
|
||||
file_path = f'/etc/xdg/{file_name}'
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
with open(file_path, 'w') as file:
|
||||
for section, keys in sections.items():
|
||||
file.write(f'[{section}]\n')
|
||||
for key, value in keys.items():
|
||||
if key in locks_dict and locks_dict[key] == '1':
|
||||
file.write(f'{key}[$i]={value}\n')
|
||||
else:
|
||||
file.write(f'{key}={value}\n')
|
||||
file.write('\n')
|
||||
else:
|
||||
for file_name, sections in all_kde_settings.items():
|
||||
for section, keys in sections.items():
|
||||
for key, value in keys.items():
|
||||
if key in locks_dict and locks_dict[key] == '1':
|
||||
command = [
|
||||
'kwriteconfig5',
|
||||
'--file', file_name,
|
||||
'--group', section,
|
||||
'--key', key +'/$i/',
|
||||
'--type', 'string',
|
||||
value
|
||||
]
|
||||
else:
|
||||
command = [
|
||||
'kwriteconfig5',
|
||||
'--file', file_name,
|
||||
'--group', section,
|
||||
'--key', key,
|
||||
'--type', 'string',
|
||||
value
|
||||
]
|
||||
try:
|
||||
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
except Exception as exc:
|
||||
clear_locks_settings(username, file_name, key)
|
||||
try:
|
||||
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
except Exception as exc:
|
||||
logdata = dict()
|
||||
logdata['command'] = command
|
||||
log('E68', logdata)
|
||||
new_content = []
|
||||
file_path = os.path.expanduser(f'{get_homedir(username)}/.config/{file_name}')
|
||||
with open(file_path, 'r') as file:
|
||||
for line in file:
|
||||
line = line.replace('/$i/', '[$i]').replace(')(', '][')
|
||||
new_content.append(line)
|
||||
with open(file_path, 'w') as file:
|
||||
file.writelines(new_content)
|
||||
logdata = dict()
|
||||
logdata['file'] = file_name
|
||||
log('D202', logdata)
|
||||
|
||||
def clear_locks_settings(username, file_name, key):
|
||||
'''
|
||||
Method to remove old locked settings
|
||||
'''
|
||||
file_path = f'{get_homedir(username)}/.config/{file_name}'
|
||||
with open(file_path, 'r') as file:
|
||||
lines = file.readlines()
|
||||
with open(file_path, 'w') as file:
|
||||
for line in lines:
|
||||
if f'{key}[$i]=' not in line:
|
||||
file.write(line)
|
||||
for line in lines:
|
||||
if f'{key}[$i]=' in line:
|
||||
logdata = dict()
|
||||
logdata['line'] = line.strip()
|
||||
log('I10', logdata)
|
||||
|
||||
def apply_for_widget(value, data):
|
||||
'''
|
||||
Method for changing graphics settings in plasma context
|
||||
'''
|
||||
try:
|
||||
if value in widget_utilities:
|
||||
os.environ["PATH"] = "/usr/lib/kf5/bin:"
|
||||
command = [f"{widget_utilities[value]}", f"{data}"]
|
||||
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if proc.returncode == None:
|
||||
log('D203')
|
||||
else:
|
||||
log('E66')
|
||||
else:
|
||||
pass
|
||||
except OSError as e:
|
||||
log('E67')
|
@ -62,6 +62,9 @@ msgstr "Политика Chromium"
|
||||
msgid "Set user property to"
|
||||
msgstr "Установка свойств для пользователя"
|
||||
|
||||
msgid "The line in the configuration file was cleared"
|
||||
msgstr "В конфигурационном файле была очищена строка"
|
||||
|
||||
# Error
|
||||
msgid "Insufficient permissions to run gpupdate"
|
||||
msgstr "Недостаточно прав для запуска gpupdate"
|
||||
@ -228,6 +231,15 @@ msgstr "Ошибка очистки каталога для машины"
|
||||
msgid "Error cleaning directory for user"
|
||||
msgstr "Ошибка очистки каталога для пользователя"
|
||||
|
||||
msgid "Error while executing command for widgets"
|
||||
msgstr "Ошибка при выполнении команды для виджетов"
|
||||
|
||||
msgid "Error creating environment variables"
|
||||
msgstr "Ошибка создания перемеенных среды"
|
||||
|
||||
msgid "Error running kwriteconfig5 command"
|
||||
msgstr "Ошибка выполнения команды kwriteconfig5"
|
||||
|
||||
# Error_end
|
||||
|
||||
# Debug
|
||||
@ -771,13 +783,13 @@ msgstr "Запись настройки Яндекс Браузера в"
|
||||
msgid "Running networkshare applier for user"
|
||||
msgstr "Запуск применение настроек сетевых каталогов для пользователя"
|
||||
|
||||
msgid "Copying a file"
|
||||
msgid "File copy"
|
||||
msgstr "Копирование файла"
|
||||
|
||||
msgid "Running networkshare applier for user will not be started"
|
||||
msgstr "Применение настроек сетевых каталогов для пользователя не будет запущено"
|
||||
|
||||
msgid "Updating a file"
|
||||
msgid "File update"
|
||||
msgstr "Обновление файла"
|
||||
|
||||
msgid "Applying settings for network share"
|
||||
@ -807,6 +819,24 @@ msgstr "Не удалось создать ссылку на точку монт
|
||||
msgid "Failed to create a symlink to the hidden system network drives mountpoint"
|
||||
msgstr "Не удалось создать ссылку на точку монтирования скрытых системных сетевых дисков"
|
||||
|
||||
msgid "Running KDE applier for machine"
|
||||
msgstr "Запуск применения настроек KDE для машины"
|
||||
|
||||
msgid "KDE applier for machine will not be started"
|
||||
msgstr "Применение настроек KDE для машины не удалось"
|
||||
|
||||
msgid "Running KDE applier for user in user context"
|
||||
msgstr "Запуск применения настроек KDE в контексте пользователя"
|
||||
|
||||
msgid "KDE applier for user in user context will not be started"
|
||||
msgstr "KDE в контексте пользователя не запускается"
|
||||
|
||||
msgid "Changing the configuration file"
|
||||
msgstr "Изменение конфигурационного файла"
|
||||
|
||||
msgid "Widget command completed successfully"
|
||||
msgstr "Команда для виджетов выполнена успешно"
|
||||
|
||||
# Debug_end
|
||||
|
||||
# Warning
|
||||
@ -856,6 +886,9 @@ msgstr "Не удалось создать допустимый список к
|
||||
msgid "Failed to copy file"
|
||||
msgstr "Не удалось скопировать файл"
|
||||
|
||||
msgid "Failed to create settings list"
|
||||
msgstr "Не удалось создать список настроек"
|
||||
|
||||
# Fatal
|
||||
msgid "Unable to refresh GPO list"
|
||||
msgstr "Невозможно обновить список объектов групповых политик"
|
||||
|
@ -30,6 +30,7 @@ def info_code(code):
|
||||
info_ids[7] = 'Firefox policy'
|
||||
info_ids[8] = 'Chromium policy'
|
||||
info_ids[9] = 'Set user property to'
|
||||
info_ids[10] = 'The line in the configuration file was cleared'
|
||||
|
||||
return info_ids.get(code, 'Unknown info code')
|
||||
|
||||
@ -99,8 +100,9 @@ def error_code(code):
|
||||
error_ids[63] = 'Error merging user GPT (from machine GPO)'
|
||||
error_ids[64] = 'Error to cleanup directory for machine'
|
||||
error_ids[65] = 'Error to cleanup directory for user'
|
||||
|
||||
|
||||
error_ids[66] = 'Error while executing command for widgets'
|
||||
error_ids[67] = 'Error creating environment variables'
|
||||
error_ids[68] = 'Error running kwriteconfig5 command'
|
||||
return error_ids.get(code, 'Unknown error code')
|
||||
|
||||
def debug_code(code):
|
||||
@ -295,14 +297,19 @@ def debug_code(code):
|
||||
debug_ids[188] = 'Running networkshare applier for user'
|
||||
debug_ids[189] = 'Running networkshare applier for user will not be started'
|
||||
debug_ids[190] = 'Applying settings for network share'
|
||||
debug_ids[191] = 'Copying a file'
|
||||
debug_ids[192] = 'Updating a file'
|
||||
debug_ids[191] = 'File copy'
|
||||
debug_ids[192] = 'File update'
|
||||
debug_ids[193] = 'Deleting a file'
|
||||
debug_ids[194] = 'Failed to create a symlink to the network drives mountpoint'
|
||||
debug_ids[195] = 'Failed to create a symlink to the system network drives mountpoint'
|
||||
debug_ids[196] = 'Failed to create a symlink to the hidden network drives mountpoint'
|
||||
debug_ids[197] = 'Failed to create a symlink to the hidden system network drives mountpoint'
|
||||
|
||||
debug_ids[198] = 'Running KDE applier for machine'
|
||||
debug_ids[199] = 'KDE applier for machine will not be started'
|
||||
debug_ids[200] = 'Running KDE applier for user in user context'
|
||||
debug_ids[201] = 'KDE applier for user in user context will not be started'
|
||||
debug_ids[202] = 'Changing the configuration file'
|
||||
debug_ids[203] = 'Widget command completed successfully'
|
||||
return debug_ids.get(code, 'Unknown debug code')
|
||||
|
||||
def warning_code(code):
|
||||
@ -328,6 +335,7 @@ def warning_code(code):
|
||||
warning_ids[13] = 'Failed to caching the file'
|
||||
warning_ids[14] = 'Could not create a valid list of keys'
|
||||
warning_ids[15] = 'Failed to copy file'
|
||||
warning_ids[16] = 'Failed to create settings list'
|
||||
|
||||
return warning_ids.get(code, 'Unknown warning code')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user