mirror of
https://github.com/sileht/bird-lg.git
synced 2024-12-22 12:34:42 +01:00
Use proxy instead for socket redirect
This commit is contained in:
parent
535e06a682
commit
3f4f5a6960
14
README
14
README
|
@ -3,7 +3,15 @@ bird-lg depend on :
|
|||
- python-flask
|
||||
- python-dnspython
|
||||
|
||||
It use TCP socket to talk with bird
|
||||
|
||||
To convert unix socket to tcp-socket you can use:
|
||||
# socat UNIX-CONNECT:/var/run/bird.ctl TCP-LISTEN:9994,reuseaddr,fork,range=XXX.XXX.XXX.XXX/32
|
||||
On all bird nodes:
|
||||
fill the config file lg-proxy.cfg by list all ips that can acces to the proxy
|
||||
and start "python lg-proxy.py"
|
||||
|
||||
|
||||
On frontend:
|
||||
fill config file lg.cfg by list all bird nodes
|
||||
and start "python lg.py"
|
||||
|
||||
|
||||
Each service can by embeded in any webserver by follow regular python-flask configuration
|
||||
|
|
8
lg.cfg
8
lg.cfg
|
@ -1,9 +1,9 @@
|
|||
|
||||
DOMAIN = "tetaneutral.net"
|
||||
|
||||
HOST_MAPPING={
|
||||
"gw": { "ipv4" : 9994, "ipv6": 9996, "traceroute":5000 },
|
||||
"h3": { "ipv4" : 9994, "ipv6": 9996, "traceroute":5000 },
|
||||
}
|
||||
PROXY = {
|
||||
"gw": 5000,
|
||||
"h3": 5000,
|
||||
}
|
||||
|
||||
SESSION_KEY = '\xd77\xf9\xfa\xc2\xb5\xcd\x85)`+H\x9d\xeeW\\%\xbe/\xbaT\x89\xe8\xa7'
|
||||
|
|
40
lg.py
40
lg.py
|
@ -4,7 +4,8 @@ import sys
|
|||
import os
|
||||
import subprocess
|
||||
import re
|
||||
import urllib2
|
||||
from urllib2 import urlopen
|
||||
from urllib import quote
|
||||
|
||||
from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve
|
||||
|
||||
|
@ -52,22 +53,35 @@ def set_session(req_type, hosts, proto, request_args):
|
|||
if not history: session["history"] = {}
|
||||
session["history"][req_type] = req_hist[:10]
|
||||
|
||||
def bird_command(host, proto, command):
|
||||
conf = app.config["HOST_MAPPING"].get(host, None)
|
||||
port = conf.get(proto)
|
||||
if not conf or not port:
|
||||
def bird_command(host, proto, query):
|
||||
return bird_proxy(host, proto, "bird", query)
|
||||
|
||||
def bird_proxy(host, proto, service, query):
|
||||
path = ""
|
||||
if proto == "ipv6": path = service + "6"
|
||||
elif proto == "ipv4": path = service
|
||||
port = app.config["PROXY"].get(host,"")
|
||||
if not port or not path:
|
||||
return False, "Host/Proto not allowed"
|
||||
else:
|
||||
b = BirdSocketSingleton(host, port)
|
||||
return b.cmd(command)
|
||||
url = "http://%s.%s:%d/%s?q=%s" % (host, app.config["DOMAIN"], port, path, quote(query))
|
||||
try:
|
||||
f = urlopen(url)
|
||||
resultat = f.read()
|
||||
app.logger.debug(resultat)
|
||||
status = True # retreive remote status
|
||||
except IOError:
|
||||
resultat = "Failed retreive url: %s" % url
|
||||
status = False
|
||||
return status, resultat
|
||||
|
||||
@app.context_processor
|
||||
def inject_all_host():
|
||||
return dict(all_hosts="+".join(app.config["HOST_MAPPING"].keys()))
|
||||
return dict(all_hosts="+".join(app.config["PROXY"].keys()))
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
return redirect("/summary/%s/ipv4" % "+".join(app.config["HOST_MAPPING"].keys()) )
|
||||
return redirect("/summary/%s/ipv4" % "+".join(app.config["PROXY"].keys()) )
|
||||
|
||||
def error_page(text):
|
||||
return render_template('error.html', data = { "error": text } ), 500
|
||||
|
@ -138,12 +152,8 @@ def traceroute(hosts, proto):
|
|||
|
||||
infos = {}
|
||||
for host in hosts.split("+"):
|
||||
url = "http://%s.%s:%s/traceroute%s?q=%s" % ( host, app.config["DOMAIN"], app.config["HOST_MAPPING"].get(host).get("traceroute","5000"), (proto == "ipv6" and "6" or ""), q)
|
||||
try:
|
||||
f = urllib2.urlopen(url)
|
||||
infos[host] = add_links(f.read())
|
||||
except IOError:
|
||||
infos[host] = "Failed retreive url: %s" % url
|
||||
status, resultat = bird_proxy(host, proto, "traceroute", q)
|
||||
infos[host] = add_links(resultat)
|
||||
return render_template('traceroute.html', infos=infos)
|
||||
|
||||
@app.route("/where/<hosts>/<proto>")
|
||||
|
|
|
@ -128,7 +128,7 @@ $( function() {
|
|||
</ul>
|
||||
<ul class="hosts">
|
||||
<li id="{{all_hosts}}">all</li>
|
||||
{% for host in config.HOST_MAPPING %}
|
||||
{% for host in config.PROXY %}
|
||||
<li id="{{host}}">{{host}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue