Option to use HTTP basic authentication

This commit is contained in:
JonnyWong16 2016-05-22 14:23:55 -07:00
parent f6a3bc57e2
commit 16cbfed20b
5 changed files with 48 additions and 10 deletions

View file

@ -185,6 +185,7 @@ _CONFIG_DEFINITIONS = {
'HTTPS_KEY': (str, 'General', ''),
'HTTPS_DOMAIN': (str, 'General', 'localhost'),
'HTTPS_IP': (str, 'General', '127.0.0.1'),
'HTTP_BASIC_AUTH': (int, 'General', 0),
'HTTP_ENVIRONMENT': (str, 'General', 'production'),
'HTTP_HASH_PASSWORD': (int, 'General', 0),
'HTTP_HASHED_PASSWORD': (int, 'General', 0),

View file

@ -2247,6 +2247,7 @@ class WebInterface(object):
config = {
"allow_guest_access": checked(plexpy.CONFIG.ALLOW_GUEST_ACCESS),
"http_basic_auth": checked(plexpy.CONFIG.HTTP_BASIC_AUTH),
"http_hash_password": checked(plexpy.CONFIG.HTTP_HASH_PASSWORD),
"http_hashed_password": plexpy.CONFIG.HTTP_HASHED_PASSWORD,
"http_host": plexpy.CONFIG.HTTP_HOST,
@ -2367,7 +2368,7 @@ class WebInterface(object):
"ip_logging_enable", "movie_logging_enable", "tv_logging_enable", "music_logging_enable",
"notify_consecutive", "notify_upload_posters", "notify_recently_added", "notify_recently_added_grandparent",
"monitor_pms_updates", "monitor_remote_access", "get_file_sizes", "log_blacklist", "http_hash_password",
"allow_guest_access", "cache_images", "http_proxy"
"allow_guest_access", "cache_images", "http_proxy", "http_basic_auth"
]
for checked_config in checked_configs:
if checked_config not in kwargs:

View file

@ -66,8 +66,13 @@ def initialize(options):
if options['http_password']:
logger.info(u"PlexPy WebStart :: Web server authentication is enabled, username is '%s'", options['http_username'])
options_dict['tools.sessions.on'] = auth_enabled = session_enabled = True
cherrypy.tools.auth = cherrypy.Tool('before_handler', webauth.check_auth)
if options['http_basic_auth']:
auth_enabled = session_enabled = False
basic_auth_enabled = True
else:
options_dict['tools.sessions.on'] = auth_enabled = session_enabled = True
basic_auth_enabled = False
cherrypy.tools.auth = cherrypy.Tool('before_handler', webauth.check_auth)
else:
auth_enabled = session_enabled = False
@ -88,7 +93,14 @@ def initialize(options):
'application/javascript'],
'tools.auth.on': auth_enabled,
'tools.sessions.on': session_enabled,
'tools.sessions.timeout': 30 * 24 * 60 # 30 days
'tools.sessions.timeout': 30 * 24 * 60, # 30 days
'tools.auth_basic.on': basic_auth_enabled,
'tools.auth_basic.realm': 'PlexPy web server',
'tools.auth_basic.checkpassword': cherrypy.lib.auth_basic.checkpassword_dict({
options['http_username']: options['http_password']})
},
'/api': {
'tools.auth_basic.on': False
},
'/interfaces': {
'tools.staticdir.on': True,
@ -199,7 +211,7 @@ def initialize(options):
'tools.expires.secs': 60 * 60 * 24 * 30, # 30 days
'tools.auth.on': False,
'tools.sessions.on': False
},
}
}
# Prevent time-outs