# Path: sam/constants.py
# LDAP = {
#     'connection_string': config.get('LDAP', 'connection_string', default='')
# }
# def enable_local_mode():
# def init_urls():
# def find_url(target):
# def get_navbar(lang):
# 
# Path: sam/integrity.py
# def get_table_names(db):
# def get_all_subs(db):
# def get_all_dss(db):
# def check_db_access_MySQL(params):
# def check_db_access_SQLite(params):
# def check_and_fix_db_access(params):
# def check_and_fix_db_access_MySQL(params):
# def check_and_fix_db_access_SQLite(params):
# def check_shared_tables(db):
# def fix_shared_tables(db, missing_tables):
# def fix_UDF_MySQL(db):
# def fix_UDF_SQLite(db):
# def fill_port_table(db):
# def check_default_subscription(db):
# def fix_default_subscription(db, errors):
# def check_subscriptions(db):
# def fix_subscriptions(db, errors):
# def fix_default_rules(db):
# def check_settings(db):
# def fix_settings(db, errors):
# def check_data_sources(db):
# def fix_data_sources(db, errors):
# def check_sessions_table(db):
# def fix_sessions_table(db, is_missing):
# def check_plugins(db):
# def fix_plugins(db, errors):
# def check_integrity(db=None):
# def check_and_fix_integrity(db=None, params=None):


import sys
import os
import operator
import web
from sam import constants
from sam import common
from sam import integrity
from sam import httpserver
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))  # could be executed from any directory


def check_database():
    # Validate the database format
    if not integrity.check_and_fix_integrity():
        exit(1)


def create_session(app):
    # Create the session object
    if web.config.get('_session') is None:
        common.session = web.session.Session(app, common.session_store)
        web.config._session = common.session
    else:
        common.session = web.config._session


def localization_hook():
    default_lang = 'en'  # default language
    lang = None
    path_info = web.ctx.env['PATH_INFO']
    cookie = web.cookies().get("lang")

    # try reading language from URL path

# Path: sam/constants.py
# LDAP = {
#     'connection_string': config.get('LDAP', 'connection_string', default='')
# }
# def enable_local_mode():
# def init_urls():
# def find_url(target):
# def get_navbar(lang):
# 
# Path: sam/integrity.py
# def get_table_names(db):
# def get_all_subs(db):
# def get_all_dss(db):
# def check_db_access_MySQL(params):
# def check_db_access_SQLite(params):
# def check_and_fix_db_access(params):
# def check_and_fix_db_access_MySQL(params):
# def check_and_fix_db_access_SQLite(params):
# def check_shared_tables(db):
# def fix_shared_tables(db, missing_tables):
# def fix_UDF_MySQL(db):
# def fix_UDF_SQLite(db):
# def fill_port_table(db):
# def check_default_subscription(db):
# def fix_default_subscription(db, errors):
# def check_subscriptions(db):
# def fix_subscriptions(db, errors):
# def fix_default_rules(db):
# def check_settings(db):
# def fix_settings(db, errors):
# def check_data_sources(db):
# def fix_data_sources(db, errors):
# def check_sessions_table(db):
# def fix_sessions_table(db, is_missing):
# def check_plugins(db):
# def fix_plugins(db, errors):
# def check_integrity(db=None):
# def check_and_fix_integrity(db=None, params=None):


# Path: sam/server_webserver.py
import sys
import os
import operator
import web
from sam import constants
from sam import common
from sam import integrity
from sam import httpserver

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))  # could be executed from any directory


def check_database():
    # Validate the database format
    if not integrity.check_and_fix_integrity():
        exit(1)


def create_session(app):
    # Create the session object
    if web.config.get('_session') is None:
        common.session = web.session.Session(app, common.session_store)
        web.config._session = common.session
    else:
        common.session = web.config._session


def localization_hook():
    default_lang = 'en'  # default language
    lang = None
    path_info = web.ctx.env['PATH_INFO']
    cookie = web.cookies().get("lang")

    # try reading language from URL path

    if not lang and path_info[1:3] in constants.supported_languages: