Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
OPDS Authentication, Cleanup, and Config Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WillowMist authored and evilhero committed Oct 31, 2017
1 parent 9f739d8 commit e1f4cab
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 32 deletions.
4 changes: 4 additions & 0 deletions Mylar.py
Expand Up @@ -240,6 +240,10 @@ def main():
'https_chain': mylar.CONFIG.HTTPS_CHAIN,
'http_username': mylar.CONFIG.HTTP_USERNAME,
'http_password': mylar.CONFIG.HTTP_PASSWORD,
'opds_enable': mylar.CONFIG.OPDS_ENABLE,
'opds_authentication': mylar.CONFIG.OPDS_AUTHENTICATION,
'opds_username': mylar.CONFIG.OPDS_USERNAME,
'opds_password': mylar.CONFIG.OPDS_PASSWORD,
}

# Try to start the server.
Expand Down
66 changes: 66 additions & 0 deletions data/interfaces/default/config.html
Expand Up @@ -204,6 +204,34 @@ <h1 class="clearfix"><img src="interfaces/default/images/icon_gear.png" alt="set
</div>
</div>
</fieldset>
<fieldset>
<legend>OPDS</legend>
<div class="row">
<div class="row_checkbox">
<input id="opds_enable" type="checkbox" name="opds_enable" value="1" ${config['opds_enable']} /><label>Enable OPDS</label>
</div>
<div id="opdsoptions">
<div class="row_checkbox">
<input id="opds_authentication" type="checkbox" name="opds_authentication" value="1" ${config['opds_authentication']} /><label>OPDS Requires Credentials</label>
<%
opds_notes = "Require authentication for OPDS. If checked\nyou will need to provide a username/password.\nThe service user name will work (if set). Additionally,\nyou can provide a user with only OPDS access below.\nNOTE: If this is not checked, OPDS will be available\nwithout a password."
%>
<a href="#" title="${opds_notes}"><img src="interfaces/default/images/info32.png" height="16" alt="" /></a>
<div id="opdscredentials">
<div class="row">
<label>OPDS Username</label>
<input type="text" name="opds_username" value="${config['opds_username']}" size="30">
</div>

<div class="row">
<label>OPDS Password</label>
<input type="password" name="opds_password" value="${config['opds_password']| h}" size="30">
</div>
</div>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Interval</legend>
<div class="row">
Expand Down Expand Up @@ -1366,7 +1394,45 @@ <h3><img src="interfaces/default/images/slack.png" style="vertical-align: middle
$("#apioptions").slideUp();
}
});
if ($("#opds_enable").is(":checked"))
{
$("#opdsoptions").show();
}
else
{
$("#opdsoptions").hide();
}

$("#opds_enable").click(function(){
if ($("#opds_enable").is(":checked"))
{
$("#opdsoptions").slideDown();
}
else
{
$("#opdsoptions").slideUp();
}
});

if ($("#opds_authentication").is(":checked"))
{
$("#opdscredentials").show();
}
else
{
$("#opdscredentials").hide();
}

$("#opds_authentication").click(function(){
if ($("#opds_authentication").is(":checked"))
{
$("#opdscredentials").slideDown();
}
else
{
$("#opdscredentials").slideUp();
}
});

if ($("#cbr2cbz").is(":checked"))
{
Expand Down
12 changes: 6 additions & 6 deletions mylar/config.py
Expand Up @@ -44,8 +44,8 @@
'CORRECT_METADATA': (bool, 'General', False),
'MOVE_FILES': (bool, 'General', False),
'RENAME_FILES': (bool, 'General', False),
'FOLDER_FORMAT': (str, 'General', None),
'FILE_FORMAT': (str, 'General', None),
'FOLDER_FORMAT': (str, 'General', '$Series ($Year)'),
'FILE_FORMAT': (str, 'General', '$Series $Annual $Issue ($Year)'),
'REPLACE_SPACES': (bool, 'General', False),
'REPLACE_CHAR': (str, 'General', None),
'ZERO_LEVEL': (bool, 'General', False),
Expand Down Expand Up @@ -104,7 +104,7 @@
'CV_VERIFY': (bool, 'CV', True),
'CV_ONLY': (bool, 'CV', True),
'CV_ONETIMER': (bool, 'CV', True),
'CVINFO': (bool, 'CV', True),
'CVINFO': (bool, 'CV', False),

'LOG_DIR' : (str, 'Logs', None),
'MAX_LOGSIZE' : (int, 'Logs', 10000000),
Expand Down Expand Up @@ -320,9 +320,9 @@
'QBITTORRENT_STARTONLOAD': (bool, 'qBittorrent', False),

'OPDS_ENABLE': (bool, 'OPDS', False),
'OPDS_READONLYUSER': (bool, 'OPDS', False),
'OPDS_READONLYUSERNAME': (str, 'OPDS', None),
'OPDS_READONLYPASSWORD': (str, 'OPDS', None),
'OPDS_AUTHENTICATION': (bool, 'OPDS', False),
'OPDS_USERNAME': (str, 'OPDS', None),
'OPDS_PASSWORD': (str, 'OPDS', None),

})

Expand Down
56 changes: 32 additions & 24 deletions mylar/opds.py
Expand Up @@ -20,7 +20,6 @@
from mylar import db, mb, importer, search, PostProcessor, versioncheck, logger
import simplejson as simplejson
import cherrypy
from lxml import etree
import os
import urllib2
import cache
Expand Down Expand Up @@ -81,12 +80,9 @@ def fetchData(self):
return self.data

