Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/work.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on:
# Workflows check plugin Jeedom
push:
branches:
- beta
pull_request:
branches:
- beta
- master

name : 'Full Workflows Plugin Jeedom'

jobs:
plugin:
uses: jeedom/workflows/.github/workflows/plugin.yml@main
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ test.php
core/config/common.config.php
plugins
sftp-config.json
.vscode/settings.json
.vscode/sftp.json
.vscode
20 changes: 10 additions & 10 deletions 3rdparty/networks_ping.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
class networks_Ping {
private $host;
private $ttl;
private $timeout;
private $port = 80;
private $data = 'Ping';

public function __construct($host, $ttl = 255) {
public function __construct($host, $ttl = 255, $timeout = 3) {
if (!isset($host)) {
throw new \Exception("Error: Host name not supplied.");
}
$this->host = $host;
$this->ttl = $ttl;
$this->timeout = $timeout;
}

public function setTtl($ttl) {
Expand Down Expand Up @@ -53,16 +54,17 @@ private function pingExec($_mode = 'ip') {
$latency = false;
$ttl = escapeshellcmd($this->ttl);
$host = escapeshellcmd($this->host);
$timeout = escapeshellcmd($this->timeout);
if ($_mode == 'arp') {
$exec_string = 'sudo arping -c 10 -C 1 -w 500000 ' . $host . ' 2> /dev/null';
$exec_string = "sudo arping -c 1 -C 1 -w 10 -W {$timeout} {$host} 2> /dev/null";
} else {
$exec_string = 'sudo ping -n -c 1 -t ' . $ttl . ' ' . $host . ' 2> /dev/null';
$exec_string = "sudo ping -n -c 1 -t {$ttl} -W {$timeout} {$host} 2> /dev/null";
}
exec($exec_string, $output, $return);
$output = array_values(array_filter($output));
if (!empty($output[1])) {
if (count($output) >= 5) {
$response = preg_match("/time(?:=|<)(?<time>[\.0-9]+)(?:|\s)(?<unit>[mu]?s(ec)?)/", $output[count($output)-4], $matches);
$response = preg_match("/time(?:=|<)(?<time>[\.0-9]+)(?:|\s)(?<unit>[mu]?s(ec)?)/", $output[count($output) - 4], $matches);
if ($response > 0 && isset($matches['time'])) {
$latency = $matches['time'];
if (isset($matches['unit'])) {
Expand All @@ -72,15 +74,15 @@ private function pingExec($_mode = 'ip') {
$latency /= 1000;
}
}
}
}
}
}
}
return $latency;
}

private function pingPort() {
$start = microtime(true);
$fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->ttl);
$fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
if (!$fp) {
$latency = false;
} else {
Expand All @@ -89,6 +91,4 @@ private function pingPort() {
}
return $latency;
}

}
?>
163 changes: 71 additions & 92 deletions core/class/networks.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,25 @@
require_once dirname(__FILE__) . '/../php/networks.inc.php';

