Full synchronization of shared folders, contacts, calendars between distributed Kerio Connect servers

Good afternoon, Habr!



A task



In my organization, a mail server is used on the Kerio Connect platform; mail servers serving their users are installed in different cities. Initially, there was no distributed structure, since domains differ at the third level, indicating the city of the site. Everything worked and everyone was happy. One fine day - the management set a task, a common calendar of affairs between all sites!



Background



Initially, the idea was to raise the Distributed Kerio mail domain and he will do everything himself. It was said, the distributed domain was created, but it was not there, the server was ready to synchronize calendars, folders, contacts - between domains located on the same server, but it was not at all going to synchronize data between several servers.



Of course, I did not expect such a trick and for a long time could not believe in the absence of the functionality I needed. Later I found documentary confirmation of this fact. Than I was very much puzzled and disappointed.



The task smoothly turned into a problem.



What were the options



  • Create two clients on different servers, which exchanged the necessary data with some third-party software. It was necessary to find this very third-party software that would implement this functionality - I don't like such a rake, but it seemed that this was the only quick solution.
  • . , Kerio , , - , , - .


, Kerio , , — .



, “ ”, 6 :



  • – .
  • — .


, – DFS







  • , OS Windows. ( Linux. OS)
  • , — .
  • DFS .
  • Kerio, , , Kerio . ( )
  • DFS.
  • - ( )




( )



1. Kerio Distributed domain





Master , .



, Kerio , ,



:







, Master :









— .



! , ( — )



— , .

— ( ) .



2. Kerio



, . , , .



– , , , - , .



.



~DataMail\mail\#public\ \#msgs

~DataMail\mail\**Domain**\#public\ \#msgs



, , #msgs — , .



3. DFS



DFS, , .



DFS — Windows Server, ,

MS DFS



DFS – .







.





( — ) .



.



4.





(DFS), — - - , - .



, , . 6 – 12 .



, - , DFS, - , #msgs , .



Kerio , , 6 .

, index.fld, Kerio . , , , , , Kerio - index.fld

— - - .



, - — , , , .



?



.





, —



. , - #msgs, , . .



, , (15 ) 3-4 .



, , .



Kerio API







, , –

session = callMethod("Domains.checkPublicFoldersIntegrity",{}, token)



, , - , .



, , , .





CMD



Re-index.bat



@echo off
set dir=%~dp0
%dir:~0,2%
CD "%~dp0\"
md "%CD%\LOG\"
md "%CD%\Setup\"

ECHO -Start- >> "%CD%\LOG\%Computername%.log"
ECHO Start -> %Computername% %Date% %Time% >> "%CD%\LOG\%Computername%.log"

SetLocal EnableDelayedExpansion
for /f "UseBackQ Delims=" %%A IN ("%CD%\Setup\%Computername%.List") do (
  set /a c+=1
  set "m!c!=%%A"
)

set d=%c%
Echo Folder = %c%
ECHO Folder = %c% >> "%CD%\LOG\%Computername%.log"
ECHO.
ECHO. >> "%CD%\LOG\%Computername%.log"

:start
cls
if %c% LSS 1 exit
set /a id=1
set R=0

:Find
REM PF-Start
if "%id%" gtr "%c%" if %R% == 1 Goto Reindex 
if "%id%" gtr "%c%" timeout 60 && Goto start

For /F "tokens=1-3" %%a IN ('Dir "!m%id%!\#msgs\" /-C/S/A:-D') Do Set 2DirSize!id!=!DS!& Set DS=%%c
if "2DirSize!id!" == "" set 1DirSize!id!=!2DirSize%id%!

echo %id%
ECHO !m%id%!
echo Count        [ !1DirSize%id%! -- !2DirSize%id%! ]

if "!1DirSize%id%!" == "!2DirSize%id%!" ECHO Synk

REM DEL index.fld
if "!1DirSize%id%!" NEQ "!2DirSize%id%!" del /f /q !m%id%!\index.fld && del /f /q !m%id%!\indexlog.fld && del /f /q !m%id%!\search.fld && set R=1 && ECHO RE-index Count && ECHO RE-index Count %Date% %Time% - Delete !m%id%! >> "%CD%\LOG\%Computername%.log"

set 1DirSize!id!=!2DirSize%id%!

ECHO.
ECHO.

set /a id+=1
goto Find

:Reindex
ECHO. >> "%CD%\LOG\%Computername%.log"
ECHO --- RE-INDEX - Start - %Date% %Time% --- >> "%CD%\LOG\%Computername%.log"
ECHO. >> ----------------------------------- >> "%CD%\LOG\%Computername%.log"
call PublicFolders.py
timeout 60
goto start

exit


( , )



\Setup\%Computername%.List



%Computername% — ( .)



%Computername%.List – , , .



, , .



.



, , , : index.fld, indexlog.fld, search.fld — .



LOG .



Indexing

process The indexing process is reduced to executing the API function Kerio

Session = callMethod ("Domains.checkPublicFoldersIntegrity", {}, token)



An example of execution is given in - python

PublicFolders.py



import json
import urllib.request
import http.cookiejar
""" Cookie storage is necessary for session handling """
jar = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))
urllib.request.install_opener(opener)
""" Hostname or ip address of your Kerio Control instance with protocol, port and credentials """

server = "http://127.0.0.1:4040"
username = "user"
password = "password"

def callMethod(method, params, token = None):
    """
    Remotely calls given method with given params.
    :param: method string with fully qualified method name
    :param: params dict with parameters of remotely called method
    :param: token CSRF token is always required except login method. Use method "Session.login" to obtain this token.
    """
    data =  {"method": method ,"id":1, "jsonrpc":"2.0", "params": params}

    req = urllib.request.Request(url = server + '/admin/api/jsonrpc/')
    req.add_header('Content-Type', 'application/json')
    if (token is not None):
        req.add_header('X-Token', token)    

    httpResponse = urllib.request.urlopen(req, json.dumps(data).encode())

    if (httpResponse.status == 200):
        body = httpResponse.read().decode()
        return json.loads(body)

session = callMethod("Session.login", {"userName":username, "password":password, "application":{"vendor":"Kerio", "name":"Control Api-Local", "version":"Python"}})
token = session["result"]["token"]
print (session)

session = callMethod("Domains.checkPublicFoldersIntegrity",{"domainId": "test2.local"}, token)
print (session)

callMethod("Session.logout",{}, token)


http://127.0.0.1:4040 can be left as is, however if you require HTTPS - python must trust the Kerio certificate.



Also in the file you must specify an account with the rights to perform this function (Admin - shared mail folders) of the mail server.



I hope my article will be useful for Kerio Connect administrators.




All Articles