def _error_with_message(self, message):
feed = etree.Element("feed")

error = etree.SubElement(feed,'error')
error.text = message
error = '<feed><error>%s</error></feed>' % message
cherrypy.response.headers['Content-Type'] = "text/xml"
return etree.tostring(feed)
return error

def _root(self, **kwargs):
myDB = db.DBConnection()
Expand All @@ -96,23 +92,9 @@ def _root(self, **kwargs):
feed['updated'] = mylar.helpers.now()
links = []
entries=[]
links.append({
'href': '/opds',
'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
'rel': 'start',
'title': 'Home'
})
links.append({
'href': '/opds',
'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
'rel': 'self',
})
links.append({
'href': '/opds?cmd=search',
'type': 'application/opensearchdescription+xml',
'rel': 'search',
'title': 'Search',
})
links.append(getLink(href='/opds',type='application/atom+xml;profile=opds-catalog;kind=navigation', rel='start', title='Home'))
links.append(getLink(href='/opds',type='application/atom+xml;profile=opds-catalog;kind=navigation',rel='self'))
links.append(getLink(href='/opds?cmd=search', type='application/opensearchdescription+xml',rel='search',title='Search'))
publishers = myDB.select("SELECT ComicPublisher from comics GROUP BY ComicPublisher")
if len(publishers) > 0:
count = len(publishers)
Expand Down Expand Up @@ -142,7 +124,33 @@ def _root(self, **kwargs):
'kind': 'navigation'
}
)
storyArcs = mylar.helpers.listStoryArcs()
logger.debug(storyArcs)
if len(storyArcs) > 0:
entries.append(
{
'title': 'Story Arcs (%s)' % len(storyArcs),
'id': 'StoryArcs',
'updated': mylar.helpers.now(),
'content': 'List of Story Arcs',
'href': '/opds?cmd=StoryArcs',
'kind': 'navigation'
}
)

feed['links'] = links
feed['entries'] = entries
self.data = feed
return
return

def getLink(href=None, type=None, rel=None, title=None):
link = {}
if href:
link['href'] = href
if type:
link['type'] = type
if rel:
link['rel'] = rel
if title:
link['title'] = title
return link
9 changes: 7 additions & 2 deletions mylar/webserve.py
Expand Up @@ -4353,7 +4353,11 @@ def config(self):
"config_file": mylar.CONFIG_FILE,
"branch_history": 'None',
# "branch_history" : br_hist,
"log_dir": mylar.CONFIG.LOG_DIR
"log_dir": mylar.CONFIG.LOG_DIR,
"opds_enable": helpers.checked(mylar.CONFIG.OPDS_ENABLE),
"opds_authentication": helpers.checked(mylar.CONFIG.OPDS_AUTHENTICATION),
"opds_username": mylar.CONFIG.OPDS_USERNAME,
"opds_password": mylar.CONFIG.OPDS_PASSWORD,
}
return serve_template(templatename="config.html", title="Settings", config=config, comicinfo=comicinfo)
config.exposed = True
Expand Down Expand Up @@ -4570,7 +4574,8 @@ def configUpdate(self, **kwargs):
'enable_meta', 'cbr2cbz_only', 'ct_tag_cr', 'ct_tag_cbl', 'ct_cbz_overwrite', 'rename_files', 'replace_spaces', 'zero_level',
'lowercase_filenames', 'autowant_upcoming', 'autowant_all', 'comic_cover_local', 'cvinfo', 'snatchedtorrent_notify',
'prowl_enabled', 'prowl_onsnatch', 'nma_enabled', 'nma_onsnatch', 'pushover_enabled', 'pushover_onsnatch', 'boxcar_enabled',
'boxcar_onsnatch', 'pushbullet_enabled', 'pushbullet_onsnatch', 'telegram_enabled', 'telegram_onsnatch', 'slack_enabled', 'slack_onsnatch' ]
'boxcar_onsnatch', 'pushbullet_enabled', 'pushbullet_onsnatch', 'telegram_enabled', 'telegram_onsnatch', 'slack_enabled', 'slack_onsnatch',
'opds_enable', 'opds_authentication']

for checked_config in checked_configs:
if checked_config not in kwargs:
Expand Down
12 changes: 12 additions & 0 deletions mylar/webstart.py
Expand Up @@ -125,6 +125,18 @@ def initialize(options):
})
conf['/api'] = {'tools.auth_basic.on': False}

if options['opds_authentication']:
user_list = {}
if len(options['opds_username']) > 0:
user_list[options['opds_username']] = options['opds_password']
if options['http_password'] is not None and options['http_username'] != options['opds_username']:
user_list[options['http_username']] = options['http_password']
conf['/opds'] = {'tools.auth_basic.on': True,
'tools.auth_basic.realm': 'Mylar OPDS',
'tools.auth_basic.checkpassword': cherrypy.lib.auth_basic.checkpassword_dict(user_list)}
else:
conf['/opds'] = {'tools.auth_basic.on': False}

# Prevent time-outs
cherrypy.engine.timeout_monitor.unsubscribe()

Expand Down

0 comments on commit e1f4cab

Please sign in to comment.