Commit 3452d7f8 authored by PidgeyL's avatar PidgeyL
Browse files

Allow plugins to return more data types (e.g xml)

parent 7e547cf4
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -164,14 +164,25 @@ class PluginManager(metaclass=Singleton):
                    print("[!] Failed to perform %s action on module %s: "%(action, plugin))
                    print("[!]  -> %s"%e)


    def _parse_page(self, pageInfo):
        mimetype = 'text/html'
        if len(pageInfo) == 2:  page, content           = pageInfo
        elif len(pageInfo) > 2: page, content, mimetype = pageInfo[:3]
        else:                   page, content           = pageInfo, None

        if page and not content: content = {}

        if   page:    return ("plugins/%s"%page, content, mimetype)
        elif content: return (None, content, mimetype)
        else:         return None

    def openPage(self, name, **args):
        if name.strip() in self.plugins.keys(): # Check if plugin exists
            if self.plugins[name].isWebPlugin():  # Check if plugin is web plugin
                pageInfo = self.plugins[name].getPage(**args)
                if type(pageInfo) == tuple:
                    page, content = pageInfo
                    if page: return ("plugins/%s"%page, content)
                    else:    return None
                    return self._parse_page(pageInfo)
                else:
                    return ("error.html", {'status': {'except': 'plugin-page-missing'}})
            else:
@@ -183,8 +194,7 @@ class PluginManager(metaclass=Singleton):
            if self.plugins[name].isWebPlugin():  # Check if plugin is web plugin
                pageInfo = self.plugins[name].getSubpage(subpage, **args)
                if type(pageInfo) == tuple:
                    page, content = pageInfo
                    if page: return ("plugins/%s"%page, content)
                    return self._parse_page(pageInfo)
                # Else, the page is missing, so we send None to throw a 404
                return None
            else:
+23 −15
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import urllib
_runPath = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(_runPath, ".."))

from flask       import abort, jsonify, request, redirect, render_template, send_file
from flask       import abort, jsonify, request, redirect, render_template, send_file, Response
from flask_login import LoginManager, current_user, login_user, logout_user, login_required
from io          import TextIOWrapper, BytesIO
from redis       import exceptions as redisExceptions
@@ -228,13 +228,17 @@ class Index(Minimal, Advanced_API):
        if self.plugManager.requiresAuth(plugin) and not current_user.is_authenticated():
            return render_template("requiresAuth.html")
        else:
            page, args = self.plugManager.openPage(plugin, **self.pluginArgs)
            data = self.plugManager.openPage(plugin, **self.pluginArgs)
            if data:
                page, data, mimetype = data
                if page:
                    try:
                    return render_template(page, **args)
                        return render_template(page, **data)
                    except jinja2.exceptions.TemplateSyntaxError: return render_template("error.html", status={'except': 'plugin-page-corrupt'})
                    except jinja2.exceptions.TemplateNotFound:    return render_template("error.html", status={'except': 'plugin-page-not-found', 'page': page})
            else: abort(404)
                elif data:
                    return Response(data, mimetype=mimetype)
            abort(404)


    # /plugin/<plugin>/subpage/<page>
@@ -242,13 +246,17 @@ class Index(Minimal, Advanced_API):
        if self.plugManager.requiresAuth(plugin) and not current_user.is_authenticated():
            return render_template("requiresAuth.html")
        else:
            page, args = self.plugManager.openSubpage(plugin, page, **self.pluginArgs)
            data = self.plugManager.openSubpage(plugin, page, **self.pluginArgs)
            if data:
                page, data, mimetype = data
                if page:
                    try:
                    return render_template(page, **args)
                        return render_template(page, **data)
                    except jinja2.exceptions.TemplateSyntaxError: return render_template("error.html", status={'except': 'plugin-page-corrupt'})
                    except jinja2.exceptions.TemplateNotFound:    return render_template("error.html", status={'except': 'plugin-page-not-found', 'page': page})
            else: abort(404)
                elif data:
                    return Response(data, mimetype=mimetype)
            abort(404)


    # /plugin/<plugin>/_cve_action/<action>