Skip to content

Commit 92b5162

Browse files
committed
Allow cameras with no authentication - danger
1 parent c33f98e commit 92b5162

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

prusa/link/config.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ def __init__(self, settings_file):
301301
self.service_local = Model(
302302
self.get_section('service::local',
303303
(('enable', int, 1), ('username', str, ''),
304-
('digest', str, ''), ('api_key', str, ''))))
304+
('digest', str, ''), ('api_key', str, ''),
305+
('auth', bool, True))))
305306

306307
Settings.instance = self
307308

@@ -329,10 +330,13 @@ def is_wizard_needed(self, camera_mode=False):
329330
"""
330331
Is there a reason for the wizard to be shown?
331332
"""
332-
interested_in = [
333-
self.service_local["username"],
334-
self.service_local["digest"],
335-
]
333+
interested_in = []
334+
335+
if self.service_local["auth"]:
336+
interested_in.extend([
337+
self.service_local["username"],
338+
self.service_local["digest"],
339+
])
336340
if not camera_mode:
337341
interested_in.append(self.printer["type"])
338342
return not all(interested_in)

prusa/link/templates/camera_wizard.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ <h2 class="align-center">
4040
<div class="col">
4141
<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>
4242
</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>
43+
<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>
44+
<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>
4645
</div>
4746
</div>
4847
</div>

prusa/link/web/camera_wizard.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ def wizard_credentials(req):
7171
wizard=app.wizard)
7272

7373

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+
7483
@app.route('/wizard/credentials', method=state.METHOD_POST)
7584
@check_ready
7685
def wizard_credentials_post(req):

prusa/link/web/lib/auth.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from functools import wraps
44

5+
import poorwsgi
56
from poorwsgi import state
67
from poorwsgi.digest import check_credentials, hexdigest
78
from poorwsgi.response import HTTPException, Response
@@ -28,6 +29,18 @@
2829
SAME_DIGEST = "Nothing to change. All credentials are same as old ones"
2930

3031

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)
40+
return func(req, *args, **kwargs)
41+
return handler
42+
43+
3144
def check_digest(req):
3245
"""Check HTTP Digest.
3346
@@ -56,6 +69,9 @@ def check_api_digest(func):
5669

5770
@wraps(func)
5871
def handler(req, *args, **kwargs):
72+
if not app.settings.service_local["auth"]:
73+
return func(req, *args, **kwargs)
74+
5975
prusa_link = app.daemon.prusa_link
6076
if not prusa_link or not prusa_link.printer:
6177
raise HTTPException(state.HTTP_SERVICE_UNAVAILABLE)

prusa/link/web/lib/wizard.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, _app):
8585
self.serial = None
8686

8787
# auth
88+
self.auth = True
8889
self.username = _app.settings.service_local.username
8990
self.digest = None
9091
self.restored_digest = False
@@ -178,9 +179,11 @@ def check_connect(self):
178179

179180
def write_settings(self, settings):
180181
"""Write settings configuration."""
181-
# auth
182-
settings.service_local.digest = self.digest
183-
settings.service_local.username = self.username
182+
settings.service_local.auth = self.auth
183+
if self.auth:
184+
# auth
185+
settings.service_local.digest = self.digest
186+
settings.service_local.username = self.username
184187

185188
# network
186189
settings.network.hostname = self.net_hostname

prusa/link/web/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from gcode_metadata import get_metadata
1010
from pkg_resources import working_set # type: ignore
1111
from poorwsgi import state
12-
from poorwsgi.digest import check_digest
1312
from poorwsgi.response import (
1413
EmptyResponse,
1514
FileResponse,
@@ -34,7 +33,7 @@
3433
update_prusalink,
3534
)
3635
from ..printer_adapter.job import Job, JobState
37-
from .lib.auth import REALM, check_api_digest, check_config
36+
from .lib.auth import check_api_digest, check_config, optional_auth
3837
from .lib.core import app
3938
from .lib.files import fill_printfile_data, gcode_analysis, get_os_path
4039
from .lib.view import package_to_api
@@ -73,7 +72,7 @@ def instance(req):
7372

7473
@app.route('/', method=state.METHOD_GET)
7574
@check_config
76-
@check_digest(REALM)
75+
@optional_auth
7776
def index(req):
7877
"""Return status page"""
7978
# pylint: disable=unused-argument

0 commit comments

Comments
 (0)