mirror of
https://github.com/sileht/bird-lg.git
synced 2024-11-22 06:54:43 +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-flask
|
||||||
- python-dnspython
|
- python-dnspython
|
||||||
|
|
||||||
It use TCP socket to talk with bird
|
|
||||||
|
|
||||||
To convert unix socket to tcp-socket you can use:
|
On all bird nodes:
|
||||||
# socat UNIX-CONNECT:/var/run/bird.ctl TCP-LISTEN:9994,reuseaddr,fork,range=XXX.XXX.XXX.XXX/32
|
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"
|
DOMAIN = "tetaneutral.net"
|
||||||
|
|
||||||
HOST_MAPPING={
|
PROXY = {
|
||||||
"gw": { "ipv4" : 9994, "ipv6": 9996, "traceroute":5000 },
|
"gw": 5000,
|
||||||
"h3": { "ipv4" : 9994, "ipv6": 9996, "traceroute":5000 },
|
"h3": 5000,
|
||||||
}
|
}
|
||||||
|
|
||||||
SESSION_KEY = '\xd77\xf9\xfa\xc2\xb5\xcd\x85)`+H\x9d\xeeW\\%\xbe/\xbaT\x89\xe8\xa7'
|
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 os
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
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
|
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"] = {}
|
if not history: session["history"] = {}
|
||||||
session["history"][req_type] = req_hist[:10]
|
session["history"][req_type] = req_hist[:10]
|
||||||
|
|
||||||
def bird_command(host, proto, command):
|
def bird_command(host, proto, query):
|
||||||
conf = app.config["HOST_MAPPING"].get(host, None)
|
return bird_proxy(host, proto, "bird", query)
|
||||||
port = conf.get(proto)
|
|
||||||
if not conf or not port:
|
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"
|
return False, "Host/Proto not allowed"
|
||||||
else:
|
else:
|
||||||
b = BirdSocketSingleton(host, port)
|
url = "http://%s.%s:%d/%s?q=%s" % (host, app.config["DOMAIN"], port, path, quote(query))
|
||||||
return b.cmd(command)
|
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
|
@app.context_processor
|
||||||
def inject_all_host():
|
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("/")
|
@app.route("/")
|
||||||
def hello():
|
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):
|
def error_page(text):
|
||||||
return render_template('error.html', data = { "error": text } ), 500
|
return render_template('error.html', data = { "error": text } ), 500
|
||||||
|
@ -138,12 +152,8 @@ def traceroute(hosts, proto):
|
||||||
|
|
||||||
infos = {}
|
infos = {}
|
||||||
for host in hosts.split("+"):
|
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)
|
status, resultat = bird_proxy(host, proto, "traceroute", q)
|
||||||
try:
|
infos[host] = add_links(resultat)
|
||||||
f = urllib2.urlopen(url)
|
|
||||||
infos[host] = add_links(f.read())
|
|
||||||
except IOError:
|
|
||||||
infos[host] = "Failed retreive url: %s" % url
|
|
||||||
return render_template('traceroute.html', infos=infos)
|
return render_template('traceroute.html', infos=infos)
|
||||||
|
|
||||||
@app.route("/where/<hosts>/<proto>")
|
@app.route("/where/<hosts>/<proto>")
|
||||||
|
|
|
@ -128,7 +128,7 @@ $( function() {
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="hosts">
|
<ul class="hosts">
|
||||||
<li id="{{all_hosts}}">all</li>
|
<li id="{{all_hosts}}">all</li>
|
||||||
{% for host in config.HOST_MAPPING %}
|
{% for host in config.PROXY %}
|
||||||
<li id="{{host}}">{{host}}</li>
|
<li id="{{host}}">{{host}}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue