1
0
Fork 0
mirror of https://github.com/sileht/bird-lg.git synced 2024-11-26 00:34:42 +01:00

Merge remote-tracking branch 'zorun/master'

This commit is contained in:
Mehdi Abaakouk 2014-03-18 14:09:36 +01:00
commit af2c305049
5 changed files with 45 additions and 12 deletions

8
lg.cfg
View file

@ -5,6 +5,9 @@ LOG_LEVEL="WARNING"
DOMAIN = "tetaneutral.net" DOMAIN = "tetaneutral.net"
BIND_IP = "0.0.0.0"
BIND_PORT = 5000
PROXY = { PROXY = {
"gw": 5000, "gw": 5000,
"h3": 5000, "h3": 5000,
@ -21,4 +24,9 @@ AS_NUMBER = {
"h3" : "197422" "h3" : "197422"
} }
#WHOIS_SERVER = "whois.foo.bar"
# DNS zone to query for ASN -> name mapping
ASN_ZONE = "asn.cymru.com"
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'

23
lg.py
View file

@ -29,7 +29,7 @@ from urllib import quote, unquote
import json import json
import random import random
from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_cache_pickle, load_cache_pickle, get_asn_from_as, unescape from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_cache_pickle, load_cache_pickle, unescape
#from xml.sax.saxutils import escape #from xml.sax.saxutils import escape
@ -46,6 +46,15 @@ file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
app.logger.addHandler(file_handler) app.logger.addHandler(file_handler)
def get_asn_from_as(n):
asn_zone = app.config.get("ASN_ZONE", "asn.cymru.com")
try:
data = resolve("AS%s.%s" % (n, asn_zone) ,"TXT").replace("'","").replace('"','')
except:
return " "*5
return [ field.strip() for field in data.split("|") ]
def add_links(text): def add_links(text):
"""Browser a string and replace ipv4, ipv6, as number, with a """Browser a string and replace ipv4, ipv6, as number, with a
whois link """ whois link """
@ -96,7 +105,10 @@ def set_session(request_type, hosts, proto, request_args):
def whois_command(query): def whois_command(query):
return subprocess.Popen(['whois', query], stdout=subprocess.PIPE).communicate()[0].decode('utf-8', 'ignore') server = []
if app.config.get("WHOIS_SERVER", ""):
server = [ "-h", app.config.get("WHOIS_SERVER") ]
return subprocess.Popen(['whois'] + server + [query], stdout=subprocess.PIPE).communicate()[0].decode('utf-8', 'ignore')
def bird_command(host, proto, query): def bird_command(host, proto, query):
@ -458,7 +470,10 @@ def show_bgpmap():
add_node(_as, fillcolor=(first and "#F5A9A9" or "white")) add_node(_as, fillcolor=(first and "#F5A9A9" or "white"))
edge = add_edge(nodes[previous_as], nodes[_as] , label=hop_label, fontsize="7") if hop_label:
edge = add_edge(nodes[previous_as], nodes[_as], label=hop_label, fontsize="7")
else:
edge = add_edge(nodes[previous_as], nodes[_as], fontsize="7")
hop_label = "" hop_label = ""
@ -605,4 +620,4 @@ def show_route(request_type, hosts, proto):
if __name__ == "__main__": if __name__ == "__main__":
app.run("0.0.0.0") app.run(app.config.get("BIND_IP", "0.0.0.0"), app.config.get("BIND_PORT", 5000))

View file

@ -20,6 +20,7 @@
### ###
import sys
import logging import logging
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
from logging import FileHandler from logging import FileHandler
@ -56,21 +57,34 @@ def check_accesslist():
def traceroute(): def traceroute():
check_accesslist() check_accesslist()
if sys.platform.startswith('freebsd') or sys.platform.startswith('netbsd') or sys.platform.startswith('openbsd'):
traceroute4 = [ 'traceroute' ]
traceroute6 = [ 'traceroute6' ]
else: # For Linux
traceroute4 = [ 'traceroute', '-4' ]
traceroute6 = [ 'traceroute', '-6' ]
src = [] src = []
if request.path == '/traceroute6': if request.path == '/traceroute6':
o = "-6" traceroute = traceroute6
if app.config.get("IPV6_SOURCE",""): if app.config.get("IPV6_SOURCE",""):
src = [ "-s", app.config.get("IPV6_SOURCE") ] src = [ "-s", app.config.get("IPV6_SOURCE") ]
else: else:
o = "-4" traceroute = traceroute4
if app.config.get("IPV4_SOURCE",""): if app.config.get("IPV4_SOURCE",""):
src = [ "-s", app.config.get("IPV4_SOURCE") ] src = [ "-s", app.config.get("IPV4_SOURCE") ]
query = request.args.get("q","") query = request.args.get("q","")
query = unquote(query) query = unquote(query)
command = [ 'traceroute' , o ] + src + [ '-A', '-q1', '-N32', '-w1', '-m15', query ] if sys.platform.startswith('freebsd') or sys.platform.startswith('netbsd'):
options = [ '-a', '-q1', '-w1', '-m15' ]
elif sys.platform.startswith('openbsd'):
options = [ '-A', '-q1', '-w1', '-m15' ]
else: # For Linux
options = [ '-A', '-q1', '-N32', '-w1', '-m15' ]
command = traceroute + src + options + [ query ]
result = subprocess.Popen( command , stdout=subprocess.PIPE).communicate()[0].decode('utf-8', 'ignore').replace("\n","<br>") result = subprocess.Popen( command , stdout=subprocess.PIPE).communicate()[0].decode('utf-8', 'ignore').replace("\n","<br>")
return result return result

View file

@ -1,6 +1,6 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<title>Tetaneutral.net looking glass</title> <title>{{config.DOMAIN|capitalize}} looking glass</title>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/bootstrap.min.css') }}"> <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/bootstrap.min.css') }}">

View file

@ -27,10 +27,6 @@ import xml.parsers.expat
def resolve(n, q): def resolve(n, q):
return str(resolver.query(n,q)[0]) return str(resolver.query(n,q)[0])
def get_asn_from_as(n):
data = resolve("AS%s.asn.cymru.com" % n ,"TXT").replace("'","").replace('"','')
return [ field.strip() for field in data.split("|") ]
def mask_is_valid(n): def mask_is_valid(n):
if not n: if not n:
return True return True