#718: Creación de OGAgent:

* adaptar algunos ficheros a la sintaxis recomendada por el comando {{{pylint}}};
 * OGAgent para Windows:
   * actualizar componentes y reducir los aviso de Wine;
   * corregir fallo al instalar {{{pycrypto}}} para Windows;
   * corregir localización de certificado en Windows (ahora está en librería {{{certifi}}} en vez de en {{{requests}}});
 * OGAgent para Linux:
   * evitar bucle infinito al intentar parar el proceso. 
 * Ignorar mensajes de SELinux en la MV Vagrant para OGAgent.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5471 a21b9725-9963-47de-94b9-378ad31fedc9
remotes/github/oglive
ramon 2017-10-19 11:52:05 +00:00
parent e21cba12d0
commit 90e5c2d1a4
5 changed files with 40 additions and 43 deletions

View File

@ -156,7 +156,7 @@ class Daemon:
# Try killing the daemon process
try:
while True:
for i in range(10):
os.kill(pid, SIGTERM)
time.sleep(1)
except OSError as err:

View File

@ -30,13 +30,6 @@
'''
from __future__ import unicode_literals
from opengnsys.workers import ServerWorker
from opengnsys import REST, RESTError
from opengnsys import operations
from opengnsys.log import logger
from opengnsys.scriptThread import ScriptExecutorThread
import subprocess
import threading
import thread
@ -47,6 +40,12 @@ import random
import string
import urllib
from opengnsys.workers import ServerWorker
from opengnsys import REST, RESTError
from opengnsys import operations
from opengnsys.log import logger
from opengnsys.scriptThread import ScriptExecutorThread
# Error handler decorator.
def catchBackgroundError(fnc):
def wrapper(*args, **kwargs):
@ -64,7 +63,7 @@ class OpenGnSysWorker(ServerWorker):
locked = {}
random = None # Random string for secure connections
length = 32 # Random string length
def checkSecret(self, server):
'''
Checks for received secret key and raise exception if it isn't valid.
@ -84,7 +83,7 @@ class OpenGnSysWorker(ServerWorker):
# Ensure cfg has required configuration variables or an exception will be thrown
self.REST = REST(self.service.config.get('opengnsys', 'remote'))
# Get network interfaces until they are active or timeout (30 sec)
for t in range(0,30):
for t in range(0, 30):
try:
self.interface = list(operations.getNetworkInfo())[0] # Get first network interface
except Exception as e:
@ -103,24 +102,24 @@ class OpenGnSysWorker(ServerWorker):
self.random = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(self.length))
# Send initalization message
self.REST.sendMessage('ogagent/started', {'mac': self.interface.mac, 'ip': self.interface.ip, 'secret': self.random, 'ostype': operations.osType, 'osversion': operations.osVersion})
def onDeactivation(self):
'''
Sends OGAgent stopping notification to OpenGnsys server
'''
logger.debug('onDeactivation')
self.REST.sendMessage('ogagent/stopped', {'mac': self.interface.mac, 'ip': self.interface.ip, 'ostype': operations.osType, 'osversion': operations.osVersion})
def processClientMessage(self, message, data):
logger.debug('Got OpenGnsys message from client: {}, data {}'.format(message, data))
def onLogin(self, user):
'''
Sends session login notification to OpenGnsys server
'''
logger.debug('Received login for {}'.format(user))
self.loggedin = True
self.REST.sendMessage('ogagent/loggedin', {'ip': self.interface.ip, 'user': user, 'ostype': operations.osType, 'osversion': operations.osVersion})
self.REST.sendMessage('ogagent/loggedin', {'ip': self.interface.ip, 'user': user, 'ostype': operations.osType, 'osversion': operations.osVersion})
def onLogout(self, user):
'''
@ -138,29 +137,28 @@ class OpenGnSysWorker(ServerWorker):
Imagine this invocation url (no matter if GET or POST): http://example.com:9999/Sample/mazinger/Z
The HTTP Server will remove "Sample" from path, parse arguments and invoke this method as this:
module.processMessage(["mazinger","Z"], getParams, postParams)
This method will process "mazinger", and look for a "self" method that is called "process_mazinger", and invoke it this way:
return self.process_mazinger(["Z"], getParams, postParams)
In the case path is empty (that is, the path is composed only by the module name, like in "http://example.com/Sample", the "process" method
will be invoked directly
The methods must return data that can be serialized to json (i.e. Ojects are not serializable to json, basic type are)
'''
if len(path) == 0:
if not path:
return "ok"
try:
operation = getattr(self, 'ogclient_' + path[0])
except Exception:
raise Exception('Message processor for "{}" not found'.format(path[0]))
return operation(path[1:], getParams, postParams)
def process_status(self, path, getParams, postParams, server):
'''
Returns client status.
'''
res = { 'status': '', 'loggedin': self.loggedin }
res = {'status': '', 'loggedin': self.loggedin}
if platform.system() == 'Linux': # GNU/Linux
# Check if it's OpenGnsys Client.
if os.path.exists('/scripts/oginit'):
@ -171,14 +169,14 @@ class OpenGnSysWorker(ServerWorker):
res['status'] = 'OPG'
else:
# Check if there is an active session.
res['status'] = 'LNX'
res['status'] = 'LNX'
elif platform.system() == 'Windows': # Windows
# Check if there is an active session.
res['status'] = 'WIN'
elif platform.system() == 'Darwin': # Mac OS X ??
res['status'] = 'OSX'
return res
def process_reboot(self, path, getParams, postParams, server):
'''
Launches a system reboot operation.
@ -220,7 +218,7 @@ class OpenGnSysWorker(ServerWorker):
else:
self.sendClientMessage('script', {'code': script})
return {'op': 'launched'}
def process_logoff(self, path, getParams, postParams, server):
'''
Closes user session.
@ -241,6 +239,6 @@ class OpenGnSysWorker(ServerWorker):
self.sendClientMessage('popup', postParams)
return {'op': 'launched'}
def process_client_popup(tself, params):
def process_client_popup(self, params):
self.REST.sendMessage('popup_done', params)

