2016-08-10 09:57:57 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#encoding: utf-8
|
2016-07-28 15:01:35 +02:00
|
|
|
|
|
|
|
from MAPI import *
|
|
|
|
from MAPI.Util import *
|
|
|
|
import sys
|
|
|
|
try:
|
2017-02-15 09:05:45 +01:00
|
|
|
import kopano
|
2017-03-27 11:09:12 +02:00
|
|
|
except ImportError:
|
2017-02-15 09:05:45 +01:00
|
|
|
import zarafa as kopano
|
|
|
|
try:
|
|
|
|
import json
|
2016-07-28 15:01:35 +02:00
|
|
|
except ImportError:
|
2017-02-15 09:05:45 +01:00
|
|
|
import simplejson as json
|
2016-07-28 15:01:35 +02:00
|
|
|
|
|
|
|
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")
|
2018-03-05 12:30:18 +01:00
|
|
|
parser.add_option("--remove", dest="remove", action="store_true", help="Remove webapp settings")
|
2016-07-28 15:01:35 +02:00
|
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
options, args = opt_args()
|
|
|
|
|
2018-03-05 12:30:18 +01:00
|
|
|
if not options.user or (not options.backup and not options.restore and not options.remove):
|
2016-07-28 15:01:35 +02:00
|
|
|
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
|
2018-03-05 16:04:49 +01:00
|
|
|
user.store.create_prop(PR_EC_WEBACCESS_SETTINGS_JSON, json.dumps(data))
|
2018-03-05 12:30:18 +01:00
|
|
|
|
|
|
|
if options.remove:
|
|
|
|
user.store.delete(user.store.prop('PR_EC_WEBACCESS_SETTINGS_JSON'))
|
|
|
|
|
2016-07-28 15:01:35 +02:00
|
|
|
if __name__ == "__main__":
|
2018-03-05 12:30:18 +01:00
|
|
|
main()
|