Merge remote-tracking branch 'origin/master'

This commit is contained in:
robing 2017-02-15 08:06:07 +00:00
commit 0678b0ef9b
3 changed files with 161 additions and 1 deletions

View File

@ -57,6 +57,47 @@ Dumps all the signatures in a users Webapp to seperate files, meant as companion
The files will be written in the current directory.
#### Usage:
```python
```
python dump_webapp_signatures.py --user user
```
webapp_switch_locale.py
=========================
List or change the locale currently set in the user's WebApp settings.
#### Usage:
###### List locale
```
python switchlocale.py --user user1
Original locale: nl_NL.UTF-8
```
###### Change locale
```
python switchlocale.py --user user1 --locale de_DE.UTF-8
Original locale: nl_NL.UTF-8
Setting locale to: de_DE.UTF-8
```
# set_webapp_default_signature.py
Add and set a Default signature in Webapp for user(s), will overwrite any other default.
Please use a signature as dumped with dump_webapp_signatures.py
## Examples
### Set signature of a local user on the local server
```
./set_webapp_default_signature.py -u user1 -f user2-signature.sig
```
### Set signature multiple local users on the local server
```
./set_webapp_default_signature.py -u user1 -u user3 -f user2-signature.sig
```
### Set signature for all local users on the local server
```
./set_webapp_default_signature.py -a -f user2-signature.sig
```

View File

@ -0,0 +1,84 @@
#!/usr/bin/env python
# coding=utf-8
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
"""
Set A Default WebApp Signature.
"""
import json
import kopano
from MAPI.Tags import *
def read_settings(user):
try:
mapisettings = user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).value
settings = json.loads(mapisettings)
except Exception as e:
print '%s: Has no or no valid WebApp settings creating empty config tree' % user.name
settings = json.loads(
'{"settings": {"zarafa": {"v1": {"contexts": {"mail": {}}}}}}')
return settings
def write_settings(user, webappsettings):
try:
user.store.create_prop(PR_EC_WEBACCESS_SETTINGS_JSON, webappsettings)
except Exception as e:
print '%s: Error Writing WebApp settings for user: %s' % (e, user.name)
def main(options):
with open(options.file, 'r') as sigfile:
signaturehtml = sigfile.read()
signatureid = '1'
signaturename = options.file.replace('template', 'default').replace('-', ' ').replace('.html', '').title().split('/')[-1].replace(' Nl', ' NL').replace(
' De', ' DE')
signaturecontent = dict(
{u'name': signaturename, u'content': signaturehtml, u'isHTML': True})
runusers = []
if options.allusers:
for ruser in server.users(remote=False):
runusers.append(ruser.name)
else:
runusers = options.users
for username in runusers:
try:
user = server.user(username)
webappsettings = read_settings(user)
except Exception as e:
print e
continue
if not len(webappsettings['settings']['zarafa']['v1']['contexts']['mail']):
print "%s: Adding config tree." % user.name
webappsettings['settings']['zarafa'][
'v1']['contexts']['mail'] = dict({})
if 'signatures' not in list(webappsettings['settings']['zarafa']['v1']['contexts']['mail']):
print "%s: Adding Signature settings to config tree." % user.name
webappsettings['settings']['zarafa']['v1'][
'contexts']['mail']['signatures'] = dict({})
if 'all' not in list(webappsettings['settings']['zarafa']['v1']['contexts']['mail']['signatures']):
print "%s: Empty Signature settings detected." % user.name
webappsettings['settings']['zarafa']['v1']['contexts'][
'mail']['signatures'] = dict({'all': dict({})})
print '%s: Adding/Replacing Default Signature with %s' % (user.name, signaturename)
webappsettings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all'][
signatureid] = signaturecontent
webappsettings['settings']['zarafa']['v1']['contexts'][
'mail']['signatures']['new_message'] = signatureid
webappsettings['settings']['zarafa']['v1']['contexts']['mail']['signatures'][
'replyforward_message'] = signatureid
write_settings(user, json.dumps(webappsettings))
if __name__ == '__main__':
parser = kopano.parser('uUPckpsC') # select common cmd-line options
parser.add_option('-a', dest='allusers', action='store_true',
default=None, help='run program for all local users')
parser.add_option('-f', dest='file', action='store',
default=None, help='signature filename')
options, args = parser.parse_args()
server = kopano.Server(options=options)
if (options.users or options.allusers) and options.file:
main(options)

35
webapp_switch_locale.py Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env python
# encoding: utf-8
import json
import kopano
from MAPI.Util import *
import sys
def opt_args():
parser = kopano.parser('skpcfm')
parser.add_option("--user", dest="user", action="store", help="Run script for user")
parser.add_option("--locale", dest="locale", action="store", help="Set new locale")
return parser.parse_args()
def main():
options, args = opt_args()
if not options.user:
print 'Please use:\n %s --user <username> [--locale]' % (sys.argv[0])
sys.exit()
user = kopano.Server(options).user(options.user)
settings = json.loads(user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).value)
current = settings['settings']['zarafa']['v1']['main']['language']
print 'Original locale: %s' % current
if options.locale:
print 'Setting locale to: %s' % options.locale
settings['settings']['zarafa']['v1']['main']['language'] = options.locale
user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).set_value(json.dumps(settings))
if __name__ == "__main__":
main()