Commit da677b59 authored by janis.streib's avatar janis.streib 🦉
Browse files

Clenaup of python middleware

parent a3c21846
Pipeline #164810 passed with stages
in 9 minutes and 35 seconds
from json import JSONEncoder
from flask import Flask, url_for, jsonify
from flask import Flask
from beaker.middleware import SessionMiddleware
from kitnet.lib.netdb import PostgreSQL
import sys
import os
import inspect
import subprocess
from .model import DBObject, MetaDBObject, SimpleKITUser
import importlib
......@@ -26,7 +24,7 @@ session_opts = {
class ModMetaData(object):
def __init__(self, name, version, contact_email, printable_name, mod_path, gitlab_url=None, search_func=None,
search_opts_func=None, is_tool=False):
self.version = version
self.contact_mail = contact_email
self.gitlab_url = gitlab_url
......@@ -35,7 +33,6 @@ class ModMetaData(object): = name
self.search_func = search_func
self.search_opts_func = search_opts_func if search_func is not None else None
self.is_tool = is_tool
class CustomJSONEncoder(JSONEncoder):
......@@ -62,6 +59,7 @@ class CustomJSONEncoder(JSONEncoder):
class MyApp(Flask):
# Define the WSGI application object
app = MyApp(__name__)
app.json_encoder = CustomJSONEncoder
......@@ -95,10 +93,11 @@ def load_mods():
mod = importlib.import_module(m['mod'])
app.register_blueprint(blueprint=getattr(mod, m['mod'].split('.')[-1]),
url_prefix='{prefix}{url}'.format(prefix='/tools' if mod.METADATA.is_tool else '',
url_prefix='{prefix}{url}'.format(prefix='', url=m['url']))
def finalize_init():
from . import views
This diff is collapsed.
......@@ -2,7 +2,6 @@ from flask import Blueprint
from . import dhcp_leases_model
from net_suite import app, get_git_version, ModMetaData
# we are assuming, that at the time of loading the app is initializes and the config is loaded
bb_name = 'dhcp_leases'
dhcp_leases = Blueprint(bb_name, __name__, template_folder='templates')
......@@ -5,6 +5,7 @@ from . import dhcp_leases_model
from net_suite import db
from net_suite.model import BCD
def get_dhcpleaseDB():
if not hasattr(g, 'dhcpleaseDB'):
g.dhcpleaseDB = dhcp_leases_model.DhcpLeaseDB(database=current_app.config['MINIDHCPVS_DB'],
......@@ -8,6 +8,6 @@ ip_contact = Blueprint(bb_name, __name__, template_folder='templates')
METADATA = ModMetaData(name=bb_name, mod_path=__name__, gitlab_url='',
printable_name='Adressbetreuer kontaktieren', version=get_git_version(__file__),
contact_email='', is_tool=True)
MENU = {METADATA.printable_name: 'ip_contact.main'}
from . import views
......@@ -10,12 +10,12 @@'Loading OUI databse...')
ouis = requests.get('').text.split('\n')
OUI_DB = dict()
for line in ouis:
if not '(hex)' in line:
if '(hex)' not in line:
parts = line.split('(hex)')
OUI_DB[parts[0].strip().lower().replace('-', ':')] = parts[1].strip()
METADATA = ModMetaData(name=bb_name, mod_path=__name__, gitlab_url='',
printable_name='MACFinder', version=get_git_version(__file__),
contact_email='', is_tool=False)
from . import views
<h1>DEBUG: Forward user-data to {{new_target}}?</h1>
<form method="post" action="{{new_target}}">
<input type="hidden" name="redir" value="{{redir}}">
{% for key, value in userinfo.items() %}
<dt>{{ key }}</dt>
<dd>{{ value }}</dd>
<input type="hidden" name="{{key}}" value="{{value}}">
{% endfor %}
<button type="submit">OK</button>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment