from werkzeug.middleware.proxy_fix import ProxyFix import logging import os root_dir = os.path.abspath(os.path.dirname(__file__)) DEFAULT_DATA_DIR = os.path.join('/mnt/nopaque') DEFAULT_DB_PORT = '5432' DEFAULT_DEBUG = 'False' DEFAULT_LOG_DATE_FORMAT = '%Y-%m-%d %H:%M:%S' DEFAULT_LOG_FILE = os.path.join(root_dir, 'nopaque.log') DEFAULT_LOG_FORMAT = ('[%(asctime)s] %(levelname)s in %(pathname)s ' '(function: %(funcName)s, line: %(lineno)d): ' '%(message)s') DEFAULT_LOG_LEVEL = 'ERROR' DEFAULT_SMTP_USE_SSL = 'False' DEFAULT_SMTP_USE_TLS = 'False' DEFAULT_NUM_PROXIES = '0' DEFAULT_PROTOCOL = 'http' DEFAULT_REMEMBER_COOKIE_HTTPONLY = 'True' DEFAULT_REMEMBER_COOKIE_SECURE = 'False' DEFAULT_SECRET_KEY = 'hard to guess string' DEFAULT_SESSION_COOKIE_SECURE = 'False' class Config: ''' ### Database ### ''' DB_HOST = os.environ.get('NOPAQUE_DB_HOST') DB_NAME = os.environ.get('NOPAQUE_DB_NAME') DB_PASSWORD = os.environ.get('NOPAQUE_DB_PASSWORD') DB_PORT = os.environ.get('NOPAQUE_DB_PORT', DEFAULT_DB_PORT) DB_USERNAME = os.environ.get('NOPAQUE_DB_USERNAME') SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@{}:{}/{}'.format( DB_USERNAME, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME) SQLALCHEMY_RECORD_QUERIES = True SQLALCHEMY_TRACK_MODIFICATIONS = False ''' ### Email ### ''' MAIL_DEFAULT_SENDER = os.environ.get('NOPAQUE_SMTP_DEFAULT_SENDER') MAIL_PASSWORD = os.environ.get('NOPAQUE_SMTP_PASSWORD') MAIL_PORT = os.environ.get('NOPAQUE_SMTP_PORT') MAIL_SERVER = os.environ.get('NOPAQUE_SMTP_SERVER') MAIL_USERNAME = os.environ.get('NOPAQUE_SMTP_USERNAME') MAIL_USE_SSL = os.environ.get('NOPAQUE_SMTP_USE_SSL', DEFAULT_SMTP_USE_SSL).lower() == 'true' MAIL_USE_TLS = os.environ.get('NOPAQUE_SMTP_USE_TLS', DEFAULT_SMTP_USE_TLS).lower() == 'true' ''' ### General ### ''' ADMIN_EMAIL_ADRESS = os.environ.get('NOPAQUE_ADMIN_EMAIL_ADRESS') CONTACT_EMAIL_ADRESS = os.environ.get('NOPAQUE_CONTACT_EMAIL_ADRESS') DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', DEFAULT_DATA_DIR) DEBUG = os.environ.get('NOPAQUE_DEBUG', DEFAULT_DEBUG).lower() == 'true' NUM_PROXIES = int(os.environ.get('NOPAQUE_NUM_PROXIES', DEFAULT_NUM_PROXIES)) PROTOCOL = os.environ.get('NOPAQUE_PROTOCOL', DEFAULT_PROTOCOL) REMEMBER_COOKIE_HTTPONLY = os.environ.get( 'NOPAQUE_REMEMBER_COOKIE_HTTPONLY', DEFAULT_REMEMBER_COOKIE_HTTPONLY ).lower() == 'true' REMEMBER_COOKIE_SECURE = os.environ.get( 'NOPAQUE_REMEMBER_COOKIE_SECURE', DEFAULT_REMEMBER_COOKIE_SECURE ).lower() == 'true' SECRET_KEY = os.environ.get('RECIPY_SECRET_KEY', DEFAULT_SECRET_KEY) SESSION_COOKIE_SECURE = os.environ.get( 'NOPAQUE_SESSION_COOKIE_SECURE', DEFAULT_SESSION_COOKIE_SECURE ).lower() == 'true' ''' ### Logging ### ''' LOG_DATE_FORMAT = os.environ.get('NOPAQUE_LOG_DATE_FORMAT', DEFAULT_LOG_DATE_FORMAT) LOG_FILE = os.environ.get('NOPAQUE_LOG_FILE', DEFAULT_LOG_FILE) LOG_FORMAT = os.environ.get('NOPAQUE_LOG_FORMAT', DEFAULT_LOG_FORMAT) LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL', DEFAULT_LOG_LEVEL) ''' ### Message queue ### ''' MQ_HOST = os.environ.get('NOPAQUE_MQ_HOST') MQ_PORT = os.environ.get('NOPAQUE_MQ_PORT') MQ_TYPE = os.environ.get('NOPAQUE_MQ_TYPE') SOCKETIO_MESSAGE_QUEUE_URI = \ '{}://{}:{}/'.format(MQ_TYPE, MQ_HOST, MQ_PORT) def init_app(self, app): # Configure logging according to the corresponding (LOG_*) config # entries logging.basicConfig(datefmt=self.LOG_DATE_FORMAT, filename=self.LOG_FILE, format=self.LOG_FORMAT, level=self.LOG_LEVEL) # Apply the ProxyFix middleware if nopaque is running behind reverse # proxies. (NUM_PROXIES indicates the number of reverse proxies running # in front of nopaque) if self.NUM_PROXIES > 0: app.wsgi_app = ProxyFix(app.wsgi_app, x_for=self.NUM_PROXIES, x_host=self.NUM_PROXIES, x_port=self.NUM_PROXIES, x_proto=self.NUM_PROXIES)