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"; }
function openzwave_update() { log::add('openzwave', 'error', __('Après toute installation/mise à jour pensez bien à mettre à jour les dépendances Openzwave (voir documentation)', __FILE__)); if (!file_exists(dirname(__FILE__) . '/../data')) { mkdir(dirname(__FILE__) . '/../data'); } shell_exec('cp -R /opt/python-openzwave/xml_backups ' . dirname(__FILE__) . '/../data'); shell_exec('cp -R /opt/python-openzwave/zwcfg_*.xml ' . dirname(__FILE__) . '/../data'); shell_exec('rm -rf /opt/python-openzwave/xml_backups'); shell_exec('rm -rf /opt/python-openzwave/zwcfg_*.xml'); config::save('allowStartDeamon', 0, 'openzwave'); echo 'Stop zwave network...'; openzwave::stop(); openzwave::stopDeamon(); echo "OK\n"; echo 'Stop cron...'; $cron = cron::byClassAndFunction('openzwave', 'pull'); 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') { openzwave::updateOpenzwave(false); } 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"; echo 'Redemarrage zwave network...'; try { config::save('allowStartDeamon', 1, 'openzwave'); openzwave::runDeamon(); } catch (Exception $e) { } echo "OK\n"; }
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'); }
function listing() { if (!$this->haveAccessTo('view')) { return $this->showAccessDenied(); } $nType = func::GET('type', false, true); $sQuery = ''; switch ($nType) { case CONTACTS_TYPE_CONTACT: $sQuery = 'SELECT C.*, U.login as ulogin, U.name as uname, U.blocked as ublocked, U.admin as uadmin FROM ' . TABLE_CONTACTS . ' C LEFT JOIN ' . TABLE_USERS . ' U ON C.user_id=U.user_id WHERE C.ctype=' . $nType; break; } $this->generatePagenationPrevNext($sQuery . ' ORDER BY C.created DESC', $aData, 'contacts', 15); $this->db->execute('UPDATE ' . TABLE_CONTACTS . ' SET viewed = 1 WHERE viewed = 0'); config::save('contacts_new', 0); $aData['type'] = $nType; $this->tplAssignByRef('aData', $aData); return $this->tplFetch('admin.listing.tpl'); }
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"); }
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'); } } } }
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é'); }
/** * Archive les données de history dans historyArch */ public static function archive() { $sql = 'DELETE FROM history WHERE `datetime` <= "2000-01-01 01:00:00" OR `datetime` >= "2020-01-01 01:00:00"'; DB::Prepare($sql, array()); $sql = 'DELETE FROM historyArch WHERE `datetime` <= "2000-01-01 01:00:00" OR `datetime` >= "2020-01-01 01:00:00"'; DB::Prepare($sql, array()); $sql = 'DELETE FROM history WHERE `value` IS NULL'; DB::Prepare($sql, array()); $sql = 'DELETE FROM historyArch WHERE `value` IS NULL'; DB::Prepare($sql, array()); if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) { config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1); } if (config::byKey('historyArchiveTime') < 1) { $archiveDatetime = date('Y-m-d H:i:s', strtotime('- 1 hours')); } else { $archiveDatetime = date('Y-m-d H:i:s', strtotime('- ' . config::byKey('historyArchiveTime', 'core', 1) . ' hours')); } if (config::byKey('historyArchivePackage') < 1) { $archivePackage = '00:' . config::byKey('historyArchivePackage') * 60 . ':00'; } else { $archivePackage = config::byKey('historyArchivePackage') . ':00:00'; if (strlen($archivePackage) < 8) { $archivePackage = '0' . $archivePackage; } } $values = array('archiveDatetime' => $archiveDatetime); $sql = 'SELECT DISTINCT(cmd_id) FROM history WHERE `datetime`<:archiveDatetime'; $list_sensors = DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL); foreach ($list_sensors as $sensors) { $cmd = cmd::byId($sensors['cmd_id']); if (is_object($cmd) && $cmd->getType() == 'info' && $cmd->getIsHistorized() == 1) { if ($cmd->getConfiguration('historyPurge', '') != '') { $purgeTime = date('Y-m-d H:i:s', strtotime($cmd->getConfiguration('historyPurge', ''))); $values = array('cmd_id' => $cmd->getId(), 'datetime' => $purgeTime); $sql = 'DELETE FROM historyArch WHERE cmd_id=:cmd_id AND `datetime` < :datetime'; DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); } if ($cmd->getSubType() == 'binary' || $cmd->getConfiguration('historizeMode', 'avg') == 'none') { $values = array('cmd_id' => $cmd->getId()); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM history WHERE cmd_id=:cmd_id ORDER BY `datetime` ASC'; $history = DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__); for ($i = 1; $i < count($history); $i++) { if ($history[$i]->getValue() != $history[$i - 1]->getValue()) { $history[$i]->setTableName('historyArch'); $history[$i]->save(); $history[$i]->setTableName('history'); } $history[$i]->remove(); } $history[0]->setTableName('historyArch'); $history[0]->save(); $history[0]->setTableName('history'); $history[0]->remove(); $values = array('cmd_id' => $cmd->getId()); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM historyArch WHERE cmd_id=:cmd_id ORDER BY datetime ASC'; $history = DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__); for ($i = 1; $i < count($history); $i++) { if ($history[$i]->getValue() == $history[$i - 1]->getValue()) { $history[$i]->setTableName('historyArch'); $history[$i]->remove(); } } } else { $values = array('cmd_id' => $sensors['cmd_id'], 'archiveDatetime' => $archiveDatetime); $sql = 'SELECT MIN(`datetime`) as oldest FROM history WHERE `datetime`<:archiveDatetime AND cmd_id=:cmd_id'; $oldest = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); $mode = $cmd->getConfiguration('historizeMode', 'avg'); while ($oldest['oldest'] != null) { $values = array('cmd_id' => $sensors['cmd_id'], 'oldest' => $oldest['oldest'], 'archivePackage' => $archivePackage); $sql = 'SELECT ' . $mode . '(value) as value, FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(`datetime`))) as datetime FROM history WHERE TIMEDIFF(`datetime`,:oldest)<:archivePackage AND cmd_id=:cmd_id'; $avg = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); $history = new self(); $history->setCmd_id($sensors['cmd_id']); $history->setValue($avg['value']); $history->setDatetime($avg['datetime']); $history->setTableName('historyArch'); $history->save(); $values = array('cmd_id' => $sensors['cmd_id'], 'oldest' => $oldest['oldest'], 'archivePackage' => $archivePackage); $sql = 'DELETE FROM history WHERE TIMEDIFF(`datetime`,:oldest)<:archivePackage AND cmd_id=:cmd_id'; DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); $values = array('cmd_id' => $sensors['cmd_id'], 'archiveDatetime' => $archiveDatetime); $sql = 'SELECT MIN(`datetime`) as oldest FROM history WHERE `datetime`<:archiveDatetime AND cmd_id=:cmd_id'; $oldest = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); } } } } }
public static function getVersion($_module = 'openzwave') { if ($_module == 'openzwave') { try { $network = self::callOpenzwave('/ZWaveAPI/Run/network.GetStatus()', 0, 2000); if (isset($network['OpenZwaveLibraryVersion'])) { config::save('currentOzwVersion', $network['OpenZwaveLibraryVersion'], 'openzwave'); } } catch (Exception $e) { } return config::byKey('currentOzwVersion', 'openzwave', -1); } }
<?php require '../class.config.php'; $config = new config('test.php'); var_dump($config->get()); $config->save(); $config->save('test.xml');
public static function cronHourly() { if (config::byKey('noAlertOnNotification', 'zwave', 0) == 1) { return; } foreach (self::listServerZway() as $serverID => $server) { if (!isset($server['name'])) { continue; } $notifications = self::showNotification($serverID); if (is_array($notifications) && isset($notifications['data']) && isset($notifications['data']['notifications'])) { $notifications = array_reverse($notifications['data']['notifications']); $lastCheck = config::byKey('lastNotificationCheck' . $serverID, 'zwave', strtotime('now')); foreach ($notifications as $notification) { $timestamp = strtotime($notification['timestamp']); if ($timestamp > $lastCheck) { log::add('zwave', 'error', __('Notification sur ', __FILE__) . $server['name'] . __(' le ', __FILE__) . date('Y-m-d H:i:s', $timestamp) . __(' type ', __FILE__) . $notification['type'] . __(' de niveau ', __FILE__) . $notification['level'] . ' : ' . $notification['message']); } } config::save('lastNotificationCheck' . $serverID, strtotime('now'), 'zwave'); } } }
/** * Generates the code to build a module * @static function * @param string $name module name * @param string $title module title */ public static function build($name, $title) { $reservedKeywords = array('__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'); if (!is_dir('modules/' . $name) && !is_numeric($name) && !in_array($name, $reservedKeywords)) { $name = preg_replace('@[^a-zA-Z0-9]@', '', $name); $licence = str_replace('{{module}}', $name, file_get_contents("modules/admin/licence.txt")); tools::createDirectory('modules/' . $name); $template = '<?php ' . $licence . ' namespace ' . $name . '; /** * @title ' . str_replace('\'', '\\\'', $title) . ' * @description ' . str_replace('\'', '\\\'', $title) . ' * @copyright 1 * @browsers all * @php_version_min 5.3 */ class module extends \\module { protected $name = \'' . str_replace('\'', '\\\'', $name) . '\'; } ?>'; file_put_contents('modules/' . $name . '/module.php', $template); include 'modules/' . $name . '/module.php'; $name2 = $name . '\\module'; $mod = new $name2($name); $page = new \page(1, $name); $page->setModule($name); $page->setTitle('Index ' . $name); $page->setRegex('@^index$@'); /* Set rights forbidden for non admins, admins are allowed by default */ foreach (\app::getModule('core')->getEntity('role') as $role) { if ($role->permissions == 0) { $mod->setRights($role->id_role, 0); $page->setRights($role->id_role, 0); } } $mod->addPage($page); $mod->save(); $config = new \config('profiles/' . PROFILE . '/config.php', TRUE); $config->add('$config[\'modules\'][\'' . $name . '\']', '7'); return $config->save(); } else { return FALSE; } }
public static function pull() { try { $request_http = new com_http(config::byKey('superviseurIP', 'ewattch') . '/log.json?mode=1'); $result = json_decode(trim(trim($request_http->exec(1, 1)), ','), true); if (config::byKey('numberFailed', 'ewattch', 0) > 0) { config::save('numberFailed', 0, 'ewattch'); } } catch (Exception $e) { if (config::byKey('numberFailed', 'ewattch', 0) > 3) { log::add('ewattch', 'error', __('Erreur sur synchro ewattch ', __FILE__) . '(' . config::byKey('numberFailed', 'ewattch', 0) . ')' . $e->getMessage()); } else { config::save('numberFailed', config::byKey('numberFailed', 'ewattch', 0) + 1, 'ewattch'); } return; } print_r($result); if (isset($result[1][0])) { foreach ($result[1][0] as $resource) { $name = $resource[0]; $eqLogic = self::byLogicalId('electricity_' . $name, 'ewattch'); if (!is_object($eqLogic)) { continue; } $index = $eqLogic->getCmd(null, 'index'); if (is_object($index)) { $value = $resource[7] + $index->getConfiguration('previous', 0); $index->event($value); if ($index->getConfiguration('lastPrevious') == '') { $index->setConfiguration('previous', 0); $index->setConfiguration('lastPrevious', date('Y-m-d')); $index->save(); } if ($index->getConfiguration('lastPrevious', date('Y-m-d')) != date('Y-m-d')) { $index->setConfiguration('previous', $value); $index->setConfiguration('lastPrevious', date('Y-m-d')); $index->save(); } } $cost = $eqLogic->getCmd(null, 'cost'); if (is_object($cost)) { $value = $resource[6] + $index->getConfiguration('previous', 0); $cost->event($value); if ($cost->getConfiguration('lastPrevious') == '') { $cost->setConfiguration('previous', 0); $cost->setConfiguration('lastPrevious', date('Y-m-d')); $cost->save(); } if ($cost->getConfiguration('lastPrevious', date('Y-m-d')) != date('Y-m-d')) { $cost->setConfiguration('previous', $value); $cost->setConfiguration('lastPrevious', date('Y-m-d')); $cost->save(); } } } } if (isset($result[1][1])) { foreach ($result[1][1] as $resource) { $name = $resource[0]; $eqLogic = self::byLogicalId('water_' . $name, 'ewattch'); if (!is_object($eqLogic)) { continue; } $index = $eqLogic->getCmd(null, 'index'); if (is_object($index)) { $value = $resource[7] + $index->getConfiguration('previous', 0); $index->event($value); if ($index->getConfiguration('lastPrevious') == '') { $index->setConfiguration('previous', 0); $index->setConfiguration('lastPrevious', date('Y-m-d')); $index->save(); } if ($index->getConfiguration('lastPrevious', date('Y-m-d')) != date('Y-m-d')) { $index->setConfiguration('previous', $value); $index->setConfiguration('lastPrevious', date('Y-m-d')); $index->save(); } } $cost = $eqLogic->getCmd(null, 'cost'); if (is_object($cost)) { $value = $resource[6] + $index->getConfiguration('previous', 0); $cost->event($value); if ($cost->getConfiguration('lastPrevious') == '') { $cost->setConfiguration('previous', 0); $cost->setConfiguration('lastPrevious', date('Y-m-d')); $cost->save(); } if ($cost->getConfiguration('lastPrevious', date('Y-m-d')) != date('Y-m-d')) { $cost->setConfiguration('previous', $value); $cost->setConfiguration('lastPrevious', date('Y-m-d')); $cost->save(); } } } } try { $request_http = new com_http(config::byKey('superviseurIP', 'ewattch') . '/log.json?mode=10'); $result = json_decode(trim(trim($request_http->exec(1, 1)), ','), true); if (config::byKey('numberFailed', 'ewattch', 0) > 0) { config::save('numberFailed', 0, 'ewattch'); } } catch (Exception $e) { if (config::byKey('numberFailed', 'ewattch', 0) > 150) { log::add('ewattch', 'error', __('Erreur sur synchro ewattch ', __FILE__) . '(' . config::byKey('numberFailed', 'ewattch', 0) . ')' . $e->getMessage()); } else { config::save('numberFailed', config::byKey('numberFailed', 'ewattch', 0) + 1, 'ewattch'); } } foreach ($result['resource']['heating'] as $resource) { if (!isset($resource['index'])) { continue; } $eqLogic = self::byLogicalId('heating_' . $resource['name'], 'ewattch'); if (!is_object($eqLogic)) { continue; } $index = $eqLogic->getCmd(null, 'index'); if (!is_object($index)) { continue; } $index->event($resource['index'] - $previous); } foreach ($result['resource']['environment'] as $resource) { if (!isset($resource['value'])) { continue; } $eqLogic = self::byLogicalId('environment_' . $resource['name'], 'ewattch'); if (!is_object($eqLogic)) { continue; } $index = $eqLogic->getCmd(null, 'index'); if (!is_object($index)) { continue; } $index->event($resource['value']); } }
public static function getHardwareName() { if (config::byKey('hardware_name') != '') { return config::byKey('hardware_name'); } $result = 'DIY'; $uname = shell_exec('uname -a'); if (strpos($uname, 'cubox') !== false) { $result = 'Jeedomboard'; } else { if (file_exists('/.dockerinit')) { $result = 'Docker'; } else { if (file_exists('/usr/bin/raspi-config')) { $result = 'RPI/RPI2'; } } } config::save('hardware_name', $result); return config::byKey('hardware_name'); }
connection::failed(); echo 'Clef API non valide, vous n\'etes pas autorisé à effectuer cette action (jeeZwave)'; die; } if (isset($_GET['test'])) { echo 'OK'; die; } if (isset($_GET['stopOpenzwave'])) { config::save('allowStartDeamon', 0, 'openzwave'); openzwave::stopDeamon(); die; } if (isset($_GET['startOpenzwave'])) { log::add('openzwave', 'debug', 'Restart Zwave deamon'); config::save('allowStartDeamon', 1, 'openzwave'); openzwave::runDeamon(); openzwave::getVersion(); die; } $results = json_decode(file_get_contents("php://input"), true); if (!is_array($results)) { die; } if (isset($results['device'])) { foreach ($results['device'] as $node_id => $datas) { $eqLogic = openzwave::getEqLogicByLogicalIdAndServerId($node_id, $results['serverId']); if (is_object($eqLogic)) { if (strpos($eqLogic->getConfiguration('fileconf'), 'fibaro.fgs221.fil.pilote') !== false) { foreach ($eqLogic->getCmd('info', '0&&1.0x0', null, true) as $cmd) { if ($cmd->getConfiguration('value') == 'pilotWire') {
} if ($jsonrpc->getMethod() == 'update::checkUpdate') { update::checkAllUpdate(); $jsonrpc->makeSuccess('ok'); } /* * ************************Network*************************** */ if ($jsonrpc->getMethod() == 'network::restartNgrok') { config::save('market::allowDNS', 1); if (network::dns_run()) { network::dns_stop(); } network::dns_start(); $jsonrpc->makeSuccess(); } if ($jsonrpc->getMethod() == 'network::stopNgrok') { config::save('market::allowDNS', 0); network::dns_stop(); $jsonrpc->makeSuccess(); } if ($jsonrpc->getMethod() == 'network::ngrokRun') { if (!isset($params['proto'])) { $params['proto'] = 'https'; } if (!isset($params['port'])) { $params['port'] = 80; } if (!isset($params['name'])) { $params['name'] = ''; } $jsonrpc->makeSuccess(network::dns_run()); }
$logLevel = array('info' => 0, 'debug' => 0, 'event' => 0, 'error' => 1); if (init('mode') != 'force') { echo "Jeedom est-il installé sur un Rasberry PI ? [o/N] "; if (trim(fgets(STDIN)) === 'o') { config::save('cronSleepTime', 60); } } else { config::save('cronSleepTime', 60); } config::save('logLevel', $logLevel); echo "OK\n"; echo 'Installation de socket.io et express (peut etre très long > 30min)'; echo shell_exec('cd ' . dirname(__FILE__) . '/../core/nodeJS;sudo npm install socket.io;npm install express'); echo "OK\n"; } config::save('version', jeedom::version()); } catch (Exception $e) { if ($update) { if ($backup_ok && $update_begin) { jeedom::restore(); } jeedom::start(); } echo __('Erreur durant l\'installation : ', __FILE__) . $e->getMessage(); echo __('Details : ', __FILE__) . print_r($e->getTrace()); echo "[END UPDATE ERROR]\n"; throw $e; } echo "[END UPDATE SUCCESS]\n"; function incrementVersion($_version) {
echo "Création de plugin::cron15\n"; $cron = new cron(); } $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(); cache::deleteBySearch('widgetHtml'); cache::deleteBySearch('cmdWidgetdashboard'); cache::deleteBySearch('cmdWidgetmobile'); cache::deleteBySearch('scenarioHtmldashboard'); config::save('hardware_name', ''); if (config::byKey('api') == '') { config::save('api', config::genKey()); } } catch (Exception $e) { echo "Error : "; echo $e->getMessage(); } echo "[END CONSISTENCY]\n";
public static function checkConf($_mode = 'external') { if ($_mode == 'internal') { if (trim(config::byKey('internalComplement')) == '/') { config::save('internalComplement', ''); } if (!filter_var(config::byKey('internalAddr'), FILTER_VALIDATE_IP)) { $internalAddr = str_replace(array('http://', 'https://'), '', config::byKey('internalAddr')); $pos = strpos($internalAddr, '/'); if ($pos !== false) { $internalAddr = substr($internalAddr, 0, $pos); } if ($internalAddr != config::byKey('internalAddr') && !netMatch('127.0.*.*', $internalAddr)) { config::save('internalAddr', $internalAddr); } } else { $internalIp = getHostByName(getHostName()); if (netMatch('127.0.*.*', $internalIp) || $internalIp == '' || !filter_var($internalIp, FILTER_VALIDATE_IP)) { $internalIp = self::getInterfaceIp('eth0'); } if (netMatch('127.0.*.*', $internalIp) || $internalIp == '' || !filter_var($internalIp, FILTER_VALIDATE_IP)) { $internalIp = self::getInterfaceIp('bond0'); } if (netMatch('127.0.*.*', $internalIp) || $internalIp == '' || !filter_var($internalIp, FILTER_VALIDATE_IP)) { $internalIp = self::getInterfaceIp('wlan0'); } if (netMatch('127.0.*.*', $internalIp) || $internalIp == '' || !filter_var($internalIp, FILTER_VALIDATE_IP)) { $internalIp = explode(' ', shell_exec('hostname -I')); $internalIp = $internalIp[0]; } if ($internalIp != '' && filter_var($internalIp, FILTER_VALIDATE_IP) && !netMatch('127.0.*.*', $internalIp)) { config::save('internalAddr', $internalIp); } } if (config::byKey('internalProtocol') == '') { config::save('internalProtocol', 'http://'); } if (config::byKey('internalPort') == '') { config::save('internalPort', 80); } if (config::byKey('internalProtocol') == 'https://' && config::byKey('internalPort') == 80) { config::save('internalPort', 443); } if (config::byKey('internalProtocol') == 'http://' && config::byKey('internalPort') == 443) { config::save('internalPort', 80); } } if ($_mode == 'external') { if ($_mode == 'external' && trim(config::byKey('externalComplement')) == '/') { config::save('externalComplement', ''); } if (!filter_var(config::byKey('externalAddr'), FILTER_VALIDATE_IP)) { $externalAddr = str_replace(array('http://', 'https://'), '', config::byKey('externalAddr')); $pos = strpos($externalAddr, '/'); if ($pos !== false) { $externalAddr = substr($externalAddr, 0, $pos); } if ($externalAddr != config::byKey('externalAddr')) { config::save('externalAddr', $externalAddr); } } } if (file_exists('/etc/nginx/sites-available/default')) { $data = file_get_contents('/etc/nginx/sites-available/default'); if (strpos($data, 'root /usr/share/nginx/www;') !== false) { if ($_mode == 'internal') { config::save('internalComplement', '/jeedom'); } if ($_mode == 'external') { config::save('externalComplement', '/jeedom'); } } else { if ($_mode == 'internal') { config::save('internalComplement', ''); } if ($_mode == 'external') { config::save('externalComplement', ''); } } } }
public static function removeNginxRedirection() { foreach (self::listServerZwave(false) as $zwave) { $urlPath = config::byKey('urlPath' . $zwave['id'], 'openzwave'); $rules = array("location /" . $urlPath . "/ {\n"); network::nginx_removeRule($rules); config::save('urlPath' . $zwave['id'], '', 'openzwave'); } }
function saveConfig($aConfig, $bSave2File = false) { if ($bSave2File) { $aFind = array("'\r'", "'\n'"); $aReplace = array('', ''); $rHandler = fopen(PATH_BASE . 'config/site.config.php', "w"); $bMagicQuotes = get_magic_quotes_gpc(); fwrite($rHandler, "<?php \n\n return array (\n"); foreach ($aConfig as $sName => $sValue) { if (in_array($sName, array('offline_reason', 'copyright', 'contactaddress', 'ps_rbkmoney_info', 'ps_zpay_info', 'ps_robox_info', 'ps_webmoney_info', 'ps_checkout_info'))) { $sValue = trim($sValue); if (!$bMagicQuotes) { $sValue = addslashes($sValue); } $sValue = preg_replace($aFind, $aReplace, $sValue); } else { $sValue = trim($sValue); if (!$bMagicQuotes) { $sValue = addslashes($sValue); } $sValue = htmlentities($sValue, ENT_QUOTES, 'UTF-8'); } fwrite($rHandler, "'{$sName}' => \"{$sValue}\",\n"); } fwrite($rHandler, ");\n\n"); fclose($rHandler); } else { foreach ($aConfig as $config_name => $config_value) { config::save($config_name, $config_value); } } }
public static function updateKey() { config::save('nodeJsKey', config::genKey()); }
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; }
public static function postJsonRpc(&$_result) { if (is_array($_result)) { if (config::byKey('market::allowDNS') == 1) { $dnsRestart = false; if (isset($_result['register::ngrokAddr']) && config::byKey('ngrok::addr') != $_result['register::ngrokAddr']) { config::save('ngrok::addr', $_result['register::ngrokAddr']); $dnsRestart = true; } if (isset($_result['register::ngrokToken']) && config::byKey('ngrok::token') != $_result['register::ngrokToken']) { config::save('ngrok::token', $_result['register::ngrokToken']); $dnsRestart = true; } if ($dnsRestart) { if (network::dns_run()) { network::dns_stop(); } network::dns_start(); } if (isset($_result['jeedom::url']) && config::byKey('jeedom::url') != $_result['jeedom::url']) { config::save('jeedom::url', $_result['jeedom::url']); } } if (isset($_result['register::ngrokAddr'])) { unset($_result['register::ngrokAddr']); } if (isset($_result['register::ngrokPort'])) { unset($_result['register::ngrokPort']); } if (isset($_result['register::ngrokToken'])) { unset($_result['register::ngrokToken']); } if (isset($_result['jeedom::url'])) { unset($_result['jeedom::url']); } if (isset($_result['register::hwkey_nok']) && $_result['register::hwkey_nok'] == 1) { config::save('jeedom::installKey', ''); } } }
$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'); config::save('hardware_name', ''); } catch (Exception $e) { echo "Error : "; echo $e->getMessage(); } echo "[END CONSISTENCY]\n";
} die; } $cnt->configure($e); if ($e->has()) { foreach ($e->getList() as $ei) { print "ERROR: " . $ei . "\n"; } } else { $spl = StartingPointPackage::getClass($cliconfig['starting-point']); require DIR_CONFIG_SITE . '/site_install.php'; require DIR_CONFIG_SITE . '/site_install_user.php'; $routines = $spl->getInstallRoutines(); try { foreach ($routines as $r) { print $r->getProgress() . '%: ' . $r->getText() . "\n"; call_user_func(array($spl, $r->getMethod())); } } catch (Exception $ex) { print "ERROR: " . $ex->getMessage() . "\n"; $cnt->reset(); } if ($cliconfig['demo-username']) { print "Adding demo user\n"; UserInfo::add(array('uName' => $cliconfig['demo-username'], 'uEmail' => $cliconfig['demo-email'], 'uPassword' => $cliconfig['demo-password']))->getUserObject()->enterGroup(Group::getByID(ADMIN_GROUP_ID)); } if (!isset($ex)) { config::save('concrete.misc.seen_introduction', true); print "Installation Complete!\n"; } }
if (init('action') == 'removeBackup') { jeedom::removeBackup(init('backup')); ajax::success(); } if (init('action') == 'listBackup') { ajax::success(jeedom::listBackup()); } if (init('action') == 'getConfiguration') { ajax::success(jeedom::getConfiguration(init('key'), init('default'))); } if (init('action') == 'flushcache') { cache::flush(); ajax::success(); } if (init('action') == 'resetHwKey') { config::save('jeedom::installKey', ''); ajax::success(); } if (init('action') == 'backupupload') { $uploaddir = dirname(__FILE__) . '/../../backup'; if (!file_exists($uploaddir)) { mkdir($uploaddir); } if (!file_exists($uploaddir)) { throw new Exception(__('Répertoire d\'upload non trouvé : ', __FILE__) . $uploaddir); } if (!isset($_FILES['file'])) { throw new Exception(__('Aucun fichier trouvé. Vérifié parametre PHP (post size limit)', __FILE__)); } $extension = strtolower(strrchr($_FILES['file']['name'], '.')); if (!in_array($extension, array('.gz'))) {
} th { width:150px; text-align: right; font-weight:normal; vertical-align: top; margin: 0px; border: 0; } </style> </head> <body> <?php // user is registered and the mainadmin if (isset($_SESSION['relaxx']) && $_SESSION['relaxx'] == $config->admin_name && $_SESSION['relaxx_pass'] == $config->admin_pass) { // update config if (isset($_POST['host'])) { $config->getPost(); $config->save('./config/config.php'); } $config->edit(); } else { // user is not valid echo "<h3>" . $lng->error . "</h3><p>" . str_replace("\\n", "<br />", $lng->error_login) . "</p>"; } ?> </body> </html>
$TPL[$name] = $_POST[$name]; } } $c->save(); $TPL["message_good"] = "Saved configuration."; } } // Handle the only checkbox specially. If more checkboxes are added this // should be rewritten. #echo var_dump($_POST); if ($_POST['sbs_link'] == "rss" && !$_POST['rssShowProject']) { $c = new config(); $c->set_id(config::get_config_item_id('rssShowProject')); $c->select(); $c->set_value("value", '0'); $c->save(); } $TPL["message"] or $TPL["message_good"] = "Saved configuration."; } else { if ($_POST["delete_logo"]) { foreach (array(ALLOC_LOGO, ALLOC_LOGO_SMALL) as $logo) { if (file_exists($logo)) { if (unlink($logo)) { $TPL["message_good"][] = "Deleted " . $logo; } } if (file_exists($logo)) { alloc_error("Unable to delete " . $logo); } } }
nodejs::updateKey(); ajax::success(config::byKey('nodeJsKey')); } if (init('action') == 'getNodeJsKey') { ajax::success(config::byKey('nodeJsKey')); } if (init('action') == 'addKey') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } $values = json_decode(init('value'), true); foreach ($values as $key => $value) { if ($key == 'market::password' && !preg_match('/^[0-9a-f]{40}$/i', $value)) { $value = sha1($value); } config::save($key, jeedom::fromHumanReadable($value), init('plugin', 'core')); if ($key == 'internalAddr') { jeeNetwork::pull(); } if ($key == 'market::allowDNS') { if ($value == 1) { if (!network::dns_run()) { network::dns_start(); } } else { if (network::dns_run()) { network::dns_stop(); } } } }