2015-03-04 21:00:36 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2012-09-13 15:27:34 +00:00
|
|
|
# This file is part of Headphones.
|
|
|
|
#
|
|
|
|
# Headphones is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Headphones is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Headphones. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import cherrypy
|
|
|
|
|
|
|
|
import mylar
|
2015-01-25 02:26:22 +00:00
|
|
|
from mylar import logger
|
2012-09-13 15:27:34 +00:00
|
|
|
from mylar.webserve import WebInterface
|
2015-01-25 02:26:22 +00:00
|
|
|
from mylar.helpers import create_https_certificates
|
2012-09-13 15:27:34 +00:00
|
|
|
|
2015-01-25 02:26:22 +00:00
|
|
|
def initialize(options):
|
2012-09-13 15:27:34 +00:00
|
|
|
|
2015-01-25 02:26:22 +00:00
|
|
|
# HTTPS stuff stolen from sickbeard
|
|
|
|
enable_https = options['enable_https']
|
|
|
|
https_cert = options['https_cert']
|
|
|
|
https_key = options['https_key']
|
2012-09-13 15:27:34 +00:00
|
|
|
|
2015-01-25 02:26:22 +00:00
|
|
|
if enable_https:
|
|
|
|
# If either the HTTPS certificate or key do not exist, try to make
|
|
|
|
# self-signed ones.
|
|
|
|
if not (https_cert and os.path.exists(https_cert)) or not (https_key and os.path.exists(https_key)):
|
|
|
|
if not create_https_certificates(https_cert, https_key):
|
|
|
|
logger.warn("Unable to create certificate and key. Disabling " \
|
|
|
|
"HTTPS")
|
|
|
|
enable_https = False
|
|
|
|
|
|
|
|
if not (os.path.exists(https_cert) and os.path.exists(https_key)):
|
|
|
|
logger.warn("Disabled HTTPS because of missing certificate and " \
|
|
|
|
"key.")
|
|
|
|
enable_https = False
|
|
|
|
|
|
|
|
options_dict = {
|
|
|
|
'server.socket_port': options['http_port'],
|
|
|
|
'server.socket_host': options['http_host'],
|
|
|
|
'server.thread_pool': 10,
|
|
|
|
'tools.encode.on': True,
|
|
|
|
'tools.encode.encoding': 'utf-8',
|
|
|
|
'tools.decode.on': True,
|
|
|
|
'log.screen': False,
|
|
|
|
'engine.autoreload.on': False,
|
|
|
|
}
|
|
|
|
|
|
|
|
if enable_https:
|
|
|
|
options_dict['server.ssl_certificate'] = https_cert
|
|
|
|
options_dict['server.ssl_private_key'] = https_key
|
|
|
|
protocol = "https"
|
|
|
|
else:
|
|
|
|
protocol = "http"
|
|
|
|
|
|
|
|
logger.info("Starting Mylar on %s://%s:%d/", protocol,
|
|
|
|
options['http_host'], options['http_port'])
|
|
|
|
cherrypy.config.update(options_dict)
|
|
|
|
|
|
|
|
# cherrypy.config.update({
|
|
|
|
# 'log.screen': False,
|
|
|
|
# 'server.thread_pool': 10,
|
|
|
|
# 'server.socket_port': options['http_port'],
|
|
|
|
# 'server.socket_host': options['http_host'],
|
|
|
|
# 'engine.autoreload_on': False,
|
|
|
|
# })
|
2012-09-13 15:27:34 +00:00
|
|
|
|
|
|
|
conf = {
|
|
|
|
'/': {
|
2015-03-04 21:00:36 +00:00
|
|
|
'tools.staticdir.root': os.path.join(mylar.PROG_DIR, 'data')
|
2012-09-13 15:27:34 +00:00
|
|
|
},
|
2015-05-22 08:32:51 +00:00
|
|
|
'/interfaces': {
|
2012-09-13 15:27:34 +00:00
|
|
|
'tools.staticdir.on': True,
|
|
|
|
'tools.staticdir.dir': "interfaces"
|
|
|
|
},
|
2015-05-22 08:32:51 +00:00
|
|
|
'/images': {
|
2012-09-13 15:27:34 +00:00
|
|
|
'tools.staticdir.on': True,
|
|
|
|
'tools.staticdir.dir': "images"
|
|
|
|
},
|
2015-05-22 08:32:51 +00:00
|
|
|
'/css': {
|
2012-09-13 15:27:34 +00:00
|
|
|
'tools.staticdir.on': True,
|
|
|
|
'tools.staticdir.dir': "css"
|
|
|
|
},
|
2015-05-22 08:32:51 +00:00
|
|
|
'/js': {
|
2012-09-13 15:27:34 +00:00
|
|
|
'tools.staticdir.on': True,
|
|
|
|
'tools.staticdir.dir': "js"
|
|
|
|
},
|
2015-05-22 08:32:51 +00:00
|
|
|
'/favicon.ico': {
|
2012-09-13 15:27:34 +00:00
|
|
|
'tools.staticfile.on': True,
|
2015-01-25 02:26:22 +00:00
|
|
|
'tools.staticfile.filename': os.path.join(os.path.abspath(os.curdir), 'images' + os.sep + 'favicon.ico')
|
2012-09-13 15:27:34 +00:00
|
|
|
},
|
2015-05-22 08:32:51 +00:00
|
|
|
'/cache': {
|
2012-09-13 15:27:34 +00:00
|
|
|
'tools.staticdir.on': True,
|
2015-03-04 21:00:36 +00:00
|
|
|
'tools.staticdir.dir': mylar.CACHE_DIR,
|
|
|
|
'tools.auth_basic.on': False
|
2012-09-13 15:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-04 21:00:36 +00:00
|
|
|
|
2012-09-13 15:27:34 +00:00
|
|
|
if options['http_password'] != "":
|
|
|
|
conf['/'].update({
|
|
|
|
'tools.auth_basic.on': True,
|
|
|
|
'tools.auth_basic.realm': 'Mylar',
|
|
|
|
'tools.auth_basic.checkpassword': cherrypy.lib.auth_basic.checkpassword_dict(
|
2015-05-22 08:32:51 +00:00
|
|
|
{options['http_username']: options['http_password']})
|
2012-09-13 15:27:34 +00:00
|
|
|
})
|
2015-01-25 02:26:22 +00:00
|
|
|
conf['/api'] = {'tools.auth_basic.on': False}
|
2012-09-13 15:27:34 +00:00
|
|
|
|
|
|
|
# Prevent time-outs
|
|
|
|
cherrypy.engine.timeout_monitor.unsubscribe()
|
2015-03-04 21:00:36 +00:00
|
|
|
|
FIX: Added user-agent to all CV queries, and switched all queries to utilize the requests module, FIX: Added User-Agent to ComicTagger and switched to requests module for all CV queries, FIX: Removed libraryscan option from GUI as no longer used, FIX: Ability to sort 'Have' column on main index page properly now (by % complete), FIX: Fixed some display issues with the series detail page and displaying, FIX: Metatagging should now be working again for story-arc, and one-off post-processing, FIX: Fixed post-processing problem with decimal places if number was padded, FIX: Updated CV-URL to point to new CV api location, FIX: Fixed problem when file-checking and series contained numbers and/or decimals, would take the modified series name instead of the actual series name resulting in some missed matches, IMP: Added another keyword to ignore when checking for annuals against a particular series, FIX:(#1210) When importing files, if issues were meta-tagged with CVS would not scan the metadata properly, FIX: Fixed checkboxes on annuals table so drop-down will work again (just doesn't refresh the screen afterwards atm), FIX:(#1182) Notifications not respecting http base, IMP: Added option to specify SSL Verification on/off per provider when searching/downloading, FIX: Possible fix for cache_dir not being used on restarts of mylar, FIX: configparser check would only check on linux systems, and if not present would cause errors during post-processing on non nix-based systems, FIX:(#1181) Manual renaming an entire series would fail if lowercase_filenames was enabled as an option
2016-02-25 16:40:09 +00:00
|
|
|
cherrypy.tree.mount(WebInterface(), str(options['http_root']), config = conf)
|
2015-03-04 21:00:36 +00:00
|
|
|
|
2012-09-13 15:27:34 +00:00
|
|
|
try:
|
|
|
|
cherrypy.process.servers.check_port(options['http_host'], options['http_port'])
|
|
|
|
cherrypy.server.start()
|
|
|
|
except IOError:
|
|
|
|
print 'Failed to start on port: %i. Is something else running?' % (options['http_port'])
|
|
|
|
sys.exit(0)
|
2015-03-04 21:00:36 +00:00
|
|
|
|
2012-09-13 15:27:34 +00:00
|
|
|
cherrypy.server.wait()
|