mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-28 02:12:25 +03:00
added default policy for users
This commit is contained in:
parent
c76256a050
commit
dc41120420
3 changed files with 111 additions and 30 deletions
|
@ -13,6 +13,7 @@ from base.system.system import System
|
|||
from base.timer.setup_timer import SetupTimer
|
||||
from base.timer.timer import Timer
|
||||
from base.util.util import Util
|
||||
from base.default_policy.default_policy import DefaultPolicy
|
||||
|
||||
|
||||
class CommandRunner(object):
|
||||
|
@ -25,6 +26,7 @@ class CommandRunner(object):
|
|||
self.conf_manager = scope.get_configuration_manager()
|
||||
self.db_service = scope.get_db_service()
|
||||
self.execute_manager = scope.get_execution_manager()
|
||||
self.default_policy = DefaultPolicy()
|
||||
|
||||
def check_last_login(self):
|
||||
last_login_tmstmp = self.db_service.select_one_result('session', 'timestamp')
|
||||
|
@ -83,37 +85,11 @@ class CommandRunner(object):
|
|||
agreement = Agreement()
|
||||
agreement_choice = None
|
||||
|
||||
self.logger.info("if mozilla profile is not created run firefox to create profile for user: " + username)
|
||||
if not Util.is_exist("/home/" + username + "/.mozilla/"):
|
||||
self.logger.info("firefox profile does not exist. Check autostart file.")
|
||||
if not Util.is_exist("/home/" + username + "/.config/autostart/"):
|
||||
self.logger.info(".config/autostart folder does not exist. Creating folder.")
|
||||
Util.create_directory("/home/" + username + "/.config/autostart/")
|
||||
else:
|
||||
self.logger.info(".config/autostart folder exists.")
|
||||
self.logger.info(
|
||||
"Checking if firefox-esr-autostart-for-profile.desktop autorun file exists.")
|
||||
## Default policy for users
|
||||
|
||||
if not Util.is_exist(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop"):
|
||||
self.logger.info(
|
||||
"firefox-esr-autostart-for-profile.desktop autorun file does not exists. Creating file.")
|
||||
Util.create_file(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop")
|
||||
content = "[Desktop Entry]\n\n" \
|
||||
"Type=Application\n\n" \
|
||||
"Exec=firefox-esr www.liderahenk.org"
|
||||
Util.write_file(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop",
|
||||
content)
|
||||
self.logger.info(
|
||||
"Autorun config is written to firefox-esr-autostart-for-profile.desktop.")
|
||||
else:
|
||||
self.logger.info("firefox-esr-autostart-for-profile.desktop exists")
|
||||
else:
|
||||
self.logger.info(".mozilla firefox profile path exists. Delete autorun file.")
|
||||
Util.delete_file(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop")
|
||||
self.logger.info("Applying default policies for user {0}".format(username))
|
||||
self.default_policy.default_firefox_policy(username)
|
||||
self.default_policy.disable_update_package_notify(username)
|
||||
|
||||
if agreement.check_agreement(username) is not True and System.Ahenk.agreement() == '1':
|
||||
self.logger.debug('User {0} has not accepted agreement.'.format(username))
|
||||
|
|
0
src/base/default_policy/__init__.py
Normal file
0
src/base/default_policy/__init__.py
Normal file
105
src/base/default_policy/default_policy.py
Normal file
105
src/base/default_policy/default_policy.py
Normal file
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: Tuncay Çolak <tuncay.colak@tubitak.gov.tr> <tncyclk05@gmail.com>
|
||||
# Author: Hasan Kara <h.kara27@gmail.com>
|
||||
|
||||
# Default Policy for users
|
||||
|
||||
from base.scope import Scope
|
||||
from base.util.util import Util
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
class DefaultPolicy:
|
||||
def __init__(self):
|
||||
scope = Scope().get_instance()
|
||||
self.logger = scope.get_logger()
|
||||
self.util = Util()
|
||||
|
||||
## default firefox policy for user
|
||||
def default_firefox_policy(self, username):
|
||||
|
||||
self.logger.info("if mozilla profile is not created run firefox to create profile for user: " + username)
|
||||
if not Util.is_exist("/home/" + username + "/.mozilla/"):
|
||||
self.logger.info("firefox profile does not exist. Check autostart file.")
|
||||
if not Util.is_exist("/home/" + username + "/.config/autostart/"):
|
||||
self.logger.info(".config/autostart folder does not exist. Creating folder.")
|
||||
Util.create_directory("/home/" + username + "/.config/autostart/")
|
||||
else:
|
||||
self.logger.info(".config/autostart folder exists.")
|
||||
self.logger.info(
|
||||
"Checking if firefox-esr-autostart-for-profile.desktop autorun file exists.")
|
||||
|
||||
if not Util.is_exist(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop"):
|
||||
self.logger.info(
|
||||
"firefox-esr-autostart-for-profile.desktop autorun file does not exists. Creating file.")
|
||||
Util.create_file(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop")
|
||||
content = "[Desktop Entry]\n\n" \
|
||||
"Type=Application\n\n" \
|
||||
"Exec=firefox-esr www.liderahenk.org"
|
||||
Util.write_file(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop",
|
||||
content)
|
||||
self.logger.info(
|
||||
"Autorun config is written to firefox-esr-autostart-for-profile.desktop.")
|
||||
else:
|
||||
self.logger.info("firefox-esr-autostart-for-profile.desktop exists")
|
||||
else:
|
||||
self.logger.info(".mozilla firefox profile path exists. Delete autorun file.")
|
||||
Util.delete_file(
|
||||
"/home/" + username + "/.config/autostart/firefox-esr-autostart-for-profile.desktop")
|
||||
|
||||
## disabled update package notify for user
|
||||
def disable_update_package_notify(self, username):
|
||||
|
||||
app_name_for_blocking = "pk-update-icon"
|
||||
fileName = "/home/{0}/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml".format(username)
|
||||
|
||||
if not self.util.is_exist(fileName):
|
||||
self.logger.info("Configuration file does not exist")
|
||||
else:
|
||||
tree = ET.parse(fileName)
|
||||
root = tree.getroot()
|
||||
|
||||
element = root.find("./property/[@name='applications']")
|
||||
if element is None:
|
||||
self.logger.info("applications element could not be found.")
|
||||
else:
|
||||
element = root.find("./property/property[@name='muted_applications']")
|
||||
if element is None:
|
||||
self.logger.info("muted_applications element could not be found.")
|
||||
self.logger.info("adding muted_applications element to applications tag.")
|
||||
element = root.find("./property/[@name='applications']")
|
||||
new_element = ET.SubElement(element, 'property')
|
||||
new_element.attrib["name"] = 'muted_applications'
|
||||
new_element.attrib["type"] = 'array'
|
||||
tree.write(fileName)
|
||||
else:
|
||||
self.logger.info("muted_applications tag exists.")
|
||||
|
||||
self.logger.info("checking if '" + app_name_for_blocking + "' exists in muted_applications tag.")
|
||||
element = root.find(
|
||||
"./property/property[@name='muted_applications']/value[@value='{0}']".format(app_name_for_blocking))
|
||||
if element is None:
|
||||
self.logger.info("'" + app_name_for_blocking + "' is not found in muted_applications element.")
|
||||
self.logger.info("'" + app_name_for_blocking + "' will be added to muted_applications tag.")
|
||||
element = root.find("./property/property[@name='muted_applications']")
|
||||
new_element = ET.SubElement(element, 'value')
|
||||
new_element.attrib["type"] = 'string'
|
||||
new_element.attrib["value"] = app_name_for_blocking
|
||||
tree.write(fileName)
|
||||
else:
|
||||
self.logger.info("'" + app_name_for_blocking + "' is already added to muted_applications tag.")
|
||||
|
||||
pk_update_icon_file = "/etc/xdg/autostart/pk-update-icon.desktop"
|
||||
if self.util.is_exist(pk_update_icon_file):
|
||||
self.logger.info("{0} file exists".format(pk_update_icon_file))
|
||||
self.util.rename_file(pk_update_icon_file, pk_update_icon_file+".ahenk")
|
||||
self.logger.info("Renamed from {0} to {0}.ahenk".format(pk_update_icon_file))
|
||||
self.logger.info("Disabled autostart for pk-update-icon")
|
||||
|
||||
else:
|
||||
self.logger.info("File not found")
|
||||
|
||||
self.logger.info("Disable notifications if there is a package update notification for user: " + username)
|
Loading…
Reference in a new issue