コード例 #1
0
ファイル: sonos3.class.php プロジェクト: eliovir/plugin-sonos
 public static function updateSonos()
 {
     log::remove('sonos_update');
     $cmd = 'sudo /bin/bash ' . dirname(__FILE__) . '/../../ressources/install.sh';
     $cmd .= ' >> ' . log::getPathToLog('sonos_update') . ' 2>&1 &';
     exec($cmd);
 }
コード例 #2
0
 public static function runDeamon()
 {
     if (!file_exists('/opt/homebridge/config.json')) {
         $response = array();
         $platform = array();
         $response['description'] = "Configuration Jeedom";
         $platform['platform'] = "Jeedom";
         $platform['name'] = "Jeedom";
         $platform['jeedom_ip'] = "127.0.0.1";
         $platform['jeedom_port'] = config::byKey('internalPort');
         $platform['jeedom_url'] = config::byKey('internalComplement');
         $platform['jeedom_api_key'] = config::byKey('api');
         $response['platforms'] = array();
         $response['platforms'][] = $platform;
         $response['accessories'] = array();
         $fp = fopen('/opt/homebridge/config.json', 'w');
         fwrite($fp, json_encode($response));
         fclose($fp);
     }
     log::add('homebridge', 'info', 'Lancement du démon homebridge');
     $cmd = 'nice -n 19 /usr/bin/nodejs /opt/homebridge/app.js';
     log::add('homebridge', 'info', 'Lancement démon homebridge : ' . $cmd);
     $result = exec('nohup ' . $cmd . ' >> ' . log::getPathToLog('homebridge') . ' 2>&1 &');
     if (!self::deamonRunning()) {
         sleep(10);
         if (!self::deamonRunning()) {
             log::add('homebridge', 'error', 'Impossible de lancer le démon homebridge', 'unableStartDeamon');
             return false;
         }
     }
     message::removeAll('homebridge', 'unableStartDeamon');
     log::add('homebridge', 'info', 'Démon homebridge lancé');
 }
コード例 #3
0
 public static function runDeamon()
 {
     log::add('rfxcom', 'info', 'Lancement du démon RFXcom');
     $port = config::byKey('port', 'rfxcom');
     if (!file_exists($port)) {
         config::save('port', '', 'rfxcom');
         throw new Exception('Le port : ' . $port . ' n\'éxiste pas');
     }
     $rfxcom_path = realpath(dirname(__FILE__) . '/../../ressources/rfxcmd');
     $trigger = file_get_contents($rfxcom_path . '/trigger_tmpl.xml');
     $config = file_get_contents($rfxcom_path . '/config_tmpl.xml');
     $pid_file = realpath(dirname(__FILE__) . '/../../../../tmp') . '/rfxcom.pid';
     if (file_exists($rfxcom_path . '/trigger.xml')) {
         unlink($rfxcom_path . '/trigger.xml');
     }
     if (file_exists($rfxcom_path . '/config.xml')) {
         unlink($rfxcom_path . '/config.xml');
     }
     file_put_contents($rfxcom_path . '/trigger.xml', str_replace('#path#', $rfxcom_path . '/../../core/php/jeeRfxcom.php', $trigger));
     $config = str_replace('#log_path#', log::getPathToLog('rfxcmd'), str_replace('#trigger_path#', $rfxcom_path . '/trigger.xml', $config));
     file_put_contents($rfxcom_path . '/config.xml', $config);
     chmod($rfxcom_path . '/trigger.xml', 0777);
     chmod($rfxcom_path . '/config.xml', 0777);
     $cmd = '/usr/bin/python ' . $rfxcom_path . '/rfxcmd.py -z -d ' . $port;
     $cmd .= ' -o ' . $rfxcom_path . '/config.xml --pidfile=' . $pid_file;
     log::add('rfxcmd', 'info', 'Lancement démon rfxcmd : ' . $cmd);
     $result = exec('nohup ' . $cmd . ' >> ' . log::getPathToLog('rfxcmd') . ' 2>&1 &');
     if (strpos(strtolower($result), 'error') !== false || strpos(strtolower($result), 'traceback') !== false) {
         log::add('rfxcom', 'error', $result);
         return false;
     }
     if (!self::deamonRunning()) {
         sleep(10);
         if (!self::deamonRunning()) {
             log::add('rfxcom', 'info', 'Impossible de lancer le démon RFXcom');
             return false;
         }
     }
     log::add('rfxcom', 'info', 'Démon RFXcom lancé');
 }
