mirror of
https://github.com/YunoHost/check-http.git
synced 2024-09-03 19:56:42 +02:00
Merge f6e18f1e16
into dcb199362a
This commit is contained in:
commit
35e3c66f8e
2 changed files with 44 additions and 3 deletions
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
FROM python:3.9
|
||||||
|
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements-frozen.txt yunodiagnoser.py /app/
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir -r /app/requirements-frozen.txt
|
||||||
|
|
||||||
|
CMD ["python3", "/app/yunodiagnoser.py"]
|
|
@ -4,6 +4,7 @@ import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import validators
|
import validators
|
||||||
import socket
|
import socket
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.log import logger
|
from sanic.log import logger
|
||||||
|
@ -11,6 +12,9 @@ from sanic.response import html, json as json_response
|
||||||
from sanic.exceptions import InvalidUsage
|
from sanic.exceptions import InvalidUsage
|
||||||
|
|
||||||
app = Sanic(__name__)
|
app = Sanic(__name__)
|
||||||
|
# Don't override values from environment variables
|
||||||
|
app.config.setdefault('MAX_DOMAINS', 60)
|
||||||
|
app.config.setdefault('MAX_PORTS', 30)
|
||||||
|
|
||||||
# ########################################################################### #
|
# ########################################################################### #
|
||||||
# Rate limit #
|
# Rate limit #
|
||||||
|
@ -125,7 +129,7 @@ async def check_http(request):
|
||||||
# Check domain list format
|
# Check domain list format
|
||||||
assert isinstance(data["domains"], list), "'domains' ain't a list"
|
assert isinstance(data["domains"], list), "'domains' ain't a list"
|
||||||
assert len(data["domains"]) > 0, "'domains' list is empty"
|
assert len(data["domains"]) > 0, "'domains' list is empty"
|
||||||
assert len(data["domains"]) < 60, "You cannot test that many domains"
|
assert len(data["domains"]) < int(request.app.config.MAX_DOMAINS), "You cannot test that many domains"
|
||||||
for domain in data["domains"]:
|
for domain in data["domains"]:
|
||||||
assert isinstance(domain, str), "domain names must be strings"
|
assert isinstance(domain, str), "domain names must be strings"
|
||||||
assert len(domain) < 100, "Domain %s name seems pretty long, that's suspicious...?" % domain
|
assert len(domain) < 100, "Domain %s name seems pretty long, that's suspicious...?" % domain
|
||||||
|
@ -260,7 +264,7 @@ async def check_ports(request):
|
||||||
|
|
||||||
assert isinstance(data["ports"], list), "'ports' ain't a list"
|
assert isinstance(data["ports"], list), "'ports' ain't a list"
|
||||||
assert len(data["ports"]) > 0, "'ports' list is empty"
|
assert len(data["ports"]) > 0, "'ports' list is empty"
|
||||||
assert len(data["ports"]) < 30, "That's too many ports to check"
|
assert len(data["ports"]) < int(request.app.config.MAX_PORTS), "That's too many ports to check"
|
||||||
assert len(data["ports"]) == len(set(data["ports"])), "'ports' list should contain unique elements"
|
assert len(data["ports"]) == len(set(data["ports"])), "'ports' list should contain unique elements"
|
||||||
|
|
||||||
def is_port_number(p):
|
def is_port_number(p):
|
||||||
|
@ -394,5 +398,31 @@ 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 with an API to check if a services running on YunoHost instance can be reached from 'the global internet'.")
|
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'.")
|
||||||
|
|
||||||
|
|
||||||
|
def serve():
|
||||||
|
parser = ArgumentParser('yunodiagnoser.py')
|
||||||
|
parser.add_argument('--host', help='Address to host on', default='0.0.0.0')
|
||||||
|
parser.add_argument('--port', help='Port to host on', default=8000, type=int)
|
||||||
|
parser.add_argument('--workers', help='Number of processes received before it is respected', default=16, type=int)
|
||||||
|
parser.add_argument('--debug', help='Enables debug output (slows server)', action='store_true')
|
||||||
|
parser.add_argument('--auto-reload', help='Reload app whenever its source code is changed. Enabled by default in debug mode.', default=None, action='store_true')
|
||||||
|
|
||||||
|
# Inherit from environment variables or defaults
|
||||||
|
parser.add_argument('--max-domains', help='Maximum domains allowed to check in a batch', default=app.config.MAX_DOMAINS, type=int)
|
||||||
|
parser.add_argument('--max-ports', help='Maximum ports allowed to check in a batch', default=app.config.MAX_PORTS, type=int)
|
||||||
|
|
||||||
|
args, _ = parser.parse_known_args()
|
||||||
|
|
||||||
|
for arg in ('max_domains', 'max_ports'):
|
||||||
|
app.config[arg.upper()] = getattr(args, arg)
|
||||||
|
|
||||||
|
app.run(
|
||||||
|
host=args.host,
|
||||||
|
port=args.port,
|
||||||
|
workers=args.workers,
|
||||||
|
debug=args.debug,
|
||||||
|
auto_reload=args.auto_reload,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=7000, workers=16)
|
serve()
|
||||||
|
|
Loading…
Add table
Reference in a new issue