mirror of
https://github.com/kerberos-io/agent.git
synced 2025-10-23 16:23:06 +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",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Camera Config",
|
||||
"name": "cameraConfig",
|
||||
"description": "OnvifCredentials",
|
||||
"name": "config",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.IPCamera"
|
||||
"$ref": "#/definitions/models.OnvifCredentials"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@@ -597,12 +597,12 @@
|
||||
"operationId": "verify-onvif",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Camera Config",
|
||||
"name": "cameraConfig",
|
||||
"description": "OnvifCredentials",
|
||||
"name": "config",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.IPCamera"
|
||||
"$ref": "#/definitions/models.OnvifCredentials"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@@ -705,12 +705,12 @@ paths:
|
||||
description: Will verify the ONVIF connectivity.
|
||||
operationId: verify-onvif
|
||||
parameters:
|
||||
- description: Camera Config
|
||||
- description: OnvifCredentials
|
||||
in: body
|
||||
name: cameraConfig
|
||||
name: config
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.IPCamera'
|
||||
$ref: '#/definitions/models.OnvifCredentials'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
|
@@ -235,7 +235,7 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models.
|
||||
var pullPointAddress string
|
||||
if config.Capture.IPCamera.ONVIFXAddr != "" {
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
pullPointAddress, err = onvif.CreatePullPointSubscription(device)
|
||||
if err != nil {
|
||||
@@ -260,7 +260,7 @@ loop:
|
||||
var onvifEventsList []byte
|
||||
if config.Capture.IPCamera.ONVIFXAddr != "" {
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
configurations, err := onvif.GetPTZConfigurationsFromDevice(device)
|
||||
if err == nil {
|
||||
@@ -553,7 +553,7 @@ loop:
|
||||
|
||||
if pullPointAddress != "" {
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
onvif.UnsubscribePullPoint(device, pullPointAddress)
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ func HandleONVIFActions(configuration *models.Configuration, communication *mode
|
||||
|
||||
// Connect to Onvif device
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
|
||||
// Get token from the first profile
|
||||
@@ -189,7 +189,7 @@ func HandleONVIFActions(configuration *models.Configuration, communication *mode
|
||||
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")
|
||||
dev, err := onvif.NewDevice(onvif.DeviceParams{
|
||||
Xaddr: cameraConfiguration.ONVIFXAddr,
|
||||
@@ -197,6 +197,8 @@ func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device,
|
||||
Password: cameraConfiguration.ONVIFPassword,
|
||||
AuthMode: "both",
|
||||
})
|
||||
|
||||
var capabilities device.GetCapabilitiesResponse
|
||||
if err != nil {
|
||||
log.Log.Debug("onvif.ConnectToOnvifDevice(): " + err.Error())
|
||||
} else {
|
||||
@@ -220,7 +222,6 @@ func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device,
|
||||
if err != nil {
|
||||
log.Log.Error("onvif.ConnectToOnvifDevice(): " + err.Error())
|
||||
} else {
|
||||
var capabilities device.GetCapabilitiesResponse
|
||||
if err := decodedXML.DecodeElement(&capabilities, et); err != nil {
|
||||
log.Log.Error("onvif.ConnectToOnvifDevice(): " + err.Error())
|
||||
} else {
|
||||
@@ -231,7 +232,7 @@ func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device,
|
||||
log.Log.Info("onvif.ConnectToOnvifDevice(): successfully connected to device")
|
||||
}
|
||||
log.Log.Debug("onvif.ConnectToOnvifDevice(): finished")
|
||||
return dev, err
|
||||
return dev, capabilities, err
|
||||
}
|
||||
|
||||
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
|
||||
// Connect to Onvif device
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
|
||||
// Get token from the first profile
|
||||
@@ -899,28 +900,52 @@ func GetPTZFunctionsFromDevice(configurations ptz.GetConfigurationsResponse) ([]
|
||||
// @in header
|
||||
// @name Authorization
|
||||
// @Tags onvif
|
||||
// @Param cameraConfig body models.IPCamera true "Camera Config"
|
||||
// @Param config body models.OnvifCredentials true "OnvifCredentials"
|
||||
// @Summary Will verify the ONVIF connectivity.
|
||||
// @Description Will verify the ONVIF connectivity.
|
||||
// @Success 200 {object} models.APIResponse
|
||||
func VerifyOnvifConnection(c *gin.Context) {
|
||||
var cameraConfig models.IPCamera
|
||||
err := c.BindJSON(&cameraConfig)
|
||||
var onvifCredentials models.OnvifCredentials
|
||||
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 {
|
||||
device, err := ConnectToOnvifDevice(&cameraConfig)
|
||||
// Get token from the first profile
|
||||
token, err := GetTokenFromProfile(device, 0)
|
||||
if err == nil {
|
||||
log.Log.Info("onvif.main.VerifyOnvifConnection(): successfully verified the ONVIF connection")
|
||||
c.JSON(200, models.APIResponse{
|
||||
Data: device,
|
||||
c.JSON(200, gin.H{
|
||||
"device": device,
|
||||
"capabilities": capabilities,
|
||||
"token": token,
|
||||
})
|
||||
} else {
|
||||
c.JSON(400, models.APIResponse{
|
||||
Message: "onvif.main.VerifyOnvifConnection(): s went wrong while verifying the ONVIF connection " + err.Error(),
|
||||
c.JSON(400, gin.H{
|
||||
"data": "Something went wrong: " + err.Error(),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
c.JSON(400, models.APIResponse{
|
||||
Message: "onvif.main.VerifyOnvifConnection(): s went wrong while receiving the config " + err.Error(),
|
||||
c.JSON(400, gin.H{
|
||||
"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())
|
||||
}
|
||||
}
|
||||
|
@@ -44,10 +44,15 @@ func LoginToOnvif(c *gin.Context) {
|
||||
}
|
||||
|
||||
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 {
|
||||
c.JSON(200, gin.H{
|
||||
"device": device,
|
||||
"capabilities": capabilities,
|
||||
"token": token,
|
||||
})
|
||||
} else {
|
||||
c.JSON(400, gin.H{
|
||||
@@ -59,6 +64,11 @@ func LoginToOnvif(c *gin.Context) {
|
||||
"data": "Something went wrong: " + err.Error(),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
c.JSON(400, gin.H{
|
||||
"data": "Something went wrong: " + err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// GetOnvifCapabilities godoc
|
||||
@@ -88,10 +98,10 @@ func GetOnvifCapabilities(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
_, capabilities, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
c.JSON(200, gin.H{
|
||||
"capabilities": onvif.GetCapabilitiesFromDevice(device),
|
||||
"capabilities": capabilities,
|
||||
})
|
||||
} else {
|
||||
c.JSON(400, gin.H{
|
||||
@@ -132,7 +142,7 @@ func DoOnvifPanTilt(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
|
||||
if err == nil {
|
||||
// Get token from the first profile
|
||||
@@ -206,7 +216,7 @@ func DoOnvifZoom(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
|
||||
if err == nil {
|
||||
// Get token from the first profile
|
||||
@@ -279,7 +289,7 @@ func GetOnvifPresets(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
presets, err := onvif.GetPresetsFromDevice(device)
|
||||
if err == nil {
|
||||
@@ -330,7 +340,7 @@ func GoToOnvifPreset(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
err := onvif.GoToPresetFromDevice(device, onvifPreset.Preset)
|
||||
if err == nil {
|
||||
@@ -385,7 +395,7 @@ func DoGetDigitalInputs(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
_, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
_, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
// Get the digital inputs and outputs from the device
|
||||
inputOutputs, err := onvif.GetInputOutputs()
|
||||
@@ -454,7 +464,7 @@ func DoGetRelayOutputs(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
_, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
_, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
// Get the digital inputs and outputs from the device
|
||||
inputOutputs, err := onvif.GetInputOutputs()
|
||||
@@ -527,7 +537,7 @@ func DoTriggerRelayOutput(c *gin.Context) {
|
||||
}
|
||||
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
err := onvif.TriggerRelayOutput(device, output)
|
||||
if err == nil {
|
||||
|
@@ -518,7 +518,7 @@ func HandleTriggerRelay(mqttClient mqtt.Client, hubKey string, payload models.Pa
|
||||
token := triggerRelayPayload.Token
|
||||
// Connect to Onvif device
|
||||
cameraConfiguration := configuration.Config.Capture.IPCamera
|
||||
device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration)
|
||||
if err == nil {
|
||||
// Trigger relay output
|
||||
err := onvif.TriggerRelayOutput(device, token)
|
||||
|
Reference in New Issue
Block a user