mirror of
https://github.com/sileht/bird-lg.git
synced 2024-12-22 12:34:42 +01:00
+ custom startpage
This commit is contained in:
parent
6f277c23cb
commit
63a81874a6
4
lg.cfg
4
lg.cfg
|
@ -30,3 +30,7 @@ AS_NUMBER = {
|
|||
ASN_ZONE = "asn.cymru.com"
|
||||
|
||||
SESSION_KEY = '\xd77\xf9\xfa\xc2\xb5\xcd\x85)`+H\x9d\xeeW\\%\xbe/\xbaT\x89\xe8\xa7'
|
||||
|
||||
# specifies an alternative start page template for the "/" route.
|
||||
# If not specified default action is redirection to /summary/%s/ipv4.
|
||||
# DEFAULT_TEMPLATE="/etc/bird-lg/index.html"
|
13
lg.py
13
lg.py
|
@ -38,7 +38,7 @@ from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_c
|
|||
|
||||
|
||||
import pydot
|
||||
from flask import Flask, render_template, jsonify, redirect, session, request, abort, Response, Markup
|
||||
from flask import Flask, render_template, render_template_string, jsonify, redirect, session, request, abort, Response, Markup
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-c', dest='config_file', help='path to config file', default='lg.cfg')
|
||||
args = parser.parse_args()
|
||||
|
@ -188,6 +188,17 @@ def inject_all_host():
|
|||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
if app.config.get("DEFAULT_TEMPLATE", False):
|
||||
# initializes session with first command of commands_dict, first host and ipv4 for rendering layout.html.
|
||||
first_command = next(iter(inject_commands()['commands_dict']))
|
||||
set_session(first_command, "+".join(app.config["PROXY"].keys()), "ipv4", "")
|
||||
|
||||
# usage of open + render_template_string instead of render_template allows
|
||||
# file location outside of template directory.
|
||||
with open(app.config.get("DEFAULT_TEMPLATE"), 'r') as filehandle:
|
||||
filecontent = filehandle.read()
|
||||
return render_template_string(filecontent)
|
||||
|
||||
return redirect("/summary/%s/ipv4" % "+".join(app.config["PROXY"].keys()))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue