From b4a063d70d1afb4f5998a122915c0bf39a04b5d2 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Mon, 28 Sep 2026 19:02:20 +0200 Subject: [PATCH 01/15] preset --- 3rdparty/ponvif.php | 21 +++-- core/ajax/camera.ajax.php | 17 +++- core/class/camera.class.php | 154 ++++++++++++++++++++++++++++++--- desktop/js/camera.js | 119 ++++++++++++++++++++++++- desktop/modal/discover.cam.php | 70 ++++++++------- desktop/php/camera.php | 87 +++++++++++-------- 6 files changed, 376 insertions(+), 92 deletions(-) diff --git a/3rdparty/ponvif.php b/3rdparty/ponvif.php index f244aff..28a8876 100644 --- a/3rdparty/ponvif.php +++ b/3rdparty/ponvif.php @@ -14,7 +14,7 @@ * getDeviceUri() - fixed "deviceuri" * setDeviceUri() - fixed "deviceuri" * setMediaUri() - added MediaUri setter - +* * Improved by Cycne 10.06.2017 ( Reference: https://www.onvif.org/ver10/media/wsdl/media.wsdl ) * getCodecEncoders() * media_GetVideoEncoderConfigurations() @@ -22,18 +22,25 @@ * media_SetVideoEncoderConfiguration() * media_GetOSDs() * media_DeleteOSD() -* * + * FIX by Aidom 30.11.2019 * Correction ONVIF pour JeeDom * - makeToken() * - _xml2array * - _sendrequest -* - _passwordDigest +* - _passwordDigest + +* Improved by Freddye83 24.03.2021 +* Add function setPTZUri to speed action on ptz (no need initialize()) + * FIX by Flobul 18.08.2023 * Correction sourcetoken * Catch error in request method * Fix discovery method -* + +* Fix by Phpvarious 20.09.2026 +* ptz_GetPresets (PTZPosition on null) + **/ class Ponvif { @@ -84,6 +91,7 @@ public function getMediaUri() {return $this->mediauri;} public function setMediaUri($mediauri) {$this->mediauri = $mediauri;} public function getCodecEncoders($codec) {return $this->_getCodecEncoders($codec);} public function getPTZUri() {return $this->ptzuri;} + public function setPTZUri($ptzuri) {$this->ptzuri = $ptzuri; } public function getBaseUrl() {return $this->baseuri;} public function getSupportedVersion() {return $this->onvifversion;} public function getCapabilities() {return $this->capabilities;} @@ -583,7 +591,7 @@ public function ptz_GetPresets($profileToken) { foreach ($getpresetsresponse as $preset) { $presets[] = array('Token' => $preset['@attributes']['token'], 'Name' => $preset['Name'], - 'PTZPosition' => $preset['PTZPosition']); + 'PTZPosition' => isset($preset['PTZPosition']) ? $preset['PTZPosition'] : ""); // by Phpvarious - replace 'PTZPosition' => $preset['PTZPosition']); } return $presets; } @@ -1188,5 +1196,4 @@ public function events_Pull($endpoint) { return $response['Envelope']['Body']['PullMessagesResponse']; } - } - + } \ No newline at end of file diff --git a/core/ajax/camera.ajax.php b/core/ajax/camera.ajax.php index e5cf011..ae3df53 100644 --- a/core/ajax/camera.ajax.php +++ b/core/ajax/camera.ajax.php @@ -101,6 +101,22 @@ camera::addDiscoverCam(json_decode(init('config'), true)); ajax::success(); } + + if (init('action') == 'getConfigOnvif') { + $camera = camera::byId(init('id')); + if (!is_object($camera)) { + throw new Exception(__('Equipement introuvable', __FILE__) . ' : ' . init('id')); + } + ajax::success($camera->getConfigOnvif()); + } + + if (init('action') == 'createCmdPresetOnvif') { + $camera = camera::byId(init('id')); + if (!is_object($camera)) { + throw new Exception(__('Equipement introuvable', __FILE__) . ' : ' . init('id')); + } + ajax::success($camera->createCmdPresetOnvif()); + } if (init('action') == 'removeRecord') { $file = init('file'); @@ -111,7 +127,6 @@ } if (init('action') == 'removeAllSnapshot') { - /** @var camera $camera */ $camera = camera::byId(init('id')); if (!is_object($camera)) { throw new Exception(__('Equipement introuvable', __FILE__) . ' : ' . init('id')); diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 9ff5d67..3843170 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -300,13 +300,17 @@ public static function discoverCam() { $onvif = new Ponvif(); $onvif->setDiscoveryTimeout(10); $result = $onvif->discover(); + log::add(__CLASS__, 'debug', 'discoverCam -> ' . json_encode($result)); if (count($result) > 0) { foreach ($result as $cam) { $url = parse_url($cam['XAddrs']); $return[] = array( - 'ip' => $url['host'] . ':' . $url['port'], + 'ip' => $url['host'], + 'port' => $url['port'], 'type' => $cam['Types'], 'discover' => 'onvif', + 'urn' => $cam['EndpointReference']['Address'], + 'xaddrs' => $cam['XAddrs'], 'exist' => false, ); } @@ -324,13 +328,12 @@ public static function discoverCam() { } public static function addDiscoverCam($_config) { - $host = explode(':', $_config['ip']); $eqLogic = new self(); - $eqLogic->setName($host[0]); + $eqLogic->setName($_config['ip']); $eqLogic->setConfiguration('username', $_config['username']); $eqLogic->setConfiguration('password', $_config['password']); - $eqLogic->setConfiguration('ip', $host[0]); - $eqLogic->setConfiguration('onvif_port', $host[1]); + $eqLogic->setConfiguration('ip', $_config['ip']); + $eqLogic->setConfiguration('onvif_port', $_config['port']); $eqLogic->setEqType_name(__CLASS__); $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); @@ -355,6 +358,105 @@ public function configOnvif() { log::add(__CLASS__, 'error', '[ONVIF] ' . $e->getMessage()); } } + + public function getConfigOnvif() { + $return = array(); + $ip = $this->getConfiguration('ip'); + if ($ip == 'null' || $ip == '') { + throw new Exception(__("L'adresse IP ne peut être vide.", __FILE__)); + } + + foreach (camera::discoverCam() as $_cam) { + if ($_cam['ip'] == $ip) { + $return['onvif_port'] = $_cam['port']; + $xaddr = explode(" ",$_cam['xaddrs']); + + $onvif = new ponvif(); + $onvif->setUsername($this->getConfiguration('username')); + $onvif->setPassword($this->getConfiguration('password')); + $onvif->setIPAddress($ip); + $onvif->setMediaUri($xaddr[0]); + $onvif->initialize(); + try { + $profiles = $onvif->media_GetProfiles(); + $token = $profiles[0]['@attributes']['token']; + $return['cameraStreamProfileToken'] = $token; + } catch(Exception $e) { + log::add(__CLASS__,'debug','media_GetProfiles : ' . $e); + } + + try { + $ptzUri = $onvif->getPTZUri(); + $return['ptzuri'] = $ptzUri; + } catch(Exception $e) { + log::add(__CLASS__,'debug','getPTZUri : ' . $e); + } + break; + } + } + return array('configuration' => $return); + } + + public function createCmdPresetOnvif() { + $return = array(); + $ip = $this->getConfiguration('ip'); + if ($ip == 'null' || $ip == '') { + throw new Exception(__("L'adresse IP ne peut etre vide.", __FILE__)); + } + + foreach (camera::discoverCam() as $_cam) { + if ($_cam['ip'] == $ip) { + $onvif = new ponvif(); + $onvif->setUsername($this->getConfiguration('username')); + $onvif->setPassword($this->getConfiguration('password')); + $onvif->setIPAddress($ip); + $onvif->setMediaUri($xaddr[0]); + $onvif->initialize(); + try { + $profiles = $onvif->media_GetProfiles(); + $token = $profiles[0]['@attributes']['token']; + } catch(Exception $e) { + log::add(__CLASS__,'debug','media_GetProfiles : ' . $e); + } + + try { + $presets = $onvif->ptz_GetPresets($token); + $nbpresetMax = 10; + log::add(__CLASS__,'debug',json_encode($presets)); + $nbpreset = 1; + $nbCreatepreset = 0; + foreach ($presets as $preset) { + if ($nbpreset > $nbpresetMax) break; + $logicalId = 'preset::' . preg_replace("/\s+/", '', $preset['Token']); + if (!is_object($this->getCmd(null, $logicalId))) { + log::add(__CLASS__,'debug', 'création du preset avec logicalId ' . $logicalId); + $cmdPreset = new cameraCmd(); + $cmdPreset->setName($preset['Name']); + $cmdPreset->setType('action'); + $cmdPreset->setSubType('other'); + $cmdPreset->setEqLogic_id($this->getId()); + $cmdPreset->setConfiguration('request', 'preset'); + $cmdPreset->setConfiguration('token', $preset['Token']); + $cmdPreset->setLogicalId($logicalId); + try { + $cmdPreset->save(); + } catch (Exception $e) { + $cmdPreset->setName($preset['Name'] . rand(0, 9999)); + $cmdPreset->save(); + } + $nbCreatepreset++; + } + $nbpreset++; + } + $return['createPreset'] = $nbCreatepreset; + } catch(Exception $e) { + log::add(__CLASS__,'debug','ptz_GetPresets : ' . $e); + } + } + break; + } + return $return; + } public function decrypt() { $this->setConfiguration('password', utils::decrypt($this->getConfiguration('password'))); @@ -606,10 +708,10 @@ public function toHtml($_version = 'dashboard', $_fluxOnly = false) { $sendSnapshot = $this->getCmd(null, 'sendSnapshot'); $recordState = $this->getCmd(null, 'recordState'); $replace_action = array( - '#record_id#' => $sendSnapshot->getId(), - '#stopRecord_id#' => $stopRecord->getId(), - '#recordState#' => $recordState->execCmd(), - '#recordState_id#' => $recordState->getId(), + '#record_id#' => is_object($sendSnapshot) ? $sendSnapshot->getId() : '""', + '#stopRecord_id#' => is_object($stopRecord) ? $stopRecord->getId() : '""', + '#recordState#' => is_object($recordState) ? $recordState->execCmd() : '0', + '#recordState_id#' => is_object($recordState) ? $recordState->getId() : '""', ); $on = $this->getCmd(null, 'on'); $off = $this->getCmd(null, 'off'); @@ -1075,8 +1177,19 @@ public function execute($_options = null) { $onvif = new Ponvif(); $onvif->setUsername($eqLogic->getConfiguration('username')); $onvif->setPassword($eqLogic->getConfiguration('password')); - $onvif->setIPAddress($eqLogic->getConfiguration('ip') . ':' . $eqLogic->getConfiguration('onvif_port', 80)); - $onvif->initialize(); + + $ptzuri = trim($eqLogic->getConfiguration('ptzuri', '')); + $fastMethode = ($ptzuri != ''); + + if ($fastMethode) { + // fast method (no initialize) + $onvif->setIPAddress($eqLogic->getConfiguration('ip')); + $onvif->setPTZUri($ptzuri); + } else { + // slow method + $onvif->setIPAddress($eqLogic->getConfiguration('ip') . ':' . $eqLogic->getConfiguration('onvif_port', 80)); + $onvif->initialize(); + } $action = false; @@ -1124,11 +1237,24 @@ public function execute($_options = null) { $cmd->execCmd(); } return true; + } else if ($action && $fastMethode) { + $onvif->ptz_Stop($profileToken, 'true', 'true'); + return true; + } + + //////////// Preset ///////////////// + if (strpos($logicalId, 'preset') !== false) { + $presetToken = $this->getConfiguration('token', ''); + if ($presetToken != '') { + $onvif->ptz_GotoPreset($profileToken, $presetToken, $speedX, $speedY, $speedZ); + } } + ////////////////////////////////// } catch (Exception $e) { - log::add(__CLASS__, 'debug', 'onvif error reason for ' . $logicalId . ' : ' . json_encode($onvif->getLastResponse())); + log::add('camera', 'debug', 'onvif error reason for ' . $logicalId . ' : ' . json_encode($onvif->getLastResponse())); } } + if (strpos($request, '#') === 0) { $cmd = cmd::byId(str_replace('#', '', $request)); if (is_object($cmd)) { @@ -1144,7 +1270,7 @@ public function execute($_options = null) { '#port#' => $eqLogic->getConfiguration('port'), ); $request = str_replace(array_keys($replace), $replace, $request); - log::add(__CLASS__, 'debug', 'Executing ' . $request); + log::add('camera', 'debug', 'Executing ' . $request); shell_exec($request); } else { $http = new com_http($url, $eqLogic->getConfiguration('username'), $eqLogic->getConfiguration('password')); @@ -1161,4 +1287,4 @@ public function execute($_options = null) { } /* * **********************Getteur Setteur*************************** */ -} +} \ No newline at end of file diff --git a/desktop/js/camera.js b/desktop/js/camera.js index c60418d..0c91042 100644 --- a/desktop/js/camera.js +++ b/desktop/js/camera.js @@ -1,4 +1,5 @@ + /* This file is part of Jeedom. * * Jeedom is free software: you can redistribute it and/or modify @@ -60,6 +61,123 @@ $('#div_pageContainer').off('click', '.listCmdActionOther').on('click', '.listCm }) }) +//// Analyse Onvif \\\\ +document.querySelector('.analyseOnvif').addEventListener('click', function(event) { + if (is_object(eqLogic = document.querySelector('.eqLogicAttr[data-l1key=id]'))) { + let eqLogicId = eqLogic.jeeValue() + if (eqLogicId != '' && eqLogicId != null) { + domUtils.ajax({ + type: 'POST', + url: 'plugins/camera/core/ajax/camera.ajax.php', + data: { + action: 'getConfigOnvif', + id: eqLogicId + }, + dataType: 'json', + error: function(request, status, error) { + handleAjaxError(request, status, error) + }, + success: function (data) { + if (data.state != 'ok') { + jeedomUtils.showAlert({ + title: "Camera", + message: data.result, + level: 'danger' + }); + return + } + if (!data.result) { + jeedomUtils.showAlert({ + title: "Camera", + message: "{{Camera Onvif introuvable}}", + level: 'danger' + }); + return; + } + + let selector + for (let l1key in data.result) { + for (let l2key in data.result[l1key]) { + selector = '.eqLogicAttr[data-l1key="' + l1key.replaceAll('"', '') + '"][data-l2key="' + l2key.replaceAll('"', '') + '"]' + document.querySelectorAll(selector).forEach(_selector => { + if (_selector.jeeValue() == '') { + _selector.style.setProperty('background', 'rgba(248, 216, 0, 0.25)', 'important'); + _selector.jeeValue(data.result[l1key][l2key]) + } + }) + } + } + jeedomUtils.showAlert({ + title: "Camera", + message: "{{Veuillez enregistrer les modifications}}", + level: 'info' + }); + } + }); + } + } +}) + +//// Create command preset onvif \\\\ +document.querySelector('.createCmdPresetOnvif').addEventListener('click', function(event) { + if (is_object(eqLogic = document.querySelector('.eqLogicAttr[data-l1key=id]'))) { + let eqLogicId = eqLogic.jeeValue() + if (eqLogicId != '' && eqLogicId != null) { + domUtils.ajax({ + type: 'POST', + url: 'plugins/camera/core/ajax/camera.ajax.php', + data: { + action: 'createCmdPresetOnvif', + id: eqLogicId + }, + dataType: 'json', + error: function(request, status, error) { + handleAjaxError(request, status, error) + }, + success: function (data) { + if (data.state != 'ok') { + jeedomUtils.showAlert({ + title: "Camera", + message: data.result, + level: 'danger' + }); + return + } + if (!data.result) { + jeedomUtils.showAlert({ + title: "Camera", + message: "{{Camera Onvif introuvable}}", + level: 'danger' + }); + return; + } + if (isset(data.result.createPreset) && data.result.createPreset > 0) + { + + jeedomUtils.showAlert({ + title: "Camera", + message: " {{preset importé}} : " + data.result.createPreset + '
{{Actualisation de la page}}...', + level: 'info' + }); + + setTimeout(function () { + var vars = getUrlVars() + var url = 'index.php?' + for (var i in vars) { + if (i != 'saveSuccessFull' && i != 'removeSuccessFull') { //i != 'id' && + url += i + '=' + vars[i].replace('#', '') + '&' + } + } + url += 'saveSuccessFull=1#commandtab' + jeedomUtils.loadPage(url) + }, 2000); + } + } + }); + } + } +}) + function addCmdToTable(_cmd) { if (!isset(_cmd)) { var _cmd = {} @@ -137,7 +255,6 @@ $('#table_cmd tbody').on('change', '.cmd .cmdAttr[data-l1key=type]', function() } }) - $('#bt_removeAllCapture').on('click', function() { bootbox.confirm('{{Etes-vous sur de vouloir supprimer toutes les captures de la caméra ?}}', function(result) { if (result) { diff --git a/desktop/modal/discover.cam.php b/desktop/modal/discover.cam.php index 5cf67db..88bde4b 100644 --- a/desktop/modal/discover.cam.php +++ b/desktop/modal/discover.cam.php @@ -11,6 +11,7 @@ {{IP}} + {{Port}} {{Découverte}} {{Type}} {{Nom d'utilisateur}} @@ -20,39 +21,42 @@ '; - echo ''; - echo '' . $cam['ip'] . ''; - echo ''; - echo ''; - echo '' . $cam['discover'] . ''; - echo ''; - echo ''; - echo $cam['type']; - echo ''; - echo ''; - if ($cam['exist'] === false) { - echo ''; - } else { - echo 'NA'; - } - echo ''; - echo ''; - if ($cam['exist'] === false) { - echo ''; - } else { - echo 'NA'; - } - echo ''; - echo ''; - if ($cam['exist'] === false) { - echo ' {{Ajouter}}'; - } - echo ''; - echo ''; - } - ?> +foreach ($discover_cameras as $cam) { + echo ''; + echo ''; + echo '' . $cam['ip'] . ''; + echo ''; + echo ''; + echo '' . $cam['port'] . ''; + echo ''; + echo ''; + echo '' . $cam['discover'] . ''; + echo ''; + echo ''; + echo $cam['type']; + echo ''; + echo ''; + if ($cam['exist'] === false) { + echo ''; + } else { + echo 'NA'; + } + echo ''; + echo ''; + if ($cam['exist'] === false) { + echo ''; + } else { + echo 'NA'; + } + echo ''; + echo ''; + if ($cam['exist'] === false) { + echo ' {{Ajouter}}'; + } + echo ''; + echo ''; +} +?> diff --git a/desktop/php/camera.php b/desktop/php/camera.php index 7127b2a..a9047fe 100644 --- a/desktop/php/camera.php +++ b/desktop/php/camera.php @@ -151,36 +151,6 @@ -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
- -
-
- -
-
-
- -
- -
-
@@ -239,14 +209,59 @@
- + {{Paramètres Onvif}} +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+
+ + +
+
+ + +
+ -
- {{Informations}}
{{Si votre caméra n'est pas dans la liste référez-vous}} {{à cette page}} {{pour trouver les informations de configuration de nombreuses caméras}}
From 4347444758d10b238d341f27c953b26f5dffa8ab Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Mon, 28 Sep 2026 19:51:58 +0200 Subject: [PATCH 02/15] fix undefined variable --- core/class/camera.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 3843170..40f505b 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -369,7 +369,7 @@ public function getConfigOnvif() { foreach (camera::discoverCam() as $_cam) { if ($_cam['ip'] == $ip) { $return['onvif_port'] = $_cam['port']; - $xaddr = explode(" ",$_cam['xaddrs']); + $xaddr = explode(" ", $_cam['xaddrs']); $onvif = new ponvif(); $onvif->setUsername($this->getConfiguration('username')); @@ -410,7 +410,6 @@ public function createCmdPresetOnvif() { $onvif->setUsername($this->getConfiguration('username')); $onvif->setPassword($this->getConfiguration('password')); $onvif->setIPAddress($ip); - $onvif->setMediaUri($xaddr[0]); $onvif->initialize(); try { $profiles = $onvif->media_GetProfiles(); From e1db7f357d9930f24257891cbc2cd9d95587d842 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Mon, 28 Sep 2026 19:58:17 +0200 Subject: [PATCH 03/15] noNeedMediaUri --- core/class/camera.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 40f505b..97e772f 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -369,13 +369,12 @@ public function getConfigOnvif() { foreach (camera::discoverCam() as $_cam) { if ($_cam['ip'] == $ip) { $return['onvif_port'] = $_cam['port']; - $xaddr = explode(" ", $_cam['xaddrs']); - + //$xaddr = explode(" ", $_cam['xaddrs']); $onvif = new ponvif(); $onvif->setUsername($this->getConfiguration('username')); $onvif->setPassword($this->getConfiguration('password')); $onvif->setIPAddress($ip); - $onvif->setMediaUri($xaddr[0]); + //$onvif->setMediaUri($xaddr[0]); $onvif->initialize(); try { $profiles = $onvif->media_GetProfiles(); From feedce830fdb8c7d962a58b0132314096dcb1ef7 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Tue, 29 Sep 2026 17:33:56 +0200 Subject: [PATCH 04/15] add gotohome --- core/config/devices/onvif/onvif.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/config/devices/onvif/onvif.json b/core/config/devices/onvif/onvif.json index 82dd6bb..96e9a85 100644 --- a/core/config/devices/onvif/onvif.json +++ b/core/config/devices/onvif/onvif.json @@ -101,6 +101,15 @@ "isHistorized": "0", "isVisible": "1" }, + { + "eqType": "camera", + "logicalId": "gotohome", + "name": "Go to home", + "type": "action", + "subType": "other", + "isHistorized": "0", + "isVisible": "1" + }, { "eqType": "camera", "logicalId": "ptzreboot", From 58f46201fee66a3d8ca9e8aed64e5f6880960eae Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Tue, 29 Sep 2026 19:08:13 +0200 Subject: [PATCH 05/15] setMediaUri & log --- core/class/camera.class.php | 49 ++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 97e772f..815e757 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -369,30 +369,55 @@ public function getConfigOnvif() { foreach (camera::discoverCam() as $_cam) { if ($_cam['ip'] == $ip) { $return['onvif_port'] = $_cam['port']; - //$xaddr = explode(" ", $_cam['xaddrs']); + $xaddr = explode(" ",$_cam['xaddrs']); // + $onvif = new ponvif(); $onvif->setUsername($this->getConfiguration('username')); $onvif->setPassword($this->getConfiguration('password')); $onvif->setIPAddress($ip); - //$onvif->setMediaUri($xaddr[0]); - $onvif->initialize(); + $onvif->setMediaUri($xaddr[0]); // + + $etape = 0; + $error = false; + try { - $profiles = $onvif->media_GetProfiles(); - $token = $profiles[0]['@attributes']['token']; - $return['cameraStreamProfileToken'] = $token; + $onvif->initialize(); + $etape++; + log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - initialize'); } catch(Exception $e) { - log::add(__CLASS__,'debug','media_GetProfiles : ' . $e); + log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - initialize : ' . $e); + $error = true; } - try { - $ptzUri = $onvif->getPTZUri(); - $return['ptzuri'] = $ptzUri; - } catch(Exception $e) { - log::add(__CLASS__,'debug','getPTZUri : ' . $e); + if (!$error) { + try { + $profiles = $onvif->media_GetProfiles(); + $token = $profiles[0]['@attributes']['token']; + $return['cameraStreamProfileToken'] = $token; + $etape++; + log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - media_GetProfiles'); + } catch(Exception $e) { + log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - media_GetProfiles : ' . $e); + $error = true; + } } + + if (!$error) { + try { + $ptzUri = $onvif->getPTZUri(); + $return['ptzuri'] = $ptzUri; + $etape++; + log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - getPTZUri'); + } catch(Exception $e) { + log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - getPTZUri : ' . $e); + $error = true; + } + } + break; } } + log::add(__CLASS__,'debug','[getConfigOnvif] [INFO] Return -> ' . json_encode($return)); return array('configuration' => $return); } From 90692e1df43511ff19f83c40172a99881af644e1 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Tue, 29 Sep 2026 19:43:01 +0200 Subject: [PATCH 06/15] setMediaUri --- core/class/camera.class.php | 107 ++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 40 deletions(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 815e757..914141a 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -369,26 +369,27 @@ public function getConfigOnvif() { foreach (camera::discoverCam() as $_cam) { if ($_cam['ip'] == $ip) { $return['onvif_port'] = $_cam['port']; - $xaddr = explode(" ",$_cam['xaddrs']); // + $xaddr = explode(" ",$_cam['xaddrs']); $onvif = new ponvif(); $onvif->setUsername($this->getConfiguration('username')); $onvif->setPassword($this->getConfiguration('password')); $onvif->setIPAddress($ip); - $onvif->setMediaUri($xaddr[0]); // - - $etape = 0; + $onvif->setMediaUri($xaddr[0]); + + $etape = 1; $error = false; - + try { $onvif->initialize(); - $etape++; log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - initialize'); } catch(Exception $e) { log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - initialize : ' . $e); $error = true; } + $etape++; + if (!$error) { try { $profiles = $onvif->media_GetProfiles(); @@ -402,6 +403,8 @@ public function getConfigOnvif() { } } + $etape++; + if (!$error) { try { $ptzUri = $onvif->getPTZUri(); @@ -413,7 +416,6 @@ public function getConfigOnvif() { $error = true; } } - break; } } @@ -430,54 +432,79 @@ public function createCmdPresetOnvif() { foreach (camera::discoverCam() as $_cam) { if ($_cam['ip'] == $ip) { + $xaddr = explode(" ",$_cam['xaddrs']); $onvif = new ponvif(); $onvif->setUsername($this->getConfiguration('username')); $onvif->setPassword($this->getConfiguration('password')); $onvif->setIPAddress($ip); - $onvif->initialize(); + $onvif->setMediaUri($xaddr[0]); + + $etape = 1; + $error = false; + try { - $profiles = $onvif->media_GetProfiles(); - $token = $profiles[0]['@attributes']['token']; + $onvif->initialize(); + log::add(__CLASS__,'debug','[createCmdPresetOnvif] OK Etape ' . $etape . ' - initialize'); } catch(Exception $e) { - log::add(__CLASS__,'debug','media_GetProfiles : ' . $e); + log::add(__CLASS__,'debug','[createCmdPresetOnvif] KO Etape ' . $etape . ' - initialize : ' . $e); + $error = true; } - try { - $presets = $onvif->ptz_GetPresets($token); - $nbpresetMax = 10; - log::add(__CLASS__,'debug',json_encode($presets)); - $nbpreset = 1; - $nbCreatepreset = 0; - foreach ($presets as $preset) { - if ($nbpreset > $nbpresetMax) break; - $logicalId = 'preset::' . preg_replace("/\s+/", '', $preset['Token']); - if (!is_object($this->getCmd(null, $logicalId))) { - log::add(__CLASS__,'debug', 'création du preset avec logicalId ' . $logicalId); - $cmdPreset = new cameraCmd(); - $cmdPreset->setName($preset['Name']); - $cmdPreset->setType('action'); - $cmdPreset->setSubType('other'); - $cmdPreset->setEqLogic_id($this->getId()); - $cmdPreset->setConfiguration('request', 'preset'); - $cmdPreset->setConfiguration('token', $preset['Token']); - $cmdPreset->setLogicalId($logicalId); - try { - $cmdPreset->save(); - } catch (Exception $e) { - $cmdPreset->setName($preset['Name'] . rand(0, 9999)); - $cmdPreset->save(); + $etape++; + + if (!$error) { + try { + $profiles = $onvif->media_GetProfiles(); + $token = $profiles[0]['@attributes']['token']; + log::add(__CLASS__,'debug','[createCmdPresetOnvif] OK Etape ' . $etape . ' - media_GetProfiles'); + } catch(Exception $e) { + log::add(__CLASS__,'debug','[createCmdPresetOnvif] KO Etape ' . $etape . ' - media_GetProfiles : ' . $e); + $error = true; + } + } + + $etape++; + + if (!$error) { + try { + $presets = $onvif->ptz_GetPresets($token); + $nbpresetMax = 10; + log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Etape ' . $etape . ' - ptz_GetPresets -> ' . json_encode($presets)); + $nbpreset = 1; + $nbCreatepreset = 0; + foreach ($presets as $preset) { + if ($nbpreset > $nbpresetMax) break; + $logicalId = 'preset::' . preg_replace("/\s+/", '', $preset['Token']); + if (!is_object($this->getCmd(null, $logicalId))) { + log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création du preset avec logicalId ' . $logicalId); + $cmdPreset = new cameraCmd(); + $cmdPreset->setName($preset['Name']); + $cmdPreset->setType('action'); + $cmdPreset->setSubType('other'); + $cmdPreset->setEqLogic_id($this->getId()); + $cmdPreset->setConfiguration('request', 'preset'); + $cmdPreset->setConfiguration('token', $preset['Token']); + $cmdPreset->setLogicalId($logicalId); + try { + $cmdPreset->save(); + } catch (Exception $e) { + $cmdPreset->setName($preset['Name'] . rand(0, 9999)); + $cmdPreset->save(); + } + $nbCreatepreset++; } - $nbCreatepreset++; + $nbpreset++; } - $nbpreset++; + $return['createPreset'] = $nbCreatepreset; + } catch(Exception $e) { + log::add(__CLASS__,'debug','[createCmdPresetOnvif] KO Etape ' . $etape . ' - ptz_GetPresets : ' . $e); + $error = true; } - $return['createPreset'] = $nbCreatepreset; - } catch(Exception $e) { - log::add(__CLASS__,'debug','ptz_GetPresets : ' . $e); } } break; } + log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Return -> ' . json_encode($return)); return $return; } From 7dea0f1f42d1280d01c6ed005470959040197cd0 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Tue, 29 Sep 2026 20:02:23 +0200 Subject: [PATCH 07/15] usleep ptz stop --- core/class/camera.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 914141a..4813bf7 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -469,7 +469,7 @@ public function createCmdPresetOnvif() { try { $presets = $onvif->ptz_GetPresets($token); $nbpresetMax = 10; - log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Etape ' . $etape . ' - ptz_GetPresets -> ' . json_encode($presets)); + log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Etape ' . $etape . ' - ptz_GetPresets -> ' . json_encode($presets)); $nbpreset = 1; $nbCreatepreset = 0; foreach ($presets as $preset) { @@ -1288,6 +1288,7 @@ public function execute($_options = null) { } return true; } else if ($action && $fastMethode) { + usleep($sleep); $onvif->ptz_Stop($profileToken, 'true', 'true'); return true; } From ca8ed312fdb3121234bfe389d6f2f4e03f511fa0 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Mon, 9 Nov 2026 23:22:06 +0100 Subject: [PATCH 08/15] gotohome & ptzreboot --- core/class/camera.class.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 4813bf7..9e5c64e 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -395,7 +395,6 @@ public function getConfigOnvif() { $profiles = $onvif->media_GetProfiles(); $token = $profiles[0]['@attributes']['token']; $return['cameraStreamProfileToken'] = $token; - $etape++; log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - media_GetProfiles'); } catch(Exception $e) { log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - media_GetProfiles : ' . $e); @@ -409,7 +408,6 @@ public function getConfigOnvif() { try { $ptzUri = $onvif->getPTZUri(); $return['ptzuri'] = $ptzUri; - $etape++; log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - getPTZUri'); } catch(Exception $e) { log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - getPTZUri : ' . $e); @@ -474,6 +472,11 @@ public function createCmdPresetOnvif() { $nbCreatepreset = 0; foreach ($presets as $preset) { if ($nbpreset > $nbpresetMax) break; + // Fixes double encoding (Mojibake) caused by the XML server (UTF-8 header but ISO-8859-1 content). + // The regex detects broken characters (e.g., "é") and the conversion restores the original accent (e.g., "é"). + if (is_string($preset['Name']) && preg_match('/[\xC2-\xC3][\x80-\xBF]/', $preset['Name'])) { + $preset['Name'] = mb_convert_encoding($preset['Name'], 'ISO-8859-1', 'UTF-8'); + } $logicalId = 'preset::' . preg_replace("/\s+/", '', $preset['Token']); if (!is_object($this->getCmd(null, $logicalId))) { log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création du preset avec logicalId ' . $logicalId); @@ -1229,9 +1232,10 @@ public function execute($_options = null) { $onvif->setPassword($eqLogic->getConfiguration('password')); $ptzuri = trim($eqLogic->getConfiguration('ptzuri', '')); - $fastMethode = ($ptzuri != ''); + $forceInitialize = array('gotohome', 'ptzreboot'); + $byPtzUri = ($ptzuri != '' && !in_array($logicalId, $forceInitialize)); - if ($fastMethode) { + if ($byPtzUri) { // fast method (no initialize) $onvif->setIPAddress($eqLogic->getConfiguration('ip')); $onvif->setPTZUri($ptzuri); @@ -1287,7 +1291,7 @@ public function execute($_options = null) { $cmd->execCmd(); } return true; - } else if ($action && $fastMethode) { + } else if ($action && $byPtzUri) { usleep($sleep); $onvif->ptz_Stop($profileToken, 'true', 'true'); return true; From 7d0701162efd886572e2047ac48fa336a7081a76 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:31:07 +0100 Subject: [PATCH 09/15] update --- core/ajax/camera.ajax.php | 3 +- core/class/camera.class.php | 99 +++++++++++++++++----------- core/config/devices/onvif/onvif.json | 9 --- desktop/js/camera.js | 22 ++----- desktop/modal/discover.cam.php | 86 +++++++++++------------- desktop/php/camera.php | 10 +-- 6 files changed, 104 insertions(+), 125 deletions(-) diff --git a/core/ajax/camera.ajax.php b/core/ajax/camera.ajax.php index ae3df53..ba92376 100644 --- a/core/ajax/camera.ajax.php +++ b/core/ajax/camera.ajax.php @@ -98,8 +98,7 @@ } if (init('action') == 'addDiscoverCam') { - camera::addDiscoverCam(json_decode(init('config'), true)); - ajax::success(); + ajax::success(camera::addDiscoverCam(json_decode(init('config'), true))); } if (init('action') == 'getConfigOnvif') { diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 9e5c64e..2a51fe9 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -304,9 +304,11 @@ public static function discoverCam() { if (count($result) > 0) { foreach ($result as $cam) { $url = parse_url($cam['XAddrs']); + $port = $url['port'] ?? ($url['scheme'] === 'https' ? 443 : 80); $return[] = array( + 'protocole' => $url['scheme'], 'ip' => $url['host'], - 'port' => $url['port'], + 'port' => $port, 'type' => $cam['Types'], 'discover' => 'onvif', 'urn' => $cam['EndpointReference']['Address'], @@ -318,12 +320,15 @@ public static function discoverCam() { $cameras = self::byType(__CLASS__); foreach ($return as &$cam) { foreach ($cameras as $camera) { - if ($cam['ip'] == $camera->getConfiguration('ip') . ':' . $camera->getConfiguration('onvif_port')) { + if ($cam['ip'] == $camera->getConfiguration('ip')) { $cam['exist'] = true; break; } } } + usort($return, function ($a, $b) { + return $a['exist'] <=> $b['exist']; + }); return $return; } @@ -334,11 +339,13 @@ public static function addDiscoverCam($_config) { $eqLogic->setConfiguration('password', $_config['password']); $eqLogic->setConfiguration('ip', $_config['ip']); $eqLogic->setConfiguration('onvif_port', $_config['port']); + $eqLogic->setConfiguration('protocole', $_config['protocole']); $eqLogic->setEqType_name(__CLASS__); $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); $eqLogic->setConfiguration('device', 'onvif'); $eqLogic->save(); + return $eqLogic->getId(); } /* * *********************Methode d'instance************************* */ @@ -365,43 +372,29 @@ public function getConfigOnvif() { if ($ip == 'null' || $ip == '') { throw new Exception(__("L'adresse IP ne peut être vide.", __FILE__)); } - + $search = false; foreach (camera::discoverCam() as $_cam) { if ($_cam['ip'] == $ip) { $return['onvif_port'] = $_cam['port']; - $xaddr = explode(" ",$_cam['xaddrs']); + $xaddr = explode(" ",trim($_cam['xaddrs'])); $onvif = new ponvif(); $onvif->setUsername($this->getConfiguration('username')); $onvif->setPassword($this->getConfiguration('password')); $onvif->setIPAddress($ip); $onvif->setMediaUri($xaddr[0]); - - $etape = 1; - $error = false; try { $onvif->initialize(); - log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - initialize'); } catch(Exception $e) { - log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - initialize : ' . $e); - $error = true; - } - - $etape++; - - if (!$error) { - try { - $profiles = $onvif->media_GetProfiles(); - $token = $profiles[0]['@attributes']['token']; - $return['cameraStreamProfileToken'] = $token; - log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - media_GetProfiles'); - } catch(Exception $e) { - log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - media_GetProfiles : ' . $e); - $error = true; - } + throw new Exception(__("Échec de la connexion ONVIF.", __FILE__) . '
' . __("Redémarrez la caméra et relancez l'analyse.", __FILE__)); } + $profiles = $onvif->media_GetProfiles(); + $token = $profiles[0]['@attributes']['token'] ?? ''; + $return['cameraStreamProfileToken'] = $token; + $search = true; + /* $etape++; if (!$error) { @@ -414,9 +407,13 @@ public function getConfigOnvif() { $error = true; } } + */ break; } } + if (!$search) { + throw new Exception(__("Échec de la découverte réseau.", __FILE__) . '
' . __("Assurez-vous que la caméra est sous tension ou redémarrez-la avant de relancer l'analyse.", __FILE__)); + } log::add(__CLASS__,'debug','[getConfigOnvif] [INFO] Return -> ' . json_encode($return)); return array('configuration' => $return); } @@ -424,6 +421,7 @@ public function getConfigOnvif() { public function createCmdPresetOnvif() { $return = array(); $ip = $this->getConfiguration('ip'); + $nbCreatepreset = 0; if ($ip == 'null' || $ip == '') { throw new Exception(__("L'adresse IP ne peut etre vide.", __FILE__)); } @@ -469,7 +467,6 @@ public function createCmdPresetOnvif() { $nbpresetMax = 10; log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Etape ' . $etape . ' - ptz_GetPresets -> ' . json_encode($presets)); $nbpreset = 1; - $nbCreatepreset = 0; foreach ($presets as $preset) { if ($nbpreset > $nbpresetMax) break; // Fixes double encoding (Mojibake) caused by the XML server (UTF-8 header but ISO-8859-1 content). @@ -498,15 +495,45 @@ public function createCmdPresetOnvif() { } $nbpreset++; } - $return['createPreset'] = $nbCreatepreset; } catch(Exception $e) { log::add(__CLASS__,'debug','[createCmdPresetOnvif] KO Etape ' . $etape . ' - ptz_GetPresets : ' . $e); $error = true; } } + + $etape++; + + if (!$error) { + try { + $node = $onvif->ptz_GetNode($token); + $homeSupported = $node['HomeSupported'] ?? false; + if ($homeSupported) { + if (!is_object($this->getCmd(null, 'gotohome'))) { + log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création de la commande gotohome'); + $cmdGotohome = new cameraCmd(); + $cmdGotohome->setName('Go to home'); + $cmdGotohome->setType('action'); + $cmdGotohome->setSubType('other'); + $cmdGotohome->setEqLogic_id($this->getId()); + $Gotohome->setLogicalId($logicalId); + try { + $cmdGotohome->save(); + } catch (Exception $e) { + $cmdGotohome->setName('Go to home' . rand(0, 9999)); + $cmdGotohome->save(); + } + $nbCreatepreset++; + } + } + } catch(Exception $e) { + log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - GetNode : ' . $e); + $error = true; + } + } + break; } - break; } + $return['createPreset'] = $nbCreatepreset; log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Return -> ' . json_encode($return)); return $return; } @@ -1230,19 +1257,11 @@ public function execute($_options = null) { $onvif = new Ponvif(); $onvif->setUsername($eqLogic->getConfiguration('username')); $onvif->setPassword($eqLogic->getConfiguration('password')); - - $ptzuri = trim($eqLogic->getConfiguration('ptzuri', '')); - $forceInitialize = array('gotohome', 'ptzreboot'); - $byPtzUri = ($ptzuri != '' && !in_array($logicalId, $forceInitialize)); - - if ($byPtzUri) { - // fast method (no initialize) - $onvif->setIPAddress($eqLogic->getConfiguration('ip')); - $onvif->setPTZUri($ptzuri); - } else { - // slow method - $onvif->setIPAddress($eqLogic->getConfiguration('ip') . ':' . $eqLogic->getConfiguration('onvif_port', 80)); + $onvif->setIPAddress($eqLogic->getConfiguration('ip') . ':' . $eqLogic->getConfiguration('onvif_port', 80)); + try { $onvif->initialize(); + } catch(Exception $e) { + throw new Exception(__("Échec de la connexion ONVIF.", __FILE__) . ' ' . __("Redémarrez la caméra et relancez l'analyse.", __FILE__)); } $action = false; @@ -1291,7 +1310,7 @@ public function execute($_options = null) { $cmd->execCmd(); } return true; - } else if ($action && $byPtzUri) { + } else if ($action) { usleep($sleep); $onvif->ptz_Stop($profileToken, 'true', 'true'); return true; diff --git a/core/config/devices/onvif/onvif.json b/core/config/devices/onvif/onvif.json index 96e9a85..82dd6bb 100644 --- a/core/config/devices/onvif/onvif.json +++ b/core/config/devices/onvif/onvif.json @@ -101,15 +101,6 @@ "isHistorized": "0", "isVisible": "1" }, - { - "eqType": "camera", - "logicalId": "gotohome", - "name": "Go to home", - "type": "action", - "subType": "other", - "isHistorized": "0", - "isVisible": "1" - }, { "eqType": "camera", "logicalId": "ptzreboot", diff --git a/desktop/js/camera.js b/desktop/js/camera.js index 0c91042..a2f9710 100644 --- a/desktop/js/camera.js +++ b/desktop/js/camera.js @@ -151,26 +151,14 @@ document.querySelector('.createCmdPresetOnvif').addEventListener('click', functi }); return; } - if (isset(data.result.createPreset) && data.result.createPreset > 0) - { - + if (isset(data.result.createPreset) && data.result.createPreset > 0) { + window.location.href='index.php?v=d&m=camera&p=camera&id=' + eqLogicId + '&saveSuccessFull=1#commandtab' + } else { jeedomUtils.showAlert({ - title: "Camera", - message: " {{preset importé}} : " + data.result.createPreset + '
{{Actualisation de la page}}...', + title: "Preset", + message: "{{Aucun preset importé}}", level: 'info' }); - - setTimeout(function () { - var vars = getUrlVars() - var url = 'index.php?' - for (var i in vars) { - if (i != 'saveSuccessFull' && i != 'removeSuccessFull') { //i != 'id' && - url += i + '=' + vars[i].replace('#', '') + '&' - } - } - url += 'saveSuccessFull=1#commandtab' - jeedomUtils.loadPage(url) - }, 2000); } } }); diff --git a/desktop/modal/discover.cam.php b/desktop/modal/discover.cam.php index 88bde4b..8cd0028 100644 --- a/desktop/modal/discover.cam.php +++ b/desktop/modal/discover.cam.php @@ -2,7 +2,6 @@ if (!isConnect('admin')) { throw new Exception('{{401 - Accès non autorisé}}'); } -$discover_cameras = camera::discoverCam(); ?> @@ -10,6 +9,7 @@ + @@ -21,9 +21,12 @@ '; echo ''; + echo ''; echo ''; - echo ''; + echo ''; + echo ''; } else { - echo 'NA'; + echo ''; } - echo ''; - echo ''; - echo ''; echo ''; } ?> @@ -61,34 +54,31 @@
{{Protocole}} {{IP}} {{Port}} {{Découverte}}
'; + echo '' . $cam['protocole'] . ''; + echo ''; echo '' . $cam['ip'] . ''; echo ''; @@ -35,25 +38,15 @@ echo ''; echo $cam['type']; echo ''; if ($cam['exist'] === false) { - echo ''; + echo ' {{Ajouter}}'; + echo '{{Caméra déja importée}}'; + echo ''; - if ($cam['exist'] === false) { - echo ''; - } else { - echo 'NA'; - } - echo ''; - if ($cam['exist'] === false) { - echo ' {{Ajouter}}'; - } - echo '
\ No newline at end of file diff --git a/desktop/php/camera.php b/desktop/php/camera.php index a9047fe..721ddf9 100644 --- a/desktop/php/camera.php +++ b/desktop/php/camera.php @@ -199,7 +199,7 @@
-
+
{{N'oubliez pas de sauvegarder pour prévisualiser les modifications}}
@@ -240,13 +240,6 @@
- -
- -
- -
-
@@ -259,7 +252,6 @@ Importer
-
{{Informations}} From cc8d3701bd327d8aaae71432afd029de5a3f23e2 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Fri, 13 Nov 2026 11:37:02 +0100 Subject: [PATCH 10/15] errorMessage --- core/class/camera.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 2a51fe9..79cf3d0 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -1261,7 +1261,7 @@ public function execute($_options = null) { try { $onvif->initialize(); } catch(Exception $e) { - throw new Exception(__("Échec de la connexion ONVIF.", __FILE__) . ' ' . __("Redémarrez la caméra et relancez l'analyse.", __FILE__)); + throw new Exception(__("Échec de la connexion ONVIF.", __FILE__) . ' ' . __("Si le problème persiste, redémarrez la caméra.", __FILE__)); } $action = false; From 49cf8312caac645b6e3116bceaf0f8cc972ff319 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:21:47 +0100 Subject: [PATCH 11/15] addEventListener --- desktop/modal/discover.cam.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/desktop/modal/discover.cam.php b/desktop/modal/discover.cam.php index 8cd0028..aa95c4f 100644 --- a/desktop/modal/discover.cam.php +++ b/desktop/modal/discover.cam.php @@ -6,7 +6,7 @@ - +
@@ -54,8 +54,10 @@
{{Protocole}}
\ No newline at end of file From c2157fe45ecadac52a3d9aa61c2006cc8245ad25 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:13:57 +0100 Subject: [PATCH 12/15] update --- 3rdparty/ponvif.php | 15 ++- core/class/camera.class.php | 212 +++++++++++++-------------------- desktop/js/camera.js | 13 +- desktop/modal/discover.cam.php | 6 +- 4 files changed, 105 insertions(+), 141 deletions(-) diff --git a/3rdparty/ponvif.php b/3rdparty/ponvif.php index 28a8876..56904a6 100644 --- a/3rdparty/ponvif.php +++ b/3rdparty/ponvif.php @@ -95,6 +95,7 @@ public function setPTZUri($ptzuri) {$this->ptzuri = $ptzuri; } public function getBaseUrl() {return $this->baseuri;} public function getSupportedVersion() {return $this->onvifversion;} public function getCapabilities() {return $this->capabilities;} + public function getProfiles() {return $this->profiles;} public function setBreakOnError($intransingent) {$this->intransingent = $intransingent;} public function getLastResponse() {return $this->lastresponse;} public function setDiscoveryTimeout($discoverytimeout) {$this->discoverytimeout = $discoverytimeout;} @@ -926,7 +927,7 @@ public function core_SystemReboot() } } - public function ptz_GotoHomePosition($profileToken, $pantilt, $zoom) + public function ptz_GotoHomePosition($profileToken, $speed_pantilt_x, $speed_pantilt_y, $speed_zoom_x) { if ($this->ptzuri == "") { return []; @@ -935,7 +936,7 @@ public function ptz_GotoHomePosition($profileToken, $pantilt, $zoom) $REQ = $this->_makeToken(); $post_string = - '%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%%%PANTILT%%%%ZOOM%%'; + '%%USERNAME%%%%PASSWORD%%%%NONCE%%%%CREATED%%%%PROFILETOKEN%%'; $post_string = str_replace( [ @@ -944,8 +945,9 @@ public function ptz_GotoHomePosition($profileToken, $pantilt, $zoom) "%%NONCE%%", "%%CREATED%%", "%%PROFILETOKEN%%", - "%%PANTILT%%", - "%%ZOOM%%", + "%%SPEEDPANTILTX%%", + "%%SPEEDPANTILTY%%", + "%%SPEEDZOOMX%%" ], [ $REQ["USERNAME"], @@ -953,8 +955,9 @@ public function ptz_GotoHomePosition($profileToken, $pantilt, $zoom) $REQ["NONCE"], $REQ["TIMESTAMP"], $profileToken, - $pantilt, - $zoom, + $speed_pantilt_x, + $speed_pantilt_y, + $speed_zoom_x ], $post_string ); diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 79cf3d0..79c190f 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -344,7 +344,12 @@ public static function addDiscoverCam($_config) { $eqLogic->setIsVisible(1); $eqLogic->setIsEnable(1); $eqLogic->setConfiguration('device', 'onvif'); - $eqLogic->save(); + try { + $eqLogic->save(); + } catch (Exception $e) { + $eqLogic->setName($_config['ip'] . rand(0, 9999)); + $eqLogic->save(); + } return $eqLogic->getId(); } @@ -358,8 +363,11 @@ public function configOnvif() { $onvif->setIPAddress($this->getConfiguration('ip') . ':' . $this->getConfiguration('onvif_port', 80)); $onvif->initialize(); $sources = $onvif->getSources(); + $profiles = $onvif->getProfiles(); + $token = $profiles[0]['@attributes']['token'] ?? ''; + $this->setConfiguration('cameraStreamProfileToken', $token); //save profiletoken for sending onvif ptz cmd $mediaUri = preg_replace('/(([0-9]{1,3}\.){3}[0-9]{1,3})/m', '#username#:#password#@#ip#', $onvif->media_GetStreamUri($sources[0][0]['profiletoken'])); - $this->setConfiguration('cameraStreamProfileToken', $sources[0][0]['profiletoken']); //save profiletoken for sending onvif ptz cmd + //$this->setConfiguration('cameraStreamProfileToken', $sources[0][0]['profiletoken']); //save profiletoken for sending onvif ptz cmd $this->setConfiguration('cameraStreamAccessUrl', $mediaUri); } catch (Exception $e) { log::add(__CLASS__, 'error', '[ONVIF] ' . $e->getMessage()); @@ -376,13 +384,11 @@ public function getConfigOnvif() { foreach (camera::discoverCam() as $_cam) { if ($_cam['ip'] == $ip) { $return['onvif_port'] = $_cam['port']; - $xaddr = explode(" ",trim($_cam['xaddrs'])); $onvif = new ponvif(); $onvif->setUsername($this->getConfiguration('username')); $onvif->setPassword($this->getConfiguration('password')); - $onvif->setIPAddress($ip); - $onvif->setMediaUri($xaddr[0]); + $onvif->setIPAddress($this->getConfiguration('ip') . ':' . $this->getConfiguration('onvif_port', 80)); try { $onvif->initialize(); @@ -390,24 +396,13 @@ public function getConfigOnvif() { throw new Exception(__("Échec de la connexion ONVIF.", __FILE__) . '
' . __("Redémarrez la caméra et relancez l'analyse.", __FILE__)); } - $profiles = $onvif->media_GetProfiles(); + $profiles = $onvif->getProfiles(); $token = $profiles[0]['@attributes']['token'] ?? ''; + $sources = $onvif->getSources(); + $mediaUri = preg_replace('/(([0-9]{1,3}\.){3}[0-9]{1,3})/m', '#username#:#password#@#ip#', $onvif->media_GetStreamUri($sources[0][0]['profiletoken'])); $return['cameraStreamProfileToken'] = $token; + $return['cameraStreamAccessUrl'] = $mediaUri; $search = true; - /* - $etape++; - - if (!$error) { - try { - $ptzUri = $onvif->getPTZUri(); - $return['ptzuri'] = $ptzUri; - log::add(__CLASS__,'debug','[getConfigOnvif] OK Etape ' . $etape . ' - getPTZUri'); - } catch(Exception $e) { - log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - getPTZUri : ' . $e); - $error = true; - } - } - */ break; } } @@ -420,118 +415,81 @@ public function getConfigOnvif() { public function createCmdPresetOnvif() { $return = array(); - $ip = $this->getConfiguration('ip'); - $nbCreatepreset = 0; - if ($ip == 'null' || $ip == '') { - throw new Exception(__("L'adresse IP ne peut etre vide.", __FILE__)); - } - foreach (camera::discoverCam() as $_cam) { - if ($_cam['ip'] == $ip) { - $xaddr = explode(" ",$_cam['xaddrs']); - $onvif = new ponvif(); - $onvif->setUsername($this->getConfiguration('username')); - $onvif->setPassword($this->getConfiguration('password')); - $onvif->setIPAddress($ip); - $onvif->setMediaUri($xaddr[0]); - - $etape = 1; - $error = false; - - try { - $onvif->initialize(); - log::add(__CLASS__,'debug','[createCmdPresetOnvif] OK Etape ' . $etape . ' - initialize'); - } catch(Exception $e) { - log::add(__CLASS__,'debug','[createCmdPresetOnvif] KO Etape ' . $etape . ' - initialize : ' . $e); - $error = true; - } - - $etape++; + $token = $this->getConfiguration('cameraStreamProfileToken'); + if ($token == '') { + throw new Exception(__("Le jeton de profil doit être renseigné", __FILE__)); + } - if (!$error) { - try { - $profiles = $onvif->media_GetProfiles(); - $token = $profiles[0]['@attributes']['token']; - log::add(__CLASS__,'debug','[createCmdPresetOnvif] OK Etape ' . $etape . ' - media_GetProfiles'); - } catch(Exception $e) { - log::add(__CLASS__,'debug','[createCmdPresetOnvif] KO Etape ' . $etape . ' - media_GetProfiles : ' . $e); - $error = true; - } - } + $nbCreatepreset = 0; - $etape++; + $onvif = new ponvif(); + $onvif->setUsername($this->getConfiguration('username')); + $onvif->setPassword($this->getConfiguration('password')); + $onvif->setIPAddress($this->getConfiguration('ip') . ':' . $this->getConfiguration('onvif_port', 80)); - if (!$error) { - try { - $presets = $onvif->ptz_GetPresets($token); - $nbpresetMax = 10; - log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Etape ' . $etape . ' - ptz_GetPresets -> ' . json_encode($presets)); - $nbpreset = 1; - foreach ($presets as $preset) { - if ($nbpreset > $nbpresetMax) break; - // Fixes double encoding (Mojibake) caused by the XML server (UTF-8 header but ISO-8859-1 content). - // The regex detects broken characters (e.g., "é") and the conversion restores the original accent (e.g., "é"). - if (is_string($preset['Name']) && preg_match('/[\xC2-\xC3][\x80-\xBF]/', $preset['Name'])) { - $preset['Name'] = mb_convert_encoding($preset['Name'], 'ISO-8859-1', 'UTF-8'); - } - $logicalId = 'preset::' . preg_replace("/\s+/", '', $preset['Token']); - if (!is_object($this->getCmd(null, $logicalId))) { - log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création du preset avec logicalId ' . $logicalId); - $cmdPreset = new cameraCmd(); - $cmdPreset->setName($preset['Name']); - $cmdPreset->setType('action'); - $cmdPreset->setSubType('other'); - $cmdPreset->setEqLogic_id($this->getId()); - $cmdPreset->setConfiguration('request', 'preset'); - $cmdPreset->setConfiguration('token', $preset['Token']); - $cmdPreset->setLogicalId($logicalId); - try { - $cmdPreset->save(); - } catch (Exception $e) { - $cmdPreset->setName($preset['Name'] . rand(0, 9999)); - $cmdPreset->save(); - } - $nbCreatepreset++; - } - $nbpreset++; - } - } catch(Exception $e) { - log::add(__CLASS__,'debug','[createCmdPresetOnvif] KO Etape ' . $etape . ' - ptz_GetPresets : ' . $e); - $error = true; - } + try { + $onvif->initialize(); + } catch(Exception $e) { + throw new Exception('[createCmdPresetOnvif] KO Etape initialize : ' . $e); + } + try { + $presets = $onvif->ptz_GetPresets($token); + } catch(Exception $e) { + throw new Exception('[createCmdPresetOnvif] KO Etape ptz_GetPresets(' . $token . ') : ' . $e); + } + $nbpresetMax = 10; + $nbpreset = 1; + foreach ($presets as $preset) { + if ($nbpreset > $nbpresetMax) break; + // Fixes double encoding (Mojibake) caused by the XML server (UTF-8 header but ISO-8859-1 content). + // The regex detects broken characters (e.g., "é") and the conversion restores the original accent (e.g., "é"). + if (is_string($preset['Name']) && preg_match('/[\xC2-\xC3][\x80-\xBF]/', $preset['Name'])) { + $preset['Name'] = mb_convert_encoding($preset['Name'], 'ISO-8859-1', 'UTF-8'); + } + $logicalId = 'preset::' . preg_replace("/\s+/", '', $preset['Token']); + if (!is_object($this->getCmd(null, $logicalId))) { + log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création du preset avec logicalId ' . $logicalId); + $cmdPreset = new cameraCmd(); + $cmdPreset->setName($preset['Name']); + $cmdPreset->setType('action'); + $cmdPreset->setSubType('other'); + $cmdPreset->setEqLogic_id($this->getId()); + $cmdPreset->setConfiguration('token', $preset['Token']); + $cmdPreset->setLogicalId($logicalId); + try { + $cmdPreset->save(); + } catch (Exception $e) { + $cmdPreset->setName($preset['Name'] . rand(0, 9999)); + $cmdPreset->save(); } - - $etape++; - - if (!$error) { - try { - $node = $onvif->ptz_GetNode($token); - $homeSupported = $node['HomeSupported'] ?? false; - if ($homeSupported) { - if (!is_object($this->getCmd(null, 'gotohome'))) { - log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création de la commande gotohome'); - $cmdGotohome = new cameraCmd(); - $cmdGotohome->setName('Go to home'); - $cmdGotohome->setType('action'); - $cmdGotohome->setSubType('other'); - $cmdGotohome->setEqLogic_id($this->getId()); - $Gotohome->setLogicalId($logicalId); - try { - $cmdGotohome->save(); - } catch (Exception $e) { - $cmdGotohome->setName('Go to home' . rand(0, 9999)); - $cmdGotohome->save(); - } - $nbCreatepreset++; - } - } - } catch(Exception $e) { - log::add(__CLASS__,'debug','[getConfigOnvif] KO Etape ' . $etape . ' - GetNode : ' . $e); - $error = true; - } + $nbCreatepreset++; + } + $nbpreset++; + } + try { + $node = $onvif->ptz_GetNode($token); + $homeSupported = $node['HomeSupported'] ?? false; + } catch(Exception $e) { + throw new Exception('[createCmdPresetOnvif] KO Etape ptz_GetNode(' . $token . ') : ' . $e); + } + if ($homeSupported) { + if (!is_object($this->getCmd(null, 'gotohome'))) { + log::add(__CLASS__,'debug','[createCmdPresetOnvif] [NOTICE] Création de la commande gotohome'); + $cmdGotohome = new cameraCmd(); + $cmdGotohome->setName('Go to home'); + $cmdGotohome->setType('action'); + $cmdGotohome->setSubType('other'); + $cmdGotohome->setEqLogic_id($this->getId()); + $cmdGotohome->setLogicalId('gotohome'); + try { + $cmdGotohome->save(); + } catch (Exception $e) { + $cmdGotohome->setName('Go to home' . rand(0, 9999)); + $cmdGotohome->save(); } - break; - } + $nbCreatepreset++; + } } $return['createPreset'] = $nbCreatepreset; log::add(__CLASS__,'debug','[createCmdPresetOnvif] [INFO] Return -> ' . json_encode($return)); @@ -1299,7 +1257,7 @@ public function execute($_options = null) { $onvif->core_SystemReboot(); break; case 'gotohome': - $onvif->ptz_GotoHomePosition($profileToken, 0, 0); + $onvif->ptz_GotoHomePosition($profileToken, $speedX, $speedY, $speedZ); break; } diff --git a/desktop/js/camera.js b/desktop/js/camera.js index a2f9710..7b2f79a 100644 --- a/desktop/js/camera.js +++ b/desktop/js/camera.js @@ -20,9 +20,16 @@ $('#bt_healthCamera').on('click', function() { $('#md_modal').load('index.php?v=d&plugin=camera&modal=health').dialog('open') }) -$('#bt_discoverCam').on('click', function() { - $('#md_modal').dialog({ title: "{{Découverte Caméras}}" }) - $('#md_modal').load('index.php?v=d&plugin=camera&modal=discover.cam').dialog('open') +document.getElementById('div_pageContainer')?.addEventListener('click', function(event) { + let _target = null + if (_target = event.target.closest('#bt_discoverCam')) { + jeeDialog.dialog({ + id: 'jee_modal', + title: "{{Découverte Caméras}}", + contentUrl: 'index.php?v=d&plugin=camera&modal=discover.cam', + }) + return + } }) $('#bt_previewCam').off('click').on('click', function() { diff --git a/desktop/modal/discover.cam.php b/desktop/modal/discover.cam.php index aa95c4f..3d8f491 100644 --- a/desktop/modal/discover.cam.php +++ b/desktop/modal/discover.cam.php @@ -39,13 +39,9 @@ echo $cam['type']; echo ''; if ($cam['exist'] === false) { - echo ''; - echo ''; echo ' {{Ajouter}}'; } else { - echo ''; - echo '{{Caméra déja importée}}'; - echo ''; + echo ' {{Ajouter}}'; } echo ''; } From 9d21c4f25349a4191b63669a3760e4617aaa3025 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:28:33 +0100 Subject: [PATCH 13/15] update From 5a418d984a3eecc2d09d0ca3a13d01b17fd23130 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:37:34 +0100 Subject: [PATCH 14/15] oupss --- desktop/modal/discover.cam.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/desktop/modal/discover.cam.php b/desktop/modal/discover.cam.php index 3d8f491..d5c8b14 100644 --- a/desktop/modal/discover.cam.php +++ b/desktop/modal/discover.cam.php @@ -38,6 +38,8 @@ echo ''; echo $cam['type']; echo ''; + echo ''; + echo ''; if ($cam['exist'] === false) { echo ' {{Ajouter}}'; } else { From 2eebfc509e67a26004134797e3e741e0201d7711 Mon Sep 17 00:00:00 2001 From: David <79108364+Phpvarious@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:36:29 +0100 Subject: [PATCH 15/15] no_ptz_if_request --- core/class/camera.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/camera.class.php b/core/class/camera.class.php index 79c190f..f0c590b 100644 --- a/core/class/camera.class.php +++ b/core/class/camera.class.php @@ -1205,7 +1205,7 @@ public function execute($_options = null) { $eqLogic->recordCam($_options['title'], $_options['message']); return true; } - if ($eqLogic->getConfiguration('device') == 'onvif') { + if ($eqLogic->getConfiguration('device') == 'onvif' && $request == '') { $profileToken = $eqLogic->getConfiguration('cameraStreamProfileToken'); $speedX = $eqLogic->getConfiguration('speed_x', 1); $speedY = $eqLogic->getConfiguration('speed_y', 1);