Add Permission checks to Scheduler, Probe, and ONVIF Device Man
parent
4e8300f3f9
commit
55f2567976
|
|
@ -26,10 +26,26 @@ module.exports = function(s,config,lang,app,io){
|
||||||
*/
|
*/
|
||||||
app.get(config.webPaths.apiPrefix+':auth/onvifDeviceManager/:ke/:id',function (req,res){
|
app.get(config.webPaths.apiPrefix+':auth/onvifDeviceManager/:ke/:id',function (req,res){
|
||||||
s.auth(req.params,async (user) => {
|
s.auth(req.params,async (user) => {
|
||||||
|
const groupKey = req.params.ke
|
||||||
|
const monitorId = req.params.id
|
||||||
|
const {
|
||||||
|
monitorPermissions,
|
||||||
|
monitorRestrictions,
|
||||||
|
} = s.getMonitorsPermitted(user.details,monitorId)
|
||||||
|
const {
|
||||||
|
isRestricted,
|
||||||
|
isRestrictedApiKey,
|
||||||
|
apiKeyPermissions,
|
||||||
|
} = s.checkPermission(user)
|
||||||
|
if(
|
||||||
|
isRestrictedApiKey && apiKeyPermissions.get_monitors_disallowed ||
|
||||||
|
isRestricted && !monitorPermissions[`${monitorId}_monitors`]
|
||||||
|
){
|
||||||
|
s.closeJsonResponse(res,{ok: false, msg: lang['Not Authorized']});
|
||||||
|
return
|
||||||
|
}
|
||||||
const endData = {ok: true}
|
const endData = {ok: true}
|
||||||
try{
|
try{
|
||||||
const groupKey = req.params.ke
|
|
||||||
const monitorId = req.params.id
|
|
||||||
const onvifDevice = await getOnvifDevice(groupKey,monitorId)
|
const onvifDevice = await getOnvifDevice(groupKey,monitorId)
|
||||||
const cameraInfo = await getUIFieldValues(onvifDevice)
|
const cameraInfo = await getUIFieldValues(onvifDevice)
|
||||||
endData.onvifData = cameraInfo
|
endData.onvifData = cameraInfo
|
||||||
|
|
@ -46,11 +62,29 @@ module.exports = function(s,config,lang,app,io){
|
||||||
*/
|
*/
|
||||||
app.post(config.webPaths.apiPrefix+':auth/onvifDeviceManager/:ke/:id/save',function (req,res){
|
app.post(config.webPaths.apiPrefix+':auth/onvifDeviceManager/:ke/:id/save',function (req,res){
|
||||||
s.auth(req.params,async (user) => {
|
s.auth(req.params,async (user) => {
|
||||||
|
const groupKey = req.params.ke
|
||||||
|
const monitorId = req.params.id
|
||||||
|
const {
|
||||||
|
monitorPermissions,
|
||||||
|
monitorRestrictions,
|
||||||
|
} = s.getMonitorsPermitted(user.details,monitorId);
|
||||||
|
const {
|
||||||
|
isRestricted,
|
||||||
|
isRestrictedApiKey,
|
||||||
|
apiKeyPermissions,
|
||||||
|
} = s.checkPermission(user);
|
||||||
|
if(
|
||||||
|
isRestrictedApiKey && apiKeyPermissions.control_monitors_disallowed
|
||||||
|
){
|
||||||
|
s.closeJsonResponse(res,{
|
||||||
|
ok: false,
|
||||||
|
msg: lang['Not Authorized']
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
const endData = {ok: true}
|
const endData = {ok: true}
|
||||||
const responses = {}
|
const responses = {}
|
||||||
try{
|
try{
|
||||||
const groupKey = req.params.ke
|
|
||||||
const monitorId = req.params.id
|
|
||||||
const onvifDevice = await getOnvifDevice(groupKey,monitorId)
|
const onvifDevice = await getOnvifDevice(groupKey,monitorId)
|
||||||
const form = s.getPostData(req)
|
const form = s.getPostData(req)
|
||||||
const videoToken = form.VideoConfiguration && form.VideoConfiguration.videoToken ? form.VideoConfiguration.videoToken : null
|
const videoToken = form.VideoConfiguration && form.VideoConfiguration.videoToken ? form.VideoConfiguration.videoToken : null
|
||||||
|
|
@ -100,10 +134,28 @@ module.exports = function(s,config,lang,app,io){
|
||||||
*/
|
*/
|
||||||
app.get(config.webPaths.apiPrefix+':auth/onvifDeviceManager/:ke/:id/reboot',function (req,res){
|
app.get(config.webPaths.apiPrefix+':auth/onvifDeviceManager/:ke/:id/reboot',function (req,res){
|
||||||
s.auth(req.params,async (user) => {
|
s.auth(req.params,async (user) => {
|
||||||
|
const groupKey = req.params.ke
|
||||||
|
const monitorId = req.params.id
|
||||||
|
const {
|
||||||
|
monitorPermissions,
|
||||||
|
monitorRestrictions,
|
||||||
|
} = s.getMonitorsPermitted(user.details,monitorId);
|
||||||
|
const {
|
||||||
|
isRestricted,
|
||||||
|
isRestrictedApiKey,
|
||||||
|
apiKeyPermissions,
|
||||||
|
} = s.checkPermission(user);
|
||||||
|
if(
|
||||||
|
isRestrictedApiKey && apiKeyPermissions.control_monitors_disallowed
|
||||||
|
){
|
||||||
|
s.closeJsonResponse(res,{
|
||||||
|
ok: false,
|
||||||
|
msg: lang['Not Authorized']
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
const endData = {ok: true}
|
const endData = {ok: true}
|
||||||
try{
|
try{
|
||||||
const groupKey = req.params.ke
|
|
||||||
const monitorId = req.params.id
|
|
||||||
const onvifDevice = await getOnvifDevice(groupKey,monitorId)
|
const onvifDevice = await getOnvifDevice(groupKey,monitorId)
|
||||||
const cameraInfo = await rebootCamera(onvifDevice)
|
const cameraInfo = await rebootCamera(onvifDevice)
|
||||||
endData.onvifData = cameraInfo
|
endData.onvifData = cameraInfo
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,20 @@ module.exports = function(s,config,lang,app,io){
|
||||||
*/
|
*/
|
||||||
app.get(config.webPaths.apiPrefix+':auth/probe/:ke',function (req,res){
|
app.get(config.webPaths.apiPrefix+':auth/probe/:ke',function (req,res){
|
||||||
s.auth(req.params,function(user){
|
s.auth(req.params,function(user){
|
||||||
|
const {
|
||||||
|
isRestricted,
|
||||||
|
isRestrictedApiKey,
|
||||||
|
apiKeyPermissions,
|
||||||
|
} = s.checkPermission(user);
|
||||||
|
if(
|
||||||
|
isRestrictedApiKey && apiKeyPermissions.control_monitors_disallowed
|
||||||
|
){
|
||||||
|
s.closeJsonResponse(res,{
|
||||||
|
ok: false,
|
||||||
|
msg: lang['Not Authorized']
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
ffprobe(req.query.url,req.params.auth,(endData) => {
|
ffprobe(req.query.url,req.params.auth,(endData) => {
|
||||||
s.closeJsonResponse(res,endData)
|
s.closeJsonResponse(res,endData)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -194,9 +194,11 @@ module.exports = function(s,config,lang,app,io){
|
||||||
var endData = {
|
var endData = {
|
||||||
ok : false
|
ok : false
|
||||||
}
|
}
|
||||||
if(user.details.sub){
|
const {
|
||||||
endData.msg = user.lang['Not Permitted']
|
isSubAccount,
|
||||||
s.closeJsonResponse(res,endData)
|
} = s.checkPermission(user)
|
||||||
|
if(isSubAccount){
|
||||||
|
s.closeJsonResponse(res,{ok: false, msg: lang['Not an Administrator Account']});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var whereQuery = [
|
var whereQuery = [
|
||||||
|
|
@ -234,9 +236,11 @@ module.exports = function(s,config,lang,app,io){
|
||||||
var endData = {
|
var endData = {
|
||||||
ok : false
|
ok : false
|
||||||
}
|
}
|
||||||
if(user.details.sub){
|
const {
|
||||||
endData.msg = user.lang['Not Permitted']
|
isSubAccount,
|
||||||
s.closeJsonResponse(res,endData)
|
} = s.checkPermission(user)
|
||||||
|
if(isSubAccount){
|
||||||
|
s.closeJsonResponse(res,{ok: false, msg: lang['Not an Administrator Account']});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch(req.params.action){
|
switch(req.params.action){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue