From f5f57d76076a8cad6a0f5c5221bcac659c649c22 Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Wed, 4 Aug 2021 19:04:50 -0700 Subject: [PATCH] add limited rule import --- web/app.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/web/app.py b/web/app.py index 561b7d3..7d3d19b 100644 --- a/web/app.py +++ b/web/app.py @@ -1811,6 +1811,50 @@ def create_app(): ''' return render_template('flask_user_layout.html', markup_content = Markup(content)) + @app.route('/import_rules/', methods=['POST', 'GET']) + @login_required + @roles_required('Admin') + def import_rules(server): + if request.args.get('import') == 'true': + try: + imp_dict = ast.literal_eval(request.form.get('rules')) + for e in imp_dict.items(): + b_db = BridgeList.query.filter_by(bridge_name=e[0]).first() + if b_db == None: + bridge_add(e[0], 'Add a description', True, 0) + for i in e[1]: #.items(): + add_system_rule(e[0], i['SYSTEM'], i['TS'], i['TGID'], i['ACTIVE'], i['TIMEOUT'], i['TO_TYPE'], re.sub('\[|\]', '', str(i['ON'])), re.sub('\[|\]', '', str(i['OFF'])), re.sub('\[|\]', '', str(i['RESET'])), server) + content = '''

Sucessfully imported rules (or something else).

+

Redirecting in 3 seconds.

+ ''' + except: + content = '''

Rules import failed.

+

Redirecting in 3 seconds.

+ ''' + else: + content = ''' +

Before importing:

+

1. You must have master, proxy, and peer connections set up prior to importing rules. The names of each master, proxy, or peer must match 'SYSTEM' in your rules.py.

+

2. In rules.py, locate BRIDGES = {...................}. Copy and paste the brackets, { and }, and everything in between into the box below.

+ +
+ + + + + + + + + +

+

 

+

+
+
+''' + return render_template('flask_user_layout.html', markup_content = Markup(content)) + @app.route('/user_tg') def tg_status(): cu = current_user @@ -3097,6 +3141,8 @@ def create_app():

Delete server

+

Import Rules

+

 

Server