コード例 #1
0
ファイル: server_rpc.py プロジェクト: vysecurity/king-phisher
    def decorator(function):
        @functools.wraps(function)
        def wrapper(handler_instance, *args, **kwargs):
            if log_call and rpc_logger.isEnabledFor(logging.DEBUG):
                args_repr = ', '.join(map(repr, args))
                if kwargs:
                    for key, value in sorted(kwargs.items()):
                        args_repr += ", {0}={1!r}".format(key, value)
                msg = "calling RPC method {0}({1})".format(
                    function.__name__, args_repr)
                if getattr(handler_instance, 'rpc_session', False):
                    msg = handler_instance.rpc_session.user + ' is ' + msg
                rpc_logger.debug(msg)
            signals.rpc_method_call.send(path[1:-1],
                                         request_handler=handler_instance,
                                         args=args,
                                         kwargs=kwargs)
            if database_access:
                session = db_manager.Session()
                try:
                    result = function(handler_instance, session, *args,
                                      **kwargs)
                finally:
                    session.close()
            else:
                result = function(handler_instance, *args, **kwargs)
            signals.rpc_method_called.send(path[1:-1],
                                           request_handler=handler_instance,
                                           args=args,
                                           kwargs=kwargs,
                                           retval=result)
            return result

        advancedhttpserver.RegisterPath(path, is_rpc=True)(wrapper)
        return wrapper
コード例 #2
0
	def decorator(function):
		@functools.wraps(function)
		def wrapper(handler_instance, *args, **kwargs):
			if log_call:
				_log_rpc_call(handler_instance, function.__name__, *args, **kwargs)
			signals.send_safe('rpc-method-call', rpc_logger, path[1:-1], request_handler=handler_instance, args=args, kwargs=kwargs)
			if database_access:
				session = db_manager.Session()
				try:
					result = function(handler_instance, session, *args, **kwargs)
				finally:
					session.close()
			else:
				result = function(handler_instance, *args, **kwargs)
			signals.send_safe('rpc-method-called', rpc_logger, path[1:-1], request_handler=handler_instance, args=args, kwargs=kwargs, retval=result)
			return result
		advancedhttpserver.RegisterPath(path, is_rpc=True)(wrapper)
		return wrapper
コード例 #3
0
ファイル: plugins.py プロジェクト: roostergere/king-phisher
    def register_http(self, path, method):
        """
		Register a new HTTP request handler at *path* that is handled by
		*method*. Two parameters are passed to the method. The first parameter
		is a :py:class:`~king_phisher.server.server.KingPhisherRequestHandler`
		instance and the second is a dictionary of the HTTP query parameters.
		The specified path is added within the plugins private HTTP handler
		namespace at ``_/plugins/$PLUGIN_NAME/$PATH``

		.. warning::
			This resource can be reached by any user whether or not they
			are authenticated and or associated with a campaign.

		:param str path: The path to register the method at.
		:param method: The handler for the HTTP method.
		"""
        if path.startswith('/'):
            path = path[1:]
        path = "_/plugins/{0}/{1}".format(self.name, path)
        advancedhttpserver.RegisterPath(path)(method)