tis-cwrsync 3.1.1-5

  • package : tis-cwrsync
  • version : 3.1.1-5
  • architecture : all
  • locale :
  • description : install of a cwRsync daemon manages by nssm. rsyncd.conf must be customized to suit your needs. meant to be used with tisbackup for example.
  • maintainer : Hubert TOUVET
  • date : 2018-02-27 18:58:29
  • min_wapt_version :
  • min_os_version :
  • max_os_version :
  • impacted_process :

setup.py

# -*- coding: utf-8 -*-
from setuphelpers import *
from iniparse import RawConfigParser
import string,random


uninstallkey = []

service_name = 'cwRsync'
portnumber = 873

install_path = makepath(programfiles32,service_name)
nssm_path = makepath(install_path,'nssm.exe')
rsync_conf = makepath(install_path,'rsyncd.conf')
rsync_secrets = makepath(install_path,'rsyncd.secrets')
rsync_log = makepath(install_path,'rsyncd.log')

def install():
    print('installing tis-cwrsync')

    if service_installed(service_name) and  not service_is_stopped(service_name):
        print('Stopping rsync service')
        service_stop(service_name)

    print('Copy of cwRsync binaries')
    copytree2('cwRsync',install_path)
    if not isfile(nssm_path):
        print('Copy of nssm binary')
        if iswin64():
            filecopyto(makepath('win64','nssm.exe'),nssm_path)
        else:
            filecopyto(makepath('win32','nssm.exe'),nssm_path)


    if not isfile(rsync_conf):
        print('Adding a rsyncd.conf file')
        filecopyto('rsyncd.conf',rsync_conf)
    else:
        print('Keeping existing rsyncd.conf file')


    if not isfile(rsync_secrets):
        print('Create a secrets file')
        password = ''.join(random.choice(string.ascii_letters + string.digits) for x in range(20))
        open(rsync_secrets,'w').write('root:%s'%password)
        print('root password is %s'% password)
    else:
        print('Keep existing secrets file')

    print('Set secrets readable only by administrators')
    print run('echo O| cacls "%s" /S:"D:PAI(A;;FA;;;SY)(A;;FA;;;BA)"' % rsync_secrets)
    print run('echo Y| cacls "%s" /S:"D:PAI(A;;FA;;;SY)(A;;FA;;;BA)"' % rsync_secrets)

    print('Open firewall')
    check_open_port()

    print('Install service with nssm manager')
    install_service()
    # or using cygrunsrv instead...
    #run(r'"{pf32}\cwRsync\cygrunsrv.exe" --install cwRsync -p "{pf32}\cwRsync\rsync.exe" -a "--config rsyncd.conf --daemon --no-detach" -c "{pf32}\cwRsync"'.format(pf32=programfiles32))

    print('Start rsync service')
    service_start(service_name)


def check_open_port():
    """Configure local firewall to accept incoming request to specified tcp port
    >>> check_open_port(8088)
    """
    import win32serviceutil
    import platform
    import win32service
    win_major_version = int(platform.win32_ver()[1].split('.')[0])
    try:
        if win_major_version<6:
            #check if firewall is running
            if win32serviceutil.QueryServiceStatus( 'SharedAccess', None)[1]==win32service.SERVICE_RUNNING:
                print(u"Firewall started, checking for port openning...")
                #WinXP 2003
                if service_name not in run_notfatal('netsh firewall show portopening'):
                    print(u"Adding a firewall rule to open port %s"%portnumber)
                    print run_notfatal("""netsh.exe firewall add portopening name="%s %s" port=%s protocol=TCP profile=ALL"""%(service_name,portnumber,portnumber))
                else:
                    print(u"port %s already opened, skipping firewall configuration"%(portnumber,))
        else:
            if win32serviceutil.QueryServiceStatus('MpsSvc', None)[1]==win32service.SERVICE_RUNNING:
                print(u"Firewall started, checking for port openning...")
                if service_name not in run_notfatal('netsh advfirewall firewall show rule name="%s %s"'%(service_name,portnumber,)):
                    print(u"No port opened for %s, opening port %s"%(service_name,portnumber))
                    #win Vista and higher
                    print run_notfatal("""netsh advfirewall firewall add rule name="%s %s" dir=in action=allow protocol=TCP localport=%s """%(service_name,portnumber,portnumber))
                else:
                    print(u"port %s already opened, skipping firewall configuration"%(portnumber,))
    except Exception as e:
        print('Unable to check if port %s is opened : %s' % (portnumber,e))


