Commit 135fcf33 authored by PidgeyL's avatar PidgeyL
Browse files

add functionality of subpages

parent 680a7cc9
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -112,6 +112,21 @@ class PluginManager():
          else:    return None
        else:
          return ("error.html", {'status': {'except': 'plugin-page-missing'}})
      else:
        return ("error.html", {'status': {'except': 'plugin-not-webplugin'}})
    return ("error.html", {'status': {'except': 'plugin-not-loaded'}})

  def openSubpage(self, subpage, **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].getSubpage(subpage, **args)
        if type(pageInfo) == tuple:
          page, content = pageInfo
          if page: return ("plugins/%s"%page, content)
        # Else, the page is missing, so we send None to throw a 404
        return None
      else:
        return ("error.html", {'status': {'except': 'plugin-not-webplugin'}})
    return ("error.html", {'status': {'except': 'plugin-not-loaded'}})

  def cvePluginInfo(self, cve, **args):
+5 −4
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ class WebPlugin(Plugin):
  def isWebPlugin(self):           return True
  # To override
  def getPage(self, **args):           return (None, None)
  def openSubpage(self, page, **args): return (None, None)
  def getCVEActions(self, **args):     return []
  # Functions based on user interaction
  def onCVEAction(self, action, **args): pass
  def cvePluginInfo(self, action, **args): pass
  def cvePluginInfo(self, cve, **args):  pass
+13 −0
Original line number Diff line number Diff line
@@ -355,6 +355,19 @@ def openPlugin(plugin):
            except jinja2.exceptions.TemplateNotFound:    return render_template("error.html", status={'except': 'plugin-page-not-found', 'page': page})
        else: abort(404)

@app.route('/plugin/<plugin>/subpage/<page>', methods=['GET'])
def openPluginSubpage(plugin, page):
    if plugManager.requiresAuth(plugin) and not current_user.is_authenticated():
        return render_template("requiresAuth.html")
    else:
        page, args = plugManager.openSubpage(plugin, page, current_user=current_user)
        if page:
            try:
                return render_template(page, **args)
            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)

@app.route('/plugin/<plugin>/_cve_action/<action>', methods=['GET'])
def jsonCVEAction(plugin, action):
    cve = request.args.get('cve', type=str).split(",")
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@
      <p>The plug-in could not find the page it was looking for ({{status['page']}}). </p>
      <p>Please check if you installed this page correctly. If the error is not at your side, but the developer, please contact them.</p>
      <p>Error code <code>013</code></p>
    {% elif status['except']=='plugin-not-webplugin' %}
      <h1>Plug-in not a webplugin</h1>
      <p>This plug-in is not a web plug-in, and has no page to display.</p>
    {% endif %}
  </div>
{% endblock %}