|
@@ -103,33 +103,6 @@ manager = Manager(
|
|
|
reconnect_timeout=app.config['AMI_TIMEOUT'],
|
|
reconnect_timeout=app.config['AMI_TIMEOUT'],
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-# class AuthMiddleware:
|
|
|
|
|
- # '''ASGI process middleware that rejects requests missing
|
|
|
|
|
- # the correct authentication header'''
|
|
|
|
|
-
|
|
|
|
|
- # def __init__(self, app):
|
|
|
|
|
- # self.app = app
|
|
|
|
|
- # async def __call__(self, scope, receive, send):
|
|
|
|
|
- # if 'headers' not in scope:
|
|
|
|
|
- # return await self.app(scope, receive, send)
|
|
|
|
|
- # for header, value in scope['headers']:
|
|
|
|
|
- # if ((header == bytes(app.config['AUTH_HEADER'].lower(), 'utf-8')) and
|
|
|
|
|
- # (value == bytes(app.config['AUTH_SECRET'], 'utf-8'))):
|
|
|
|
|
- # return await self.app(scope, receive, send)
|
|
|
|
|
- # # Paths "/openapi.json" and "/ui" do not require auth
|
|
|
|
|
- # if (('path' in scope) and
|
|
|
|
|
- # ((scope['path'] in NO_AUTH_ROUTES) or
|
|
|
|
|
- # (scope['path'].startswith('/static/records')))):
|
|
|
|
|
- # return await self.app(scope, receive, send)
|
|
|
|
|
- # return await self.error_response(receive, send)
|
|
|
|
|
- # async def error_response(self, receive, send):
|
|
|
|
|
- # await send({'type': 'http.response.start',
|
|
|
|
|
- # 'status': 401,
|
|
|
|
|
- # 'headers': [(b'content-length', b'21')]})
|
|
|
|
|
- # await send({'type': 'http.response.body',
|
|
|
|
|
- # 'body': b'Authorization requred',
|
|
|
|
|
- # 'more_body': False})
|
|
|
|
|
-
|
|
|
|
|
def authRequired(func):
|
|
def authRequired(func):
|
|
|
@wraps(func)
|
|
@wraps(func)
|
|
|
async def authWrapper(*args, **kwargs):
|
|
async def authWrapper(*args, **kwargs):
|
|
@@ -139,6 +112,7 @@ def authRequired(func):
|
|
|
(auth.type == "basic") and
|
|
(auth.type == "basic") and
|
|
|
(auth.username in current_app.cache['devices']) and
|
|
(auth.username in current_app.cache['devices']) and
|
|
|
(compare_digest(auth.password, current_app.cache['devices'][auth.username]))):
|
|
(compare_digest(auth.password, current_app.cache['devices'][auth.username]))):
|
|
|
|
|
+ request.device = auth.username
|
|
|
return await func(*args, **kwargs)
|
|
return await func(*args, **kwargs)
|
|
|
elif ((current_app.config['AUTH_HEADER'].lower() in headers) and
|
|
elif ((current_app.config['AUTH_HEADER'].lower() in headers) and
|
|
|
(headers[current_app.config['AUTH_HEADER'].lower()] == current_app.config['AUTH_SECRET'])):
|
|
(headers[current_app.config['AUTH_HEADER'].lower()] == current_app.config['AUTH_SECRET'])):
|
|
@@ -147,7 +121,6 @@ def authRequired(func):
|
|
|
abort(401)
|
|
abort(401)
|
|
|
return authWrapper
|
|
return authWrapper
|
|
|
|
|
|
|
|
-# app.asgi_app = AuthMiddleware(app.asgi_app)
|
|
|
|
|
db = PintDB(app)
|
|
db = PintDB(app)
|
|
|
|
|
|
|
|
@manager.register_event('FullyBooted')
|
|
@manager.register_event('FullyBooted')
|
|
@@ -313,7 +286,6 @@ async def amiGetVar(variable):
|
|
|
@authRequired
|
|
@authRequired
|
|
|
@app.route('/ami/auths')
|
|
@app.route('/ami/auths')
|
|
|
async def amiPJSIPShowAuths():
|
|
async def amiPJSIPShowAuths():
|
|
|
- app.logger.warning(pformat(request.headers))
|
|
|
|
|
return successReply(app.cache['devices'])
|
|
return successReply(app.cache['devices'])
|
|
|
|
|
|
|
|
@authRequired
|
|
@authRequired
|
|
@@ -781,6 +753,7 @@ class UsersStates(Resource):
|
|
|
'''Returns all users with their combined states.
|
|
'''Returns all users with their combined states.
|
|
|
Possible states are: available, away, dnd, inuse, busy, unavailable, ringing
|
|
Possible states are: available, away, dnd, inuse, busy, unavailable, ringing
|
|
|
'''
|
|
'''
|
|
|
|
|
+ app.logger.warning('request device: {}'.format(request.device))
|
|
|
usersCount = await refreshStatesCache()
|
|
usersCount = await refreshStatesCache()
|
|
|
if usersCount == 0:
|
|
if usersCount == 0:
|
|
|
return stateCacheEmpty()
|
|
return stateCacheEmpty()
|