Example #1
0
  def authErrors():
    # Check auth
    if not request.headers.get('Authorization'):
      return ({'status': 'error', 'reason': 'Authentication needed'}, 401)
    method, name, token = Advanced_API.getAuth()

    data = None
    if method.lower() not in ['basic', 'token', 'session', 'bearer']:
      data = ({'status': 'error', 'reason': 'Authorization method not allowed'}, 400)
    else:
      try:
        authenticated = False
        if   method.lower() == 'basic':
          authenticator = AuthenticationHandler()
          if authenticator.validateUser(name, token): authenticated = True
        elif method.lower() == 'bearer':
            authenticated, name  = db.isBearerAuthenticated(token)
        elif method.lower() == 'token':
            if db.getToken(name) == token: authenticated = True
        elif method.lower() == 'session':
          authenticator = AuthenticationHandler()
          if authenticator.api_sessions.get(name) == token: authenticated = True
        if not authenticated: data = ({'status': 'error', 'reason': 'Authentication failed'}, 401)
      except Exception as e:
        print(e)
        data = ({'status': 'error', 'reason': 'Malformed Authentication String'}, 400)
    if data:
      return data
    else: return None
Example #2
0
 def adminInfo(self, output=None):
     return {
         'stats': db.getDBStats(True),
         'plugins': self.plugManager.getPlugins(),
         'updateOutput': self.filterUpdateField(output),
         'token': str(db.getToken(current_user.id))
     }
Example #3
0
 def authErrors():
   # Check auth
   if not request.headers.get('Authorization'):
     return ({'status': 'error', 'reason': 'Authentication needed'}, 401)
   method, name, token = Advanced_API.getAuth()
   data = None
   if method.lower() not in ['basic', 'token', 'session']:
     data = ({'status': 'error', 'reason': 'Authorization method not allowed'}, 400)
   else:
     try:
       authenticated = False
       if   method.lower() == 'basic':
         authenticator = AuthenticationHandler()
         if authenticator.validateUser(name, token): authenticated = True
       elif method.lower() == 'token':
         if db.getToken(name) == token: authenticated = True
       elif method.lower() == 'session':
         authenticator = AuthenticationHandler()
         if authenticator.api_sessions.get(name) == token: authenticated = True
       if not authenticated: data = ({'status': 'error', 'reason': 'Authentication failed'}, 401)
     except Exception as e:
       print(e)
       data = ({'status': 'error', 'reason': 'Malformed Authentication String'}, 400)
   if data:
     return data
   else: return None
Example #4
0
 def authErrors(self):
     # Check auth
     if not request.headers.get("Authorization"):
         return ({
             "status": "error",
             "reason": "Authentication needed"
         }, 401)
     method, name, token = Advanced_API.getAuth()
     data = None
     if method.lower() not in ["basic", "token", "session"]:
         data = (
             {
                 "status": "error",
                 "reason": "Authorization method not allowed"
             },
             400,
         )
     else:
         try:
             authenticated = False
             if method.lower() == "basic":
                 authenticator = AuthenticationHandler()
                 if authenticator.validateUser(name, token):
                     authenticated = True
             elif method.lower() == "token":
                 if db.getToken(name) == token:
                     authenticated = True
             elif method.lower() == "session":
                 authenticator = AuthenticationHandler()
                 if authenticator.api_sessions.get(name) == token:
                     authenticated = True
             if not authenticated:
                 data = ({
                     "status": "error",
                     "reason": "Authentication failed"
                 }, 401)
         except Exception as e:
             print(e)
             data = (
                 {
                     "status": "error",
                     "reason": "Malformed Authentication String"
                 },
                 400,
             )
     if data:
         return data
     else:
         return None
Example #5
0
 def api_admin_get_token(self):
     method, name, key = Advanced_API.getAuth()
     return db.getToken(name)
Example #6
0
 def adminInfo(self, output=None):
   return {'stats':        db.getDBStats(True),
           'plugins':      self.plugManager.getPlugins(),
           'updateOutput': self.filterUpdateField(output),
           'token':        db.getToken(current_user.id)}
Example #7
0
 def api_admin_get_token(self):
   method, name, key =   Advanced_API.getAuth()
   return db.getToken(name)