Skip to content

Commit 4bea979

Browse files
committed
withhold MJPEG stream URLs until authentication
- main.html fills the url attribute only when a session exists - doAuth() reloads the frame page after login, so the stream starts without a manual refresh - refreshCameraFrame() skips the refresh while the URL is empty - frame() marks its response uncacheable
1 parent 2d62cce commit 4bea979

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

motioneye/handlers/picture.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ async def list(self, camera_id):
252252
raise HTTPError(400, 'unknown operation')
253253

254254
async def frame(self, camera_id):
255+
self.set_header('Cache-Control', 'private, no-store, must-revalidate')
256+
255257
camera_config = config.get_camera(camera_id)
256258

257259
if (

motioneye/static/js/frame.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ function refreshCameraFrame() {
8282

8383
if (cameraFrame.proto == 'mjpeg') {
8484
/* no manual refresh for simple mjpeg cameras */
85+
if (!cameraFrame.url) {
86+
return; /* the stream URL is withheld until login */
87+
}
88+
8589
var url = cameraFrame.url.replace('127.0.0.1', window.location.host.split(':')[0]);
8690
url += (url.indexOf('?') > 0 ? '&' : '?') + '_=' + new Date().getTime();
8791
img.src = url;

motioneye/static/js/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5494,6 +5494,10 @@ function doAuth() {
54945494
if (!frame) {
54955495
fetchCurrentConfig(endProgress);
54965496
}
5497+
else if (frame && !currentUser) {
5498+
/* the page was rendered anonymously and lacks the stream URL */
5499+
window.location.reload();
5500+
}
54975501
} else {
54985502
// Session invalid, show login dialog
54995503
runLoginDialog(function () {

motioneye/templates/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@
13601360
{% else %}
13611361
<div class="camera-frame" id="camera{{camera_id}}"
13621362
streaming_framerate="{{camera_config['stream_maxrate']}}" streaming_server_resize="{{camera_config['@webcam_server_resize']|string|lower}}"
1363-
proto="{{camera_config['@proto']}}" url="{{camera_config['@url']}}">
1363+
proto="{{camera_config['@proto']}}" url="{% if current_user %}{{camera_config['@url']}}{% endif %}">
13641364
<div class="camera-container">
13651365
<div class="camera-placeholder"><img class="no-camera" src="{{static_path}}img/no-camera.svg"></div>
13661366
<img class="camera">

0 commit comments

Comments
 (0)