From d0a992da659acd429ff2c22caf2557fb36ad03a2 Mon Sep 17 00:00:00 2001 From: Ignace LE ROUX Date: Tue, 29 Sep 2020 15:41:16 +0200 Subject: [PATCH 1/2] Add Info field to get IP from Mac adress - Formatting sources - Fix Orthographe fr - Fix "My Pings" add command GUI - Add info field for Current IP reverse looking from MAC adress in ARP mode - Tune ARP request --- core/ajax/ping.ajax.php | 1 - core/class/ping.class.php | 63 +++++-- core/i18n/tr.json | 2 +- desktop/js/ping.js | 344 +++++++++++++++++----------------- desktop/php/ping.php | 124 ++++++------ plugin_info/configuration.php | 22 +-- plugin_info/install.php | 1 - 7 files changed, 301 insertions(+), 256 deletions(-) diff --git a/core/ajax/ping.ajax.php b/core/ajax/ping.ajax.php index e0beba3..6138172 100644 --- a/core/ajax/ping.ajax.php +++ b/core/ajax/ping.ajax.php @@ -53,4 +53,3 @@ } catch (Exception $e) { ajax::error(displayExeption($e), $e->getCode()); } -?> diff --git a/core/class/ping.class.php b/core/class/ping.class.php index 732d62d..429996a 100644 --- a/core/class/ping.class.php +++ b/core/class/ping.class.php @@ -130,7 +130,7 @@ public function preUpdate() $cmd->setName('Ping'); $cmd->setEqLogic_id($this->getId()); $cmd->setType('action'); - $cmd->setSubType('other'); + $cmd->setSubType('string'); $cmd->setLogicalId('ping'); $cmd->setEventOnly(1); $cmd->setDisplay('icon',''); @@ -146,6 +146,21 @@ public function preUpdate() $cmd->save(); } } + + $cmd = $this->getCmd(null, 'info'); + if ( ! is_object($cmd) ) { + $cmd = new pingCmd(); + $cmd->setName('Info'); + $cmd->setEqLogic_id($this->getId()); + $cmd->setLogicalId('info'); + $cmd->setType('info'); + $cmd->setSubType('string'); + $cmd->setIsHistorized(0); + $cmd->setEventOnly(1); + $cmd->setDisplay('icon',''); + $cmd->setDisplay('generic_type','GENERIC_INFO'); + $cmd->save(); + } } public function postUpdate() @@ -203,6 +218,20 @@ public function postInsert() $cmd->setDisplay('generic_type','GENERIC_INFO'); $cmd->save(); } + $cmd = $this->getCmd(null, 'info'); + if ( ! is_object($cmd) ) { + $cmd = new pingCmd(); + $cmd->setName('Info'); + $cmd->setEqLogic_id($this->getId()); + $cmd->setLogicalId('info'); + $cmd->setType('info'); + $cmd->setSubType('string'); + $cmd->setIsHistorized(0); + $cmd->setEventOnly(1); + $cmd->setDisplay('icon',''); + $cmd->setDisplay('generic_type','GENERIC_INFO'); + $cmd->save(); + } } public function ping() { @@ -210,7 +239,8 @@ public function ping() { log::add('ping','debug','Test '.$this->getHumanName()); $statuscmd = $this->getCmd(null, 'state'); $delaicmd = $this->getCmd(null, 'delai'); - + $infocmd = $this->getCmd(null, 'info'); + log::add('ping','debug','mode : '.$this->getConfiguration('mode')); switch ($this->getConfiguration('mode')) { case "Tcp": @@ -289,30 +319,35 @@ public function ping() { case "Arp": log::add('ping','debug','Search '.$this->getConfiguration('mac')); $cmd = config::byKey('cmd_arp', 'ping'); - $cmd .= " -l -g --retry=5 -t 800"; + $cmd .= " -q -l -g --retry=4 -t 800"; if ( $this->getConfiguration('interface') != "" ) { $cmd .= ' -I '.$this->getConfiguration('interface'); } - $cmd .= ' -T '.$this->getConfiguration('mac').' 2>&1'; + $cmd .= ' -T '.strtolower($this->getConfiguration('mac')).' 2>/dev/null | grep "'.strtolower($this->getConfiguration('mac')).'" | awk -F \'\t\' \'{ print $1 }\''; log::add('ping','debug',$cmd); $lastligne = exec($cmd, $return, $code); log::add('ping','debug','Retour commande '.join("\n", $return)); - if ( preg_match("/\t".strtolower($this->getConfiguration('mac'))."\t/", strtolower(join("\n", $return))) ) + if (empty($return)) { - log::add('ping','debug','Ok'); - if ($statuscmd->execCmd() != 1) { - $statuscmd->setCollectDate(''); - $statuscmd->event(1); - } - } else { log::add('ping','debug','Ko'); if ($statuscmd->execCmd() != 0) { $statuscmd->setCollectDate(''); $statuscmd->event(0); + $infocmd->event('!'.$infocmd->execCmd().'!'); + } + } else { + $infocmd->setCollectDate(''); + log::add('ping','debug','Ok'); + $infocmd->event(''.join("", $return)); + if ($statuscmd->execCmd() != 1) { + $statuscmd->setCollectDate(''); + $statuscmd->event(1); } } - break; + + + break; } } } @@ -334,7 +369,7 @@ public static function GetPingCmd() { } public static function GetArpCmd() { - foreach(array('sudo /usr/bin/arp-scan') as $cmd) + foreach(array('sudo /usr/sbin/arp-scan') as $cmd) { log::add('ping','debug','Essai la commande pour arp :'.$cmd); unset($return); @@ -374,4 +409,4 @@ public function execute($_options = null) { return true; } } -?> +?> \ No newline at end of file diff --git a/core/i18n/tr.json b/core/i18n/tr.json index c40ceea..e446d8e 100644 --- a/core/i18n/tr.json +++ b/core/i18n/tr.json @@ -40,6 +40,6 @@ "plugins\/ping\/plugin_info\/configuration.php": { "Commande ping": "Commande ping", "Commande arp-scan": "Commande arp-scan", - "Detecter les programme ping et arp-scan": "Detecter les programme ping et arp-scan" + "Detecter les programme ping et arp-scan": "Detecter les programmes ping et arp-scan" } } \ No newline at end of file diff --git a/desktop/js/ping.js b/desktop/js/ping.js index 78eb141..42f96b4 100644 --- a/desktop/js/ping.js +++ b/desktop/js/ping.js @@ -1,186 +1,196 @@ function addCmdToTable(_cmd) { - if (!isset(_cmd)) { - var _cmd = {configuration: {}}; + if (!isset(_cmd)) { + var _cmd = { configuration: {} }; + } + if (!isset(_cmd.configuration)) { + _cmd.configuration = {}; + } + + if (init(_cmd.type) == "info") { + + var tr = ''; + tr += ""; + tr += ''; + tr += ''; + tr += ""; + tr += ""; + tr += ' Icone'; + tr += ''; + tr += ""; + tr += ''; + tr += ''; + tr += ''; + tr += ''; + tr += ""; + tr += ""; + tr += ' {{Historiser}}
'; + tr += ' {{Afficher}}
'; + tr += ""; + // tr += ''; + tr += ""; + if (is_numeric(_cmd.id)) { + tr += ' '; } - if (!isset(_cmd.configuration)) { - _cmd.configuration = {}; + tr += ""; + table_cmd = "#table_cmd"; + if ($(table_cmd + "_" + _cmd.eqType).length) { + table_cmd += "_" + _cmd.eqType; } - - if (init(_cmd.type) == 'info') { - var tr = ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ' Icone'; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ' {{Historiser}}
'; - tr += ' {{Afficher}}
'; - tr += ''; -// tr += ''; - tr += ''; - if (is_numeric(_cmd.id)) { - tr += ' '; - } - tr += ''; - table_cmd = '#table_cmd'; - if ( $(table_cmd+'_'+_cmd.eqType ).length ) { - table_cmd+= '_'+_cmd.eqType; - } - $(table_cmd+' tbody').append(tr); - $(table_cmd+' tbody tr:last').setValues(_cmd, '.cmdAttr'); + $(table_cmd + " tbody").append(tr); + $(table_cmd + " tbody tr:last").setValues(_cmd, ".cmdAttr"); + } + if (init(_cmd.type) == "action") { + var tr = ''; + tr += ""; + tr += ''; + tr += ''; + tr += ""; + tr += ""; + tr += ' Icone'; + tr += ''; + tr += ""; + tr += ""; + tr += ''; + tr += ''; + tr += ""; + tr += ""; + tr += ' {{Afficher}}
'; + tr += ""; + tr += ""; + if (is_numeric(_cmd.id)) { + tr += ' '; + tr += ' {{Tester}}'; } - if (init(_cmd.type) == 'action') { - var tr = ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ' Icone'; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ' {{Afficher}}
'; - tr += ''; - tr += ''; - if (is_numeric(_cmd.id)) { - tr += ' '; - tr += ' {{Tester}}'; - } -// tr += ''; - tr += ''; + // tr += ''; + tr += ""; - table_cmd = '#table_cmd'; - if ( $(table_cmd+'_'+_cmd.eqType ).length ) { - table_cmd+= '_'+_cmd.eqType; - } - $(table_cmd+' tbody').append(tr); - $(table_cmd+' tbody tr:last').setValues(_cmd, '.cmdAttr'); - var tr = $(table_cmd+' tbody tr:last'); - jeedom.eqLogic.builSelectCmd({ - id: $(".li_eqLogic.active").attr('data-eqLogic_id'), - filter: {type: 'info'}, - error: function (error) { - $('#div_alert').showAlert({message: error.message, level: 'danger'}); - }, - success: function (result) { - tr.find('.cmdAttr[data-l1key=value]').append(result); - tr.setValues(_cmd, '.cmdAttr'); - } - }); + table_cmd = "#table_cmd"; + if ($(table_cmd + "_" + _cmd.eqType).length) { + table_cmd += "_" + _cmd.eqType; } + $(table_cmd + " tbody").append(tr); + $(table_cmd + " tbody tr:last").setValues(_cmd, ".cmdAttr"); + var tr = $(table_cmd + " tbody tr:last"); + jeedom.eqLogic.builSelectCmd({ + id: $(".li_eqLogic.active").attr("data-eqLogic_id"), + filter: { type: "info" }, + error: function (error) { + $("#div_alert").showAlert({ message: error.message, level: "danger" }); + }, + success: function (result) { + tr.find(".cmdAttr[data-l1key=value]").append(result); + tr.setValues(_cmd, ".cmdAttr"); + }, + }); + } } -$("#table_cmd").sortable({axis: "y", cursor: "move", items: ".cmd", placeholder: "ui-state-highlight", tolerance: "intersect", forcePlaceholderSize: true}); +$("#table_cmd").sortable({ + axis: "y", + cursor: "move", + items: ".cmd", + placeholder: "ui-state-highlight", + tolerance: "intersect", + forcePlaceholderSize: true, +}); -$(function(){ - $('input[type=radio][name=mode]').change(function(){ - if ( $(this).val() == 'Icmp' ) - { - $("#port").hide(); - $("#ip").show(); - $("#mac").hide(); - $("#interface").hide(); - } - else if ( $(this).val() == 'Arp' ) - { - $("#port").hide(); - $("#ip").hide(); - $("#mac").show(); - $("#interface").show(); - } - else - { - $("#ip").show(); - $("#mac").hide(); - $("#port").show(); - $("#interface").hide(); - } - }) -}) +$(function () { + $("input[type=radio][name=mode]").change(function () { + if ($(this).val() == "Icmp") { + $("#port").hide(); + $("#ip").show(); + $("#mac").hide(); + $("#interface").hide(); + } else if ($(this).val() == "Arp") { + $("#port").hide(); + $("#ip").hide(); + $("#mac").show(); + $("#interface").show(); + } else { + $("#ip").show(); + $("#mac").hide(); + $("#port").show(); + $("#interface").hide(); + } + }); +}); function saveEqLogic(_eqLogic) { - _eqLogic.configuration.mode = $('input[type=radio][name=mode]:checked').val(); - return _eqLogic; + _eqLogic.configuration.mode = $("input[type=radio][name=mode]:checked").val(); + return _eqLogic; } function printEqLogic(_eqLogic) { - if (isset(_eqLogic.configuration) && isset(_eqLogic.configuration.mode) && _eqLogic.configuration.mode != '') { - $('input[type=radio][name=mode][value='+_eqLogic.configuration.mode+']').prop('checked', true); - if ( _eqLogic.configuration.mode == 'Icmp' ) - { - $("#port").hide(); - $("#ip").show(); - $("#mac").hide(); - $("#interface").hide(); - } - else if ( _eqLogic.configuration.mode == 'Arp' ) - { - $("#port").hide(); - $("#ip").hide(); - $("#mac").show(); - $("#interface").show(); - } - else - { - $("#ip").show(); - $("#mac").hide(); - $("#port").show(); - $("#interface").hide(); - } - } - else - { - $('input[type=radio][name=mode][value=Tcp]').prop('checked', true); - $("#ip").show(); - $("#mac").hide(); - $("#port").show(); - $("#interface").hide(); - } + if (isset(_eqLogic.configuration) && isset(_eqLogic.configuration.mode) && _eqLogic.configuration.mode != "") { + $("input[type=radio][name=mode][value=" + _eqLogic.configuration.mode + "]").prop("checked", true); + if (_eqLogic.configuration.mode == "Icmp") { + $("#port").hide(); + $("#ip").show(); + $("#mac").hide(); + $("#interface").hide(); + } else if (_eqLogic.configuration.mode == "Arp") { + $("#port").hide(); + $("#ip").hide(); + $("#mac").show(); + $("#interface").show(); + } else { + $("#ip").show(); + $("#mac").hide(); + $("#port").show(); + $("#interface").hide(); + } + } else { + $("input[type=radio][name=mode][value=Tcp]").prop("checked", true); + $("#ip").show(); + $("#mac").hide(); + $("#port").show(); + $("#interface").hide(); + } } -$('#bt_DetectBin').on('click', function() { - $.ajax({// fonction permettant de faire de l'ajax - type: "POST", // methode de transmission des données au fichier php - url: "plugins/ping/core/ajax/ping.ajax.php", // url du fichier php - data: { - action: "DetectBin", +$("#bt_DetectBin").on("click", function () { + $.ajax({ + // fonction permettant de faire de l'ajax + type: "POST", // methode de transmission des données au fichier php + url: "plugins/ping/core/ajax/ping.ajax.php", // url du fichier php + data: { + action: "DetectBin", + }, + dataType: "json", + error: function (request, status, error) { + handleAjaxError(request, status, $("#div_DetectBin")); + }, + success: function (data) { + // si l'appel a bien fonctionné + if (data.state != "ok") { + $("#div_DetectBin").showAlert({ + message: data.result, + level: "danger", + }); + } else { + $("#div_DetectBin").showAlert({ + message: data.result, + level: "success", + }); + } + jeedom.config.load({ + configuration: $("#config").getValues(".configKey")[0], + plugin: "ping", + error: function (error) { + $("#div_alert").showAlert({ + message: error.message, + level: "danger", + }); }, - dataType: 'json', - error: function(request, status, error) { - handleAjaxError(request, status, $('#div_DetectBin')); + success: function (data) { + $("#config").setValues(data, ".configKey"); + modifyWithoutSave = false; + $("#div_alert").showAlert({ + message: "{{Sauvegarde réussie}}", + level: "success", + }); }, - success: function(data) { // si l'appel a bien fonctionné - if (data.state != 'ok') { - $('#div_DetectBin').showAlert({message: data.result, level: 'danger'}); - } else { - $('#div_DetectBin').showAlert({message: data.result, level: 'success'}); - } - jeedom.config.load({ - configuration: $('#config').getValues('.configKey')[0], - plugin: 'ping', - error: function (error) { - $('#div_alert').showAlert({message: error.message, level: 'danger'}); - }, - success: function (data) { - $('#config').setValues(data, '.configKey'); - modifyWithoutSave = false; - $('#div_alert').showAlert({message: '{{Sauvegarde réussie}}', level: 'success'}); - } - }); - } - }); + }); + }, + }); }); diff --git a/desktop/php/ping.php b/desktop/php/ping.php index c55e9f7..1d46d33 100644 --- a/desktop/php/ping.php +++ b/desktop/php/ping.php @@ -11,45 +11,45 @@
- {{Gestion}} -
-
-
- -
-
Ajouter
-
-
-
- -
-
{{Configuration}}
-
-
+ {{Gestion}} +
+
+
+ +
+
Ajouter
+
+
+
+ +
+
{{Configuration}}
+
+
{{Mes Pings}} -
-
-
- -
-
Ajouter
-
-

{{Vous n'avez pas encore de ping, cliquez sur Ajouter un équipement pour commencer}}
"; - } else { +
+
+
+ +
+
Ajouter
+
+

{{Vous n'avez pas encore de ping, cliquez sur Ajouter un équipement pour commencer}}
"; + } else { foreach ($eqLogics as $eqLogic) { echo '
'; echo "
"; @@ -58,32 +58,32 @@ echo '
' . $eqLogic->getHumanName(true, true) . '
'; echo '
'; } - ?> -
- + ?> +
+
- + \ No newline at end of file diff --git a/plugin_info/configuration.php b/plugin_info/configuration.php index 98e9bac..bb70b1f 100644 --- a/plugin_info/configuration.php +++ b/plugin_info/configuration.php @@ -18,7 +18,7 @@ require_once dirname(__FILE__) . '/../../../core/php/core.inc.php'; include_file('core', 'authentification', 'php'); if (!isConnect('admin')) { - throw new Exception('{{401 - Accès non autorisé}}'); + throw new Exception('{{401 - Accès non autorisé}}'); } ?> @@ -26,24 +26,22 @@
- +
- +
- +
-
-
- +
+
+
- - - + \ No newline at end of file diff --git a/plugin_info/install.php b/plugin_info/install.php index 7c1019b..f80cccb 100644 --- a/plugin_info/install.php +++ b/plugin_info/install.php @@ -60,4 +60,3 @@ function ping_remove() { $cron->remove(); } } -?> From 2e1239893d8474761a7790fc9dca64c9d97e4d61 Mon Sep 17 00:00:00 2001 From: Ignace LE ROUX Date: Tue, 29 Sep 2020 15:54:49 +0200 Subject: [PATCH 2/2] Fix Ping subtype (Last commit fix) Fix Ping subtype (Last commit fix) --- core/class/ping.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/ping.class.php b/core/class/ping.class.php index 429996a..d1c7879 100644 --- a/core/class/ping.class.php +++ b/core/class/ping.class.php @@ -130,7 +130,7 @@ public function preUpdate() $cmd->setName('Ping'); $cmd->setEqLogic_id($this->getId()); $cmd->setType('action'); - $cmd->setSubType('string'); + $cmd->setSubType('other'); $cmd->setLogicalId('ping'); $cmd->setEventOnly(1); $cmd->setDisplay('icon','');