#718: OGAgent soporta ruta {{{/opengnsys/popup}}} para mostrar un mensaje emergente con título en la sesión del usuario.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5153 a21b9725-9963-47de-94b9-378ad31fedc9
remotes/github/oglive
ramon 2017-01-17 13:37:40 +00:00
parent 08ecf23b1b
commit 1deb0d1666
8 changed files with 53 additions and 9 deletions

View File

@ -142,8 +142,8 @@ p, li { white-space: pre-wrap; }
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Verdana'; font-size:9pt; font-weight:400; font-style:normal;">
<p style=" margin-top:5px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif';">OGAgent developer: Ramón M. Gómez <ramongomez@us.es></span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif';">UDS Actor developer: Adolfo Gómez García <agomez@virtualcable.es></span></p>
<p style=" margin-top:5px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif';">OGAgent contributor: Ramón M. Gómez <ramongomez@us.es></span></p>
&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">

View File

@ -46,6 +46,7 @@ from opengnsys.log import logger
# ------------ -------- --------------------------
# MSG_LOGOFF None Logout user from session
# MSG_MESSAGE message,level Display a message with level (INFO, WARN, ERROR, FATAL) # TODO: Include level, right now only has message
# MSG_POPUP title,message Display a popup box with a title
# MSG_SCRIPT python script Execute an specific python script INSIDE CLIENT environment (this messages is not sent right now)
# The messages received (sent from client) will be the following:
# Message_id Data Action
@ -63,10 +64,12 @@ from opengnsys.log import logger
# Client messages
MSG_LOGOFF = 0xA1 # Request log off from an user
MSG_MESSAGE = 0xB2
MSG_POPUP = 0xB3
MSG_SCRIPT = 0xC3
# Request messages
REQ_MESSAGE = 0xD4
REQ_POPUP = 0xD5
REQ_LOGIN = 0xE5
REQ_LOGOUT = 0xF6
@ -74,6 +77,7 @@ REQ_LOGOUT = 0xF6
REV_DICT = {
MSG_LOGOFF: 'MSG_LOGOFF',
MSG_MESSAGE: 'MSG_MESSAGE',
MSG_POPUP: 'MSG_POPUP',
MSG_SCRIPT: 'MSG_SCRIPT',
REQ_LOGIN: 'REQ_LOGIN',
REQ_LOGOUT: 'REQ_LOGOUT',
@ -237,6 +241,9 @@ class ServerIPC(threading.Thread):
def sendMessageMessage(self, message):
self.sendMessage(MSG_MESSAGE, message)
def sendPopupMessage(self, title, message):
self.sendMessage(MSG_POPUP, {'title':title, 'message':message})
def sendScriptMessage(self, script):
self.sendMessage(MSG_SCRIPT, script)

View File

@ -269,3 +269,10 @@ def getCurrentUser():
Returns current logged in user
'''
return os.environ['USER']
def showPopup(title, message):
'''
Displays a message box on user's session (during 1 min).
'''
return subprocess.call('zenity --info --timeout 60 --title "{}" --text "{}"'.format(title, message), shell=True)

View File

@ -50,9 +50,14 @@ class OpenGnSysWorker(ClientWorker):
logger.debug('Processed message: script({})'.format(jsonParams))
thr = ScriptExecutorThread(jsonParams['code'])
thr.start()
#self.sendServerMessage({'op', 'launched'})
#self.sendServerMessage('script', {'op', 'launched'})
def process_logoff(self, jsonParams):
logger.debug('Processed message: logoff({})'.format(jsonParams))
operations.logoff()
def process_popup(self, jsonParams):
logger.debug('Processed message: popup({})'.format(jsonParams))
ret = operations.showPopup(jsonParams['title'], jsonParams['message'])
#self.sendServerMessage('popup', {'op', ret})

View File

@ -88,25 +88,19 @@ class OpenGnSysWorker(ServerWorker):
# Generate random secret to send on activation
self.random = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(self.length))
# Send an initialize message
#self.REST.sendMessage('initialize/{}/{}'.format(self.interface.mac, self.interface.ip))
# Send an POST message
# 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
'''
#self.REST.sendMessage('deinitialize/{}/{}'.format(self.interface.mac, self.interface.ip))
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 process_client_doit(self, params):
# self.REST.sendMessage('doit_done', params)
def onLogin(self, user):
'''
Sends session login notification to OpenGnsys server
@ -224,3 +218,16 @@ class OpenGnSysWorker(ServerWorker):
self.sendClientMessage('logoff', {})
return {'op': 'sended to client'}
def process_popup(self, path, getParams, postParams, server):
'''
Shows a message popup on the user's session.
'''
logger.debug('Received message operation')
self.checkSecret(server)
# Sending popup message to OGAgent client.
self.sendClientMessage('popup', postParams)
return {'op': 'launched'}
def process_client_popup(tself, params):
self.REST.sendMessage('popup_done', params)

View File

@ -241,3 +241,9 @@ class CommonService(object):
Sends a logoff message to client
'''
self.ipc.sendLoggofMessage()
def sendPopupMessage(self, title, message):
'''
Sends a poup box to be displayed by client
'''
self.ipc.sendPopupMessage(title, message)

View File

@ -39,6 +39,7 @@ import win32con # @UnresolvedImport, pylint: disable=import-error
import ctypes
from ctypes.wintypes import DWORD, LPCWSTR
import os
import subprocess
from opengnsys import utils
from opengnsys.log import logger
@ -231,3 +232,11 @@ def getCurrentUser():
Returns current logged in username
'''
return os.environ['USERNAME']
def showPopup(title, message):
'''
Displays a message box on user's session (during 1 min).
'''
return subprocess.call('mshta "javascript:var sh=new ActiveXObject(\'WScript.Shell\'); sh.Popup( \'{}\', 60, \'{}\', 64); close()"'.format(message, title), shell=True)

View File

@ -181,3 +181,6 @@ class ServerWorker(object):
def sendLogoffMessage(self):
self.service.sendLogoffMessage()
def sendPopupMessage(self):
self.service.sendPopupMessage()