From eb9204a43783aa31f6a66694b2e2a95bfc0b48f1 Mon Sep 17 00:00:00 2001 From: 3bru <16ebruarslan@gmail.com> Date: Wed, 22 Feb 2023 17:50:04 +0300 Subject: [PATCH] proxy settings done --- src/plugins/browser-chrome/main.py | 2 +- src/plugins/browser-chrome/policy.py | 46 ++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/plugins/browser-chrome/main.py b/src/plugins/browser-chrome/main.py index 79b4d94..d87b112 100644 --- a/src/plugins/browser-chrome/main.py +++ b/src/plugins/browser-chrome/main.py @@ -14,4 +14,4 @@ def info(): inf['machine_oriented'] = True inf['developer'] = '16ebruarslan@gmail.com' - return inf \ No newline at end of file + return inf diff --git a/src/plugins/browser-chrome/policy.py b/src/plugins/browser-chrome/policy.py index 93f7dc5..66fe529 100644 --- a/src/plugins/browser-chrome/policy.py +++ b/src/plugins/browser-chrome/policy.py @@ -17,6 +17,8 @@ class BrowserChrome(AbstractPlugin): 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" @@ -26,9 +28,6 @@ class BrowserChrome(AbstractPlugin): except: raise - #def is_installed(package_name): ile true/false kontrol edilecek - - def handle_policy(self): self.logger.info('Browser Chrome plugin handling...') try: @@ -36,10 +35,14 @@ class BrowserChrome(AbstractPlugin): username = self.get_username() self.logger.info('Username: {}'.format(username)) self.logger.debug('Writing preferences to user profile') - self.write_to_profile() + #self.write_to_profile() + try: + self.write_to_chrome_proxy() + except Exception as e: + self.logger.error(e) self.context.create_response(code=self.message_code.POLICY_PROCESSED.value, message='Kullanıcı browser chrome profili başarıyla uygulandı.') except Exception as e: - self.logger.error('A problem occurred while handling browser profile: {0}'.format(str(e))) + self.logger.error('A problem occurred while handling chrome browser profile: {0}'.format(str(e))) self.context.create_response(code=self.message_code.POLICY_ERROR.value, message='Browser Chrome profili uygulanırken bir hata oluştu.') def silent_remove(self, filename): @@ -58,9 +61,8 @@ class BrowserChrome(AbstractPlugin): path = self.local_settings_path+self.local_settings_path_suffix file = self.user_js_file.format(username) self.silent_remove(file) - user_js = open(path + file, "w") + user_js = open(path + file, "a") preferences = json.loads(self.data)['preferencesChrome'] - print(type(preferences)) self.logger.debug('Writing preferences chrome to file ...') user_js.write('{\n') for pref in preferences: @@ -76,12 +78,38 @@ class BrowserChrome(AbstractPlugin): user_js.write(line) user_js.write('\n}') - self.logger.debug('User preferences were wrote successfully') + self.logger.debug('User chrome preferences were wrote successfully') user_js.close() + def write_to_chrome_proxy(self): + proxy_full_path = self.local_settings_proxy_profile + self.local_settings_proxy_file + self.silent_remove(proxy_full_path) + # proxy preference lenght bak varsa çalıştır yoksa passs + proxy_preferences = json.loads(self.data)['proxyListChrome'] + self.logger.debug(proxy_preferences) + proxy_sh = self.create_file(proxy_full_path) + content = "" + for proxy in proxy_preferences: + + if proxy['value'].isdigit() or str(proxy['value']) == 'false' or str(proxy['value']) == 'true': + value = proxy['value'] + else: + value = '\"' + proxy['value'] + '\"' + line = '"' + str(proxy['preferenceName']) + '": ' + value + ',\n' + content += line + self.logger.debug(content) + + self.write_file(proxy_full_path, content) + self.execute_script(proxy_full_path) + # subprocess.Popen('sudo chmod +x {0}'.format(proxy_sh), shell=True) + self.logger.debug('User proxy preferences were wrote successfully') + + +#sudo chmod +x /etc/profile.d/proxy.sh + def handle_policy(profile_data, context): browser = BrowserChrome(profile_data, context) browser.handle_policy() - \ No newline at end of file +