예제 #1
0
 public function setIsEnable($_state)
 {
     if (version_compare(jeedom::version(), $this->getRequire()) == -1 && $_state == 1) {
         throw new Exception('Votre version de jeedom n\'est pas assez récente pour activer ce plugin');
     }
     $alreadyActive = config::byKey('active', $this->getId(), 0);
     if ($_state == 1) {
         if (config::byKey('jeeNetwork::mode') != 'master' && $this->getAllowRemote() != 1) {
             throw new Exception('Vous ne pouvez pas activer ce plugin sur un Jeedom configuré en esclave');
         }
         //market::checkPayment($this->getId());
         config::save('active', $_state, $this->getId());
     }
     if ($_state == 0) {
         $eqLogics = eqLogic::byType($this->getId());
         if (is_array($eqLogics)) {
             foreach ($eqLogics as $eqLogic) {
                 try {
                     $eqLogic->setConfiguration('previousIsEnable', $eqLogic->getIsEnable());
                     $eqLogic->setConfiguration('previousIsVisible', $eqLogic->getIsVisible());
                     $eqLogic->setIsEnable(0);
                     $eqLogic->setIsVisible(0);
                     $eqLogic->save();
                 } catch (Exception $e) {
                 }
             }
         }
         $listeners = listener::byClass($this->getId());
         if (is_array($listeners)) {
             foreach ($listeners as $listener) {
                 $listener->remove();
             }
         }
     }
     if ($alreadyActive == 0 && $_state == 1) {
         foreach (eqLogic::byType($this->getId()) as $eqLogic) {
             try {
                 $eqLogic->setIsEnable($eqLogic->getConfiguration('previousIsEnable', 1));
                 $eqLogic->setIsVisible($eqLogic->getConfiguration('previousIsVisible', 1));
                 $eqLogic->save();
             } catch (Exception $e) {
             }
         }
     }
     try {
         if ($_state == 1) {
             if ($alreadyActive == 1) {
                 $out = $this->callInstallFunction('update');
             } else {
                 $out = $this->callInstallFunction('install');
             }
         } else {
             if ($alreadyActive == 1) {
                 $out = $this->callInstallFunction('remove');
             }
         }
         if (isset($out) && trim($out) != '') {
             log::add($this->getId(), 'info', "Installation/remove/update result : " . $out);
         }
     } catch (Exception $e) {
         config::save('active', $alreadyActive, $this->getId());
         log::add('plugin', 'error', $e->getMessage());
         throw $e;
     }
     if ($_state == 0) {
         config::save('active', $_state, $this->getId());
     }
     return true;
 }
예제 #2
0
파일: cmd.class.php 프로젝트: jimibi/core
 public function event($_value, $_loop = 1)
 {
     if (trim($_value) === '' && $_value !== false || $_loop > 4 || $this->getType() != 'info') {
         return;
     }
     $value = $this->formatValue($_value);
     if ($this->getSubType() == 'numeric' && $value > $this->getConfiguration('maxValue', $value) && $value < $this->getConfiguration('minValue', $value) && strpos($value, 'error') === false) {
         return;
     }
     $eqLogic = $this->getEqLogic();
     if (!is_object($eqLogic) || $eqLogic->getIsEnable() == 0) {
         return;
     }
     $collectDate = $this->getCollectDate() != '' ? $this->getCollectDate() : date('Y-m-d H:i:s');
     $valueDate = $collectDate;
     if ($this->execCmd(null, 2) == $value) {
         if (strpos($value, 'error') === false) {
             $eqLogic->setStatus('lastCommunication', $collectDate);
         }
         if ($this->getConfiguration('doNotRepeatEvent', 0) == 1) {
             return;
         }
         $valueDate = $this->getValueDate();
     }
     $_loop++;
     $this->setCollectDate($collectDate);
     $this->setValueDate($valueDate);
     log::add('event', 'event', __('Evènement sur la commande ', __FILE__) . $this->getHumanName() . __(' valeur : ', __FILE__) . $value);
     cache::set('cmd' . $this->getId(), $value, $this->getCacheLifetime(), array('collectDate' => $this->getCollectDate(), 'valueDate' => $this->getValueDate()));
     scenario::check($this);
     $this->setCollect(0);
     $eqLogic->emptyCacheWidget();
     $nodeJs = array(array('cmd_id' => $this->getId()));
     $foundInfo = false;
     foreach (self::byValue($this->getId(), null, true) as $cmd) {
         if ($cmd->getType() == 'action') {
             $nodeJs[] = array('cmd_id' => $cmd->getId());
         } else {
             if ($_loop > 1) {
                 $cmd->event($cmd->execute(), $_loop);
             } else {
                 $foundInfo = true;
             }
         }
     }
     nodejs::pushUpdate('eventCmd', $nodeJs);
     if ($foundInfo) {
         listener::backgroundCalculDependencyCmd($this->getId());
     }
     listener::check($this->getId(), $value);
     if (strpos($value, 'error') === false) {
         $eqLogic->setStatus('lastCommunication', $collectDate);
         $this->addHistoryValue($value, $this->getCollectDate());
     } else {
         $this->addHistoryValue(null, $this->getCollectDate());
     }
     $this->checkReturnState($value);
     $this->checkCmdAlert($value);
     $this->pushUrl($value);
 }
예제 #3
0
 public function run()
 {
     if (!empty($this->service)) {
         $this->instance || ($this->instance = new $this->service());
         $listener = new listener($this->socket);
         $listener->listen($this->instance);
         return true;
     }
     return false;
 }
예제 #4
0
            $_GET[$argList[0]] = $argList[1];
        }
    }
}
set_time_limit(config::byKey('maxExecTimeScript', 60));
if (init('listener_id') == '') {
    foreach (cmd::byValue(init('event_id'), 'info') as $cmd) {
        $cmd->event($cmd->execute(), 2);
    }
} else {
    try {
        $listener_id = init('listener_id');
        if ($listener_id == '') {
            throw new Exception(__('Le listener ID ne peut être vide', __FILE__));
        }
        $listener = listener::byId($listener_id);
        if (!is_object($listener)) {
            throw new Exception(__('Listener non trouvé : ', __FILE__) . $listener_id);
        }
        $option = array();
        if (count($listener->getOption()) > 0) {
            $option = $listener->getOption();
        }
        $option['event_id'] = init('event_id');
        $option['value'] = init('value');
        if ($listener->getClass() != '') {
            $class = $listener->getClass();
            $function = $listener->getFunction();
            if (class_exists($class) && method_exists($class, $function)) {
                $class::$function($option);
            } else {
예제 #5
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;
     }
 }