1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-21 18:03:54 +03:00

Fixed actor for linux

This commit is contained in:
Adolfo Gómez García 2020-01-08 14:38:19 +01:00
parent a4353dde86
commit 69c4fd6325
22 changed files with 58 additions and 275 deletions

6
actor/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Debian source builds
udsactor_*.dsc
udsactor_*.tar.xz
udsactor_*.deb
udsactor_*.buildinfo
udsactor_*.changes

View File

@ -1 +1 @@
9
10

View File

@ -1,16 +1,16 @@
Source: udsactor
Section: admin
Priority: optional
Maintainer: Adolfo Gómez García <agomez@virtualcable.es>
Build-Depends: debhelper (>= 7), po-debconf
Standards-Version: 3.9.2
Homepage: http://www.virtualcable.es
Maintainer: Adolfo Gómez García <agomez@virtualcable.net>
Build-Depends: debhelper (>= 7), po-debconf, dh-systemd (>= 1.5)
Standards-Version: 4.1.4
Homepage: http://www.udsenterprise.com
Package: udsactor
Section: admin
Priority: optional
Architecture: all
Depends: policykit-1(>=0.100), python3-requests (>=0.8.2), python3-pyqt4 (>=4.9), python3-six(>=1.1), python3 (>=3.4), libxss1, xscreensaver, ${misc:Depends}
Depends: policykit-1(>=0.100), python3-requests (>=0.8.2), python3-pyqt5 (>=4.9), python3-six(>=1.1), python3 (>=3.4), libxss1, xscreensaver, ${misc:Depends}
Recommends: python3-prctl(>=1.1.1)
Description: Actor for Universal Desktop Services (UDS) Broker
This package provides the required components to allow this machine to work on an environment managed by UDS Broker.

View File

@ -3,7 +3,7 @@ Name: udsactor
Maintainer: Adolfo Gómez García
Source: http://www.udsenterprise.com/
Copyright: 2014 Virtual Cable S.L.U.
Copyright: 2014-2019 Virtual Cable S.L.U.
License: BSD-3-clause
License: GPL-2+

View File

@ -22,8 +22,6 @@ install: build
dh_prep
dh_installdirs
$(MAKE) DESTDIR=$(CURDIR)/debian/udsactor install-udsactor
$(MAKE) DESTDIR=$(CURDIR)/debian/udsactor-xrdp install-udsactor-xrdp
$(MAKE) DESTDIR=$(CURDIR)/debian/udsactor-nx install-udsactor-nx
binary-arch: build install
# emptyness
binary-indep: build install
@ -32,7 +30,9 @@ binary-indep: build install
dh_installchangelogs
dh_installdocs
dh_installdebconf
dh_installinit --no-start
dh_systemd_enable
dh_installinit --no-restart-on-upgrade --no-start --name=udsactor
dh_systemd_start
dh_python2=python
dh_compress
dh_link

View File

@ -1,37 +0,0 @@
#!/bin/sh
NXNODECFG=/usr/NX/etc/node.cfg
. /usr/share/debconf/confmodule
set -e
case "$1" in
configure)
TMPFILE=$(mktemp /tmp/node.cfg.XXXXX)
trap "rm -f $TMPFILE" 0
cat $NXNODECFG | sed -e "s/.*udsnxst.*//; s/\(UserScriptAfterSessionStart *=.*\)/#\1/;s/\(UserScriptAfterSessionClose *=.*\)/#\1/" > $TMPFILE
echo >> $TMPFILE
echo "# Added by udsactor-nx (udsnxstart and udsnxstop)" >> $TMPFILE
echo UserScriptAfterSessionStart = \"/usr/bin/udsnxstart\" >> $TMPFILE
echo UserScriptAfterSessionClose = \"/usr/bin/udsnxstop\" >> $TMPFILE
cp $TMPFILE $NXNODECFG
invoke-rc.d nxserver restart
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
# Don't know why, but descriptors get "weird" when launched daemon, so we tell here to debconf to stop.
# Solved not starting the service right now, defered to next reboot
exit 0

View File

@ -1,30 +0,0 @@
#!/bin/sh
NXNODECFG=/usr/NX/etc/node.cfg
. /usr/share/debconf/confmodule
set -e
case "$1" in
purge)
;;
remove)
if [ -f $NXNODECFG ]; then
TMPFILE=$(mktemp /tmp/node.cfg.XXXXX)
trap "rm -f $TMPFILE" 0
cat $NXNODECFG | sed -e "s/.*udsnxst.*//" > $TMPFILE
cp $TMPFILE $NXNODECFG
invoke-rc.d nxserver restart
fi
;;
upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#

View File

@ -1,39 +0,0 @@
#!/bin/sh
SESMANFILE=/etc/pam.d/xrdp-sesman
. /usr/share/debconf/confmodule
set -e
case "$1" in
configure)
trap "cp $SESMANFILE $SESMANFILE.uds.old" 0
TMPFILE=$(mktemp /tmp/sesman.XXXXX)
trap "rm -f $TMPFILE" 0
grep -v uds $SESMANFILE > $TMPFILE # Removes all UDS lines from sesman if they exists
echo >> $TMPFILE
echo "# Added by udsactor-xrdp" >> $TMPFILE
echo "session optional pam_exec.so /usr/bin/uds-sesman" >> $TMPFILE
cp $TMPFILE $SESMANFILE
trap "rm -f $TMPFILE" 0
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
# Don't know why, but descriptors get "weird" when launched daemon, so we tell here to debconf to stop.
# Solved not starting the service right now, defered to next reboot
exit 0

View File

@ -1,30 +0,0 @@
#!/bin/sh -e
SESMANFILE=/etc/pam.d/xrdp-sesman
. /usr/share/debconf/confmodule
set -e
case "$1" in
purge)
;;
remove)
if [ -f $SESMANFILE ]; then
TMPFILE=$(mktemp /tmp/sesman.XXXXX)
trap "rm -f $TMPFILE" 0
grep -v uds $SESMANFILE > $TMPFILE # Removes all UDS lines from sesman if they exists
cp $TMPFILE $SESMANFILE
trap "rm -f $TMPFILE" 0
fi
;;
upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#

View File

@ -1,45 +1,3 @@
#!/bin/sh -e
. /usr/share/debconf/confmodule
db_version 2.0
# This conf script is capable of backing up
db_capb backup
if [ -f /etc/udsactor/udsactor.cfg ] && [ "$1" != "reconfigure" ]; then
echo "/etc/udsactor/udsactor.cfg already exists, leaving untouched."
exit 0
fi
STATE=1
while [ "$STATE" != 0 -a "$STATE" != 4 ]; do
case "$STATE" in
1)
db_input high udsactor/host || true
;;
2)
db_input high udsactor/secure || true
;;
3)
db_input high udsactor/masterKey || true
;;
esac
if db_go; then
STATE=$(($STATE + 1))
else
STATE=$(($STATE - 1))
fi
done
# If "cancelled", exit
if [ "$STATE" = 0 ]; then
exit 0
fi
# If using reconfigure, and already exists an configuration file, move it to a backup
if [ -f /etc/udsactor/udsactor.cfg ] && [ "$1" = "reconfigure" ]; then
echo "/etc/udsactor.cfg backup to /etc/udsactor.cfg.back"
mv /etc/udsactor/udsactor.cfg /etc/udsactor/udsactor.cfg.back
fi
exit 0

View File

@ -1,23 +0,0 @@
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: udsactor
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: UDS Actor
### END INIT INFO
#
# . /lib/lsb/init-functions
case "$1" in
start|stop|restart)
/usr/bin/udsactor $1
;;
force-reload)
/usr/bin/udsactor restart
;;
*) echo "Usage: $0 {start|stop|restart|force-reload}" >&2; exit 1 ;;
esac

View File

@ -1,2 +0,0 @@
/usr/share/UDSActor/UDSActorConfig.py /usr/sbin/UDSActorConfig
/usr/share/UDSActor/UDSActorUser.py /usr/bin/UDSActorTool

View File

@ -6,38 +6,12 @@ set -e
case "$1" in
configure)
/usr/bin/python3 -m compileall /usr/share/UDSActor > /dev/nul 2>&1
# If new "fresh" install or if configuration file has disappeared...
if [ "$2" = "" ] || [ ! -f /etc/udsactor/udsactor.cfg ]; then
db_get udsactor/host
host=$RET
db_get udsactor/secure
ssl=$RET
if [ "$ssl" = "true" ]; then
ssl=True;
else
ssl=False;
fi
db_get udsactor/masterKey
masterKey=$RET
# If already has a config file there
if [ -f /etc/udsactor/udsactor.cfg ]; then
cp /etc/udsactor/udsactor.cfg /etc/udsactor/udsactor.cfg.dpkg-old
fi
echo "[uds]" > /etc/udsactor/udsactor.cfg
echo "host = $host" >> /etc/udsactor/udsactor.cfg
echo "logLevel = 30000" >> /etc/udsactor/udsactor.cfg
echo "ssl = $ssl" >> /etc/udsactor/udsactor.cfg
echo "masterKey = $masterKey" >> /etc/udsactor/udsactor.cfg
fi
# Fix perms so only root can access "masterKey"
chmod 0700 /etc/udsactor
chmod 0600 /etc/udsactor/udsactor.cfg
# chmod 0600 /etc/udsactor/udsactor.cfg
chown root:root /etc/udsactor
chown root:root /etc/udsactor/udsactor.cfg
# chown root:root /etc/udsactor/udsactor.cfg
;;
abort-upgrade|abort-remove|abort-deconfigure)

View File

