added safe.py file

This commit is contained in:
3bru 2023-03-13 18:01:22 +03:00
parent 4063f1b81c
commit f029e916ef
3 changed files with 47 additions and 22 deletions

View file

@ -14,14 +14,12 @@ class Logout(AbstractPlugin):
self.local_settings_path = '/etc/opt/chrome/'
self.local_settings_proxy_profile = '/etc/profile.d/'
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
self.logger.info('Parameters were initialized.')
self.user_js_file = "browser_chrome_preferences_{0}.json"
self.user_js_file = 'liderahenk_browser_chrome_preferences.json'
self.logger.debug('Parameters were initialized.')
def handle_logout_mode(self):
username = self.get_username()
profil_full_path = self.local_settings_path+self.local_settings_path_suffix+self.user_js_file.format(username)
profil_full_path = self.local_settings_path+self.local_settings_path_suffix+self.user_js_file
profil_proxy_path = self.local_settings_proxy_profile+self.local_settings_proxy_file
if self.is_exist(profil_full_path):
self.delete_file(profil_full_path)

View file

@ -3,24 +3,25 @@
# Author: Ebru Arslan <16ebruarslan@gmail.com>
import json
import os
import os,re
from pathlib import Path
from base.plugin.abstract_plugin import AbstractPlugin
class BrowserChrome(AbstractPlugin):
def __init__(self, data, context):
super(AbstractPlugin, self).__init__()
self.data = data
self.context = context
self.logger = self.get_logger()
self.message_code = self.get_message_code()
self.local_settings_path_suffix = 'policies/managed/'
self.local_settings_path = '/etc/opt/chrome/'
self.local_settings_proxy_profile = '/etc/profile.d/'
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
self.logger.info('Parameters were initialized.')
self.user_js_file = "browser_chrome_preferences_{0}.json"
super(AbstractPlugin, self).__init__()
self.data = data
self.context = context
self.logger = self.get_logger()
self.message_code = self.get_message_code()
self.local_settings_path_suffix = 'policies/managed/'
self.local_settings_path = '/etc/opt/chrome/'
self.local_settings_proxy_profile = '/etc/profile.d/'
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
self.user_js_file = 'liderahenk_browser_chrome_preferences.json'
self.logger.info('Parameters were initialized.')
def create_chrome_file(self):
try:
@ -58,17 +59,13 @@ class BrowserChrome(AbstractPlugin):
def write_to_profile(self):
username = self.get_username()
path = self.local_settings_path+self.local_settings_path_suffix
file = self.user_js_file.format(username)
file_full_path = path + file
file_full_path = self.local_settings_path+self.local_settings_path_suffix+self.user_js_file
self.silent_remove(file_full_path)
self.create_file(file_full_path)
preferences = json.loads(self.data)
self.logger.debug('Writing preferences chrome to file ...')
content = "{\n"
for pref in preferences["preferencesChrome"]:
self.logger.debug(pref)
line = ""
if pref["value"] == "false" or pref["value"] == "true":
line = '"'+pref["preferenceName"]+'":' + str(pref["value"])+',\n'
@ -79,6 +76,7 @@ class BrowserChrome(AbstractPlugin):
content += line
content += "\n}"
self.logger.debug(content)
self.write_file(file_full_path, content)
self.logger.debug('User chrome preferences were wrote successfully')
@ -92,7 +90,6 @@ class BrowserChrome(AbstractPlugin):
line = ""
if len(proxy_preferences) > 0:
proxy_data = proxy_preferences["proxyListChrome"]
self.logger.debug(proxy_data)
if proxy_data[0].get('value') == '0' :
line = proxy_data[1].get('preferenceName')

View file

@ -0,0 +1,30 @@
from base.plugin.abstract_plugin import AbstractPlugin
class Safe(AbstractPlugin):
def __init__(self, context):
super(Safe, self).__init__()
self.context = context
self.logger = self.get_logger()
self.local_settings_path_suffix = 'policies/managed/'
self.local_settings_path = '/etc/opt/chrome/'
self.local_settings_proxy_profile = '/etc/profile.d/'
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
self.user_js_file = 'liderahenk_browser_chrome_preferences.json'
self.logger.info('Parameters were initialized.')
def handle_safe_mode(self):
profil_full_path = self.local_settings_path+self.local_settings_path_suffix+self.user_js_file
profil_proxy_path = self.local_settings_proxy_profile+self.local_settings_proxy_file
if self.is_exist(profil_full_path):
self.delete_file(profil_full_path)
if self.is_exist(profil_proxy_path):
self.delete_file(profil_proxy_path)
else:
self.logger.debug("{0} user's privilege file not found".format(username))
def handle_mode(context):
init = Safe(context)
init.handle_safe_mode()