From fa99f6e684e7487522b987e1fff1af00915043db Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Wed, 16 May 2018 23:11:28 -0700 Subject: [PATCH] Add self-hosted newsletter authentication metnods --- data/interfaces/default/css/tautulli.css | 9 ++- data/interfaces/default/newsletter_auth.html | 43 +++++++++++ data/interfaces/default/settings.html | 79 ++++++++++++++++---- plexpy/config.py | 2 + plexpy/webserve.py | 23 +++++- 5 files changed, 139 insertions(+), 17 deletions(-) create mode 100644 data/interfaces/default/newsletter_auth.html diff --git a/data/interfaces/default/css/tautulli.css b/data/interfaces/default/css/tautulli.css index 5c9c8076..1b150465 100644 --- a/data/interfaces/default/css/tautulli.css +++ b/data/interfaces/default/css/tautulli.css @@ -3525,8 +3525,7 @@ a.no-highlight:hover { } .login-logo { margin: 0 auto 50px auto; - width: 340px; - height: 100px; + text-align: center; } .login-container .form-group { margin-bottom: 20px; @@ -4098,4 +4097,8 @@ a[data-tab-destination] { margin-top: 10px !important; padding-top: 10px; border-top: 1px solid #444; -} \ No newline at end of file +} +.newsletter-logo { + margin: 0 auto 50px auto; + text-align: center; +} diff --git a/data/interfaces/default/newsletter_auth.html b/data/interfaces/default/newsletter_auth.html new file mode 100644 index 00000000..770ba26a --- /dev/null +++ b/data/interfaces/default/newsletter_auth.html @@ -0,0 +1,43 @@ +<% + import urllib +%> + + + + + + Tautulli - ${title} + + + + + + + + +
+
+
+ +
+
+
+ + diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 41734d64..8dffc303 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -965,10 +965,35 @@

Enable to host newsletters on your own domain. This will generate a link to an HTML page where you can view the newsletter.

-

- Note: The ${http_root}newsletter endpoint on your domain must be publicly accessible from the internet. -

-

Warning: Public Tautulli domain not set under Web Interface.

+
+

+ Note: The ${http_root}newsletter endpoint on your domain must be publicly accessible from the internet. +

+

Warning: Public Tautulli domain not set under Web Interface.

+
+
+ +
+
+ +
+
+

Select the authentication method to use for self-hosted newsletters.

+ +
+
+ +
+
+ +
+
+

Enter the password that will be required to view self-hosted newsletters.

+
@@ -1025,10 +1050,12 @@

Select where to host Plex images for notifications and newsletters.

-

- You can register a new Imgur application here.
- Warning: Imgur uploads are rate-limited and newsletters may exceed the limit. Please use Cloudinary for newsletters instead. -

+
+

+ You can register a new Imgur application here.
+ Warning: Imgur uploads are rate-limited and newsletters may exceed the limit. Please use Cloudinary for newsletters instead. +

+
@@ -1040,13 +1067,17 @@
-

Note: The ${http_root}image endpoint on your domain must be publicly accessible from the internet.

-

Warning: Public Tautulli domain not set under Web Interface.

+
+

Note: The ${http_root}image endpoint on your domain must be publicly accessible from the internet.

+

Warning: Public Tautulli domain not set under Web Interface.

+
-

- You can sign up for Cloudinary here.
-

+
+

+ You can sign up for Cloudinary here.
+

+
@@ -2680,6 +2711,28 @@ $(document).ready(function() { newsletterUploadEnabled(); }); + function newsletterPasswordEnabled() { + if ($('#newsletter_auth').val() === '1') { + $('#newsletter_password_option').slideDown(); + } else { + $('#newsletter_password_option').slideUp(); + } + if ($('#newsletter_auth').val() === '2' && !($('#allow_guest_access').is(':checked'))) { + $('.newsletter-guest-access-warning').show(); + } else { + $('.newsletter-guest-access-warning').hide(); + } + } + newsletterPasswordEnabled(); + + $('#newsletter_auth').change(function () { + newsletterPasswordEnabled(); + }); + + $('#allow_guest_access').click(function () { + newsletterPasswordEnabled(); + }) + $('body').on('click', 'a[data-tab-destination]', function () { var tab = $(this).data('tab-destination'); $("a[href=#" + tab + "]").click(); diff --git a/plexpy/config.py b/plexpy/config.py index 920e63ac..20aee534 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -312,6 +312,8 @@ _CONFIG_DEFINITIONS = { 'MONITOR_REMOTE_ACCESS': (int, 'Monitoring', 0), 'MONITORING_INTERVAL': (int, 'Monitoring', 60), 'MONITORING_USE_WEBSOCKET': (int, 'Monitoring', 0), + 'NEWSLETTER_AUTH': (int, 'Newsletter', 0), + 'NEWSLETTER_PASSWORD': (str, 'Newsletter', ''), 'NEWSLETTER_CUSTOM_DIR': (str, 'Newsletter', ''), 'NEWSLETTER_INLINE_STYLES': (int, 'Newsletter', 1), 'NEWSLETTER_TEMPLATES': (str, 'Newsletter', 'newsletters'), diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 4ddc7b42..418dfc41 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -56,7 +56,7 @@ import web_socket from plexpy.api2 import API2 from plexpy.helpers import checked, addtoapi, get_ip, create_https_certificates, build_datatables_json from plexpy.session import get_session_info, get_session_user_id, allow_session_user, allow_session_library -from plexpy.webauth import AuthController, requireAuth, member_of, name_is +from plexpy.webauth import AuthController, requireAuth, member_of def serve_template(templatename, **kwargs): @@ -2826,6 +2826,8 @@ class WebInterface(object): "show_advanced_settings": plexpy.CONFIG.SHOW_ADVANCED_SETTINGS, "newsletter_dir": plexpy.CONFIG.NEWSLETTER_DIR, "newsletter_self_hosted": checked(plexpy.CONFIG.NEWSLETTER_SELF_HOSTED), + "newsletter_auth": plexpy.CONFIG.NEWSLETTER_AUTH, + "newsletter_password": plexpy.CONFIG.NEWSLETTER_PASSWORD, "newsletter_inline_styles": checked(plexpy.CONFIG.NEWSLETTER_INLINE_STYLES), "newsletter_custom_dir": plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR } @@ -5741,6 +5743,25 @@ class WebInterface(object): @cherrypy.expose def newsletter(self, *args, **kwargs): + request_uri = cherrypy.request.wsgi_environ['REQUEST_URI'] + if plexpy.CONFIG.NEWSLETTER_AUTH == 2: + redirect_uri = request_uri.replace('/newsletter', '/newsletter_auth') + raise cherrypy.HTTPRedirect(redirect_uri) + + elif plexpy.CONFIG.NEWSLETTER_AUTH == 1 and plexpy.CONFIG.NEWSLETTER_PASSWORD: + if kwargs.pop('key', None) == plexpy.CONFIG.NEWSLETTER_PASSWORD: + return self.newsletter_auth(*args, **kwargs) + else: + return serve_template(templatename="newsletter_auth.html", + title="Newsletter Login", + uri=request_uri) + + else: + return self.newsletter_auth(*args, **kwargs) + + @cherrypy.expose + @requireAuth() + def newsletter_auth(self, *args, **kwargs): if args: # Keep this for backwards compatibility for images through /newsletter/image if len(args) >= 2 and args[0] == 'image':