Ejemplo n.º 1
0
function sonos3_update()
{
    $cron = cron::byClassAndFunction('sonos3', 'pull');
    if (!is_object($cron)) {
        $cron = new cron();
    }
    $cron->setClass('sonos3');
    $cron->setFunction('pull');
    $cron->setEnable(1);
    $cron->setDeamon(1);
    $cron->setDeamonSleepTime(5);
    $cron->setTimeout(1440);
    $cron->setSchedule('* * * * *');
    $cron->save();
    $cron->stop();
    foreach (sonos3::byType('sonos3') as $sonos) {
        $sonos->save();
    }
    $files = array('24 LED Bright.ttf', '24 LED Grid.ttf', '24 LED Modul.ttf', '24 LED.ttf', 'advanced_dot_digital-7.ttf', 'AHDN.ttf', 'alpha04.ttf', 'CUBS LED TFB.ttf', 'enhanced_led_board-7.ttf', 'led_counter-7.ttf', 'liquid_crystal_display.ttf', 'liquid.ttf');
    foreach ($files as $file) {
        $path = dirname(__FILE__) . '/../core/template/fonts/' . $file;
        if (file_exists($path)) {
            unlink($path);
        }
    }
}
Ejemplo n.º 2
0
function openzwave_update()
{
    if (openzwave::deamonRunning()) {
        echo 'Stop zwave network...';
        openzwave::stopDeamon();
        echo "OK\n";
    }
    echo 'Stop cron...';
    $cron = cron::byClassAndFunction('openzwave', 'pull');
    if (config::byKey('jeeNetwork::mode') != 'slave') {
        if (!is_object($cron)) {
            $cron = new cron();
        }
        $cron->setClass('openzwave');
        $cron->setFunction('pull');
        $cron->setEnable(1);
        $cron->setDeamon(1);
        $cron->setDeamonSleepTime(0.5);
        $cron->setTimeout(1440);
        $cron->setSchedule('* * * * *');
        $cron->save();
        $cron->stop();
    } else {
        if (is_object($cron)) {
            $cron->remove();
        }
    }
    echo "OK\n";
    echo 'Check zwave system...';
    if (count(eqLogic::byType('zwave')) > 0) {
        log::add('openzwave', 'error', 'Attention vous etes sur la nouvelle version d\'openzwave, des actions de votre part sont necessaire merci d\'aller voir https://jeedom.fr/blog/?p=1576');
    }
    if (config::byKey('port', 'openzwave', 'none') != 'none') {
        if (method_exists('openzwave', 'getVersion')) {
            if (version_compare(config::byKey('openzwave_version', 'openzwave'), openzwave::getVersion('openzwave'), '>')) {
                if (jeedom::getHardwareName() == 'Jeedomboard') {
                    config::save('allowStartDeamon', 0, 'openzwave');
                    openzwave::updateOpenzwave(false);
                    config::save('allowStartDeamon', 1, 'openzwave');
                } else {
                    log::add('openzwave', 'error', __('Attention votre version d\'openzwave est dépassée sur le démon local, il faut ABSOLUMENT la mettre à jour', __FILE__));
                }
            }
        }
    }
    if (config::byKey('jeeNetwork::mode') == 'master') {
        foreach (jeeNetwork::byPlugin('openzwave') as $jeeNetwork) {
            try {
                if ($jeeNetwork->configByKey('port', 'openzwave', 'none') != 'none') {
                    if (version_compare($jeeNetwork->sendRawRequest('getVersion', array('plugin' => 'openzwave', 'module' => 'openzwave')), openzwave::getVersion('openzwave'), '>')) {
                        log::add('openzwave', 'error', __('Attention votre version d\'openzwave est dépassée sur', __FILE__) . ' ' . $jeeNetwork->getName() . ' ' . __('il faut ABSOLUMENT la mettre à jour', __FILE__));
                    }
                }
            } catch (Exception $e) {
            }
        }
    }
    echo "OK\n";
}
Ejemplo n.º 3
0
function install()
{
    $cron = cron::byClassAndFunction('alarm', 'pull');
    if (!is_object($cron)) {
        $cron = new cron();
    }
    $cron->setClass('alarm');
    $cron->setFunction('pull');
    $cron->setEnable(1);
    $cron->setDeamon(1);
    $cron->setSchedule('* * * * *');
    $cron->save();
}
Ejemplo n.º 4
0
function ewattch_update()
{
    $cron = cron::byClassAndFunction('ewattch', 'pull');
    if (!is_object($cron)) {
        $cron = new cron();
        $cron->setClass('ewattch');
        $cron->setFunction('pull');
        $cron->setEnable(1);
        $cron->setSchedule('*/20 * * * *');
        $cron->save();
    }
    $cron->stop();
}
Ejemplo n.º 5
0
function tesla_update()
{
    $cron = cron::byClassAndFunction('tesla', 'pull');
    if (!is_object($cron)) {
        $cron = new cron();
        $cron->setClass('tesla');
        $cron->setFunction('pull');
        $cron->setEnable(1);
        $cron->setDeamon(0);
        $cron->setSchedule('* * * * *');
        $cron->save();
    }
    $cron->stop();
}
Ejemplo n.º 6
0
function install()
{
    $cron = cron::byId(config::byKey('xPLDeamonCronId', 'xPL'));
    if (!is_object($cron)) {
        $cron = new cron();
    }
    $cron->setClass('xpl');
    $cron->setFunction('deamon');
    $cron->setEnable(1);
    $cron->setDeamon(1);
    $cron->setSchedule('* * * * *');
    $cron->save();
    config::save('xPLDeamonCronId', $cron->getId(), 'xPL');
}
Ejemplo n.º 7
0
function xpl_update()
{
    $cron = cron::byClassAndFunction('xpl', 'deamon');
    if (!is_object($cron)) {
        $cron = new cron();
        $cron->setClass('xpl');
        $cron->setFunction('deamon');
        $cron->setEnable(1);
        $cron->setDeamon(1);
        $cron->setSchedule('* * * * *');
        $cron->save();
    }
    $cron->stop();
}
Ejemplo n.º 8
0
function domogeek_update()
{
    $cron = cron::byClassAndFunction('domogeek', 'pull');
    if (!is_object($cron)) {
        $cron = new cron();
        $cron->setClass('domogeek');
        $cron->setFunction('pull');
        $cron->setEnable(1);
        $cron->setDeamon(0);
        $cron->setSchedule('0 */2 * * *');
        $cron->save();
    }
    $cron->stop();
}
Ejemplo n.º 9
0
function mySensors_update()
{
    $cron = cron::byClassAndFunction('mySensors', 'pull');
    if (!is_object($cron)) {
        $cron = new cron();
        $cron->setClass('mySensors');
        $cron->setFunction('pull');
        $cron->setEnable(1);
        $cron->setDeamon(0);
        $cron->setSchedule('*/15 * * * *');
        $cron->save();
    }
    if (method_exists('mySensors', 'stopDeamon')) {
        mySensors::stopDeamon();
    }
    $cron->stop();
}
Ejemplo n.º 10
0
function install()
{
    $cron = cron::byClassAndFunction('zwave', 'pull');
    if (!is_object($cron)) {
        $cron = new cron();
    }
    $cron->setClass('zwave');
    $cron->setFunction('pull');
    $cron->setEnable(1);
    $cron->setDeamon(1);
    $cron->setSchedule('* * * * *');
    $cron->save();
    $cibDir = dirname(__FILE__) . '/../ressources';
    if (file_exists($cibDir)) {
        rrmdir($cibDir);
    }
}
Ejemplo n.º 11
0
function zwave_update()
{
    $cron = cron::byClassAndFunction('zwave', 'pull');
    if (config::byKey('jeeNetwork::mode') != 'slave') {
        if (!is_object($cron)) {
            $cron = new cron();
        }
        $cron->setClass('zwave');
        $cron->setFunction('pull');
        $cron->setEnable(1);
        $cron->setDeamon(1);
        $cron->setTimeout(1440);
        $cron->setSchedule('* * * * *');
        $cron->save();
        $cron->stop();
    } else {
        if (is_object($cron)) {
            $cron->remove();
        }
    }
    foreach (zwave::byType('zwave') as $zwave) {
        if ($zwave->getConfiguration('serverID') == '') {
            $zwave->setConfiguration('serverID', 1);
        }
        $zwave->save();
    }
    config::save('zwaveAddr1', config::byKey('zwaveAddr1', 'zwave', config::byKey('zwaveAddr', 'zwave')), 'zwave');
    config::save('zwavePort1', config::byKey('zwavePort1', 'zwave', config::byKey('zwavePort', 'zwave')), 'zwave');
    config::save('isOpenZwave1', config::byKey('isOpenZwave1', 'zwave', config::byKey('isOpenZwave', 'zwave')), 'zwave');
    if (method_exists('zwave', 'listServerZway')) {
        foreach (zwave::listServerZway() as $serverID => $server) {
            if (config::byKey('lastNotificationCheck' . $serverID, 'zwave', 0) == 0) {
                config::save('lastNotificationCheck' . $serverID, strtotime('now'), 'zwave');
            }
        }
    }
}
Ejemplo n.º 12
0
function arduidom_update()
{
    arduidom::stopdaemon();
    $MigrationCheck = config::byKey('db_version', 'arduidom', 0);
    if ($MigrationCheck < 108) {
        arduidom::MigrateDatas();
        arduidom::start();
    }
    if ($MigrationCheck < 145) {
        arduidom::stopdaemon();
        $daemon_path = realpath(dirname(__FILE__) . '/../../ressources');
        log::add('arduidom', 'info', "Suppression de arduidom1.py devenu inutile => " . unlink($daemon_path . "/arduidom1.py"));
        log::add('arduidom', 'info', "Suppression de arduidom2.py devenu inutile => " . unlink($daemon_path . "/arduidom2.py"));
        log::add('arduidom', 'info', "Suppression de arduidom3.py devenu inutile => " . unlink($daemon_path . "/arduidom3.py"));
        log::add('arduidom', 'info', "Suppression de arduidom4.py devenu inutile => " . unlink($daemon_path . "/arduidom4.py"));
        log::add('arduidom', 'info', "Suppression de arduidom5.py devenu inutile => " . unlink($daemon_path . "/arduidom5.py"));
        log::add('arduidom', 'info', "Suppression de arduidom6.py devenu inutile => " . unlink($daemon_path . "/arduidom6.py"));
        log::add('arduidom', 'info', "Suppression de arduidom7.py devenu inutile => " . unlink($daemon_path . "/arduidom7.py"));
        log::add('arduidom', 'info', "Suppression de arduidom8.py devenu inutile => " . unlink($daemon_path . "/arduidom8.py"));
        config::save('db_version', 145, 'arduidom');
        // Inscrit la version de migration dans la config
        arduidom::start();
    }
    arduidom::startdaemon();
    $cron = cron::byClassAndFunction('arduidom', 'checkdaemon');
    if (!is_object($cron)) {
        $cron = new cron();
        $cron->setClass('arduidom');
        $cron->setFunction('checkdaemon');
        $cron->setEnable(1);
        $cron->setDeamon(0);
        $cron->setSchedule('* * * * *');
        $cron->save();
    }
    $cron->stop();
    @exec("sudo usermod -G dialout www-data");
}
Ejemplo n.º 13
0
 }
 $cron->setClass('plugin');
 $cron->setFunction('cron15');
 $cron->setSchedule('*/15 * * * * *');
 $cron->setTimeout(60);
 $cron->save();
 $cron = cron::byClassAndFunction('plugin', 'cron30');
 if (!is_object($cron)) {
     echo "Création de plugin::cron30\n";
     $cron = new cron();
 }
 $cron->setClass('plugin');
 $cron->setFunction('cron30');
 $cron->setSchedule('*/30 * * * * *');
 $cron->setTimeout(60);
 $cron->save();
 $dynamic_apache_path = dirname(__FILE__) . '/../core/config/apache_jeedom_dynamic_rules';
 if (!file_exists($dynamic_apache_path)) {
     touch($dynamic_apache_path);
 }
 if (jeedom::isCapable('sudo')) {
     if (!file_exists('/var/log/auth.log')) {
         exec('sudo touch /var/log/auth.log');
         exec('sudo service fail2ban restart');
     }
     exec('sudo service cron restart');
 }
 cache::deleteBySearch('widgetHtml');
 cache::deleteBySearch('cmdWidgetdashboard');
 cache::deleteBySearch('cmdWidgetmobile');
 cache::deleteBySearch('scenarioHtmldashboard');
Ejemplo n.º 14
0
 public function executeAndReply($_parameters)
 {
     $interactDef = interactDef::byId($this->getInteractDef_id());
     if (!is_object($interactDef)) {
         return __('Inconsistance de la base de données', __FILE__);
     }
     if (isset($_parameters['profile']) && trim($interactDef->getPerson()) != '') {
         $person = strtolower($interactDef->getPerson());
         $person = explode('|', $person);
         if (!in_array($_parameters['profile'], $person)) {
             return __('Vous n\'êtes pas autorisé à exécuter cette action', __FILE__);
         }
     }
     $reply = $interactDef->selectReply();
     $replace = array();
     $tags = interactDef::getTagFromQuery($this->getQuery(), $_parameters['dictation']);
     $tags_replace = array();
     foreach ($tags as $key => $value) {
         $tags_replace['#' . $key . '#'] = $value;
         $replace['#' . $key . '#'] = $value;
     }
     $executeDate = null;
     $dateConvert = array('heure' => 'hour', 'mois' => 'month', 'semaine' => 'week', 'année' => 'year');
     if (isset($tags_replace['#duration#'])) {
         $tags_replace['#duration#'] = str_replace(array_keys($dateConvert), $dateConvert, $tags_replace['#duration#']);
         $executeDate = strtotime('+' . $tags_replace['#duration#']);
     }
     if (isset($tags_replace['#time#'])) {
         $time = str_replace(array('h'), array(':'), $tags_replace['#time#']);
         if (strlen($time) == 2) {
             $time .= ':00';
         } else {
             if (strlen($time) == 3) {
                 $time .= '00';
             }
         }
         $executeDate = strtotime($time);
         if ($executeDate < strtotime('now')) {
             $executeDate += 3600;
         }
     }
     if ($executeDate !== null && !isset($_parameters['execNow'])) {
         if (date('Y', $executeDate) < 2000) {
             return __('Erreur impossible de calculer la date de programmation', __FILE__);
         }
         if ($executeDate < strtotime('now') + 60) {
             $executeDate = strtotime('now') + 60;
         }
         $crons = cron::searchClassAndFunction('interactQuery', 'doIn', '"interactQuery_id":' . $this->getId());
         if (is_array($crons)) {
             foreach ($crons as $cron) {
                 if ($cron->getState() != 'run') {
                     $cron->remove();
                 }
             }
         }
         $cron = new cron();
         $cron->setClass('interactQuery');
         $cron->setFunction('doIn');
         $cron->setOption(array_merge(array('interactQuery_id' => intval($this->getId())), $_parameters));
         $cron->setLastRun(date('Y-m-d H:i:s'));
         $cron->setOnce(1);
         $cron->setSchedule(date('i', $executeDate) . ' ' . date('H', $executeDate) . ' ' . date('d', $executeDate) . ' ' . date('m', $executeDate) . ' * ' . date('Y', $executeDate));
         $cron->save();
         $replace['#value#'] = date('Y-m-d H:i:s', $executeDate);
         $result = scenarioExpression::setTags(str_replace(array_keys($replace), $replace, $reply));
         return $result;
     }
     $colors = config::byKey('convertColor');
     foreach ($this->getActions('cmd') as $action) {
         try {
             $options = array();
             if (isset($action['options'])) {
                 $options = $action['options'];
             }
             if ($tags != null) {
                 foreach ($options as &$option) {
                     $option = str_replace(array_keys($tags_replace), $tags_replace, $option);
                 }
                 if (isset($options['color']) && isset($colors[strtolower($options['color'])])) {
                     $options['color'] = $colors[strtolower($options['color'])];
                 }
             }
             $cmd = cmd::byId(str_replace('#', '', $action['cmd']));
             if (is_object($cmd) && $cmd->getType() == 'info') {
                 $replace['#unite#'] = $cmd->getUnite();
                 $replace['#commande#'] = $cmd->getName();
                 $replace['#objet#'] = '';
                 $replace['#equipement#'] = '';
                 $eqLogic = $cmd->getEqLogic();
                 if (is_object($eqLogic)) {
                     $replace['#equipement#'] = $eqLogic->getName();
                     $object = $eqLogic->getObject();
                     if (is_object($object)) {
                         $replace['#objet#'] = $object->getName();
                     }
                 }
             }
             $options['tags'] = $tags_replace;
             $return = scenarioExpression::createAndExec('action', $action['cmd'], $options);
             if (trim($return) != '') {
                 $replace['#valeur#'] = $return;
             }
         } catch (Exception $e) {
             log::add('interact', 'error', __('Erreur lors de l\'éxecution de ', __FILE__) . $action['cmd'] . __('. Détails : ', __FILE__) . $e->getMessage());
         }
     }
     $replace['#profile#'] = isset($_parameters['profile']) ? $_parameters['profile'] : '';
     if ($interactDef->getOptions('convertBinary') != '') {
         $convertBinary = $interactDef->getOptions('convertBinary');
         $convertBinary = explode('|', $convertBinary);
         $replace['1'] = $convertBinary[1];
         $replace['0'] = $convertBinary[0];
     }
     $result = scenarioExpression::setTags(str_replace(array_keys($replace), $replace, $reply));
     return $result;
 }
