Example #1
0
 private static function baseUrl()
 {
     if (config::byKey('nodeJsKey') == '') {
         self::updateKey();
     }
     return '127.0.0.1:' . config::byKey('nodeJsInternalPort') . '?key=' . config::byKey('nodeJsKey') . '&';
 }
 public static function runDeamon()
 {
     if (!file_exists('/opt/homebridge/config.json')) {
         $response = array();
         $platform = array();
         $response['description'] = "Configuration Jeedom";
         $platform['platform'] = "Jeedom";
         $platform['name'] = "Jeedom";
         $platform['jeedom_ip'] = "127.0.0.1";
         $platform['jeedom_port'] = config::byKey('internalPort');
         $platform['jeedom_url'] = config::byKey('internalComplement');
         $platform['jeedom_api_key'] = config::byKey('api');
         $response['platforms'] = array();
         $response['platforms'][] = $platform;
         $response['accessories'] = array();
         $fp = fopen('/opt/homebridge/config.json', 'w');
         fwrite($fp, json_encode($response));
         fclose($fp);
     }
     log::add('homebridge', 'info', 'Lancement du démon homebridge');
     $cmd = 'nice -n 19 /usr/bin/nodejs /opt/homebridge/app.js';
     log::add('homebridge', 'info', 'Lancement démon homebridge : ' . $cmd);
     $result = exec('nohup ' . $cmd . ' >> ' . log::getPathToLog('homebridge') . ' 2>&1 &');
     if (!self::deamonRunning()) {
         sleep(10);
         if (!self::deamonRunning()) {
             log::add('homebridge', 'error', 'Impossible de lancer le démon homebridge', 'unableStartDeamon');
             return false;
         }
     }
     message::removeAll('homebridge', 'unableStartDeamon');
     log::add('homebridge', 'info', 'Démon homebridge lancé');
 }
Example #3
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";
}
Example #4
0
function remove()
{
    $cron = cron::byId(config::byKey('xPLDeamonCronId', 'xPL'));
    if (is_object($cron)) {
        $cron->remove();
    }
    config::remove('xPLDeamonCronId', 'xPL');
}
Example #5
0
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";
}
Example #6
0
 public function execute($_options = null)
 {
     $request = str_replace('#API#', config::byKey('api'), $this->getConfiguration('request'));
     if ($_options != null) {
         switch ($this->getType()) {
             case 'action':
                 switch ($this->getSubType()) {
                     case 'slider':
                         $request = str_replace('#slider#', $_options['slider'], $request);
                         break;
                     case 'color':
                         $request = str_replace('#color#', $_options['color'], $request);
                         break;
                     case 'message':
                         $replace = array('#title#', '#message#');
                         $replaceBy = array($_options['title'], $_options['message']);
                         if ($_options['message'] == '' || $_options['title'] == '') {
                             throw new Exception('[Script] Le message et le sujet ne peuvent être vide');
                         }
                         $request = str_replace($replace, $replaceBy, $request);
                         break;
                 }
                 break;
         }
     }
     switch ($this->getConfiguration('requestType')) {
         case 'http':
             $request_http = new com_http($request);
             log::add('script', 'info', 'Execution http de "' . $request . '"');
             return $request_http->exec();
             break;
         case 'script':
             $pathinfo = pathinfo($request);
             switch ($pathinfo['extension']) {
                 case 'php':
                     $request_shell = new com_shell('php ' . $request);
                     break;
                 case 'rb':
                     $request_shell = new com_shell('ruby ' . $request);
                     break;
                 case 'py':
                     $request_shell = new com_shell('python ' . $request);
                     break;
                 case 'pl':
                     $request_shell = new com_shell('perl ' . $request);
                     break;
                 default:
                     $request_shell = new com_shell($request);
                     break;
             }
             log::add('script', 'info', 'Execution shell de "' . $request . '"');
             return $request_shell->exec();
             break;
     }
     return false;
 }
 public static function updateporkfolio()
 {
     log::remove('porkfolio_update');
     $clientid = config::byKey('clientid', 'porkfolio', 0);
     $clientsecret = config::byKey('clientsecret', 'porkfolio', 0);
     $username = config::byKey('username', 'porkfolio', 0);
     $password = config::byKey('password', 'porkfolio', 0);
     $cmd = '/usr/bin/python ' . dirname(__FILE__) . '/../../3rdparty/py-wink-adapt/login.py ' . $clientid . ' ' . $clientsecret . ' ' . $username . ' ' . $password;
     $cmd .= ' >> ' . log::getPathToLog('porkfolio_update') . ' 2>&1 &';
     exec($cmd);
 }