View File

@ -37,7 +37,7 @@ import os
import tempfile
# Valid logging levels, from UDS Broker (uds.core.utils.log)
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in xrange(6))
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in range(6))
class LocalLogger(object):

View File

@ -28,6 +28,7 @@
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
@author: Ramón M. Gómez, ramongomez at us dot es
'''
VERSION = '1.1.0'
@ -63,9 +64,12 @@ import os
sys.argv.append('py2exe')
def get_requests_cert_file():
"""Add Python requests .pem file for installers."""
"""Add Python requests or certifi .pem file for installers."""
import requests
f = os.path.join(os.path.dirname(requests.__file__), 'cacert.pem')
if not os.path.exists(f):
import certifi
f = os.path.join(os.path.dirname(certifi.__file__), 'cacert.pem')
return f
@ -117,8 +121,8 @@ setup(
'bundle_files': 3,
'compressed': True,
'optimize': 2,
'includes': [ 'sip', 'PyQt4', 'win32com.shell', 'requests'] + HIDDEN_BY_SIX,
'excludes': [ 'doctest', 'unittest' ],
'includes': ['sip', 'PyQt4', 'win32com.shell', 'requests'] + HIDDEN_BY_SIX,
'excludes': ['doctest', 'unittest'],
'dll_excludes': ['msvcp90.dll'],
'dist_dir': '..\\bin',
}

View File

@ -4,17 +4,17 @@
# * Wine (32 bit)
# * winetricks (in some distributions)
export WINEARCH=win32
export WINEARCH=win32 WINEPREFIX=$PWD/wine WINEDEBUG=fixme-all
WINE=wine
download() {
mkdir downloads
# Get needed software
cd downloads
wget -nd https://www.python.org/ftp/python/2.7.11/python-2.7.11.msi -O python-2.7.msi
wget -nd https://www.python.org/ftp/python/2.7.14/python-2.7.14.msi -O python-2.7.msi
wget -nd http://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi
wget -nd https://bootstrap.pypa.io/get-pip.py
wget -nd http://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/pywin32-220.win32-py2.7.exe/download -O pywin32-install.exe
wget -nd http://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/pywin32-221.win32-py2.7.exe/download -O pywin32-install.exe
wget -nd http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/py2exe-0.6.9.win32-py2.7.exe/download -O py2exe-install.exe
wget -nd http://prdownloads.sourceforge.net/nsis/nsis-3.0rc1-setup.exe?download -O nsis-install.exe
wget -nd http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe/download -O pyqt-install.exe
@ -23,8 +23,6 @@ download() {
}
install_python() {
WINEPREFIX=`pwd`/wine
export WINEPREFIX
if which winetricks &>/dev/null; then
echo "Setting up wine prefix (using winetricks)"
winetricks
@ -50,18 +48,15 @@ install_python() {
setup_pip() {
echo "Seting up pip..."
#mkdir $WINEPREFIX/drive_c/temp
#cp downloads/get-pip.py $WINEPREFIX/drive_c/temp
#cd $WINEPREFIX/drive_c/temp
#$WINE c:\\Python27\\python.exe get-pip.py
wine c:\\Python27\\python -m pip install --upgrade pip
$WINE C:\\Python27\\python -m pip install --upgrade pip
}
install_packages() {
echo "Installing required packages"
wine c:\\Python27\\python -m pip install requests
wine c:\\Python27\\python -m pip install pycrypto
wine c:\\Python27\\python -m pip install six
$WINE C:\\Python27\\python -m pip install requests
$WINE C:\\Python27\\python -m pip install six
# Using easy_install instead of pip to install pycrypto
$WINE C:\\Python27\\Scripts\\easy_install http://www.voidspace.org.uk/python/pycrypto-2.6.1/pycrypto-2.6.1.win32-py2.7.exe
# Copy nsis required NSIS_Simple_Firewall_Plugin_1
echo "Copying simple firewall plugin for nsis installer"
unzip -o downloads/NSIS_Simple_Firewall_Plugin_1.20.zip SimpleFC.dll -d $WINEPREFIX/drive_c/Program\ Files/NSIS/Plugins/x86-ansi/