def install_service(nssm_path=nssm_path,exe_path=None,exe_params=None):
    """Setup cwRsync as a windows Service managed by nssm
    >>> install_service()
    """
    datatypes = {
        'dword':REG_DWORD,
        'sz':REG_SZ,
        'expand_sz':REG_EXPAND_SZ,
        'multi_sz':REG_MULTI_SZ,
    }

    if service_installed(service_name):
        if not service_is_stopped(service_name):
            print(u'Stop running "%s"' % service_name)
            run('net stop "%s"' % service_name)
            while not service_is_stopped(service_name):
                print(u'Waiting for "%s" to terminate' % service_name)
                time.sleep(2)
        print(u'Unregister existing "%s"' % service_name)
        run('sc delete "%s"' % service_name)

    if not exe_path:
        exe_path = makepath(install_path,'rsync.exe')

    if not exe_params:
        exe_params = '--daemon --no-detach --config rsyncd.conf'

    print(u'Register new %s with nssm' % service_name)
    run('"{nssm_path}" install {service_name} "{exe_path}" "{exe_params}"'.format(
        service_name = service_name,
        exe_path = exe_path,
        nssm_path = nssm_path,
        exe_params = exe_params,
     ))

    # fix some parameters (quotes for path with spaces...
    params = {
        "Description": "sz:%s" % service_name,
        "DisplayName" : "sz:%s" % service_name,
        "AppStdout" : r"expand_sz:{}".format(rsync_log),
        "Parameters\\AppStderr" : r"expand_sz:{}".format(rsync_log),
        "Parameters\\AppParameters" : r'expand_sz:{}'.format(exe_params),
        }

    print('Set service parameters...')
    root = HKEY_LOCAL_MACHINE
    base = r'SYSTEM\CurrentControlSet\services\%s' % service_name
    for key in params:
        if isinstance(params[key],int):
            (valuetype,value) = ('dword',params[key])
        elif ':' in params[key]:
            (valuetype,value) = params[key].split(':',1)
            if valuetype == 'dword':
                value = int(value)
        else:
            (valuetype,value) = ('sz',params[key])
        fullpath = base+'\\'+key
        (path,keyname) = fullpath.rsplit('\\',1)
        if keyname == '@' or keyname =='':
            keyname = None
        registry_set(root,path,keyname,value,type = datatypes[valuetype])
        print(r'HKLM\%s : %s = %s' % (path,keyname,value))

def uninstall():
    if service_installed(service_name):
        if not service_is_stopped(service_name):
            print(u'Stop running "%s"' % service_name)
            run('net stop "%s"' % service_name)
            while not service_is_stopped(service_name):
                print(u'Waiting for "%s" to terminate' % service_name)
                time.sleep(2)
        print(u'Unregister service "%s"' % service_name)
        run('sc delete "%s"' % service_name)
    print('Remove service files')
    remove_tree(install_path)

    print('Remove firewall exception')
    # winxp
    run_notfatal("""netsh.exe firewall add portopening name="%s %s" port=%s protocol=TCP profile=ALL"""%(service_name,portnumber,portnumber))
    # win 7
    run_notfatal("""netsh advfirewall firewall add rule name="%s %s" dir=in action=allow protocol=TCP localport=%s"""%(service_name,portnumber,portnumber,))

    

Changelog

No changelog
    

manifest.sha256

WAPT/certificate.crt 79e5388683c0b6cb03f4f81e4e58e3a11463b2b6cf169dd9c453098027dcfaa4
win32/nssm.exe 8209a46dcafd75ee941898bb82418237cfd6bc9ab954b6160313d5457e9f3348
rsyncd.conf 39e9a47d4f94973c5ebc9151f89c965b2bb305c002b22f55684a873fe48ee3c3
cwRsync/README.rsync.txt 368fe92590d47a6d77568e2252ddd4d346010faf8bcea7448af9f247250f1a39
cwRsync/ssh.exe 19500cc0f70a3c7069c58308b48fae038a6daaa9f007bcd480cc3e2e132b3679
cwRsync/rsyncd.conf.html 8aecc72e630b17c65293295c0e61cee77540fe05e31338b1895cbeb40b10240f
cwRsync/rsync.log d5ae7eb5468c8d56369a07acb83bef36ff22cdfc90bf2b356721fa29a8605d65
WAPT/control 6231ac49224b50ba9330005eca1359f8cb3e4a9839ea666b71f719fa717e4b5c
cwRsync/cygz.dll 8438a2dc82263609f1dde391b32b130353b59b17c947ed60269504922b230784
cwRsync/cygssp-0.dll 8ec14765dbf37b0b6684ade9be508bbcc573495ae0ba9bf9a9967ad9a4cf217d
WAPT/wapt.psproj 7377c7b433554efabae335522b68460f9f1c2386e93e923a2c28161999d0e408
cwRsync/cygcrypto-1.0.0.dll 240cb5a2d03861a59e60bf342ed7ad484658cd8f5e1a2015a5dc24d97eb2c37b
cwRsync/cygrunsrv.exe 3526bf5d4be8420b0ba4b2cacd0bd87e5c4e63a2222c26eb81a8d9a2149c0648
cwRsync/rsync.html e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
win64/nssm.exe a59705914c35c8f61b7052be375143c3b57c11060ee155d1678397051ce0d809
cwRsync/cygwin1.dll 0f2564731e4f6341f7bd6fc053de9e34b561e4f356c944fdd1180a4c1e92e4fe
cwRsync/cwrsync.cmd e428a21d8555c4e211b039f0e6aba09e5010d76dc9e1e149297d3759c248eb54
cwRsync/cyggcc_s-1.dll d9f91bd8ab1a7c413206648cb63e8fc05465d9b259af58e95d812e91f0971477
setup.py 6b011857efc373c3d150f9a1a9798b4fc53884c8c40679e6c23662a7f3f0d6a7
cwRsync/cygiconv-2.dll 679f5516407c7f6c9ffc78361f809370ae0f229ad51c237a8633ebe22452f6ef
cwRsync/rsync.exe 9cabd68ed0ca5c2e851e00e58992c60cbf99847edeebf234fc50dfca82d99015
cwRsync/ssh-keygen.exe 858c0983fc9609cd80401a9d9d9647d26f59a2844401b2d371396f47a5afc002
cwRsync/README.cwrsync.txt 6e633cb66e7c8653822d09656ee0257c9fa34c4846e1c7c714b913c24d819e39