Ship with pre-configured paths that can work in both Server and Desktop modes out of the box. Fixes #2662

Ship the web code using server mode with appropriate paths by default and enable the runtime to override the mode, and force into desktop changing the appropriate paths to user-specific ones.

Note that this change will likely cause more advanced users to have to tweak configs.

RPMs will also need changes to create /var/lib/pgadmin and /var/log/pgadmin, owned by the webserver account.
This commit is contained in:
Dave Page 2017-08-25 10:54:28 +01:00
parent fb9eee47bd
commit f195b18f2d
4 changed files with 89 additions and 42 deletions

View File

@ -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();

View File

@ -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.
@ -91,46 +97,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
##########################################################################
@ -140,7 +106,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.
@ -175,6 +153,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
##########################################################################

View File

@ -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

View File

@ -27,6 +27,11 @@ if sys.version_info < (2, 7):
else:
import unittest as unit_test
if sys.version_info[0] >= 3:
import builtins
else:
import __builtin__ as builtins
logger = logging.getLogger(__name__)
file_name = os.path.basename(__file__)
@ -41,6 +46,12 @@ if sys.path[0] != root:
sys.path.insert(0, root)
os.chdir(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
from pgadmin import create_app
import config
from regression import test_setup