Ejemplo n.º 15
0
 public function checkCmdAlert($_value)
 {
     if ($this->getConfiguration('jeedomCheckCmdOperator') == '' || $this->getConfiguration('jeedomCheckCmdTest') == '' || $this->getConfiguration('jeedomCheckCmdTime') == '' || is_nan($this->getConfiguration('jeedomCheckCmdTime'))) {
         return;
     }
     $check = jeedom::evaluateExpression($_value . $this->getConfiguration('jeedomCheckCmdOperator') . $this->getConfiguration('jeedomCheckCmdTest'));
     if ($check == 1 || $check || $check == '1') {
         if ($this->getConfiguration('jeedomCheckCmdTime') == 0) {
             $this->executeAlertCmdAction();
             return;
         }
         $cron = cron::byClassAndFunction('cmd', 'cmdAlert', array('cmd_id' => intval($this->getId())));
         if (!is_object($cron)) {
             $cron = new cron();
         }
         $cron->setClass('cmd');
         $cron->setFunction('cmdAlert');
         $cron->setOnce(1);
         $cron->setOption(array('cmd_id' => intval($this->getId())));
         $next = strtotime('+ ' . ($this->getConfiguration('jeedomCheckCmdTime') + 1) . ' minutes ' . date('Y-m-d H:i:s'));
         $schedule = date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next);
         $cron->setSchedule($schedule);
         $cron->setLastRun(date('Y-m-d H:i:s'));
         $cron->save();
     } else {
         $cron = cron::byClassAndFunction('cmd', 'cmdAlert', array('cmd_id' => intval($this->getId())));
         if (is_object($cron)) {
             $cron->remove();
         }
     }
 }
