mirror of
https://github.com/kerberos-io/agent.git
synced 2025-10-26 17:50:28 +08:00
add more description error with onvif invalid credentials + send capabilitites as part of onvif/login or verify
This commit is contained in:
@@ -605,12 +605,12 @@ const docTemplate = `{
|
|||||||
"operationId": "verify-onvif",
|
"operationId": "verify-onvif",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Camera Config",
|
"description": "OnvifCredentials",
|
||||||
"name": "cameraConfig",
|
"name": "config",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/models.IPCamera"
|
"$ref": "#/definitions/models.OnvifCredentials"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -597,12 +597,12 @@
|
|||||||
"operationId": "verify-onvif",
|
"operationId": "verify-onvif",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Camera Config",
|
"description": "OnvifCredentials",
|
||||||
"name": "cameraConfig",
|
"name": "config",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/models.IPCamera"
|
"$ref": "#/definitions/models.OnvifCredentials"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -705,12 +705,12 @@ paths:
|
|||||||
description: Will verify the ONVIF connectivity.
|
description: Will verify the ONVIF connectivity.
|
||||||
operationId: verify-onvif
|
operationId: verify-onvif
|
||||||
parameters:
|
parameters:
|
||||||
- description: Camera Config
|
- description: OnvifCredentials
|
||||||
in: body
|
in: body
|
||||||
name: cameraConfig
|
name: config
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/models.IPCamera'
|
$ref: '#/definitions/models.OnvifCredentials'
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models.
|
|||||||
var pullPointAddress string
|
var pullPointAddress string
|
||||||
if config.Capture.IPCamera.ONVIFXAddr != "" {
|
if config.Capture.IPCamera.ONVIFXAddr != "" {
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
pullPointAddress, err = onvif.CreatePullPointSubscription(device)
|
pullPointAddress, err = onvif.CreatePullPointSubscription(device)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -260,7 +260,7 @@ loop:
|
|||||||
var onvifEventsList []byte
|
var onvifEventsList []byte
|
||||||
if config.Capture.IPCamera.ONVIFXAddr != "" {
|
if config.Capture.IPCamera.ONVIFXAddr != "" {
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
configurations, err := onvif.GetPTZConfigurationsFromDevice(device)
|
configurations, err := onvif.GetPTZConfigurationsFromDevice(device)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -553,7 +553,7 @@ loop:
|
|||||||
|
|
||||||
if pullPointAddress != "" {
|
if pullPointAddress != "" {
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
onvif.UnsubscribePullPoint(device, pullPointAddress)
|
onvif.UnsubscribePullPoint(device, pullPointAddress)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func HandleONVIFActions(configuration *models.Configuration, communication *mode
|
|||||||
|
|
||||||
// Connect to Onvif device
|
// Connect to Onvif device
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
// Get token from the first profile
|
// Get token from the first profile
|
||||||
@@ -189,7 +189,7 @@ func HandleONVIFActions(configuration *models.Configuration, communication *mode
|
|||||||
log.Log.Debug("onvif.HandleONVIFActions(): finished")
|
log.Log.Debug("onvif.HandleONVIFActions(): finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device, error) {
|
func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device, device.GetCapabilitiesResponse, error) {
|
||||||
log.Log.Debug("onvif.ConnectToOnvifDevice(): started")
|
log.Log.Debug("onvif.ConnectToOnvifDevice(): started")
|
||||||
dev, err := onvif.NewDevice(onvif.DeviceParams{
|
dev, err := onvif.NewDevice(onvif.DeviceParams{
|
||||||
Xaddr: cameraConfiguration.ONVIFXAddr,
|
Xaddr: cameraConfiguration.ONVIFXAddr,
|
||||||
@@ -197,6 +197,8 @@ func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device,
|
|||||||
Password: cameraConfiguration.ONVIFPassword,
|
Password: cameraConfiguration.ONVIFPassword,
|
||||||
AuthMode: "both",
|
AuthMode: "both",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var capabilities device.GetCapabilitiesResponse
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log.Debug("onvif.ConnectToOnvifDevice(): " + err.Error())
|
log.Log.Debug("onvif.ConnectToOnvifDevice(): " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
@@ -220,7 +222,6 @@ func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log.Error("onvif.ConnectToOnvifDevice(): " + err.Error())
|
log.Log.Error("onvif.ConnectToOnvifDevice(): " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
var capabilities device.GetCapabilitiesResponse
|
|
||||||
if err := decodedXML.DecodeElement(&capabilities, et); err != nil {
|
if err := decodedXML.DecodeElement(&capabilities, et); err != nil {
|
||||||
log.Log.Error("onvif.ConnectToOnvifDevice(): " + err.Error())
|
log.Log.Error("onvif.ConnectToOnvifDevice(): " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
@@ -231,7 +232,7 @@ func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device,
|
|||||||
log.Log.Info("onvif.ConnectToOnvifDevice(): successfully connected to device")
|
log.Log.Info("onvif.ConnectToOnvifDevice(): successfully connected to device")
|
||||||
}
|
}
|
||||||
log.Log.Debug("onvif.ConnectToOnvifDevice(): finished")
|
log.Log.Debug("onvif.ConnectToOnvifDevice(): finished")
|
||||||
return dev, err
|
return dev, capabilities, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTokenFromProfile(device *onvif.Device, profileId int) (xsdonvif.ReferenceToken, error) {
|
func GetTokenFromProfile(device *onvif.Device, profileId int) (xsdonvif.ReferenceToken, error) {
|
||||||
@@ -302,7 +303,7 @@ func GetPositionFromDevice(configuration models.Configuration) (xsdonvif.PTZVect
|
|||||||
var position xsdonvif.PTZVector
|
var position xsdonvif.PTZVector
|
||||||
// Connect to Onvif device
|
// Connect to Onvif device
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
// Get token from the first profile
|
// Get token from the first profile
|
||||||
@@ -899,28 +900,52 @@ func GetPTZFunctionsFromDevice(configurations ptz.GetConfigurationsResponse) ([]
|
|||||||
// @in header
|
// @in header
|
||||||
// @name Authorization
|
// @name Authorization
|
||||||
// @Tags onvif
|
// @Tags onvif
|
||||||
// @Param cameraConfig body models.IPCamera true "Camera Config"
|
// @Param config body models.OnvifCredentials true "OnvifCredentials"
|
||||||
// @Summary Will verify the ONVIF connectivity.
|
// @Summary Will verify the ONVIF connectivity.
|
||||||
// @Description Will verify the ONVIF connectivity.
|
// @Description Will verify the ONVIF connectivity.
|
||||||
// @Success 200 {object} models.APIResponse
|
// @Success 200 {object} models.APIResponse
|
||||||
func VerifyOnvifConnection(c *gin.Context) {
|
func VerifyOnvifConnection(c *gin.Context) {
|
||||||
var cameraConfig models.IPCamera
|
var onvifCredentials models.OnvifCredentials
|
||||||
err := c.BindJSON(&cameraConfig)
|
err := c.BindJSON(&onvifCredentials)
|
||||||
|
|
||||||
|
if err == nil && onvifCredentials.ONVIFXAddr != "" {
|
||||||
|
|
||||||
|
configuration := &models.Configuration{
|
||||||
|
Config: models.Config{
|
||||||
|
Capture: models.Capture{
|
||||||
|
IPCamera: models.IPCamera{
|
||||||
|
ONVIFXAddr: onvifCredentials.ONVIFXAddr,
|
||||||
|
ONVIFUsername: onvifCredentials.ONVIFUsername,
|
||||||
|
ONVIFPassword: onvifCredentials.ONVIFPassword,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
|
device, capabilities, err := ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
device, err := ConnectToOnvifDevice(&cameraConfig)
|
// Get token from the first profile
|
||||||
|
token, err := GetTokenFromProfile(device, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Log.Info("onvif.main.VerifyOnvifConnection(): successfully verified the ONVIF connection")
|
c.JSON(200, gin.H{
|
||||||
c.JSON(200, models.APIResponse{
|
"device": device,
|
||||||
Data: device,
|
"capabilities": capabilities,
|
||||||
|
"token": token,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(400, models.APIResponse{
|
c.JSON(400, gin.H{
|
||||||
Message: "onvif.main.VerifyOnvifConnection(): s went wrong while verifying the ONVIF connection " + err.Error(),
|
"data": "Something went wrong: " + err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(400, models.APIResponse{
|
c.JSON(400, gin.H{
|
||||||
Message: "onvif.main.VerifyOnvifConnection(): s went wrong while receiving the config " + err.Error(),
|
"data": "Something went wrong: " + err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.JSON(400, gin.H{
|
||||||
|
"data": "Something went wrong: " + err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1264,5 +1289,12 @@ func getXMLNode(xmlBody string, nodeName string) (*xml.Decoder, *xml.StartElemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for authorisation error
|
||||||
|
// - The action requested requires authorization and the sender is not authorized
|
||||||
|
if strings.Contains(xmlBody, "not authorized") {
|
||||||
|
return nil, nil, errors.New("getXMLNode(): not authorized, make sure you have the correct credentials")
|
||||||
|
} else {
|
||||||
return nil, nil, errors.New("getXMLNode(): " + err.Error())
|
return nil, nil, errors.New("getXMLNode(): " + err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,10 +44,15 @@ func LoginToOnvif(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, capabilities, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
|
if err == nil {
|
||||||
|
// Get token from the first profile
|
||||||
|
token, err := onvif.GetTokenFromProfile(device, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"device": device,
|
"device": device,
|
||||||
|
"capabilities": capabilities,
|
||||||
|
"token": token,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(400, gin.H{
|
||||||
@@ -59,6 +64,11 @@ func LoginToOnvif(c *gin.Context) {
|
|||||||
"data": "Something went wrong: " + err.Error(),
|
"data": "Something went wrong: " + err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
c.JSON(400, gin.H{
|
||||||
|
"data": "Something went wrong: " + err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOnvifCapabilities godoc
|
// GetOnvifCapabilities godoc
|
||||||
@@ -88,10 +98,10 @@ func GetOnvifCapabilities(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
_, capabilities, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"capabilities": onvif.GetCapabilitiesFromDevice(device),
|
"capabilities": capabilities,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(400, gin.H{
|
||||||
@@ -132,7 +142,7 @@ func DoOnvifPanTilt(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Get token from the first profile
|
// Get token from the first profile
|
||||||
@@ -206,7 +216,7 @@ func DoOnvifZoom(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Get token from the first profile
|
// Get token from the first profile
|
||||||
@@ -279,7 +289,7 @@ func GetOnvifPresets(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
presets, err := onvif.GetPresetsFromDevice(device)
|
presets, err := onvif.GetPresetsFromDevice(device)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -330,7 +340,7 @@ func GoToOnvifPreset(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err := onvif.GoToPresetFromDevice(device, onvifPreset.Preset)
|
err := onvif.GoToPresetFromDevice(device, onvifPreset.Preset)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -385,7 +395,7 @@ func DoGetDigitalInputs(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
_, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
_, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Get the digital inputs and outputs from the device
|
// Get the digital inputs and outputs from the device
|
||||||
inputOutputs, err := onvif.GetInputOutputs()
|
inputOutputs, err := onvif.GetInputOutputs()
|
||||||
@@ -454,7 +464,7 @@ func DoGetRelayOutputs(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
_, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
_, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Get the digital inputs and outputs from the device
|
// Get the digital inputs and outputs from the device
|
||||||
inputOutputs, err := onvif.GetInputOutputs()
|
inputOutputs, err := onvif.GetInputOutputs()
|
||||||
@@ -527,7 +537,7 @@ func DoTriggerRelayOutput(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err := onvif.TriggerRelayOutput(device, output)
|
err := onvif.TriggerRelayOutput(device, output)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -518,7 +518,7 @@ func HandleTriggerRelay(mqttClient mqtt.Client, hubKey string, payload models.Pa
|
|||||||
token := triggerRelayPayload.Token
|
token := triggerRelayPayload.Token
|
||||||
// Connect to Onvif device
|
// Connect to Onvif device
|
||||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Trigger relay output
|
// Trigger relay output
|
||||||
err := onvif.TriggerRelayOutput(device, token)
|
err := onvif.TriggerRelayOutput(device, token)
|
||||||
|
|||||||
Reference in New Issue
Block a user