1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-30 13:30:00 +00:00

Added variable to allow loading cover from localhost

This commit is contained in:
Ozzie Isaacs 2022-01-23 13:43:35 +01:00
parent 35f6f4c727
commit d9c10b830a
2 changed files with 10 additions and 6 deletions

View File

@ -45,6 +45,7 @@ parser.add_argument('-v', '--version', action='version', help='Shows version num
parser.add_argument('-i', metavar='ip-address', help='Server IP-Address to listen') parser.add_argument('-i', metavar='ip-address', help='Server IP-Address to listen')
parser.add_argument('-s', metavar='user:pass', help='Sets specific username to new password') parser.add_argument('-s', metavar='user:pass', help='Sets specific username to new password')
parser.add_argument('-f', action='store_true', help='Flag is depreciated and will be removed in next version') parser.add_argument('-f', action='store_true', help='Flag is depreciated and will be removed in next version')
parser.add_argument('-l', action='store_true', help='Allow loading covers from localhost')
args = parser.parse_args() args = parser.parse_args()
settingspath = args.p or os.path.join(_CONFIG_DIR, "app.db") settingspath = args.p or os.path.join(_CONFIG_DIR, "app.db")
@ -77,6 +78,8 @@ if (args.k and not args.c) or (not args.k and args.c):
if args.k == "": if args.k == "":
keyfilepath = "" keyfilepath = ""
# load covers from localhost
allow_localhost = args.l or None
# handle and check ip address argument # handle and check ip address argument
ip_address = args.i or None ip_address = args.i or None
if ip_address: if ip_address:

View File

@ -46,7 +46,7 @@ try:
except ImportError: except ImportError:
use_unidecode = False use_unidecode = False
from . import calibre_db from . import calibre_db, cli
from .tasks.convert import TaskConvert from .tasks.convert import TaskConvert
from . import logger, config, get_locale, db, ub from . import logger, config, get_locale, db, ub
from . import gdriveutils as gd from . import gdriveutils as gd
@ -584,11 +584,12 @@ def get_book_cover_internal(book, use_generic_cover_on_failure):
# saves book cover from url # saves book cover from url
def save_cover_from_url(url, book_path): def save_cover_from_url(url, book_path):
try: try:
# 127.0.x.x, localhost, [::1], [::ffff:7f00:1] if not cli.allow_localhost:
ip = socket.getaddrinfo(urlparse(url).hostname, 0)[0][4][0] # 127.0.x.x, localhost, [::1], [::ffff:7f00:1]
if ip.startswith("127.") or ip.startswith('::ffff:7f') or ip == "::1": ip = socket.getaddrinfo(urlparse(url).hostname, 0)[0][4][0]
log.error("Localhost was accessed for cover upload") if ip.startswith("127.") or ip.startswith('::ffff:7f') or ip == "::1":
return False, _("You are not allowed to access localhost for cover uploads") log.error("Localhost was accessed for cover upload")
return False, _("You are not allowed to access localhost for cover uploads")
img = requests.get(url, timeout=(10, 200)) # ToDo: Error Handling img = requests.get(url, timeout=(10, 200)) # ToDo: Error Handling
img.raise_for_status() img.raise_for_status()
return save_cover(img, book_path) return save_cover(img, book_path)