Ejemplo n.º 16
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;
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
 public static function changeMode($_mode)
 {
     switch ($_mode) {
         case 'master':
             if (config::byKey('jeeNetwork::mode') != 'master') {
                 $cron = new cron();
                 $cron->setClass('history');
                 $cron->setFunction('historize');
                 $cron->setSchedule('*/5 * * * * *');
                 $cron->setTimeout(5);
                 $cron->save();
                 $cron = new cron();
                 $cron->setClass('scenario');
                 $cron->setFunction('check');
                 $cron->setSchedule('* * * * * *');
                 $cron->setTimeout(5);
                 $cron->save();
                 $cron = new cron();
                 $cron->setClass('cmd');
                 $cron->setFunction('collect');
                 $cron->setSchedule('*/5 * * * * *');
                 $cron->setTimeout(5);
                 $cron->save();
                 $cron = new cron();
                 $cron->setClass('history');
                 $cron->setFunction('archive');
                 $cron->setSchedule('00 * * * * *');
                 $cron->setTimeout(20);
                 $cron->save();
                 config::save('jeeNetwork::mode', 'master');
             }
             break;
         case 'slave':
             if (config::byKey('jeeNetwork::mode') != 'slave') {
                 foreach (eqLogic::all() as $eqLogic) {
                     $eqLogic->remove();
                 }
                 foreach (object::all() as $object) {
                     $object->remove();
                 }
                 foreach (update::all() as $update) {
                     switch ($update->getType()) {
                         case 'core':
                             break;
                         case 'plugin':
                             try {
                                 $plugin = plugin::byId($update->getLogicalId());
                                 if (is_object($plugin) && $plugin->getAllowRemote() != 1) {
                                     $update->deleteObjet();
                                 }
                             } catch (Exception $e) {
                             }
                             break;
                         default:
                             $update->deleteObjet();
                             break;
                     }
                 }
                 foreach (view::all() as $view) {
                     $view->remove();
                 }
                 foreach (plan::all() as $plan) {
                     $plan->remove();
                 }
                 foreach (scenario::all() as $scenario) {
                     $scenario->remove();
                 }
                 foreach (listener::all() as $listener) {
                     $listener->remove();
                 }
                 $cron = cron::byClassAndFunction('history', 'historize');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $cron = cron::byClassAndFunction('scenario', 'check');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $cron = cron::byClassAndFunction('cmd', 'collect');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $cron = cron::byClassAndFunction('history', 'archive');
                 if (is_object($cron)) {
                     $cron->remove();
                 }
                 $user = new user();
                 $user->setLogin('jeedom_master');
                 $user->setPassword(config::genKey(255));
                 $user->setRights('admin', 1);
                 $user->save();
                 config::save('jeeNetwork::mode', 'slave');
             }
             break;
     }
 }
