Changelog: https://haproxy-wi.org/changelog.py#5_3_1
This commit is contained in:
Pavel Loginov
2021-10-21 21:41:54 +06:00
parent a4b4a33e5f
commit f40011bc4f
3 changed files with 67 additions and 34 deletions

View File

@@ -19,8 +19,8 @@ _allow_headers = 'Authorization, Origin, Accept, Content-Type, X-Requested-With'
@hook('before_request')
def check_login():
return api_funct.check_login()
def check_login(required_service=0):
return api_funct.check_login(required_service=required_service)
@hook('after_request')
@@ -38,7 +38,7 @@ def error_handler_500(error):
@route('/', method=['GET', 'POST'])
@route('/help', method=['GET', 'POST'])
def index():
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
data = {
@@ -55,10 +55,10 @@ def index():
'haproxy/<id,hostname,ip>/action/restart':'restart HAProxy service by id or hostname or ip. METHOD: GET',
'haproxy/<id,hostname,ip>/config':'get HAProxy config from the server by id or hostname or ip. METHOD: GET',
'haproxy/<id,hostname,ip>/log':'show HAProxy log by id or hostname or ip. May to have config next headers: rows(format INT) default: 10 grep, waf(if needs WAF log) default: 0, start_hour(format: 24) default: 00, start_minute, end_hour(format: 24) default: 24, end_minute. METHOD: GET',
'haproxy/<id,hostname,ip>/section':'show certain section, headers: section_name. METHOD: GET',
'haproxy/<id,hostname,ip>/section':'add section to the HAProxy config by id or hostname or ip. Has to have config header with section and action header for action after upload. Action header accepts next value: save, test, reload and restart. May be empty for just save. METHOD: POST',
'haproxy/<id,hostname,ip>/acl':'add acl to certain section. Must be JSON body: "section_name", "if", "then", "if_value", "then_value" and "action" for action after upload. Action accepts next value: "save", "test", "reload" and "restart". METHOD: POST',
'haproxy/<id,hostname,ip>/acl':'delete acl to certain section. Must be JSON body: "section_name", "if", "then", "if_value", "then_value" and "action" for action after upload. Action accepts next value: "save", "test", "reload" and "restart". METHOD: DELETE'
'haproxy/<id,hostname,ip>/section':'show certain section, headers: section-name. METHOD: GET',
'haproxy/<id,hostname,ip>/section/add':'add section to the HAProxy config by id or hostname or ip. Has to have config header with section and action header for action after upload. Section header must consist type: listen, frontend, etc. Action header accepts next value: save, test, reload and restart. Can be empty for just save. METHOD: POST',
'haproxy/<id,hostname,ip>/acl':'add acl to certain section. Must be JSON body: "section-name", "if", "then", "if_value", "then_value" and "action" for action after upload. Action accepts next value: "save", "test", "reload" and "restart". METHOD: POST',
'haproxy/<id,hostname,ip>/acl':'delete acl to certain section. Must be JSON body: "section-name", "if", "then", "if_value", "then_value" and "action" for action after upload. Action accepts next value: "save", "test", "reload" and "restart". METHOD: DELETE'
}
return dict(help=data)
@@ -108,7 +108,7 @@ def callback():
@route('/haproxy/<haproxy_id>', method=['GET'])
@route('/haproxy/<haproxy_id:int>', method=['GET'])
def callback(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.get_server(haproxy_id)
@@ -116,7 +116,7 @@ def callback(haproxy_id):
@route('/haproxy/<haproxy_id>/status', method=['GET'])
@route('/haproxy/<haproxy_id:int>/status', method=['GET'])
def callback(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.get_status(haproxy_id)
@@ -124,7 +124,7 @@ def callback(haproxy_id):
@route('/haproxy/<haproxy_id>/action/<action:re:[a-z]+>', method=['GET'])
@route('/haproxy/<haproxy_id:int>/action/<action:re:[a-z]+>', method=['GET'])
def callback(haproxy_id, action):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.actions(haproxy_id, action)
@@ -132,7 +132,7 @@ def callback(haproxy_id, action):
@route('/haproxy/<haproxy_id>/runtime', method=['POST'])
@route('/haproxy/<haproxy_id:int>/runtime', method=['POST'])
def callback(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.runtime(haproxy_id)
@@ -140,7 +140,7 @@ def callback(haproxy_id):
@route('/haproxy/<haproxy_id>/backends', method=['GET'])
@route('/haproxy/<haproxy_id:int>/backends', method=['GET'])
def callback(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.show_backends(haproxy_id)
@@ -148,7 +148,7 @@ def callback(haproxy_id):
@route('/haproxy/<haproxy_id>/config', method=['GET'])
@route('/haproxy/<haproxy_id:int>/config', method=['GET'])
def callback(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.get_config(haproxy_id)
#
@@ -156,7 +156,7 @@ def callback(haproxy_id):
# @route('/haproxy/<haproxy_id>/config', method=['POST'])
# @route('/haproxy/<haproxy_id:int>/config', method=['POST'])
# def callback(haproxy_id):
# if not check_login():
# if not check_login(required_service=1):
# return dict(error=_error_auth)
# return api_funct.upload_config(haproxy_id)
@@ -164,36 +164,37 @@ def callback(haproxy_id):
@route('/haproxy/<haproxy_id>/log', method=['GET'])
@route('/haproxy/<haproxy_id:int>/log', method=['GET'])
def callback(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.show_log(haproxy_id)
@route('/haproxy/<haproxy_id>/section', method=['GET'])
def get_section(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
print(str(request.headers.get('section-name')))
return api_funct.get_section(haproxy_id)
@route('/haproxy/<haproxy_id>/section', method=['POST'])
@route('/haproxy/<haproxy_id:int>/section', method=['POST'])
@route('/haproxy/<haproxy_id>/section/add', method=['POST'])
@route('/haproxy/<haproxy_id:int>/section/add', method=['POST'])
def callback(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.add_to_config(haproxy_id)
@route('/haproxy/<haproxy_id>/acl', method=['POST'])
def add_acl(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.add_acl(haproxy_id)
@route('/haproxy/<haproxy_id>/acl', method=['DELETE'])
def add_acl(haproxy_id):
if not check_login():
if not check_login(required_service=1):
return dict(error=_error_auth)
return api_funct.del_acl(haproxy_id)