From 87499b859e345d5fde390c8d05c119150f001690 Mon Sep 17 00:00:00 2001 From: Kierre Date: Wed, 1 Oct 2025 18:28:54 -0400 Subject: [PATCH] init --- .gitignore | 1 + LICENSE | 11 ++++++ README.md | 20 +++++++++++ assets/style.css | 53 +++++++++++++++++++++++++++++ config-example.toml | 16 +++++++++ index.py | 65 ++++++++++++++++++++++++++++++++++++ templates/index.xht | 33 ++++++++++++++++++ templates/internal_error.xht | 17 ++++++++++ 8 files changed, 216 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 assets/style.css create mode 100644 config-example.toml create mode 100644 index.py create mode 100644 templates/index.xht create mode 100644 templates/internal_error.xht diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6c096 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.toml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3f2b56c --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Velicense + +Copyright (c) 2025 Kierre Sametti + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +2. Any person or entity releasing a proprietary version of the Software must clearly state, in an easily accessible location, that they are a massive cuck. This statement does not require an explanation of any kind. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7acc11 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# velping +a pinger. it pings. this is made specifically for my needs, so you can open an issue for a feature request, but i likely won't accept it unless it's something i want. + +## configuration options +### frontend +- `name`: what will show as the header on the landing page. +- `port`: what port the frontend will run on. +- `pings`: how many pings to show on the frontend + +### pinging +- `allow_empty_responses`: this does NOT mean HTTP 204, but rather if the connection being suddenly closed after a request should be accepted as online. this option only exists because i run a minecraft server. +- `seconds_between_ping`: how often services should be pinged, in seconds. + +### ntfy +- `enabled`: whether or not to enable ntfy. +- `server`: the server to send notifications to. +- `topic`: the ntfy topic. + +### services +you can add services here, with the name of the key being the name of the service and the value being the URL to ping. diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..098e635 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,53 @@ +::selection { + background-color: #eeadb7; + color: #1e1e2e; +} + +::-moz-selection { + background-color: #eeadb7; + color: #1e1e2e; +} + +body { + font-family: 'Adwaita Mono', monospace; + padding-left: 20px; + padding-top: 10px; + margin: 0; + max-width: 1000px; + background-color: #1e1e2e; + color: #eeadb7; +} + +.green, .green::selection, .green::-moz-selection { + color: #5cdd8b; +} + +.red, .red::selection, .red::-moz-selection { + color: #dc3545; +} + +.grey, .grey::selection, .grey::-moz-selection { + color: #dadada; +} + +.service { + width: 400px; + height: 20px; + padding: 10px; + display: flex; + align-items: center; + border-radius: 10px; +} + +.service p { + width: 33% +} + +.status { + display: flex; + width: 66% +} + +.status p { + width: 9px; +} diff --git a/config-example.toml b/config-example.toml new file mode 100644 index 0000000..43e3cdf --- /dev/null +++ b/config-example.toml @@ -0,0 +1,16 @@ +[frontend] +port = 4200 +name = "velping" +pings = 25 + +[pinging] +allow_empty_responses = false +seconds_between_ping = 60 + +[ntfy] +enabled = false +server = "ntfy.sh" +topic = "my_velping_instance" + +[services] +Google = "https://google.com/" diff --git a/index.py b/index.py new file mode 100644 index 0000000..4de9a1b --- /dev/null +++ b/index.py @@ -0,0 +1,65 @@ +from flask import Flask, send_file, redirect, render_template +import threading +import requests +import logging +import time +import toml + +config = toml.load('config.toml') +app = Flask('velping') +logging.disable(logging.CRITICAL) + +uptime = {} + +def ping(service): + while True: + print(f'[I] Pinging {service}') + try: + resp = requests.get(config['services'][service]) + resp.raise_for_status() + + if uptime[service][config['frontend']['pings'] - 1] != 'I' and config['ntfy']['enabled']: + requests.post(f'https://{config['ntfy']['server']}/{config['ntfy']['topic']}', data=f'Service {service} is online') + + uptime[service].pop(0) + uptime[service].append('I') + print(f'[I] Pinging {service} worked!') + except Exception as e: + if 'Remote end closed connection without response' in str(e) and config['pinging']['allow_empty_responses']: + uptime[service].pop(0) + uptime[service].append('I') + print(f'[I] Pinging {service} worked!') + else: + if uptime[service][config['frontend']['pings'] - 1] != 'O' and config['ntfy']['enabled']: + requests.post(f'https://{config['ntfy']['server']}/{config['ntfy']['topic']}', data=f'Service {service} is offline') + + uptime[service].pop(0) + uptime[service].append('O') + print(f'[E] An error happened while pinging for {service}: {e}') + + time.sleep(config['pinging']['seconds_between_ping']) + +for service in config['services']: + uptime[service] = [] + for ping_but_different in range(config['frontend']['pings']): + uptime[service].append('?') + + threading.Thread(target=ping, args=(service,)).start() + +@app.errorhandler(404) +def not_found(error): + return redirect('/', 303) + +@app.errorhandler(500) +def internal_error(error): + return render_template('internal_error.xht', config=config), 500 + +@app.route('/style.css') +def css(): + return send_file('assets/style.css') + +@app.route('/') +def root(): + return render_template('index.xht', config=config, services=config['services'], uptime=uptime), 200 + +app.run(port=config['frontend']['port'], host='::') diff --git a/templates/index.xht b/templates/index.xht new file mode 100644 index 0000000..596d4e6 --- /dev/null +++ b/templates/index.xht @@ -0,0 +1,33 @@ + + + + + + + + {{ config['frontend']['name'] }} + + + + +

{{ config['frontend']['name'] }}

+ + {% for service in services %} +
+

{{ service }}

+
+ {% for ping in uptime[service] %} + {% if ping == "I" %} +

+ {% elif ping == "O" %} +

+ {% else %} +

+ {% endif %} + {% endfor %} +
+
+ {% endfor %} + + + diff --git a/templates/internal_error.xht b/templates/internal_error.xht new file mode 100644 index 0000000..bd3ee2f --- /dev/null +++ b/templates/internal_error.xht @@ -0,0 +1,17 @@ + + + + + + + + internal error - {{ config['frontend']['name'] }} + + + + +

internal error

+

something happened on our end. go home?

+ + + \ No newline at end of file