Commit 00963bfb authored by PidgeyL's avatar PidgeyL
Browse files

add jsonp support

parent b79d6a37
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ _runPath = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(_runPath, ".."))

from bson               import json_util
from flask              import Flask, request, Response, render_template
from flask              import Flask, request, Response, render_template, current_app
from functools          import wraps
from logging.handlers   import RotatingFileHandler
from redis              import exceptions as redisExceptions
@@ -54,6 +54,7 @@ class API():
              {'r': '/api/cvefor/<path:cpe>',              'm': ['GET'], 'f': self.api_cvesFor},
              {'r': '/api/cve/<cveid>',                    'm': ['GET'], 'f': self.api_cve},
              {'r': '/api/cwe',                            'm': ['GET'], 'f': self.api_cwe},
              {'r': '/api/cwe/<int:cwe_id>',               'm': ['GET'], 'f': self.api_cwe},
              {'r': '/api/capec/<cweid>',                  'm': ['GET'], 'f': self.api_capec},
              {'r': '/api/last',                           'm': ['GET'], 'f': self.api_last},
              {'r': '/api/last/',                          'm': ['GET'], 'f': self.api_last},
@@ -87,8 +88,12 @@ class API():
      # Check if data should be returned as html or data
      try:
        if request.url_rule.rule.lower().startswith("/api/"):
          # Support JSONP
          if request.args.get('callback', False):
            data="%s(%s)"%(request.args.get('callback'), data)

          # Check API version for backwards compatibility. We'll call the old API v1.0
          if request.headers.get('Version') in ['1.1']:
          elif request.headers.get('Version') in ['1.1']:
            # Get the requested return type
            returnType = request.headers.get('Accept')
            # Default to JSON
@@ -142,14 +147,15 @@ class API():
    return cve

  # /api/cwe
  # /api/cwe/<cwe_id>
  @api
  def api_cwe(self):
    return db.getCWEs()
  def api_cwe(self, cwe_id=None):
    return db.getCAPECFor(str(cwe_id)) if cwe_id else db.getCWEs()

  # /api/capec/<cweid>
  @api
  def api_capec(self, cweid):
    return db.getCAPECFor(cweid)
    return db.getCAPEC(cweid)

  # /api/last
  # /api/last/