Skip to content

Commit

Permalink
updates for object v3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjpanda committed Mar 26, 2022
1 parent 9bea697 commit 2b9987b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
15 changes: 14 additions & 1 deletion chimera/splitAndValidateEnvVars.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const isFolderCheck = (varName) => {
}

const confirmPath = (varName, shouldBeFolder=false) => {
if(process.env[varName].length == 0){
return
}
const isAbsolutePath = path.isAbsolute(process.env[varName])
if(process.env[varName].length != 0 && !isAbsolutePath){
if(!isAbsolutePath){
console.log(varName, "SHOULD BE AN ABSOLUTE PATH")
allEnvPresent = false
return
Expand Down Expand Up @@ -136,9 +139,19 @@ confirmPath("livestream_FOLDERPATH", true)
writeVarLine("object_ON")
writeVarLine("object_PORT")
env.gateway += writeVarLine("object_HOST")
writeVarLine("object_FULL_URL")
env.lib += writeVarLine("object_AUTH")

writeVarLine("object_CAMERA_URLS")
writeVarLine("object_minimumConfidence")
writeVarLine("object_alertUrls")

writeVarLine("object_headless_ON")
writeVarLine("object_browser_FILEPATH")
confirmPath("object_browser_FILEPATH")
writeVarLine("object_data_FOLDERPATH")
confirmPath("object_data_FOLDERPATH", true)

env.memory += writeVarLine("memory_ON")
env.memory += writeVarLine("memory_PORT")
env.memory += writeVarLine("memory_HOST")
Expand Down
6 changes: 6 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ livestream_CAMERA_URL_1 = Full url with authentication for rtsp stream
object_ON = (true | false)
object_PORT = Port for object server
object_HOST = https://object.server.example or http://127.0.0.1:8081
object_FULL_URL = https://chimera.server.example/object or http://127.0.0.1:8081/object
object_AUTH = Authorization token to bypass auth for object (keep secret)

object_CAMERA_URLS = array of strings with HLS stream urls

object_minimumConfidence = minimum confidence to warrant an alert for people detection
object_alertUrls = object webhook url array

object_headless_ON = (true | false)
object_browser_FILEPATH = file path to browser for object headless to use
object_data_FOLDERPATH = folder path to hold temp data

##################################################################
#
# Memory
Expand Down
14 changes: 14 additions & 0 deletions lib/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const jwt = require("jsonwebtoken")
const bcrypt = require("bcryptjs")

const schedulableUrls = ["/convert/createVideo", "/convert/createZip", "/file/pathMetrics", "/file/pathDelete", "/file/pathClean"]
const objectUrl = "/livestream/feed/"

module.exports = {
authorize: (req, res, next) => {
Expand All @@ -16,6 +17,10 @@ module.exports = {
let [key, value] = cookie.split("=")
return key == "bearertoken" && value.includes("Bearer")
})
const objectTokenCookie = cookies.find((cookie) => {
let [key] = cookie.split("=")
return key == "objecttoken"
})
if(bearerTokenCookie){
const bearerToken = bearerTokenCookie.split("=")[1]
jwt.verify(bearerToken.split("%20")[1], secretKey, (err, decoded) => {
Expand All @@ -26,6 +31,15 @@ module.exports = {
}
})
}
else if(objectTokenCookie){
const objectToken = objectTokenCookie.split("=")[1]
if(req.path.includes(objectUrl) && objectToken == process.env.object_AUTH){
next()
}
else{
method == "GET" ? res.redirect(303, "/?loginForm") : res.status(401).send({error: "unauthorized"})
}
}
else method == "GET" ? res.redirect(303, "/?loginForm") : res.status(401).send({error: "unauthorized"})
} else method == "GET" ? res.redirect(303, "/?loginForm") : res.status(401).send({error: "unauthorized"})
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chimera",
"version": "5.0.4",
"version": "5.1.0",
"description": "a microservices based security camera system",
"main": "server.js",
"engines": {
Expand Down Expand Up @@ -80,7 +80,7 @@
"mkdirp": "^1.0.4",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"object": "jjjpanda/object#v3.2.0",
"object": "jjjpanda/object#v3.3.0",
"pg": "^8.7.1",
"pm2": "^5.1.2",
"rimraf": "^3.0.2",
Expand Down

0 comments on commit 2b9987b

Please sign in to comment.