diff --git a/xmrnodes/app.py b/xmrnodes/app.py
index 46473e4..7c3a313 100644
--- a/xmrnodes/app.py
+++ b/xmrnodes/app.py
@@ -7,7 +7,7 @@ import geoip2.database
import arrow
import requests
from flask import Flask, request, redirect, jsonify
-from flask import render_template, flash
+from flask import render_template, flash, Response
from urllib.parse import urlparse, urlencode
from xmrnodes.helpers import determine_crypto, is_onion, make_request
@@ -99,6 +99,25 @@ def nodes_json():
}
})
+@app.route("/haproxy.cfg")
+def haproxy():
+ crypto = request.args.get('chain') or 'monero'
+ nettype = request.args.get('network') or 'mainnet'
+ cors = request.args.get('cors') or False
+ tor = request.args.get('onion') or False
+ nodes = Node.select().where(
+ Node.validated == True,
+ Node.nettype == nettype,
+ Node.crypto == crypto,
+ Node.is_tor == tor,
+ Node.web_compatible == cors
+ )
+ tpl = render_template("haproxy.html", nodes=nodes)
+ print(tpl)
+ res = Response(tpl)
+ res.headers['Content-Disposition'] = f'attachment; filename="haproxy-{crypto}-{nettype}-cors_{cors}-tor_{tor}.cfg"'
+ return res
+
@app.route("/wow_nodes.json")
def wow_nodes_json():
nodes = Node.select().where(
@@ -314,7 +333,7 @@ def validate():
@app.cli.command("export")
def export():
all_nodes = []
- ts = int(arrow.get().timestamp)
+ ts = int(arrow.get().timestamp())
export_dir = f"{config.DATA_DIR}/export.txt"
export_dir_stamped = f"{config.DATA_DIR}/export-{ts}.txt"
nodes = Node.select().where(Node.validated == True)
diff --git a/xmrnodes/models.py b/xmrnodes/models.py
index 842ab46..6de16ef 100644
--- a/xmrnodes/models.py
+++ b/xmrnodes/models.py
@@ -24,6 +24,10 @@ class Node(Model):
datetime_failed = DateTimeField(default=None, null=True)
fail_reason = CharField(null=True)
+ def get_netloc(self):
+ _url = urlparse(self.url)
+ return _url.netloc
+
def get_failed_checks(self):
hcs = HealthCheck.select().where(HealthCheck.node == self, HealthCheck.health == False)
return hcs
diff --git a/xmrnodes/templates/haproxy.html b/xmrnodes/templates/haproxy.html
new file mode 100644
index 0000000..43a0107
--- /dev/null
+++ b/xmrnodes/templates/haproxy.html
@@ -0,0 +1,18 @@
+defaults
+ mode http
+ timeout client 10s
+ timeout connect 5s
+ timeout server 10s
+ timeout http-request 10s
+
+frontend frontend
+ bind :8080
+ default_backend nodes
+
+backend nodes
+ balance roundrobin
+ option httpchk GET /get_info
+ {% for node in nodes -%}
+ server backend-{{ node.id }} {{ node.get_netloc() }}
+ {% endfor %}
+
diff --git a/xmrnodes/templates/index.html b/xmrnodes/templates/index.html
index 71d74ed..cd3244c 100644
--- a/xmrnodes/templates/index.html
+++ b/xmrnodes/templates/index.html
@@ -69,7 +69,6 @@
-
{% if nodes %}
@@ -81,6 +80,7 @@
{% endif %}
+ Download HAProxy config
Tracking {{ nodes_all }} {{ nettype }} {{ crypto | capitalize }} nodes in the database.
Of those, {{ nodes_unhealthy }} nodes failed their last check-in (unresponsive to ping or over 500 blocks away from highest reported block).