mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-25 03:02:16 +03:00
added safe.py file
This commit is contained in:
parent
4063f1b81c
commit
f029e916ef
3 changed files with 47 additions and 22 deletions
|
@ -14,14 +14,12 @@ class Logout(AbstractPlugin):
|
||||||
self.local_settings_path = '/etc/opt/chrome/'
|
self.local_settings_path = '/etc/opt/chrome/'
|
||||||
self.local_settings_proxy_profile = '/etc/profile.d/'
|
self.local_settings_proxy_profile = '/etc/profile.d/'
|
||||||
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
|
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
|
||||||
self.logger.info('Parameters were initialized.')
|
self.user_js_file = 'liderahenk_browser_chrome_preferences.json'
|
||||||
self.user_js_file = "browser_chrome_preferences_{0}.json"
|
|
||||||
|
|
||||||
self.logger.debug('Parameters were initialized.')
|
self.logger.debug('Parameters were initialized.')
|
||||||
|
|
||||||
def handle_logout_mode(self):
|
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
|
||||||
profil_full_path = self.local_settings_path+self.local_settings_path_suffix+self.user_js_file.format(username)
|
|
||||||
profil_proxy_path = self.local_settings_proxy_profile+self.local_settings_proxy_file
|
profil_proxy_path = self.local_settings_proxy_profile+self.local_settings_proxy_file
|
||||||
if self.is_exist(profil_full_path):
|
if self.is_exist(profil_full_path):
|
||||||
self.delete_file(profil_full_path)
|
self.delete_file(profil_full_path)
|
||||||
|
|
|
@ -3,24 +3,25 @@
|
||||||
# Author: Ebru Arslan <16ebruarslan@gmail.com>
|
# Author: Ebru Arslan <16ebruarslan@gmail.com>
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os,re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from base.plugin.abstract_plugin import AbstractPlugin
|
from base.plugin.abstract_plugin import AbstractPlugin
|
||||||
|
|
||||||
class BrowserChrome(AbstractPlugin):
|
class BrowserChrome(AbstractPlugin):
|
||||||
|
|
||||||
def __init__(self, data, context):
|
def __init__(self, data, context):
|
||||||
super(AbstractPlugin, self).__init__()
|
super(AbstractPlugin, self).__init__()
|
||||||
self.data = data
|
self.data = data
|
||||||
self.context = context
|
self.context = context
|
||||||
self.logger = self.get_logger()
|
self.logger = self.get_logger()
|
||||||
self.message_code = self.get_message_code()
|
self.message_code = self.get_message_code()
|
||||||
self.local_settings_path_suffix = 'policies/managed/'
|
self.local_settings_path_suffix = 'policies/managed/'
|
||||||
self.local_settings_path = '/etc/opt/chrome/'
|
self.local_settings_path = '/etc/opt/chrome/'
|
||||||
self.local_settings_proxy_profile = '/etc/profile.d/'
|
self.local_settings_proxy_profile = '/etc/profile.d/'
|
||||||
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
|
self.local_settings_proxy_file = 'liderahenk_chrome_proxy.sh'
|
||||||
self.logger.info('Parameters were initialized.')
|
self.user_js_file = 'liderahenk_browser_chrome_preferences.json'
|
||||||
self.user_js_file = "browser_chrome_preferences_{0}.json"
|
|
||||||
|
self.logger.info('Parameters were initialized.')
|
||||||
|
|
||||||
def create_chrome_file(self):
|
def create_chrome_file(self):
|
||||||
try:
|
try:
|
||||||
|
@ -58,17 +59,13 @@ class BrowserChrome(AbstractPlugin):
|
||||||
|
|
||||||
|
|
||||||
def write_to_profile(self):
|
def write_to_profile(self):
|
||||||
username = self.get_username()
|
file_full_path = self.local_settings_path+self.local_settings_path_suffix+self.user_js_file
|
||||||
path = self.local_settings_path+self.local_settings_path_suffix
|
|
||||||
file = self.user_js_file.format(username)
|
|
||||||
file_full_path = path + file
|
|
||||||
self.silent_remove(file_full_path)
|
self.silent_remove(file_full_path)
|
||||||
self.create_file(file_full_path)
|
self.create_file(file_full_path)
|
||||||
preferences = json.loads(self.data)
|
preferences = json.loads(self.data)
|
||||||
self.logger.debug('Writing preferences chrome to file ...')
|
self.logger.debug('Writing preferences chrome to file ...')
|
||||||
content = "{\n"
|
content = "{\n"
|
||||||
for pref in preferences["preferencesChrome"]:
|
for pref in preferences["preferencesChrome"]:
|
||||||
self.logger.debug(pref)
|
|
||||||
line = ""
|
line = ""
|
||||||
if pref["value"] == "false" or pref["value"] == "true":
|
if pref["value"] == "false" or pref["value"] == "true":
|
||||||
line = '"'+pref["preferenceName"]+'":' + str(pref["value"])+',\n'
|
line = '"'+pref["preferenceName"]+'":' + str(pref["value"])+',\n'
|
||||||
|
@ -79,6 +76,7 @@ class BrowserChrome(AbstractPlugin):
|
||||||
content += line
|
content += line
|
||||||
|
|
||||||
content += "\n}"
|
content += "\n}"
|
||||||
|
self.logger.debug(content)
|
||||||
self.write_file(file_full_path, content)
|
self.write_file(file_full_path, content)
|
||||||
|
|
||||||
self.logger.debug('User chrome preferences were wrote successfully')
|
self.logger.debug('User chrome preferences were wrote successfully')
|
||||||
|
@ -92,7 +90,6 @@ class BrowserChrome(AbstractPlugin):
|
||||||
line = ""
|
line = ""
|
||||||
if len(proxy_preferences) > 0:
|
if len(proxy_preferences) > 0:
|
||||||
proxy_data = proxy_preferences["proxyListChrome"]
|
proxy_data = proxy_preferences["proxyListChrome"]
|
||||||
self.logger.debug(proxy_data)
|
|
||||||
if proxy_data[0].get('value') == '0' :
|
if proxy_data[0].get('value') == '0' :
|
||||||
line = proxy_data[1].get('preferenceName')
|
line = proxy_data[1].get('preferenceName')
|
||||||
|
|
||||||
|
|
30
src/plugins/browser-chrome/safe.py
Normal file
30
src/plugins/browser-chrome/safe.py
Normal 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()
|
Loading…
Reference in a new issue