class networks extends eqLogic {
/* * *************************Attributs****************************** */

public static $_widgetPossibility = array('custom' => true);

/* * ***********************Methode static*************************** */

public static function dependancy_info() {
$return = array();
$return['log'] = 'networks_update';
$return['progress_file'] = '/tmp/dependancy_networks_in_progress';
$return['state'] = 'ok';
if (exec('which etherwake | wc -l') == 0 || exec('which wakeonlan | wc -l') == 0) {
if (exec(" dpkg --get-selections | grep -v deinstall | grep -E 'wakeonlan|etherwake' | wc -l") != 2) {
$return['state'] = 'nok';
}
}
return $return;
}

public static function dependancy_install() {
log::remove(__CLASS__ . '_update');
return array('script' => dirname(__FILE__) . '/../../resources/install_#stype#.sh ' . jeedom::getTmpFolder('networks') . '/dependance', 'log' => log::getPathToLog(__CLASS__ . '_update'));
}
/* * ***********************Method static*************************** */

public static function update() {
foreach (self::byType('networks') as $networks) {
/** @var networks */
foreach (self::byType('networks', true) as $networks) {
$autorefresh = $networks->getConfiguration('autorefresh');
if ($networks->getIsEnable() == 1 && $autorefresh != '') {
try {
$c = new Cron\CronExpression($autorefresh, new Cron\FieldFactory);
if ($c->isDue()) {
try {
$networks->ping();
} catch (Exception $exc) {
log::add('networks', 'error', __('Erreur pour ', __FILE__) . $networks->getHumanName() . ' : ' . $exc->getMessage());
}
if ($autorefresh == '') continue;

try {
$c = new Cron\CronExpression($autorefresh, new Cron\FieldFactory);
if ($c->isDue()) {
try {
$networks->ping();
} catch (Exception $exc) {
log::add('networks', 'error', __('Erreur pour ', __FILE__) . $networks->getHumanName() . ' : ' . $exc->getMessage());
}
} catch (Exception $exc) {
log::add('networks', 'error', __('Expression cron non valide pour ', __FILE__) . $networks->getHumanName() . ' : ' . $autorefresh);
}
} catch (Exception $exc) {
log::add('networks', 'error', __('Expression cron non valide pour ', __FILE__) . $networks->getHumanName() . ' : ' . $autorefresh);
}
}
}
Expand All @@ -69,6 +48,16 @@ public static function update() {

/* * *********************Méthodes d'instance************************* */

public function preInsert() {
$this->setConfiguration('pingMode', 'ip');
}

public function preUpdate() {
if ($this->getConfiguration('ip') == '') {
throw new Exception(__('L\'adresse IP ne peut être vide', __FILE__));
}
}

public function preSave() {
if ($this->getConfiguration('autorefresh') == '') {
$this->setConfiguration('autorefresh', '* * * * *');
Expand Down Expand Up @@ -96,7 +85,7 @@ public function postSave() {
$ping->setName(__('Statut', __FILE__));
$ping->setOrder(1);
$ping->setTemplate('dashboard', 'line');
$ping->setConfiguration('repeatEventManagement','never');
$ping->setConfiguration('repeatEventManagement', 'never');
}
$ping->setType('info');
$ping->setSubType('binary');
Expand All @@ -118,33 +107,33 @@ public function postSave() {
$latency->setUnite('ms');
$latency->save();

$addresseIP = $this->getCmd(null, 'addresseIP');
if (!is_object($addresseIP)) {
$addresseIP = new networksCmd();
$addresseIP->setLogicalId('addresseIP');
$addresseIP->setIsVisible(1);
$addresseIP->setName(__('addresseIP', __FILE__));
$addresseIP->setOrder(3);
}
$addresseIP->setType('info');
$addresseIP->setSubType('string');
$addresseIP->setEqLogic_id($this->getId());
$addresseIP->save();
$addresseIP->event($this->getConfiguration('ip', ''));

$addresseMAC = $this->getCmd(null, 'addresseMAC');
if (!is_object($addresseMAC)) {
$addresseMAC = new networksCmd();
$addresseMAC->setLogicalId('addresseMAC');
$addresseMAC->setIsVisible(1);
$addresseMAC->setName(__('addresseMAC', __FILE__));
$addresseMAC->setOrder(4);
}
$addresseMAC->setType('info');
$addresseMAC->setSubType('string');
$addresseMAC->setEqLogic_id($this->getId());
$addresseMAC->save();
$addresseMAC->event($this->getConfiguration('mac'), '');
$addressIP = $this->getCmd(null, 'addresseIP');
if (!is_object($addressIP)) {
$addressIP = new networksCmd();
$addressIP->setLogicalId('addresseIP');
$addressIP->setIsVisible(1);
$addressIP->setName(__('addresseIP', __FILE__));
$addressIP->setOrder(3);
}
$addressIP->setType('info');
$addressIP->setSubType('string');
$addressIP->setEqLogic_id($this->getId());
$addressIP->save();
$addressIP->event($this->getConfiguration('ip', ''));

$addressMAC = $this->getCmd(null, 'addresseMAC');
if (!is_object($addressMAC)) {
$addressMAC = new networksCmd();
$addressMAC->setLogicalId('addresseMAC');
$addressMAC->setIsVisible(1);
$addressMAC->setName(__('addresseMAC', __FILE__));
$addressMAC->setOrder(4);
}
$addressMAC->setType('info');
$addressMAC->setSubType('string');
$addressMAC->setEqLogic_id($this->getId());
$addressMAC->save();
$addressMAC->event($this->getConfiguration('mac'), '');

$wol = $this->getCmd(null, 'wol');
if ($this->getConfiguration('mac') == '' || $this->getConfiguration('broadcastIP') == '') {
Expand All @@ -165,29 +154,23 @@ public function postSave() {
}
}

public function preUpdate() {
if ($this->getConfiguration('ip') == '') {
throw new Exception(__('L\'adresse IP ne peut être vide', __FILE__));
}
}

public function ping() {
if ($this->getConfiguration('ip') == '') {
return;
}
$changed = false;
$ping = new networks_Ping($this->getConfiguration('ip'), $this->getConfiguration('ttl', 255));
if ($this->getConfiguration('pingMode', 'ip') == 'port') {
$ping = new networks_Ping($this->getConfiguration('ip'), $this->getConfiguration('ttl', 255), $this->getConfiguration('timeout', 3));
$pingMode = $this->getConfiguration('pingMode', 'ip');
if ($pingMode == 'port') {
$ping->setPort($this->getConfiguration('port', 80));
}
$latency_time = $ping->ping($this->getConfiguration('pingMode', 'ip'));
if ($latency_time === false) {
$latency_time = $ping->ping($this->getConfiguration('pingMode', 'ip'));
}
if ($latency_time === false) {

$maxTry = max(min(10, $this->getConfiguration('maxTry', 3)), 1);
do {
log::add(__CLASS__, 'debug', '[' . getmypid() . '] ' . __('Tentative de ping sur : ', __FILE__) . $this->getHumanName());
$latency_time = $ping->ping($pingMode);
usleep(100);
$latency_time = $ping->ping($this->getConfiguration('pingMode', 'ip'));
}
} while ($latency_time === false && --$maxTry > 0);

if ($this->getConfiguration('notifyifko') == 1) {
if ($latency_time === false) {
message::add('networks', __('Echec du ping sur : ', __FILE__) . $this->getHumanName(), '', 'pingFailed' . $this->getId());
Expand All @@ -198,33 +181,31 @@ public function ping() {
}
}
if ($latency_time !== false) {
$changed = $this->checkAndUpdateCmd('ping', 1) || $changed;
$changed = $this->checkAndUpdateCmd('latency', $latency_time) || $changed;
log::add(__CLASS__, 'info', '[' . getmypid() . '] ' . __('Ping réussi sur : ', __FILE__) . $this->getHumanName());
$this->checkAndUpdateCmd('ping', 1);
$this->checkAndUpdateCmd('latency', $latency_time);
} else {
$changed = $this->checkAndUpdateCmd('ping', 0) || $changed;
$changed = $this->checkAndUpdateCmd('latency', -1) || $changed;
}
if ($changed) {
$this->refreshWidget();
log::add(__CLASS__, 'info', '[' . getmypid() . '] ' . __('Ping échoué sur : ', __FILE__) . $this->getHumanName());
$this->checkAndUpdateCmd('ping', 0);
$this->checkAndUpdateCmd('latency', -1);
}
}

/* * **********************Getteur Setteur*************************** */
}

class networksCmd extends cmd {
/* * *************************Attributs****************************** */

public static $_widgetPossibility = array('custom' => true);

/* * ***********************Methode static*************************** */
/* * ***********************Method static*************************** */

/* * *********************Methode d'instance************************* */
/* * *********************Method d'instance************************* */

public function execute($_options = array()) {
if ($this->getType() == 'info') {
return;
}
/** @var networks */
$eqLogic = $this->getEqLogic();
if ($this->getLogicalId() == 'wol') {
$f = new \Phpwol\Factory();
Expand Down Expand Up @@ -253,6 +234,4 @@ public function execute($_options = array()) {
$eqLogic->ping();
}
}

/* * **********************Getteur Setteur*************************** */
}
9 changes: 8 additions & 1 deletion core/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"IP": "IP",
"ARP": "ARP",
"Port": "Hafen",
"Timeout (s)": "Zeitüberschreitung(en)",
"Entre 1s & 10s. Par défaut 3s.": "Zwischen 1s und 10s. Standard 3s",
"Maximum de tentatives en cas d'échec": "Maximum de tentatives en cas d'échec",
"Entre 1 & 10. Par défaut 3.": "Entre 1 & 10. Par défaut 3",
"TTL": "TTL",
"Auto-actualisation": "Selbstauffrischung",
"Fréquence de rafraîchissement des commandes infos de l'équipement": "Aktualisierungsrate des Ausrüstungsinfo-Befehls",
Expand Down Expand Up @@ -65,14 +69,17 @@
"plugins\/networks\/core\/class\/networks.class.php": {
"Erreur pour ": "Fehler für",
"Expression cron non valide pour ": "Ungültiger Cron-Ausdruck für",
"L\\'adresse IP ne peut être vide": "Die IP-Adresse darf nicht leer sein",
"Rafraîchir": "Aktualisieren",
"Statut": "Status",
"Latence": "Latenz",
"addresseIP": "AdresseIP",
"addresseMAC": "MAC-Adresse",
"Wake-on-lan": "Wake-on-Lan",
"L\\'adresse IP ne peut être vide": "Die IP-Adresse darf nicht leer sein",
"Tentative de ping sur : ": "Tentative de ping sur :",
"Echec du ping sur : ": "Ping fehlgeschlagen am:",
"Ping réussi sur : ": "Ping réussi sur :",
"Ping échoué sur : ": "Ping échoué sur :",
"IP invalide": "Ungültige IP",
"MAC invalide": "Ungültiger MAC",
"SUBNET invalide": "Ungültiges SUBNET",
Expand Down
11 changes: 9 additions & 2 deletions core/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"IP": "IP",
"ARP": "ARP",
"Port": "Port",
"Timeout (s)": "Timeout(s)",
"Entre 1s & 10s. Par défaut 3s.": "Between 1s & 10s. Default 3s",
"Maximum de tentatives en cas d'échec": "Maximum de tentatives en cas d'échec",
"Entre 1 & 10. Par défaut 3.": "Entre 1 & 10. Par défaut 3",
"TTL": "TTL",
"Auto-actualisation": "Self-refresh",
"Fréquence de rafraîchissement des commandes infos de l'équipement": "Equipment Info Command Refresh Rate",
Expand All @@ -52,7 +56,7 @@
"Historiser": "Historize",
"Inverser": "Reverse",
"Min": "Minimum",
"Max": "Max",
"Max": "Maximum",
"Unité": "Unity",
"Configuration avancée": "Advanced configuration",
"Tester": "Test",
Expand All @@ -65,14 +69,17 @@
"plugins\/networks\/core\/class\/networks.class.php": {
"Erreur pour ": "Error for",
"Expression cron non valide pour ": "Invalid cron expression for",
"L\\'adresse IP ne peut être vide": "IP address can't be empty",
"Rafraîchir": "Refresh",
"Statut": "Status",
"Latence": "Latency",
"addresseIP": "addressIP",
"addresseMAC": "MACaddress",
"Wake-on-lan": "Wake-on-lan",
"L\\'adresse IP ne peut être vide": "IP address can't be empty",
"Tentative de ping sur : ": "Tentative de ping sur :",
"Echec du ping sur : ": "Ping failed on:",
"Ping réussi sur : ": "Ping réussi sur :",
"Ping échoué sur : ": "Ping échoué sur :",
"IP invalide": "Invalide IP",
"MAC invalide": "MAC address invalid",
"SUBNET invalide": "Subnet invalid",
Expand Down
Loading