Example #8
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');
            }
        }
    }
}
Example #9
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");
}
Example #10
0
 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');
 }
Example #11
0
<?php

if (!isConnect('admin')) {
    throw new Exception('Error 401 Unauthorized');
}
sendVarToJS('eqType', 'bluetooth');
$secure = 0;
$options = array();
$port = config::byKey('port', 'bluetooth');
echo '<div class="row row-overflow">

    <div class="col-lg-12 eqLogic" style="border-left: solid 1px #EEE; padding-left: 25px;">
        <div class="row">
            <div class="col-lg-12">
               <legend>{{équipements Bluetooth à proximité}}</legend> 
            </div>
        </div>
        <button onclick="printDiscoverBT()">{{Rafraichir}}</button><br><br>
        <table id="table_discover_bt" class="table table-bordered table-condensed">
            <thead>
                <tr>
                    <th>{{MAC}}</th>
                    <th>{{Nom}}</th>
                    <th>{{Type}}</th>
                    <th>{{Services}}</th>
                    <th>{{Action}}</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
Example #12
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;
 }
Example #13
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;
 }
Example #14
0
 public static function connectToLDAP()
 {
     $ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port'));
     ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
     ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
     if (ldap_bind($ad, config::byKey('ldap:username'), config::byKey('ldap:password'))) {
         return $ad;
     }
     return false;
 }
Example #15
0
 public function save()
 {
     if (trim($this->getName()) == '') {
         throw new Exception(__('Le nom du widget ne peut etre vide', __FILE__));
     }
     $allowWritePath = config::byKey('allowWriteDir', 'widget');
     if (!hadFileRight($allowWritePath, $this->generatePath())) {
         throw new Exception(__('Vous n\'etes pas autoriser à écrire : ', __FILE__) . $this->generatePath());
     }
     file_put_contents($this->generatePath(), $this->getContent());
     if (realpath($this->getPath()) != realpath($this->generatePath())) {
         if (file_exists($this->getPath())) {
             unlink($this->getPath());
             $informations = explode('.', $this->getPath());
             $name = $informations[count($informations) - 2];
             $type = $informations[count($informations) - 4];
             $subtype = $informations[count($informations) - 3];
             $cmds = cmd::searchTemplate('"' . $this->getVersion() . '":"' . $name . '"', null, $type, $subtype);
             foreach ($cmds as $cmd) {
                 $cmd->setTemplate($this->getVersion(), $this->getName());
                 $cmd->save();
             }
         }
         if (is_dir(str_replace('.html', '', $this->getPath()))) {
             if (!rename(str_replace('.html', '', $this->getPath()), str_replace('.html', '', $this->generatePath()))) {
                 throw new Exception(__('Impossible de déplacer : ', __FILE__) . str_replace('.html', '', $this->getPath()) . __(' vers ', __FILE__) . str_replace('.html', '', $this->generatePath()));
             }
         }
     }
     foreach ($this->getUsedBy() as $cmd) {
         $cmd->save();
     }
     return true;
 }
Example #16
0
 public function getDirectUrlAccess()
 {
     $url = '/core/api/jeeApi.php?apikey=' . config::byKey('api') . '&type=cmd&id=' . $this->getId();
     if ($this->getType() == 'action') {
         switch ($this->getSubType()) {
             case 'slider':
                 $url .= '&slider=50';
                 break;
             case 'color':
                 $url .= '&color=#123456';
                 break;
             case 'message':
                 $url .= '&title=montitre&message=monmessage';
                 break;
         }
     }
     return network::getNetworkAccess('external') . $url;
 }
Example #17
0
 public static function tendance($_cmd_id, $_period = '1 hour', $_threshold = '')
 {
     $cmd = cmd::byId(trim(str_replace('#', '', $_cmd_id)));
     if (!is_object($cmd)) {
         return '';
     }
     if ($cmd->getIsHistorized() == 0) {
         return '';
     }
     $endTime = date('Y-m-d H:i:s');
     if (str_word_count($_period) == 1 && is_numeric(trim($_period)[0])) {
         $startTime = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' -' . $_period));
     } else {
         $startTime = date('Y-m-d H:i:s', strtotime($_period));
         if ($startTime == date('Y-m-d H:i:s', strtotime(0))) {
             return '';
         }
     }
     $tendance = $cmd->getTendance($startTime, $endTime);
     if ($_threshold != '') {
         $maxThreshold = $_threshold;
         $minThreshold = -$_threshold;
     } else {
         $maxThreshold = config::byKey('historyCalculTendanceThresholddMax');
         $minThreshold = config::byKey('historyCalculTendanceThresholddMin');
     }
     if ($tendance > $maxThreshold) {
         return 1;
     }
     if ($tendance < $minThreshold) {
         return -1;
     }
     return 0;
 }
Example #18
0
 public static function cron()
 {
     if (config::byKey('market::allowDNS') == 1 && !network::test('external', false, 120)) {
         network::dns_start();
     }
     if (config::byKey('network::disableMangement') == 1) {
         return;
     }
     if (!jeedom::isCapable('sudo')) {
         return;
     }
     try {
         $gws = self::checkGw();
         if (count($gws) == 0) {
             log::add('network', 'error', __('Aucune interface réseau trouvée, je redemarre tous les réseaux', __FILE__));
             exec('sudo service networking restart');
             return;
         }
         foreach ($gws as $iface => $gw) {
             if ($gw['ping'] != 'ok') {
                 if (strpos($iface, 'tun') !== false) {
                     continue;
                 }
                 if (strpos($iface, 'br0') !== false) {
                     continue;
                 }
                 log::add('network', 'error', __('La passerelle distante de l\'interface ', __FILE__) . $iface . __(' est injoignable, je la redemarre pour essayer de corriger', __FILE__));
                 exec('sudo ifdown ' . $iface);
                 sleep(5);
                 exec('sudo ifup --force ' . $iface);
             }
         }
     } catch (Exception $e) {
     }
 }
Example #19
0
        ?>
                      <div class="form-group">
                        <label class="col-sm-3 control-label">{{Wakeup (seconde)}}</label>
                        <div class="col-sm-2">
                            <input class="form-control" id="in_wakeUpTime" value="<?php 
        echo $wakeup;
        ?>
" />
                        </div>
                        <div class="col-sm-2">
                            <a class="btn btn-success" id="bt_valideWakeup"><i class="fa fa-check"></i> Valider</a>
                        </div>
                    </div>
                    <?php 
    }
    if (config::byKey('isOpenZwave', 'zwave', 0) == 1) {
        ?>
                  <div class="form-group">
                    <label class="col-sm-3 control-label">{{Polling (par pas de 30 sec)}}</label>
                    <div class="col-sm-2">
                        <input class="form-control" id="in_pollingTime" value="<?php 
        echo $eqLogic->getPolling();
        ?>
" />
                    </div>
                    <div class="col-sm-2">
                        <a class="btn btn-success" id="bt_validePolling"><i class="fa fa-check"></i> Valider</a>
                    </div>
                </div>
                <?php 
    }
Example #20
0
 public static function listAllVehicles()
 {
     $url = "https://owner-api.teslamotors.com/api/1/vehicles";
     $token = config::byKey('token', 'tesla');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_HEADER, FALSE);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $token, 'Content-Type: application/json'));
     $response = curl_exec($ch);
     $error = curl_error($ch);
     $errno = curl_errno($ch);
     curl_close($ch);
     if ($errno) {
         throw new Exception(__("Curl Error : " . curl_strerror($errno), __FILE__));
     }
     $list = json_decode($response, false, 512, JSON_BIGINT_AS_STRING);
     return $list;
 }
Example #21
0
<?php

/* This file is part of Jeedom.
*
* Jeedom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Jeedom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
*/
require_once dirname(__FILE__) . '/../../../core/php/core.inc.php';
foreach ($argv as $arg) {
    $argList = explode('=', $arg);
    if ($argList[0] == 'api' && !isset($_GET['api'])) {
        $_GET['api'] = $argList[1];
    }
}
if (config::byKey('api') != init('api')) {
    log::add('core', 'Error', 'Problème dans la clef API, vous n\'etez pas autorisé à effectuer cette action (PHP Scripts)');
    die;
}
Example #22
0
    $_SERVER['REDIRECT_STATUS'] = 404;
    echo "<h1>404 Not Found</h1>";
    echo "The page that you have requested could not be found.";
    exit;
}
require_once dirname(__FILE__) . "/core.inc.php";
if (isset($argv)) {
    foreach ($argv as $arg) {
        $argList = explode('=', $arg);
        if (isset($argList[0]) && isset($argList[1])) {
            $_GET[$argList[0]] = $argList[1];
        }
    }
}
try {
    set_time_limit(config::byKey('maxExecTimeScript', 10));
    $plugin_id = init('plugin_id');
    if ($plugin_id == '') {
        throw new Exception(__('Le plugin ID ne peut être vide', __FILE__));
    }
    $plugin = plugin::byId($plugin_id);
    if (!is_object($plugin)) {
        throw new Exception(__('Plugin non trouvé : ', __FILE__) . init('plugin_id'));
    }
    $function = init('function');
    if ($function == '') {
        throw new Exception(__('La fonction ne peut être vide', __FILE__));
    }
    if (!class_exists($plugin_id) || !method_exists($plugin_id, $function)) {
        throw new Exception(__('Il n\'existe aucune méthode : ', __FILE__) . $plugin_id . '::' . $function);
    }
Example #23
0
 public static function cron()
 {
     $sql = 'DELETE FROM `connection` 
             WHERE id NOT IN 
             (SELECT * FROM (
                 SELECT id 
                 FROM `connection`
                 ORDER BY `datetime` DESC LIMIT 100
             ) tmp);';
     DB::Prepare($sql, array(), DB::FETCH_TYPE_ROW);
     if (is_numeric(config::byKey('security::bantime'))) {
         $sql = 'UPDATE `connection`
             SET `status` = "Not connected"
             WHERE status="Ban"
                 AND `datetime` < DATE_SUB(NOW(),INTERVAL ' . config::byKey('security::bantime') . ' MINUTE)';
         DB::Prepare($sql, array(), DB::FETCH_TYPE_ROW);
     }
 }
Example #24
0
 $default_image = 'core/img/no_image.gif';
 switch ($market->getType()) {
     case 'widget':
         $default_image = 'core/img/no-image-widget.png';
         break;
     case 'plugin':
         $default_image = 'core/img/no-image-plugin.png';
         break;
     case 'camera':
         $default_image = 'core/img/no-image-camera.png';
         break;
     case 'script':
         $default_image = 'core/img/no-image-script.png';
         break;
 }
 $urlPath = config::byKey('market::address') . '/' . $market->getImg('icon');
 if ($market->getType() == 'widget') {
     echo '<img class="lazy" src="' . $default_image . '" data-original="' . $urlPath . '" height="105" width="95" style="margin-left: 20px;border: 1px solid #C5C5C5;border-radius:5px; padding: 3px" />';
 } else {
     echo '<img class="lazy" src="' . $default_image . '" data-original="' . $urlPath . '" height="105" width="95" />';
 }
 echo "</center>";
 echo '<span style="font-size : 1.1em;position:relative; top : 15px;word-break: break-all;white-space: pre-wrap;word-wrap: break-word;">' . $market->getName() . '</span>';
 $note = $market->getRating();
 echo '<span style="position : absolute;bottom : 5px;left : 5px;font-size : 0.7em;">';
 for ($i = 1; $i < 6; $i++) {
     if ($i <= $note) {
         echo '<i class="fa fa-star"></i>';
     } else {
         echo '<i class="fa fa-star-o"></i>';
     }
 public static function stopDeamon()
 {
     self::stop();
     $pid_file = '/tmp/openzwave.pid';
     if (file_exists($pid_file)) {
         $pid = intval(trim(file_get_contents($pid_file)));
         posix_kill($pid, 15);
         if (self::deamonRunning()) {
             sleep(1);
             posix_kill($pid, 9);
         }
         if (self::deamonRunning()) {
             sleep(1);
             exec('kill -9 ' . $pid . ' > /dev/null 2>&1');
         }
     }
     exec('fuser -k ' . config::byKey('port_server', 'openzwave', 8083) . '/tcp > /dev/null 2>&1');
     exec('sudo fuser -k ' . config::byKey('port_server', 'openzwave', 8083) . '/tcp > /dev/null 2>&1');
     exec("ps aux | grep -ie 'openZWave.py' | awk '{print \$2}' | xargs kill -9 > /dev/null 2>&1");
     return self::deamonRunning();
 }
Example #26
0
    <span class="marketAttr" data-l1key="changelog" style="word-wrap: break-word;white-space: -moz-pre-wrap;white-space: pre-wrap;" ></span>
</div>
</div>
<br/>
<div class='row'>
    <div class='col-sm-6'>
        <legend>Avis</legend>
        <div class='row'>
            <div class='col-sm-6'>
                <center>
                    <span class="marketAttr" data-l1key="rating" style="font-size: 4em;"></span>/5
                </center>
            </div>
            <div class='col-sm-6'>
                <?php 
if (config::byKey('market::apikey') != '' || config::byKey('market::username') != '' && config::byKey('market::password') != '') {
    ?>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">{{Ma Note}}</label>
                        <div class="col-sm-8">
                            <span><input type="number" class="rating" id="in_myRating" data-max="5" data-empty-value="0" data-min="1" data-clearable="Effacer" value="<?php 
    echo $market->getRating('user');
    ?>
" /></span>
                        </div>
                    </div><br/>
                    <?php 
}
?>
                </div>
            </div>
Example #27
0
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
 */
try {
    require_once dirname(__FILE__) . '/../../core/php/core.inc.php';
    include_file('core', 'authentification', 'php');
    if (init('action') == 'getInfoApplication') {
        if (!isConnect()) {
            throw new Exception(__('401 - Accès non autorisé', __FILE__), -1234);
        }
        $_SESSION['user']->refresh();
        $return = array();
        $return['user_id'] = $_SESSION['user']->getId();
        $return['nodeJsKey'] = config::byKey('nodeJsKey');
        $return['userProfils'] = $_SESSION['user']->getOptions();
        $return['plugins'] = array();
        foreach (plugin::listPlugin(true) as $plugin) {
            if ($plugin->getMobile() != '') {
                $return['plugins'][] = utils::o2a($plugin);
            }
        }
        $return['custom'] = array();
        $return['custom']['js'] = file_exists(dirname(__FILE__) . '/../../mobile/custom/custom.js');
        $return['custom']['css'] = file_exists(dirname(__FILE__) . '/../../mobile/custom/custom.css');
        ajax::success($return);
    }
    if (!isConnect('admin')) {
        throw new Exception(__('401 - Accès non autorisé', __FILE__), -1234);
    }
Example #28
0
			<div class="col-sm-2">
				<input type="checkbox" class="configKey bootstrapSwitch" data-l1key="directPush" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">{{Gestion du démon}}</label>
			<div class="col-sm-8">
				<a class="btn btn-success" id="bt_startopenZwaveDemon"><i class='fa fa-play'></i> {{(Re)démarrer}}</a>
				<a class="btn btn-danger" id="bt_stopopenZwaveDemon"><i class='fa fa-stop'></i> {{Arrêter}}</a>
				<a class="btn btn-warning" id="bt_launchOpenZwaveInDebug"><i class="fa fa-exclamation-triangle"></i> {{Lancer en mode debug}}</a>
			</div>
		</div>
	</fieldset>
</form>
<?php 
if (config::byKey('jeeNetwork::mode') == 'master') {
    foreach (jeeNetwork::byPlugin('openzwave') as $jeeNetwork) {
        ?>
		<form class="form-horizontal slaveConfig" data-slave_id="<?php 
        echo $jeeNetwork->getId();
        ?>
">
			<fieldset>
				<legend>{{Démon sur l'esclave}} <?php 
        echo $jeeNetwork->getName();
        ?>
</legend>
				<div class="form-group">
					<label class="col-lg-4 control-label">{{Port clé Z-Wave}}</label>
					<div class="col-lg-4">
						<select class="slaveConfigKey form-control" data-l1key="port">
Example #29
0
<?php

if (!isConnect('admin')) {
    throw new Exception('{{401 - Accès non autorisé}}');
}
include_file('3rdparty', 'jquery.fileupload/jquery.ui.widget', 'js');
include_file('3rdparty', 'jquery.fileupload/jquery.iframe-transport', 'js');
include_file('3rdparty', 'jquery.fileupload/jquery.fileupload', 'js');
sendVarToJS('eqType', 'openzwave');
sendVarToJS('marketAddr', config::byKey('market::address'));
sendVarToJS('listServerZwave', openzwave::listServerZwave());
echo '<div id="div_inclusionAlert"></div>';
$controlerState = 0;
$state = 10;
foreach (openzwave::listServerZwave() as $id => $server) {
    if (isset($server['name'])) {
        try {
            $controlerState = openzwave::callOpenzwave('/ZWaveAPI/Run/network.GetControllerStatus()', $id);
            if (isset($controlerState['result']['data'])) {
                $state = $controlerState['result']['data']['networkstate']['value'];
                $controlerState = $controlerState['result']['data']['mode']['value'];
            }
        } catch (Exception $e) {
            $controlerState = null;
        }
        if ($state < 7) {
            echo '<div class="alert jqAlert alert-warning" id="div_inclusionAlert' . $id . '" style="margin : 0px 5px 15px 15px; padding : 7px 35px 7px 15px;">{{Openzwave est en cours de démarrage sur ' . $server['name'] . '.}}</div>';
        }
        if ($controlerState === 0) {
            echo '<div id="div_inclusionAlert' . $id . '"></div>';
        }
Example #30
0
 public static function runDeamon()
 {
     log::add('rfxcom', 'info', 'Lancement du démon RFXcom');
     $port = config::byKey('port', 'rfxcom');
     if (!file_exists($port)) {
         config::save('port', '', 'rfxcom');
         throw new Exception('Le port : ' . $port . ' n\'éxiste pas');
     }
     $rfxcom_path = realpath(dirname(__FILE__) . '/../../ressources/rfxcmd');
     $trigger = file_get_contents($rfxcom_path . '/trigger_tmpl.xml');
     $config = file_get_contents($rfxcom_path . '/config_tmpl.xml');
     $pid_file = realpath(dirname(__FILE__) . '/../../../../tmp') . '/rfxcom.pid';
     if (file_exists($rfxcom_path . '/trigger.xml')) {
         unlink($rfxcom_path . '/trigger.xml');
     }
     if (file_exists($rfxcom_path . '/config.xml')) {
         unlink($rfxcom_path . '/config.xml');
     }
     file_put_contents($rfxcom_path . '/trigger.xml', str_replace('#path#', $rfxcom_path . '/../../core/php/jeeRfxcom.php', $trigger));
     $config = str_replace('#log_path#', log::getPathToLog('rfxcmd'), str_replace('#trigger_path#', $rfxcom_path . '/trigger.xml', $config));
     file_put_contents($rfxcom_path . '/config.xml', $config);
     chmod($rfxcom_path . '/trigger.xml', 0777);
     chmod($rfxcom_path . '/config.xml', 0777);
     $cmd = '/usr/bin/python ' . $rfxcom_path . '/rfxcmd.py -z -d ' . $port;
     $cmd .= ' -o ' . $rfxcom_path . '/config.xml --pidfile=' . $pid_file;
     log::add('rfxcmd', 'info', 'Lancement démon rfxcmd : ' . $cmd);
     $result = exec('nohup ' . $cmd . ' >> ' . log::getPathToLog('rfxcmd') . ' 2>&1 &');
     if (strpos(strtolower($result), 'error') !== false || strpos(strtolower($result), 'traceback') !== false) {
         log::add('rfxcom', 'error', $result);
         return false;
     }
     if (!self::deamonRunning()) {
         sleep(10);
         if (!self::deamonRunning()) {
             log::add('rfxcom', 'info', 'Impossible de lancer le démon RFXcom');
             return false;
         }
     }
     log::add('rfxcom', 'info', 'Démon RFXcom lancé');
 }