public static function sendToController($destination, $sensor, $command, $acknowledge, $type, $payload)
 {
     if (config::byKey('externalDeamon', 'mySensors', 0) == 2) {
         $jeeSlave = jeeNetwork::byId(config::byKey('jeeSlave', 'mySensors'));
         $urlNode = getIpFromString($jeeSlave->getIp());
     } else {
         $urlNode = "127.0.0.1";
     }
     log::add('mySensors', 'info', $urlNode);
     $msg = $destination . ";" . $sensor . ";" . $command . ";" . $acknowledge . ";" . $type . ";" . $payload;
     log::add('mySensors', 'info', $msg);
     $fp = fsockopen($urlNode, 8019, $errno, $errstr);
     if (!$fp) {
         echo "ERROR: {$errno} - {$errstr}<br />\n";
     } else {
         fwrite($fp, $msg);
         fclose($fp);
     }
 }
示例#2
0
 public static function getNetworkAccess($_mode = 'auto', $_protocole = '', $_default = '', $_test = true)
 {
     if ($_mode == 'auto') {
         $_mode = self::getUserLocation();
     }
     if ($_test && !self::test($_mode, false)) {
         self::checkConf($_mode);
     }
     if ($_mode == 'internal') {
         if (strpos(config::byKey('internalAddr', 'core', $_default), 'http://') != false || strpos(config::byKey('internalAddr', 'core', $_default), 'https://') !== false) {
             config::save('internalAddr', str_replace(array('http://', 'https://'), '', config::byKey('internalAddr', 'core', $_default)));
         }
         if ($_protocole == 'ip' || $_protocole == 'dns') {
             return config::byKey('internalAddr', 'core', $_default);
         }
         if ($_protocole == 'ip:port' || $_protocole == 'dns:port') {
             return config::byKey('internalAddr') . ':' . config::byKey('internalPort', 'core', 80);
         }
         if ($_protocole == 'proto:ip:port' || $_protocole == 'proto:dns:port') {
             return config::byKey('internalProtocol') . config::byKey('internalAddr') . ':' . config::byKey('internalPort', 'core', 80);
         }
         if ($_protocole == 'proto:127.0.0.1:port:comp') {
             return config::byKey('internalProtocol') . '127.0.0.1:' . config::byKey('internalPort', 'core', 80) . config::byKey('internalComplement');
         }
         if ($_protocole == 'http:127.0.0.1:port:comp') {
             return 'http://127.0.0.1:' . config::byKey('internalPort', 'core', 80) . config::byKey('internalComplement');
         }
         return config::byKey('internalProtocol') . config::byKey('internalAddr') . ':' . config::byKey('internalPort', 'core', 80) . config::byKey('internalComplement');
     }
     if ($_mode == 'dnsjeedom') {
         return config::byKey('jeedom::url');
     }
     if ($_mode == 'external') {
         if ($_protocole == 'ip') {
             if (config::byKey('market::allowDNS') == 1 && config::byKey('jeedom::url') != '') {
                 return getIpFromString(config::byKey('jeedom::url'));
             }
             return getIpFromString(config::byKey('externalAddr'));
         }
         if ($_protocole == 'ip:port') {
             if (config::byKey('market::allowDNS') == 1 && config::byKey('jeedom::url') != '') {
                 $url = parse_url(config::byKey('jeedom::url'));
                 if (isset($url['host'])) {
                     if (isset($url['port'])) {
                         return getIpFromString($url['host']) . ':' . $url['port'];
                     } else {
                         return getIpFromString($url['host']);
                     }
                 }
             }
             return config::byKey('externalAddr') . ':' . config::byKey('externalPort', 'core', 80);
         }
         if ($_protocole == 'proto:dns:port' || $_protocole == 'proto:ip:port') {
             if (config::byKey('market::allowDNS') == 1 && config::byKey('jeedom::url') != '') {
                 $url = parse_url(config::byKey('jeedom::url'));
                 $return = '';
                 if (isset($url['scheme'])) {
                     $return = $url['scheme'] . '://';
                 }
                 if (isset($url['host'])) {
                     if (isset($url['port'])) {
                         return $return . $url['host'] . ':' . $url['port'];
                     } else {
                         return $return . $url['host'];
                     }
                 }
             }
             return config::byKey('externalProtocol') . config::byKey('externalAddr') . ':' . config::byKey('externalPort', 'core', 80);
         }
         if ($_protocole == 'dns:port') {
             if (config::byKey('market::allowDNS') == 1 && config::byKey('jeedom::url') != '') {
                 $url = parse_url(config::byKey('jeedom::url'));
                 if (isset($url['host'])) {
                     if (isset($url['port'])) {
                         return $url['host'] . ':' . $url['port'];
                     } else {
                         return $url['host'];
                     }
                 }
             }
             return config::byKey('externalAddr') . ':' . config::byKey('externalPort', 'core', 80);
         }
         if ($_protocole == 'proto') {
             if (config::byKey('market::allowDNS') == 1 && config::byKey('jeedom::url') != '') {
                 $url = parse_url(config::byKey('jeedom::url'));
                 if (isset($url['scheme'])) {
                     return $url['scheme'] . '://';
                 }
             }
             return config::byKey('externalProtocol');
         }
         if (config::byKey('market::allowDNS') == 1 && config::byKey('jeedom::url') != '') {
             return config::byKey('jeedom::url');
         }
         return config::byKey('externalProtocol') . config::byKey('externalAddr') . ':' . config::byKey('externalPort', 'core', 80) . config::byKey('externalComplement');
     }
 }
示例#3
0
 public function getRealIp()
 {
     return getIpFromString($this->getIp());
 }