Ejemplo n.º 18
0
 public function reschedule()
 {
     $sunrise = $this->getCmd(null, 'sunrise')->execCmd();
     $sunset = $this->getCmd(null, 'sunset')->execCmd();
     if ($sunrise == '' || !is_numeric($sunrise) || $sunrise < 500 || $sunrise > 1000) {
         $sunrise = 500;
     }
     if ($sunset == '' || !is_numeric($sunset) || $sunset > 2300 || $sunset < 1600) {
         $sunset = 1600;
     }
     $next = null;
     if (date('Gi') + 100 > $sunrise && date('Gi') + 100 < $sunset) {
         $next = $sunset;
     } else {
         $next = $sunrise;
     }
     if ($next == null || $next == '' || !is_numeric($next)) {
         return;
     }
     if ($next < date('Gi') + 10) {
         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);
         }
     }
     $cron = cron::byClassAndFunction('weather', 'pull', array('weather_id' => intval($this->getId())));
     if ($next != null) {
         if (!is_object($cron)) {
             $cron = new cron();
             $cron->setClass('weather');
             $cron->setFunction('pull');
             $cron->setOption(array('weather_id' => intval($this->getId())));
             $cron->setLastRun(date('Y-m-d H:i:s'));
         }
         $next = strtotime($next);
         $cron->setSchedule(date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next));
         $cron->save();
     } else {
         if (is_object($cron)) {
             $cron->remove();
         }
     }
 }