From 2c5192563803001b60d3ca89b04e11441bcd1503 Mon Sep 17 00:00:00 2001 From: Pradip Parkale Date: Tue, 1 Jun 2021 20:18:24 +0530 Subject: [PATCH] =?UTF-8?q?Added=20OS,=20Browser,=20Configuration=20detail?= =?UTF-8?q?s=C2=A0in=20the=20About=20dialog.=20Fixes=20#6231?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en_US/release_notes_5_4.rst | 1 + requirements.txt | 2 + runtime/package.json | 1 + web/pgadmin/about/__init__.py | 64 ++++++++++++++++++-- web/pgadmin/about/static/js/about.js | 17 ++++-- web/pgadmin/about/templates/about/index.html | 46 ++++++++------ 6 files changed, 103 insertions(+), 28 deletions(-) diff --git a/docs/en_US/release_notes_5_4.rst b/docs/en_US/release_notes_5_4.rst index 97a9c7d08..31487baf4 100644 --- a/docs/en_US/release_notes_5_4.rst +++ b/docs/en_US/release_notes_5_4.rst @@ -11,6 +11,7 @@ New features | `Issue #2341 `_ - Added support to launch PSQL for the connected database server. | `Issue #4064 `_ - Added window maximize/restore functionality for properties dialog. +| `Issue #6231 `_ - Added OS, Browser, Configuration details in the About dialog. | `Issue #6395 `_ - Added support to rotate the pgadmin log file on the basis of Size and Age. Housekeeping diff --git a/requirements.txt b/requirements.txt index a14774736..e3133e368 100644 --- a/requirements.txt +++ b/requirements.txt @@ -38,3 +38,5 @@ Flask-BabelEx==0.* gssapi==1.6.* flask-socketio>=5.0.1 eventlet==0.30.2 +httpagentparser==1.9.* +user_agents==2.2.* diff --git a/runtime/package.json b/runtime/package.json index bdc024b18..82628732d 100644 --- a/runtime/package.json +++ b/runtime/package.json @@ -6,6 +6,7 @@ "author": "pgAdmin Development Team (https://www.pgadmin.org/)", "license": "PostgreSQL", "chromium-args": "--disable-popup-blocking", + "user-agent": "Nwjs:%nwver-%osinfo-%chromium_ver", "window": { "width": 440, "height": 170, diff --git a/web/pgadmin/about/__init__.py b/web/pgadmin/about/__init__.py index 94ffefe6e..a27248559 100644 --- a/web/pgadmin/about/__init__.py +++ b/web/pgadmin/about/__init__.py @@ -10,13 +10,16 @@ """A blueprint module implementing the about box.""" import sys -from flask import Response, render_template, __version__, url_for +from flask import Response, render_template, __version__, url_for, request from flask_babelex import gettext from flask_security import current_user, login_required from pgadmin.utils import PgAdminModule from pgadmin.utils.menu import MenuItem from pgadmin.utils.constants import MIMETYPE_APP_JS import config +import httpagentparser +from pgadmin.model import User +from user_agents import parse MODULE_NAME = 'about' @@ -59,23 +62,74 @@ blueprint = AboutModule(MODULE_NAME, __name__, static_url_path='') @login_required def index(): """Render the about box.""" - info = { - 'python_version': sys.version, - 'flask_version': __version__ - } + info = {} + # Get OS , NW.js, Browser details + browser, os_details, nwjs_version = detect_browser(request) + + if nwjs_version: + info['nwjs'] = nwjs_version + + info['browser_details'] = browser + info['os_details'] = os_details + info['config_db'] = config.SQLITE_PATH + info['log_file'] = config.LOG_FILE if config.SERVER_MODE: info['app_mode'] = gettext('Server') + admin = is_admin(current_user.email) + info['admin'] = admin else: info['app_mode'] = gettext('Desktop') info['current_user'] = current_user.email + settings = '' + for setting in dir(config): + if not setting.startswith('_') and setting.isupper() and \ + setting not in ['CSRF_SESSION_KEY', + 'SECRET_KEY', + 'SECURITY_PASSWORD_SALT', + 'SECURITY_PASSWORD_HASH', + 'ALLOWED_HOSTS']: + settings = settings + '{} = {}\n'.format(setting, + getattr(config, setting)) + + info['settings'] = settings + return render_template( MODULE_NAME + '/index.html', info=info, _=gettext ) +def is_admin(load_user): + user = User.query.filter_by(email=load_user).first() + return user.has_role("Administrator") + + +def detect_browser(request): + """This function returns the browser and os details""" + nwjs_version = None + agent = request.environ.get('HTTP_USER_AGENT') + user_agent = parse(agent) + + if 'Nwjs' in agent: + agent = agent.split('-') + nwjs_version = agent[0].split(':')[1] + browser = 'Chromium' + ' ' + agent[2] + os_details = user_agent.os.family + ' ' + user_agent.os.version_string + + else: + browser = httpagentparser.detect(agent) + os_details = user_agent.os.family + ' ' + user_agent.os.version_string + if not browser: + browser = agent.split('/')[0] + else: + browser = browser['browser']['name'] + ' ' + browser['browser'][ + 'version'] + + return browser, os_details, nwjs_version + + @blueprint.route("/about.js") @login_required def script(): diff --git a/web/pgadmin/about/static/js/about.js b/web/pgadmin/about/static/js/about.js index c6c73e6c2..4dfa6b149 100644 --- a/web/pgadmin/about/static/js/about.js +++ b/web/pgadmin/about/static/js/about.js @@ -9,9 +9,9 @@ define( ['jquery', 'alertify', 'sources/pgadmin', 'sources/gettext', - 'sources/url_for','sources/utils', + 'sources/url_for','sources/utils','pgadmin.user_management.current_user', ], - function($, alertify, pgAdmin, gettext, url_for, commonUtils) { + function($, alertify, pgAdmin, gettext, url_for, commonUtils, current_user) { pgAdmin = pgAdmin || window.pgAdmin || {}; /* Return back, this has been called more than once */ @@ -52,7 +52,6 @@ define( prepare:function() { this.setContent(this.message); - }, }; }); @@ -60,9 +59,15 @@ define( $.get(url_for('about.index'), function(data) { - alertify.aboutDialog( - gettext('About %s', pgAdmin.Browser.utils.app_name), data - ).resizeTo(pgAdmin.Browser.stdW.md, pgAdmin.Browser.stdH.md); + if(!current_user.is_admin && pgAdmin.server_mode){ + alertify.aboutDialog( + gettext('About %s', pgAdmin.Browser.utils.app_name), data + ).resizeTo(pgAdmin.Browser.stdW.md, 300); + }else{ + alertify.aboutDialog( + gettext('About %s', pgAdmin.Browser.utils.app_name), data + ).resizeTo(750, 470); + } }); }, }; diff --git a/web/pgadmin/about/templates/about/index.html b/web/pgadmin/about/templates/about/index.html index 607e6c298..e1c94f0bf 100644 --- a/web/pgadmin/about/templates/about/index.html +++ b/web/pgadmin/about/templates/about/index.html @@ -3,18 +3,6 @@
{{ _('Version') }}
{{ config.APP_VERSION }}
-
-
{{ _('Copyright') }}
-
{{ config.APP_COPYRIGHT }}
-
-
-
{{ _('Python Version') }}
-
{{ info.python_version }}
-
-
-
{{ _('Flask Version') }}
-
{{ info.flask_version }}
-
{{ _('Application Mode') }}
{{ info.app_mode }}
@@ -23,10 +11,34 @@
{{ _('Current User') }}
{{ info.current_user }}
-
-
{{ config.APP_NAME }} {{ _('logo') }}
+ {% if info.nwjs %} +
+
{{ _('NW.js Version') }}
+
{{ info.nwjs }}
+ {% endif %} +
+
{{ _('Browser') }}
+
{{ info.browser_details }}
+
+
+
{{ _('Operating System') }}
+
{{ info.os_details }}
+
+
+
{{ _('pgAdmin Database File') }}
+
{{ info.config_db }}
+
+
+
{{ _('Log File') }}
+
{{ info.log_file }}
+
+ {%if (info.app_mode == 'Desktop') or (info.app_mode == 'Server' and info.admin)%} +
+
{{ _('Server Configuration') }}
+
+
+
+
+ {% endif %}