mirror of
https://github.com/UiO-Gaming/infoscreen3.git
synced 2026-11-05 13:56:52 +01:00
fixed rest of errors due adding schedules slides, also logout was broken due update of dependency library, works now
This commit is contained in:
1 parent
beaf0bc482
commit
84874a5197
7 files changed
+142
-125
No files matched your search
+10
-2
@@ -341,6 +341,8 @@ export default class admin {
|
||||
zoom: parseFloat(data.zoom) || 1.0,
|
||||
index: bundle.allSlides.length,
|
||||
transition: null,
|
||||
epochStart: -1,
|
||||
epochEnd: -1
|
||||
};
|
||||
|
||||
let obj = bundle.findSlideByUuid(filename);
|
||||
@@ -353,6 +355,8 @@ export default class admin {
|
||||
obj.displayTime = data.displayTime;
|
||||
obj.zoom = parseFloat(data.zoom) || 1.0;
|
||||
obj.transition = null;
|
||||
obj.epochStart = -1;
|
||||
obj.epochEnd = -1;
|
||||
}
|
||||
|
||||
bundle.save();
|
||||
@@ -402,11 +406,13 @@ export default class admin {
|
||||
enabled: true,
|
||||
displayTime: data.displayTime,
|
||||
type: "video",
|
||||
webUrl: data.url,
|
||||
url: data.url,
|
||||
mute: data.mute,
|
||||
loop: data.loop,
|
||||
index: bundle.allSlides.length,
|
||||
transition: null
|
||||
transition: null,
|
||||
epochStart: -1,
|
||||
epochEnd: -1
|
||||
};
|
||||
|
||||
let obj = bundle.findSlideByUuid(filename);
|
||||
@@ -420,6 +426,8 @@ export default class admin {
|
||||
obj.mute = data.mute;
|
||||
obj.loop = data.loop;
|
||||
obj.transition = null;
|
||||
obj.epochEnd = -1;
|
||||
obj.epochStart = -1;
|
||||
}
|
||||
|
||||
bundle.save();
|
||||
|
||||
+61
-59
@@ -27,80 +27,82 @@ export default function (websocket, dispatcher) {
|
||||
});
|
||||
|
||||
router.post('/login',
|
||||
function (req, res, next) {
|
||||
passport.authenticate('local', async function (err, user, info) {
|
||||
const ipAddr = req.ip;
|
||||
const usernameIPkey = getUsernameIPkey(req.body.username, ipAddr);
|
||||
function (req, res, next) {
|
||||
passport.authenticate('local', async function (err, user, info) {
|
||||
const ipAddr = req.ip;
|
||||
const usernameIPkey = getUsernameIPkey(req.body.username, ipAddr);
|
||||
|
||||
const [resUsernameAndIP, resSlowByIP] = await Promise.all([
|
||||
limiterConsecutiveFailsByUsernameAndIP.get(usernameIPkey),
|
||||
limiterSlowBruteByIP.get(ipAddr),
|
||||
]);
|
||||
const [resUsernameAndIP, resSlowByIP] = await Promise.all([
|
||||
limiterConsecutiveFailsByUsernameAndIP.get(usernameIPkey),
|
||||
limiterSlowBruteByIP.get(ipAddr),
|
||||
]);
|
||||
|
||||
let retrySecs = 0;
|
||||
let retrySecs = 0;
|
||||
|
||||
// Check if IP or Username + IP is already blocked
|
||||
if (resSlowByIP !== null && resSlowByIP.consumedPoints > maxWrongAttemptsByIPperDay) {
|
||||
retrySecs = Math.round(resSlowByIP.msBeforeNext / 1000) || 1;
|
||||
} else if (resUsernameAndIP !== null && resUsernameAndIP.consumedPoints > maxConsecutiveFailsByUsernameAndIP) {
|
||||
retrySecs = Math.round(resUsernameAndIP.msBeforeNext / 1000) || 1;
|
||||
}
|
||||
// Check if IP or Username + IP is already blocked
|
||||
if (resSlowByIP !== null && resSlowByIP.consumedPoints > maxWrongAttemptsByIPperDay) {
|
||||
retrySecs = Math.round(resSlowByIP.msBeforeNext / 1000) || 1;
|
||||
} else if (resUsernameAndIP !== null && resUsernameAndIP.consumedPoints > maxConsecutiveFailsByUsernameAndIP) {
|
||||
retrySecs = Math.round(resUsernameAndIP.msBeforeNext / 1000) || 1;
|
||||
}
|
||||
|
||||
if (retrySecs > 0) {
|
||||
console.log(`Blocked ${req.ip}, due too many requests`);
|
||||
res.status(429).end('Too Many Requests');
|
||||
return;
|
||||
} else {
|
||||
if (!user) {
|
||||
// Consume 1 point from limiters on wrong attempt and block if limits reached
|
||||
try {
|
||||
const promises = [limiterSlowBruteByIP.consume(ipAddr)];
|
||||
// Count failed attempts by Username + IP only for registered users
|
||||
promises.push(limiterConsecutiveFailsByUsernameAndIP.consume(usernameIPkey));
|
||||
await Promise.all(promises);
|
||||
if (retrySecs > 0) {
|
||||
console.log(`Blocked ${req.ip}, due too many requests`);
|
||||
res.status(429).end('Too Many Requests');
|
||||
return;
|
||||
} else {
|
||||
if (!user) {
|
||||
// Consume 1 point from limiters on wrong attempt and block if limits reached
|
||||
try {
|
||||
const promises = [limiterSlowBruteByIP.consume(ipAddr)];
|
||||
// Count failed attempts by Username + IP only for registered users
|
||||
promises.push(limiterConsecutiveFailsByUsernameAndIP.consume(usernameIPkey));
|
||||
await Promise.all(promises);
|
||||
|
||||
return res.redirect('/login');
|
||||
} catch (rlRejected) {
|
||||
if (rlRejected instanceof Error) {
|
||||
throw rlRejected;
|
||||
} else {
|
||||
console.log(`Blocked ${req.ip}, due too many requests`);
|
||||
res.status(429).end('Too Many Requests');
|
||||
return;
|
||||
}
|
||||
return res.redirect('/login');
|
||||
} catch (rlRejected) {
|
||||
if (rlRejected instanceof Error) {
|
||||
throw rlRejected;
|
||||
} else {
|
||||
console.log(`Blocked ${req.ip}, due too many requests`);
|
||||
res.status(429).end('Too Many Requests');
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
req.logIn(user, async function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (resUsernameAndIP !== null && resUsernameAndIP.consumedPoints > 0) {
|
||||
// Reset on successful authorisation
|
||||
await limiterConsecutiveFailsByUsernameAndIP.delete(usernameIPkey);
|
||||
}
|
||||
|
||||
if (req.session.location) {
|
||||
return res.redirect(req.session.location);
|
||||
}
|
||||
return res.redirect("/");
|
||||
});
|
||||
}
|
||||
|
||||
req.logIn(user, async function (err) {
|
||||
if (err) {
|
||||
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (resUsernameAndIP !== null && resUsernameAndIP.consumedPoints > 0) {
|
||||
// Reset on successful authorisation
|
||||
await limiterConsecutiveFailsByUsernameAndIP.delete(usernameIPkey);
|
||||
}
|
||||
|
||||
if (req.session.location) {
|
||||
return res.redirect(req.session.location);
|
||||
}
|
||||
return res.redirect("/");
|
||||
});
|
||||
|
||||
if (err) {
|
||||
|
||||
return next(err);
|
||||
}
|
||||
})(req, res, next);
|
||||
});
|
||||
}
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
router.get('/logout',
|
||||
function (req, res) {
|
||||
req.logout();
|
||||
res.redirect('/');
|
||||
});
|
||||
function (req, res) {
|
||||
req.logout({}, (err) => {
|
||||
res.redirect('/')
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
router.get('/empty', function (req, res, next) {
|
||||
res.render('empty');
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
<button class="ui small basic inverted icon button"
|
||||
onclick="editSlide('{{ slide.uuid }}', '{{ slide.type }}');"><i
|
||||
class="edit outline icon"></i></button>
|
||||
<div onclick="duplicateSlide('{{bundle.name}}','{{slide.uuid}}')" class="ui small basic inverted icon button"><i class="ui copy icon"></i></div>
|
||||
<div onclick="duplicateSlide('{{bundle.name}}','{{slide.uuid}}')" class="ui small basic inverted icon button"><i class="ui copy icon"></i></div>
|
||||
<button class="ui small basic inverted icon button"
|
||||
onclick="remove('{{ slide.uuid }}');"><i class="delete icon"></i>
|
||||
</button>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="editable">{{ slide.name }} </div>
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var socket = io.connect("{{ config.serverUrl }}:{{ config.serverListenPort }}/admin");
|
||||
var socket = io("{{ config.serverUrl }}/admin");
|
||||
var bundleName = "{{ bundle.name }}";
|
||||
</script>
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
socket.on("callback.updateBundleData", function() {
|
||||
socket.on("callback.updateBundleData", function() {
|
||||
document.location.reload(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
{% block header %}
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
{% if config.useLocalAssets %}
|
||||
<script src="/assets/jquery.jeditable.min.js"></script>
|
||||
<script src="/assets/jquery.jeditable.min.js"></script>
|
||||
{% else %}
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jeditable.js/2.0.6/jquery.jeditable.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jeditable.js/2.0.6/jquery.jeditable.min.js"></script>
|
||||
{% endif %}
|
||||
<style>
|
||||
<style>
|
||||
#sortable1, #sortable2 {
|
||||
height: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -24,11 +24,11 @@
|
||||
<input type="hidden" name="bundle1">
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Bundle</div>
|
||||
<div class="menu">
|
||||
<div class="menu">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui slides list connectedSortable" id="sortable1" data-bundleDir="">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="eight wide column">
|
||||
@@ -36,7 +36,7 @@
|
||||
<input type="hidden" name="bundle2">
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Bundle</div>
|
||||
<div class="menu">
|
||||
<div class="menu">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui slides list connectedSortable" id="sortable2" data-bundleDir="">
|
||||
@@ -46,8 +46,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var socket = io.connect("{{ config.serverUrl }}:{{ config.serverListenPort }}/admin");
|
||||
|
||||
var socket = io("{{ config.serverUrl }}/admin");
|
||||
|
||||
function editSlide(bundleName, uuid, type) {
|
||||
switch (type) {
|
||||
case "slide":
|
||||
@@ -71,21 +71,21 @@
|
||||
socket.emit("admin.removeSlide", {bundleName: bundleDir, uuid: uuid});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function updateBundleData() {
|
||||
loadBundleData("#sortable1", $("#bundle1").dropdown("get value"));
|
||||
loadBundleData("#sortable2", $("#bundle2").dropdown("get value"));
|
||||
loadBundleData("#sortable2", $("#bundle2").dropdown("get value"));
|
||||
}
|
||||
|
||||
|
||||
function loadBundleData(block, bundleDir) {
|
||||
$.getJSON("/admin/ajax/getSlides?bundle="+bundleDir, function (data) {
|
||||
var htmlData = "";
|
||||
|
||||
for(var slide of data.allSlides) {
|
||||
htmlData +=`<div class="ui green message item" data-uuid="${slide.uuid}" data-bundle="${bundleDir}">
|
||||
<div class="ui right floated content" style="width: fit-content;">
|
||||
|
||||
for(var slide of data.allSlides) {
|
||||
htmlData +=`<div class="ui green message item" data-uuid="${slide.uuid}" data-bundle="${bundleDir}">
|
||||
<div class="ui right floated content" style="width: fit-content;">
|
||||
<button class="ui small basic inverted icon button"
|
||||
onclick="editSlide('${bundleDir}','${ slide.uuid }', '${ slide.type }');"><i
|
||||
class="edit outline icon"></i></button>
|
||||
@@ -95,16 +95,16 @@
|
||||
<div class="content">
|
||||
<i class="ui icon move"></i>
|
||||
<span class="editable">${slide.name}</span>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
$(block).data('bundleDir',bundleDir);
|
||||
$(block).html(htmlData);
|
||||
$(block).html(htmlData);
|
||||
$('.editable').editable(function (value, settings) {
|
||||
var uuid = $(this).parent().parent().data("uuid");
|
||||
var bundle = $(this).parent().parent().data("bundle");
|
||||
socket.emit("admin.renameSlide", { uuid: uuid, name: value, bundleName: bundle });
|
||||
socket.emit("admin.renameSlide", { uuid: uuid, name: value, bundleName: bundle });
|
||||
return (value);
|
||||
}, {
|
||||
submit: 'rename',
|
||||
@@ -113,10 +113,10 @@
|
||||
cssclass: 'ui mini nopadded form',
|
||||
cancelcssclass: 'ui tiny basic negative button',
|
||||
submitcssclass: 'ui tiny basic positive button',
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$(function () {
|
||||
@@ -127,19 +127,19 @@
|
||||
items.push({value: elem.dir, name: elem.name, selected: boolval});
|
||||
boolval = false;
|
||||
}
|
||||
|
||||
$('#bundle1').dropdown({
|
||||
|
||||
$('#bundle1').dropdown({
|
||||
values: items,
|
||||
onChange: function (_value, _text, _item) {
|
||||
if (_value !== "") {
|
||||
loadBundleData("#sortable1", _value);
|
||||
loadBundleData("#sortable1", _value);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#bundle2').dropdown({
|
||||
$('#bundle2').dropdown({
|
||||
values: items,
|
||||
onChange: function (_value, _text, _item) {
|
||||
onChange: function (_value, _text, _item) {
|
||||
if (_value !== "") {
|
||||
loadBundleData("#sortable2", _value);
|
||||
}
|
||||
@@ -148,7 +148,7 @@
|
||||
|
||||
});
|
||||
|
||||
$("#sortable1").sortable({
|
||||
$("#sortable1").sortable({
|
||||
connectWith: ".connectedSortable",
|
||||
handle: ".move",
|
||||
cursor: "move",
|
||||
@@ -161,16 +161,16 @@
|
||||
if (position < 0) {
|
||||
position = 0;
|
||||
}
|
||||
socket.emit("admin.moveSlide", {from: originBundle, to: targetBundle, uuid: uuid, position:position });
|
||||
socket.emit("admin.moveSlide", {from: originBundle, to: targetBundle, uuid: uuid, position:position });
|
||||
},
|
||||
stop: function (event, element) {
|
||||
var sortedIDs = $("#sortable1").sortable("toArray", {attribute: "data-uuid"});
|
||||
var currentBundle = $("#bundle1").dropdown("get value");
|
||||
socket.emit("admin.reorderSlides", { bundleName: currentBundle, sortedIDs: sortedIDs });
|
||||
}
|
||||
socket.emit("admin.reorderSlides", { bundleName: currentBundle, sortedIDs: sortedIDs });
|
||||
}
|
||||
}).disableSelection();
|
||||
|
||||
$("#sortable2").sortable({
|
||||
|
||||
$("#sortable2").sortable({
|
||||
connectWith: ".connectedSortable",
|
||||
handle: ".move",
|
||||
cursor: "move",
|
||||
@@ -178,26 +178,26 @@
|
||||
var targetBundle = $("#bundle2").dropdown("get value");
|
||||
var originBundle = ui.item[0].dataset.bundle;
|
||||
var uuid = ui.item[0].dataset.uuid;
|
||||
var sortedIDs = $("#sortable1").sortable("toArray", {attribute: "data-uuid"});
|
||||
var sortedIDs = $("#sortable1").sortable("toArray", {attribute: "data-uuid"});
|
||||
var position = sortedIDs.indexOf(uuid)-1;
|
||||
if (position < 0) {
|
||||
position = 0;
|
||||
}
|
||||
socket.emit("admin.moveSlide", {from: originBundle, to: targetBundle, uuid: uuid, position: position });
|
||||
}
|
||||
socket.emit("admin.moveSlide", {from: originBundle, to: targetBundle, uuid: uuid, position: position });
|
||||
},
|
||||
stop: function (event, ui) {
|
||||
stop: function (event, ui) {
|
||||
var sortedIDs = $("#sortable2").sortable("toArray", {attribute: "data-uuid"});
|
||||
var currentBundle = $("#bundle2").dropdown("get value");
|
||||
socket.emit("admin.reorderSlides", { bundleName: currentBundle, sortedIDs: sortedIDs });
|
||||
}
|
||||
socket.emit("admin.reorderSlides", { bundleName: currentBundle, sortedIDs: sortedIDs });
|
||||
}
|
||||
}).disableSelection();
|
||||
});
|
||||
|
||||
socket.on("connect", function () {
|
||||
socket.on("connect", function () {
|
||||
socket.emit("admin.editBundles", {});
|
||||
});
|
||||
|
||||
socket.on("callback.updateBundleData", function() {
|
||||
socket.on("callback.updateBundleData", function() {
|
||||
updateBundleData();
|
||||
});
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
var socket = io.connect("{{ config.serverUrl }}:{{ config.serverListenPort }}/admin-{{ displayId }}");
|
||||
var socket = io("{{ config.serverUrl }}/admin-{{ displayId }}");
|
||||
|
||||
$(function () {
|
||||
$("#time").checkbox();
|
||||
@@ -102,7 +102,9 @@
|
||||
webUrl: $("#weburl").val(),
|
||||
duration: duration,
|
||||
zoom: zoom,
|
||||
displayTime: $("#displaytime").checkbox('is checked')
|
||||
displayTime: $("#displaytime").checkbox('is checked'),
|
||||
epochStart: -1,
|
||||
epochEnd: -1
|
||||
};
|
||||
socket.emit("edit.saveLink", obj);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{% block header %}
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
var socket = io.connect("{{ config.serverUrl }}:{{ config.serverListenPort }}/admin");
|
||||
var socket = io("{{ config.serverUrl }}/admin-{{ displayId }}");
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
+17
-12
@@ -60,7 +60,7 @@
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
var socket = io.connect("{{ config.serverUrl }}:{{ config.serverListenPort }}/admin-{{ displayId }}");
|
||||
var socket = io("{{ config.serverUrl }}/admin-{{ displayId }}");
|
||||
var videoDuration = 0;
|
||||
|
||||
$(function () {
|
||||
@@ -68,10 +68,10 @@
|
||||
$("#dropdownAnnounce").dropdown();
|
||||
});
|
||||
|
||||
function loadVideo() {
|
||||
function loadVideo() {
|
||||
var video = document.getElementById("preview");
|
||||
video.src = $('#url').val();
|
||||
video.onloadedmetadata = function() {
|
||||
video.onloadedmetadata = function() {
|
||||
videoDuration = video.duration;
|
||||
setActive();
|
||||
};
|
||||
@@ -96,19 +96,22 @@
|
||||
json: {
|
||||
type: "video",
|
||||
duration: videoDuration,
|
||||
url: $("#url").val(),
|
||||
url: $("#url").val(),
|
||||
displayTime: $("#displaytime").checkbox('is checked'),
|
||||
mute: $("#mute").checkbox('is checked'),
|
||||
loop: $("#loop").checkbox('is checked')
|
||||
loop: $("#loop").checkbox('is checked'),
|
||||
epochStart: -1,
|
||||
epochEnd: -1
|
||||
},
|
||||
displayId: dispId,
|
||||
transition: null,
|
||||
displayId: dispId,
|
||||
transition: null,
|
||||
|
||||
|
||||
};
|
||||
socket.emit("admin.overrideVideo", obj);
|
||||
}
|
||||
|
||||
function save() {
|
||||
function save() {
|
||||
if (videoDuration == 0) {
|
||||
alert("video duration not set!");
|
||||
return;
|
||||
@@ -119,10 +122,12 @@
|
||||
bundleName: bundle,
|
||||
duration: videoDuration,
|
||||
name: $("#name").val(),
|
||||
url: $("#url").val(),
|
||||
url: $("#url").val(),
|
||||
displayTime: $("#displaytime").checkbox('is checked'),
|
||||
mute: $("#mute").checkbox('is checked'),
|
||||
loop: $("#loop").checkbox('is checked')
|
||||
loop: $("#loop").checkbox('is checked'),
|
||||
epochStart: -1,
|
||||
epochEnd: -1.
|
||||
};
|
||||
socket.emit("edit.saveVideo", obj);
|
||||
}
|
||||
@@ -136,8 +141,8 @@
|
||||
var json = data.json;
|
||||
|
||||
$("#name").val(json.name);
|
||||
$("#url").val(json.url);
|
||||
|
||||
$("#url").val(json.url);
|
||||
|
||||
if (json.displayTime) {
|
||||
$("#displaytime").checkbox('set checked', true);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user