mirror of
https://github.com/YunoHost/check-http.git
synced 2024-09-03 19:56:42 +02:00
Misc fixes / updates for messages
This commit is contained in:
parent
d23290299e
commit
1445a12ab6
1 changed files with 19 additions and 13 deletions
20
server.py
20
server.py
|
@ -57,6 +57,7 @@ async def check_port_is_open(ip, port):
|
|||
return result == 0
|
||||
|
||||
|
||||
# FIXME : remove it ? not used anymore...
|
||||
async def query_dns(host, dns_entry_type):
|
||||
loop = asyncio.get_event_loop()
|
||||
dns_resolver = aiodns.DNSResolver(loop=loop)
|
||||
|
@ -119,15 +120,20 @@ async def check_http(request):
|
|||
}, status=400)
|
||||
|
||||
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({
|
||||
"status": "error",
|
||||
"code": "error_no_domain",
|
||||
"code": "error_no_domain_",
|
||||
"content": "Request must specify a domain and a nonce",
|
||||
}, status=400)
|
||||
|
||||
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)
|
||||
if check_rate_limit_domain:
|
||||
return check_rate_limit_domain
|
||||
|
@ -172,7 +178,7 @@ async def check_http(request):
|
|||
return json_response({
|
||||
"status": "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)
|
||||
except Exception:
|
||||
import traceback
|
||||
|
@ -181,7 +187,7 @@ async def check_http(request):
|
|||
return json_response({
|
||||
"status": "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)
|
||||
|
||||
return json_response({"status": "ok"})
|
||||
|
@ -224,7 +230,7 @@ async def check_ports(request):
|
|||
return json_response({
|
||||
"status": "error",
|
||||
"code": "error_bad_json",
|
||||
"content": "Invalid usage, body isn't proper json",
|
||||
"content": "Invalid usage: body isn't proper json",
|
||||
}, status=400)
|
||||
|
||||
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
|
||||
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({
|
||||
"status": "error",
|
||||
"code": "error_no_ports_list",
|
||||
|
@ -271,7 +277,7 @@ async def check_smtp(request):
|
|||
|
||||
@app.route("/")
|
||||
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__":
|
||||
|
|
Loading…
Reference in a new issue