SOGo Addons for WAPT
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
3.1 KiB

  1. # -*- coding: UTF-8 -*-
  2. from setuphelpers import *
  3. import os
  4. from jinja2 import Environment, FileSystemLoader
  5. uninstallkey = []
  6. variables = {
  7. 'sogo_server': 'mail.server.local'
  8. }
  9. def install():
  10. # Read local variables file if available
  11. if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')):
  12. print('Reading local encrypted variables file')
  13. from cryptography.fernet import Fernet
  14. import yaml
  15. f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
  16. variables.update(yaml.safe_load(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read())))
  17. connector_version = control['version'].split('-',1)[0]
  18. major_version = control['version'].split('.',1)[0]
  19. extension_dir = makepath(programfiles,'Mozilla Thunderbird','distribution','extensions')
  20. for extension in ['connector', 'integrator']:
  21. if isdir(makepath(extension_dir, 'sogo-%s@inverse.ca' % extension)):
  22. remove_tree(makepath(extension_dir, 'sogo-%s@inverse.ca' % extension))
  23. if isfile(makepath(extension_dir, 'sogo-%s@inverse.ca.xpi' % extension)):
  24. remove_file(makepath(extension_dir, 'sogo-%s@inverse.ca.xpi' % extension))
  25. mkdirs(makepath(extension_dir, 'sogo-connector@inverse.ca'))
  26. # The extension must be customized, so first extract it
  27. print('Extraction demo extension')
  28. unzip('sogo-connector-%s-demo.xpi' % connector_version, makepath(extension_dir,'sogo-connector@inverse.ca'))
  29. # And replace the extensions.rdf content
  30. print('Customizing extension')
  31. jinja2 = Environment(
  32. loader=FileSystemLoader(os.path.dirname(os.path.abspath(__file__))),
  33. trim_blocks=True
  34. )
  35. open(makepath(extension_dir,'sogo-connector@inverse.ca','chrome','content','sogo-connector','global','extensions.rdf'),'w').write(
  36. jinja2.get_template('extensions.rdf.j2').render(
  37. sogo_server = variables['sogo_server']
  38. )
  39. )
  40. # Also remove custom settings
  41. os.unlink(makepath(extension_dir,'sogo-connector@inverse.ca','defaults','preferences','site.js'))
  42. # Now create an XPI
  43. print('Creating XPI')
  44. run(r'"%s" a -tzip "%s" "%s"' %(makepath(programfiles, '7-Zip', '7z.exe'), makepath(extension_dir, 'sogo-connector@inverse.ca.xpi'), makepath(extension_dir, 'sogo-connector@inverse.ca', '*')))
  45. # Note : we could remove the extension directory, but we keep it for easier auditing
  46. def uninstall():
  47. print('Removing SOGo connector for Thunderbird')
  48. remove_tree(makepath(programfiles,'Mozilla Thunderbird','distribution','extensions','sogo-connector@inverse.ca' % extension))
  49. def audit():
  50. connector_version = control['version'].split('-',1)[0]
  51. try:
  52. run('type "%s" | find /I "em:version=" | find "%s"' % (makepath(programfiles,'Mozilla Thunderbird','distribution','extensions','sogo-connector@inverse.ca','install.rdf'), connector_version))
  53. except:
  54. print('SOGO connector version check failed')
  55. return "ERROR"
  56. return "OK"