proxy settings done

This commit is contained in:
3bru 2023-02-22 17:50:04 +03:00
parent ee9e3944ff
commit eb9204a437
2 changed files with 38 additions and 10 deletions

View file

@ -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,10 +78,36 @@ 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()