mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Removed last remaining xmlrcp part
This commit is contained in:
parent
7f1252a70a
commit
401fbac63e
@ -79,8 +79,6 @@ class UDSAppConfig(AppConfig):
|
||||
from . import plugins # To make sure plugins are loaded on memory
|
||||
from . import REST # To make sure REST initializes all what it needs
|
||||
|
||||
import uds.xmlrpc # To make actor live
|
||||
|
||||
|
||||
default_app_config = 'uds.UDSAppConfig'
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012 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.
|
||||
|
||||
'''
|
||||
XMLRCP processing part
|
||||
This package contains all xmlrpc related stuff
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# from django.utils.translation import ugettext_noop as _
|
||||
|
||||
# from uds.core.managers.DownloadsManager import DownloadsManager
|
||||
# import os.path
|
||||
# import sys
|
||||
|
||||
# DownloadsManager.manager().registerDownloadable('UDSAdminSetup.exe',
|
||||
# _('UDS Client Administration Interface <b>(Important!! Requires .net framework 3.5 sp1)</b>'),
|
||||
# os.path.dirname(sys.modules[__package__].__file__) + '/files/UDSAdminSetup.exe',
|
||||
# 'application/x-msdownload')
|
@ -1,93 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012 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 uds.models import UserService
|
||||
from uds.core.util.State import State
|
||||
from uds.core.util import log
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def test():
|
||||
'''
|
||||
Simple test function called by actors to test communication.
|
||||
'''
|
||||
logger.debug("Test called")
|
||||
return True
|
||||
|
||||
|
||||
def message_fnc(id_, message, data):
|
||||
'''
|
||||
Process a message from the actor.
|
||||
@param _id: Ids used by actors to identify themself and locate services to witch they belongs
|
||||
@param message: Mesagge received from actor
|
||||
@param data: Extra data
|
||||
'''
|
||||
ids = id_.split(",")[:5] # Limit ids received to five...
|
||||
logger.debug("Called message for id_ {0}, message \"{1}\" and data \"{2}\"".format(ids, message, data))
|
||||
|
||||
# Fix: Log used to send "INFO", "DEBUG", .. as level instead of numeric
|
||||
# Now, we use levels, so for "legacy" actors we can do logs correctly
|
||||
if message == 'log':
|
||||
try:
|
||||
msg, level = data.split('\t')
|
||||
logger.debug('Msg: {}, level: "{}"'.format(msg, level))
|
||||
level = "{}".format(log.logLevelFromStr(level))
|
||||
logger.debug('Level: "{}"'.format(level))
|
||||
data = '\t'.join([msg, level])
|
||||
except Exception:
|
||||
logger.exception("Exception at log")
|
||||
data = data.replace('\t', ' ') + '\t10000' # Other
|
||||
|
||||
res = ""
|
||||
try:
|
||||
services = UserService.objects.filter(unique_id__in=ids, state__in=[State.USABLE, State.PREPARING])
|
||||
if services.count() == 0:
|
||||
res = ""
|
||||
else:
|
||||
res = services[0].getInstance().osmanager().process(services[0], message, data, None)
|
||||
except Exception as e:
|
||||
logger.error("Exception at message (client): {0}".format(e))
|
||||
res = ""
|
||||
logger.debug("Returning {0}".format(res))
|
||||
return res
|
||||
|
||||
|
||||
def registerActorFunctions(dispatcher):
|
||||
'''
|
||||
Utility function to register methods at xmlrpc server for actor
|
||||
'''
|
||||
dispatcher.register_function(test, 'test')
|
||||
dispatcher.register_function(message_fnc, 'message')
|
@ -1,3 +0,0 @@
|
||||
'''
|
||||
This module is responsible of the communication between actors and OS Managers
|
||||
'''
|
@ -1,99 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2012 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 django.http import HttpResponse
|
||||
from SimpleXMLRPCServer import SimpleXMLRPCDispatcher
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from uds.xmlrpc.actor.Actor import registerActorFunctions
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class XMLRPCDispatcher(SimpleXMLRPCDispatcher):
|
||||
'''
|
||||
Own dispatchers, to allow the pass of the request to the methods.
|
||||
|
||||
Request will be, in most cases, removed from params at @needs_credentials decorator
|
||||
This means that all xmlrpc methods that needs_credentials, will have the request at
|
||||
the Credentials object.
|
||||
|
||||
If no request is needed, normal method invocation will be done
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
SimpleXMLRPCDispatcher.__init__(self, allow_none=False, encoding=None)
|
||||
|
||||
def dispatch(self, request, **kwargs):
|
||||
import xmlrpclib
|
||||
xml = request.body
|
||||
try:
|
||||
params, method = xmlrpclib.loads(xml)
|
||||
try:
|
||||
response = self._dispatch(method, params + (request,))
|
||||
except TypeError:
|
||||
response = self._dispatch(method, params)
|
||||
|
||||
response = (response,)
|
||||
response = xmlrpclib.dumps(response, methodresponse=1)
|
||||
except xmlrpclib.Fault as fault:
|
||||
response = xmlrpclib.dumps(fault)
|
||||
except Exception as e:
|
||||
response = xmlrpclib.dumps(
|
||||
xmlrpclib.Fault(1, "Exception caught!: {0}".format(e))
|
||||
)
|
||||
logger.exception('Excaption processing xmlrpc message')
|
||||
|
||||
return HttpResponse(response, content_type='text/xml')
|
||||
|
||||
|
||||
dispatcher = XMLRPCDispatcher()
|
||||
|
||||
|
||||
# csrf_exempt is needed because we don't expect xmlrcp to be called from a web form
|
||||
@csrf_exempt
|
||||
def xmlrpc(request):
|
||||
if request.method == "POST":
|
||||
response = dispatcher.dispatch(request)
|
||||
else:
|
||||
logger.error('XMLRPC invocation with GET method {0}'.format(request.path))
|
||||
response = HttpResponse()
|
||||
response.write("<b>This is an XML-RPC Service.</b><br>")
|
||||
response.write("You need to invoke it using an XML-RPC Client!<br>")
|
||||
|
||||
response['Content-length'] = str(len(response.content))
|
||||
return response
|
||||
|
||||
registerActorFunctions(dispatcher)
|
Loading…
Reference in New Issue
Block a user