diff --git a/core/ajax/teleinfo.ajax.php b/core/ajax/teleinfo.ajax.php index 911486c..9cb39e0 100644 --- a/core/ajax/teleinfo.ajax.php +++ b/core/ajax/teleinfo.ajax.php @@ -166,7 +166,7 @@ $return = history::byCmdIdDatetime(init('id'), date('Y-m-d H:i:s')); ajax::success($return); break; - case 'diagnostic_step0': + case 'diagnostic_step1': $return = array(); $return['portName'] = config::byKey('port', 'teleinfo'); @@ -180,18 +180,20 @@ $return['result'] = '1'; } $return['message'] = "Modem configuré : " . $return['portName']; + $return['test'] = jeedom::getTmpFolder("teleinfo"); try { - $diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + //$diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + $diagnosticFile = jeedom::getTmpFolder("teleinfo") . '/teleinfo_diag.txt'; exec('rm ' . $diagnosticFile); file_put_contents($diagnosticFile, serialize(date('Y-m-d H:i:s')), FILE_APPEND | LOCK_EX); - file_put_contents($diagnosticFile, serialize('||STEP_0||'), FILE_APPEND | LOCK_EX); + file_put_contents($diagnosticFile, serialize('||STEP_1||'), FILE_APPEND | LOCK_EX); file_put_contents($diagnosticFile, serialize($return), FILE_APPEND | LOCK_EX); } catch (\Exception $e) { } ajax::success($return); break; - case 'diagnostic_step1': + case 'diagnostic_step2': $return = array(); $return['portName'] = config::byKey('port', 'teleinfo'); if ($return['portName'] == "serie") { @@ -208,13 +210,14 @@ $return['message'] = 'Accès OK'; } try { - $diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; - file_put_contents($diagnosticFile, serialize('||STEP_1||'), FILE_APPEND | LOCK_EX); + //$diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + $diagnosticFile = jeedom::getTmpFolder("teleinfo") . '/teleinfo_diag.txt'; + file_put_contents($diagnosticFile, serialize('||STEP_2||'), FILE_APPEND | LOCK_EX); file_put_contents($diagnosticFile, serialize($return), FILE_APPEND | LOCK_EX); } catch (\Exception $e) {} ajax::success($return); break; - case 'diagnostic_step2': + case 'diagnostic_step3': $return = array(); $return['isCapable'] = jeedom::isCapable('sudo'); if (!jeedom::isCapable('sudo')) { @@ -226,13 +229,14 @@ $return['message'] = 'OK'; } try { - $diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; - file_put_contents($diagnosticFile, serialize('||STEP_2||'), FILE_APPEND | LOCK_EX); + //$diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + $diagnosticFile = jeedom::getTmpFolder("teleinfo") . '/teleinfo_diag.txt'; + file_put_contents($diagnosticFile, serialize('||STEP_3||'), FILE_APPEND | LOCK_EX); file_put_contents($diagnosticFile, serialize($return), FILE_APPEND | LOCK_EX); } catch (\Exception $e) {} ajax::success($return); break; - case 'diagnostic_step3': + case 'diagnostic_step4': $return = array(); $modemSerieAddr = config::byKey('port', 'teleinfo'); $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); @@ -264,27 +268,32 @@ $return['message'] = 'NOK'; } try { - $diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; - file_put_contents($diagnosticFile, serialize('||STEP_3||'), FILE_APPEND | LOCK_EX); + //$diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + $diagnosticFile = jeedom::getTmpFolder("teleinfo") . '/teleinfo_diag.txt'; + file_put_contents($diagnosticFile, serialize('||STEP_4||'), FILE_APPEND | LOCK_EX); file_put_contents($diagnosticFile, serialize($return), FILE_APPEND | LOCK_EX); } catch (\Exception $e) {} ajax::success($return); break; - case 'diagnostic_step4': + case 'diagnostic_step5': $return = array(); $return['message'] = ''; + $return['launch_url'] = parse_url(config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . config::byKey('internalComplement', 'core')); $return['result'] = '1'; try { - $diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; - file_put_contents($diagnosticFile, serialize('||STEP_4||'), FILE_APPEND | LOCK_EX); + //$diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + $diagnosticFile = jeedom::getTmpFolder("teleinfo") . '/teleinfo_diag.txt'; + file_put_contents($diagnosticFile, serialize('||STEP_5||'), FILE_APPEND | LOCK_EX); file_put_contents($diagnosticFile, serialize($return), FILE_APPEND | LOCK_EX); } catch (\Exception $e) {} ajax::success($return); break; - case 'diagnostic_step5': + case 'diagnostic_step6': $return = array(); - $monfichier = dirname(__FILE__) . '/../../../../tmp/teleinfo_export.txt'; - $diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + //$monfichier = dirname(__FILE__) . '/../../../../tmp/teleinfo_export.txt'; + $monfichier = jeedom::getTmpFolder("teleinfo") . '/teleinfo_export.txt'; + //$diagnosticFile = dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + $diagnosticFile = jeedom::getTmpFolder("teleinfo") . '/teleinfo_diag.txt'; exec('rm ' . $monfichier); file_put_contents($monfichier, serialize(date('Y-m-d H:i:s')), FILE_APPEND | LOCK_EX); foreach (eqLogic::byType('teleinfo') as $eqLogic) { @@ -300,11 +309,16 @@ } file_put_contents($monfichier, serialize('||EQLOGIC_END||'), FILE_APPEND | LOCK_EX); } - $return["files"] = log::getPathToLog('teleinfo'). " " . log::getPathToLog('teleinfo_deamon'). " " . log::getPathToLog('teleinfo_update') . " " . dirname(__FILE__) . '/../../plugin_info/info.json'. " " . dirname(__FILE__) . '/../../../../tmp/teleinfo_export.txt' . " " . dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + //$return["files"] = log::getPathToLog('teleinfo'). " " . log::getPathToLog('teleinfo_deamon'). " " . log::getPathToLog('teleinfo_update') . " " . dirname(__FILE__) . '/../../plugin_info/info.json'. " " . dirname(__FILE__) . '/../../../../tmp/teleinfo_export.txt' . " " . dirname(__FILE__) . '/../../../../tmp/teleinfo_diag.txt'; + $return["files"] = log::getPathToLog('teleinfo'). " " . log::getPathToLog('teleinfo_deamon'). " " . log::getPathToLog('teleinfo_update') . " " . dirname(__FILE__) . '/../../plugin_info/info.json'. " " . $diagnosticFile . " " . $monfichier; $return["path"] = dirname(__FILE__) . '/../../../../tmp/teleinfolog.tar'; + //$return["path"] = jeedom::getTmpFolder("teleinfo") . '/teleinfolog.tar'; exec('rm ' . dirname(__FILE__) . '/../../../../tmp/teleinfolog.tar'); + //exec('rm ' . jeedom::getTmpFolder("teleinfo") . '/teleinfolog.tar'); $return["compress"] = exec('tar -cvf ' . dirname(__FILE__) . '/../../../../tmp/teleinfolog.tar ' . $return["files"]); - $return['message'] = 'Télécharger'; + //$return["compress"] = exec('tar -cvf ' . jeedom::getTmpFolder("teleinfo") . '/teleinfolog.tar ' . $return["files"]); + $return['message'] = 'Télécharger le package'; + //$return['message'] = 'Télécharger le package'; $return['result'] = '2'; ajax::success($return); break; diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 51f9f22..abc38db 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -77,8 +77,8 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) $cmd = (new teleinfoCmd()) ->setName($_oKey) ->setLogicalId($_oKey) - ->setType('info'); - $cmd->setEqLogic_id($teleinfo->id); + ->setType('info'); + $cmd->setEqLogic_id($teleinfo->id); $cmd->setConfiguration('info_conso', $_oKey); switch ($_oKey) { //case "PAPP": @@ -111,44 +111,51 @@ public static function runDeamon($_debug = false, $type = 'conso') $modemSerieAddr = config::byKey('port', 'teleinfo'); $_debug = config::byKey('debug', 'teleinfo'); $_force = config::byKey('force', 'teleinfo'); - $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); + $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); $linky = config::byKey('linky', 'teleinfo'); - if (config::byKey('modem_vitesse', 'teleinfo') == "") { - $modemVitesse = '1200'; + $modemVitesse = config::byKey('modem_vitesse', 'teleinfo'); + if ($modemSerieAddr == "serie") { + $port = config::byKey('modem_serie_addr', 'teleinfo'); } else { - $modemVitesse = config::byKey('modem_vitesse', 'teleinfo'); + $port = jeedom::getUsbMapping(config::byKey('port', 'teleinfo')); + if ($twoCptCartelectronic == 1) { + $port = '/dev/ttyUSB1'; + } else { + if (!file_exists($port)) { + log::add('teleinfo', 'error', 'Le port n\'existe pas'); + return false; + } + $cle_api = config::byKey('api'); + if ($cle_api == '') { + log::add('teleinfo', 'error', 'Erreur de clé api, veuillez la vérifier.'); + return false; + } + } } - if ($modemSerieAddr == "serie") { - $port = config::byKey('modem_serie_addr', 'teleinfo'); - } else { - $port = jeedom::getUsbMapping(config::byKey('port', 'teleinfo')); - if ($twoCptCartelectronic == 1) { - $port = '/dev/ttyUSB1'; - } else { - if (!file_exists($port)) { - log::add('teleinfo', 'error', 'Le port n\'existe pas'); - return false; - } - $cle_api = config::byKey('api'); - if ($cle_api == '') { - log::add('teleinfo', 'error', 'Erreur de clé api, veuillez la vérifier.'); - return false; - } - } - } - if ($linky == 1) { - $mode = 'standard'; - $modemVitesse = '9600'; - } - else { - $mode = 'historique'; + if ($linky == 1) { + $mode = 'standard'; + if ($modemVitesse == "") { + $modemVitesse = '9600'; + } + } + else { + $mode = 'historique'; + if ($modemVitesse == "") { + $modemVitesse = '1200'; + } } - $parsed_url = parse_url(config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . config::byKey('internalComplement', 'core')); + if (config::byKey('internalComplement', 'core') !== ""){ + $internalComplement = "/" .config::byKey('internalComplement', 'core'); + } + else{ + $internalComplement = ""; + } + $parsed_url = parse_url(config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . $internalComplement); exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1'); // TODO : Vérifier dans futur release si tjs nécessaire log::add('teleinfo', 'info', '--------- Informations sur le master --------'); - log::add('teleinfo', 'info', 'Adresse :' . config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . config::byKey('internalComplement', 'core')); + log::add('teleinfo', 'info', 'Adresse :' . config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . $internalComplement); log::add('teleinfo', 'info', 'Host / Port :' . $parsed_url['host'] . ':' . $parsed_url['port']); log::add('teleinfo', 'info', 'Path complémentaire :' . $parsed_url['path']); $ip_interne = $parsed_url['scheme'] . '://' . $parsed_url['host'] . ':' . $parsed_url['port'] . $parsed_url['path']; @@ -156,7 +163,7 @@ public static function runDeamon($_debug = false, $type = 'conso') log::add('teleinfo', 'info', 'Debug : ' . $_debug); log::add('teleinfo', 'info', 'Force : ' . $_force); log::add('teleinfo', 'info', 'Port modem : ' . $port); - log::add('teleinfo', 'info', 'Type : ' . $type); + log::add('teleinfo', 'info', 'Type : ' . $type); log::add('teleinfo', 'info', 'Mode : ' . $mode); $_debug = ($_debug) ? "1" : "0"; $_force = ($_force) ? "1" : "0"; @@ -194,37 +201,48 @@ public static function runDeamon($_debug = false, $type = 'conso') public static function runProductionDeamon($_debug = false, $type = 'prod') { log::add('teleinfo', 'info', '[Production] Mode local'); - $teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources'); - $modemSerieAddr = config::byKey('port_production', 'teleinfo'); + $teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources'); + $modemSerieAddr = config::byKey('port_production', 'teleinfo'); $_debug = config::byKey('debug_production', 'teleinfo'); $_force = config::byKey('force_production', 'teleinfo'); $twoCptCartelectronic = config::byKey('2cpt_cartelectronic_production', 'teleinfo'); - if (config::byKey('modem_vitesse_production', 'teleinfo') == "") { - $modemVitesse = '1200'; - } else { - $modemVitesse = config::byKey('modem_vitesse_production', 'teleinfo'); - } + $linky = config::byKey('linky_prod', 'teleinfo'); + $modemVitesse = config::byKey('modem_vitesse_production', 'teleinfo'); + if ($modemSerieAddr == "serie") { $port = config::byKey('modem_serie_production_addr', 'teleinfo'); - } else { - $port = jeedom::getUsbMapping(config::byKey('port_production', 'teleinfo')); - if ($twoCptCartelectronic == 1) { - $port = '/dev/ttyUSB1'; - } else { - if (!file_exists($port)) { - log::add('teleinfo', 'error', '[Production] Le port n\'existe pas'); - return false; - } - $cle_api = config::byKey('api'); - if ($cle_api == '') { - log::add('teleinfo', 'error', '[Production] Erreur de clé api, veuillez la vérifier.'); - return false; - } - } + } else { + $port = jeedom::getUsbMapping(config::byKey('port_production', 'teleinfo')); + if ($twoCptCartelectronic == 1) { + $port = '/dev/ttyUSB1'; + } else { + if (!file_exists($port)) { + log::add('teleinfo', 'error', '[Production] Le port n\'existe pas'); + return false; + } + $cle_api = config::byKey('api'); + if ($cle_api == '') { + log::add('teleinfo', 'error', '[Production] Erreur de clé api, veuillez la vérifier.'); + return false; + } + } + } + + if ($linky == 1) { + $mode = 'standard'; + if ($modemVitesse == "") { + $modemVitesse = '9600'; + } + } + else { + $mode = 'historique'; + if ($modemVitesse == "") { + $modemVitesse = '1200'; + } } + $parsed_url = parse_url(config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . config::byKey('internalComplement', 'core')); - exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1'); log::add('teleinfo', 'info', '--------- Informations sur le master --------'); log::add('teleinfo', 'info', 'Adresse :' . config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . config::byKey('internalComplement', 'core')); @@ -236,7 +254,7 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') log::add('teleinfo', 'info', 'Force : ' . $_force); log::add('teleinfo', 'info', 'Port modem : ' . $port); log::add('teleinfo', 'info', 'Type : ' . $type); - + log::add('teleinfo', 'info', 'Mode : ' . $mode); $_debug = ($_debug) ? "1" : "0"; $_force = ($_force) ? "1" : "0"; log::add('teleinfo', 'info', '---------------------------------------------'); @@ -248,7 +266,7 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') } else { log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); $teleinfoPath = $teleinfoPath . '/teleinfo.py'; - $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); + $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -m ' . $mode . ' -r ' . realpath(dirname(__FILE__)); } log::add('teleinfo', 'info', '[Production] Exécution du service : ' . $cmd); @@ -308,6 +326,17 @@ public static function deamon_info() shell_exec('sudo rm -rf ' . $pidFile . ' 2>&1 > /dev/null;rm -rf ' . $pidFile . ' 2>&1 > /dev/null;'); } } + $productionActivated = config::byKey('activation_production', 'teleinfo'); + if ($productionActivated == 1) { + $pidFile = '/tmp/teleinfo_prod.pid'; + if (file_exists($pidFile)) { + if (posix_getsid(trim(file_get_contents($pidFile)))) { + $return['state'] = 'ok'; + } else { + shell_exec('sudo rm -rf ' . $pidFile . ' 2>&1 > /dev/null;rm -rf ' . $pidFile . ' 2>&1 > /dev/null;'); + } + } + } $return['launchable'] = 'ok'; return $return; } @@ -351,8 +380,8 @@ public static function deamon_stop() $pid = intval(trim(file_get_contents($pidFile))); $kill = posix_kill($pid, 15); usleep(500); - if (!$kill) { - system::kill($pid); + if (!$kill) { + system::kill($pid); } } } @@ -1071,8 +1100,8 @@ public static function installationOk() } public static function dependancy_install() - { - log::remove(__CLASS__ . '_update'); + { + log::remove(__CLASS__ . '_update'); return array('script' => dirname(__FILE__) . '/../../ressources/install_#stype#.sh ' . jeedom::getTmpFolder('teleinfo') . '/dependance', 'log' => log::getPathToLog(__CLASS__ . '_update')); } diff --git a/core/php/jeeTeleinfo.php b/core/php/jeeTeleinfo.php index d6fd7d1..8b5c1d3 100644 --- a/core/php/jeeTeleinfo.php +++ b/core/php/jeeTeleinfo.php @@ -94,7 +94,9 @@ 'NJOURF' => FILTER_SANITIZE_STRING, 'NJOURF+1' => FILTER_SANITIZE_STRING, 'PJOURF+1' => FILTER_SANITIZE_STRING, - 'PPOINTE' => FILTER_SANITIZE_STRING + 'PPOINTE' => FILTER_SANITIZE_STRING, + 'SINSTI' => FILTER_SANITIZE_STRING, + 'IRMS1' => FILTER_SANITIZE_STRING ); $message = filter_input(INPUT_GET, 'message', FILTER_SANITIZE_STRING); diff --git a/desktop/css/diagnostic.css b/desktop/css/diagnostic.css new file mode 100644 index 0000000..e3776de --- /dev/null +++ b/desktop/css/diagnostic.css @@ -0,0 +1,42 @@ +body { + margin-top:40px; +} +.stepwizard-step p { + margin-top: 10px; +} +.stepwizard-row { + display: table-row; +} +.stepwizard { + display: table; + width: 55%; + position: relative; +} +.stepwizard-step button[disabled] { + opacity: 1 !important; + filter: alpha(opacity=100) !important; +} +.stepwizard-row:before { + top: 14px; + bottom: 0; + position: absolute; + content: " "; + width: 100%; + height: 1px; + background-color: #ccc; + z-order: 0; +} +.stepwizard-step { + display: table-cell; + text-align: center; + position: relative; +} +.stepwizard-btn-circle { + width: 30px; + height: 30px; + text-align: center; + padding: 6px 0; + font-size: 12px; + line-height: 1.428571429; + border-radius: 15px; +} diff --git a/desktop/css/teleinfo.css b/desktop/css/teleinfo.css index b9252fd..d846ed2 100644 --- a/desktop/css/teleinfo.css +++ b/desktop/css/teleinfo.css @@ -9,8 +9,7 @@ and open the template in the editor. */ [type="checkbox"][data-l1key="configuration"]:not(:checked), [type="checkbox"][data-l1key="configuration"]:checked { - position: absolute; - left: -9999px; + display:none; } [type="checkbox"][data-l1key="configuration"]:not(:checked) + label, [type="checkbox"][data-l1key="configuration"]:checked + label { diff --git a/desktop/js/diagnostic.js b/desktop/js/diagnostic.js index e3944d1..559075f 100644 --- a/desktop/js/diagnostic.js +++ b/desktop/js/diagnostic.js @@ -1,39 +1,3 @@ -var etapes = [{"name": "Configuration du plugin", "result": "", "advise": "Vérifier la configuration du plugin"}, - {"name": "Modem connecté", "result": "", "advise": "Vérifier la connexion du modem à Jeedom"}, - {"name": "Accès au Modem", "result": "", "advise": "Vérifier les droits sur le port du Modem"}, - {"name": "Lecture des données", "result": "", "advise": "Vérifier que les cables soient bien connectés; que la téléinformation est bien activée par EDF"}, - {"name": "Intégritée des données", "result": "", "advise": ""}, - {"name": "Package de logs", "result": "", "advise": ""} -]; - -function populate_table(){ - - var tbody = ''; - for(var i in etapes){ - tbody += '