mirror of
https://github.com/lalanza808/monero.fail.git
synced 2025-04-18 18:15:48 -04:00
add haproxy config generator for proxying
This commit is contained in:
parent
33a6a9b8a2
commit
0d12e4d30a
@ -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)
|
||||
|
@ -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
|
||||
|
18
xmrnodes/templates/haproxy.html
Normal file
18
xmrnodes/templates/haproxy.html
Normal file
@ -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 %}
|
||||
|
@ -69,7 +69,6 @@
|
||||
</span>
|
||||
</form>
|
||||
</div>
|
||||
<br>
|
||||
{% if nodes %}
|
||||
<div class="xmrnodes">
|
||||
<p class="center">
|
||||
@ -81,6 +80,7 @@
|
||||
</strong>
|
||||
<br><br>
|
||||
{% endif %}
|
||||
<a href="{{ url_for('haproxy', chain=request.args.get('chain'), network=request.args.get('network'), cors=request.args.get('cors'), onion=request.args.get('onion')) }}">Download HAProxy config</a><br /><br />
|
||||
Tracking {{ nodes_all }} {{ nettype }} {{ crypto | capitalize }} nodes in the database.
|
||||
<br>
|
||||
Of those, {{ nodes_unhealthy }} nodes failed their last check-in (unresponsive to ping or over 500 blocks away from highest reported block).
|
||||
|
Loading…
x
Reference in New Issue
Block a user