Script for adding Shared Folders

Hello Forum,

im about to write a simple script to add a shared folder to a user via z-push-admin.

But im stuck in getting the folderid from kopano-db.

Does someone knows where to find it or do i need to convert something?
if im finished, the script should work with just:

scriptname  'remove' 'username' 'local folder name'
optional with asking which device should remove the folder
or
scriptname 'add' 'username' 'local folder name' 'user from which is shared' 'typ'
optional with asking which device should add the folder

i will provide it here for others

///EDIT: Find a solution:
php /usr/share/z-push/backend/zarafa/listfolders.php -l ‘username’ and grep the name with following id :)
i leave this open to provide the script in the future

coffee_is_life

I guess you are talking about z-push 2.4 (your signature still says 2.3.9).

The required folder id can be retrieved via the listfolders.php script in /usr/share/z-push/backend/kopano/.

my signature isnt updated cause im using 2.3.9 in productive env… im working in test env atm :)
and i found the solution the same moment you posted :) edited and saw your answer popping up

coffee_is_life

Hello again,

im done with the first basic version, created on RHEL 7 (CentOS 7 with php56) - choosing device not implemented yet
confirmed working for emails, calendars and contacts.
i think there are some better programmers out there who can optimize it a bit :)

should i copy the raw bash code here or another scripting location?

coffee_is_life

Perhaps kopano-python is also a solution to find the user id: https://documentation.kopano.io/kopano_python_kopano/getting_started.html

@coffee_is_life You could create a gist on github for it.

Good Morning,

i’ve created a branch for that on git:

https://github.com/Coffee-IsLife/Z-Push-shared-folders

there will come updates such as adding a device-choice but not today, but i think this week.

Feel free to correct some ways i did in the script - was a 2h quick solution :)
but in most cases it might help some users to add folders without searching every folderid etc.

//EDIT: ok, got some time - device-choice is added

coffee_is_life

Hi @Coffee_is_life , seems great work.

Will this also work for the univention server which has a debian 9 base now?
Maybe you can turn this in to a plugin to in case the MDM Plugin is not working for me.

HI @theodorm,

i’m not familiar with plugins neither with debian. - since im using buildin linux commands and not using full paths this should work with debian aswell. feel free to test it on a testuser :)

i will look into plugin building and report back if i can or cannot accomplish that

are there some guidlines somewhere (remember to saw it somewhere ^^)

coffee_is_life

Hello again,

since its quite a task to merge this into a plugin and it would take some time, i cant do that within my worktime. in private i will try to take this time, but it would take weeks for me (did said im new to plugins and integration to webapp).

i will update my git and add a comment that everyone is welcome to create this plugin - think its quite usefull for admins to manage this via clicky color gui :)

coffee_is_life

@Coffee_is_life
sounds great!!!..

I still don’t understand what this “plugin” should do any different than the mdm plugin for WebApp. But that may be just me.

@fbartels the MDM Plugin is not working on my System…it seems this script is working…

@Coffee_is_life
I have only one Problem whit the syntax at the moment…I see all the time when I add a folder the following.

Failed adding folder 'Kalender' for user 'user1' on device 'd1aar1gxxxxxxxxxxxs'. ASDevice->AddAdditionalFolder(): folder can not be added because there is already a folder with the same name synchronized in the same parent: 'Kalender'.

so my syntax was

bash add_shared_folder.sh "add" "user1" "Kalender" "user2" "calendar"

so user1 is the receiver the person who will receive this new calendar on his system…right?
user2 is the sender who shares the calendar.

It’s clear on the user1 system is also a Folder whit the Name Kalender and it can not be addet.

In case I use this

bash add_shared_folder.sh "add" "user1" "Kalender - user2" "user2" "calendar"

i got this error

USER, FOLDERNAME, STORE, TYPE and FOLDERID are required for addshared command.

