We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c33f98e commit 92b5162Copy full SHA for 92b5162
prusa/link/config.py
@@ -301,7 +301,8 @@ def __init__(self, settings_file):
301
self.service_local = Model(
302
self.get_section('service::local',
303
(('enable', int, 1), ('username', str, ''),
304
- ('digest', str, ''), ('api_key', str, ''))))
+ ('digest', str, ''), ('api_key', str, ''),
305
+ ('auth', bool, True))))
306
307
Settings.instance = self
308
@@ -329,10 +330,13 @@ def is_wizard_needed(self, camera_mode=False):
329
330
"""
331
Is there a reason for the wizard to be shown?
332
- interested_in = [
333
- self.service_local["username"],
334
- self.service_local["digest"],
335
- ]
+ interested_in = []
+
+ if self.service_local["auth"]:
336
+ interested_in.extend([
337
+ self.service_local["username"],
338
+ self.service_local["digest"],
339
+ ])
340
if not camera_mode:
341
interested_in.append(self.printer["type"])
342
return not all(interested_in)
prusa/link/templates/camera_wizard.html
@@ -40,9 +40,8 @@ <h2 class="align-center">
40
<div class="col">
41
<a id="restore_btn" href={{ "/wizard/restore" | prefixed }} class="btn btn-outline-light full-width" onmouseover="changeIconImage('img/reset-icon-black.svg')" onmouseout="changeIconImage('img/reset-icon-white.svg')">Restore settings <img id="restore_icon" height="25" src="img/reset-icon-white.svg"></a>
42
</div>
43
- <div class="col-sm-auto"><a href={{ "/wizard/credentials" | prefixed }} class="btn btn-outline-light full-width">Setup credentials | NEXT <img src="img/arrow-right.svg" height="16" /></a>
44
- </div>
45
+ <div class="col-sm-auto"><a href={{ "/wizard/no-auth" | prefixed }} class="btn btn-outline-light full-width">No authentication [DANGER] <img src="img/arrow-right.svg" height="16" /></a></div>
+ <div class="col-sm-auto"><a href={{ "/wizard/credentials" | prefixed }} class="btn btn-outline-light full-width">Setup credentials | NEXT <img src="img/arrow-right.svg" height="16" /></a></div>
46
47
48
prusa/link/web/camera_wizard.py
@@ -71,6 +71,15 @@ def wizard_credentials(req):
71
wizard=app.wizard)
72
73
74
+@app.route('/wizard/no-auth')
75
+@check_ready
76
+def wizard_no_auth(req):
77
+ """Credentials configuration."""
78
+ app.wizard.auth = False
79
+ app.wizard.write_settings(app.settings)
80
+ redirect_with_proxy(req, '/')
81
82
83
@app.route('/wizard/credentials', method=state.METHOD_POST)
84
@check_ready
85
def wizard_credentials_post(req):
prusa/link/web/lib/auth.py
@@ -2,6 +2,7 @@
2
import logging
3
from functools import wraps
4
5
+import poorwsgi
6
from poorwsgi import state
7
from poorwsgi.digest import check_credentials, hexdigest
8
from poorwsgi.response import HTTPException, Response
@@ -28,6 +29,18 @@
28
29
SAME_DIGEST = "Nothing to change. All credentials are same as old ones"
30
31
32
+def optional_auth(func):
33
+ """Used for optional authentication of index page"""
34
35
+ @wraps(func)
36
+ def handler(req, *args, **kwargs):
37
+ if app.settings is None or app.settings.service_local["auth"]:
38
+ return poorwsgi.digest.check_digest(REALM)(func)(
39
+ 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):
56
69
57
70
@wraps(func)
58
def handler(req, *args, **kwargs):
+ if not app.settings.service_local["auth"]:
59
prusa_link = app.daemon.prusa_link
60
if not prusa_link or not prusa_link.printer:
61
raise HTTPException(state.HTTP_SERVICE_UNAVAILABLE)
prusa/link/web/lib/wizard.py
@@ -85,6 +85,7 @@ def __init__(self, _app):
self.serial = None
86
87
# auth
88
+ self.auth = True
89
self.username = _app.settings.service_local.username
90
self.digest = None
91
self.restored_digest = False
@@ -178,9 +179,11 @@ def check_connect(self):
178
179
180
def write_settings(self, settings):
181
"""Write settings configuration."""
- # auth
182
- settings.service_local.digest = self.digest
183
- settings.service_local.username = self.username
+ settings.service_local.auth = self.auth
+ if self.auth:
184
+ # auth
185
+ settings.service_local.digest = self.digest
186
+ settings.service_local.username = self.username
187
188
# network
189
settings.network.hostname = self.net_hostname
prusa/link/web/main.py
@@ -9,7 +9,6 @@
9
from gcode_metadata import get_metadata
10
from pkg_resources import working_set # type: ignore
11
12
-from poorwsgi.digest import check_digest
13
from poorwsgi.response import (
14
EmptyResponse,
15
FileResponse,
@@ -34,7 +33,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
@@ -73,7 +72,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
0 commit comments