コード例 #4
0
ファイル: alarm.class.php プロジェクト: Wators/jeedom_plugins
 public function launch($_trigger_id, $_value)
 {
     $cmd = 'nohup php ' . dirname(__FILE__) . '/../../core/php/jeeAlarm.php ';
     $cmd .= ' eqLogic_id=' . $this->getId() . ' trigger_id=' . $_trigger_id . ' value=' . $_value;
     $cmd .= ' >> ' . log::getPathToLog('alarm') . ' 2>&1 &';
     shell_exec($cmd);
     return true;
 }
コード例 #5
0
     ajax::success(openzwave::listServerZwave());
 }
 if (init('action') == 'autoDetectModule') {
     $eqLogic = openzwave::byId(init('id'));
     if (!is_object($eqLogic)) {
         throw new Exception(__('Zwave eqLogic non trouvé : ', __FILE__) . init('id'));
     }
     foreach ($eqLogic->getCmd() as $cmd) {
         $cmd->remove();
     }
     $eqLogic->createCommand(true);
     ajax::success();
 }
 if (init('action') == 'migrateZwave') {
     $cmd = 'sudo php ' . dirname(__FILE__) . '/../../script/migrate.php';
     $cmd .= ' >> ' . log::getPathToLog('openzwave_migrate') . ' 2>&1 &';
     exec($cmd);
     ajax::success();
 }
 if (init('action') == 'getAllPossibleConf') {
     $eqLogic = openzwave::byId(init('id'));
     if (!is_object($eqLogic)) {
         ajax::success();
     }
     ajax::success($eqLogic->getConfFilePath(true));
 }
 if (init('action') == 'getConfiguration') {
     if (init('translation') == 1 && config::byKey('language', 'core', 'fr_FR') != 'fr_FR') {
         ajax::success();
     }
     $id = init('manufacturer_id') . '.' . init('product_type') . '.' . init('product_id');
コード例 #6
0
ファイル: scenario.class.php プロジェクト: GaelGRIFFON/core
 public function launch($_force = false, $_trigger = '', $_message = '', $_speedPriority = null)
 {
     if (config::byKey('enableScenario') != 1 || $this->getIsActive() != 1) {
         return false;
     }
     if ($_speedPriority === null) {
         $_speedPriority = $this->getConfiguration('speedPriority', 0);
     }
     if ($_speedPriority == 1) {
         return $this->execute($_trigger, $_message);
     } else {
         $cmd = 'php ' . dirname(__FILE__) . '/../../core/php/jeeScenario.php ';
         $cmd .= ' scenario_id=' . $this->getId();
         $cmd .= ' force=' . $_force;
         $cmd .= ' trigger=' . escapeshellarg($_trigger);
         $cmd .= ' message=' . escapeshellarg($_message);
         $cmd .= ' >> ' . log::getPathToLog('scenario_execution') . ' 2>&1 &';
         exec($cmd);
     }
     return true;
 }
コード例 #7
0
 public function start_openvpn()
 {
     $this->stop_openvpn();
     $this->writeConfig();
     $log_name = 'openvpn_' . str_replace(' ', '_', $this->getName());
     log::remove($log_name);
     $cmd = 'sudo ' . $this->getCmdLine() . ' >> ' . log::getPathToLog($log_name) . '  2>&1 &';
     log::add($log_name, 'info', __('Lancement openvpn : ', __FILE__) . $cmd);
     shell_exec($cmd);
     $this->updateState();
 }
コード例 #8
0
ファイル: jeedom.class.php プロジェクト: GaelGRIFFON/core
 public static function updateSystem()
 {
     if (config::byKey('update::autoSystem') == 1 && jeedom::isCapable('systemUpdate') && jeedom::isCapable('sudo')) {
         $output = array();
         $return_val = -1;
         log::remove('system_update');
         exec('sudo apt-get -y update >> ' . log::getPathToLog('system_update') . ' 2>&1', $output, $return_val);
         if ($return_val != 0) {
             log::add('update', 'error', __('Echec de la mise à jour des dépot, veuillez consulter la log system_update', __FILE__));
             return;
         }
         exec('sudo DEBIAN_FRONTEND=noninteractive apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" dist-upgrade >> ' . log::getPathToLog('system_update') . ' 2>&1', $output, $return_val);
         if ($return_val != 0) {
             log::add('update', 'error', __('Echec de la mise à jour des paquets, veuillez consulter la log system_update', __FILE__));
             return;
         }
         exec('sudo apt-get -y autoremove >> ' . log::getPathToLog('system_update') . ' 2>&1', $output, $return_val);
         if ($return_val != 0) {
             log::add('update', 'error', __('Echec su nettoyage des paquets, veuillez consulter la log system_update', __FILE__));
             return;
         }
         exec('sudo service cron restart');
     }
 }
コード例 #9
0
ファイル: jeedom.class.php プロジェクト: saez0pub/core
 public static function updateSystem()
 {
     log::clear('update');
     $cmd = 'sudo chown wwww-data:www-data ' . dirname(__FILE__) . '/../../install/update_system.sh;';
     $cmd .= 'sudo chmod +x ' . dirname(__FILE__) . '/../../install/update_system.sh;';
     $cmd .= 'sudo ' . dirname(__FILE__) . '/../../install/update_system.sh';
     $cmd .= ' >> ' . log::getPathToLog('update') . ' 2>&1 &';
     exec($cmd);
 }
コード例 #10
0
ファイル: cron.class.php プロジェクト: saez0pub/core
 /**
  * Launch cron (this method must be only call by jeecron master)
  * @throws Exception
  */
 public function run($_noErrorReport = false)
 {
     $cmd = '/usr/bin/php ' . dirname(__FILE__) . '/../php/jeeCron.php';
     $cmd .= ' cron_id=' . $this->getId();
     if (!$this->running()) {
         exec($cmd . ' >> ' . log::getPathToLog('cron_execution') . ' 2>&1 &');
     } else {
         if (!$_noErrorReport) {
             $this->halt();
             if (!$this->running()) {
                 exec($cmd . ' >> /dev/null 2>&1 &');
             } else {
                 throw new Exception(__('Impossible d\'exécuter la tâche car elle est déjà en cours d\'exécution (', __FILE__) . ' : ' . $cmd);
             }
         }
     }
 }
コード例 #11
0
 public static function deamon_start($_debug = false)
 {
     self::deamon_stop();
     $deamon_info = self::deamon_info();
     if ($deamon_info['launchable'] != 'ok') {
         throw new Exception(__('Veuillez vérifier la configuration', __FILE__));
     }
     log::remove('openzwavecmd');
     $port = config::byKey('port', 'openzwave');
     if ($port != 'auto') {
         $port = jeedom::getUsbMapping($port);
     }
     if (config::byKey('jeeNetwork::mode') == 'slave') {
         $serverId = config::byKey('jeeNetwork::slave::id');
         $callback = config::byKey('jeeNetwork::master::ip') . '/plugins/openzwave/core/php/jeeZwave.php';
         $apikey = config::byKey('jeeNetwork::master::apikey');
     } else {
         $serverId = 0;
         $callback = network::getNetworkAccess('internal', 'proto:127.0.0.1:port:comp') . '/plugins/openzwave/core/php/jeeZwave.php';
         $apikey = config::byKey('api');
     }
     $port_server = config::byKey('port_server', 'openzwave', 8083);
     $openzwave_path = dirname(__FILE__) . '/../../ressources/zwaveserver';
     $config_path = dirname(__FILE__) . '/../../ressources/openzwave/config';
     $data_path = dirname(__FILE__) . '/../../data';
     if (!file_exists($data_path)) {
         exec('mkdir ' . $data_path . ' && chmod 775 -R ' . $data_path . ' && chown -R www-data:www-data ' . $data_path);
     }
     $log = $_debug ? 'Debug' : 'Error';
     $cmd = '/usr/bin/python ' . $openzwave_path . '/openZWave.py ';
     $cmd .= ' --pidfile=/tmp/openzwave.pid';
     $cmd .= ' --device=' . $port;
     $cmd .= ' --log=' . $log;
     $cmd .= ' --port=' . $port_server;
     $cmd .= ' --config_folder=' . $config_path;
     $cmd .= ' --data_folder=' . $data_path;
     $cmd .= ' --callback=' . $callback;
     $cmd .= ' --apikey=' . $apikey;
     $cmd .= ' --serverId=' . $serverId;
     log::add('openzwavecmd', 'info', 'Lancement démon openzwave : ' . $cmd);
     $result = exec($cmd . ' >> ' . log::getPathToLog('openzwavecmd') . ' 2>&1 &');
     if (strpos(strtolower($result), 'error') !== false || strpos(strtolower($result), 'traceback') !== false) {
         log::add('openzwavecmd', 'error', $result);
         return false;
     }
     $i = 0;
     while ($i < 30) {
         $deamon_info = self::deamon_info();
         if ($deamon_info['state'] == 'ok') {
             break;
         }
         sleep(1);
         $i++;
     }
     if ($i >= 30) {
         log::add('openzwavecmd', 'error', 'Impossible de lancer le démon openzwave, relancer le démon en debug et vérifiez la log', 'unableStartDeamon');
         return false;
     }
     message::removeAll('openzwave', 'unableStartDeamon');
     log::add('openzwavecmd', 'info', 'Démon openzwave lancé');
 }
コード例 #12
0
 public static function runDeamon()
 {
     log::add('mySensors', 'info', 'Lancement du démon mySensors');
     $modem_serie_addr = config::byKey('usbGateway', 'mySensors');
     if ($modem_serie_addr == "serie") {
         $usbGateway = config::byKey('modem_serie_addr', 'mySensors');
     } else {
         $usbGateway = jeedom::getUsbMapping(config::byKey('usbGateway', 'mySensors'));
     }
     if ($modem_serie_addr == "network") {
         $gateMode = "Network";
         $netAd = explode(":", config::byKey('gateway_addr', 'mySensors'));
         $usbGateway = $netAd[0];
         $gatePort = $netAd[1];
     } else {
         $gateMode = "Serial";
         $gatePort = "";
     }
     if ($usbGateway == '') {
         throw new Exception(__('Le port : ', __FILE__) . $port . __(' n\'éxiste pas', __FILE__));
     }
     if (config::byKey('jeeNetwork::mode') == 'slave') {
         //Je suis l'esclave
         $url = 'http://' . config::byKey('jeeNetwork::master::ip') . '/core/api/jeeApi.php?api=' . config::byKey('jeeNetwork::master::apikey');
     } else {
         if (stripos(config::byKey('internalAddr'), 'jeedom') !== FALSE) {
             //on est pas sur une Mini
             $jeeurl = "http://127.0.0.1/jeedom";
         } else {
             $jeeurl = "http://127.0.0.1";
         }
         $url = $jeeurl . '/core/api/jeeApi.php?api=' . config::byKey('api');
     }
     $sensor_path = realpath(dirname(__FILE__) . '/../../node');
     $cmd = 'nice -n 19 node ' . $sensor_path . '/mysensors.js ' . $url . ' ' . $usbGateway . ' ' . $gateMode . ' ' . $gatePort;
     log::add('mySensors', 'info', 'Lancement démon mySensors : ' . $cmd);
     $result = exec('nohup ' . $cmd . ' >> ' . log::getPathToLog('mySensors') . ' 2>&1 &');
     if (strpos(strtolower($result), 'error') !== false || strpos(strtolower($result), 'traceback') !== false) {
         log::add('mySensors', 'error', $result);
         return false;
     }
     sleep(2);
     if (!self::deamonRunning()) {
         sleep(10);
         if (!self::deamonRunning()) {
             log::add('mySensors', 'error', 'Impossible de lancer le démon mySensors, vérifiez le port', 'unableStartDeamon');
             return false;
         }
     }
     message::removeAll('mySensors', 'unableStartDeamon');
     log::add('mySensors', 'info', 'Démon mySensors lancé');
 }
コード例 #13
0
ファイル: network.class.php プロジェクト: jimibi/core
 public static function dns_start()
 {
     log::add('dns_jeedom', 'debug', 'Redemarrage du service DNS');
     self::dns_stop();
     $cmd = '/usr/bin/nodejs ' . dirname(__FILE__) . '/../../script/localtunnel/bin/client';
     $cmd .= ' --host http://dns.jeedom.fr --port 80 --authentification ' . config::byKey('ngrok::token') . ' --subdomain ' . config::byKey('ngrok::addr');
     exec($cmd . ' >> ' . log::getPathToLog('dns_jeedom') . ' 2>&1 &');
     return true;
 }
コード例 #14
0
ファイル: zwave.class.php プロジェクト: ksoul78/plugin-zwave
 public static function updateZwayServer($_version = '')
 {
     log::remove('zway_update');
     if ($_version != '') {
         $cmd = 'sudo /bin/bash ' . dirname(__FILE__) . '/../../resources/zway_update.sh ' . $_version;
     } else {
         $cmd = 'sudo /bin/bash ' . dirname(__FILE__) . '/../../resources/zway_update.sh';
     }
     $cmd .= ' >> ' . log::getPathToLog('zway_update') . ' 2>&1 &';
     exec($cmd);
 }
コード例 #15
0
ファイル: network.class.php プロジェクト: saez0pub/core
 public static function dns_start()
 {
     if (config::byKey('ngrok::addr') == '') {
         return;
     }
     network::dns_stop();
     $config_file = '/tmp/ngrok_jeedom';
     $logfile = log::getPathToLog('ngrok');
     $uname = posix_uname();
     if (strrpos($uname['machine'], 'arm') !== false) {
         $cmd = dirname(__FILE__) . '/../../script/ngrok/ngrok-arm';
     } else {
         if ($uname['machine'] == 'x86_64') {
             $cmd = dirname(__FILE__) . '/../../script/ngrok/ngrok-x64';
         } else {
             $cmd = dirname(__FILE__) . '/../../script/ngrok/ngrok-x86';
         }
     }
     exec('chmod +x ' . $cmd);
     $cmd .= ' -config=' . $config_file . ' start jeedom';
     if (!self::dns_run()) {
         $replace = array('#server_addr#' => 'dns.jeedom.com:4443', '#name#' => 'jeedom', '#proto#' => 'https', '#port#' => 80, '#remote_port#' => '', '#token#' => config::byKey('ngrok::token'), '#auth#' => '', '#subdomain#' => 'subdomain : ' . config::byKey('ngrok::addr'));
         $config = template_replace($replace, file_get_contents(dirname(__FILE__) . '/../../script/ngrok/config'));
         if (file_exists($config_file)) {
             unlink($config_file);
         }
         file_put_contents($config_file, $config);
         log::remove('ngrok');
         log::add('ngork', 'debug', 'Lancement de ngork : ' . $cmd);
         exec($cmd . ' >> /dev/null 2>&1 &');
     }
     return true;
 }
コード例 #16
0
 public static function updateporkfolio()
 {
     log::remove('porkfolio_update');
     $clientid = config::byKey('clientid', 'porkfolio', 0);
     $clientsecret = config::byKey('clientsecret', 'porkfolio', 0);
     $username = config::byKey('username', 'porkfolio', 0);
     $password = config::byKey('password', 'porkfolio', 0);
     $cmd = '/usr/bin/python ' . dirname(__FILE__) . '/../../3rdparty/py-wink-adapt/login.py ' . $clientid . ' ' . $clientsecret . ' ' . $username . ' ' . $password;
     $cmd .= ' >> ' . log::getPathToLog('porkfolio_update') . ' 2>&1 &';
     exec($cmd);
 }
コード例 #17
0
 public function execute(&$_scenario)
 {
     if ($this->getType() == 'if') {
         if ($this->getSubElement('if')->execute($_scenario)) {
             if ($this->getSubElement('if')->getOptions('allowRepeatCondition', 0) == 1) {
                 if ($this->getSubElement('if')->getOptions('previousState', -1) != 1) {
                     $this->getSubElement('if')->setOptions('previousState', 1);
                     $this->getSubElement('if')->save();
                 } else {
                     $_scenario->setLog(__('Non exécution des actions pour cause de répétition', __FILE__));
                     return;
                 }
             }
             return $this->getSubElement('then')->execute($_scenario);
         }
         if (!is_object($this->getSubElement('else'))) {
             return;
         }
         if ($this->getSubElement('if')->getOptions('allowRepeatCondition', 0) == 1) {
             if ($this->getSubElement('if')->getOptions('previousState', -1) != 0) {
                 $this->getSubElement('if')->setOptions('previousState', 0);
                 $this->getSubElement('if')->save();
             } else {
                 $_scenario->setLog(__('Non exécution des actions pour cause de répétition', __FILE__));
                 return;
             }
         }
         return $this->getSubElement('else')->execute($_scenario);
     } else {
         if ($this->getType() == 'action') {
             return $this->getSubElement('action')->execute($_scenario);
         } else {
             if ($this->getType() == 'code') {
                 return $this->getSubElement('code')->execute($_scenario);
             } else {
                 if ($this->getType() == 'for') {
                     $for = $this->getSubElement('for');
                     $limits = $for->getExpression();
                     $limits = intval(jeedom::evaluateExpression($limits[0]->getExpression()));
                     if (!is_numeric($limits)) {
                         $_scenario->setLog(__('[ERREUR] La condition pour une boucle doit être numérique : ', __FILE__) . $limits);
                         throw new Exception(__('La condition pour une boucle doit être numérique : ', __FILE__) . $limits);
                     }
                     $return = false;
                     for ($i = 1; $i <= $limits; $i++) {
                         $return = $this->getSubElement('do')->execute($_scenario);
                     }
                     return $return;
                 } else {
                     if ($this->getType() == 'in') {
                         $in = $this->getSubElement('in');
                         $in = $in->getExpression();
                         $time = ceil(str_replace('.', ',', jeedom::evaluateExpression($in[0]->getExpression())));
                         if (!is_numeric($time) || $time < 0) {
                             $time = 0;
                         }
                         if ($time == 0) {
                             $cmd = '/usr/bin/php ' . dirname(__FILE__) . '/../../core/php/jeeScenario.php ';
                             $cmd .= ' scenario_id=' . $_scenario->getId();
                             $cmd .= ' scenarioElement_id=' . $this->getId();
                             $cmd .= ' >> ' . log::getPathToLog('scenario_element_execution') . ' 2>&1 &';
                             exec($cmd);
                         } else {
                             $crons = cron::searchClassAndFunction('scenario', 'doIn', '"scenarioElement_id":' . $this->getId());
                             if (is_array($crons)) {
                                 foreach ($crons as $cron) {
                                     if ($cron->getState() != 'run') {
                                         $cron->remove();
                                     }
                                 }
                             }
                             $cron = new cron();
                             $cron->setClass('scenario');
                             $cron->setFunction('doIn');
                             $cron->setOption(array('scenario_id' => intval($_scenario->getId()), 'scenarioElement_id' => intval($this->getId()), 'second' => date('s')));
                             $cron->setLastRun(date('Y-m-d H:i:s'));
                             $cron->setOnce(1);
                             $next = strtotime('+ ' . $time . ' min');
                             $cron->setSchedule(date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next));
                             $cron->save();
                             $_scenario->setLog(__('Tâche : ', __FILE__) . $this->getId() . __(' programmé à : ', __FILE__) . date('Y-m-d H:i:00', $next) . ' (+ ' . $time . ' min)');
                         }
                         return true;
                     } else {
                         if ($this->getType() == 'at') {
                             $at = $this->getSubElement('at');
                             $at = $at->getExpression();
                             $next = jeedom::evaluateExpression($at[0]->getExpression());
                             if ($next % 100 > 59) {
                                 if (strpos($at[0]->getExpression(), '-') !== false) {
                                     $next -= 40;
                                 } else {
                                     $next += 40;
                                 }
                             }
                             if (!is_numeric($next) || $next < 0) {
                                 $_scenario->setLog(__('Erreur dans bloc (type A) : ', __FILE__) . $this->getId() . __(', heure programmée invalide : ', __FILE__) . $next);
                             }
                             if ($next < date('Gi') + 1) {
                                 if (strlen($next) == 3) {
                                     $next = date('Y-m-d', strtotime('+1 day' . date('Y-m-d'))) . ' 0' . substr($next, 0, 1) . ':' . substr($next, 1, 3);
                                 } else {
                                     $next = date('Y-m-d', strtotime('+1 day' . date('Y-m-d'))) . ' ' . substr($next, 0, 2) . ':' . substr($next, 2, 4);
                                 }
                             } else {
                                 if (strlen($next) == 3) {
                                     $next = date('Y-m-d') . ' 0' . substr($next, 0, 1) . ':' . substr($next, 1, 3);
                                 } else {
                                     $next = date('Y-m-d') . ' ' . substr($next, 0, 2) . ':' . substr($next, 2, 4);
                                 }
                             }
                             $next = strtotime($next);
                             $crons = cron::searchClassAndFunction('scenario', 'doIn', '"scenarioElement_id":' . $this->getId());
                             if (is_array($crons)) {
                                 foreach ($crons as $cron) {
                                     if ($cron->getState() != 'run') {
                                         $cron->remove();
                                     }
                                 }
                             }
                             $cron = new cron();
                             $cron->setClass('scenario');
                             $cron->setFunction('doIn');
                             $cron->setOption(array('scenario_id' => intval($_scenario->getId()), 'scenarioElement_id' => intval($this->getId()), 'second' => 0));
                             $cron->setLastRun(date('Y-m-d H:i:s'));
                             $cron->setOnce(1);
                             $cron->setSchedule(date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next));
                             $cron->save();
                             $_scenario->setLog(__('Tâche : ', __FILE__) . $this->getId() . __(' programmée à : ', __FILE__) . date('Y-m-d H:i:00', $next));
                             return true;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #18
0
 public static function runDeamon($_debug = false)
 {
     if (config::byKey('allowStartDeamon', 'openzwave', 1) == 0) {
         return;
     }
     try {
         self::stop();
         self::stopDeamon();
     } catch (Exception $e) {
     }
     log::add('openzwave', 'info', 'Lancement du démon openzwave');
     $port = config::byKey('port', 'openzwave');
     if ($port != 'auto') {
         $port = jeedom::getUsbMapping($port, true);
         if (@(!file_exists($port))) {
             throw new Exception(__('Le port : ', __FILE__) . print_r($port, true) . __(' n\'existe pas', __FILE__));
         }
         exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1');
     }
     if (config::byKey('jeeNetwork::mode') == 'slave') {
         $serverId = config::byKey('jeeNetwork::slave::id');
         $callback = config::byKey('jeeNetwork::master::ip') . '/plugins/openzwave/core/php/jeeZwave.php';
         $apikey = config::byKey('jeeNetwork::master::apikey');
     } else {
         $serverId = 0;
         $callback = network::getNetworkAccess('internal', 'proto:127.0.0.1:port:comp') . '/plugins/openzwave/core/php/jeeZwave.php';
         $apikey = config::byKey('api');
     }
     $port_server = config::byKey('port_server', 'openzwave', 8083);
     $openzwave_path = dirname(__FILE__) . '/../../ressources/zwaveserver';
     $config_path = dirname(__FILE__) . '/../../ressources/openzwave/config';
     $data_path = dirname(__FILE__) . '/../../data';
     if (!file_exists($data_path)) {
         exec('mkdir ' . $data_path . ' && chmod 775 -R ' . $data_path . ' && chown -R www-data:www-data ' . $data_path);
     }
     $log = $_debug ? 'Debug' : 'Error';
     $cmd = '/usr/bin/python ' . $openzwave_path . '/openZWave.py ';
     $cmd .= ' --pidfile=/tmp/openzwave.pid';
     $cmd .= ' --device=' . $port;
     $cmd .= ' --log=' . $log;
     $cmd .= ' --port=' . $port_server;
     $cmd .= ' --config_folder=' . $config_path;
     $cmd .= ' --data_folder=' . $data_path;
     $cmd .= ' --callback=' . $callback;
     $cmd .= ' --apikey=' . $apikey;
     $cmd .= ' --serverId=' . $serverId;
     log::add('openzwave', 'info', 'Lancement démon openzwave : ' . $cmd);
     $result = exec($cmd . ' >> ' . log::getPathToLog('openzwave') . ' 2>&1 &');
     if (strpos(strtolower($result), 'error') !== false || strpos(strtolower($result), 'traceback') !== false) {
         log::add('openzwave', 'error', $result);
         return false;
     }
     $i = 0;
     while ($i < 30) {
         if (self::deamonRunning()) {
             break;
         }
         sleep(1);
         $i++;
     }
     if ($i >= 10) {
         log::add('openzwave', 'error', 'Impossible de lancer le démon openzwave, vérifiez le port', 'unableStartDeamon');
         return false;
     }
     message::removeAll('openzwave', 'unableStartDeamon');
     log::add('openzwave', 'info', 'Démon openzwave lancé');
 }
コード例 #19
0
 public static function runDeamon($_debug = false)
 {
     if (config::byKey('allowStartDeamon', 'openzwave', 1) == 0) {
         return;
     }
     try {
         self::stopDeamon();
     } catch (Exception $e) {
     }
     log::add('openzwave', 'info', 'Lancement du démon openzwave');
     $port = config::byKey('port', 'openzwave');
     if ($port != 'auto') {
         $port = jeedom::getUsbMapping($port, true);
         if (@(!file_exists($port))) {
             throw new Exception(__('Le port : ', __FILE__) . print_r($port, true) . __(' n\'existe pas', __FILE__));
         }
         exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1');
     }
     $port_server = config::byKey('port_server', 'openzwave', 8083);
     $openzwave_path = realpath(dirname(__FILE__) . '/../../ressources/zwaveserver');
     $config_path = realpath(dirname(__FILE__) . '/../../ressources/openzwave/config');
     $log = $_debug ? 'Debug' : 'Info';
     $cmd = '/usr/bin/python ' . $openzwave_path . '/openZWave.py --pidfile=/tmp/openzwave.pid --device=' . $port . ' --log=' . $log . ' --port=' . $port_server . ' --config=' . $config_path;
     log::add('openzwave', 'info', 'Lancement démon openzwave : ' . $cmd);
     $result = exec($cmd . ' >> ' . log::getPathToLog('openzwave') . ' 2>&1 &');
     if (strpos(strtolower($result), 'error') !== false || strpos(strtolower($result), 'traceback') !== false) {
         log::add('openzwave', 'error', $result);
         return false;
     }
     $i = 0;
     while ($i < 30) {
         if (self::deamonRunning()) {
             break;
         }
         sleep(1);
         $i++;
     }
     if ($i >= 30) {
         log::add('openzwave', 'error', 'Impossible de lancer le démon openzwave, vérifiez le port', 'unableStartDeamon');
         return false;
     }
     message::removeAll('openzwave', 'unableStartDeamon');
     log::add('openzwave', 'info', 'Démon openzwave lancé');
 }
コード例 #20
0
ファイル: arduidom.class.php プロジェクト: bobox59/arduidom
 public static function FlashArduino($_AID = '')
 {
     $result = 0;
     log::add('arduidom', 'info', "Téléversement de l'arduino " . $_AID . '...');
     self::set_daemon_mode("FLASHING");
     self::deamon_stop();
     sleep(1);
     if (!file_exists("/usr/bin/avrdude")) {
         self::set_daemon_mode("KILLED");
         throw new Exception(__("le programme avrdude n'est pas installé ! (installer avec apt-get install avrdude)", __FILE__));
     }
     $daemon_path = realpath(dirname(__FILE__) . '/../../ressources');
     $model = config::byKey('A' . $_AID . '_model', 'arduidom', 'none');
     $port = config::byKey('A' . $_AID . '_port', 'arduidom', 'none');
     switch ($model) {
         case "uno":
             $cmd_model = "-patmega328p -carduino";
             $cmd_speed = "115200";
             $cmd_hexfile = "uno";
             break;
         case "duemilanove328":
             $cmd_model = "-patmega328p -carduino";
             $cmd_speed = "57600";
             $cmd_hexfile = "duemilanove328";
             break;
         case "nano328":
             $cmd_model = "-patmega328p -carduino";
             $cmd_speed = "57600";
             $cmd_hexfile = "nano328";
             break;
         case "mega2560":
             $cmd_model = "-patmega2560 -cwiring";
             $cmd_speed = "115200";
             $cmd_hexfile = "mega2560";
             break;
         case "mega1280":
             $cmd_model = "-patmega1280 -cwiring";
             $cmd_speed = "57600";
             $cmd_hexfile = "mega1280";
             break;
         default:
             self::set_daemon_mode("KILLED");
             throw new Exception(__("Modele Arduino " . $model . " n'est pas supporté par la fonction !", __FILE__));
             break;
     }
     $logfile = "/tmp/avrdude.log";
     if (file_exists($logfile)) {
         unlink($logfile);
     }
     $cmd = 'sudo /usr/bin/avrdude -C/etc/avrdude.conf -v -v -v -l ' . $logfile . ' ' . $cmd_model . ' -P' . $port . ' -b' . $cmd_speed . ' -D -Uflash:w:' . $daemon_path . '/' . $cmd_hexfile . '.hex:i';
     $cmd .= ' >> ' . log::getPathToLog("arduidom") . ' 2>&1';
     log::add('arduidom', 'info', 'Execution du téléversement: ' . $cmd);
     $result = exec($cmd);
     sleep(2);
     log::add('arduidom', 'info', '# Fin du téléversement (' . $result . ')');
     self::set_daemon_mode("KILLED");
     if (strpos(file_get_contents($logfile), "bytes of flash written") !== false) {
         if (strpos(file_get_contents($logfile), "bytes of flash verified") !== false) {
             if (strpos(file_get_contents($logfile), "avrdude done.") !== false) {
                 return "OK";
                 // do stuff
             }
         }
     }
     return $result;
 }