I was listing the folder through z-push admin but can’t figure out the syntax…sorry…
Or maybe the “Kalender” should get a different name on the device who receives the folder.

Think this something to observe.

I createt a different caldenar Treter

bash add_shared_folder.sh "add" "user1" "Treter" "user2" "calendar"

Than the skript shows me 2 calendars first Kalender and Treter, than the skript asks me to add folder id and after the rest of the process the folder is add.

In which file the configuration will be written?
Sorry for asking you…

Hello @theodorm,

there is no config written. its simply getting the folderids from user 2 with type “calendar” and list them.
if there is only one result it will use this (for calendar normally 1 result) and use this folderid to snip the original command from
z-push-admin

i advise to edit the script in the first sector “VARS” and change

debug=false

to

debug=true

it will print all results to the logfile (which can be edit in this section aswell)
and post the log if you cant figure out the bug yourself.
the command to add the store will be logged aswell and you can check it against “z-push-admin --help” syntax for adding the store

coffee_is_life

@Coffee_is_life
Hi…
thanks again…this really works great after I was able to understand how it works.
Don’t know why this mdm Plugin is not working but this works out of the box…thank you so much.
Will be great to have a working Plugin solution…

How firm are you whit kopano?

Best Theo

Pleas note if you wand name your Kalender Kalender User1 then it's not working if there are space between Kalender and User1 ... 
Example KalenderUser1 or Kalender-User1
Otherwise you will get a list whit all possible syntax...

Hi Theo,

@theodorm said in Script for adding Shared Folders:

Pleas note if you wand name your Kalender Kalender User1 then it's not working if there are space between Kalender and User1 ... 
Example KalenderUser1 or Kalender-User1
Otherwise you will get a list whit all possible syntax...

using z-push-admin it’s possible to add folders which contain spaces in the name, e.g.

z-push-admin -a addshared -u ol -n "Project 2" -f ef66451d403a42a09067f23ce7e6b599170700000000 -o system -t email
z-push-admin -a list -u ol --shared

Synchronized devices of user: ol
-----------------------------------------------------
DeviceId:		65aa
Device type:		WindowsOutlook
UserAgent:		Outlook/15.0 (15.0.4971.1000; C2R; x86)
Additional Folders:	1
	Folder name:	Project 2
	Store:		system
	Type:		Email
	Origin:		Shared
	Folder id:	ef66451d403a42a09067f23ce7e6b599170700000000
	Parent id:	0
	Synched:	Active
	------------------------
Kopano Outlook Extension:
	Version:	1.6.254
	Build:		873f554c71cfa9e1105c47c80cfe7ca5e081d537
	Build Date:	2017-12-01 09:57
	Capabilities:	receiveflags,sendflags,bcc,oof,ooftime,sharedfolders,webapp,freebusy,gab,notes,secondarycontacts,sendas,signatures,debugsupport,syncstate,deliveryreceipts
	Last access:	2018-03-21
Attention needed:	No errors known
-----------------------------------------------------

Manfred

@manfred thank you Manfred, whit this script it was not working for me whit a space…

Hi Theo,

just an update, on some systems you might need to quote the space with backslash:

z-push-admin -a addshared -u ol -n "Project\ 2" -f ef66451d403a42a09067f23ce7e6b599170700000000 -o system -t email

Manfred

HI,

will update the master today, so you can define in the VARS section if spaces should be masked or using it as is

//EDIT: just updated the file - choose in the VARs section " use_mask_spaces="(true|false)" "
working for me, replacing spaces " " with "\ " - can you confirm on your dist?

@theodorm im quite familiar with kopano and administration but since im a network administrator, managing servers etc. and no developer (just a hobby scripter :) ) i dont think i could create a good, bugfree plugin in time, so best would be if someone who can do this on the fly would create that or you could identify the mdm plugin failure. Like i said, i will use some private time on the plugin but no guaratee on even accomplishing that.

coffee_is_life