Rename inject files to files_admin
This commit is contained in:
22
files_admin/README.md
Normal file
22
files_admin/README.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Files Admin
|
||||
|
||||
Files admin is a command-line interface to modify, inject and export kopano-files settings.
|
||||
|
||||
# Files backend supported
|
||||
|
||||
* SMB
|
||||
* Owncloud
|
||||
* Webddav
|
||||
|
||||
# Example Usage
|
||||
|
||||
Inject settings from owncloud and smb config file
|
||||
> python files_admin -user John --file owncloud.cfg,smb.cfg
|
||||
|
||||
Use the username and password provided in the config file
|
||||
> python files_admin -user John --file owncloud.cfg,smb.cfg --default
|
||||
|
||||
# Dependencies
|
||||
|
||||
- python-kopano
|
||||
- python-mapi
|
20
files_admin/deencode.php
Normal file
20
files_admin/deencode.php
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
||||
|
||||
include "/etc/kopano/webapp/config-files.php";
|
||||
|
||||
if ( $argv[1] == 'encode' ) {
|
||||
$value = openssl_encrypt($argv[2], "des-ede3-cbc", FILES_PASSWORD_KEY, 0, FILES_PASSWORD_IV);
|
||||
}
|
||||
elseif ( $argv[1] == 'decode' ) {
|
||||
$value = openssl_decrypt($argv[2], "des-ede3-cbc", FILES_PASSWORD_KEY, 0, FILES_PASSWORD_IV);
|
||||
}
|
||||
else {
|
||||
print "No valid options provided usage php dencode.php encode/decode string\n";
|
||||
}
|
||||
|
||||
if ( ! empty($value) ) {
|
||||
print $value;
|
||||
}
|
||||
?>
|
131
files_admin/files_admin.py
Normal file
131
files_admin/files_admin.py
Normal file
@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python
|
||||
import subprocess
|
||||
from configobj import ConfigObj
|
||||
import uuid
|
||||
from MAPI.Util import *
|
||||
import kopano
|
||||
# Try simplejson if json is not available
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
|
||||
def encode(value):
|
||||
proc = subprocess.Popen(["php", "deencode.php", "encode", value], stdout=subprocess.PIPE)
|
||||
return proc.communicate()[0]
|
||||
|
||||
|
||||
def opt_args():
|
||||
parser = kopano.parser('skpcfmUP')
|
||||
parser.add_option("--user", dest="user", action="store", help="username")
|
||||
parser.add_option("--file", dest="file", default=[], action="store", help="config file(s) separate by ',' ")
|
||||
parser.add_option("--overwrite", dest="overwrite", action="store_true", help="overwrite files settings")
|
||||
parser.add_option("--default", dest="default", action="store_true",
|
||||
help="use default user and password in the configfile")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def read_settings(options):
|
||||
|
||||
try:
|
||||
user = kopano.Server(options).user(options.user)
|
||||
except MAPIErrorLogonFailed as e:
|
||||
print('User \'{}\' not found ({})'.format(options.user, e))
|
||||
sys.exit(1)
|
||||
|
||||
if not user.store:
|
||||
print('User \'{}\' has no user store ({})'.format(options.user, e))
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
mapisettings = user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).value
|
||||
return mapisettings
|
||||
except Exception:
|
||||
print('{}: Has no or no valid WebApp settings creating empty config tree'.format(user.name))
|
||||
return '{"settings": {"zarafa": {"v1": {"contexts": {"mail": {}}}}}}'
|
||||
|
||||
|
||||
def write_settings(data, options):
|
||||
user = kopano.Server(options).user(options.user)
|
||||
user.store.create_prop(PR_EC_WEBACCESS_SETTINGS_JSON, data.encode('utf-8'))
|
||||
print('Writing settings for user \'{}\''.format(user.fullname))
|
||||
|
||||
|
||||
def files(options):
|
||||
filesjson = '{'
|
||||
if options.overwrite:
|
||||
filesjson = '{"accounts": {'
|
||||
num = 0
|
||||
files = options.file.split(',')
|
||||
for file in files:
|
||||
configfile = ConfigObj(file)
|
||||
if options.default:
|
||||
username = configfile['setting']['default_user']
|
||||
else:
|
||||
username = options.user
|
||||
if num != 0:
|
||||
filesjson += ','
|
||||
id = uuid.uuid4()
|
||||
filesjson += '''
|
||||
"%s": {
|
||||
"status": "ok",
|
||||
"backend_config": {
|
||||
"server_path": "%s",
|
||||
"workgroup": "%s",
|
||||
"server_address": "%s",
|
||||
"server_ssl": %s,
|
||||
"current_account_id": "%s",
|
||||
"use_zarafa_credentials": %s,
|
||||
"user": "%s",
|
||||
"password": "%s",
|
||||
"server_port": "%s"
|
||||
},
|
||||
"cannot_change": false,
|
||||
"name": "%s",
|
||||
"status_description": "Account is ready to use.",
|
||||
"id": "%s",
|
||||
"backend_features": {
|
||||
"Sharing": true,
|
||||
"VersionInfo": true,
|
||||
"Quota": true
|
||||
},
|
||||
"backend": "%s"
|
||||
}''' % (id, encode(configfile['setting']['server_path']), encode(configfile['setting']['workgroup']),
|
||||
encode(configfile['setting']['server_address']), configfile['setting']['server_ssl'],
|
||||
encode('d4cacda458a2a26c301f2b7d75ada530'), configfile['setting']['use_zarafa_credentials'],
|
||||
encode(username), encode(configfile['setting']['default_password']),
|
||||
encode(configfile['setting']['server_port']), configfile['setting']['name'], id, configfile['setting']['type'])
|
||||
num += 1
|
||||
if options.overwrite:
|
||||
filesjson += '}}'
|
||||
else:
|
||||
filesjson += '}'
|
||||
return filesjson
|
||||
|
||||
|
||||
def main():
|
||||
options, args = opt_args()
|
||||
|
||||
data = read_settings(options)
|
||||
webappsettings = json.loads(data)
|
||||
|
||||
if not webappsettings['settings']['zarafa']['v1'].get('plugins'):
|
||||
webappsettings['settings']['zarafa']['v1']['plugins'] = {}
|
||||
|
||||
if options.overwrite:
|
||||
webappsettings['settings']['zarafa']['v1']['plugins']['files'] = json.loads(files(options))
|
||||
else:
|
||||
if not webappsettings['settings']['zarafa']['v1']['plugins'].get('files'):
|
||||
webappsettings['settings']['zarafa']['v1']['plugins']['files'] = {}
|
||||
if not webappsettings['settings']['zarafa']['v1']['plugins']['files'].get('accounts'):
|
||||
webappsettings['settings']['zarafa']['v1']['plugins']['files']['accounts'] = {}
|
||||
webappsettings['settings']['zarafa']['v1']['plugins']['files']['accounts'].update(json.loads(files(options)))
|
||||
|
||||
write_settings(json.dumps(webappsettings), options)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
11
files_admin/owncloud.cfg
Normal file
11
files_admin/owncloud.cfg
Normal file
@ -0,0 +1,11 @@
|
||||
[setting]
|
||||
name = Owncloud share
|
||||
type = Owncloud
|
||||
workgroup =
|
||||
server_path = /owncloud/remote.php/webdav
|
||||
server_address = zarafa.local
|
||||
server_ssl = true
|
||||
use_zarafa_credentials = false
|
||||
server_port = 443
|
||||
default_user = user
|
||||
default_password = welcome
|
12
files_admin/smb.cfg
Normal file
12
files_admin/smb.cfg
Normal file
@ -0,0 +1,12 @@
|
||||
[setting]
|
||||
|
||||
name = Samba share
|
||||
type = SMB
|
||||
workgroup = zarafa
|
||||
server_path = files
|
||||
server_address = 192.168.1.230
|
||||
server_ssl = false
|
||||
use_zarafa_credentials = true
|
||||
server_port = 80
|
||||
default_user = user
|
||||
default_password = welcome
|
Reference in New Issue
Block a user