From 70e7782918f7a2330a7b312f91fca5585353a6ec Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 19 Jul 2025 11:31:00 +0100 Subject: [PATCH] extra url modifications --- app.py | 28 ++++++ templates/config_dashboard.html | 156 +++++++++++++++++++++++++++----- 2 files changed, 159 insertions(+), 25 deletions(-) diff --git a/app.py b/app.py index bbbf66a..2d8a78e 100644 --- a/app.py +++ b/app.py @@ -359,6 +359,34 @@ def proxy_dns(): return jsonify({"error": str(e)}), 502 +@app.route('/extra_urls', methods=['GET', 'POST', 'DELETE']) +def proxy_extra_urls(): + """Proxies extra URL management requests to the backend.""" + if not session.get("config_logged_in"): + return jsonify({'error': 'Unauthorized'}), 401 + + backend_url = f"{app.config['BACKEND_URL']}/extra_urls" + credentials = base64.b64decode(session["auth_credentials"]).decode() + username, password = credentials.split(":", 1) + auth = requests.auth.HTTPBasicAuth(username, password) + + try: + if request.method == 'GET': + response = requests.get(backend_url, auth=auth) + elif request.method == 'POST': + response = requests.post(backend_url, auth=auth, json=request.get_json()) + if response.ok: + cache.clear() + elif request.method == 'DELETE': + response = requests.delete(backend_url, auth=auth, json=request.get_json()) + if response.ok: + cache.clear() + + return Response(response.content, status=response.status_code, mimetype=response.headers['Content-Type']) + except requests.exceptions.RequestException as e: + return jsonify({"error": str(e)}), 502 + + if __name__ == "__main__": app.run( debug=app.config["DEBUG"], diff --git a/templates/config_dashboard.html b/templates/config_dashboard.html index 50d46b6..7f6ffe3 100644 --- a/templates/config_dashboard.html +++ b/templates/config_dashboard.html @@ -3,35 +3,78 @@ {% block title %}Config Dashboard{% endblock %} {% block content %} -
-

Configuration Dashboard

-

Welcome to the configuration page.

- - +
+

Configuration Dashboard

-
-
- DNS Manager -
-
-
- -
- +
+
+
+
+ Actions +
+
+ + +
+
+
+
+ +
+
+
+
+ DNS Manager +
+
+
+ +
+ +
+
+ + + + + + + + + + +
DNS EntryActions
+
+
+
+
+
+
+
+
+ Extra URLs Manager +
+
+
+ +
+ +
+
+ + + + + + + + + + +
Extra URLActions
- - - - - - - - - - -
DNS EntryActions
{% endblock %} @@ -123,6 +166,69 @@ addDnsBtn.addEventListener('click', addDnsEntry); fetchDnsList(); + // Extra URLs Manager + const extraUrlsTableBody = document.getElementById('extra-urls-table-body'); + const addExtraUrlBtn = document.getElementById('add-extra-url-btn'); + const extraUrlInput = document.getElementById('extra-url-input'); + + function fetchExtraUrlsList() { + fetch("{{ url_for('proxy_extra_urls') }}") + .then(response => response.json()) + .then(data => { + extraUrlsTableBody.innerHTML = ''; + if (data.length === 0) { + const row = extraUrlsTableBody.insertRow(); + const cell = row.insertCell(); + cell.colSpan = 2; + cell.textContent = 'No extra URLs found.'; + cell.classList.add('text-center'); + } else { + data.forEach(entry => { + const row = extraUrlsTableBody.insertRow(); + const entryCell = row.insertCell(); + entryCell.textContent = entry; + const actionCell = row.insertCell(); + const removeBtn = document.createElement('button'); + removeBtn.className = 'btn btn-danger btn-sm'; + removeBtn.textContent = 'Delete'; + removeBtn.addEventListener('click', () => removeExtraUrl(entry)); + actionCell.appendChild(removeBtn); + }); + } + }); + } + + function addExtraUrl() { + const extraUrl = extraUrlInput.value.trim(); + if (extraUrl) { + fetch("{{ url_for('proxy_extra_urls') }}", { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ extra_url: extraUrl }) + }).then(() => { + extraUrlInput.value = ''; + fetchExtraUrlsList(); + }); + } + } + + function removeExtraUrl(extraUrl) { + fetch("{{ url_for('proxy_extra_urls') }}", { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ extra_url: extraUrl }) + }).then(() => { + fetchExtraUrlsList(); + }); + } + + addExtraUrlBtn.addEventListener('click', addExtraUrl); + fetchExtraUrlsList(); + // Other buttons document.getElementById('send-test-notification-btn').addEventListener('click', function() { fetch('{{ url_for("send_test_notification") }}', {