@ -0,0 +1,14 @@
[Unit]
Description=UDS Broker actor
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/usr/share/UDSActor
ExecStart=/usr/bin/python3 actor_service.py start-foreground
PrivateTmp=true
[Install]
WantedBy=multi-user.target

View File

@ -1,20 +0,0 @@
Template: udsactor/host
Type: string
Default:
Description: UDS Server address:
The actor needs the address of the server in order to communicate with it.
Provide here full address (or i) of the UDS server
Template: udsactor/secure
Type: boolean
Default: true
Description: Use secure (https) connection to communicate with UDS server?
If selected, the communication will be done using https.
If not selected, the communication will be done using http
Template: udsactor/masterKey
Type: string
Default:
Description: Master Key:
This key is available on UDS Administration interface.
Look for it under configuration, on Security tab.

View File

@ -38,10 +38,14 @@ from PyQt5.QtCore import QTimer
from udsactor.log import logger, DEBUG
from udsactor.client import UDSClientQApp
from udsactor.platform import operations
if __name__ == "__main__":
logger.setLevel(DEBUG)
# Ensure idle operations is initialized on start
operations.initIdleDuration(0)
if 'linux' in sys.platform:
os.environ['QT_X11_NO_MITSHM'] = '1'

View File

@ -169,6 +169,9 @@ class UDSActorClient(threading.Thread): # pylint: disable=too-many-instance-att
# Notify loging and mark it
self._loginInfo = self.api.login(platform.operations.getCurrentUser())
if self._loginInfo.max_idle:
platform.operations.initIdleDuration(self._loginInfo.max_idle)
while self._running:
time.sleep(1.3) # Sleeps between loop iterations

View File

@ -170,19 +170,19 @@ def changeUserPassword(user: str, oldPassword: str, newPassword: str) -> None:
def initIdleDuration(atLeastSeconds: int) -> None:
subprocess.call(['/usr/bin/xset', 's', '{}'.format(atLeastSeconds + 30)])
# And now reset it
subprocess.call(['/usr/bin/xset', 's', 'reset'])
xss.initIdleDuration(atLeastSeconds)
def getIdleDuration() -> float:
return xss.getIdleDuration()
def getCurrentUser() -> str:
'''
Returns current logged in user
'''
return os.environ['USER']
def forceTimeSync() -> None:
return

View File

@ -61,12 +61,15 @@ def run() -> None:
daemonSvr = UDSActorSvc()
if len(sys.argv) == 2:
# Daemon mode...
if sys.argv[1] == 'start':
daemonSvr.start()
elif sys.argv[1] == 'stop':
daemonSvr.stop()
elif sys.argv[1] == 'restart':
daemonSvr.restart()
elif sys.argv[1] == 'start-foreground':
daemonSvr.run() # Esecute in foreground
else:
usage()
sys.exit(0)

View File

@ -44,7 +44,7 @@ except ImportError: # Platform may not include prctl, so in case it's not avail
class UDSActorSvc(daemon.Daemon, CommonService):
def __init__(self) -> None:
daemon.Daemon.__init__(self, '/var/run/udsactor.pid')
daemon.Daemon.__init__(self, '/run/udsactor.pid')
CommonService.__init__(self)
# Captures signals so we can stop gracefully

View File

@ -47,8 +47,11 @@ class XScreenSaverInfo(ctypes.Structure): # pylint: disable=too-few-public-meth
('idle', ctypes.c_ulong),
('eventMask', ctypes.c_ulong)]
def _init():
def _ensureInitialized():
global xlib, xss, xssInfo, display, initialized # pylint: disable=global-statement
if initialized:
return
initialized = True
# Initialize xlib & xss
@ -73,19 +76,18 @@ def _init():
def initIdleDuration(atLeastSeconds: int) -> None:
subprocess.call(['/usr/bin/xset', 's', '{}'.format(atLeastSeconds + 30)])
# And now reset it
subprocess.call(['/usr/bin/xset', 's', 'reset'])
_ensureInitialized()
if atLeastSeconds:
subprocess.call(['/usr/bin/xset', 's', '{}'.format(atLeastSeconds + 30)])
# And now reset it
subprocess.call(['/usr/bin/xset', 's', 'reset'])
def getIdleDuration() -> float:
'''
Returns idle duration, in seconds
'''
if not initialized:
_init()
if not xlib or not xss or not xssInfo:
if not initialized or not xlib or not xss or not xssInfo:
return 0 # Libraries not available
event_base = ctypes.c_int()

View File

@ -196,7 +196,7 @@ class LASTINPUTINFO(ctypes.Structure): # pylint: disable=too-few-public-methods
('dwTime', ctypes.c_uint),
]
def initIdleDuration(atLeastSeconds: int = 0): # pylint: disable=unused-argument
def initIdleDuration(atLeastSeconds: int): # pylint: disable=unused-argument
'''
In windows, there is no need to set screensaver
'''