From af5a897d1de9cf86b082e3355ba74a4964e7ccc1 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Fri, 30 Mar 2018 21:20:47 +0200 Subject: [PATCH] Added SSL Options (#416) --- cps.py | 10 +- cps/cli.py | 24 ++ cps/templates/config_edit.html | 8 + cps/templates/layout.html | 4 +- cps/translations/de/LC_MESSAGES/messages.mo | Bin 303895 -> 304742 bytes cps/translations/de/LC_MESSAGES/messages.po | 297 ++++++++++-------- cps/translations/es/LC_MESSAGES/messages.po | 293 +++++++++-------- cps/translations/fr/LC_MESSAGES/messages.po | 293 +++++++++-------- cps/translations/it/LC_MESSAGES/messages.po | 293 +++++++++-------- cps/translations/ja/LC_MESSAGES/messages.po | 295 +++++++++-------- cps/translations/nl/LC_MESSAGES/messages.po | 293 +++++++++-------- cps/translations/pl/LC_MESSAGES/messages.po | 293 +++++++++-------- cps/translations/ru/LC_MESSAGES/messages.po | 293 +++++++++-------- .../zh_Hans_CN/LC_MESSAGES/messages.po | 293 +++++++++-------- cps/ub.py | 31 ++ cps/web.py | 36 ++- messages.pot | 289 +++++++++-------- readme.md | 13 +- 18 files changed, 1700 insertions(+), 1358 deletions(-) diff --git a/cps.py b/cps.py index d9231edd..9b911b23 100755 --- a/cps.py +++ b/cps.py @@ -30,11 +30,19 @@ if __name__ == '__main__': else: web.app.logger.info('Falling back to Tornado') # Max Buffersize set to 200MB - http_server = HTTPServer(WSGIContainer(web.app),max_buffer_size = 209700000) + if web.ub.config.get_config_certfile() and web.ub.config.get_config_keyfile(): + ssl={"certfile": web.ub.config.get_config_certfile(), + "keyfile": web.ub.config.get_config_keyfile()} + else: + ssl=None + http_server = HTTPServer(WSGIContainer(web.app), + max_buffer_size = 209700000, + ssl_options=ssl) http_server.listen(web.ub.config.config_port) IOLoop.instance().start() IOLoop.instance().close(True) + if web.helper.global_task == 0: web.app.logger.info("Performing restart of Calibre-web") os.execl(sys.executable, sys.executable, *sys.argv) diff --git a/cps/cli.py b/cps/cli.py index bd57d654..5e172626 100644 --- a/cps/cli.py +++ b/cps/cli.py @@ -3,11 +3,14 @@ import argparse import os +import sys parser = argparse.ArgumentParser(description='Calibre Web is a web app' ' providing a interface for browsing, reading and downloading eBooks\n', prog='cps.py') parser.add_argument('-p', metavar='path', help='path and name to settings db, e.g. /opt/cw.db') parser.add_argument('-g', metavar='path', help='path and name to gdrive db, e.g. /opt/gd.db') +parser.add_argument('-c', metavar='path', help='path and name to SSL certfile, e.g. /opt/test.cert, works only in combination with keyfile') +parser.add_argument('-k', metavar='path', help='path and name to SSL keyfile, e.g. /opt/test.key, works only in combination with certfile') args = parser.parse_args() generalPath = os.path.normpath(os.getenv("CALIBRE_DBPATH", @@ -22,3 +25,24 @@ if args.g: else: gdpath = os.path.join(generalPath, "gdrive.db") +certfilepath = None +keyfilepath = None +if args.c: + if os.path.isfile(args.c): + certfilepath = args.c + else: + print("Certfilepath is invalid. Exiting...") + sys.exit(1) + +if args.c is "": + certfilepath = "" + +if args.k: + if os.path.isfile(args.k): + keyfilepath = args.k + else: + print("Keyfilepath is invalid. Exiting...") + sys.exit(1) + +if args.k is "": + keyfilepath = "" diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 84e95847..7fecaa4f 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -52,6 +52,14 @@ +
+ + +
+
+ + +
diff --git a/cps/templates/layout.html b/cps/templates/layout.html index ea0aefe3..5e05db7d 100644 --- a/cps/templates/layout.html +++ b/cps/templates/layout.html @@ -100,8 +100,8 @@ {% endfor %}