gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

616 行
22KB

  1. # -*- coding: utf-8 -*-
  2. ##########################################################################
  3. #
  4. # pgAdmin 4 - PostgreSQL Tools
  5. #
  6. # Copyright (C) 2013 - 2020, The pgAdmin Development Team
  7. # This software is released under the PostgreSQL Licence
  8. #
  9. # config.py - Core application configuration settings
  10. #
  11. ##########################################################################
  12. import builtins
  13. import logging
  14. import os
  15. import sys
  16. # We need to include the root directory in sys.path to ensure that we can
  17. # find everything we need when running in the standalone runtime.
  18. root = os.path.dirname(os.path.realpath(__file__))
  19. if sys.path[0] != root:
  20. sys.path.insert(0, root)
  21. from pgadmin.utils import env, IS_WIN, fs_short_path
  22. ##########################################################################
  23. # Application settings
  24. ##########################################################################
  25. # Name of the application to display in the UI
  26. APP_NAME = 'pgAdmin 4'
  27. APP_ICON = 'pg-icon'
  28. ##########################################################################
  29. # Application settings
  30. ##########################################################################
  31. # NOTE!!!
  32. # If you change any of APP_RELEASE, APP_REVISION or APP_SUFFIX, then you
  33. # must also change APP_VERSION_INT to match.
  34. #
  35. # Any changes made here must also be made in runtime/pgAdmin4.pro and
  36. # runtime/Info.plist
  37. #
  38. # Application version number components
  39. APP_RELEASE = 4
  40. APP_REVISION = 24
  41. # Application version suffix, e.g. 'beta1', 'dev'. Usually an empty string
  42. # for GA releases.
  43. APP_SUFFIX = ''
  44. # Numeric application version for upgrade checks. Should be in the format:
  45. # [X]XYYZZ, where X is the release version, Y is the revision, with a leading
  46. # zero if needed, and Z represents the suffix, with a leading zero if needed
  47. APP_VERSION_INT = 42400
  48. # DO NOT CHANGE!
  49. # The application version string, constructed from the components
  50. if not APP_SUFFIX:
  51. APP_VERSION = '%s.%s' % (APP_RELEASE, APP_REVISION)
  52. else:
  53. APP_VERSION = '%s.%s-%s' % (APP_RELEASE, APP_REVISION, APP_SUFFIX)
  54. # Copyright string for display in the app
  55. # Any changes made here must also be made in runtime/pgAdmin4.pro
  56. APP_COPYRIGHT = 'Copyright (C) 2013 - 2020, The pgAdmin Development Team'
  57. ##########################################################################
  58. # Misc stuff
  59. ##########################################################################
  60. # Path to the online help.
  61. HELP_PATH = '../../../docs/en_US/_build/html/'
  62. # Languages we support in the UI
  63. LANGUAGES = {
  64. 'en': 'English',
  65. 'zh': 'Chinese (Simplified)',
  66. 'cs': 'Czech',
  67. 'fr': 'French',
  68. 'de': 'German',
  69. 'it': 'Italian',
  70. 'ja': 'Japanese',
  71. 'ko': 'Korean',
  72. 'pl': 'Polish',
  73. 'ru': 'Russian',
  74. 'es': 'Spanish',
  75. }
  76. # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING!
  77. # List of modules to skip when dynamically loading
  78. MODULE_BLACKLIST = ['test']
  79. # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING!
  80. # List of treeview browser nodes to skip when dynamically loading
  81. NODE_BLACKLIST = []
  82. ##########################################################################
  83. # Server settings
  84. ##########################################################################
  85. # The server mode determines whether or not we're running on a web server
  86. # requiring user authentication, or desktop mode which uses an automatic
  87. # default login.
  88. #
  89. # DO NOT DISABLE SERVER MODE IF RUNNING ON A WEBSERVER!!
  90. #
  91. # We only set SERVER_MODE if it's not already set. That's to allow the
  92. # runtime to force it to False.
  93. #
  94. # NOTE: If you change the value of SERVER_MODE in an included config file,
  95. # you may also need to redefine any values below that are derived
  96. # from it, notably various paths such as LOG_FILE and anything
  97. # using DATA_DIR.
  98. if (not hasattr(builtins, 'SERVER_MODE')) or builtins.SERVER_MODE is None:
  99. SERVER_MODE = True
  100. else:
  101. SERVER_MODE = builtins.SERVER_MODE
  102. # HTTP headers to search for CSRF token when it is not provided in the form.
  103. # Default is ['X-CSRFToken', 'X-CSRF-Token']
  104. WTF_CSRF_HEADERS = ['X-pgA-CSRFToken']
  105. # User ID (email address) to use for the default user in desktop mode.
  106. # The default should be fine here, as it's not exposed in the app.
  107. DESKTOP_USER = 'pgadmin4@pgadmin.org'
  108. # This option allows the user to host the application on a LAN
  109. # Default hosting is on localhost (DEFAULT_SERVER='localhost').
  110. # To host pgAdmin4 over LAN set DEFAULT_SERVER='0.0.0.0' (or a specific
  111. # adaptor address.
  112. #
  113. # NOTE: This is NOT recommended for production use, only for debugging
  114. # or testing. Production installations should be run as a WSGI application
  115. # behind Apache HTTPD.
  116. DEFAULT_SERVER = '127.0.0.1'
  117. # The default port on which the app server will listen if not set in the
  118. # environment by the runtime
  119. DEFAULT_SERVER_PORT = 5050
  120. # Enable X-Frame-Option protection.
  121. # Set to one of "SAMEORIGIN", "ALLOW-FROM origin" or "" to disable.
  122. # Note that "DENY" is NOT supported (and will be silently ignored).
  123. # See https://tools.ietf.org/html/rfc7034 for more info.
  124. X_FRAME_OPTIONS = "SAMEORIGIN"
  125. # Hashing algorithm used for password storage
  126. SECURITY_PASSWORD_HASH = 'pbkdf2_sha512'
  127. # Reverse Proxy parameters
  128. # You must tell the middleware how many proxies set each header
  129. # so it knows what values to trust.
  130. # See https://tinyurl.com/yyg7r9av
  131. # for more information.
  132. # Number of values to trust for X-Forwarded-For
  133. PROXY_X_FOR_COUNT = 1
  134. # Number of values to trust for X-Forwarded-Proto.
  135. PROXY_X_PROTO_COUNT = 1
  136. # Number of values to trust for X-Forwarded-Host.
  137. PROXY_X_HOST_COUNT = 0
  138. # Number of values to trust for X-Forwarded-Port.
  139. PROXY_X_PORT_COUNT = 1
  140. # Number of values to trust for X-Forwarded-Prefix.
  141. PROXY_X_PREFIX_COUNT = 0
  142. # NOTE: CSRF_SESSION_KEY, SECRET_KEY and SECURITY_PASSWORD_SALT are no
  143. # longer part of the main configuration, but are stored in the
  144. # configuration databases 'keys' table and are auto-generated.
  145. # COMPRESSION
  146. COMPRESS_MIMETYPES = [
  147. 'text/html', 'text/css', 'text/xml', 'application/json',
  148. 'application/javascript'
  149. ]
  150. COMPRESS_LEVEL = 9
  151. COMPRESS_MIN_SIZE = 500
  152. # Set the cache control max age for static files in flask to 1 year
  153. SEND_FILE_MAX_AGE_DEFAULT = 31556952
  154. # This will be added to static urls as url parameter with value as
  155. # APP_VERSION_INT for cache busting on version upgrade. If the value is set as
  156. # None or empty string then it will not be added.
  157. # eg - http:localhost:5050/pgadmin.css?intver=3.13
  158. APP_VERSION_PARAM = 'ver'
  159. # Add the internal version param to below extensions only
  160. APP_VERSION_EXTN = ('.css', '.js', '.html', '.svg', '.png', '.gif', '.ico')
  161. # Data directory for storage of config settings etc. This shouldn't normally
  162. # need to be changed - it's here as various other settings depend on it.
  163. # On Windows, we always store data in %APPDATA%\pgAdmin. On other platforms,
  164. # if we're in server mode we use /var/lib/pgadmin, otherwise ~/.pgadmin
  165. if IS_WIN:
  166. # Use the short path on windows
  167. DATA_DIR = os.path.realpath(
  168. os.path.join(fs_short_path(env('APPDATA')), u"pgAdmin")
  169. )
  170. else:
  171. if SERVER_MODE:
  172. DATA_DIR = '/var/lib/pgadmin'
  173. else:
  174. DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))
  175. # An optional login banner to show security warnings/disclaimers etc. at
  176. # login and password recovery etc. HTML may be included for basic formatting,
  177. # For example:
  178. # LOGIN_BANNER = "<h4>Authorised Users Only!</h4>" \
  179. # "Unauthorised use is strictly forbidden."
  180. LOGIN_BANNER = ""
  181. ##########################################################################
  182. # Log settings
  183. ##########################################################################
  184. # Debug mode?
  185. DEBUG = False
  186. # Application log level - one of:
  187. # CRITICAL 50
  188. # ERROR 40
  189. # WARNING 30
  190. # SQL 25
  191. # INFO 20
  192. # DEBUG 10
  193. # NOTSET 0
  194. CONSOLE_LOG_LEVEL = logging.WARNING
  195. FILE_LOG_LEVEL = logging.WARNING
  196. # Log format.
  197. CONSOLE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s'
  198. FILE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s'
  199. # Log file name. This goes in the data directory, except on non-Windows
  200. # platforms in server mode.
  201. if SERVER_MODE and not IS_WIN:
  202. LOG_FILE = '/var/log/pgadmin/pgadmin4.log'
  203. else:
  204. LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
  205. ##########################################################################
  206. # Server Connection Driver Settings
  207. ##########################################################################
  208. # The default driver used for making connection with PostgreSQL
  209. PG_DEFAULT_DRIVER = 'psycopg2'
  210. # Maximum allowed idle time in minutes before which releasing the connection
  211. # for the particular session. (in minutes)
  212. MAX_SESSION_IDLE_TIME = 60
  213. ##########################################################################
  214. # User account and settings storage
  215. ##########################################################################
  216. # The default path to the SQLite database used to store user accounts and
  217. # settings. This default places the file in the same directory as this
  218. # config file, but generates an absolute path for use througout the app.
  219. SQLITE_PATH = env('SQLITE_PATH') or os.path.join(DATA_DIR, 'pgadmin4.db')
  220. # SQLITE_TIMEOUT will define how long to wait before throwing the error -
  221. # OperationError due to database lock. On slower system, you may need to change
  222. # this to some higher value.
  223. # (Default: 500 milliseconds)
  224. SQLITE_TIMEOUT = 500
  225. # Allow database connection passwords to be saved if the user chooses.
  226. # Set to False to disable password saving.
  227. ALLOW_SAVE_PASSWORD = True
  228. # Maximum number of history queries stored per user/server/database
  229. MAX_QUERY_HIST_STORED = 20
  230. ##########################################################################
  231. # Server-side session storage path
  232. #
  233. # SESSION_DB_PATH (Default: $HOME/.pgadmin4/sessions)
  234. ##########################################################################
  235. #
  236. # We use SQLite for server-side session storage. There will be one
  237. # SQLite database object per session created.
  238. #
  239. # Specify the path used to store your session objects.
  240. #
  241. # If the specified directory does not exist, the setup script will create
  242. # it with permission mode 700 to keep the session database secure.
  243. #
  244. # On certain systems, you can use shared memory (tmpfs) for maximum
  245. # scalability, for example, on Ubuntu:
  246. #
  247. # SESSION_DB_PATH = '/run/shm/pgAdmin4_session'
  248. #
  249. ##########################################################################
  250. SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions')
  251. SESSION_COOKIE_NAME = 'pga4_session'
  252. ##########################################################################
  253. # Mail server settings
  254. ##########################################################################
  255. # These settings are used when running in web server mode for confirming
  256. # and resetting passwords etc.
  257. # See: http://pythonhosted.org/Flask-Mail/ for more info
  258. MAIL_SERVER = 'localhost'
  259. MAIL_PORT = 25
  260. MAIL_USE_SSL = False
  261. MAIL_USE_TLS = False
  262. MAIL_USERNAME = ''
  263. MAIL_PASSWORD = ''
  264. MAIL_DEBUG = False
  265. # Flask-Security overrides Flask-Mail's MAIL_DEFAULT_SENDER setting, so
  266. # that should be set as such:
  267. SECURITY_EMAIL_SENDER = 'no-reply@localhost'
  268. ##########################################################################
  269. # Mail content settings
  270. ##########################################################################
  271. # These settings define the content of password reset emails
  272. SECURITY_EMAIL_SUBJECT_PASSWORD_RESET = "Password reset instructions for %s" \
  273. % APP_NAME
  274. SECURITY_EMAIL_SUBJECT_PASSWORD_NOTICE = "Your %s password has been reset" \
  275. % APP_NAME
  276. SECURITY_EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE = \
  277. "Your password for %s has been changed" % APP_NAME
  278. ##########################################################################
  279. # Upgrade checks
  280. ##########################################################################
  281. # Check for new versions of the application?
  282. UPGRADE_CHECK_ENABLED = True
  283. # Where should we get the data from?
  284. UPGRADE_CHECK_URL = 'https://www.pgadmin.org/versions.json'
  285. # What key should we look at in the upgrade data file?
  286. UPGRADE_CHECK_KEY = 'pgadmin4'
  287. # Which CA file should we use?
  288. # Default to cacert.pem in the same directory as config.py et al.
  289. CA_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
  290. "cacert.pem")
  291. # Check if the detected browser is supported
  292. CHECK_SUPPORTED_BROWSER = True
  293. ##########################################################################
  294. # Storage Manager storage url config settings
  295. # If user sets STORAGE_DIR to empty it will show all volumes if platform
  296. # is Windows, '/' if it is Linux, Mac or any other unix type system.
  297. # For example:
  298. # 1. STORAGE_DIR = get_drive("C") or get_drive() # return C:/ by default
  299. # where C can be any drive character such as "D", "E", "G" etc
  300. # 2. Set path manually like
  301. # STORAGE_DIR = "/path/to/directory/"
  302. ##########################################################################
  303. STORAGE_DIR = os.path.join(DATA_DIR, 'storage')
  304. ##########################################################################
  305. # Default locations for binary utilities (pg_dump, pg_restore etc)
  306. #
  307. # These are intentionally left empty in the main config file, but are
  308. # expected to be overridden by packagers in config_distro.py.
  309. #
  310. # A default location can be specified for each database driver ID, in
  311. # a dictionary. Either an absolute or relative path can be specified.
  312. # In cases where it may be difficult to know what the working directory
  313. # is, "$DIR" can be specified. This will be replaced with the path to the
  314. # top-level pgAdmin4.py file. For example, on macOS we might use:
  315. #
  316. # $DIR/../../SharedSupport
  317. #
  318. ##########################################################################
  319. DEFAULT_BINARY_PATHS = {
  320. "pg": "",
  321. "ppas": "",
  322. "gpdb": ""
  323. }
  324. ##########################################################################
  325. # Test settings - used primarily by the regression suite, not for users
  326. ##########################################################################
  327. # The default path for SQLite database for testing
  328. TEST_SQLITE_PATH = os.path.join(DATA_DIR, 'test_pgadmin4.db')
  329. ##########################################################################
  330. # Allows flask application to response to the each request asynchronously
  331. ##########################################################################
  332. THREADED_MODE = True
  333. ##########################################################################
  334. # Do not allow SQLALCHEMY to track modification as it is going to be
  335. # deprecated in future
  336. ##########################################################################
  337. SQLALCHEMY_TRACK_MODIFICATIONS = False
  338. ##########################################################################
  339. # Number of records to fetch in one batch in query tool when query result
  340. # set is large.
  341. ##########################################################################
  342. ON_DEMAND_RECORD_COUNT = 1000
  343. ##########################################################################
  344. # Allow users to display Gravatar image for their username in Server mode
  345. ##########################################################################
  346. SHOW_GRAVATAR_IMAGE = True
  347. ##########################################################################
  348. # Set cookie path
  349. ##########################################################################
  350. COOKIE_DEFAULT_PATH = '/'
  351. COOKIE_DEFAULT_DOMAIN = None
  352. SESSION_COOKIE_DOMAIN = None
  353. SESSION_COOKIE_SAMESITE = 'Lax'
  354. #########################################################################
  355. # Skip storing session in files and cache for specific paths
  356. #########################################################################
  357. SESSION_SKIP_PATHS = [
  358. '/misc/ping'
  359. ]
  360. ##########################################################################
  361. # Session expiration support
  362. ##########################################################################
  363. # SESSION_EXPIRATION_TIME is the interval in Days. Session will be
  364. # expire after the specified number of *days*.
  365. SESSION_EXPIRATION_TIME = 1
  366. # CHECK_SESSION_FILES_INTERVAL is interval in Hours. Application will check
  367. # the session files for cleanup after specified number of *hours*.
  368. CHECK_SESSION_FILES_INTERVAL = 24
  369. # USER_INACTIVITY_TIMEOUT is interval in Seconds. If the pgAdmin screen is left
  370. # unattended for <USER_INACTIVITY_TIMEOUT> seconds then the user will
  371. # be logged out. When set to 0, the timeout will be disabled.
  372. # If pgAdmin doesn't detect any activity in the time specified (in seconds),
  373. # the user will be forcibly logged out from pgAdmin. Set to zero to disable
  374. # the timeout.
  375. # Note: This is applicable only for SERVER_MODE=True.
  376. USER_INACTIVITY_TIMEOUT = 0
  377. # OVERRIDE_USER_INACTIVITY_TIMEOUT when set to True will override
  378. # USER_INACTIVITY_TIMEOUT when long running queries in the Query Tool
  379. # or Debugger are running. When the queries complete, the inactivity timer
  380. # will restart in this case. If set to False, user inactivity may cause
  381. # transactions or in-process debugging sessions to be aborted.
  382. OVERRIDE_USER_INACTIVITY_TIMEOUT = True
  383. ##########################################################################
  384. # SSH Tunneling supports only for Python 2.7 and 3.4+
  385. ##########################################################################
  386. SUPPORT_SSH_TUNNEL = True
  387. # Allow SSH Tunnel passwords to be saved if the user chooses.
  388. # Set to False to disable password saving.
  389. ALLOW_SAVE_TUNNEL_PASSWORD = False
  390. ##########################################################################
  391. # Master password is used to encrypt/decrypt saved server passwords
  392. # Applicable for desktop mode only
  393. ##########################################################################
  394. MASTER_PASSWORD_REQUIRED = True
  395. ##########################################################################
  396. # Allows pgAdmin4 to create session cookies based on IP address, so even
  397. # if a cookie is stolen, the attacker will not be able to connect to the
  398. # server using that stolen cookie.
  399. # Note: This can cause problems when the server is deployed in dynamic IP
  400. # address hosting environments, such as Kubernetes or behind load
  401. # balancers. In such cases, this option should be set to False.
  402. ##########################################################################
  403. ENHANCED_COOKIE_PROTECTION = True
  404. ##########################################################################
  405. # External Authentication Sources
  406. ##########################################################################
  407. # Default setting is internal
  408. # External Supported Sources: ldap
  409. # Multiple authentication can be achieved by setting this parameter to
  410. # ['ldap', 'internal']. pgAdmin will authenticate the user with ldap first,
  411. # in case of failure internal authentication will be done.
  412. AUTHENTICATION_SOURCES = ['internal']
  413. ##########################################################################
  414. # LDAP Configuration
  415. ##########################################################################
  416. # After ldap authentication, user will be added into the SQLite database
  417. # automatically, if set to True.
  418. # Set it to False, if user should not be added automatically,
  419. # in this case Admin has to add the user manually in the SQLite database.
  420. LDAP_AUTO_CREATE_USER = True
  421. # Connection timeout
  422. LDAP_CONNECTION_TIMEOUT = 10
  423. # Server connection details (REQUIRED)
  424. # example: ldap://<ip-address>:<port> or ldap://<hostname>:<port>
  425. LDAP_SERVER_URI = 'ldap://<ip-address>:<port>'
  426. # The LDAP attribute containing user names. In OpenLDAP, this may be 'uid'
  427. # whilst in AD, 'sAMAccountName' might be appropriate. (REQUIRED)
  428. LDAP_USERNAME_ATTRIBUTE = '<User-id>'
  429. ##########################################################################
  430. # 3 ways to configure LDAP as follows (Choose anyone):
  431. # 1. Dedicated User binding
  432. # LDAP Bind User DN Example: cn=username,dc=example,dc=com
  433. # Set this parameter to allow the connection to bind using a dedicated user.
  434. # After the connection is made, the pgadmin login user will be further
  435. # authenticated by the username and password provided
  436. # at the login screen.
  437. LDAP_BIND_USER = None
  438. # LDAP Bind User Password
  439. LDAP_BIND_PASSWORD = None
  440. # OR ####################
  441. # 2. Anonymous Binding
  442. # Set this parameter to allow the anonymous bind.
  443. # After the connection is made, the pgadmin login user will be further
  444. # authenticated by the username and password provided
  445. LDAP_ANONYMOUS_BIND = False
  446. # OR ####################
  447. # 3. Bind as pgAdmin user
  448. # BaseDN (REQUIRED)
  449. # AD example:
  450. # (&(objectClass=user)(memberof=CN=MYGROUP,CN=Users,dc=example,dc=com))
  451. # OpenLDAP example: CN=Users,dc=example,dc=com
  452. LDAP_BASE_DN = '<Base-DN>'
  453. ##########################################################################
  454. # Search ldap for further authentication (REQUIRED)
  455. # It can be optional while bind as pgAdmin user
  456. LDAP_SEARCH_BASE_DN = '<Search-Base-DN>'
  457. # Filter string for the user search.
  458. # For OpenLDAP, '(cn=*)' may well be enough.
  459. # For AD, you might use '(objectClass=user)' (REQUIRED)
  460. LDAP_SEARCH_FILTER = '(objectclass=*)'
  461. # Search scope for users (one of BASE, LEVEL or SUBTREE)
  462. LDAP_SEARCH_SCOPE = 'SUBTREE'
  463. # Use TLS? If the URI scheme is ldaps://, this is ignored.
  464. LDAP_USE_STARTTLS = False
  465. # TLS/SSL certificates. Specify if required, otherwise leave empty
  466. LDAP_CA_CERT_FILE = ''
  467. LDAP_CERT_FILE = ''
  468. LDAP_KEY_FILE = ''
  469. ##########################################################################
  470. # Local config settings
  471. ##########################################################################
  472. # Load distribution-specific config overrides
  473. try:
  474. from config_distro import *
  475. except ImportError:
  476. pass
  477. # Load local config overrides
  478. try:
  479. from config_local import *
  480. except ImportError:
  481. pass
  482. # Load system config overrides. We do this last, so that the sysadmin can
  483. # override anything they want from a config file that's in a protected system
  484. # directory and away from pgAdmin to avoid invalidating signatures.
  485. system_config_dir = '/etc/pgadmin'
  486. if sys.platform.startswith('win32'):
  487. system_config_dir = os.environ['CommonProgramFiles'] + '/pgadmin'
  488. elif sys.platform.startswith('darwin'):
  489. system_config_dir = '/Library/Preferences/pgadmin'
  490. if os.path.exists(system_config_dir + '/config_system.py'):
  491. try:
  492. sys.path.insert(0, system_config_dir)
  493. from config_system import *
  494. except ImportError:
  495. pass
  496. # Override DEFAULT_SERVER value from environment variable.
  497. if 'PGADMIN_CONFIG_DEFAULT_SERVER' in os.environ:
  498. DEFAULT_SERVER = os.environ['PGADMIN_CONFIG_DEFAULT_SERVER']
  499. # Disable USER_INACTIVITY_TIMEOUT when SERVER_MODE=False
  500. if not SERVER_MODE:
  501. USER_INACTIVITY_TIMEOUT = 0
上海开阖软件有限公司 沪ICP备12045867号-1