diff --git a/prusa/link/config.py b/prusa/link/config.py index dad14bc9..0c1135b8 100644 --- a/prusa/link/config.py +++ b/prusa/link/config.py @@ -309,7 +309,8 @@ def __init__(self, settings_file): self.service_local = Model( self.get_section('service::local', (('enable', int, 1), ('username', str, ''), - ('digest', str, ''), ('api_key', str, '')))) + ('digest', str, ''), ('api_key', str, ''), + ('auth', bool, True)))) Settings.instance = self @@ -337,10 +338,13 @@ def is_wizard_needed(self, camera_mode=False): """ Is there a reason for the wizard to be shown? """ - interested_in = [ - self.service_local["username"], - self.service_local["digest"], - ] + interested_in = [] + + if self.service_local["auth"]: + interested_in.extend([ + self.service_local["username"], + self.service_local["digest"], + ]) if not camera_mode: interested_in.append(self.printer["type"]) return not all(interested_in) diff --git a/prusa/link/templates/camera_wizard.html b/prusa/link/templates/camera_wizard.html index c1129f04..1dc1229b 100644 --- a/prusa/link/templates/camera_wizard.html +++ b/prusa/link/templates/camera_wizard.html @@ -40,9 +40,8 @@

Restore settings
-
Setup credentials | NEXT -
- +
No authentication [DANGER]
+
Setup credentials | NEXT
diff --git a/prusa/link/web/camera_wizard.py b/prusa/link/web/camera_wizard.py index a728f35d..a612a0c1 100644 --- a/prusa/link/web/camera_wizard.py +++ b/prusa/link/web/camera_wizard.py @@ -71,6 +71,15 @@ def wizard_credentials(req): wizard=app.wizard) +@app.route('/wizard/no-auth') +@check_ready +def wizard_no_auth(req): + """Credentials configuration.""" + app.wizard.auth = False + app.wizard.write_settings(app.settings) + redirect_with_proxy(req, '/') + + @app.route('/wizard/credentials', method=state.METHOD_POST) @check_ready def wizard_credentials_post(req): diff --git a/prusa/link/web/lib/auth.py b/prusa/link/web/lib/auth.py index 97117952..946fc821 100644 --- a/prusa/link/web/lib/auth.py +++ b/prusa/link/web/lib/auth.py @@ -2,6 +2,7 @@ import logging from functools import wraps +import poorwsgi from poorwsgi import state from poorwsgi.digest import check_credentials, hexdigest from poorwsgi.response import HTTPException, Response @@ -28,6 +29,18 @@ SAME_DIGEST = "Nothing to change. All credentials are same as old ones" +def optional_auth(func): + """Used for optional authentication of index page""" + + @wraps(func) + def handler(req, *args, **kwargs): + if app.settings is None or app.settings.service_local["auth"]: + return poorwsgi.digest.check_digest(REALM)(func)( + req, *args, **kwargs) + return func(req, *args, **kwargs) + return handler + + def check_digest(req): """Check HTTP Digest. @@ -56,6 +69,9 @@ def check_api_digest(func): @wraps(func) def handler(req, *args, **kwargs): + if not app.settings.service_local["auth"]: + return func(req, *args, **kwargs) + prusa_link = app.daemon.prusa_link if not prusa_link or not prusa_link.printer: raise HTTPException(state.HTTP_SERVICE_UNAVAILABLE) diff --git a/prusa/link/web/lib/wizard.py b/prusa/link/web/lib/wizard.py index dfa5d594..9dfed688 100644 --- a/prusa/link/web/lib/wizard.py +++ b/prusa/link/web/lib/wizard.py @@ -85,6 +85,7 @@ def __init__(self, _app): self.serial = None # auth + self.auth = True self.username = _app.settings.service_local.username self.digest = None self.restored_digest = False @@ -178,9 +179,11 @@ def check_connect(self): def write_settings(self, settings): """Write settings configuration.""" - # auth - settings.service_local.digest = self.digest - settings.service_local.username = self.username + settings.service_local.auth = self.auth + if self.auth: + # auth + settings.service_local.digest = self.digest + settings.service_local.username = self.username # network settings.network.hostname = self.net_hostname diff --git a/prusa/link/web/main.py b/prusa/link/web/main.py index bdd0db7a..15e72db3 100644 --- a/prusa/link/web/main.py +++ b/prusa/link/web/main.py @@ -14,7 +14,6 @@ from gcode_metadata import get_metadata from pkg_resources import working_set # type: ignore from poorwsgi import state -from poorwsgi.digest import check_digest from poorwsgi.response import ( EmptyResponse, FileResponse, @@ -40,7 +39,7 @@ update_prusalink, ) from ..printer_adapter.job import Job, JobState -from .lib.auth import REALM, check_api_digest, check_config +from .lib.auth import check_api_digest, check_config, optional_auth from .lib.core import app from .lib.files import fill_printfile_data, gcode_analysis, get_os_path from .lib.view import package_to_api @@ -79,7 +78,7 @@ def instance(req): @app.route('/', method=state.METHOD_GET) @check_config -@check_digest(REALM) +@optional_auth def index(req): """Return status page""" # pylint: disable=unused-argument