2015-06-30 00:51:55 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2023-01-02 00:23:55 -06:00
|
|
|
# Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2015-06-30 00:51:55 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
2018-03-02 03:37:11 -06:00
|
|
|
import os
|
|
|
|
import sys
|
2022-01-04 00:57:17 -06:00
|
|
|
import json
|
2021-06-08 02:54:17 -05:00
|
|
|
import subprocess
|
2015-06-29 01:58:41 -05:00
|
|
|
from collections import defaultdict
|
|
|
|
from operator import attrgetter
|
2016-06-21 08:12:14 -05:00
|
|
|
|
2022-09-19 05:06:10 -05:00
|
|
|
from flask import Blueprint, current_app, url_for
|
2021-11-24 05:52:57 -06:00
|
|
|
from flask_babel import gettext
|
2019-05-28 01:30:18 -05:00
|
|
|
from flask_security import current_user, login_required
|
2022-09-19 05:06:10 -05:00
|
|
|
from flask_security.utils import get_post_login_redirect
|
2019-05-28 01:30:18 -05:00
|
|
|
from threading import Lock
|
2016-06-21 08:12:14 -05:00
|
|
|
|
2016-05-12 13:34:28 -05:00
|
|
|
from .paths import get_storage_directory
|
2016-06-21 08:12:14 -05:00
|
|
|
from .preferences import Preferences
|
2023-03-24 05:57:02 -05:00
|
|
|
from pgadmin.utils.constants import UTILITIES_ARRAY, USER_NOT_FOUND, \
|
|
|
|
MY_STORAGE, ACCESS_DENIED_MESSAGE
|
|
|
|
from pgadmin.utils.ajax import make_json_response
|
2022-01-07 09:59:17 -06:00
|
|
|
from pgadmin.model import db, User, ServerGroup, Server
|
|
|
|
from urllib.parse import unquote
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
ADD_SERVERS_MSG = "Added %d Server Group(s) and %d Server(s)."
|
2015-06-29 01:58:41 -05:00
|
|
|
|
|
|
|
|
|
|
|
class PgAdminModule(Blueprint):
|
|
|
|
"""
|
|
|
|
Base class for every PgAdmin Module.
|
|
|
|
|
|
|
|
This class defines a set of method and attributes that
|
|
|
|
every module should implement.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, name, import_name, **kwargs):
|
|
|
|
kwargs.setdefault('url_prefix', '/' + name)
|
|
|
|
kwargs.setdefault('template_folder', 'templates')
|
|
|
|
kwargs.setdefault('static_folder', 'static')
|
|
|
|
self.submodules = []
|
2017-07-07 01:25:55 -05:00
|
|
|
self.parentmodules = []
|
2016-03-07 05:48:24 -06:00
|
|
|
|
2022-11-18 22:43:41 -06:00
|
|
|
super().__init__(name, import_name, **kwargs)
|
2015-06-29 01:58:41 -05:00
|
|
|
|
2016-03-07 05:48:24 -06:00
|
|
|
def create_module_preference():
|
|
|
|
# Create preference for each module by default
|
|
|
|
if hasattr(self, 'LABEL'):
|
|
|
|
self.preference = Preferences(self.name, self.LABEL)
|
|
|
|
else:
|
|
|
|
self.preference = Preferences(self.name, None)
|
|
|
|
|
|
|
|
self.register_preferences()
|
|
|
|
|
|
|
|
# Create and register the module preference object and preferences for
|
|
|
|
# it just before the first request
|
|
|
|
self.before_app_first_request(create_module_preference)
|
|
|
|
|
|
|
|
def register_preferences(self):
|
2020-07-24 01:16:30 -05:00
|
|
|
# To be implemented by child classes
|
2016-03-07 05:48:24 -06:00
|
|
|
pass
|
|
|
|
|
2021-11-24 05:52:57 -06:00
|
|
|
def register(self, app, options):
|
2015-06-29 01:58:41 -05:00
|
|
|
"""
|
|
|
|
Override the default register function to automagically register
|
|
|
|
sub-modules at once.
|
|
|
|
"""
|
2016-03-07 05:48:24 -06:00
|
|
|
|
2022-11-18 22:43:41 -06:00
|
|
|
super().register(app, options)
|
2016-03-07 05:48:24 -06:00
|
|
|
|
2015-06-29 01:58:41 -05:00
|
|
|
for module in self.submodules:
|
2021-11-24 05:52:57 -06:00
|
|
|
module.parentmodules.append(self)
|
|
|
|
if app.blueprints.get(module.name) is None:
|
|
|
|
app.register_blueprint(module)
|
|
|
|
app.register_logout_hook(module)
|
2015-06-29 01:58:41 -05:00
|
|
|
|
|
|
|
def get_own_stylesheets(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
list: the stylesheets used by this module, not including any
|
|
|
|
stylesheet needed by the submodules.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2016-05-10 05:37:45 -05:00
|
|
|
def get_own_messages(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
dict: the i18n messages used by this module, not including any
|
|
|
|
messages needed by the submodules.
|
|
|
|
"""
|
|
|
|
return dict()
|
|
|
|
|
2015-06-29 01:58:41 -05:00
|
|
|
def get_own_menuitems(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
dict: the menuitems for this module, not including
|
|
|
|
any needed from the submodules.
|
|
|
|
"""
|
|
|
|
return defaultdict(list)
|
|
|
|
|
2015-06-29 02:54:05 -05:00
|
|
|
def get_panels(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
list: a list of panel objects to add
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2017-06-12 01:31:22 -05:00
|
|
|
def get_exposed_url_endpoints(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
list: a list of url endpoints exposed to the client.
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
2015-06-29 01:58:41 -05:00
|
|
|
@property
|
|
|
|
def stylesheets(self):
|
|
|
|
stylesheets = self.get_own_stylesheets()
|
|
|
|
for module in self.submodules:
|
|
|
|
stylesheets.extend(module.stylesheets)
|
|
|
|
return stylesheets
|
|
|
|
|
2016-05-10 05:37:45 -05:00
|
|
|
@property
|
|
|
|
def messages(self):
|
|
|
|
res = self.get_own_messages()
|
|
|
|
|
|
|
|
for module in self.submodules:
|
|
|
|
res.update(module.messages)
|
|
|
|
return res
|
|
|
|
|
2015-06-29 01:58:41 -05:00
|
|
|
@property
|
|
|
|
def menu_items(self):
|
|
|
|
menu_items = self.get_own_menuitems()
|
|
|
|
for module in self.submodules:
|
|
|
|
for key, value in module.menu_items.items():
|
|
|
|
menu_items[key].extend(value)
|
2016-01-27 08:59:54 -06:00
|
|
|
menu_items = dict((key, sorted(value, key=attrgetter('priority')))
|
2016-06-21 08:21:06 -05:00
|
|
|
for key, value in menu_items.items())
|
2015-06-29 01:58:41 -05:00
|
|
|
return menu_items
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
|
2017-06-12 01:31:22 -05:00
|
|
|
@property
|
|
|
|
def exposed_endpoints(self):
|
|
|
|
res = self.get_exposed_url_endpoints()
|
|
|
|
|
|
|
|
for module in self.submodules:
|
|
|
|
res += module.exposed_endpoints
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
|
|
|
|
IS_WIN = (os.name == 'nt')
|
|
|
|
|
|
|
|
sys_encoding = sys.getdefaultencoding()
|
|
|
|
if not sys_encoding or sys_encoding == 'ascii':
|
|
|
|
# Fall back to 'utf-8', if we couldn't determine the default encoding,
|
|
|
|
# or 'ascii'.
|
|
|
|
sys_encoding = 'utf-8'
|
|
|
|
|
|
|
|
fs_encoding = sys.getfilesystemencoding()
|
|
|
|
if not fs_encoding or fs_encoding == 'ascii':
|
|
|
|
# Fall back to 'utf-8', if we couldn't determine the file-system encoding,
|
|
|
|
# or 'ascii'.
|
|
|
|
fs_encoding = 'utf-8'
|
|
|
|
|
|
|
|
|
2020-07-09 08:25:33 -05:00
|
|
|
def u_encode(_s, _encoding=sys_encoding):
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
return _s
|
|
|
|
|
|
|
|
|
|
|
|
def file_quote(_p):
|
|
|
|
return _p
|
|
|
|
|
2018-01-31 07:58:55 -06:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
if IS_WIN:
|
|
|
|
import ctypes
|
|
|
|
from ctypes import wintypes
|
|
|
|
|
2020-04-30 06:52:48 -05:00
|
|
|
def env(name):
|
|
|
|
if name in os.environ:
|
|
|
|
return os.environ[name]
|
|
|
|
return None
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
|
|
|
|
_GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW
|
|
|
|
_GetShortPathNameW.argtypes = [
|
|
|
|
wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD
|
|
|
|
]
|
|
|
|
_GetShortPathNameW.restype = wintypes.DWORD
|
|
|
|
|
|
|
|
def fs_short_path(_path):
|
|
|
|
"""
|
|
|
|
Gets the short path name of a given long path.
|
|
|
|
http://stackoverflow.com/a/23598461/200291
|
|
|
|
"""
|
|
|
|
buf_size = len(_path)
|
|
|
|
while True:
|
|
|
|
res = ctypes.create_unicode_buffer(buf_size)
|
2018-07-17 07:04:28 -05:00
|
|
|
# Note:- _GetShortPathNameW may return empty value
|
|
|
|
# if directory doesn't exist.
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
needed = _GetShortPathNameW(_path, res, buf_size)
|
|
|
|
|
|
|
|
if buf_size >= needed:
|
|
|
|
return res.value
|
|
|
|
else:
|
|
|
|
buf_size += needed
|
|
|
|
|
|
|
|
def document_dir():
|
|
|
|
CSIDL_PERSONAL = 5 # My Documents
|
|
|
|
SHGFP_TYPE_CURRENT = 0 # Get current, not default value
|
|
|
|
|
|
|
|
buf = ctypes.create_unicode_buffer(wintypes.MAX_PATH)
|
|
|
|
ctypes.windll.shell32.SHGetFolderPathW(
|
|
|
|
None, CSIDL_PERSONAL, None, SHGFP_TYPE_CURRENT, buf
|
|
|
|
)
|
|
|
|
|
|
|
|
return buf.value
|
|
|
|
|
|
|
|
else:
|
|
|
|
def env(name):
|
|
|
|
if name in os.environ:
|
|
|
|
return os.environ[name]
|
|
|
|
return None
|
|
|
|
|
|
|
|
def fs_short_path(_path):
|
|
|
|
return _path
|
|
|
|
|
|
|
|
def document_dir():
|
2020-08-31 06:15:31 -05:00
|
|
|
return os.path.realpath(os.path.expanduser('~/'))
|
2017-12-13 07:28:07 -06:00
|
|
|
|
|
|
|
|
2021-08-23 05:49:01 -05:00
|
|
|
def get_complete_file_path(file, validate=True):
|
2017-12-13 07:28:07 -06:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
file: File returned by file manager
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Full path for the file
|
|
|
|
"""
|
|
|
|
if not file:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# If desktop mode
|
|
|
|
if current_app.PGADMIN_RUNTIME or not current_app.config['SERVER_MODE']:
|
|
|
|
return file if os.path.isfile(file) else None
|
|
|
|
|
|
|
|
storage_dir = get_storage_directory()
|
|
|
|
if storage_dir:
|
|
|
|
file = os.path.join(
|
|
|
|
storage_dir,
|
2020-08-31 06:15:31 -05:00
|
|
|
file.lstrip('/').lstrip('\\')
|
2017-12-13 07:28:07 -06:00
|
|
|
)
|
|
|
|
if IS_WIN:
|
|
|
|
file = file.replace('\\', '/')
|
|
|
|
file = fs_short_path(file)
|
|
|
|
|
2021-08-23 05:49:01 -05:00
|
|
|
if validate:
|
|
|
|
return file if os.path.isfile(file) else None
|
|
|
|
else:
|
|
|
|
return file
|
2018-02-27 08:32:03 -06:00
|
|
|
|
|
|
|
|
2023-01-13 00:59:21 -06:00
|
|
|
def filename_with_file_manager_path(_file, create_file=False,
|
|
|
|
skip_permission_check=False):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
file: File name returned from client file manager
|
|
|
|
create_file: Set flag to False when file creation doesn't required
|
|
|
|
Returns:
|
|
|
|
Filename to use for backup with full path taken from preference
|
|
|
|
"""
|
2023-03-24 05:57:02 -05:00
|
|
|
# retrieve storage directory path
|
2023-03-28 11:49:01 -05:00
|
|
|
try:
|
|
|
|
last_storage = Preferences.module('file_manager').preference(
|
|
|
|
'last_storage').get()
|
|
|
|
except Exception as e:
|
|
|
|
last_storage = MY_STORAGE
|
|
|
|
|
2023-03-24 05:57:02 -05:00
|
|
|
if last_storage != MY_STORAGE:
|
|
|
|
selDirList = [sdir for sdir in current_app.config['SHARED_STORAGE']
|
|
|
|
if sdir['name'] == last_storage]
|
|
|
|
selectedDir = selDirList[0] if len(
|
|
|
|
selDirList) == 1 else None
|
|
|
|
|
|
|
|
if selectedDir:
|
|
|
|
if selectedDir['restricted_access'] and \
|
|
|
|
not current_user.has_role("Administrator"):
|
|
|
|
return make_json_response(success=0,
|
|
|
|
errormsg=ACCESS_DENIED_MESSAGE,
|
|
|
|
info='ACCESS_DENIED',
|
|
|
|
status=403)
|
|
|
|
storage_dir = get_storage_directory(
|
|
|
|
shared_storage=last_storage)
|
|
|
|
else:
|
|
|
|
storage_dir = get_storage_directory()
|
2023-01-13 00:59:21 -06:00
|
|
|
|
|
|
|
from pgadmin.misc.file_manager import Filemanager
|
|
|
|
Filemanager.check_access_permission(
|
|
|
|
storage_dir, _file, skip_permission_check)
|
|
|
|
if storage_dir:
|
|
|
|
_file = os.path.join(storage_dir, _file.lstrip('/').lstrip('\\'))
|
|
|
|
elif not os.path.isabs(_file):
|
|
|
|
_file = os.path.join(document_dir(), _file)
|
|
|
|
|
|
|
|
def short_filepath():
|
|
|
|
short_path = fs_short_path(_file)
|
|
|
|
# fs_short_path() function may return empty path on Windows
|
|
|
|
# if directory doesn't exists. In that case we strip the last path
|
|
|
|
# component and get the short path.
|
|
|
|
if os.name == 'nt' and short_path == '':
|
|
|
|
base_name = os.path.basename(_file)
|
|
|
|
dir_name = os.path.dirname(_file)
|
|
|
|
short_path = fs_short_path(dir_name) + '\\' + base_name
|
|
|
|
return short_path
|
|
|
|
|
|
|
|
if create_file:
|
|
|
|
# Touch the file to get the short path of the file on windows.
|
|
|
|
with open(_file, 'a'):
|
|
|
|
return short_filepath()
|
|
|
|
|
|
|
|
return short_filepath()
|
|
|
|
|
|
|
|
|
2019-07-12 07:00:23 -05:00
|
|
|
def does_utility_exist(file):
|
2018-10-22 02:05:21 -05:00
|
|
|
"""
|
|
|
|
This function will check the utility file exists on given path.
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
error_msg = None
|
2021-06-07 10:06:34 -05:00
|
|
|
if file is None:
|
|
|
|
error_msg = gettext("Utility file not found. Please correct the Binary"
|
|
|
|
" Path in the Preferences dialog")
|
|
|
|
return error_msg
|
|
|
|
|
2018-10-22 02:05:21 -05:00
|
|
|
if not os.path.exists(file):
|
2020-08-31 06:15:31 -05:00
|
|
|
error_msg = gettext("'%s' file not found. Please correct the Binary"
|
|
|
|
" Path in the Preferences dialog" % file)
|
2018-10-22 02:05:21 -05:00
|
|
|
return error_msg
|
|
|
|
|
|
|
|
|
2021-04-22 06:59:04 -05:00
|
|
|
def get_server(sid):
|
|
|
|
"""
|
|
|
|
# Fetch the server etc
|
|
|
|
:param sid:
|
|
|
|
:return: server
|
|
|
|
"""
|
|
|
|
server = Server.query.filter_by(id=sid).first()
|
|
|
|
return server
|
|
|
|
|
|
|
|
|
2021-06-10 12:19:05 -05:00
|
|
|
def set_binary_path(binary_path, bin_paths, server_type,
|
|
|
|
version_number=None, set_as_default=False):
|
2021-06-08 02:54:17 -05:00
|
|
|
"""
|
|
|
|
This function is used to iterate through the utilities and set the
|
|
|
|
default binary path.
|
|
|
|
"""
|
2021-06-14 08:53:26 -05:00
|
|
|
path_with_dir = binary_path if "$DIR" in binary_path else None
|
|
|
|
|
2021-06-10 12:19:05 -05:00
|
|
|
# Check if "$DIR" present in binary path
|
|
|
|
binary_path = replace_binary_path(binary_path)
|
|
|
|
|
2021-06-08 02:54:17 -05:00
|
|
|
for utility in UTILITIES_ARRAY:
|
|
|
|
full_path = os.path.abspath(
|
|
|
|
os.path.join(binary_path, (utility if os.name != 'nt' else
|
|
|
|
(utility + '.exe'))))
|
|
|
|
|
|
|
|
try:
|
2021-06-10 12:19:05 -05:00
|
|
|
# if version_number is provided then no need to fetch it.
|
|
|
|
if version_number is None:
|
|
|
|
# Get the output of the '--version' command
|
2021-06-14 04:31:49 -05:00
|
|
|
version_string = \
|
|
|
|
subprocess.getoutput('"{0}" --version'.format(full_path))
|
2021-06-08 02:54:17 -05:00
|
|
|
|
2021-06-10 12:19:05 -05:00
|
|
|
# Get the version number by splitting the result string
|
|
|
|
version_number = \
|
|
|
|
version_string.split(") ", 1)[1].split('.', 1)[0]
|
2021-06-15 09:14:54 -05:00
|
|
|
elif version_number.find('.'):
|
|
|
|
version_number = version_number.split('.', 1)[0]
|
2021-06-08 02:54:17 -05:00
|
|
|
|
|
|
|
# Get the paths array based on server type
|
|
|
|
if 'pg_bin_paths' in bin_paths or 'as_bin_paths' in bin_paths:
|
|
|
|
paths_array = bin_paths['pg_bin_paths']
|
|
|
|
if server_type == 'ppas':
|
|
|
|
paths_array = bin_paths['as_bin_paths']
|
|
|
|
else:
|
|
|
|
paths_array = bin_paths
|
|
|
|
|
|
|
|
for path in paths_array:
|
|
|
|
if path['version'].find(version_number) == 0 and \
|
|
|
|
path['binaryPath'] is None:
|
2021-06-14 08:53:26 -05:00
|
|
|
path['binaryPath'] = path_with_dir \
|
|
|
|
if path_with_dir is not None else binary_path
|
2021-06-10 12:19:05 -05:00
|
|
|
if set_as_default:
|
|
|
|
path['isDefault'] = True
|
2021-06-08 02:54:17 -05:00
|
|
|
break
|
|
|
|
break
|
|
|
|
except Exception:
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
2021-06-10 12:19:05 -05:00
|
|
|
def replace_binary_path(binary_path):
|
|
|
|
"""
|
|
|
|
This function is used to check if $DIR is present in
|
|
|
|
the binary path. If it is there then replace it with
|
|
|
|
module.
|
|
|
|
"""
|
|
|
|
if "$DIR" in binary_path:
|
|
|
|
# When running as an WSGI application, we will not find the
|
|
|
|
# '__file__' attribute for the '__main__' module.
|
|
|
|
main_module_file = getattr(
|
|
|
|
sys.modules['__main__'], '__file__', None
|
|
|
|
)
|
|
|
|
|
|
|
|
if main_module_file is not None:
|
|
|
|
binary_path = binary_path.replace(
|
|
|
|
"$DIR", os.path.dirname(main_module_file)
|
|
|
|
)
|
|
|
|
|
|
|
|
return binary_path
|
|
|
|
|
|
|
|
|
2022-01-04 00:57:17 -06:00
|
|
|
def add_value(attr_dict, key, value):
|
|
|
|
"""Add a value to the attribute dict if non-empty.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
attr_dict (dict): The dictionary to add the values to
|
|
|
|
key (str): The key for the new value
|
|
|
|
value (str): The value to add
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The updated attribute dictionary
|
|
|
|
"""
|
|
|
|
if value != "" and value is not None:
|
|
|
|
attr_dict[key] = value
|
|
|
|
|
|
|
|
return attr_dict
|
|
|
|
|
|
|
|
|
|
|
|
def dump_database_servers(output_file, selected_servers,
|
|
|
|
dump_user=current_user, from_setup=False):
|
|
|
|
"""Dump the server groups and servers.
|
|
|
|
"""
|
|
|
|
user = _does_user_exist(dump_user, from_setup)
|
|
|
|
if user is None:
|
2022-01-05 02:16:26 -06:00
|
|
|
return False, USER_NOT_FOUND % dump_user
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
user_id = user.id
|
|
|
|
# Dict to collect the output
|
|
|
|
object_dict = {}
|
|
|
|
# Counters
|
|
|
|
servers_dumped = 0
|
|
|
|
|
|
|
|
# Dump servers
|
|
|
|
servers = Server.query.filter_by(user_id=user_id).all()
|
|
|
|
server_dict = {}
|
|
|
|
for server in servers:
|
|
|
|
if selected_servers is None or str(server.id) in selected_servers:
|
|
|
|
# Get the group name
|
|
|
|
group_name = ServerGroup.query.filter_by(
|
|
|
|
user_id=user_id, id=server.servergroup_id).first().name
|
|
|
|
|
|
|
|
attr_dict = {}
|
|
|
|
add_value(attr_dict, "Name", server.name)
|
|
|
|
add_value(attr_dict, "Group", group_name)
|
|
|
|
add_value(attr_dict, "Host", server.host)
|
|
|
|
add_value(attr_dict, "Port", server.port)
|
|
|
|
add_value(attr_dict, "MaintenanceDB", server.maintenance_db)
|
|
|
|
add_value(attr_dict, "Username", server.username)
|
|
|
|
add_value(attr_dict, "Role", server.role)
|
|
|
|
add_value(attr_dict, "Comment", server.comment)
|
|
|
|
add_value(attr_dict, "Shared", server.shared)
|
|
|
|
add_value(attr_dict, "DBRestriction", server.db_res)
|
|
|
|
add_value(attr_dict, "BGColor", server.bgcolor)
|
|
|
|
add_value(attr_dict, "FGColor", server.fgcolor)
|
|
|
|
add_value(attr_dict, "Service", server.service)
|
|
|
|
add_value(attr_dict, "UseSSHTunnel", server.use_ssh_tunnel)
|
|
|
|
add_value(attr_dict, "TunnelHost", server.tunnel_host)
|
|
|
|
add_value(attr_dict, "TunnelPort", server.tunnel_port)
|
|
|
|
add_value(attr_dict, "TunnelUsername", server.tunnel_username)
|
|
|
|
add_value(attr_dict, "TunnelAuthentication",
|
|
|
|
server.tunnel_authentication)
|
2023-01-23 05:49:59 -06:00
|
|
|
add_value(attr_dict, "KerberosAuthentication",
|
|
|
|
server.kerberos_conn),
|
|
|
|
add_value(attr_dict, "ConnectionParameters",
|
|
|
|
server.connection_params)
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
servers_dumped = servers_dumped + 1
|
|
|
|
|
|
|
|
server_dict[servers_dumped] = attr_dict
|
|
|
|
|
|
|
|
object_dict["Servers"] = server_dict
|
|
|
|
|
|
|
|
try:
|
2023-04-19 05:35:35 -05:00
|
|
|
if from_setup:
|
|
|
|
file_path = unquote(output_file)
|
|
|
|
else:
|
|
|
|
file_path = filename_with_file_manager_path(unquote(output_file))
|
2022-01-04 00:57:17 -06:00
|
|
|
except Exception as e:
|
2022-01-07 09:59:17 -06:00
|
|
|
return _handle_error(str(e), from_setup)
|
|
|
|
|
|
|
|
# write to file
|
|
|
|
file_content = json.dumps(object_dict, indent=4)
|
2022-01-10 04:46:10 -06:00
|
|
|
error_str = "Error: {0}"
|
2022-01-04 00:57:17 -06:00
|
|
|
try:
|
2022-01-07 09:59:17 -06:00
|
|
|
with open(file_path, 'w') as output_file:
|
|
|
|
output_file.write(file_content)
|
|
|
|
except IOError as e:
|
|
|
|
err_msg = error_str.format(e.strerror)
|
|
|
|
return _handle_error(err_msg, from_setup)
|
2022-01-04 00:57:17 -06:00
|
|
|
except Exception as e:
|
2022-01-07 09:59:17 -06:00
|
|
|
err_msg = error_str.format(e.strerror)
|
|
|
|
return _handle_error(err_msg, from_setup)
|
2022-01-04 00:57:17 -06:00
|
|
|
|
2022-04-29 05:48:28 -05:00
|
|
|
msg = gettext("Configuration for %s servers dumped to %s" %
|
|
|
|
(servers_dumped, output_file.name))
|
2022-01-04 00:57:17 -06:00
|
|
|
print(msg)
|
|
|
|
|
2022-01-05 02:16:26 -06:00
|
|
|
return True, msg
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
|
2022-01-05 02:16:26 -06:00
|
|
|
def validate_json_data(data, is_admin):
|
2022-01-04 00:57:17 -06:00
|
|
|
"""
|
|
|
|
Used internally by load_servers to validate servers data.
|
|
|
|
:param data: servers data
|
2022-01-05 02:16:26 -06:00
|
|
|
:param is_admin:
|
2022-01-04 00:57:17 -06:00
|
|
|
:return: error message if any
|
|
|
|
"""
|
|
|
|
skip_servers = []
|
|
|
|
# Loop through the servers...
|
|
|
|
if "Servers" not in data:
|
2022-04-29 05:48:28 -05:00
|
|
|
return gettext("'Servers' attribute not found in the specified file.")
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
for server in data["Servers"]:
|
|
|
|
obj = data["Servers"][server]
|
|
|
|
|
|
|
|
# Check if server is shared.Won't import if user is non-admin
|
|
|
|
if obj.get('Shared', None) and not is_admin:
|
|
|
|
print("Won't import the server '%s' as it is shared " %
|
|
|
|
obj["Name"])
|
|
|
|
skip_servers.append(server)
|
|
|
|
continue
|
|
|
|
|
|
|
|
def check_attrib(attrib):
|
|
|
|
if attrib not in obj:
|
2022-04-29 05:48:28 -05:00
|
|
|
return gettext("'%s' attribute not found for server '%s'" %
|
|
|
|
(attrib, server))
|
2022-01-04 00:57:17 -06:00
|
|
|
return None
|
|
|
|
|
2022-01-05 02:16:26 -06:00
|
|
|
def check_is_integer(value):
|
|
|
|
if not isinstance(value, int):
|
2022-04-29 05:48:28 -05:00
|
|
|
return gettext("Port must be integer for server '%s'" % server)
|
2022-01-05 02:16:26 -06:00
|
|
|
return None
|
|
|
|
|
2022-01-04 00:57:17 -06:00
|
|
|
for attrib in ("Group", "Name"):
|
|
|
|
errmsg = check_attrib(attrib)
|
|
|
|
if errmsg:
|
|
|
|
return errmsg
|
|
|
|
|
|
|
|
is_service_attrib_available = obj.get("Service", None) is not None
|
|
|
|
|
|
|
|
if not is_service_attrib_available:
|
|
|
|
for attrib in ("Port", "Username"):
|
|
|
|
errmsg = check_attrib(attrib)
|
|
|
|
if errmsg:
|
|
|
|
return errmsg
|
2022-01-05 02:16:26 -06:00
|
|
|
if attrib == 'Port':
|
|
|
|
errmsg = check_is_integer(obj[attrib])
|
|
|
|
if errmsg:
|
|
|
|
return errmsg
|
2022-01-04 00:57:17 -06:00
|
|
|
|
2023-01-23 05:49:59 -06:00
|
|
|
errmsg = check_attrib("MaintenanceDB")
|
|
|
|
if errmsg:
|
|
|
|
return errmsg
|
2022-01-04 00:57:17 -06:00
|
|
|
|
2023-01-23 05:49:59 -06:00
|
|
|
if "Host" not in obj and not is_service_attrib_available:
|
|
|
|
return gettext("'Host' or 'Service' attribute not "
|
2022-04-29 05:48:28 -05:00
|
|
|
"found for server '%s'" % server)
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
for server in skip_servers:
|
|
|
|
del data["Servers"][server]
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def load_database_servers(input_file, selected_servers,
|
|
|
|
load_user=current_user, from_setup=False):
|
|
|
|
"""Load server groups and servers.
|
|
|
|
"""
|
2022-01-10 04:46:10 -06:00
|
|
|
user = _does_user_exist(load_user, from_setup)
|
|
|
|
if user is None:
|
|
|
|
return False, USER_NOT_FOUND % load_user
|
|
|
|
|
2022-01-07 09:59:17 -06:00
|
|
|
# generate full path of file
|
2023-01-13 00:59:21 -06:00
|
|
|
try:
|
2023-01-18 01:49:21 -06:00
|
|
|
if from_setup:
|
|
|
|
file_path = unquote(input_file)
|
|
|
|
else:
|
|
|
|
file_path = filename_with_file_manager_path(unquote(input_file))
|
2023-01-13 00:59:21 -06:00
|
|
|
except Exception as e:
|
|
|
|
return _handle_error(str(e), from_setup)
|
2022-01-07 09:59:17 -06:00
|
|
|
|
2022-01-04 00:57:17 -06:00
|
|
|
try:
|
2022-01-07 09:59:17 -06:00
|
|
|
with open(file_path) as f:
|
2022-01-04 00:57:17 -06:00
|
|
|
data = json.load(f)
|
|
|
|
except json.decoder.JSONDecodeError as e:
|
2022-04-29 05:48:28 -05:00
|
|
|
return _handle_error(gettext("Error parsing input file %s: %s" %
|
|
|
|
(file_path, e)), from_setup)
|
2022-01-04 00:57:17 -06:00
|
|
|
except Exception as e:
|
2022-04-29 05:48:28 -05:00
|
|
|
return _handle_error(gettext("Error reading input file %s: [%d] %s" %
|
|
|
|
(file_path, e.errno, e.strerror)), from_setup)
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
user_id = user.id
|
|
|
|
# Counters
|
|
|
|
groups_added = 0
|
|
|
|
servers_added = 0
|
|
|
|
|
|
|
|
# Get the server groups
|
|
|
|
groups = ServerGroup.query.filter_by(user_id=user_id)
|
|
|
|
|
|
|
|
# Validate server data
|
2022-01-05 02:16:26 -06:00
|
|
|
error_msg = validate_json_data(data, user.has_role("Administrator"))
|
2022-01-04 00:57:17 -06:00
|
|
|
if error_msg is not None and from_setup:
|
|
|
|
print(ADD_SERVERS_MSG % (groups_added, servers_added))
|
|
|
|
return _handle_error(error_msg, from_setup)
|
|
|
|
|
|
|
|
for server in data["Servers"]:
|
|
|
|
if selected_servers is None or str(server) in selected_servers:
|
|
|
|
obj = data["Servers"][server]
|
|
|
|
|
|
|
|
# Get the group. Create if necessary
|
|
|
|
group_id = next(
|
|
|
|
(g.id for g in groups if g.name == obj["Group"]), -1)
|
|
|
|
|
|
|
|
if group_id == -1:
|
|
|
|
new_group = ServerGroup()
|
|
|
|
new_group.name = obj["Group"]
|
|
|
|
new_group.user_id = user_id
|
|
|
|
db.session.add(new_group)
|
|
|
|
|
|
|
|
try:
|
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
|
|
|
if from_setup:
|
|
|
|
print(ADD_SERVERS_MSG % (groups_added, servers_added))
|
|
|
|
return _handle_error(
|
2022-04-29 05:48:28 -05:00
|
|
|
gettext("Error creating server group '%s': %s" %
|
|
|
|
(new_group.name, e)), from_setup)
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
group_id = new_group.id
|
|
|
|
groups_added = groups_added + 1
|
|
|
|
groups = ServerGroup.query.filter_by(user_id=user_id)
|
|
|
|
|
|
|
|
# Create the server
|
|
|
|
new_server = Server()
|
|
|
|
new_server.name = obj["Name"]
|
|
|
|
new_server.servergroup_id = group_id
|
|
|
|
new_server.user_id = user_id
|
|
|
|
new_server.maintenance_db = obj["MaintenanceDB"]
|
|
|
|
|
|
|
|
new_server.host = obj.get("Host", None)
|
|
|
|
|
|
|
|
new_server.port = obj.get("Port", None)
|
|
|
|
|
|
|
|
new_server.username = obj.get("Username", None)
|
|
|
|
|
|
|
|
new_server.role = obj.get("Role", None)
|
|
|
|
|
|
|
|
new_server.comment = obj.get("Comment", None)
|
|
|
|
|
|
|
|
new_server.db_res = obj.get("DBRestriction", None)
|
|
|
|
|
2023-01-23 05:49:59 -06:00
|
|
|
if 'ConnectionParameters' in obj:
|
|
|
|
new_server.connection_params = \
|
|
|
|
obj.get("ConnectionParameters", None)
|
|
|
|
else:
|
|
|
|
# JSON file format is old before introduction of the
|
|
|
|
# connection parameters.
|
|
|
|
conn_param = dict()
|
|
|
|
for item in ['HostAddr', 'SSLMode', 'PassFile', 'SSLCert',
|
|
|
|
'SSLKey', 'SSLRootCert', 'SSLCrl', 'Timeout',
|
|
|
|
'SSLCompression']:
|
|
|
|
if item in obj:
|
|
|
|
key = item.lower()
|
|
|
|
if item == 'Timeout':
|
|
|
|
key = 'connect_timeout'
|
|
|
|
conn_param[key] = obj.get(item)
|
|
|
|
|
|
|
|
new_server.connection_params = conn_param
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
new_server.bgcolor = obj.get("BGColor", None)
|
|
|
|
|
|
|
|
new_server.fgcolor = obj.get("FGColor", None)
|
|
|
|
|
|
|
|
new_server.service = obj.get("Service", None)
|
|
|
|
|
|
|
|
new_server.use_ssh_tunnel = obj.get("UseSSHTunnel", None)
|
|
|
|
|
|
|
|
new_server.tunnel_host = obj.get("TunnelHost", None)
|
|
|
|
|
|
|
|
new_server.tunnel_port = obj.get("TunnelPort", None)
|
|
|
|
|
|
|
|
new_server.tunnel_username = obj.get("TunnelUsername", None)
|
|
|
|
|
|
|
|
new_server.tunnel_authentication = \
|
|
|
|
obj.get("TunnelAuthentication", None)
|
|
|
|
|
2023-01-23 05:49:59 -06:00
|
|
|
new_server.shared = obj.get("Shared", None)
|
|
|
|
|
|
|
|
new_server.kerberos_conn = obj.get("KerberosAuthentication", None)
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
db.session.add(new_server)
|
|
|
|
|
|
|
|
try:
|
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
|
|
|
if from_setup:
|
|
|
|
print(ADD_SERVERS_MSG % (groups_added, servers_added))
|
2022-04-29 05:48:28 -05:00
|
|
|
return _handle_error(gettext("Error creating server '%s': %s" %
|
|
|
|
(new_server.name, e)), from_setup)
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
servers_added = servers_added + 1
|
|
|
|
|
|
|
|
msg = ADD_SERVERS_MSG % (groups_added, servers_added)
|
|
|
|
print(msg)
|
|
|
|
|
2022-01-05 02:16:26 -06:00
|
|
|
return True, msg
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
|
|
|
|
def clear_database_servers(load_user=current_user, from_setup=False):
|
|
|
|
"""Clear groups and servers configurations.
|
|
|
|
"""
|
|
|
|
user = _does_user_exist(load_user, from_setup)
|
|
|
|
if user is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
user_id = user.id
|
|
|
|
|
|
|
|
# Remove all servers
|
|
|
|
servers = Server.query.filter_by(user_id=user_id)
|
|
|
|
for server in servers:
|
|
|
|
db.session.delete(server)
|
|
|
|
|
|
|
|
# Remove all groups
|
|
|
|
groups = ServerGroup.query.filter_by(user_id=user_id)
|
|
|
|
for group in groups:
|
|
|
|
db.session.delete(group)
|
|
|
|
servers = Server.query.filter_by(user_id=user_id)
|
|
|
|
|
|
|
|
for server in servers:
|
|
|
|
db.session.delete(server)
|
|
|
|
|
|
|
|
try:
|
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
2022-04-29 05:48:28 -05:00
|
|
|
error_msg = \
|
|
|
|
gettext("Error clearing server configuration with error (%s)" %
|
|
|
|
str(e))
|
2022-01-04 00:57:17 -06:00
|
|
|
if from_setup:
|
|
|
|
print(error_msg)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
return False, error_msg
|
|
|
|
|
|
|
|
|
|
|
|
def _does_user_exist(user, from_setup):
|
|
|
|
"""
|
|
|
|
This function will check user is exist or not. If exist then return
|
|
|
|
"""
|
|
|
|
if isinstance(user, User):
|
|
|
|
user = user.email
|
|
|
|
|
2022-08-31 03:58:48 -05:00
|
|
|
new_user = User.query.filter_by(email=user).first()
|
2022-01-04 00:57:17 -06:00
|
|
|
|
2022-08-31 03:58:48 -05:00
|
|
|
if new_user is None:
|
2022-01-04 00:57:17 -06:00
|
|
|
print(USER_NOT_FOUND % user)
|
|
|
|
if from_setup:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2022-08-31 03:58:48 -05:00
|
|
|
return new_user
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
|
|
|
|
def _handle_error(error_msg, from_setup):
|
|
|
|
"""
|
|
|
|
This function is used to print the error msg and exit from app if
|
|
|
|
called from setup.py
|
|
|
|
"""
|
|
|
|
if from_setup:
|
|
|
|
print(error_msg)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2022-01-05 02:16:26 -06:00
|
|
|
return False, error_msg
|
2022-01-04 00:57:17 -06:00
|
|
|
|
|
|
|
|
2018-02-27 08:32:03 -06:00
|
|
|
# Shortcut configuration for Accesskey
|
|
|
|
ACCESSKEY_FIELDS = [
|
|
|
|
{
|
|
|
|
'name': 'key',
|
|
|
|
'type': 'keyCode',
|
|
|
|
'label': gettext('Key')
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
# Shortcut configuration
|
|
|
|
SHORTCUT_FIELDS = [
|
|
|
|
{
|
|
|
|
'name': 'key',
|
|
|
|
'type': 'keyCode',
|
|
|
|
'label': gettext('Key')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'shift',
|
|
|
|
'type': 'checkbox',
|
|
|
|
'label': gettext('Shift')
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
'name': 'control',
|
|
|
|
'type': 'checkbox',
|
|
|
|
'label': gettext('Ctrl')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'alt',
|
|
|
|
'type': 'checkbox',
|
|
|
|
'label': gettext('Alt/Option')
|
|
|
|
}
|
|
|
|
]
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
class KeyManager:
|
|
|
|
def __init__(self):
|
|
|
|
self.users = dict()
|
|
|
|
self.lock = Lock()
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def get(self):
|
|
|
|
user = self.users.get(current_user.id, None)
|
|
|
|
if user is not None:
|
|
|
|
return user.get('key', None)
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def set(self, _key, _new_login=True):
|
|
|
|
with self.lock:
|
|
|
|
user = self.users.get(current_user.id, None)
|
|
|
|
if user is None:
|
|
|
|
self.users[current_user.id] = dict(
|
|
|
|
session_count=1, key=_key)
|
|
|
|
else:
|
|
|
|
if _new_login:
|
|
|
|
user['session_count'] += 1
|
|
|
|
user['key'] = _key
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def reset(self):
|
|
|
|
with self.lock:
|
|
|
|
user = self.users.get(current_user.id, None)
|
|
|
|
|
|
|
|
if user is not None:
|
|
|
|
# This will not decrement if session expired
|
|
|
|
user['session_count'] -= 1
|
|
|
|
if user['session_count'] == 0:
|
|
|
|
del self.users[current_user.id]
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def hard_reset(self):
|
|
|
|
with self.lock:
|
|
|
|
user = self.users.get(current_user.id, None)
|
|
|
|
|
|
|
|
if user is not None:
|
|
|
|
del self.users[current_user.id]
|
2022-09-19 05:06:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
def get_safe_post_login_redirect():
|
|
|
|
allow_list = [
|
|
|
|
url_for('browser.index')
|
|
|
|
]
|
2022-09-20 04:14:05 -05:00
|
|
|
if "SCRIPT_NAME" in os.environ and os.environ["SCRIPT_NAME"]:
|
|
|
|
allow_list.append(os.environ["SCRIPT_NAME"])
|
|
|
|
|
2022-09-19 05:06:10 -05:00
|
|
|
url = get_post_login_redirect()
|
2022-09-20 04:14:05 -05:00
|
|
|
for item in allow_list:
|
|
|
|
if url.startswith(item):
|
|
|
|
return url
|
2022-09-19 05:06:10 -05:00
|
|
|
|
2022-11-14 07:28:36 -06:00
|
|
|
return url_for('browser.index')
|