From 60dcc4fdf3868122c0099025d94b3c5579593473 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Thu, 31 Aug 2023 16:59:43 -0400 Subject: stackrpms base plus reverse-proxy --- instance/config.py | 3 ++ instance/sqlite.py | 3 ++ newspipe/bootstrap.py | 19 ++++++++++ newspipe/controllers/user.py | 8 ++++- newspipe/static/css/custom.css | 72 +++++++++++++++++++++++++++++++++----- newspipe/static/js/articles.js | 6 ++-- newspipe/static/js/config.js | 7 ++++ newspipe/templates/about.html | 1 + newspipe/templates/about_more.html | 2 +- newspipe/templates/article.html | 2 +- newspipe/templates/duplicates.html | 6 ++-- newspipe/templates/history.html | 2 +- newspipe/templates/home.html | 10 +++--- newspipe/templates/layout.html | 3 +- newspipe/templates/login.html | 2 +- newspipe/templates/management.html | 2 +- newspipe/web/__init__.py | 11 ++---- newspipe/web/views/user.py | 1 + newspipe/web/views/views.py | 4 +-- 19 files changed, 127 insertions(+), 37 deletions(-) create mode 100644 newspipe/static/js/config.js diff --git a/instance/config.py b/instance/config.py index 42e624cb..af7617a4 100644 --- a/instance/config.py +++ b/instance/config.py @@ -10,6 +10,9 @@ PORT = 5000 DEBUG = True API_ROOT = "/api/v2.0" +# Optional, and useful if you are using a reverse proxy with this virtual path prefix +#PREFIX = "/newspipe" + CSRF_ENABLED = True SECRET_KEY = "LCx3BchmHRxFzkEv4BqQJyeXRLXenf" SECURITY_PASSWORD_SALT = "L8gTsyrpRQEF8jNWQPyvRfv7U5kJkD" diff --git a/instance/sqlite.py b/instance/sqlite.py index 1f8d6206..c6eaa461 100644 --- a/instance/sqlite.py +++ b/instance/sqlite.py @@ -10,6 +10,9 @@ PORT = 5000 DEBUG = True API_ROOT = "/api/v2.0" +# Optional, and useful if you are using a reverse proxy with this virtual path prefix +#PREFIX = "/newspipe" + CSRF_ENABLED = True SECRET_KEY = "LCx3BchmHRxFzkEv4BqQJyeXRLXenf" SECURITY_PASSWORD_SALT = "L8gTsyrpRQEF8jNWQPyvRfv7U5kJkD" diff --git a/newspipe/bootstrap.py b/newspipe/bootstrap.py index 12044916..1c5c967d 100644 --- a/newspipe/bootstrap.py +++ b/newspipe/bootstrap.py @@ -44,6 +44,14 @@ def set_logging( handler.setLevel(log_level) logger.setLevel(log_level) +class ReverseProxied(object): + def __init__(self, app, script_name): + self.app = app + self.script_name = script_name + + def __call__(self, environ, start_response): + environ['SCRIPT_NAME'] = self.script_name + return self.app(environ, start_response) # Create Flask application application = Flask(__name__, instance_relative_config=True) @@ -63,6 +71,11 @@ else: set_logging(application.config["LOG_PATH"]) +_prefix = "" +if "PREFIX" in application.config: + application.wsgi_app = ReverseProxied(application.wsgi_app, script_name=application.config["PREFIX"]) + _prefix = application.config["PREFIX"] + db = SQLAlchemy(application) migrate = Migrate(application, db) @@ -100,3 +113,9 @@ application.jinja_env.filters["datetime"] = format_datetime application.jinja_env.filters["datetimeformat"] = datetimeformat # inject application in Jinja env application.jinja_env.globals["application"] = application + +@application.context_processor +def utility_processor(): + def prefix(): + return _prefix.rstrip("/") + return dict(prefix=prefix) diff --git a/newspipe/controllers/user.py b/newspipe/controllers/user.py index 00ffb96a..54137794 100644 --- a/newspipe/controllers/user.py +++ b/newspipe/controllers/user.py @@ -5,6 +5,7 @@ import ldap3 from ldap3.core.exceptions import LDAPBindError from werkzeug.security import check_password_hash from werkzeug.security import generate_password_hash +from urllib.parse import urlparse from .abstract import AbstractController from newspipe.bootstrap import application @@ -17,6 +18,11 @@ from newspipe.models import User logger = logging.getLogger(__name__) +# FOR LDAP +# Reference: session_app +import ldap3 +from ldap3.core.exceptions import LDAPBindError, LDAPPasswordIsMandatoryError + class UserController(AbstractController): _db_cls = User @@ -138,7 +144,7 @@ class LdapuserController: namelist = [] try: query = dns.resolver.query(f"_ldap._tcp.{domain}", "SRV") - except dns.resolver.NXDOMAIN: + except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): # no records exist that match the request, so we were probably # given a specific hostname, and an empty query will trigger # the logic below that will add the original domain to the list. diff --git a/newspipe/static/css/custom.css b/newspipe/static/css/custom.css index 70a24bf8..65625f0e 100644 --- a/newspipe/static/css/custom.css +++ b/newspipe/static/css/custom.css @@ -1,3 +1,13 @@ +:root { + /* primary color, for header bar, links, etc. */ + --main-color: #bc0900; + /* right side of header bar, border around some buttons, button hover color */ + --main-shade: #7f0600; + /* color of active button */ + --main-tint: #ed0b00; + /* very light color, not used at present, but designed for the background of (2n+1) table rows */ + --main-accent: #fcf5f4; +} html { position: relative; min-height: 100%; @@ -11,8 +21,9 @@ body { img { padding: 2px; } -a { - color: #3572B0; +a, a.nav-link { + /*color: #3572B0;*/ + color: var(--main-color); } #sidebar { @@ -33,28 +44,55 @@ a { rgb(255, 255, 255, 1); } +a:hover,a.nav-link:hover { + color: var(--main-shade); +} + .bg-newspipe-blue { /* background-color: #0082c9; */ - background-image: linear-gradient(40deg, #0082c9 0%, #30b6ff 100%); + /* background-image: linear-gradient(40deg, #0082c9 0%, #30b6ff 100%); */ + background-image: linear-gradient(40deg, var(--main-color) 0%, var(--main-shade) 100%); } .btn-primary { - background-color: #0082c9; + /* background-color: #0082c9; */ + background-color: var(--main-color); + border-color: var(--main-shade); opacity: 1; color: white; } .btn-secondary { - background-color: #0082c9; + /* background-color: #0082c9; */ + background-color: var(--main-color); opacity: 0.6; color: white; } +.btn-primary:hover, .btn-secondary { + background-color: var(--main-shade); +} .btn-outline-primary { - border-color: #0082c9; - color: #0082c9; + /* border-color: #0082c9; + color: #0082c9; */ + border-color: var(--main-color); + color: var(--main-color); +} + +.btn-primary:hover { + border-color: var(--main-shade); +} + +.btn-primary:active, .btn.btn-primary:active, .btn-secondary:active, a.btn.btn-primary:active { + background-color: var(--main-tint); + border: var(--main-tint); +} + +.dropdown-item:active, a.dropdown-item:active { + background-color: var(--main-tint); } .bg-primary { - background-color: #0082c9 !important; + /* background-color: #0082c9 !important; */ + background-color: var(--main-color) !important; opacity: 1; color: white; text-align: center; @@ -63,7 +101,12 @@ a { .badge-light { background-color: rgb(246, 248, 250); opacity: 1; - color: #0082c9 !important; + /* color: #0082c9 !important; */ + color: var(--main-color) !important; +} + +.badge:hover { + color: var(--main-shade); } /* Main table for the list of news */ @@ -113,3 +156,14 @@ a { .pagination-page-info { display: inline; } + +.fa-square-o::before, .fa-checked-square-o::before, .fa-star-o::before { + color: var(--main-color); +} + +/* + * Unnecessary +.table-striped tbody tr:nth-of-type(2n+1) { + background-color: var(--main-accent); +} + */ diff --git a/newspipe/static/js/articles.js b/newspipe/static/js/articles.js index f1cee6e7..29ebac2e 100644 --- a/newspipe/static/js/articles.js +++ b/newspipe/static/js/articles.js @@ -86,7 +86,7 @@ Array.prototype.map.call(nodes, function(node) { } // sends the updates to the server - fetch(API_ROOT + "article/" + article_id, { + fetch(prefix + API_ROOT + "article/" + article_id, { method: "PUT", headers: { 'Content-Type': 'application/json', @@ -157,7 +157,7 @@ Array.prototype.map.call(nodes, function(node) { } // sends the updates to the server - fetch(API_ROOT + "article/" + article_id, { + fetch(prefix + API_ROOT + "article/" + article_id, { method: "PUT", headers: { 'Content-Type': 'application/json', @@ -189,7 +189,7 @@ Array.prototype.map.call(nodes, function(node) { data = JSON.stringify(data); // sends the updates to the server - fetch(API_ROOT + "articles", { + fetch(prefix + API_ROOT + "articles", { method: "DELETE", headers: { 'Content-Type': 'application/json', diff --git a/newspipe/static/js/config.js b/newspipe/static/js/config.js new file mode 100644 index 00000000..7fad4388 --- /dev/null +++ b/newspipe/static/js/config.js @@ -0,0 +1,7 @@ +/* + * Set variables here for the javascript used by newspipe. + */ +var prefix = "/newspipe"; + +/* Set exactly one trailing slash on prefix. */ +prefix = prefix.replace(/\/+$/,"/"); diff --git a/newspipe/templates/about.html b/newspipe/templates/about.html index 45703ea0..973c086e 100644 --- a/newspipe/templates/about.html +++ b/newspipe/templates/about.html @@ -12,6 +12,7 @@

{{ _('Found a bug? Report it here.') }} {{ _('A documentation is available here.') }}

{{ _('More information') }} {{ _('about this instance.') }}

+

This fork's source


diff --git a/newspipe/templates/about_more.html b/newspipe/templates/about_more.html index 0df05852..6f01681f 100644 --- a/newspipe/templates/about_more.html +++ b/newspipe/templates/about_more.html @@ -5,7 +5,7 @@

{{ _('Information about this instance') }}