diff --git a/actors/linux/.gitignore b/actors/linux/.gitignore new file mode 100644 index 000000000..5b3aa44ec --- /dev/null +++ b/actors/linux/.gitignore @@ -0,0 +1 @@ +/udsactor-opensuse-1.7.0.spec diff --git a/actors/linux/buildrpm.sh b/actors/linux/buildrpm.sh index ce568163d..60c98e4e0 100755 --- a/actors/linux/buildrpm.sh +++ b/actors/linux/buildrpm.sh @@ -1,13 +1,30 @@ #!/bin/bash +VERSION=1.7.0 +RELEASE=1 top=`pwd` -rm -rf rpm -for folder in SOURCES BUILD RPMS SPECS SRPMS; do - mkdir -p rpm/$folder -done - -for pkg in udsactor-1.7.0.spec udsactor-xrdp-1.7.0.spec; do - rpmbuild -v -bb --clean --target noarch $pkg 2>&1 + +cat udsactor-template.spec | + sed -e s/"version 1.7.0"/"version ${VERSION}"/g | + sed -e s/"release 1"/"release ${RELEASE}"/g > udsactor-$VERSION.spec + +# Now fix dependencies for opensuse +cat udsactor-template.spec | + sed -e s/"name udsactor"/"name udsactor-opensuse"/g | + sed -e s/"PyQt4"/"python-qt4"/g | + sed -e s/"libXScrnSaver"/"libXss1"/g > udsactor-opensuse-$VERSION.spec + + +# Right now, udsactor-xrdp-1.7.0.spec is not needed +for pkg in udsactor-$VERSION.spec udsactor-opensuse-$VERSION.spec; do + + rm -rf rpm + for folder in SOURCES BUILD RPMS SPECS SRPMS; do + mkdir -p rpm/$folder + done + + rpmbuild -v -bb --clean --buildroot=$top/rpm/BUILD/$pkg-root --target noarch $pkg 2>&1 done +#rm udsactor-$VERSION \ No newline at end of file diff --git a/actors/linux/scripts/UDSActorTool-startup b/actors/linux/scripts/UDSActorTool-startup index fc8ff001c..514b28c55 100644 --- a/actors/linux/scripts/UDSActorTool-startup +++ b/actors/linux/scripts/UDSActorTool-startup @@ -1,10 +1,10 @@ #!/bin/sh # Simple hack to wait for systray to be present -sleep 5 # Exec tool if not already runned by session manager -ps -ef | grep "$USER" | grep -v grep | grep 'UDSActorTool' -q +ps -ef | grep "$USER" | grep -v grep | grep -v UDSActorTool-startup | grep 'UDSActorTool' -q # If not already running if [ $? -eq 1 ]; then + sleep 5 exec /usr/bin/UDSActorTool fi \ No newline at end of file diff --git a/actors/linux/udsactor-template.spec b/actors/linux/udsactor-template.spec new file mode 100644 index 000000000..cd45db3b1 --- /dev/null +++ b/actors/linux/udsactor-template.spec @@ -0,0 +1,69 @@ +%define _topdir %(echo $PWD)/rpm +%define name udsactor +%define version 1.7.0 +%define release 1 +%define buildroot %{_topdir}/%{name}-%{version}-%{release}-root + +BuildRoot: %{buildroot} +Name: %{name} +Version: %{version} +Release: %{release} +Summary: Actor for Universal Desktop Services (UDS) Broker +License: BSD3 +Group: Admin +Requires: python-six python-requests PyQt4 libXScrnSaver +Vendor: Virtual Cable S.L.U. +URL: http://www.udsenterprise.com +Provides: udsactor + +%define _rpmdir ../ +%define _rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm + + +%install +curdir=`pwd` +cd ../.. +make DESTDIR=$RPM_BUILD_ROOT DISTRO=rh install-udsactor +cd $curdir + +%clean +rm -rf $RPM_BUILD_ROOT +curdir=`pwd` +cd ../.. +make DESTDIR=$RPM_BUILD_ROOT DISTRO=rh clean +cd $curdir + + +%post +systemctl enable udsactor.service > /dev/null 2>&1 + +%preun +systemctl disable udsactor.service > /dev/null 2>&1 +systemctl stop udsactor.service > /dev/null 2>&1 + +%postun +# $1 == 0 on uninstall, == 1 on upgrade for preun and postun (just a reminder for me... :) ) +if [ $1 -eq 0 ]; then + rm -rf /etc/udsactor + rm /var/log/udsactor.log +fi +# And, posibly, the .pyc leaved behind on /usr/share/UDSActor +rm -rf /usr/share/UDSActor > /dev/null 2>&1 + +%description +This package provides the required components to allow this machine to work on an environment managed by UDS Broker. + +%files +%defattr(-,root,root) +/etc/udsactor +/etc/xdg/autostart/UDSActorTool.desktop +/etc/init.d/udsactor +/usr/bin/UDSActorTool-startup +/usr/bin/udsactor +/usr/bin/UDSActorTool +/usr/sbin/UDSActorConfig +/usr/sbin/UDSActorConfig-pkexec +/usr/share/UDSActor/* +/usr/share/applications/UDS_Actor_Configuration.desktop +/usr/share/autostart/UDSActorTool.desktop +/usr/share/polkit-1/actions/org.openuds.pkexec.UDSActorConfig.policy diff --git a/actors/src/udsactor/REST.py b/actors/src/udsactor/REST.py index aab698bf9..99af5710b 100644 --- a/actors/src/udsactor/REST.py +++ b/actors/src/udsactor/REST.py @@ -39,7 +39,6 @@ import logging import json import uuid import six -import codecs from udsactor.log import logger @@ -99,28 +98,11 @@ def ensureResultIsOk(result): raise err -def unscramble(value): - if value is None or value == '': - return value - - value = bytearray(codecs.decode(value, 'hex')) - - n = 0x32 - result = [] - for ch in value: - c = ch ^ n - n = (n + c) & 0xFF - result.append(six.int2byte(c)) - - return b''.join(result)[::-1].decode('utf8') - - class Api(object): - def __init__(self, host, masterKey, ssl, scrambledResponses=False): + def __init__(self, host, masterKey, ssl): self.host = host self.masterKey = masterKey self.useSSL = ssl - self.scrambledResponses = scrambledResponses self.uuid = None self.mac = None self.url = "{}://{}/rest/actor/".format(('http', 'https')[ssl], self.host) @@ -166,13 +148,6 @@ class Api(object): ensureResultIsOk(r) - if self.scrambledResponses is True: - # test && init are not scrambled, even if rest of messages are - try: - r['result'] = unscramble(r['result']) - except Exception as e: # Can't unscramble, return result "as is" - r['warning'] = True - return r @property diff --git a/actors/src/udsactor/linux/daemon.py b/actors/src/udsactor/linux/daemon.py index c323cb401..9b0660491 100644 --- a/actors/src/udsactor/linux/daemon.py +++ b/actors/src/udsactor/linux/daemon.py @@ -150,8 +150,8 @@ class Daemon: if pid is None: message = "pidfile {} does not exist. Daemon not running?\n".format(self.pidfile) - logger.error(message) - sys.stderr.write(message) + logger.info(message) + # sys.stderr.write(message) return # not an error in a restart # Try killing the daemon process diff --git a/actors/src/udsactor/linux/renamer/__init__.py b/actors/src/udsactor/linux/renamer/__init__.py index 670a3d15b..54cd3c06f 100644 --- a/actors/src/udsactor/linux/renamer/__init__.py +++ b/actors/src/udsactor/linux/renamer/__init__.py @@ -43,13 +43,13 @@ renamers = {} # Renamers now are for IPv4 only addresses def rename(newName): - distribution = platform.linux_distribution()[0].lower() + distribution = platform.linux_distribution()[0].lower().strip() if distribution in renamers: return renamers[distribution](newName) # Try Debian renamer, simplest one logger.info('Renamer for platform "{0}" not found, tryin debian renamer'.format(distribution)) - return renamers['debian'] + return renamers['debian'](newName) # Do load of packages diff --git a/actors/src/udsactor/linux/renamer/opensuse.py b/actors/src/udsactor/linux/renamer/opensuse.py new file mode 100644 index 000000000..d7826e009 --- /dev/null +++ b/actors/src/udsactor/linux/renamer/opensuse.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2014 Virtual Cable S.L. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the name of Virtual Cable S.L. nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +''' +@author: Adolfo Gómez, dkmaster at dkmon dot com +''' +from __future__ import unicode_literals + +from udsactor.linux.renamer import renamers +from udsactor.log import logger + +import os + + +def rename(newName): + ''' + RH, Centos, Fedora Renamer + Expects new host name on newName + Host does not needs to be rebooted after renaming + ''' + logger.debug('using SUSE renamer') + + with open('/etc/hostname', 'w') as hostname: + hostname.write(newName) + + # Force system new name + os.system('/bin/hostname %s' % newName) + + # add name to "hosts" + with open('/etc/hosts', 'r') as hosts: + lines = hosts.readlines() + with open('/etc/hosts', 'w') as hosts: + hosts.write("127.0.1.1\t{}\n".format(newName)) + for l in lines: + if l[:9] != '127.0.1.1': # Skips existing 127.0.1.1. if it already exists + hosts.write(l) + + return True + +# All names in lower case +renamers['opensuse'] = rename +renamers['suse'] = rename diff --git a/actors/src/udsactor/service.py b/actors/src/udsactor/service.py index 9850069dd..6121b40ce 100644 --- a/actors/src/udsactor/service.py +++ b/actors/src/udsactor/service.py @@ -86,7 +86,7 @@ class CommonService(object): def setReady(self): self.api.setReady([(v.mac, v.ip) for v in operations.getNetworkInfo()]) - def interactWithBroker(self, scrambledResponses=False): + def interactWithBroker(self): ''' Returns True to continue to main loop, false to stop & exit service ''' @@ -95,7 +95,7 @@ class CommonService(object): logger.fatal('No configuration found, stopping service') return False - self.api = REST.Api(cfg['host'], cfg['masterKey'], cfg['ssl'], scrambledResponses=scrambledResponses) + self.api = REST.Api(cfg['host'], cfg['masterKey'], cfg['ssl']) # Wait for Broker to be ready counter = 0 @@ -125,7 +125,7 @@ class CommonService(object): logger.fatal('This host is not managed by UDS Broker (ids: {})'.format(ids)) return False # On unmanaged hosts, there is no reason right now to continue running except Exception as e: - logger.debug('Exception caugh: {}, retrying'.format(exceptionToMessage(e))) + logger.debug('Exception caught: {}, retrying'.format(exceptionToMessage(e))) # Any other error is expectable and recoverable, so let's wait a bit and retry again # but, if too many errors, will log it (one every minute, for # example) @@ -176,7 +176,7 @@ class CommonService(object): except Exception: counter += 1 if counter % 60 == 0: - logger.warn('Too many retries in progress, though still trying (last error: {})'.format(e.message.decode('windows-1250', 'ignore'))) + logger.warn('Too many retries in progress, though still trying (last error: {})'.format(exceptionToMessage(e))) # Any other error is expectable and recoverable, so let's wait # a bit and retry again # Wait a bit before next check @@ -232,7 +232,7 @@ class CommonService(object): self.ipc.start() if self.api.mac in self.knownIps: - address = (self.knownIps[self.api.mac], random.randrange(32000, 64000)) + address = (self.knownIps[self.api.mac], random.randrange(40000, 44000)) logger.debug('Starting REST listener at {}'.format(address)) self.httpServer = httpserver.HTTPServerThread(address, self.ipc) self.httpServer.start() diff --git a/actors/src/udsactor/windows/UDSActorService.py b/actors/src/udsactor/windows/UDSActorService.py index aac3c3e9e..32d56fe15 100644 --- a/actors/src/udsactor/windows/UDSActorService.py +++ b/actors/src/udsactor/windows/UDSActorService.py @@ -180,7 +180,7 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService): # ******************************************************** # * Ask brokers what to do before proceding to main loop * # ******************************************************** - if self.interactWithBroker(scrambledResponses=True) is False: + if self.interactWithBroker() is False: logger.debug('Interact with broker returned false, stopping service after a while') self.notifyStop() win32event.WaitForSingleObject(self.hWaitStop, 5000)