def get(p): # get host and index from the global config h = tools.get_conf(p['host'], p['navigation']['id'], 'host', 'http://localhost:9200') n = tools.get_conf(p['host'], p['navigation']['id'], 'index', '') return { 'name': get_conf(h, n, 'name', ''), 'description': get_conf(h, n, 'description', ''), 'host': h, 'index': n, 'upload_dir': get_conf(h, n, 'upload_dir', os.path.join( app.config.get('BASE_DIR'), 'uploads' ) ), 'allowed_exts': get_conf(h, n, 'allowed_exts',''), 'page_size': get_conf(h, n, 'page_size', '10'), 'query': get_conf(h, n, 'query', '*'), 'sort_field': get_conf(h, n, 'sort_field', '_score'), 'sort_dir': get_conf(h, n, 'sort_dir', 'desc'), 'top': get_conf(h, n, 'top', ''), 'footer': get_conf(h, n, 'footer', ''), 'side': get_conf(h, n, 'side', ''), 'content_header': get_conf(h, n, 'content_header', ''), 'content_footer': get_conf(h, n, 'content_footer', ''), 'intro': get_conf(h, n, 'intro', ''), 'search_query': get_conf(h, n, 'search_query', ''), 'search_item_template': get_conf(h, n, 'search_item_template', ''), 'keep_history': get_conf(h, n, 'keep_history', 'Yes'), }
def authorize(p): # get operation/mode string if not p['operation']: auth_key = 'search/' else: auth_key = p['operation'] + '/' if len(p['nav']) > 3 and p['nav'][3] \ and p['operation'] != "permission" \ and p['operation'] != "search" \ and p['operation'] != "filter" \ and p['operation'] != "file": auth_key += p['nav'][3] if auth_key in p['allowed_operation']: return True # if auth method is none then show auth = tools.get_conf(p['host'], '-1', 'auth', '') if auth == 'None' or not auth: return True # super user can have access admins = tools.get_conf(p['host'], '-1', 'admins', '') if p['login'] in admins: return True return False
def authorize(p): # if auth method is none then show auth = tools.get_conf(p['host'], '-1', 'auth', '') if auth == 'None' or not auth: return True # only super user can have access admins = tools.get_conf(p['host'], '-1', 'admins', '') if p['login'] in admins: return True return False
def set(p): # get host and index from the global config h = tools.get_conf(p['host'], p['navigation']['id'], 'host', 'http://localhost:9200') n = tools.get_conf(p['host'], p['navigation']['id'], 'index', '') set_conf(h, n, 'name', tools.get('name')) set_conf(h, n, 'description', tools.get('description')) set_conf(h, n, 'upload_dir', tools.get('upload_dir')) set_conf(h, n, 'allowed_exts', tools.get('allowed_exts')) set_conf(h, n, 'page_size', tools.get('page_size')) set_conf(h, n, 'query', tools.get('query')) set_conf(h, n, 'sort_field', tools.get('sort_field')) set_conf(h, n, 'sort_dir', tools.get('sort_dir')) set_conf(h, n, 'keep_history', tools.get('keep_history'))
def post(p): # get login Process login_modules = get_login_modules(p) # try all login process until succeeds for login in login_modules: # find which auth module to use path = "web.modules.auth.services.{}".format( tools.get_conf(p['host'], '-1', 'auth', 'LDAP')) mod = importlib.import_module(path) if mod.authenticate(login['configuration'], tools.get('login'), tools.get('password')): # when authentication is successful # remember me if tools.get('remember'): # session will live for 31 days session.permanent = True else: session.permanent = False # save user_id in session session['user'] = tools.get('login') return tools.redirect(get_return_url()) # ending up here means login failed p['message'] = "Login Failed. Check your login name and password." return render_template("auth/default.html", p=p)
def send(p): h = p['host']; n = p['navigation']['id']; gmail_id = tools.get_conf(h, n, 'gmail_id', '') gmail_pw = tools.get_conf(h, n, 'gmail_pw', '') # transform header and message header = jinja.render(p['notification'].get('header'), p) message = jinja.render(p['notification'].get('message'), p) recipients = list(set(p['notification'].get('recipients'))) gmail.send( gmail_id, gmail_pw, recipients, header, message ) return True
def authorize(p): # check which permission the user has if not p['operation']: p['operation'] = 'default' if p['operation'] == 'config': p['operation'] = 'edit' if p['operation'] in p['allowed_operation']: return True # if auth method is none then show auth = tools.get_conf(p['host'], '-1', 'auth', '') if auth == 'None' or not auth: return True # super user can have access admins = tools.get_conf(p['host'], '-1', 'admins', '') if p['login'] in admins: return True return False
def get(p): if request.method == "POST": # save login html tools.set_conf(p['host'], p['navigation']['id'], 'login_html', request.form['login_html']) # return tools.redirect(request.referrer) # get login html p['login_html'] = tools.get_conf(p['host'], p['navigation']['id'], 'login_html', '') return render_template("auth/admin.html", p=p)
def get(p): if request.method == "POST": return post(p) # Form welcome message if user is already logged in if session.get("user"): p['message'] = "Welcome, {}".format(session.get('user')) # render custom login page p['login_html'] = tools.get_conf(p['host'], p['navigation']['id'], 'login_html', '') # redirect url p['return_url'] = tools.get('url') return render_template("auth/default.html", p=p)
def get(p): if request.method == "POST": # save dashboard tools.set_conf(p['host'], p['navigation']['id'], "dashboard", request.form["dashboard"]) # get dashboard template from the configuration p['dashboard'] = tools.get_conf(p["host"], p["navigation"]["id"], "dashboard") if not p['dashboard']: # use default template when nothing is configured p['dashboard'] = tools.read_file("web/templates/dashboard/empty.html", p['base_dir']) return render_template("dashboard/edit.html", p=p)
def get_conf(h, n): conf = { 'gmail_id': tools.get_conf(h, n, 'gmail_id', ''), 'gmail_pw': tools.get_conf(h, n, 'gmail_pw', '') } return conf
def get_conf(host): conf = { 'gmail_id': tools.get_conf(host, '-1', 'gmail_id', ''), 'gmail_pw': tools.get_conf(host, '-1', 'gmail_pw', '') } return conf
def get(p): # Load Dashboard from the configuration dashboard = tools.get_conf(p["host"], p["navigation"]["id"], "dashboard") if dashboard: return render_template(app.jinja_env.from_string(dashboard), p=p) return render_template("dashboard/empty.html", p=p)
def get_all_conf(host): conf = {} conf['title'] = tools.get_conf(host, '-1', 'title', '') conf['script'] = tools.get_conf(host, '-1', 'script', '') return conf
def get_all_conf(host): conf = {} conf['admins'] = tools.get_conf(host, '-1', 'admins', '') conf['safe_network'] = tools.get_conf(host, '-1', 'safe_network', '') return conf