public static function updateNginxRedirection() { foreach (self::listServerZwave(false) as $zwave) { if (trim($zwave['addr']) == '' || trim($zwave['port']) == '') { continue; } $urlPath = config::byKey('urlPath' . $zwave['id'], 'openzwave'); if ($urlPath == '') { $urlPath = 'openzwave_' . $zwave['id'] . '_' . config::genKey(30); config::save('urlPath' . $zwave['id'], $urlPath, 'openzwave'); } $rules = array("location /" . $urlPath . "/ {\n" . "proxy_pass http://" . $zwave['addr'] . ":" . $zwave['port'] . "/;\n" . "proxy_redirect off;\n" . "proxy_set_header Host \$host:\$server_port;\n" . "proxy_set_header X-Real-IP \$remote_addr;\n" . "}"); network::nginx_saveRule($rules); } }
public static function createTemporary($_hours) { $user = new self(); $user->setLogin('temp_' . config::genKey()); $user->setPassword(config::genKey(45)); $user->setRights('admin', 1); $user->setOptions('validity_limit', date('Y-m-d H:i:s', strtotime('+' . $_hours . ' hour now'))); $user->save(); return $user; }
if (!isConnect() && !login(init('username'), init('password'), true)) { throw new Exception('Mot de passe ou nom d\'utilisateur incorrect'); } if (init('storeConnection') == 1) { setcookie('registerDevice', $_SESSION['user']->getHash(), time() + 365 * 24 * 3600, "/", '', false, true); } ajax::success(); } if (init('action') == 'forgotPassword') { log::add('user', 'info', __('Demande de récupération de mot de passe pour : ', __FILE__) . init('login')); $user = user::byLogin(init('login')); if (!is_object($user)) { connection::failed(); throw new Exception('Utilisateur introuvable'); } $newPassword = config::genKey(); $oldPassword = $user->getPassword(); $user->setPassword(sha1($newPassword)); $cmds = explode('&&', config::byKey('emailAdmin')); $found = false; try { if (count($cmds) > 0) { foreach ($cmds as $id) { $cmd = cmd::byId(str_replace('#', '', $id)); if (is_object($cmd)) { $found = true; $cmd->execCmd(array('title' => __('[JEEDOM] Récuperation de mot de passe', __FILE__), 'message' => 'Voici votre nouveau mot de passe pour votre installation jeedom : ' . $newPassword)); } } } } catch (Exception $e) {
public static function renameSysInfoFolder() { $folder = self::getCurrentSysInfoFolder(); if ($folder != '') { rename(dirname(__FILE__) . '/../../' . $folder, dirname(__FILE__) . '/../../sysinfo' . config::genKey()); } }
public function getHash() { if ($this->hash == '' && $this->id != '') { $hash = sha1(config::genKey(128)); while (is_object(self::byHash($hash))) { $hash = sha1(config::genKey(128)); } $this->setHash($hash); $this->save(); } return $this->hash; }
public function preSave() { if ($this->getConfiguration('key') == '') { $this->setConfiguration('key', config::genKey(30)); } }
public function save() { if ($this->getMessage() == '') { return; } if ($this->getLogicalId() == '') { $this->setLogicalId($this->getPlugin() . '::' . config::genKey()); } $values = array('message' => $this->getMessage(), 'logicalId' => $this->getLogicalId(), 'plugin' => $this->getPlugin()); $sql = 'SELECT count(*) FROM message WHERE plugin=:plugin AND ( logicalId=:logicalId OR message=:message ) '; $result = DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW); if ($result['count(*)'] == 0) { DB::save($this); @nodejs::pushNotification(__('Message de ', __FILE__) . $this->getPlugin(), $this->getMessage(), 'message'); $cmds = explode('&&', config::byKey('emailAdmin')); if (count($cmds) > 0) { foreach ($cmds as $id) { $cmd = cmd::byId(str_replace('#', '', $id)); if (is_object($cmd)) { $cmd->execCmd(array('title' => __('[JEEDOM] Message de ', __FILE__) . $this->getPlugin(), 'message' => $this->getMessage())); } else { log::add('message', 'info', __('Impossible de trouver la commande correspondant à :', __FILE__) . $id); } } } } @nodejs::pushUpdate('message::refreshMessageNumber'); }
$jsonrpc->makeSuccess($scenario->save()); } if ($params['state'] == 'disable') { $scenario->setIsActive(0); $jsonrpc->makeSuccess($scenario->save()); } throw new Exception('La paramètre "state" ne peut être vide et doit avoir pour valeur [run,stop,enable;disable]'); } /* * ************************JeeNetwork*************************** */ if ($jsonrpc->getMethod() == 'jeeNetwork::handshake') { if (config::byKey('jeeNetwork::mode') != 'slave') { throw new Exception('Impossible d\'ajouter une box jeedom non esclave à un réseau Jeedom'); } $auiKey = config::byKey('auiKey'); if ($auiKey == '') { $auiKey = config::genKey(255); config::save('auiKey', $auiKey); } $return = array('mode' => config::byKey('jeeNetwork::mode'), 'nbUpdate' => update::nbNeedUpdate(), 'version' => jeedom::version(), 'nbMessage' => message::nbMessage(), 'auiKey' => $auiKey, 'jeedom::url' => config::byKey('jeedom::url'), 'ngrok::port' => config::byKey('ngrok::port')); if (!filter_var(network::getNetworkAccess('external', 'ip'), FILTER_VALIDATE_IP) && network::getNetworkAccess('external', 'ip') != '') { $return['jeedom::url'] = network::getNetworkAccess('internal'); } foreach (plugin::listPlugin(true) as $plugin) { if ($plugin->getAllowRemote() == 1) { $return['plugin'][] = $plugin->getId(); } } $address = isset($params['address']) && $params['address'] != '' ? $params['address'] : getClientIp(); config::save('jeeNetwork::master::ip', $address); config::save('jeeNetwork::master::apikey', $params['apikey_master']); config::save('jeeNetwork::slave::id', $params['slave_id']);
if (init('mode') != 'force') { echo "Jeedom va être installé. Voulez-vous continuer ? [o/N] "; if (trim(fgets(STDIN)) !== 'o') { echo "L'installation de Jeedom est annulée\n"; echo "[END UPDATE SUCCESS]\n"; exit(0); } } echo "\nInstallation de Jeedom " . jeedom::version() . "\n"; $sql = file_get_contents(dirname(__FILE__) . '/install.sql'); echo "Installation de la base de données..."; DB::Prepare($sql, array(), DB::FETCH_TYPE_ROW); echo "OK\n"; echo "Post installe...\n"; nodejs::updateKey(); config::save('api', config::genKey()); require_once dirname(__FILE__) . '/consistency.php'; echo "Ajout de l\\'utilisateur (admin,admin)\n"; $user = new user(); $user->setLogin('admin'); $user->setPassword(sha1('admin')); $user->setRights('admin', 1); $user->save(); $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);
public static function updateKey() { config::save('nodeJsKey', config::genKey()); }
die; } $cron->setState('stop'); $cron->setPID(); $cron->setServer(''); $cron->setDuration(convertDuration(strtotime('now') - $datetimeStart)); $cron->save(); } die; } catch (Exception $e) { $cron->setState('error'); $cron->setPID(''); $cron->setServer(''); $cron->setDuration(-1); $cron->save(); $logicalId = config::genKey(); if ($e->getCode() != 0) { $logicalId = $cron->getName() . '::' . $e->getCode(); } echo '[Erreur] ' . $cron->getName() . ' : ' . print_r($e, true); log::add('cron', 'error', __('Erreur sur ', __FILE__) . $cron->getName() . ' : ' . print_r($e, true), $logicalId); } } else { if (cron::jeeCronRun()) { die; } $sleepTime = config::byKey('cronSleepTime'); $started = jeedom::isStarted(); set_time_limit(59); cron::setPidFile(); while (true) {
function login($_login, $_password, $_ajax = false, $_passAlreadyEncode = false) { $user = user::connect($_login, $_password, $_passAlreadyEncode); if (is_object($user) && $user->getEnable() == 1) { connection::success($user->getLogin()); @session_start(); $_SESSION['user'] = $user; if (init('v') == 'd' && init('registerDevice') == 'on') { if ($_SESSION['user']->getOptions('registerDevice') == '') { $_SESSION['user']->setOptions('registerDevice', config::genKey(255)); $_SESSION['user']->save(); } setcookie('registerDevice', $_SESSION['user']->getOptions('registerDevice'), time() + 365 * 24 * 3600, "/", '', false, true); } @session_write_close(); log::add('connection', 'info', __('Connexion de l\'utilisateur : ', __FILE__) . $_login); $getParams = ''; unset($_GET['auth']); foreach ($_GET as $var => $value) { $getParams .= $var . '=' . $value . '&'; } if (!$_ajax) { if (strpos($_SERVER['PHP_SELF'], 'core') || strpos($_SERVER['PHP_SELF'], 'desktop')) { header('Location:../../index.php?' . trim($getParams, '&')); } else { header('Location:index.php?' . trim($getParams, '&')); } } return true; } connection::failed(); sleep(5); if (!$_ajax) { if (strpos($_SERVER['PHP_SELF'], 'core') || strpos($_SERVER['PHP_SELF'], 'desktop')) { header('Location:../../index.php?v=d&error=1'); } else { header('Location:index.php?v=' . $_GET['v'] . '&error=1'); } } return false; }
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; } }