diff --git a/couchpotato/__init__.py b/couchpotato/__init__.py index 8386ed9f..8482160e 100644 --- a/couchpotato/__init__.py +++ b/couchpotato/__init__.py @@ -15,6 +15,7 @@ from sqlalchemy.orm import scoped_session from sqlalchemy.orm.session import sessionmaker from werkzeug.utils import redirect import os +import time log = CPLog(__name__) @@ -73,5 +74,10 @@ def getApiKey(): def page_not_found(error): index_url = url_for('web.index') url = getattr(request, 'path')[len(index_url):] - return redirect(index_url + '#' + url) + + if url[:3] != 'api': + return redirect(index_url + '#' + url) + else: + time.sleep(2) + return 'Wrong API key used', 404 diff --git a/couchpotato/api.py b/couchpotato/api.py index 71cf9b87..934fa94a 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -1,6 +1,5 @@ from flask.blueprints import Blueprint from flask.helpers import url_for -from flask.templating import render_template from werkzeug.utils import redirect api = Blueprint('api', __name__) diff --git a/couchpotato/core/_base/_core/main.py b/couchpotato/core/_base/_core/main.py index 81ed9449..81ccac24 100644 --- a/couchpotato/core/_base/_core/main.py +++ b/couchpotato/core/_base/_core/main.py @@ -165,7 +165,7 @@ class Core(Plugin): return '%s:%d%s' % (cleanHost(host).rstrip('/'), int(port), '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else '') def createApiUrl(self): - return '%s/%s' % (self.createBaseUrl(), Env.setting('api_key')) + return '%s/api/%s' % (self.createBaseUrl(), Env.setting('api_key')) def version(self): ver = fireEvent('updater.info', single = True) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 035ccab1..d91fc6c7 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -55,7 +55,7 @@ class Plugin(object): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', self.__class__.__name__) class_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() - path = '%s/static/%s/' % (Env.setting('api_key'), class_name) + path = 'api/%s/static/%s/' % (Env.setting('api_key'), class_name) addView(path + '', self.showStatic, static = True) if add_to_head: diff --git a/couchpotato/runner.py b/couchpotato/runner.py index 66d9d7d0..0be3bdbc 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -172,13 +172,13 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En # Static path app.static_folder = os.path.join(base_path, 'couchpotato', 'static') - web.add_url_rule('%s/static/' % api_key, + web.add_url_rule('api/%s/static/' % api_key, endpoint = 'static', view_func = app.send_static_file) # Register modules app.register_blueprint(web, url_prefix = '%s/' % url_base) - app.register_blueprint(api, url_prefix = '%s/%s/' % (url_base, api_key)) + app.register_blueprint(api, url_prefix = '%s/api/%s/' % (url_base, api_key)) # Some logging and fire load event try: log.info('Starting server on port %(port)s' % config)