Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Working on issues #540

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion components/mdns/message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (scope) => {


// listen for newly added items
scope.events.on("added", ({ name, type, _matches }) => {
scope.events.on("add", ({ name, type, _matches }) => {
matchCallbacks.push({
name,
type,
Expand All @@ -24,6 +24,28 @@ module.exports = (scope) => {
});


// liste for removed items
scope.events.on("remove", ({ name, type }) => {
try {

let item = matchCallbacks.find((item) => {
return item.name === name && item.type === type;
});

let index = matchCallbacks.indexOf(item);

if (index !== -1) {
matchCallbacks.splice(index, 1);
}

} catch (err) {

logger.error(err, "Could not remove matchCallback");

}
});


scope.events.on("connected", (ws) => {

let questions = scope.items.map(({ type, name }) => {
Expand Down
8 changes: 8 additions & 0 deletions components/scenes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ class C_SCENES extends COMPONENT {
// fix #390
data.triggers.forEach((trigger, i, arr) => {
if (!(trigger instanceof Trigger)) {

arr[i] = new Trigger(trigger);

// data = scene item instance
// same handling as in class.scene.js
arr[i].signal.on("fire", () => {
data.trigger();
});

}
});

Expand Down
24 changes: 23 additions & 1 deletion components/ssdp/message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = (scope) => {

// listen for newly added items
//scope.events.on("added", ({ nt, usn, _matches, headers }) => {
scope.events.on("added", ({ nt, usn, _matches }) => {
scope.events.on("add", ({ nt, usn, _matches }) => {
matchCallbacks.push({
nt,
usn,
Expand All @@ -37,6 +37,28 @@ module.exports = (scope) => {
});


// liste for removed items
scope.events.on("remove", ({ name, type }) => {
try {

let item = matchCallbacks.find((item) => {
return item.name === name && item.type === type;
});

let index = matchCallbacks.indexOf(item);

if (index !== -1) {
matchCallbacks.splice(index, 1);
}

} catch (err) {

logger.error(err, "Could not remove matchCallback");

}
});


scope.events.on("message", (type, headers, description) => {

// feedback
Expand Down
3 changes: 3 additions & 0 deletions routes/auth-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const jwt = require("jsonwebtoken");

module.exports = (C_USERS, router) => {

const { logger } = C_USERS;

// check if the request came from the same machine
// either via reverse proxy or socket
// if it came via unix socket, handle the request as authentciated
Expand Down Expand Up @@ -57,6 +59,7 @@ module.exports = (C_USERS, router) => {
}, (err, decoded) => {
if (err) {

logger.error(err);
res.status(401).end();

} else {
Expand Down
40 changes: 27 additions & 13 deletions routes/router.auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const jwt = require("jsonwebtoken");
const C_USERS = require("../components/users");
const { logger } = C_USERS;

module.exports = (app, router) => {

router.get("/", (req, res) => {
router.get("/check", (req, res) => {
if (process.env.API_AUTH_ENABLED === "true") {

// override header header token with query token
Expand Down Expand Up @@ -79,32 +80,45 @@ module.exports = (app, router) => {
router.post("/logout", (req, res) => {
if (req.headers["x-auth-token"]) {

let decoded = jwt.decode(req.headers["x-auth-token"]);

if (!decoded.uuid || decoded.uuid !== process.env.UUID) {
res.status(401).end();
return;
}

C_USERS.logout(decoded.email, (err, user, success) => {
// TODO: use jwt.verify() instead, otherwise you could trigger a logout for any other user
//let decoded = jwt.decode(req.headers["x-auth-token"]);
jwt.verify(req.headers["x-auth-token"], process.env.USERS_JWT_SECRET, {
algorithms: [process.env.USERS_JWT_ALGORITHM]
}, (err, decoded) => {
if (err) {

logger.error(err);
res.status(401).end();

} else {

if (!user) {
if (!decoded.uuid || decoded.uuid !== process.env.UUID) {
res.status(401).end();
return;
}

res.status(200).json({
success
// NOTE: could this a security risk?
C_USERS.logout(decoded.email, (err, user, success) => {
if (err) {

res.status(401).end();

} else {

if (!user) {
res.status(401).end();
return;
}

res.status(200).json({
success
});

}
});

}
});

} else {

res.status(401).end();
Expand Down