wapt-firefox-config/setup.py

44 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
from setuphelpers import *
import json
from cryptography.fernet import Fernet
import os
from jinja2 import Environment, FileSystemLoader
uninstallkey = []
variables = {
'firefox_config_url': 'https://server/mcd/firefox.cfg',
'firefox_config_append_domain': ''
}
# Read local variables file if available
if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')):
print('Reading local encrypted variables file')
f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
variables.update(json.loads(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read())))
def install():
filecopyto('autoconf.js',makepath(programfiles,'Mozilla Firefox','defaults','pref'))
filecopyto('override.ini',makepath(programfiles,'Mozilla Firefox'))
jinja2 = Environment(loader=FileSystemLoader(os.path.dirname(os.path.abspath(__file__))),trim_blocks=True)
open(makepath(programfiles,'Mozilla Firefox','firefox.cfg'),'w').write(
jinja2.get_template('firefox.cfg.j2').render(
firefox_config_url = variables['firefox_config_url'],
firefox_config_append_domain = variables['firefox_config_append_domain']
)
)
def uninstall():
os.unlink(makepath(programfiles,'Mozilla Firefox','defaults','pref','autoconf.js'))
os.unlink(makepath(programfiles,'Mozilla Firefox','override.ini'))
os.unlink(makepath(programfiles,'Mozilla Firefox','firefox.cfg'))
def audit():
if (
not isfile(makepath(programfiles,'Mozilla Firefox','defaults','pref','autoconf.js')) or
not isfile(makepath(programfiles,'Mozilla Firefox','override.ini')) or
not isfile(makepath(programfiles,'Mozilla Firefox','firefox.cfg'))
):
print('At least one config file is missing')
return "ERROR"
return "OK"