def __init__(self): self.LDAP_HOST = config.get('ldap', 'host') self.LDAP_PORT = int(config.get('ldap', 'port')) self.LDAP_PROTO = 'ldaps' if config.getboolean('ldap', 'ssl') else 'ldap' self.LDAP_BIND_METHOD = config.get('ldap', 'bind_method') self.LDAP_BASE = config.get('ldap', 'base') self.LDAP_BIND_DN = config.get('ldap', 'bind_dn') self.LDAP_PASS = config.get('ldap', 'password') self.ID_MAPPING = config.get('ldap', 'id_mapping') self.DISPLAY_MAPPING = config.get('ldap', 'display_mapping') self.OBJECT_CLASS = config.get('ldap', 'object_class') self.REQUIRED_GROUP = config.get('ldap', 'required_group')
def refresh_info(): return jsonify({ 'cpu': lwp.host_cpu_percent(), 'uptime': lwp.host_uptime(), 'disk': lwp.host_disk_usage(partition=config.get('overview', 'partition')) })
import time import socket import subprocess import ConfigParser from flask import Blueprint, request, session, g, redirect, url_for, abort, render_template, flash, jsonify import lwp import lwp.lxclite as lxc from lwp.utils import query_db, if_logged_in, get_bucket_token, hash_passwd, config, cgroup_ext from lwp.views.auth import AUTH # TODO: see if we can move this block somewhere better try: USE_BUCKET = config.getboolean('global', 'buckets') BUCKET_HOST = config.get('buckets', 'buckets_host') BUCKET_PORT = config.get('buckets', 'buckets_port') except ConfigParser.NoOptionError: USE_BUCKET = False print("- Bucket feature disabled") storage_repos = config.items('storage_repository') # Flask module mod = Blueprint('main', __name__) @mod.route('/') @mod.route('/home') @if_logged_in() def home():
import time import socket import subprocess import ConfigParser from flask import Blueprint, request, session, g, redirect, url_for, abort, render_template, flash, jsonify import lwp import lwp.lxclite as lxc from lwp.utils import query_db, if_logged_in, get_bucket_token, hash_passwd, config, cgroup_ext from lwp.views.auth import AUTH # TODO: see if we can move this block somewhere better try: USE_BUCKET = config.getboolean('global', 'buckets') BUCKET_HOST = config.get('buckets', 'buckets_host') BUCKET_PORT = config.get('buckets', 'buckets_port') except ConfigParser.NoOptionError: USE_BUCKET = False print("- Bucket feature disabled") storage_repos = config.items('storage_repository') # Flask module mod = Blueprint('main', __name__) @mod.route('/') @mod.route('/home') @if_logged_in()
import sys from flask import Flask, g from lwp.utils import connect_db, check_session_limit, config from lwp import SESSION_SECRET_FILE from lwp.views import main, auth, api try: SECRET_KEY = open(SESSION_SECRET_FILE, 'r').read() except IOError: print(' * Missing session_secret file, your session will not survive server reboot. Run with --generate-session-secret to generate permanent file.') SECRET_KEY = os.urandom(24) DEBUG = config.getboolean('global', 'debug') DATABASE = config.get('database', 'file') ADDRESS = config.get('global', 'address') PORT = int(config.get('global', 'port')) PREFIX = config.get('global', 'prefix') # Flask app app = Flask('lwp', static_url_path="{0}/static".format(PREFIX)) app.config.from_object(__name__) app.register_blueprint(main.mod, url_prefix=PREFIX) app.register_blueprint(auth.mod, url_prefix=PREFIX) app.register_blueprint(api.mod, url_prefix=PREFIX) if '--profiling' in sys.argv[1:]: from werkzeug.contrib.profiler import ProfilerMiddleware app.config['PROFILE'] = True
def refresh_info(): return jsonify({'cpu': lwp.host_cpu_percent(), 'uptime': lwp.host_uptime(), 'disk': lwp.host_disk_usage(partition=config.get('overview', 'partition'))})
# -*- coding: utf-8 -*- from __future__ import absolute_import, print_function import time from flask import Blueprint, request, session, redirect, url_for, render_template, flash from lwp.utils import query_db, hash_passwd, get_token, config # TODO: see if we can move this block somewhere better try: AUTH = config.get('global', 'auth') print(' * Auth type: ' + AUTH) if AUTH == 'ldap': import ldap LDAP_HOST = config.get('ldap', 'host') LDAP_PORT = int(config.get('ldap', 'port')) LDAP_BASE = config.get('ldap', 'base') LDAP_BIND_DN = config.get('ldap', 'bind_dn') LDAP_PASS = config.get('ldap', 'password') ID_MAPPING = config.get('ldap', 'id_mapping') DISPLAY_MAPPING = config.get('ldap', 'display_mapping') OBJECT_CLASS = config.get('ldap', 'object_class') elif AUTH == 'htpasswd': HTPASSWD_FILE = config.get('htpasswd', 'file') elif AUTH == 'pam': import pam PAM_SERVICE = config.get('pam', 'service') except NameError as err: print(' ! Revert to DB authentication ' + str(err)) AUTH = 'database'
from flask import Flask, g from lwp.utils import connect_db, check_session_limit, config from lwp import SESSION_SECRET_FILE from lwp.views import main, auth, api try: SECRET_KEY = open(SESSION_SECRET_FILE, 'r').read() except IOError: print( ' * Missing session_secret file, your session will not survive server reboot. Run with --generate-session-secret to generate permanent file.' ) SECRET_KEY = os.urandom(24) DEBUG = config.getboolean('global', 'debug') DATABASE = config.get('database', 'file') ADDRESS = config.get('global', 'address') PORT = int(config.get('global', 'port')) PREFIX = config.get('global', 'prefix') # Flask app app = Flask('lwp', static_url_path="{0}/static".format(PREFIX)) app.config.from_object(__name__) app.register_blueprint(main.mod, url_prefix=PREFIX) app.register_blueprint(auth.mod, url_prefix=PREFIX) app.register_blueprint(api.mod, url_prefix=PREFIX) if '--profiling' in sys.argv[1:]: from werkzeug.contrib.profiler import ProfilerMiddleware app.config['PROFILE'] = True app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
def __init__(self): self.HTPASSWD_FILE = config.get('htpasswd', 'file')
# -*- coding: utf-8 -*- from __future__ import absolute_import, print_function import time from flask import Blueprint, request, session, redirect, url_for, render_template, flash from lwp.utils import get_token, config import lwp.authenticators as auth AUTH = config.get('global', 'auth') AUTH_INSTANCE = auth.get_authenticator(AUTH) print(' * Auth type: ' + AUTH) # Flask module mod = Blueprint('auth', __name__) @mod.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': request_username = request.form['username'] request_passwd = request.form['password'] current_url = request.form['url'] user = AUTH_INSTANCE.authenticate(request_username, request_passwd) if user: session['logged_in'] = True
# -*- coding: utf-8 -*- from __future__ import absolute_import, print_function import time from flask import Blueprint, request, session, redirect, url_for, render_template, flash from lwp.utils import query_db, hash_passwd, get_token, config # TODO: see if we can move this block somewhere better try: AUTH = config.get('global', 'auth') print(' * Auth type: ' + AUTH) if AUTH == 'ldap': import ldap LDAP_HOST = config.get('ldap', 'host') LDAP_PORT = int(config.get('ldap', 'port')) LDAP_BASE = config.get('ldap', 'base') LDAP_BIND_DN = config.get('ldap', 'bind_dn') LDAP_PASS = config.get('ldap', 'password') ID_MAPPING = config.get('ldap', 'id_mapping') DISPLAY_MAPPING = config.get('ldap', 'display_mapping') OBJECT_CLASS = config.get('ldap', 'object_class') elif AUTH == 'htpasswd': HTPASSWD_FILE = config.get('htpasswd', 'file') except NameError as err: print(' ! Revert to DB authentication ' + str(err)) AUTH = 'database'
# -*- coding: utf-8 -*- from __future__ import absolute_import, print_function import time from flask import Blueprint, request, session, redirect, url_for, render_template, flash from lwp.utils import get_token, config import lwp.authenticators as auth AUTH = config.get('global', 'auth') AUTH_INSTANCE = auth.get_authenticator(AUTH) print(' * Auth type: ' + AUTH) # Flask module mod = Blueprint('auth', __name__) @mod.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': request_username = request.form['username'] request_passwd = request.form['password'] current_url = request.form['url'] user = AUTH_INSTANCE.authenticate(request_username, request_passwd) if user:
if "--generate-session-secret" in sys.argv[1:]: key = os.urandom(24) with os.fdopen(os.open(SESSION_SECRET_FILE, os.O_WRONLY | os.O_CREAT, 0644), "w") as handle: handle.write(key) exit(0) try: SECRET_KEY = open(SESSION_SECRET_FILE, "r").read() except IOError: print( " * Missing session_secret file, your session will not survive server reboot. Run with --generate-session-secret to generate permanent file." ) SECRET_KEY = os.urandom(24) DEBUG = config.getboolean("global", "debug") DATABASE = config.get("database", "file") ADDRESS = config.get("global", "address") PORT = int(config.get("global", "port")) PREFIX = config.get("global", "prefix") # Flask app app = Flask("lwp", static_url_path="{0}/static".format(PREFIX)) app.config.from_object(__name__) app.register_blueprint(main.mod, url_prefix=PREFIX) app.register_blueprint(auth.mod, url_prefix=PREFIX) app.register_blueprint(api.mod, url_prefix=PREFIX) if "--profiling" in sys.argv[1:]: from werkzeug.contrib.profiler import ProfilerMiddleware