allow websocket connections from files and localhost and use it in installer and static load file
This commit is contained in:
parent
01caf50ffa
commit
871a602acd
2 changed files with 39 additions and 13 deletions
|
@ -16,8 +16,15 @@ logger = logging.getLogger('oml.websocket')
|
||||||
|
|
||||||
class Handler(WebSocketHandler):
|
class Handler(WebSocketHandler):
|
||||||
|
|
||||||
|
def check_origin(self, origin):
|
||||||
|
# allow access to websocket from site, installer and loader (local file)
|
||||||
|
return self.request.host in origin \
|
||||||
|
or origin == 'http://localhost:9842' \
|
||||||
|
or origin == 'null'
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
if self.request.host not in self.request.headers['origin']:
|
if self.request.headers['origin'] not in ('null', 'http://localhost:9842') \
|
||||||
|
and self.request.host not in self.request.headers['origin']:
|
||||||
logger.debug('reject cross site attempt to open websocket %s', self.request)
|
logger.debug('reject cross site attempt to open websocket %s', self.request)
|
||||||
self.close()
|
self.close()
|
||||||
if self not in state.websockets:
|
if self not in state.websockets:
|
||||||
|
|
|
@ -3,24 +3,43 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Open Media Library</title>
|
<title>Open Media Library</title>
|
||||||
</head>
|
<link href="../oxjs/build/Ox.UI/css/Ox.UI.css" rel="stylesheet" type="text/css" />
|
||||||
<body>
|
<style>
|
||||||
|
#loading {
|
||||||
|
text-align: center;
|
||||||
|
padding-top: 24px;
|
||||||
|
}
|
||||||
|
#status {
|
||||||
|
padding-bottom: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<script>
|
<script>
|
||||||
function load() {
|
function load() {
|
||||||
var base = 'http://[::1]:9842',
|
var port = document.location.hash.length
|
||||||
img = new Image();
|
? document.location.hash.slice(1)
|
||||||
img.onload = function(event) {
|
: '9842',
|
||||||
document.location.href = base;
|
base = '//[::1]:' + port,
|
||||||
|
ws = new WebSocket('ws:' + base + '/ws');
|
||||||
|
ws.onopen = function(event) {
|
||||||
|
document.location.href = 'http:' + base;
|
||||||
|
};
|
||||||
|
ws.onerror = function(event) {
|
||||||
|
ws.close();
|
||||||
|
};
|
||||||
|
ws.onclose = function(event) {
|
||||||
|
setTimeout(load, 500);
|
||||||
};
|
};
|
||||||
img.src = base + '/static/oxjs/build/Ox.UI/png/transparent.png?' + new Date;
|
|
||||||
};
|
};
|
||||||
load();
|
load();
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
load();
|
document.querySelector('#status').innerHTML = 'Failed to start Open Media Library';
|
||||||
setTimeout(function() {
|
|
||||||
document.body.innerHTML = 'Looks like Open Media Library is not running.';
|
|
||||||
}, 10000);
|
}, 10000);
|
||||||
}, 3000);
|
|
||||||
</script>
|
</script>
|
||||||
|
</head>
|
||||||
|
<body class="OxThemeOxlight">
|
||||||
|
<div id="loading">
|
||||||
|
<div id="status">Starting Open Media Library</div>
|
||||||
|
<img src="../png/oml.png">
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue