# Path: toughwlan/models.py
# def get_metadata(db_engine):
# class SystemSession(DeclarativeBase):
# class SystemCache(DeclarativeBase):
# class TrwOperator(DeclarativeBase):
# class TrwOperatorRule(DeclarativeBase):
# class TrwParam(DeclarativeBase):
# class TrwIsp(DeclarativeBase):
# class TrwIspService(DeclarativeBase):
# class TrwBas(DeclarativeBase):
# class TrwDomain(DeclarativeBase):
# class TrwDomainAttr(DeclarativeBase):
# class TrwSsid(DeclarativeBase):
# class TrwRadius(DeclarativeBase):
# class TrwTemplate(DeclarativeBase):
# class TrwOperateLog(DeclarativeBase):
# class TrwOSTypes(DeclarativeBase):
# 
# Path: toughwlan/manage/settings.py
# def redis_conf(config):
#     eredis_url = os.environ.get("REDIS_URL")
#     eredis_port = os.environ.get("REDIS_PORT")
#     eredis_pwd = os.environ.get("REDIS_PWD")
#     eredis_db = os.environ.get("REDIS_DB")
# 
#     is_update = any([eredis_url,eredis_port,eredis_pwd,eredis_db])
# 
#     if eredis_url:
#         config['redis']['host'] = eredis_url
#     if eredis_port:
#         config['redis']['port'] = int(eredis_port)
#     if eredis_pwd:
#         config['redis']['passwd'] = eredis_pwd 
#     if eredis_db:
#         config['redis']['db'] = int(eredis_db)
#     if is_update:
#         config.save()
# 
#     return config['redis']


import sys
import os
import time
import cyclone.web
import toughwlan
from twisted.python import log
from twisted.internet import reactor
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
from mako.lookup import TemplateLookup
from sqlalchemy.orm import scoped_session, sessionmaker
from toughlib import utils
from toughlib import logger
from toughwlan import models
from toughwlan.manage.settings import redis_conf
from toughlib.dbengine import get_engine
from toughlib.permit import permit, load_handlers
from toughlib import redis_cache
from toughlib import redis_session
from toughlib.db_backup import DBBackup
            debug=self.config.system.debug,
            xheaders=True,
        )

        self.cache = CacheManager(**parse_cache_config_options({
            'cache.type': 'file',
            'cache.data_dir': '/tmp/cache/data',
            'cache.lock_dir': '/tmp/cache/lock'
        }))

        self.tp_lookup = TemplateLookup(directories=[settings['template_path']],
                                        default_filters=['decode.utf8'],
                                        input_encoding='utf-8',
                                        output_encoding='utf-8',
                                        encoding_errors='replace',
                                        module_directory="/tmp/toughwlan")

        self.db_engine = dbengine
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))

        redisconf = redis_conf(config)
        self.session_manager = redis_session.SessionManager(redisconf,settings["cookie_secret"], 600)
        self.mcache = redis_cache.CacheManager(redisconf,cache_name='ToughWlanWeb-%s'%os.getpid())
        self.mcache.print_hit_stat(10)

        self.db_backup = DBBackup(models.get_metadata(self.db_engine), excludes=[
            'trw_online','system_session','system_cache'])

        self.aes = utils.AESCipher(key=self.config.system.secret)


# Path: toughwlan/models.py
# def get_metadata(db_engine):
# class SystemSession(DeclarativeBase):
# class SystemCache(DeclarativeBase):
# class TrwOperator(DeclarativeBase):
# class TrwOperatorRule(DeclarativeBase):
# class TrwParam(DeclarativeBase):
# class TrwIsp(DeclarativeBase):
# class TrwIspService(DeclarativeBase):
# class TrwBas(DeclarativeBase):
# class TrwDomain(DeclarativeBase):
# class TrwDomainAttr(DeclarativeBase):
# class TrwSsid(DeclarativeBase):
# class TrwRadius(DeclarativeBase):
# class TrwTemplate(DeclarativeBase):
# class TrwOperateLog(DeclarativeBase):
# class TrwOSTypes(DeclarativeBase):
# 
# Path: toughwlan/manage/settings.py
# def redis_conf(config):
#     eredis_url = os.environ.get("REDIS_URL")
#     eredis_port = os.environ.get("REDIS_PORT")
#     eredis_pwd = os.environ.get("REDIS_PWD")
#     eredis_db = os.environ.get("REDIS_DB")
# 
#     is_update = any([eredis_url,eredis_port,eredis_pwd,eredis_db])
# 
#     if eredis_url:
#         config['redis']['host'] = eredis_url
#     if eredis_port:
#         config['redis']['port'] = int(eredis_port)
#     if eredis_pwd:
#         config['redis']['passwd'] = eredis_pwd 
#     if eredis_db:
#         config['redis']['db'] = int(eredis_db)
#     if is_update:
#         config.save()
# 
#     return config['redis']


# Path: toughwlan/manage/httpd.py
import sys
import os
import time
import cyclone.web
import toughwlan
from twisted.python import log
from twisted.internet import reactor
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
from mako.lookup import TemplateLookup
from sqlalchemy.orm import scoped_session, sessionmaker
from toughlib import utils
from toughlib import logger
from toughwlan import models
from toughwlan.manage.settings import redis_conf
from toughlib.dbengine import get_engine
from toughlib.permit import permit, load_handlers
from toughlib import redis_cache
from toughlib import redis_session
from toughlib.db_backup import DBBackup

            debug=self.config.system.debug,
            xheaders=True,
        )

        self.cache = CacheManager(**parse_cache_config_options({
            'cache.type': 'file',
            'cache.data_dir': '/tmp/cache/data',
            'cache.lock_dir': '/tmp/cache/lock'
        }))

        self.tp_lookup = TemplateLookup(directories=[settings['template_path']],
                                        default_filters=['decode.utf8'],
                                        input_encoding='utf-8',
                                        output_encoding='utf-8',
                                        encoding_errors='replace',
                                        module_directory="/tmp/toughwlan")

        self.db_engine = dbengine
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))

        redisconf = redis_conf(config)
        self.session_manager = redis_session.SessionManager(redisconf,settings["cookie_secret"], 600)
        self.mcache = redis_cache.CacheManager(redisconf,cache_name='ToughWlanWeb-%s'%os.getpid())
        self.mcache.print_hit_stat(10)

        self.db_backup = DBBackup(models.get_metadata(self.db_engine), excludes=[
            'trw_online','system_session','system_cache'])

        self.aes = utils.AESCipher(key=self.config.system.secret)


        permit.add_route(cyclone.web.StaticFileHandler,