Merge pull request #5 in KSC/webapp-tools from remove_old_files to master

* commit '1425c84ce01bee97e9f3f29c6fe289c1675d0c94':
  Remove files that are replaced by webapp_admin
This commit is contained in:
Robin van Genderen 2019-02-08 14:48:59 +01:00
commit d3c0f36c1b
8 changed files with 0 additions and 282 deletions

View File

@ -1,38 +0,0 @@
#!/usr/bin/env python
import kopano
from MAPI.Util import *
try:
import json
except ImportError:
import simplejson as json
def opt_args():
parser = kopano.parser('skpcf')
parser.add_option("--user", dest="user", action="store", help="Dump signatures for user")
return parser.parse_args()
def main():
options, args = opt_args()
if not options.user:
print 'Please use:\n %s --user <username>' % (sys.argv[0])
else:
user = kopano.Server(options=options).user(options.user)
try:
settings = json.loads(user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).value)
except Exception as e:
print 'Could not load WebApp settings for user %s (Error: %s)' % (user.name, repr(e))
else:
if len(settings['settings']['zarafa']['v1']['contexts']['mail']):
if 'signatures' in settings['settings']['zarafa']['v1']['contexts']['mail']:
for item in settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all']:
name = settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all'][item]['name']
filename = '%s-%s-%s.html' % (user.name, name.replace(' ', '-'), item)
with open(filename, 'w') as outfile:
print 'Dumping: \'%s\' to \'%s\' ' % (name, filename)
outfile.write(settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all'][item]['content'].encode('utf-8'))
if __name__ == '__main__':
main()

View File

@ -1,12 +0,0 @@
dump_webapp_signatures.py
=========================
Dumps all the signatures in a users Webapp to seperate files, meant as companion to the script setdefaultsignature.py as delivered with Webapp (see /usr/share/doc/kopano-webapp/scripts/signatures/ on your Webapp server.)
The files will be written in the current directory.
#### Usage:
```
python dump_webapp_signatures.py --user user
```

View File

@ -1,25 +0,0 @@
# 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

@ -1,84 +0,0 @@
#!/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)

View File

@ -1,19 +0,0 @@
webapp_settings.py
==================
#### Usage:
###### Backup
```python
python webapp_settings.py --user user --backup
```
###### Restore
```python
python webapp_settings.py --user user --restore
```

View File

@ -1,52 +0,0 @@
#!/usr/bin/env python
#encoding: utf-8
from MAPI import *
from MAPI.Util import *
import sys
try:
import kopano
except ImportError:
import zarafa as kopano
try:
import json
except ImportError:
import simplejson as json
def opt_args():
parser = kopano.parser('skpcfm')
parser.add_option("--user", dest="user", action="store", help="Run script for user")
parser.add_option("--backup", dest="backup", action="store_true", help="Backup webapp setting ")
parser.add_option("--restore", dest="restore", action="store_true", help="Restore webapp settings")
parser.add_option("--remove", dest="remove", action="store_true", help="Remove webapp settings")
return parser.parse_args()
def main():
options, args = opt_args()
if not options.user or (not options.backup and not options.restore and not options.remove):
print 'Please use:\n %s --user <username> (--backup or --restore) ' % (sys.argv[0])
sys.exit()
user = kopano.Server(options).user(options.user)
if options.backup:
webapp = json.loads(user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).value)
f = open('%s.json' % user.name,'w')
f.write(json.dumps(webapp, sort_keys=True,
indent=4, separators=(',', ': ')))
f.close()
if options.restore:
with open('%s.json' % user.name) as data_file:
data = json.load(data_file)
print data
user.store.create_prop(PR_EC_WEBACCESS_SETTINGS_JSON, json.dumps(data))
if options.remove:
user.store.delete(user.store.prop('PR_EC_WEBACCESS_SETTINGS_JSON'))
if __name__ == "__main__":
main()

View File

@ -1,17 +0,0 @@
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
```

View File

@ -1,35 +0,0 @@
#!/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.create_prop(PR_EC_WEBACCESS_SETTINGS_JSON, json.dumps(settings))
if __name__ == "__main__":
main()