Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab3ebf101f | ||
|
|
1875623f05 | ||
|
|
ac6240a3a3 | ||
|
|
ae407492bc | ||
|
|
de3a12999e | ||
|
|
395354212c | ||
|
|
b38785a25a | ||
|
|
f28a53f3e6 | ||
|
|
d94e13e9dc | ||
|
|
eb9e144746 | ||
|
|
b4d0ed30ab | ||
|
|
8e9c09a818 | ||
|
|
5091487719 | ||
|
|
2f62feaaec | ||
|
|
27a576e352 | ||
|
|
2703d528a3 | ||
|
|
be0d452ab9 | ||
|
|
0093d96da4 | ||
|
|
73c199c98c | ||
|
|
f334decb33 | ||
|
|
daa5dbc4d6 | ||
|
|
147d982c87 | ||
|
|
b87b965fc5 | ||
|
|
9bc2d54196 |
No files matched your search
@@ -65,6 +65,20 @@ jobs:
|
||||
run: |
|
||||
pytest
|
||||
|
||||
test-js-unit:
|
||||
name: 🧪 JavaScript unit tests
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: 🏗 Set up test dependencies
|
||||
run: |
|
||||
npm -g install node-qunit-puppeteer@2.1.0
|
||||
- name: 🚀 Run helpers.js test suite
|
||||
run: |
|
||||
node-qunit-puppeteer tests/static/js/test-helpers.html
|
||||
node-qunit-puppeteer tests/static/js/test-client-base.html
|
||||
|
||||
test-install:
|
||||
name: 🧪 Installation tests
|
||||
needs: build
|
||||
@@ -146,6 +160,7 @@ jobs:
|
||||
needs:
|
||||
- pre-commit
|
||||
- test-unit
|
||||
- test-js-unit
|
||||
- test-install
|
||||
- test-e2e
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -23,6 +23,24 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: 🔀 Merge staging/bugfix into maintenance
|
||||
uses: robotology/gh-action-nightly-merge@v1.3.3
|
||||
with:
|
||||
stable_branch: "staging/bugfix"
|
||||
development_branch: "maintenance"
|
||||
allow_ff: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: 🔀 Merge staging/maintenance into maintenance
|
||||
uses: robotology/gh-action-nightly-merge@v1.3.3
|
||||
with:
|
||||
stable_branch: "staging/bugfix"
|
||||
development_branch: "maintenance"
|
||||
allow_ff: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: 🔀 Merge maintenance into devel
|
||||
uses: robotology/gh-action-nightly-merge@v1.3.3
|
||||
with:
|
||||
|
||||
@@ -55,6 +55,7 @@ repos:
|
||||
- id: flake8
|
||||
additional_dependencies:
|
||||
- flake8-bugbear==22.1.11
|
||||
- importlib-metadata<5.0
|
||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||
rev: v2.5.1
|
||||
hooks:
|
||||
|
||||
+3
-3
@@ -24,10 +24,10 @@ maintenance 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev
|
||||
fix/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev
|
||||
improve/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev
|
||||
|
||||
# staging/bugfix is the branch for preparation of the 1.8.3 bugfix release
|
||||
# staging/bugfix is the branch for preparation of the 1.8.6 bugfix release
|
||||
# so are any bug/... branches
|
||||
staging/bugfix 1.8.3 87f4a4e8c967dab147beb6213cbf61cca32bec62 pep440-dev
|
||||
bug/.* 1.8.3 87f4a4e8c967dab147beb6213cbf61cca32bec62 pep440-dev
|
||||
staging/bugfix 1.8.6 395354212c2bb65b37b303de171418f6475ca346 pep440-dev
|
||||
bug/.* 1.8.6 395354212c2bb65b37b303de171418f6475ca346 pep440-dev
|
||||
|
||||
# staging/maintenance is currently the branch for preparation of 1.8.0rc6
|
||||
# so is regressionfix/...
|
||||
|
||||
+2
-2
@@ -19,6 +19,7 @@ thanks to everyone who contributed!
|
||||
* Christian Wolf
|
||||
* Christian Würthner
|
||||
* Christoph Sigrist
|
||||
* Codense Consulting Oy
|
||||
* Creality3D
|
||||
* DeltaMaker 3D Printers
|
||||
* Dennis Breining
|
||||
@@ -43,7 +44,6 @@ thanks to everyone who contributed!
|
||||
* Makespace Madrid
|
||||
* Mark Greenwald
|
||||
* Mark Walker
|
||||
* Matt Van Itallie
|
||||
* Michael Aumock
|
||||
* Mike Kershaw
|
||||
* Mosaic Manufacturing
|
||||
@@ -68,4 +68,4 @@ thanks to everyone who contributed!
|
||||
* TJ Horner
|
||||
* Ulrich Kempken
|
||||
|
||||
and 2188 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)!
|
||||
and 2145 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)!
|
||||
+1
-1
@@ -30,7 +30,7 @@ following message types are currently available for usage by 3rd party clients:
|
||||
* ``connected``: Initial connection information, sent only right after establishing the socket connection. See
|
||||
:ref:`the payload data model <sec-api-push-datamodel-connected>`.
|
||||
* ``reauthRequired``: A reauthentication of the current login session is required. The ``reason`` parameter in the
|
||||
payload defines whether a full active login is necessary (values ``logout`` and ``removed``) or a simple passive
|
||||
payload defines whether a full active login is necessary (values ``logout``, ``stale``, ``removed``) or a simple passive
|
||||
login will suffice (all other values).
|
||||
* ``current``: Rate limited general state update, payload contains information about the printer's state, job progress,
|
||||
accumulated temperature points and log lines since last update. OctoPrint will send these updates when new information
|
||||
|
||||
@@ -10,6 +10,7 @@ import uuid
|
||||
|
||||
import wrapt
|
||||
from flask_login import AnonymousUserMixin, UserMixin
|
||||
from passlib.hash import pbkdf2_sha256
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from octoprint.access.groups import Group, GroupChangeListener
|
||||
@@ -19,10 +20,22 @@ from octoprint.util import atomic_write, deprecated, generate_api_key
|
||||
from octoprint.util import get_fully_qualified_classname as fqcn
|
||||
from octoprint.util import to_bytes, yaml
|
||||
|
||||
password_hashers = []
|
||||
|
||||
try:
|
||||
from passlib.hash import argon2 as passwordhash
|
||||
except ImportError:
|
||||
from passlib.hash import pbkdf2_sha256 as passwordhash
|
||||
from passlib.hash import argon2
|
||||
|
||||
# test if we can actually hash and verify, if not we won't use this backend
|
||||
hash = argon2.hash("test")
|
||||
argon2.verify("test", hash)
|
||||
|
||||
password_hashers.append(argon2)
|
||||
except Exception:
|
||||
logging.getLogger(__name__).warning(
|
||||
"Argon2 passlib backend is not available, not using it for password hashing"
|
||||
)
|
||||
|
||||
password_hashers.append(pbkdf2_sha256)
|
||||
|
||||
|
||||
class UserManager(GroupChangeListener):
|
||||
@@ -141,7 +154,7 @@ class UserManager(GroupChangeListener):
|
||||
|
||||
@staticmethod
|
||||
def create_password_hash(password, *args, **kwargs):
|
||||
return passwordhash.hash(password)
|
||||
return password_hashers[0].hash(password)
|
||||
|
||||
@staticmethod
|
||||
def create_legacy_password_hash(password, salt):
|
||||
@@ -177,8 +190,10 @@ class UserManager(GroupChangeListener):
|
||||
def cleanup_legacy_hashes(self):
|
||||
pass
|
||||
|
||||
def signature_key_for_user(self, username, salt=None):
|
||||
return self.create_password_hash(username, salt=salt)
|
||||
def signature_key_for_user(self, username, secret):
|
||||
return hashlib.sha512(
|
||||
to_bytes(username, encoding="utf-8", errors="replace") + to_bytes(secret)
|
||||
).hexdigest()
|
||||
|
||||
def add_user(self, username, password, active, permissions, groups, overwrite=False):
|
||||
pass
|
||||
@@ -809,14 +824,16 @@ class FilebasedUserManager(UserManager):
|
||||
self._settings.remove(["accessControl", "salt"])
|
||||
self._settings.save()
|
||||
|
||||
def signature_key_for_user(self, username, salt=None):
|
||||
def signature_key_for_user(self, username, secret):
|
||||
if username == "_api":
|
||||
return super().signature_key_for_user(username, secret)
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
user = self._users[username]
|
||||
|
||||
return hashlib.sha512(
|
||||
to_bytes(username + user._passwordHash, encoding="utf-8", errors="replace")
|
||||
+ to_bytes(salt)
|
||||
+ to_bytes(secret)
|
||||
).hexdigest()
|
||||
|
||||
def change_user_setting(self, username, key, value):
|
||||
@@ -1169,10 +1186,14 @@ class User(UserMixin):
|
||||
if legacy:
|
||||
return self._passwordHash == password
|
||||
|
||||
try:
|
||||
return passwordhash.verify(password, self._passwordHash)
|
||||
except ValueError:
|
||||
return False
|
||||
for password_hash in password_hashers:
|
||||
if password_hash.identify(self._passwordHash):
|
||||
try:
|
||||
return password_hash.verify(password, self._passwordHash)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
def get_id(self):
|
||||
return self.get_name()
|
||||
|
||||
@@ -381,18 +381,21 @@ class BackupPlugin(
|
||||
)
|
||||
from octoprint.util import is_hidden_path
|
||||
|
||||
plugin_folder = self.get_plugin_data_folder()
|
||||
|
||||
def path_check(path):
|
||||
joined = os.path.join(plugin_folder, path)
|
||||
return not is_hidden_path(joined) and self._valid_backup(joined)
|
||||
|
||||
return [
|
||||
(
|
||||
r"/download/(.*)",
|
||||
LargeResponseHandler,
|
||||
{
|
||||
"path": self.get_plugin_data_folder(),
|
||||
"path": plugin_folder,
|
||||
"as_attachment": True,
|
||||
"path_validation": path_validation_factory(
|
||||
lambda path: not is_hidden_path(path)
|
||||
and self._match_backup_filename(
|
||||
os.path.basename(path), self._settings
|
||||
),
|
||||
path_check,
|
||||
status_code=404,
|
||||
),
|
||||
"access_validation": access_validation_factory(
|
||||
@@ -739,9 +742,7 @@ class BackupPlugin(
|
||||
for entry in os.scandir(self.get_plugin_data_folder()):
|
||||
if is_hidden_path(entry.path):
|
||||
continue
|
||||
if not entry.is_file():
|
||||
continue
|
||||
if not entry.name.endswith(".zip"):
|
||||
if not self._valid_backup(entry.path):
|
||||
continue
|
||||
|
||||
backups.append(
|
||||
@@ -1373,13 +1374,6 @@ class BackupPlugin(
|
||||
backup_prefix, time.strftime(BACKUP_DATE_TIME_FMT)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _match_backup_filename(cls, path, settings):
|
||||
import re
|
||||
|
||||
backup_prefix = cls._get_backup_prefix(settings)
|
||||
return re.match(re.escape(backup_prefix) + r"-backup-\d{8}-\d{6}.zip", path)
|
||||
|
||||
@classmethod
|
||||
def _get_backup_prefix(cls, settings):
|
||||
if settings.global_get(["appearance", "name"]) == "":
|
||||
@@ -1397,6 +1391,17 @@ class BackupPlugin(
|
||||
not in valid_boolean_trues
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _valid_backup(cls, path):
|
||||
if not path.endswith(".zip") or not zipfile.is_zipfile(path):
|
||||
return False
|
||||
|
||||
try:
|
||||
with zipfile.ZipFile(path) as z:
|
||||
return "metadata.json" in z.namelist()
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _send_client_message(self, message, payload=None):
|
||||
if payload is None:
|
||||
payload = {}
|
||||
|
||||
@@ -18,10 +18,10 @@ from octoprint.util.version import (
|
||||
)
|
||||
|
||||
SENTRY_URL_SERVER = (
|
||||
"https://af30d06358144fb8af076ffd8984136d@o118517.ingest.sentry.io/1373987"
|
||||
"https://faa02914ec8f42139e12a36482cfdb60@o118517.ingest.sentry.io/1373987"
|
||||
)
|
||||
SENTRY_URL_COREUI = (
|
||||
"https://e1d6b5d760f241408382d62a3e7fb416@o118517.ingest.sentry.io/1374096"
|
||||
"https://be7a53389fb045b48d6c384bb8ee89eb@o118517.ingest.sentry.io/1374096"
|
||||
)
|
||||
|
||||
SETTINGS_DEFAULTS = {
|
||||
|
||||
@@ -1472,6 +1472,7 @@ class Server:
|
||||
app,
|
||||
key_func=get_remote_address,
|
||||
enabled=s.getBoolean(["devel", "enableRateLimiter"]),
|
||||
storage_uri="memory://",
|
||||
)
|
||||
|
||||
def _setup_i18n(self, app):
|
||||
|
||||
@@ -43,7 +43,7 @@ def loginFromApiKeyRequestHandler():
|
||||
if loginUserFromApiKey():
|
||||
_flask.g.login_via_apikey = True
|
||||
except InvalidApiKeyException:
|
||||
_flask.abort(403)
|
||||
_flask.abort(403, "Invalid API key")
|
||||
|
||||
|
||||
def loginFromAuthorizationHeaderRequestHandler():
|
||||
@@ -54,7 +54,7 @@ def loginFromAuthorizationHeaderRequestHandler():
|
||||
if loginUserFromAuthorizationHeader():
|
||||
_flask.g.login_via_header = True
|
||||
except InvalidApiKeyException:
|
||||
_flask.abort(403)
|
||||
_flask.abort(403, "Invalid credentials in Basic Authorization header")
|
||||
|
||||
|
||||
class InvalidApiKeyException(Exception):
|
||||
@@ -69,7 +69,7 @@ def loginUserFromApiKey():
|
||||
user = get_user_for_apikey(apikey)
|
||||
if user is None:
|
||||
# invalid API key = no API key
|
||||
return False
|
||||
raise InvalidApiKeyException("Invalid API key")
|
||||
|
||||
return loginUser(user, login_mechanism="apikey")
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ def validate_csrf_tokens(cookie, header):
|
||||
|
||||
def add_csrf_cookie(response):
|
||||
if not isinstance(response, OctoPrintFlaskResponse):
|
||||
return
|
||||
response = flask.make_response(response)
|
||||
|
||||
token = generate_csrf_token()
|
||||
response.set_cookie("csrf_token", token, httponly=False)
|
||||
@@ -77,8 +77,9 @@ def validate_csrf_request(request):
|
||||
# Irrelevant method for CSRF, bypass
|
||||
return
|
||||
|
||||
if getattr(flask.g, "login_via_apikey", False):
|
||||
# API key authorization, bypass
|
||||
session = getattr(flask, "session", {})
|
||||
if len(session) == 0 or session.get("login_mechanism") == "apikey":
|
||||
# empty session, not a browser context
|
||||
return
|
||||
|
||||
if is_exempt(request.endpoint):
|
||||
|
||||
@@ -433,7 +433,7 @@ def encode_remember_me_cookie(value):
|
||||
name = value.split("|")[0]
|
||||
try:
|
||||
remember_key = userManager.signature_key_for_user(
|
||||
name, salt=current_app.config["SECRET_KEY"]
|
||||
name, current_app.config["SECRET_KEY"]
|
||||
)
|
||||
timestamp = datetime.utcnow().timestamp()
|
||||
return encode_cookie(f"{name}|{timestamp}", key=remember_key)
|
||||
@@ -453,7 +453,7 @@ def decode_remember_me_cookie(value):
|
||||
try:
|
||||
# valid signature?
|
||||
signature_key = userManager.signature_key_for_user(
|
||||
name, salt=current_app.config["SECRET_KEY"]
|
||||
name, current_app.config["SECRET_KEY"]
|
||||
)
|
||||
cookie = decode_cookie(value, key=signature_key)
|
||||
if cookie:
|
||||
@@ -470,6 +470,20 @@ def decode_remember_me_cookie(value):
|
||||
raise ValueError("Invalid remember me cookie")
|
||||
|
||||
|
||||
def get_cookie_suffix(request):
|
||||
"""
|
||||
Request specific suffix for set and read cookies
|
||||
|
||||
We need this because cookies are not port-specific and we don't want to overwrite our
|
||||
session and other cookies from one OctoPrint instance on our machine with those of another
|
||||
one who happens to listen on the same address albeit a different port or script root.
|
||||
"""
|
||||
result = "_P" + request.server_port
|
||||
if request.script_root:
|
||||
return result + "_R" + request.script_root.replace("/", "|")
|
||||
return result
|
||||
|
||||
|
||||
class OctoPrintFlaskRequest(flask.Request):
|
||||
environment_wrapper = staticmethod(lambda x: x)
|
||||
|
||||
@@ -518,17 +532,7 @@ class OctoPrintFlaskRequest(flask.Request):
|
||||
|
||||
@cached_property
|
||||
def cookie_suffix(self):
|
||||
"""
|
||||
Request specific suffix for set and read cookies
|
||||
|
||||
We need this because cookies are not port-specific and we don't want to overwrite our
|
||||
session and other cookies from one OctoPrint instance on our machine with those of another
|
||||
one who happens to listen on the same address albeit a different port or script root.
|
||||
"""
|
||||
result = "_P" + self.server_port
|
||||
if self.script_root:
|
||||
return result + "_R" + self.script_root.replace("/", "|")
|
||||
return result
|
||||
return get_cookie_suffix(self)
|
||||
|
||||
|
||||
class OctoPrintFlaskResponse(flask.Response):
|
||||
@@ -1908,11 +1912,12 @@ class OctoPrintJsonEncoder(flask.json.JSONEncoder):
|
||||
def session_signature(user, session):
|
||||
from octoprint.server import userManager
|
||||
|
||||
key = userManager.signature_key_for_user(user, salt=current_app.config["SECRET_KEY"])
|
||||
key = userManager.signature_key_for_user(user, current_app.config["SECRET_KEY"])
|
||||
return hmac.new(
|
||||
key.encode("utf-8"), session.encode("utf-8"), hashlib.sha512
|
||||
).hexdigest()
|
||||
|
||||
|
||||
def validate_session_signature(sig, user, session):
|
||||
return hmac.compare_digest(sig, session_signature(user, session))
|
||||
user_sig = session_signature(user, session)
|
||||
return len(user_sig) == len(sig) and hmac.compare_digest(sig, user_sig)
|
||||
@@ -305,6 +305,7 @@ class PrinterStateConnection(
|
||||
f"Unknown user/session combo: {user_id}:{user_session}"
|
||||
)
|
||||
self._on_logout()
|
||||
self._sendReauthRequired("stale")
|
||||
|
||||
self._register()
|
||||
|
||||
|
||||
@@ -225,8 +225,7 @@ def login():
|
||||
_logger.exception("Error processing theming CSS, ignoring")
|
||||
|
||||
resp = make_response(render_template("login.jinja2", **render_kwargs))
|
||||
add_csrf_cookie(resp)
|
||||
return resp
|
||||
return add_csrf_cookie(resp)
|
||||
|
||||
|
||||
@app.route("/recovery")
|
||||
@@ -258,8 +257,7 @@ def recovery():
|
||||
_logger.exception("Error adding backup upload size info, ignoring")
|
||||
|
||||
resp = make_response(render_template("recovery.jinja2", **render_kwargs))
|
||||
add_csrf_cookie(resp)
|
||||
return resp
|
||||
return add_csrf_cookie(resp)
|
||||
|
||||
|
||||
@app.route("/cached.gif")
|
||||
@@ -333,6 +331,26 @@ def in_cache():
|
||||
return abort(404)
|
||||
|
||||
|
||||
@app.route("/reverse_proxy_test")
|
||||
@app.route("/reverse_proxy_test/")
|
||||
def reverse_proxy_test():
|
||||
from octoprint.server.util.flask import get_cookie_suffix, get_remote_address
|
||||
|
||||
remote_address = get_remote_address(request)
|
||||
cookie_suffix = get_cookie_suffix(request)
|
||||
|
||||
return render_template(
|
||||
"reverse_proxy_test.jinja2",
|
||||
theming=[],
|
||||
client_ip=remote_address,
|
||||
server_protocol=request.environ.get("wsgi.url_scheme"),
|
||||
server_name=request.environ.get("SERVER_NAME"),
|
||||
server_port=request.environ.get("SERVER_PORT"),
|
||||
server_path=request.script_root if request.script_root else "/",
|
||||
cookie_suffix=cookie_suffix,
|
||||
)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
from octoprint.server import connectivityChecker, printer
|
||||
@@ -700,8 +718,7 @@ def index():
|
||||
if response is None:
|
||||
return abort(404)
|
||||
|
||||
add_csrf_cookie(response)
|
||||
return response
|
||||
return add_csrf_cookie(response)
|
||||
|
||||
|
||||
def _get_render_kwargs(templates, plugin_names, plugin_vars, now):
|
||||
|
||||
@@ -228,7 +228,7 @@ default_settings = {
|
||||
"preemptiveCache": {"exceptions": [], "until": 7},
|
||||
"ipCheck": {"enabled": True, "trustedSubnets": []},
|
||||
"allowFraming": False,
|
||||
"cookies": {"secure": False, "samesite": "strict"},
|
||||
"cookies": {"secure": False, "samesite": "lax"},
|
||||
},
|
||||
"webcam": {
|
||||
"webcamEnabled": True,
|
||||
|
||||
@@ -107,13 +107,14 @@
|
||||
return url;
|
||||
};
|
||||
|
||||
OctoPrintClient.prototype.getCookieSuffix = function () {
|
||||
OctoPrintClient.prototype.getParsedBaseUrl = function (location) {
|
||||
if (!this.options.baseurl) return "";
|
||||
|
||||
try {
|
||||
var url = new URL(this.options.baseurl);
|
||||
} catch (e) {
|
||||
var parsed = new URL(window.location);
|
||||
location = location || window.location;
|
||||
var parsed = new URL(location);
|
||||
var path = this.options.baseurl;
|
||||
if (!path || path[0] !== "/") {
|
||||
path = "/" + (path ? path : "");
|
||||
@@ -121,13 +122,21 @@
|
||||
var url = new URL(parsed.protocol + "//" + parsed.host + path);
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
OctoPrintClient.prototype.getCookieSuffix = function () {
|
||||
if (!this.options.baseurl) return "";
|
||||
|
||||
var url = this.getParsedBaseUrl();
|
||||
|
||||
var port = url.port || (url.protocol === "https:" ? 443 : 80);
|
||||
if (url.pathname && url.pathname !== "/") {
|
||||
var path = url.pathname;
|
||||
if (path.endsWith("/")) {
|
||||
path = path.substring(0, path.length - 1);
|
||||
}
|
||||
return "_P" + port + "_R" + path.replace(/\//, "|");
|
||||
return "_P" + port + "_R" + path.replace(/\//g, "|");
|
||||
} else {
|
||||
return "_P" + port;
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ $(function () {
|
||||
};
|
||||
|
||||
self.onDataUpdaterReauthRequired = function (reason) {
|
||||
if (reason === "logout" || reason === "removed") {
|
||||
if (reason === "logout" || reason === "stale" || reason === "removed") {
|
||||
self.logout();
|
||||
} else {
|
||||
self.requestData();
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
$(function () {
|
||||
//~~ OctoPrint client setup
|
||||
|
||||
var OctoPrint = window.OctoPrint;
|
||||
OctoPrint.options.baseurl = BASE_URL;
|
||||
|
||||
//~~ Lodash setup
|
||||
|
||||
_.mixin({sprintf: sprintf, vsprintf: vsprintf});
|
||||
|
||||
//~~ View Model
|
||||
|
||||
function ReverseProxyTestViewModel() {
|
||||
var self = this;
|
||||
|
||||
var url = OctoPrint.getParsedBaseUrl();
|
||||
var cookieSuffix = OctoPrint.getCookieSuffix();
|
||||
var protocol = url.protocol;
|
||||
var path = url.pathname || "/";
|
||||
|
||||
if (path && path !== "/") {
|
||||
if (path.endsWith("/")) {
|
||||
path = path.substring(0, path.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
self.serverProtocol = protocol.substring(0, protocol.length - 1);
|
||||
self.serverName = url.hostname;
|
||||
self.serverPort = url.port || (url.protocol === "https:" ? 443 : 80);
|
||||
self.serverPath = path;
|
||||
self.cookieSuffix = cookieSuffix;
|
||||
|
||||
self.serverProtocolMatch = self.serverProtocol == SERVER_PROTOCOL;
|
||||
self.serverNameMatch = self.serverName == SERVER_NAME;
|
||||
self.serverPortMatch = self.serverPort == SERVER_PORT;
|
||||
self.serverPathMatch = self.serverPath == SERVER_PATH;
|
||||
self.cookieSuffixMatch = self.cookieSuffix == COOKIE_SUFFIX;
|
||||
}
|
||||
|
||||
var viewModel = new ReverseProxyTestViewModel();
|
||||
|
||||
ko.applyBindings(viewModel, document.getElementById("reverse_proxy_test"));
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>OctoPrint Reverse Proxy Test</title>
|
||||
|
||||
<link rel="shortcut icon" href="{{ url_for('static', filename='img/tentacle-32x32.png') }}">
|
||||
<link rel="mask-icon" href="{{ url_for('static', filename='img/mask.svg') }}" color="#56BE37">
|
||||
<link rel="mask-icon-theme" href="{{ url_for('static', filename='img/mask-theme.svg') }}" color="#56BE37">
|
||||
<link rel="apple-touch-icon" sizes="114x114" href="{{ url_for('static', filename='img/apple-touch-icon-114x114.png') }}">
|
||||
<link rel="apple-touch-icon" sizes="144x144" href="{{ url_for('static', filename='img/apple-touch-icon-144x144.png') }}">
|
||||
|
||||
<!-- le CSS -->
|
||||
|
||||
<link rel="stylesheet" href="{{ url_for("static", filename="css/bootstrap.min.css") }}">
|
||||
<link rel="stylesheet" href="{{ url_for("static", filename="css/bootstrap-responsive.min.css") }}">
|
||||
<link rel="stylesheet" href="{{ url_for("static", filename="vendor/font-awesome-5.15.1/css/all.min.css") }}">
|
||||
<link rel="stylesheet" href="{{ url_for("static", filename="vendor/font-awesome-5.15.1/css/v4-shims.min") }}">
|
||||
|
||||
{% for url in theming %}
|
||||
<link rel="stylesheet" href="{{ url }}">
|
||||
{% endfor %}
|
||||
|
||||
<!-- le javascript -->
|
||||
|
||||
<script>
|
||||
var BASE_URL = "{{ url_for('index') }}";
|
||||
|
||||
var CLIENT_IP = "{{ client_ip }}";
|
||||
var SERVER_PROTOCOL = "{{ server_protocol }}";
|
||||
var SERVER_NAME = "{{ server_name }}";
|
||||
var SERVER_PORT = {{ server_port }};
|
||||
var SERVER_PATH = "{{ server_path }}";
|
||||
var COOKIE_SUFFIX = "{{ cookie_suffix }}";
|
||||
</script>
|
||||
<script src="{{ url_for("static", filename="js/lib/jquery/jquery.min.js") }}"></script>
|
||||
<script src="{{ url_for("static", filename="js/lib/knockout.js") }}"></script>
|
||||
<script src="{{ url_for("static", filename="js/lib/bootstrap/bootstrap.js") }}"></script>
|
||||
<script src="{{ url_for("static", filename="js/lib/lodash.min.js") }}"></script>
|
||||
<script src="{{ url_for("static", filename="js/lib/sprintf.min.js") }}"></script>
|
||||
|
||||
{% assets "js_client" %}
|
||||
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
|
||||
{% endassets %}
|
||||
|
||||
<script src="{{ url_for("static", filename="js/app/helpers.js") }}"></script>
|
||||
<script src="{{ url_for("static", filename="js/reverse_proxy_test/reverse_proxy_test.js") }}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="navbar" class="navbar navbar-inverse navbar-static-top">
|
||||
<div class="navbar-inner">
|
||||
<span class="brand">OctoPrint Reverse Proxy Test</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="reverse_proxy_test" class="container" style="padding-top: 1em">
|
||||
<div class="alert alert-error" data-bind="visible: !cookieSuffixMatch">
|
||||
<strong>Warning!</strong> The used cookie suffix doesn't match between client and server. That means that OctoPrint's
|
||||
UI won't work properly. Please check your configuration and fix it.
|
||||
</div>
|
||||
|
||||
<p>
|
||||
This page helps you identify issues in your reverse proxy configuration. It will show you information about
|
||||
some of the variables that OctoPrint uses to set cookies and generate fully qualified URLs. If you see
|
||||
any mismatches highlighted in red below, that means that something is not configured properly and you
|
||||
need to fix it.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The table also shows you the client IP that your server saw you as. Make sure that this client IP is what
|
||||
OctoPrint should be seeing, and not for example your reverse proxy itself.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For each variable, information is displayed what influences the value the server sees and thus where to
|
||||
start debugging in case of any observed mismatches.
|
||||
</p>
|
||||
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<th>Variable</th>
|
||||
<th>Source</th>
|
||||
<th>Client</th>
|
||||
<th>Server</th>
|
||||
</thead>
|
||||
<tr>
|
||||
<td>Client IP</td>
|
||||
<td><code>X-Forwarded-For</code></td>
|
||||
<td>-</td>
|
||||
<td>{{ client_ip }}</td>
|
||||
</tr>
|
||||
<tr data-bind="css: { success: serverProtocolMatch, error: !serverProtocolMatch }">
|
||||
<td>Protocol</td>
|
||||
<td><code>X-Forwarded-Protocol</code>, <code>X-Scheme</code> or config</td>
|
||||
<td data-bind="text: serverProtocol"></td>
|
||||
<td>{{ server_protocol }}</td>
|
||||
</tr>
|
||||
<tr data-bind="css: { success: serverNameMatch, error: !serverNameMatch }">
|
||||
<td>Host</td>
|
||||
<td><code>X-Forwarded-Host</code>, <code>Host</code>, <code>X-Forwarded-Server</code> or config</td>
|
||||
<td data-bind="text: serverName"></td>
|
||||
<td>{{ server_name }}</td>
|
||||
</tr>
|
||||
<tr data-bind="css: { success: serverPortMatch, error: !serverPortMatch }">
|
||||
<td>Port</td>
|
||||
<td><code>X-Forwarded-Host</code>, <code>Host</code>, <code>X-Forwarded-Port</code>, <code>X-Forwarded-Protocol</code>, <code>X-Scheme</code> or config</td>
|
||||
<td data-bind="text: serverPort"></td>
|
||||
<td>{{ server_port }}</td>
|
||||
</tr>
|
||||
<tr data-bind="css: { success: serverPathMatch, error: !serverPathMatch }">
|
||||
<td>Path</td>
|
||||
<td><code>X-Script-Name</code> or config</td>
|
||||
<td data-bind="text: serverPath"></td>
|
||||
<td>{{ server_path }}</td>
|
||||
</tr>
|
||||
<tr data-bind="css: { success: cookieSuffixMatch, error: !cookieSuffixMatch }">
|
||||
<td>Cookie Suffix</td>
|
||||
<td>Built from port & path</td>
|
||||
<td data-bind="text: cookieSuffix"></td>
|
||||
<td>{{ cookie_suffix }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
Please refer to <a href="https://faq.octoprint.org/reverse-proxy" target="_blank" rel="noopener noreferrer">the Reverse Proxy FAQ entry</a>
|
||||
for information on correct configuration and examples.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Generated
+9
-6
@@ -1237,9 +1237,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/minimist": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
||||
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
@@ -2602,9 +2605,9 @@
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
||||
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g=="
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>src/octoprint/static/js/app/client/base.js Tests</title>
|
||||
<link rel="stylesheet" href="lib/qunit-1.18.0.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="lib/qunit-1.18.0.js"></script>
|
||||
<script src="lib/qunit-parameterize.js"></script>
|
||||
<script src="../../../src/octoprint/static/js/lib/lodash.min.js"></script>
|
||||
<script src="../../../src/octoprint/static/js/lib/sprintf.min.js"></script>
|
||||
<script src="../../../src/octoprint/static/js/app/client/base.js"></script>
|
||||
<script src="test-client-base.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,110 @@
|
||||
_.mixin({sprintf: sprintf, vsprintf: vsprintf});
|
||||
|
||||
QUnit.module("getParsedBaseUrl");
|
||||
QUnit.cases(
|
||||
(function () {
|
||||
return [
|
||||
{
|
||||
title: "fully qualified baseurl",
|
||||
baseurl: "https://example.com",
|
||||
location: undefined,
|
||||
expected: "https://example.com/"
|
||||
},
|
||||
{
|
||||
title: "fully qualified baseurl with http",
|
||||
baseurl: "http://example.com",
|
||||
location: undefined,
|
||||
expected: "http://example.com/"
|
||||
},
|
||||
{
|
||||
title: "fully qualified baseurl with custom port",
|
||||
baseurl: "https://example.com:5000",
|
||||
location: undefined,
|
||||
expected: "https://example.com:5000/"
|
||||
},
|
||||
{
|
||||
title: "website root",
|
||||
baseurl: "/",
|
||||
location: "https://example.com",
|
||||
expected: "https://example.com/"
|
||||
},
|
||||
{
|
||||
title: "website root with custom port",
|
||||
baseurl: "/",
|
||||
location: "https://example.com:5000",
|
||||
expected: "https://example.com:5000/"
|
||||
},
|
||||
{
|
||||
title: "single level prefix",
|
||||
baseurl: "/octoprint/",
|
||||
location: "https://example.com",
|
||||
expected: "https://example.com/octoprint/"
|
||||
},
|
||||
{
|
||||
title: "multi level prefix",
|
||||
baseurl: "/path/to/octoprint/",
|
||||
location: "https://example.com",
|
||||
expected: "https://example.com/path/to/octoprint/"
|
||||
},
|
||||
{
|
||||
title: "multi level prefix with http and custom port",
|
||||
baseurl: "/path/to/octoprint/",
|
||||
location: "http://example.com:5000",
|
||||
expected: "http://example.com:5000/path/to/octoprint/"
|
||||
},
|
||||
{
|
||||
title: "multi level prefix with https, custom port, no trailing slash",
|
||||
baseurl: "/path/to/octoprint",
|
||||
location: "https://example.com:5001",
|
||||
expected: "https://example.com:5001/path/to/octoprint"
|
||||
}
|
||||
];
|
||||
})()
|
||||
).test("getParsedBaseUrl", function (params, assert) {
|
||||
OctoPrint.options.baseurl = params.baseurl;
|
||||
assert.equal(
|
||||
OctoPrint.getParsedBaseUrl(params.location).toString(),
|
||||
params.expected,
|
||||
"Expected: " + String(params.expected)
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.module("getCookieSuffix");
|
||||
QUnit.cases(
|
||||
(function () {
|
||||
return [
|
||||
{
|
||||
title: "http with default port",
|
||||
baseurl: "http://example.com",
|
||||
expected: "_P80"
|
||||
},
|
||||
{
|
||||
title: "https with default port",
|
||||
baseurl: "https://example.com",
|
||||
expected: "_P443"
|
||||
},
|
||||
{
|
||||
title: "custom port",
|
||||
baseurl: "http://example.com:5000",
|
||||
expected: "_P5000"
|
||||
},
|
||||
{
|
||||
title: "single level prefix",
|
||||
baseurl: "https://example.com/octoprint/",
|
||||
expected: "_P443_R|octoprint"
|
||||
},
|
||||
{
|
||||
title: "multi level prefix",
|
||||
baseurl: "https://example.com/path/to/octoprint",
|
||||
expected: "_P443_R|path|to|octoprint"
|
||||
}
|
||||
];
|
||||
})()
|
||||
).test("getCookieSuffix", function (params, assert) {
|
||||
OctoPrint.options.baseurl = params.baseurl;
|
||||
assert.equal(
|
||||
OctoPrint.getCookieSuffix(),
|
||||
params.expected,
|
||||
"Expected: " + String(params.expected)
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user