allow websocket connections from files and localhost and use it in installer and static load file

This commit is contained in:
j 2014-08-12 14:51:38 +02:00
parent 01caf50ffa
commit 871a602acd
2 changed files with 39 additions and 13 deletions

View File

@ -16,8 +16,15 @@ logger = logging.getLogger('oml.websocket')
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):
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)
self.close()
if self not in state.websockets:

View File

@ -3,24 +3,43 @@
<head>
<meta charset="utf-8" />
<title>Open Media Library</title>
</head>
<body>
<link href="../oxjs/build/Ox.UI/css/Ox.UI.css" rel="stylesheet" type="text/css" />
<style>
#loading {
text-align: center;
padding-top: 24px;
}
#status {
padding-bottom: 16px;
}
</style>
<script>
function load() {
var base = 'http://[::1]:9842',
img = new Image();
img.onload = function(event) {
document.location.href = base;
var port = document.location.hash.length
? document.location.hash.slice(1)
: '9842',
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();
setTimeout(function() {
load();
setTimeout(function() {
document.body.innerHTML = 'Looks like Open Media Library is not running.';
}, 10000);
}, 3000);
document.querySelector('#status').innerHTML = 'Failed to start Open Media Library';
}, 10000);
</script>
</head>
<body class="OxThemeOxlight">
<div id="loading">
<div id="status">Starting Open Media Library</div>
<img src="../png/oml.png">
</div>
</body>
</html>