From 0a8622f2f55a8d2441b1c61ba9c0b0c9a4875fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuncay=20=C3=87OLAK?= Date: Mon, 20 Mar 2023 10:52:59 +0300 Subject: [PATCH] revert default proxy settings in safe and logout --- src/plugins/browser-chrome/logout.py | 26 +++++++++++++++++++++----- src/plugins/browser-chrome/policy.py | 4 ++++ src/plugins/browser-chrome/safe.py | 28 ++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/plugins/browser-chrome/logout.py b/src/plugins/browser-chrome/logout.py index cb82986..ef0b171 100644 --- a/src/plugins/browser-chrome/logout.py +++ b/src/plugins/browser-chrome/logout.py @@ -12,19 +12,35 @@ class Logout(AbstractPlugin): 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.debug('Parameters were initialized.') + self.username = self.get_username() + if self.username is None: + self.username = self.get_active_user() def handle_logout_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) + + self.default_proxy_settings() + + def default_proxy_settings(self): + username = self.get_username() + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy autoconfig-url '''".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy ignore-hosts ['localhost', '127.0.0.0/8']".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy mode 'none''".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy use-same-proxy true'".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.ftp host '''".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.ftp port 0'".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.http host '''".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.http port 8080'".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.https host '''".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.https port 0'".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.socks host '''".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.socks port 0'".format(username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.http use-authentication false'".format(username)) def handle_mode(context): diff --git a/src/plugins/browser-chrome/policy.py b/src/plugins/browser-chrome/policy.py index 92b6a2c..13c458b 100644 --- a/src/plugins/browser-chrome/policy.py +++ b/src/plugins/browser-chrome/policy.py @@ -80,6 +80,8 @@ class BrowserChrome(AbstractPlugin): proxy_type = "0" proxy_preferences = json.loads(self.data) username = self.get_username() + if username is None: + username = self.get_active_user() if len(proxy_preferences) > 0: proxy_data = proxy_preferences["proxyListChrome"] for pref in proxy_data: @@ -117,6 +119,8 @@ class BrowserChrome(AbstractPlugin): def default_proxy_settings(self): username = self.get_username() + if username is None: + username = self.get_active_user() self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy autoconfig-url '''".format(username)) self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy ignore-hosts ['localhost', '127.0.0.0/8']".format(username)) self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy mode 'none''".format(username)) diff --git a/src/plugins/browser-chrome/safe.py b/src/plugins/browser-chrome/safe.py index 3b7dc5f..6579189 100644 --- a/src/plugins/browser-chrome/safe.py +++ b/src/plugins/browser-chrome/safe.py @@ -8,22 +8,34 @@ class Safe(AbstractPlugin): 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.') + self.username = self.get_username() + if self.username is None: + self.username = self.get_active_user() 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)) + self.logger.debug("{0} user's privilege file not found".format(self.username)) + self.default_proxy_settings() + + def default_proxy_settings(self): + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy autoconfig-url '''".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy ignore-hosts ['localhost', '127.0.0.0/8']".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy mode 'none''".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy use-same-proxy true'".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.ftp host '''".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.ftp port 0'".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.http host '''".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.http port 8080'".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.https host '''".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.https port 0'".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.socks host '''".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.socks port 0'".format(self.username)) + self.execute("su - {0} -c 'gsettings set org.gnome.system.proxy.http use-authentication false'".format(self.username)) def handle_mode(context): init = Safe(context)