From: Vincent Vanwaelscappel Date: Thu, 23 Mar 2023 16:04:09 +0000 (+0100) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e2ed3e70d4af6e796f049e31b1cfe98297aef57d;p=tortuga-home.git . --- diff --git a/.docker/config/httpd/httpd.conf b/.docker/config/httpd/httpd.conf index c7da471..36ef7e9 100644 --- a/.docker/config/httpd/httpd.conf +++ b/.docker/config/httpd/httpd.conf @@ -289,8 +289,18 @@ DocumentRoot "/usr/local/apache2/htdocs" # Controls who can get stuff from this server. # Require all granted + +RemoteIPHeader X-Forwarded-For +RemoteIPInternalProxy nginx-proxy + + + + Require ip 127.0.0.0/8 192.168.13.0/24 172.0.0.0/8 + + + ProxyPassMatch ^/(.*\.php(/.*)?)$ "fcgi://tortugahome:9000/application/$1" timeout=1800 # @@ -330,12 +340,12 @@ LogLevel warn # The following directives define some format nicknames for use with # a CustomLog directive (see below). # - LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined - LogFormat "%h %l %u %t \"%r\" %>s %b" common + LogFormat "%a %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%a %h %l %u %t \"%r\" %>s %b" common # You need to enable mod_logio.c to use %I and %O - LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio + LogFormat "%a %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio # diff --git a/.htaccess b/.htaccess index c6081bf..e0f71fe 100644 --- a/.htaccess +++ b/.htaccess @@ -1,4 +1,3 @@ -Require ip 127.0.0.0/8 88.190.245.49 192.168.0.0/16 172.0.0.0/8 Options +FollowSymlinks RewriteEngine on diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index 9ae1436..8f6041b 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + " diff --git a/.idea/workspace.xml b/.idea/workspace.xml index aaefba8..a80036a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,12 @@ + + + + diff --git a/config/sdb.php b/config/sdb.php index 37139fe..5d0a221 100644 --- a/config/sdb.php +++ b/config/sdb.php @@ -15,19 +15,21 @@ config('HIDEMASK_TIMEOUT', 250); config('THEME', '#92475c'); if (DISPLAYINTERFACE) { - $c = sdb(); - $shortcuts['lights'] = $c['all']; - $nav = ['home', 'lights','water', 'music', 'media', 'remote', 'switch', 'settings', 'alert', 'off']; + $c = sdb(); + $shortcuts['lights'] = $c['all']; + $nav = ['home', 'lights', 'water', 'music', 'media', 'remote', 'switch', 'settings', 'alert', 'off']; - include_once ROOT . '/config/music.php'; + include_once ROOT . '/config/music.php'; - $favoriteslights = [ - ['type' => 'volume', 'volume' => config('VOLUME_STEP') . '%', 'increase' => '+', 'label' => ''], - ['type' => 'volume', 'volume' => config('VOLUME_STEP') . '%', 'increase' => '-', 'label' => ''], - ]; - $favoriteslights[] = array_merge($allmusics['France Info'], array('volume' => 50)); - $favoriteslights = array_merge($favoriteslights, $c['favorites']); - include "water.php"; - include "media.php"; - include "default.php"; + $favoriteslights = [ + ['type' => 'volume', 'volume' => config('VOLUME_STEP') . '%', 'increase' => '+', 'label' => ''], + ['type' => 'volume', 'volume' => config('VOLUME_STEP') . '%', 'increase' => '-', 'label' => ''], + ]; + $favoriteslights[] = array_merge($allmusics['France Info'], array('volume' => 45)); + $favoriteslights = array_merge($favoriteslights, $c['favorites']); + $favoriteslights[] = array_merge($allmusics['FIP'], array('volume' => 50)); + $favoriteslights[] = ['type' => 'phone', 'task' => 'Balance', 'phone' => 'sdb', 'label' => 'Balance']; + include "water.php"; + include "media.php"; + include "default.php"; } \ No newline at end of file diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 8c483f6..4089440 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -59,586 +59,563 @@ profile('Loaded libraries', __FILE__, __LINE__); register_shutdown_function('shutdown'); -function runAtEnd($code) -{ - global $endQueue; - $endQueue[] = $code; +function runAtEnd($code) { + global $endQueue; + $endQueue[] = $code; } -function shutdown() -{ - global $endQueue; - returnHttpResponse(); - foreach ($endQueue as $code) { - eval($code); - } +function shutdown() { + global $endQueue; + returnHttpResponse(); + foreach ($endQueue as $code) { + eval($code); + } } -function getCurrentConfig() -{ - global $forceConfig; +function getCurrentConfig() { + global $forceConfig; - $ips = ['192.168.13.31' => 'cuisine', '192.168.13.30' => 'salon', '192.168.13.32' => 'sdb']; + $ips = ['192.168.13.31' => 'cuisine', '192.168.13.30' => 'salon', '192.168.13.32' => 'sdb']; - if (!isset($forceConfig) && isset($_SERVER['HTTP_HOST']) && stristr($_SERVER['HTTP_HOST'], '.home.tortuga.enhydra.fr')) { - $e = explode('.', $_SERVER['HTTP_HOST']); - $_GET['c'] = array_shift($e); - } + if (!isset($forceConfig) && isset($_SERVER['HTTP_HOST']) && stristr($_SERVER['HTTP_HOST'], '.home.tortuga.enhydra.fr')) { + $e = explode('.', $_SERVER['HTTP_HOST']); + $_GET['c'] = array_shift($e); + } - if (isset($forceConfig)) { - $_GET['c'] = $forceConfig; - } + if (isset($forceConfig)) { + $_GET['c'] = $forceConfig; + } - $expires = time() + 60 * 60 * 24 * 30; - if (isset($_GET['c'])) { - $_SESSION['homeconfig'] = $_GET['c']; - } + $expires = time() + 60 * 60 * 24 * 30; + if (isset($_GET['c'])) { + $_SESSION['homeconfig'] = $_GET['c']; + } - if (!isset($_SESSION['homeconfig'])) { - if (isset($_SERVER['HTTP_X_REAL_IP']) && isset($ips[$_SERVER['HTTP_X_REAL_IP']])) { - $c = $ips[$_SERVER['HTTP_X_REAL_IP']]; - } else { - $c = 'salon'; - } - $_SESSION['homeconfig'] = $c; - } - return $_SESSION['homeconfig']; + if (!isset($_SESSION['homeconfig'])) { + if (isset($_SERVER['HTTP_X_REAL_IP']) && isset($ips[$_SERVER['HTTP_X_REAL_IP']])) { + $c = $ips[$_SERVER['HTTP_X_REAL_IP']]; + } else { + $c = 'salon'; + } + $_SESSION['homeconfig'] = $c; + } + return $_SESSION['homeconfig']; } -function config($key = null, $value = null) -{ - global $config; - if (!isset($config)) { - $config = ['SLEEPSCREEN' => 0, 'MUSICPLAYER' => 'squeezebox', 'SLEEPTYPE' => 'off', 'DEVICE' => getCurrentConfig(), 'VOLUME_DEVICE' => 'auto']; - } - if (null == $key) { - return $config; - } - if (null == $value && isset($config[$key])) { - return $config[$key]; - } - $config[$key] = $value; - return $config[$key]; +function config($key = null, $value = null) { + global $config; + if (!isset($config)) { + $config = ['SLEEPSCREEN' => 0, 'MUSICPLAYER' => 'squeezebox', 'SLEEPTYPE' => 'off', 'DEVICE' => getCurrentConfig(), 'VOLUME_DEVICE' => 'auto']; + } + if (null == $key) { + return $config; + } + if (null == $value && isset($config[$key])) { + return $config[$key]; + } + $config[$key] = $value; + return $config[$key]; } -function hasConfig($key) -{ - global $config; - return isset($config[$key]); +function hasConfig($key) { + global $config; + return isset($config[$key]); } -function getLinkHash($s) -{ - return sha1(json_encode($s)); +function getLinkHash($s) { + return sha1(json_encode($s)); } -function accordionClosed($accordionId) -{ - return getState($accordionId, '0') == '0'; +function accordionClosed($accordionId) { + return getState($accordionId, '0') == '0'; } -function shortcutDir($allshortcuts) -{ - $res = array(); - $hashs = array(); - if (!is_array($allshortcuts)) { - $allshortcuts = array(); - } - - - foreach ($allshortcuts as $name => $shortcuts) { - $cols = strpos($name, 'remote') !== 0; - - $size = ''; - if (isset($shortcuts['size'])) { - $size = ' data-size="' . $shortcuts['size'] . '"'; - unset($shortcuts['size']); - } - - $section = '
'; - $fit = ($name == 'remote-default'); - $i = 0; - if ($fit) { - $section .= '
'; - } - foreach ($shortcuts as $k => $s) { - if ($s['type'] == 'clear' || $s['type'] == 'accordion' || $s['type'] == 'accordion-end') { - if ($i % 2 == 1) { - $section .= '
'; - $i = 0; - } - - if ($s['type'] === 'clear') { - $section .= '
'; - } else if ($s['type'] === 'accordion') { - $section .= '' . $s['label'] . ''; - } else if ($s['type'] === 'accordion-end') { - $section .= ''; - } - - continue; - } - $size = ''; - if (isset($s['size'])) { - $size = ' data-size="' . $s['size'] . '"'; - } - if ($cols && $i % 2 == 0) { - $section .= '
'; - } - - $hash = getLinkHash($s); - $shortcut = shortcut($s, $hash); - $section .= $shortcut; - $hashs[$hash] = $shortcut; - - $i++; - if ($cols && $i % 2 == 0) { - $section .= '
'; - } - } - if ($cols && $i % 2 == 1) { - $section .= ''; - } - if ($fit) { - $section .= ''; - } - $section .= '
'; - $res[$name] = $section; - } - - $json = json_encode($res); - - connectRedis()->igbset('shortcuts.' . getCurrentConfig(), $json); - profile('save cache shortcuts', __FILE__, __LINE__); - - return 'SECTIONS = ' . $json . ';'; +function shortcutDir($allshortcuts) { + $res = array(); + $hashs = array(); + if (!is_array($allshortcuts)) { + $allshortcuts = array(); + } + + + foreach ($allshortcuts as $name => $shortcuts) { + $cols = strpos($name, 'remote') !== 0; + + $size = ''; + if (isset($shortcuts['size'])) { + $size = ' data-size="' . $shortcuts['size'] . '"'; + unset($shortcuts['size']); + } + + $section = '
'; + $fit = ($name == 'remote-default'); + $i = 0; + if ($fit) { + $section .= '
'; + } + foreach ($shortcuts as $k => $s) { + if ($s['type'] == 'clear' || $s['type'] == 'accordion' || $s['type'] == 'accordion-end') { + if ($i % 2 == 1) { + $section .= '
'; + $i = 0; + } + + if ($s['type'] === 'clear') { + $section .= '
'; + } else if ($s['type'] === 'accordion') { + $section .= '' . $s['label'] . ''; + } else if ($s['type'] === 'accordion-end') { + $section .= ''; + } + + continue; + } + $size = ''; + if (isset($s['size'])) { + $size = ' data-size="' . $s['size'] . '"'; + } + if ($cols && $i % 2 == 0) { + $section .= '
'; + } + + $hash = getLinkHash($s); + $shortcut = shortcut($s, $hash); + $section .= $shortcut; + $hashs[$hash] = $shortcut; + + $i++; + if ($cols && $i % 2 == 0) { + $section .= '
'; + } + } + if ($cols && $i % 2 == 1) { + $section .= ''; + } + if ($fit) { + $section .= ''; + } + $section .= '
'; + $res[$name] = $section; + } + + $json = json_encode($res); + + connectRedis()->igbset('shortcuts.' . getCurrentConfig(), $json); + profile('save cache shortcuts', __FILE__, __LINE__); + + return 'SECTIONS = ' . $json . ';'; } -function shortcut($s, $hash) -{ - $attrs = array(); - $markup = 'a'; - - if (isset($s['size'])) { - $attrs['data-size'] = $s['size']; - unset($s['size']); - } - - if (is_string($s)) { - return; - } - - $swcorner = ''; - - if ($s['type'] == 'ajax') { - $attrs['class'] = 'ajax'; - $attrs['href'] = $s['url']; - } elseif ($s['type'] == 'task') { - $attrs['class'] = 'ajax'; - $attrs['href'] = 'scripts/tortugatask.php?task=' . $s['command']; - } elseif ($s['type'] == 'light') { - $attrs['class'] = 'ajax'; - $attrs['href'] = 'scripts/light.php?scene=' . $s['scene']; - } elseif ($s['type'] == 'url') { - $attrs['href'] = $s['href']; - if (isset($s['iframe']) && $s['iframe']) { - $attrs['class'] = 'iframe'; - } else if (isset($s['tab']) && $s['tab']) { - $attrs['target'] = '_blank'; - } - } else if ($s['type'] == 'squeeze' || $s['type'] == 'squeeze_spotify') { - $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type']; - $attrs['class'] = 'ajax music'; - } else if ($s['type'] == 'squeeze_ambiance') { - $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_AMBIANCE_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type']; - $attrs['class'] = 'ajax'; - $attrs['data-squeeze-volume'] = 60; - $attrs['data-squeeze-player'] = config('SQUEEZEBOX_AMBIANCE_PLAYER'); - } else if ($s['type'] == 'vlc' || $s['type'] == 'omx') { - $attrs['href'] = $s['url']; - $attrs['class'] = $s['type']; - } elseif ($s['type'] == 'time') { - $attrs['href'] = isset($_GET['h']) && $_GET['h'] ? '//' . $_GET['h'] . '/' : '/'; - $attrs['data-init'] = "0"; - $attrs['data-init-function'] = "updateTime"; - $attrs['class'] = $s['type'] . ' info'; - if (!isset($s['label'])) { - $s['label'] = '-'; - } - } elseif ($s['type'] == 'time' || $s['type'] == 'separator' || $s['type'] == 'back') { - $attrs['class'] = $s['type'] . ' info'; - if (!isset($s['label'])) { - $s['label'] = '-'; - } - } elseif ($s['type'] == 'volume') { - $attrs['class'] = 'ajax'; - $attrs['href'] = 'scripts/volume.php?volume=' . $s['volume']; - if (isset($s['increase'])) { - $attrs['href'] .= '&increase=' . $s['increase']; - } - unset($s['volume']); - } else if ($s['type'] == 'weather') { - $attrs['class'] = $s['type'] . ' info'; - $attrs['data-init'] = "0"; - $attrs['data-init-function'] = "updateWeather"; - $s['label'] = ' +function shortcut($s, $hash) { + $attrs = array(); + $markup = 'a'; + + if (isset($s['size'])) { + $attrs['data-size'] = $s['size']; + unset($s['size']); + } + + if (is_string($s)) { + return; + } + + $swcorner = ''; + + if ($s['type'] == 'ajax') { + $attrs['class'] = 'ajax'; + $attrs['href'] = $s['url']; + } elseif ($s['type'] == 'task') { + $attrs['class'] = 'ajax'; + $attrs['href'] = 'scripts/tortugatask.php?task=' . $s['command']; + } elseif ($s['type'] == 'light') { + $attrs['class'] = 'ajax'; + $attrs['href'] = 'scripts/light.php?scene=' . $s['scene']; + } elseif ($s['type'] == 'url') { + $attrs['href'] = $s['href']; + if (isset($s['iframe']) && $s['iframe']) { + $attrs['class'] = 'iframe'; + } else if (isset($s['tab']) && $s['tab']) { + $attrs['target'] = '_blank'; + } + } else if ($s['type'] == 'squeeze' || $s['type'] == 'squeeze_spotify') { + $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type']; + $attrs['class'] = 'ajax music'; + } else if ($s['type'] == 'squeeze_ambiance') { + $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_AMBIANCE_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type']; + $attrs['class'] = 'ajax'; + $attrs['data-squeeze-volume'] = 60; + $attrs['data-squeeze-player'] = config('SQUEEZEBOX_AMBIANCE_PLAYER'); + } else if ($s['type'] == 'vlc' || $s['type'] == 'omx') { + $attrs['href'] = $s['url']; + $attrs['class'] = $s['type']; + } elseif ($s['type'] == 'time') { + $attrs['href'] = isset($_GET['h']) && $_GET['h'] ? '//' . $_GET['h'] . '/' : '/'; + $attrs['data-init'] = "0"; + $attrs['data-init-function'] = "updateTime"; + $attrs['class'] = $s['type'] . ' info'; + if (!isset($s['label'])) { + $s['label'] = '-'; + } + } elseif ($s['type'] == 'time' || $s['type'] == 'separator' || $s['type'] == 'back') { + $attrs['class'] = $s['type'] . ' info'; + if (!isset($s['label'])) { + $s['label'] = '-'; + } + } elseif ($s['type'] == 'volume') { + $attrs['class'] = 'ajax'; + $attrs['href'] = 'scripts/volume.php?volume=' . $s['volume']; + if (isset($s['increase'])) { + $attrs['href'] .= '&increase=' . $s['increase']; + } + unset($s['volume']); + } else if ($s['type'] == 'weather') { + $attrs['class'] = $s['type'] . ' info'; + $attrs['data-init'] = "0"; + $attrs['data-init-function'] = "updateWeather"; + $s['label'] = '
'; - } elseif ($s['type'] == 'traffic') { - $attrs['class'] = $s['type'] . ' info'; - $attrs['data-init'] = "0"; - $attrs['data-init-function'] = "updateTraffic"; - $s['label'] = '
Départ à
+ } elseif ($s['type'] == 'traffic') { + $attrs['class'] = $s['type'] . ' info'; + $attrs['data-init'] = "0"; + $attrs['data-init-function'] = "updateTraffic"; + $s['label'] = '
Départ à
de bouchons
'; - } elseif ($s['type'] == 'velib') { - $attrs['class'] = $s['type'] . ' info'; - $attrs['data-init'] = "0"; - $attrs['data-init-function'] = "updateVelib"; - $s['label'] = '
    '; - } elseif ($s['type'] == 'action') { - $attrs['data-action'] = $s['action']; - $attrs['data-device'] = isset($s['device']) ? $s['device'] : getCurrentConfig(); - $attrs['href'] = '#'; - } else if ($s['type'] == 'sub') { - if (strpos($s['sub'], 'sub-') === false) { - $s['sub'] = 'sub-' . $s['sub']; - } - $attrs['data-menu'] = $s['sub']; - $attrs['href'] = '#'; - } else if ($s['type'] == 'phone') { - $attrs['href'] = 'scripts/phonetask.php?phone=' . $s['phone'] . '&task=' . trim(base64_encode($s['task']), "="); - $attrs['class'] = 'ajax'; - } elseif ($s['type'] == 'media') { - $attrs['href'] = isset($s['path']) ? $s['path'] : $s['url']; - $attrs['class'] = 'media'; - } elseif ($s['type'] == 'freebox' || $s['type'] === 'shield' || $s['type'] === 'netflix' || $s['type'] === 'amazonprime' || $s['type'] === 'nintendoswitch') { - $attrs['href'] = $s['url']; - $attrs['class'] = 'ajax play ' . $s['type']; - $attrs['data-remote'] = "1"; - } else if ($s['type'] == 'map') { - $rand = rand(1, 1000000); - $html = '' . $s['map'] . ''; - } else if ($s['type'] == 'missing') { - $attrs['class'] = 'missing'; - } else if ($s['type'] == 'bricks') { - $html = makeBricks($s['bricks']); - } else if ($s['type'] == 'raspberrycast') { - $attrs['class'] = 'raspberrycast'; - } else if ($s['type'] == 'harmonyactivity') { - $attrs['class'] = 'harmonyactivity'; - $attrs['data-activity'] = $s['activity']; - } else if ($s['type'] == 'ifttt') { - $attrs['class'] = 'ifttt'; - $attrs['data-event'] = $s['event']; - } else if ($s['type'] == 'switch' || $s['type'] === 'switchshare') { - $attrs['href'] = '//' . $s['room'] . '.home.tortuga.enhydra.fr/'; - if ($s['type'] == 'share') { - $h = isset($_GET['h']) && $_GET['h'] ? $_GET['h'] : $_SERVER['HTTP_HOST']; - $attrs['href'] .= '?h=' . $h; - } else { - $attrs['class'] = $s['type']; - } - $attrs['style'] = 'background-image:url(/images/rooms/small/' . $s['room'] . '.jpg);background-size:cover;color:#fff;text-shadow:3px;'; - } - - if (isset($s['seen']) && $s['seen']) { - $attrs['data-seen'] = '1'; - } - - if (isset($s['srt']) && count($s['srt'])) { - $langtoemoji = ['fr' => '🇫🇷', 'en' => '🇺🇸']; - foreach ($s['srt'] as $item) { - $swcorner .= '' . $langtoemoji[$item] . ''; - } - } - - - if (isset($s['poster'])) { - if (!isset($attrs['class'])) { - $attrs['class'] = ''; - } - $attrs['class'] .= ' poster'; - $attrs['style'] = 'background-image:url(' . $s['poster'] . ');'; - $s['label'] = ''; - } - - if ($markup == 'a' && !isset($attrs['href'])) { - $attrs['href'] = '#'; - } - - if (isset($s['screenoff'])) { - $attrs['data-screenoff'] = 1; - } - if (isset($s['volume'])) { - $attrs['data-volume'] = $s['volume']; - } - - if (isset($s['confirm'])) { - $attrs['data-confirm'] = json_encode($s['confirm']['conditions']); - $attrs['data-confirm-message'] = $s['confirm']['message']; - } - - - if (isset($html)) { - $res = $html; - } else { - $res = '<' . $markup; - foreach ($attrs as $k => $v) { - if (is_array($v) || is_object($v)) { - $v = json_encode($v); - } - - $res .= ' ' . $k . '="' . htmlspecialchars($v) . '"'; - } - if (!isset($s['label'])) { - $s['label'] = ''; - } - $res .= '>' . $s['label'] . '
    ' . $swcorner . '
    '; - } - return $res; + } elseif ($s['type'] == 'velib') { + $attrs['class'] = $s['type'] . ' info'; + $attrs['data-init'] = "0"; + $attrs['data-init-function'] = "updateVelib"; + $s['label'] = '
      '; + } elseif ($s['type'] == 'action') { + $attrs['data-action'] = $s['action']; + $attrs['data-device'] = isset($s['device']) ? $s['device'] : getCurrentConfig(); + $attrs['href'] = '#'; + } else if ($s['type'] == 'sub') { + if (strpos($s['sub'], 'sub-') === false) { + $s['sub'] = 'sub-' . $s['sub']; + } + $attrs['data-menu'] = $s['sub']; + $attrs['href'] = '#'; + } else if ($s['type'] == 'phone') { + $attrs['href'] = 'scripts/phonetask.php?phone=' . $s['phone'] . '&task=' . trim($s['task']); + $attrs['class'] = 'ajax'; + } elseif ($s['type'] == 'media') { + $attrs['href'] = isset($s['path']) ? $s['path'] : $s['url']; + $attrs['class'] = 'media'; + } elseif ($s['type'] == 'freebox' || $s['type'] === 'shield' || $s['type'] === 'netflix' || $s['type'] === 'amazonprime' || $s['type'] === 'nintendoswitch') { + $attrs['href'] = $s['url']; + $attrs['class'] = 'ajax play ' . $s['type']; + $attrs['data-remote'] = "1"; + } else if ($s['type'] == 'map') { + $rand = rand(1, 1000000); + $html = '' . $s['map'] . ''; + } else if ($s['type'] == 'missing') { + $attrs['class'] = 'missing'; + } else if ($s['type'] == 'bricks') { + $html = makeBricks($s['bricks']); + } else if ($s['type'] == 'raspberrycast') { + $attrs['class'] = 'raspberrycast'; + } else if ($s['type'] == 'harmonyactivity') { + $attrs['class'] = 'harmonyactivity'; + $attrs['data-activity'] = $s['activity']; + } else if ($s['type'] == 'ifttt') { + $attrs['class'] = 'ifttt'; + $attrs['data-event'] = $s['event']; + } else if ($s['type'] == 'switch' || $s['type'] === 'switchshare') { + $attrs['href'] = '//' . $s['room'] . '.home.tortuga.enhydra.fr/'; + if ($s['type'] == 'share') { + $h = isset($_GET['h']) && $_GET['h'] ? $_GET['h'] : $_SERVER['HTTP_HOST']; + $attrs['href'] .= '?h=' . $h; + } else { + $attrs['class'] = $s['type']; + } + $attrs['style'] = 'background-image:url(/images/rooms/small/' . $s['room'] . '.jpg);background-size:cover;color:#fff;text-shadow:3px;'; + } + + if (isset($s['seen']) && $s['seen']) { + $attrs['data-seen'] = '1'; + } + + if (isset($s['srt']) && count($s['srt'])) { + $langtoemoji = ['fr' => '🇫🇷', 'en' => '🇺🇸']; + foreach ($s['srt'] as $item) { + $swcorner .= '' . $langtoemoji[$item] . ''; + } + } + + + if (isset($s['poster'])) { + if (!isset($attrs['class'])) { + $attrs['class'] = ''; + } + $attrs['class'] .= ' poster'; + $attrs['style'] = 'background-image:url(' . $s['poster'] . ');'; + $s['label'] = ''; + } + + if ($markup == 'a' && !isset($attrs['href'])) { + $attrs['href'] = '#'; + } + + if (isset($s['screenoff'])) { + $attrs['data-screenoff'] = 1; + } + if (isset($s['volume'])) { + $attrs['data-volume'] = $s['volume']; + } + + if (isset($s['confirm'])) { + $attrs['data-confirm'] = json_encode($s['confirm']['conditions']); + $attrs['data-confirm-message'] = $s['confirm']['message']; + } + + + if (isset($html)) { + $res = $html; + } else { + $res = '<' . $markup; + foreach ($attrs as $k => $v) { + if (is_array($v) || is_object($v)) { + $v = json_encode($v); + } + + $res .= ' ' . $k . '="' . htmlspecialchars($v) . '"'; + } + if (!isset($s['label'])) { + $s['label'] = ''; + } + $res .= '>' . $s['label'] . '
      ' . $swcorner . '
      '; + } + return $res; } -function init() -{ - global $volume; - $volume = intval(CONFIG('VOLUME', '0')); - if ($volume > 0) { - volume($volume); - } - profile('Inited', __FILE__, __LINE__); +function init() { + global $volume; + $volume = intval(CONFIG('VOLUME', '0')); + if ($volume > 0) { + volume($volume); + } + profile('Inited', __FILE__, __LINE__); } -function getJsonRPCClientInstance($url) -{ - global $rpcclient; - if (!isset($rpcclient)) { - $rpcclient = new \Datto\JsonRpc\Http\Client($url); - } - return $rpcclient; +function getJsonRPCClientInstance($url) { + global $rpcclient; + if (!isset($rpcclient)) { + $rpcclient = new \Datto\JsonRpc\Http\Client($url); + } + return $rpcclient; } -function getSynologyInstance() -{ - global $syno; - if (!isset($syno)) { - $syno = new Synology_Api('192.168.13.3', 5002, 'https', 1); - $syno->connect('Vincent', 'xxxx'); - } - return $syno; +function getSynologyInstance() { + global $syno; + if (!isset($syno)) { + $syno = new Synology_Api('192.168.13.3', 5002, 'https', 1); + $syno->connect('Vincent', 'xxxx'); + } + return $syno; } -function hasNetwork() -{ - return true; +function hasNetwork() { + return true; } -function ping($ip, $timeout = 5, $port = 1817) -{ - $res = @fsockopen($ip, $port, $errno, $errstr, $timeout); - if (!$res) { - echo $errno . ': ' . $errstr . "\n"; - } - return $res; +function ping($ip, $timeout = 5, $port = 1817) { + $res = @fsockopen($ip, $port, $errno, $errstr, $timeout); + if (!$res) { + echo $errno . ': ' . $errstr . "\n"; + } + return $res; } -function volume($volume, $increase = '', $device = null) -{ - $d = $device === null ? config('VOLUME_DEVICE') : $device; - echo $d . ';' . $volume . ';' . $increase; - - if ($increase == ' ') { - $increase = '+'; - } - - $e = explode(':', $d); - - $device = config('DEVICE'); - if (isset($e[1])) { - $device = $e[1]; - $d = $e[0]; - } - $d = mb_strtolower($d); - - switch ($d) { - case 'shield': - if ($increase == '-') { - return shieldKey('volume-down', $device); - } else { - return shieldKey('volume-up', $device); - } - case 'raspberry': - case 'raspberrypi': - $cmd = 'amixer -c 0 -M -- sset PCM playback ' . round(max(0, min(100, $volume))) . '%' . $increase; - return sshCommand($cmd, $device); - case 'squeezeboplayer': - case 'squeezeboxplayer': - case 'squeezebox': - return squeezeVolume($volume, $increase, config('SQUEEZEBOX_PLAYER')); - case 'harmony': - $lastHarmonyVolume = min(time(), getState('last_harmony_volume', 0)); - $limit = time() - 2; - if ($lastHarmonyVolume > $limit) { - return; - } - setState('last_harmony_volume', time()); - - $volume = min(5, max(1, $volume)); - - if ($increase == '-') { - return harmonyRequest('commands/volume-down?repeat=' . $volume, 'POST'); - } else { - return harmonyRequest('commands/volume-up?repeat=' . $volume, 'POST'); - } - case 'vlc': - return VLCCmd(['command' => 'volume', 'val' => $increase . '20'], $device); - case 'denonavr': - return denonAVRVolume($volume, $increase); - } +function volume($volume, $increase = '', $device = null) { + $d = $device === null ? config('VOLUME_DEVICE') : $device; + echo $d . ';' . $volume . ';' . $increase; + + if ($increase == ' ') { + $increase = '+'; + } + + $e = explode(':', $d); + + $device = config('DEVICE'); + if (isset($e[1])) { + $device = $e[1]; + $d = $e[0]; + } + $d = mb_strtolower($d); + + switch ($d) { + case 'shield': + if ($increase == '-') { + return shieldKey('volume-down', $device); + } else { + return shieldKey('volume-up', $device); + } + case 'raspberry': + case 'raspberrypi': + $cmd = 'amixer -c 0 -M -- sset PCM playback ' . round(max(0, min(100, $volume))) . '%' . $increase; + return sshCommand($cmd, $device); + case 'squeezeboplayer': + case 'squeezeboxplayer': + case 'squeezebox': + return squeezeVolume($volume, $increase, config('SQUEEZEBOX_PLAYER')); + case 'harmony': + $lastHarmonyVolume = min(time(), getState('last_harmony_volume', 0)); + $limit = time() - 2; + if ($lastHarmonyVolume > $limit) { + return; + } + setState('last_harmony_volume', time()); + + $volume = min(5, max(1, $volume)); + + if ($increase == '-') { + return harmonyRequest('commands/volume-down?repeat=' . $volume, 'POST'); + } else { + return harmonyRequest('commands/volume-up?repeat=' . $volume, 'POST'); + } + case 'vlc': + return VLCCmd(['command' => 'volume', 'val' => $increase . '20'], $device); + case 'denonavr': + return denonAVRVolume($volume, $increase); + } } -function triggerErrorNotif($title, $message = '') -{ - phoneTask('TortugaMessage|||' . $title . '|||' . $message, 'vincent', true); +function triggerErrorNotif($title, $message = '') { + phoneTask('TortugaMessage|||' . $title . '|||' . $message, 'vincent', true); } -function phoneTask($task, $phone, $encode = true) -{ - global $phones; - $p = $phones[$phone]; - - if ($encode) { - $task = trim(base64_encode($task), '='); - } - $task = $task . "=:=task"; - - $password = $p['password']; - - $url = "http://$p[ip]:1817/?message=$task&password=" . $password; - $res = getUrlContent($url); - //echo $url . ' : ' . $res . "\n--\n"; - if (!$res) { - $url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=$p[key]&message=$task&target=TORTUGA&password=$password"; - $res = getUrlContent($url); - //echo $url . ' : ' . $res . "\n--\n"; - } - return $res; +function phoneTask($task, $phone, $encode = true) { + global $phones; + $p = $phones[$phone]; + + if ($encode) { + $task = trim(base64_encode($task), '='); + } + $task = $task . "=:=task"; + + $password = $p['password']; + + $url = "http://$p[ip]:1817/?message=$task&password=" . $password; + $res = getUrlContent($url); + //echo $url . ' : ' . $res . "\n--\n"; + if (!$res) { + $url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=$p[key]&message=$task&target=TORTUGA&password=$password"; + $res = getUrlContent($url); + //echo $url . ' : ' . $res . "\n--\n"; + } + return $res; } -function getUrlContent($url, $timeout = 30, $user = false, $newclient = false) -{ - $httpclient = getHttpClient($newclient); - $options = ['timeout' => $timeout, 'read_timeout' => $timeout]; - if ($user !== false) { - $options['auth'] = $user; - } - try { - $response = $httpclient->get($url, $options); - return $response->getBody(); - } catch (Exception $e) { - echo $e->getMessage(); - return false; - } +function getUrlContent($url, $timeout = 30, $user = false, $newclient = false) { + $httpclient = getHttpClient($newclient); + $options = ['timeout' => $timeout, 'read_timeout' => $timeout]; + if ($user !== false) { + $options['auth'] = $user; + } + try { + $response = $httpclient->get($url, $options); + return $response->getBody(); + } catch (Exception $e) { + echo $e->getMessage(); + return false; + } } -function waitEvent($event) -{ - $file = ROOT . '/cache/events/' . $event; - while (true) { - if (file_exists($file)) { - if (filemtime($file) < time() - 60) { - // Expired event - rename($file, $file . '_' . microtime(false)); - continue; - } - rename($file, $file . '_' . microtime(false)); - break; - } - usleep(0.1 * 1000000); - } +function waitEvent($event) { + $file = ROOT . '/cache/events/' . $event; + while (true) { + if (file_exists($file)) { + if (filemtime($file) < time() - 60) { + // Expired event + rename($file, $file . '_' . microtime(false)); + continue; + } + rename($file, $file . '_' . microtime(false)); + break; + } + usleep(0.1 * 1000000); + } } -function returnHttpResponse() -{ - ignore_user_abort(true); - if (!defined('TIMELIMIT')) { - set_time_limit(0); - } - if (!headers_sent()) { - header('Connection: close'); - header('Content-Length: ' . ob_get_length()); - } - @ob_end_flush(); - @ob_flush(); - @flush(); - if (session_id()) session_write_close(); - if (function_exists('fastcgi_finish_request')) { - fastcgi_finish_request(); - } +function returnHttpResponse() { + ignore_user_abort(true); + if (!defined('TIMELIMIT')) { + set_time_limit(0); + } + if (!headers_sent()) { + header('Connection: close'); + header('Content-Length: ' . ob_get_length()); + } + @ob_end_flush(); + @ob_flush(); + @flush(); + if (session_id()) + session_write_close(); + if (function_exists('fastcgi_finish_request')) { + fastcgi_finish_request(); + } } -function isProcessRunning($process) -{ - exec("ps aux | grep -i '" . $process . "' | grep -v grep", $pids); - if (empty($pids)) { - return false; - } - return true; +function isProcessRunning($process) { + exec("ps aux | grep -i '" . $process . "' | grep -v grep", $pids); + if (empty($pids)) { + return false; + } + return true; } -function toNumber($val, $round = false) -{ - if ($val === false) { - return '--'; - } - $e = explode(',', $val); - $val = $e[0]; - $val = preg_replace('/[^0-9-.]/', '', $val); - $val = floatval($val); - if ($round) { - $val = round($val, $round === true ? 0 : $round); - } - return $val; +function toNumber($val, $round = false) { + if ($val === false) { + return '--'; + } + $e = explode(',', $val); + $val = $e[0]; + $val = preg_replace('/[^0-9-.]/', '', $val); + $val = floatval($val); + if ($round) { + $val = round($val, $round === true ? 0 : $round); + } + return $val; } -function makeNav($nav) -{ - $map = [ - 'home' => '
      Accueil
      ', - 'lights' => '
      Lumières
      ', - 'music' => '
      Musique & Radio
      ', - 'media' => '
      Medias & TV
      ', - 'coffee' => '
      Cuisine / Café
      ', - 'water' => '
      Eau chaude
      ', - 'fan' => 'Ventilateur', - 'remote' => '
      Télécommande
      ', - 'switch' => '
      Changer de pièce
      ', - 'clock' => '
      Réveil
      ', - 'settings' => '
      Paramètres
      ', - 'alert' => '
      Alerte
      ', - 'off' => '
      Éteindre
      ', - ]; - - $res = ''; - return $res; +function makeNav($nav) { + $map = [ + 'home' => '
      Accueil
      ', + 'lights' => '
      Lumières
      ', + 'music' => '
      Musique & Radio
      ', + 'media' => '
      Medias & TV
      ', + 'coffee' => '
      Cuisine / Café
      ', + 'water' => '
      Eau chaude
      ', + 'fan' => 'Ventilateur', + 'remote' => '
      Télécommande
      ', + 'switch' => '
      Changer de pièce
      ', + 'clock' => '
      Réveil
      ', + 'settings' => '
      Paramètres
      ', + 'alert' => '
      Alerte
      ', + 'off' => '
      Éteindre
      ', + ]; + + $res = ''; + return $res; } -function gloria() -{ - $j = intval(date('N')); - if ($j !== 1) { - return false; - } - $h = intval(date('H')); - return $h >= 12 && $h <= 17; +function gloria() { + $j = intval(date('N')); + if ($j !== 1) { + return false; + } + $h = intval(date('H')); + return $h >= 12 && $h <= 17; } diff --git a/scripts/lib/scenes.php b/scripts/lib/scenes.php index 59eccf3..aa44366 100644 --- a/scripts/lib/scenes.php +++ b/scripts/lib/scenes.php @@ -648,16 +648,16 @@ $scenes = [ ['type' => 'scene', 'scene' => 'bureau/sound/off'], ], 'bureau/screen/down' => [ - ['type' => 'domoticz', 'device' => '1', 'command' => true, 'priority' => true], + ['type' => 'domoticz', 'device' => '1', 'command' => 'Close', 'priority' => true], ], 'bureau/screen/up' => [ - ['type' => 'domoticz', 'device' => '1', 'command' => false, 'priority' => true], + ['type' => 'domoticz', 'device' => '1', 'command' => 'Open', 'priority' => true], ], 'bureau/rideaux/close' => [ - ['type' => 'domoticz', 'device' => '391', 'command' => true, 'priority' => true], + ['type' => 'domoticz', 'device' => '391', 'command' => 'Close', 'priority' => true], ], 'bureau/rideaux/open' => [ - ['type' => 'domoticz', 'device' => '391', 'command' => false, 'priority' => true], + ['type' => 'domoticz', 'device' => '391', 'command' => 'Open', 'priority' => true], ], 'bureau/rideaux/toggle' => [ ['type' => 'domoticz', 'device' => '391', 'command' => 'Toggle', 'priority' => true],