diff --git a/runtime/Server.cpp b/runtime/Server.cpp index 40fc414c..8fd2cadb 100644 --- a/runtime/Server.cpp +++ b/runtime/Server.cpp @@ -272,9 +272,10 @@ void Server::run() return; } - // Set the port number + // Set the port number and key, and force SERVER_MODE off. PyRun_SimpleString(QString("PGADMIN_PORT = %1").arg(m_port).toLatin1()); PyRun_SimpleString(QString("PGADMIN_KEY = '%1'").arg(m_key).toLatin1()); + PyRun_SimpleString(QString("SERVER_MODE = False").toLatin1()); // Run the app! QByteArray m_appfile_utf8 = m_appfile.toUtf8(); diff --git a/web/config.py b/web/config.py index f4609e4e..32df08d5 100644 --- a/web/config.py +++ b/web/config.py @@ -11,9 +11,15 @@ # ########################################################################## +import logging import os import sys +if sys.version_info[0] >= 3: + import builtins +else: + import __builtin__ as builtins + # We need to include the root directory in sys.path to ensure that we can # find everything we need when running in the standalone runtime. @@ -93,46 +99,6 @@ MODULE_BLACKLIST = ['test'] NODE_BLACKLIST = [] -# Data directory for storage of config settings etc. This shouldn't normally -# need to be changed - it's here as various other settings depend on it. -if IS_WIN: - # Use the short path on windows - DATA_DIR = os.path.realpath( - os.path.join(fs_short_path(env('APPDATA')), u"pgAdmin") - ) -else: - DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) - - -########################################################################## -# Log settings -########################################################################## - -# Debug mode? -DEBUG = False - - -import logging - -# Application log level - one of: -# CRITICAL 50 -# ERROR 40 -# WARNING 30 -# SQL 25 -# INFO 20 -# DEBUG 10 -# NOTSET 0 -CONSOLE_LOG_LEVEL = logging.WARNING -FILE_LOG_LEVEL = logging.WARNING - -# Log format. -CONSOLE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' -FILE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' - -# Log file name -LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') - - ########################################################################## # Server settings ########################################################################## @@ -142,7 +108,19 @@ LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') # default login. # # DO NOT DISABLE SERVER MODE IF RUNNING ON A WEBSERVER!! -SERVER_MODE = True +# +# We only set SERVER_MODE if it's not already set. That's to allow the +# runtime to force it to False. +# +# NOTE: If you change the value of SERVER_MODE in an included config file, +# you may also need to redefine any values below that are derived +# from it, notably various paths such as LOG_FILE and anything +# using DATA_DIR. + +if builtins.SERVER_MODE is None: + SERVER_MODE = True +else: + SERVER_MODE = builtins.SERVER_MODE # User ID (email address) to use for the default user in desktop mode. # The default should be fine here, as it's not exposed in the app. @@ -177,6 +155,52 @@ SECURITY_PASSWORD_HASH = 'pbkdf2_sha512' # has no effect on <= Python 2.7. MINIFY_PAGE = True +# Data directory for storage of config settings etc. This shouldn't normally +# need to be changed - it's here as various other settings depend on it. +# On Windows, we always store data in %APPDATA%\pgAdmin. On other platforms, +# if we're in server mode we use /var/lib/pgadmin, otherwise ~/.pgadmin +if IS_WIN: + # Use the short path on windows + DATA_DIR = os.path.realpath( + os.path.join(fs_short_path(env('APPDATA')), u"pgAdmin") + ) +else: + if SERVER_MODE: + DATA_DIR = '/var/lib/pgadmin' + else: + DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) + + +########################################################################## +# Log settings +########################################################################## + +# Debug mode? +DEBUG = False + +# Application log level - one of: +# CRITICAL 50 +# ERROR 40 +# WARNING 30 +# SQL 25 +# INFO 20 +# DEBUG 10 +# NOTSET 0 +CONSOLE_LOG_LEVEL = logging.WARNING +FILE_LOG_LEVEL = logging.WARNING + +# Log format. +CONSOLE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' +FILE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' + +# Log file name. This goes in the data directory, except on non-Windows +# platforms in server mode. +if SERVER_MODE and not IS_WIN: + LOG_FILE = '/var/log/pgadmin/pgadmin4.log' +else: + LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') + + ########################################################################## # Server Connection Driver Settings ########################################################################## diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 1db49584..230ce9ff 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -14,12 +14,23 @@ to start a web server.""" import os import sys +if sys.version_info[0] >= 3: + import builtins +else: + import __builtin__ as builtins + # We need to include the root directory in sys.path to ensure that we can # find everything we need when running in the standalone runtime. root = os.path.dirname(os.path.realpath(__file__)) if sys.path[0] != root: sys.path.insert(0, root) +# Grab the SERVER_MODE if it's been set by the runtime +if 'SERVER_MODE' in globals(): + builtins.SERVER_MODE = globals()['SERVER_MODE'] +else: + builtins.SERVER_MODE = None + import config from pgadmin import create_app from pgadmin.utils import u, fs_encoding, file_quote