1
0
Fork 0
mirror of https://github.com/sileht/bird-lg.git synced 2024-11-22 06:54:43 +01:00
bird-lg/lg-proxy.py

57 lines
1.2 KiB
Python
Raw Normal View History

2012-01-26 16:18:58 +01:00
import subprocess
from urllib import unquote
from bird import BirdSocket
from flask import Flask, request, abort
app = Flask(__name__)
app.config.from_pyfile('lg-proxy.cfg')
def check_accesslist():
if app.config["ACCESS_LIST"] and request.remote_addr not in app.config["ACCESS_LIST"]:
abort(401)
@app.route("/traceroute")
@app.route("/traceroute6")
def traceroute():
check_accesslist()
if request.path == '/traceroute6': o= "-6"
else: o = "-4"
query = request.args.get("q","")
query = unquote(query)
2012-01-26 22:57:52 +01:00
command = [ 'traceroute', o, '-A', '-q1', '-w1', query]
2012-01-26 16:18:58 +01:00
result = subprocess.Popen( command , stdout=subprocess.PIPE).communicate()[0].decode('utf-8', 'ignore').replace("\n","<br>")
return result
@app.route("/bird")
@app.route("/bird6")
def bird():
check_accesslist()
if request.path == "/bird": b = BirdSocket(file="/var/run/bird.ctl")
elif request.path == "/bird6": b = BirdSocket(file="/var/run/bird6.ctl")
2012-01-26 17:38:57 +01:00
else: return "No bird socket selected"
2012-01-26 16:18:58 +01:00
query = request.args.get("q","")
query = unquote(query)
status, result = b.cmd(query)
b.close()
2012-01-26 17:38:57 +01:00
# FIXME: use status
return result
2012-01-26 16:18:58 +01:00
if __name__ == "__main__":
app.debug = True
app.run("0.0.0.0")