Misc fixes / updates for messages

This commit is contained in:
Alexandre Aubin 2019-07-29 22:54:58 +02:00
parent d23290299e
commit 1445a12ab6

View file

@ -57,6 +57,7 @@ async def check_port_is_open(ip, port):
return result == 0 return result == 0
# FIXME : remove it ? not used anymore...
async def query_dns(host, dns_entry_type): async def query_dns(host, dns_entry_type):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
dns_resolver = aiodns.DNSResolver(loop=loop) dns_resolver = aiodns.DNSResolver(loop=loop)
@ -119,15 +120,20 @@ async def check_http(request):
}, status=400) }, status=400)
if not data or "domain" not in data or "nonce" not in data: if not data or "domain" not in data or "nonce" not in data:
logger.info(f"Unvalid request didn't specified a domain and a nonce id (body is : {request.body}") logger.info(f"Invalid request: didn't specified a domain and a nonce id (body is: {request.body}")
return json_response({ return json_response({
"status": "error", "status": "error",
"code": "error_no_domain", "code": "error_no_domain_",
"content": "Request must specify a domain and a nonce", "content": "Request must specify a domain and a nonce",
}, status=400) }, status=400)
domain = data["domain"] domain = data["domain"]
# Since now we are only checking the IP itself, it seems
# unecessary to also have a rate limit on domains since the
# rate limit on IP will be hit first ...
# That would simplify some code, for example we could add the
# rate limit check in a decorator for each route/check
check_rate_limit_domain = check_rate_limit(domain, now) check_rate_limit_domain = check_rate_limit(domain, now)
if check_rate_limit_domain: if check_rate_limit_domain:
return check_rate_limit_domain return check_rate_limit_domain
@ -172,7 +178,7 @@ async def check_http(request):
return json_response({ return json_response({
"status": "error", "status": "error",
"code": "error_http_check_connection_error", "code": "error_http_check_connection_error",
"content": "connection error, could not connect to the requested domain, it's very likely unreachable", "content": "Connection error: could not connect to the requested domain, it's very likely unreachable",
}, status=418) }, status=418)
except Exception: except Exception:
import traceback import traceback
@ -181,7 +187,7 @@ async def check_http(request):
return json_response({ return json_response({
"status": "error", "status": "error",
"code": "error_http_check_unknown_error", "code": "error_http_check_unknown_error",
"content": "an error happen while trying to get your domain, it's very likely unreachable", "content": "An error happened while trying to reach your domain, it's very likely unreachable",
}, status=400) }, status=400)
return json_response({"status": "ok"}) return json_response({"status": "ok"})
@ -224,7 +230,7 @@ async def check_ports(request):
return json_response({ return json_response({
"status": "error", "status": "error",
"code": "error_bad_json", "code": "error_bad_json",
"content": "Invalid usage, body isn't proper json", "content": "Invalid usage: body isn't proper json",
}, status=400) }, status=400)
def is_port_number(p): def is_port_number(p):
@ -232,7 +238,7 @@ async def check_ports(request):
# Check "ports" exist in request and is a list of port # Check "ports" exist in request and is a list of port
if not data or "ports" not in data: if not data or "ports" not in data:
logger.info(f"Unvalid request didn't specified a ports list (body is : {request.body}") logger.info(f"Invalid request didn't specified a ports list (body is: {request.body}")
return json_response({ return json_response({
"status": "error", "status": "error",
"code": "error_no_ports_list", "code": "error_no_ports_list",
@ -271,7 +277,7 @@ async def check_smtp(request):
@app.route("/") @app.route("/")
async def main(request): async def main(request):
return html("You aren't really supposed to use this website using your browser.<br><br>It's a small server to check if a YunoHost instance can be reached by http before trying to instal a LE certificate.") return html("You aren't really supposed to use this website using your browser.<br><br>It's a small server with an API to check if a services running on YunoHost instance can be reached from 'the global internet'.")
if __name__ == "__main__": if __name__ == "__main__":