diff --git a/install/resources/content/install_requirement.php b/install/resources/content/install_requirement.php index 4b3e46b..1544dff 100644 --- a/install/resources/content/install_requirement.php +++ b/install/resources/content/install_requirement.php @@ -62,7 +62,7 @@ foreach ($filesFolders as $file => $info) } // Sonstiges -if ($otherDistribution['version'] == 'Raspbian GNU/Linux 10' || $otherDistribution['version'] == 'Raspbian GNU/Linux 11') +if ($otherDistribution['version'] == 'Raspbian GNU/Linux 10' || $otherDistribution['version'] == 'Raspbian GNU/Linux 11' || $otherDistribution['version'] == 'Debian GNU/Linux 11') $otherDistribution['status'] = true; if (isset($_COOKIE['_pi-control_install_language']) && $_COOKIE['_pi-control_install_language'] != '') diff --git a/install/resources/library/main/main.function.php b/install/resources/library/main/main.function.php index d91e653..a41071e 100644 --- a/install/resources/library/main/main.function.php +++ b/install/resources/library/main/main.function.php @@ -368,8 +368,15 @@ function urlIsPublic($url) $ip = gethostbyname($url); $long = ip2long($ip); - if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1) - return false; + if (PHP_INT_SIZE == 4) { + if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1) { + return false; + } + } else { + if (($long >= 3232235520 && $long <= 3232301055) || ($long >= 2886729728 && $long <= 2887778303) || ($long >= 167772160 && $long <= 184549375) || $long == -1) { + return false; + } + } return true; } @@ -614,4 +621,3 @@ function getURLLangParam($echo = false, $html = true, $first = false) return $param; } -?> \ No newline at end of file diff --git a/resources/init.php b/resources/init.php index 7821a41..53850bf 100644 --- a/resources/init.php +++ b/resources/init.php @@ -10,13 +10,13 @@ if (!isset($config)) 'ssh_ip' => '127.0.0.1' ), 'version' => array( - 'version' => '2.3.0', - 'versioncode' => 31, + 'version' => '2.3.1beta1', + 'versioncode' => 32, 'android_comp_level' => 25 ), 'url' => array( 'update' => 'https://pic.die-schultes.eu/service/v1/update/', - 'updateDownload' => 'https://www.die-schultes.eu/wp-content/uploads/', + 'updateDownload' => 'https://bugs.die-schultes.eu/attachments/', 'updateNotification' => 'https://pi-control.de/?service=update_notification', 'plugin' => 'https://pi-control.de/service/v1/plugin/', 'pluginDownload' => 'https://pi-control.de/?service=plugin', diff --git a/resources/library/main/main.function.php b/resources/library/main/main.function.php index 7d4f294..2cf8f35 100644 --- a/resources/library/main/main.function.php +++ b/resources/library/main/main.function.php @@ -17,35 +17,34 @@ function setConfig($config, $value, $customFile = NULL) { $configPath = CONFIG_PATH; $configFileSuffix = '.config.ini.php'; // Standard-Konfig - + if ($customFile !== NULL) $configPath = $customFile; - + $file = explode(':', $config); - + if (count($file) != 2) return false; - - $configFile = $configPath.$file[0].$configFileSuffix; - - if (file_exists($configFile) !== true || is_file($configFile) !== true) - { + + $configFile = $configPath . $file[0] . $configFileSuffix; + + if (file_exists($configFile) !== true || is_file($configFile) !== true) { if (!touch($configFile)) return false; } - + $configArray = parse_ini_file($configFile, true); - + if (!strlen($config) > 0 || !is_string($config)) return false; - + $var = explode('.', $file[1]); - + if (count($var) != 2) $configArray[$var[0]] = $value; else $configArray[$var[0]][$var[1]] = $value; - + return writeConfig($configArray, $configFile); } @@ -63,43 +62,40 @@ function getConfig($config, $default = NULL, $customFile = NULL) { $configPath = CONFIG_PATH; $configFileSuffix = '.config.ini.php'; // Standard-Konfig - + if ($customFile !== NULL) $configPath = $customFile; - + $file = explode(':', $config); - + if (count($file) != 1 && count($file) != 2) return $default; - - $configFile = $configPath.$file[0].$configFileSuffix; - + + $configFile = $configPath . $file[0] . $configFileSuffix; + if (file_exists($configFile) !== true || is_file($configFile) !== true) return $default; - + $configArray = parse_ini_file($configFile, true); - + if (!strlen($config) > 0 || !is_string($config)) return $default; - + if (!count($configArray) > 0) return $default; - - if (isset($file[1])) - { + + if (isset($file[1])) { $var = explode('.', $file[1]); - + if (count($var) == 1 && isset($configArray[$var[0]])) return $configArray[$var[0]]; elseif (count($var) == 2 && isset($configArray[$var[0]][$var[1]])) return $configArray[$var[0]][$var[1]]; - } - else - { + } else { if (isset($configArray)) return $configArray; } - + return $default; } @@ -107,34 +103,34 @@ function removeConfig($config, $customFile = NULL) { $configPath = CONFIG_PATH; $configFileSuffix = '.config.ini.php'; // Standard-Konfig - + if ($customFile !== NULL) $configPath = $customFile; - + $file = explode(':', $config); - + if (count($file) != 2) return false; - - $configFile = $configPath.$file[0].$configFileSuffix; - + + $configFile = $configPath . $file[0] . $configFileSuffix; + if (file_exists($configFile) !== true || is_file($configFile) !== true) return false; - + $configArray = parse_ini_file($configFile, true); - + if (!strlen($config) > 0 || !is_string($config)) return false; - + $var = explode('.', $file[1]); - + if (count($var) == 1) unset($configArray[$var[0]]); elseif (count($var) == 2) unset($configArray[$var[0]][$var[1]]); else return false; - + return writeConfig($configArray, $configFile); } @@ -149,48 +145,42 @@ function removeConfig($config, $customFile = NULL) function writeConfig($configArray, $configFile) { $res = array('; $val) - { - if (is_array($val)) - { - $res[] = PHP_EOL."[$key]"; - + + foreach ($configArray as $key => $val) { + if (is_array($val)) { + $res[] = PHP_EOL . "[$key]"; + foreach ($val as $skey => $sval) - $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"'); - } - else - $res[] = PHP_EOL."$key = ".(is_numeric($val) ? $val : '"'.$val.'"'); + $res[] = "$skey = " . (is_numeric($sval) ? $sval : '"' . $sval . '"'); + } else + $res[] = PHP_EOL . "$key = " . (is_numeric($val) ? $val : '"' . $val . '"'); } - + $res[] = ';?>'; - + if (file_exists($configFile) !== true || is_file($configFile) !== true || is_writeable($configFile) !== true) return false; - - if ($fp = fopen($configFile, 'w')) - { + + if ($fp = fopen($configFile, 'w')) { $startTime = microtime(); - do - { + do { $canWrite = flock($fp, LOCK_EX); - + // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load if (!$canWrite) - usleep(round(rand(0, 100)*1000)); - } while ((!$canWrite) && ((microtime()-$startTime) < 1000)); - + usleep(round(rand(0, 100) * 1000)); + } while ((!$canWrite) && ((microtime() - $startTime) < 1000)); + // file was locked so now we can store information - if ($canWrite) - { + if ($canWrite) { fwrite($fp, implode(PHP_EOL, $res)); flock($fp, LOCK_UN); } fclose($fp); } - + return true; } @@ -207,25 +197,24 @@ function writeConfig($configArray, $configFile) function _t() { global $globalLanguage, $globalLanguageArray; - + $args = func_get_args(); $lang = $globalLanguage; - $langFile = LANGUAGE_PATH.$lang.'.php'; - - if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) - { + $langFile = LANGUAGE_PATH . $lang . '.php'; + + if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) { include $langFile; $globalLanguageArray = $langArray; } - + $checksum = substr(md5($args[0]), 0, 8); - + if (is_numeric($checksum)) $checksum[7] = 'z'; - + if (isset($globalLanguageArray[$checksum]) && $lang != 'de') $args[0] = $globalLanguageArray[$checksum]; - + return call_user_func_array('sprintf', $args); } @@ -242,27 +231,26 @@ function _t() function _e() { global $globalLanguage, $globalLanguageArray; - + $args = func_get_args(); $lang = $globalLanguage; - $langFile = LANGUAGE_PATH.$lang.'.php'; - - if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) - { + $langFile = LANGUAGE_PATH . $lang . '.php'; + + if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) { include $langFile; $globalLanguageArray = $langArray; } - + $checksum = substr(md5($args[0]), 0, 8); - + if (is_numeric($checksum)) $checksum[7] = 'z'; - + if (isset($globalLanguageArray[$checksum]) && $lang != 'de') $args[0] = $globalLanguageArray[$checksum]; - + echo call_user_func_array('sprintf', $args); - + return true; } @@ -270,26 +258,25 @@ function sizeUnit($size, $fixUnit = NULL) { if ($size == '') $size = 0; - + if (($size < 1024 && !isset($fixUnit)) || (isset($fixUnit) && $fixUnit == 'B')) - return number_format($size, 0, ',', '').' Byte'; + return number_format($size, 0, ',', '') . ' Byte'; elseif (($size < 1024000 && !isset($fixUnit)) || (isset($fixUnit) && $fixUnit == 'K')) - return number_format(round($size/1024,2), 2, ',', '').' KB'; + return number_format(round($size / 1024, 2), 2, ',', '') . ' KB'; elseif (($size < 1048576000 && !isset($fixUnit)) || (isset($fixUnit) && $fixUnit == 'M')) - return number_format(round($size/1048576,2), 2, ',', '').' MB'; + return number_format(round($size / 1048576, 2), 2, ',', '') . ' MB'; elseif (($size < 1073741824000 && !isset($fixUnit)) || (isset($fixUnit) && $fixUnit == 'G')) - return number_format(round($size/1073741824,2), 2, ',', '').' GB'; + return number_format(round($size / 1073741824, 2), 2, ',', '') . ' GB'; elseif (($size < 1099511627776000 && !isset($fixUnit)) || (isset($fixUnit) && $fixUnit == 'T')) - return number_format(round($size/1099511627776,2), 2, ',', '').' TB'; + return number_format(round($size / 1099511627776, 2), 2, ',', '') . ' TB'; } function return_bytes($size) { $size = trim($size); - $last = strtolower($size[strlen($size)-1]); - - switch ($last) - { + $last = strtolower($size[strlen($size) - 1]); + + switch ($last) { case 'g': $size *= 1024; case 'm': @@ -309,87 +296,83 @@ function getFolderSize($folder_path, $folder_size = 0) { if (!is_dir($folder_path)) $folder_size += filesize($folder_path); - else - { + else { $folder_dir = opendir($folder_path); - while ($folder_file = readdir($folder_dir)) - { - if (is_file($folder_path.'/'.$folder_file)) - $folder_size += filesize($folder_path.'/'.$folder_file); - if (is_dir($folder_path.'/'.$folder_file) && $folder_file != '.' && $folder_file != '..') - $folder_size = getFolderSize($folder_path.'/'.$folder_file, $folder_size); + while ($folder_file = readdir($folder_dir)) { + if (is_file($folder_path . '/' . $folder_file)) + $folder_size += filesize($folder_path . '/' . $folder_file); + if (is_dir($folder_path . '/' . $folder_file) && $folder_file != '.' && $folder_file != '..') + $folder_size = getFolderSize($folder_path . '/' . $folder_file, $folder_size); } } - return($folder_size); + return ($folder_size); } function formatTime($time, $type = 'd.m.Y H:i') { if ($time == '') return false; - + return date($type, $time); } -if (!function_exists('array_column')) -{ +if (!function_exists('array_column')) { function array_column($array, $columnName) { - return array_map(function($element) use($columnName) { return $element[$columnName]; }, $array); + return array_map(function ($element) use ($columnName) { + return $element[$columnName]; + }, $array); } } function checkUpdate() { global $config, $globalLanguage; - + $lang = $globalLanguage; - - if (!class_exists('cURL')) - (include LIBRARY_PATH.'curl/curl.class.php'); - + + if (!class_exists('cURL')) (include LIBRARY_PATH . 'curl/curl.class.php'); + $curl = new cURL($config['url']['update']); $curl->execute(); - + if ($curl->getStatusCode() != '200') return $curl->getStatusCode(); - + if ($curl->getResult($data) != JSON_ERROR_NONE) return 1; - + if (!isset($data['versions'], $data['latest'])) return 1; - - if ($data['latest']['versioncode'] > $config['version']['versioncode']) - { - $currentUpdateKey = array_search($config['version']['versioncode']+1, array_column($data['versions'], 'versioncode')); - + + if ($data['latest']['versioncode'] > $config['version']['versioncode']) { + $currentUpdateKey = array_search($config['version']['versioncode'] + 1, array_column($data['versions'], 'versioncode')); + if (isset($data['versions'][$currentUpdateKey]['changelog'][$lang])) $data['versions'][$currentUpdateKey]['changelog'] = $data['versions'][$currentUpdateKey]['changelog'][$lang]; else $data['versions'][$currentUpdateKey]['changelog'] = current($data['versions'][$currentUpdateKey]['changelog']); - + return $data['versions'][$currentUpdateKey]; - } - else + } else return 0; } function getDateFormat($time) { $day = floor($time / 60 / 60 / 24); - $day = ($day < 10) ? '0'.$day : $day; - $day = ($day == 1) ? '01 Tag ' : $day.' Tage '; + $day = ($day < 10) ? '0' . $day : $day; + $day = ($day == 1) ? '01 Tag ' : $day . ' Tage '; $day = ($day == '00 Tage ') ? '' : $day; $hour = floor($time / 60 / 60 % 24); - $hour = ($hour < 10) ? '0'.$hour : $hour; + $hour = ($hour < 10) ? '0' . $hour : $hour; $hour = ($hour == 24) ? '00' : $hour; $minute = floor($time / 60 % 60); - $minute = ($minute < 10) ? '0'.$minute : $minute; + $minute = ($minute < 10) ? '0' . $minute : $minute; $second = floor($time % 60); - $second = ($second < 10) ? '0'.$second : $second; - - return $day.$hour.':'.$minute.':'.$second; + $second = ($second < 10) ? '0' . $second : $second; + + return $day . $hour . ':' . $minute . ':' . $second; } function getImageFromSignal($signal) @@ -412,134 +395,125 @@ function getAllNetworkConnections() { $shell_string = ''; $output = array(); - + exec('/sbin/ifconfig | grep -E -o "^[[:alnum:][:punct:]]*" | grep -E -v "(lo)" | sed "s/:$//"', $networkInterfaces); foreach ($networkInterfaces as $interface) - $shell_string .= '/sbin/ifconfig '.$interface.(($networkInterfaces[count($networkInterfaces)-1] != $interface) ? ' && echo "-#-" && ' : ''); - + $shell_string .= '/sbin/ifconfig ' . $interface . (($networkInterfaces[count($networkInterfaces) - 1] != $interface) ? ' && echo "-#-" && ' : ''); + $streamInterfaces = explode('-#-', shell_exec($shell_string)); - - foreach ($streamInterfaces as $index => $streamInterface) - { + + foreach ($streamInterfaces as $index => $streamInterface) { $wirelessOption = ''; - + $interface = $networkInterfaces[$index]; - + preg_match('#inet(?:[ ]+(?:addr\:)?)([\w\.]+)#', $streamInterface, $ipAddress); preg_match('#(?:HWaddr|ether) ([\w\:]+)#', $streamInterface, $macAddress); preg_match('#RX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesReceived); preg_match('#TX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesSent); preg_match('#RX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsReceived); preg_match('#TX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsSent); - + $output0 = $interface; - - if (substr($output0, 0, 4) == 'wlan') - { - $streamWirelessInterface = shell_exec('/sbin/iwconfig '.$output0); - - if (0 == substr_count($streamWirelessInterface, 'Not-Associated')) - { + + if (substr($output0, 0, 4) == 'wlan') { + $streamWirelessInterface = shell_exec('/sbin/iwconfig ' . $output0); + + if (0 == substr_count($streamWirelessInterface, 'Not-Associated')) { $posConfig_start = @strpos($streamWirelessInterface, 'ESSID:"', 0) + 7; $posConfig_end = @strpos($streamWirelessInterface, '"', $posConfig_start); $wirelessOption['ssid'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start))); - + $posConfig_start = @strpos($streamWirelessInterface, 'Access Point:', 0) + 13; $posConfig_end = @strpos($streamWirelessInterface, 'Bit Rate', $posConfig_start); $wirelessOption['mac'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start))); - + $posConfig_start = @strpos($streamWirelessInterface, 'Signal level=', 0) + 13; - - if (($posConfig_end = @strpos($streamWirelessInterface, '/100', $posConfig_start)) === false) - { + + if (($posConfig_end = @strpos($streamWirelessInterface, '/100', $posConfig_start)) === false) { $posConfig_end = @strpos($streamWirelessInterface, ' dBm', $posConfig_start); $signal = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start))); - + if ($signal <= -100) $wirelessOption['signal'] = 0; elseif ($signal >= -50) $wirelessOption['signal'] = 100; else $wirelessOption['signal'] = 2 * ($signal + 100); - } - else + } else $wirelessOption['signal'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start))); - } } - + $output[] = array('interface' => $interface, 'mac' => strtoupper($macAddress[1]), 'ip' => (isset($ipAddress[1])) ? $ipAddress[1] : NULL, 'sent' => $bytesSent[1], 'receive' => $bytesReceived[1], 'option' => $wirelessOption, 'packets' => array('sent' => $packetsSent[1], 'received' => $packetsReceived[1])); } - + return $output; } function scanAccessPoints($networkConnections, $ssh = false) { global $tpl; - + $wlan = array(); - - foreach ($networkConnections as $interface) - { + + foreach ($networkConnections as $interface) { if (substr($interface['interface'], 0, 4) != 'wlan') continue; - + $wlan[$interface['interface']] = array(); - + if ($ssh == true) - list ($streamWlan, , ) = $tpl->executeSSH('sudo /sbin/iwlist '.escapeshellarg($interface['interface']).' scan'); + list($streamWlan,,) = $tpl->executeSSH('sudo /sbin/iwlist ' . escapeshellarg($interface['interface']) . ' scan'); else - $streamWlan = shell_exec('/sbin/iwlist '.escapeshellarg($interface['interface']).' scan'); - - for ($i = 1; $i <= substr_count($streamWlan, 'ESSID:"'); $i += 1) - { - $posCell_start = @strpos($streamWlan, 'Cell '.(($i < 10) ? '0' : '').$i.' - Address:', 0) + 19; - $posCell_end = @strpos($streamWlan, 'Cell '.((($i+1) < 10) ? '0' : '').($i+1), $posCell_start); + $streamWlan = shell_exec('/sbin/iwlist ' . escapeshellarg($interface['interface']) . ' scan'); + + for ($i = 1; $i <= substr_count($streamWlan, 'ESSID:"'); $i += 1) { + $posCell_start = @strpos($streamWlan, 'Cell ' . (($i < 10) ? '0' : '') . $i . ' - Address:', 0) + 19; + $posCell_end = @strpos($streamWlan, 'Cell ' . ((($i + 1) < 10) ? '0' : '') . ($i + 1), $posCell_start); if ($posCell_end === false) $posCell_end = strlen($streamWlan); - + $string = substr($streamWlan, $posCell_start, ($posCell_end - $posCell_start)); - + $posConfig_start = @strpos($string, 'ESSID:"', 0) + 7; $posConfig_end = @strpos($string, '"', $posConfig_start); $wirelessOption['ssid'] = trim(substr($string, $posConfig_start, ($posConfig_end - $posConfig_start))); - + $wirelessOption['mac'] = substr(trim($string), 0, 17); - + $posConfig_start = @strpos($string, 'Frequency:', 0) + 10; $posConfig_end = @strpos($string, 'Channel', $posConfig_start); - $wirelessOption['channel'] = trim(str_replace(')', '', substr($string, $posConfig_end+8, 3))); - + $wirelessOption['channel'] = trim(str_replace(')', '', substr($string, $posConfig_end + 8, 3))); + $posConfig_start = @strpos($string, 'Signal level=', 0) + 13; if (strpos(substr($string, $posConfig_start, 20), 'dBm')) $posConfig_end = @strpos($string, 'dBm', $posConfig_start); else $posConfig_end = @strpos($string, '/100', $posConfig_start); - + $wirelessOption['signal'] = trim(substr($string, $posConfig_start, ($posConfig_end - $posConfig_start))); - - if (strpos(substr($string, $posConfig_start, 20), 'dBm')) - { + + if (strpos(substr($string, $posConfig_start, 20), 'dBm')) { if ($wirelessOption['signal'] <= -100) $wirelessOption['signal'] = 0; - elseif($wirelessOption['signal'] >= -50) + elseif ($wirelessOption['signal'] >= -50) $wirelessOption['signal'] = 100; else $wirelessOption['signal'] = 2 * ($wirelessOption['signal'] + 100); } - + $posConfig_start = @strpos($string, 'IE: IEEE', 0) + 7; $posConfig_end = @strpos($string, '/', $posConfig_start); - $wirelessOption['encryption'] = trim(substr($string, $posConfig_end+1, 4)); + $wirelessOption['encryption'] = trim(substr($string, $posConfig_end + 1, 4)); if (substr($wirelessOption['encryption'], 0, 1) != 'W') $wirelessOption['encryption'] = '-'; - + $wlan[$interface['interface']][] = $wirelessOption; } } - + return $wlan; } @@ -557,21 +531,27 @@ function urlIsPublic($url) { $ip = gethostbyname($url); $long = ip2long($ip); - - if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1) - return false; - + + if (PHP_INT_SIZE == 4) { + if (($long >= 167772160 && $long <= 184549375) || ($long >= -1408237568 && $long <= -1407188993) || ($long >= -1062731776 && $long <= -1062666241) || ($long >= 2130706432 && $long <= 2147483647) || $long == -1) { + return false; + } + } else { + if (($long >= 3232235520 && $long <= 3232301055) || ($long >= 2886729728 && $long <= 2887778303) || ($long >= 167772160 && $long <= 184549375) || $long == -1) { + return false; + } + } return true; } function showSettingsIcon($url) { - echo '
'._t('Einstellungen').'
'.PHP_EOL; + echo '
' . _t('Einstellungen') . '
' . PHP_EOL; } function showGoBackIcon($url) { - echo '
'._t('Zurück').'
'.PHP_EOL; + echo '
' . _t('Zurück') . '
' . PHP_EOL; } function getDirectory($folder_) @@ -580,28 +560,25 @@ function getDirectory($folder_) $fileArray = array(); $folder = array(); $file = array(); - - foreach (@scandir($folder_) as $file_) - { - if ($file_[0] != '.') - { - if (is_dir($folder_.'/'.$file_)) - { + + foreach (@scandir($folder_) as $file_) { + if ($file_[0] != '.') { + if (is_dir($folder_ . '/' . $file_)) { $folderArray[] = $file_; $fileArray[] = $file_; } } } - + if (isset($folderArray)) foreach ($folderArray as $row) $folder[] = $row; - + if (isset($fileArray)) foreach ($fileArray as $row) $file[] = $row; - - return array ($folder, $file); + + return array($folder, $file); } function getAllFiles($folder_) @@ -611,182 +588,158 @@ function getAllFiles($folder_) $folder = array(); $file = array(); $errorArray = array(); - + foreach (@scandir($folder_) as $file_) if ($file_[0] != '.') - if (is_dir($folder_.'/'.$file_)) + if (is_dir($folder_ . '/' . $file_)) $folderArray[] = $file_; else $fileArray[] = $file_; - - if (isset($folderArray)) - { - foreach ($folderArray as $row) - { - list ($file_return, $error_log) = getAllFiles($folder_.'/'.$row); + + if (isset($folderArray)) { + foreach ($folderArray as $row) { + list($file_return, $error_log) = getAllFiles($folder_ . '/' . $row); $file[$row] = $file_return; - - if (is_writeable($folder_.'/'.$row) !== true) - $errorArray[] = $folder_.'/'.$row.'/'; + + if (is_writeable($folder_ . '/' . $row) !== true) + $errorArray[] = $folder_ . '/' . $row . '/'; $errorArray = array_merge($errorArray, $error_log); } } - - if (isset($fileArray)) - { - foreach ($fileArray as $row) - { + + if (isset($fileArray)) { + foreach ($fileArray as $row) { $file[] = $row; - - if (is_writeable($folder_.'/'.$row) !== true) - $errorArray[] = $folder_.'/'.$row; + + if (is_writeable($folder_ . '/' . $row) !== true) + $errorArray[] = $folder_ . '/' . $row; } } - + return array($file, $errorArray); } function deleteFolder($folder) { chmod($folder, 0777); - - if (is_dir($folder)) - { + + if (is_dir($folder)) { $handle = opendir($folder); while ($filename = readdir($handle)) if ($filename != '.' && $filename != '..') - deleteFolder($folder.'/'.$filename); - + deleteFolder($folder . '/' . $filename); + closedir($handle); rmdir($folder); - } - else + } else unlink($folder); } function checkInternetConnection() { - if (function_exists('fsockopen') && ini_get('allow_url_fopen') !== false) - { + if (function_exists('fsockopen') && ini_get('allow_url_fopen') !== false) { if (!$sock = @fsockopen('www.google.com', 80, $num, $error, 5)) return false; // Raspberry Pi is not connected to internet else return true; - } - else + } else return false; } function getURLLangParam($echo = false, $html = true, $first = false) { global $globalLanguage; - + $param = '&'; - + if ($html === true) $param .= 'amp;'; - + if ($first !== false) $param = '?'; - - $param .= 'lang='.$globalLanguage; - + + $param .= 'lang=' . $globalLanguage; + if ($echo !== false) echo $param; - + return $param; } function showHelper($url, $extern = false) { global $config; - + if ($extern === false) - $url = $config['url']['help'].'?s=view&i='.$url.getURLLangParam(); - - return ' '; + $url = $config['url']['help'] . '?s=view&i=' . $url . getURLLangParam(); + + return ' '; } function addCronToCrontab($cronEntry, $ssh) { exec('cat /etc/crontab', $lines); - + $newFile = ''; $lineCount = 0; - $lastLine = count($lines)-1; - $secondLastLine = count($lines)-2; + $lastLine = count($lines) - 1; + $secondLastLine = count($lines) - 2; $hashtag = 0; $hashtagLine = 0; - - if (!in_array($cronEntry, $lines)) - { - if (substr(trim($lines[$lastLine]), 0, 1) == '') - { - if (substr(trim($lines[$secondLastLine]), 0, 1) == '#') - { + + if (!in_array($cronEntry, $lines)) { + if (substr(trim($lines[$lastLine]), 0, 1) == '') { + if (substr(trim($lines[$secondLastLine]), 0, 1) == '#') { $hashtag = 1; $hashtagLine = $secondLastLine; - } - else - { + } else { $hashtag = 0; $hashtagLine = $lastLine; } } - - if (substr(trim($lines[$lastLine]), 0, 1) == '#') - { + + if (substr(trim($lines[$lastLine]), 0, 1) == '#') { $hashtag = 2; $hashtagLine = $lastLine; } - - foreach ($lines as $line) - { - if ($lineCount == $hashtagLine) - { - if ($hashtag == 0) - { - $newFile .= $cronEntry."\n"; + + foreach ($lines as $line) { + if ($lineCount == $hashtagLine) { + if ($hashtag == 0) { + $newFile .= $cronEntry . "\n"; $newFile .= '#'; - } - elseif ($hashtag == 1) - $newFile .= $cronEntry."\n"; + } elseif ($hashtag == 1) + $newFile .= $cronEntry . "\n"; elseif ($hashtag == 2) - $newFile .= $cronEntry."\n"; + $newFile .= $cronEntry . "\n"; } - - $newFile .= $lines[$lineCount]."\n"; + + $newFile .= $lines[$lineCount] . "\n"; $lineCount += 1; } - - if (file_exists(TEMP_PATH.'crontab.tmp.php') && is_file(TEMP_PATH.'crontab.tmp.php')) - unlink(TEMP_PATH.'crontab.tmp.php'); - - if (($file = fopen(TEMP_PATH.'crontab.tmp.php', 'w+'))) - { + + if (file_exists(TEMP_PATH . 'crontab.tmp.php') && is_file(TEMP_PATH . 'crontab.tmp.php')) + unlink(TEMP_PATH . 'crontab.tmp.php'); + + if (($file = fopen(TEMP_PATH . 'crontab.tmp.php', 'w+'))) { if (!fwrite($file, $newFile)) return 4; - } - else + } else return 3; - - if (($stream = ssh2_scp_send($ssh, TEMP_PATH.'crontab.tmp.php', '/etc/crontab'))) - { - unlink(TEMP_PATH.'crontab.tmp.php'); + + if (($stream = ssh2_scp_send($ssh, TEMP_PATH . 'crontab.tmp.php', '/etc/crontab'))) { + unlink(TEMP_PATH . 'crontab.tmp.php'); return 0; - } - else + } else return 1; - } - else + } else return 2; } function getWeatherIconYahoo($icon) { - switch ($icon) - { + switch ($icon) { case 32: case 36: return '01d'; @@ -852,8 +805,7 @@ function getWeatherIconYahoo($icon) function getWeatherIconOpenWeatherMap($icon) { - switch ($icon) - { + switch ($icon) { case '01d': return '01d'; case '01n': @@ -891,8 +843,7 @@ function getWeatherIconOpenWeatherMap($icon) function getWeatherIconWunderground($icon) { - switch ($icon) - { + switch ($icon) { case 'clear': case 'sunny': return '01d'; @@ -916,7 +867,7 @@ function getWeatherIconWunderground($icon) case 'rain': case 'nt_rain': return '09'; - /*case '': + /*case '': return '10d'; case '': return '10n';*/ @@ -942,8 +893,7 @@ function getWeatherIconWunderground($icon) function getWeatherIconDarksky($icon) { - switch ($icon) - { + switch ($icon) { case 'clear-day': return '01d'; case 'clear-night': @@ -958,7 +908,7 @@ function getWeatherIconDarksky($icon) return '04'; case 'rain': return '09'; - /*case '': + /*case '': return '10d'; case '': return '10n'; @@ -976,8 +926,7 @@ function getWeatherIconDarksky($icon) function getWeatherIconYr($icon) { - switch ($icon) - { + switch ($icon) { case '1': case '01': case '01d': @@ -1110,10 +1059,9 @@ function getWeatherIconYr($icon) function getWeather() { global $globalLanguage; - - if (!class_exists('cURL')) - (include LIBRARY_PATH.'curl/curl.class.php'); - + + if (!class_exists('cURL')) (include LIBRARY_PATH . 'curl/curl.class.php'); + $service = getConfig('main:weather.service', 'openweathermap'); $serviceToken = getConfig('main:weather.serviceToken', ''); $country = getConfig('main:weather.country', 'germany'); @@ -1122,305 +1070,284 @@ function getWeather() $city = getConfig('main:weather.city', ''); $latitude = getConfig('main:weather.latitude', ''); $longitude = getConfig('main:weather.longitude', ''); - + if ($serviceToken == '' && $service == 'openweathermap') return 3; - + if ($postcode == '' && $city == '') return 2; - + if (($type == 'postcode' && $postcode == '') || ($type == 'city' && $city == '')) return 0; - + if ($type == 'postcode') $location = $postcode; else $location = $city; - + $output = array(); - - if ($service == 'openweathermap') - { - $curl = new cURL('http://api.openweathermap.org/data/2.5/weather?q='.$location.','.$country.'&units=metric&lang=de&appid='.$serviceToken); + + if ($service == 'openweathermap') { + $curl = new cURL('http://api.openweathermap.org/data/2.5/weather?q=' . $location . ',' . $country . '&units=metric&lang=de&appid=' . $serviceToken); $curl->execute(); - + if ($curl->getStatusCode() != '200') return $curl->getStatusCode(); - + if ($curl->getResult($data) != JSON_ERROR_NONE) return 1; - + if (!isset($data['name']) || !isset($data['weather'])) return 1; - + $output['service'] = 'openweathermap'; $output['city'] = $data['name']; $output['country'] = $data['sys']['country']; - $output['temp'] = str_replace('.', ',' , round($data['main']['temp'])); - $output['temp_min'] = str_replace('.', ',' , round($data['main']['temp_min'])); - $output['temp_max'] = str_replace('.', ',' , round($data['main']['temp_max'])); + $output['temp'] = str_replace('.', ',', round($data['main']['temp'])); + $output['temp_min'] = str_replace('.', ',', round($data['main']['temp_min'])); + $output['temp_max'] = str_replace('.', ',', round($data['main']['temp_max'])); $output['humidity'] = $data['main']['humidity']; - $output['wind'] = str_replace('.', ',' , round($data['wind']['speed'])); + $output['wind'] = str_replace('.', ',', round($data['wind']['speed'])); $output['icon'] = getWeatherIconOpenWeatherMap($data['weather'][0]['icon']); $output['description'] = $data['weather'][0]['description']; - - if (empty($data['name'])) - { - $curl = new cURL('http://api.openweathermap.org/data/2.5/weather?q='.$location.','.$country.'&appid='.$serviceToken); + + if (empty($data['name'])) { + $curl = new cURL('http://api.openweathermap.org/data/2.5/weather?q=' . $location . ',' . $country . '&appid=' . $serviceToken); $curl->execute(); - + if ($curl->getStatusCode() != '200') return $curl->getStatusCode(); - + if ($curl->getResult($data) != JSON_ERROR_NONE) return 1; - + if (!isset($data['name']) || !isset($data['weather'])) return 1; - + $output['city'] = $data['name']; $output['country'] = $data['sys']['country']; } - } - elseif ($service == 'yahoo') - { - for ($i = 0; $i < 2; $i++) - { + } elseif ($service == 'yahoo') { + for ($i = 0; $i < 2; $i++) { $yahooApiUrl = 'https://query.yahooapis.com/v1/public/yql'; - $yqlQuery = 'select location, wind, atmosphere, item.condition, item.forecast from weather.forecast where woeid in (select woeid from geo.places(1) where text="'.$location.', '.$country.'") AND u=\'c\' | truncate(count=1)'; - $yqlQueryUrl = $yahooApiUrl.'?q='.urlencode($yqlQuery).'&format=json'; - + $yqlQuery = 'select location, wind, atmosphere, item.condition, item.forecast from weather.forecast where woeid in (select woeid from geo.places(1) where text="' . $location . ', ' . $country . '") AND u=\'c\' | truncate(count=1)'; + $yqlQueryUrl = $yahooApiUrl . '?q=' . urlencode($yqlQuery) . '&format=json'; + $curl = new cURL($yqlQueryUrl); $curl->execute(); - - if ($curl->getStatusCode() != '200') - { + + if ($curl->getStatusCode() != '200') { if ($curl->getStatusCode() == '0') return 100; - + return $curl->getStatusCode(); } - + if ($curl->getResult($data) != JSON_ERROR_NONE) return 1; - - if (!isset($data['query']['results']['channel'])) - { + + if (!isset($data['query']['results']['channel'])) { if ($i == 0) continue; - + return 1; } - + $data = $data['query']['results']['channel']; - + $output['service'] = 'yahoo'; $output['city'] = $data['location']['city']; $output['country'] = $data['location']['country']; - $output['temp'] = str_replace('.', ',' , round($data['item']['condition']['temp'])); - $output['temp_min'] = str_replace('.', ',' , round($data['item']['forecast']['low'])); - $output['temp_max'] = str_replace('.', ',' , round($data['item']['forecast']['high'])); + $output['temp'] = str_replace('.', ',', round($data['item']['condition']['temp'])); + $output['temp_min'] = str_replace('.', ',', round($data['item']['forecast']['low'])); + $output['temp_max'] = str_replace('.', ',', round($data['item']['forecast']['high'])); $output['humidity'] = $data['atmosphere']['humidity']; - $output['wind'] = str_replace('.', ',' , round($data['wind']['speed'])); + $output['wind'] = str_replace('.', ',', round($data['wind']['speed'])); $output['icon'] = getWeatherIconYahoo($data['item']['condition']['code']); $output['description'] = $data['item']['condition']['text']; } - } - elseif ($service == 'wunderground') - { - switch ($globalLanguage) - { + } elseif ($service == 'wunderground') { + switch ($globalLanguage) { case 'de': - $lang = 'DL'; + $lang = 'DL'; break; case 'en': - $lang = 'US'; + $lang = 'US'; break; default: - $lang = 'DL'; + $lang = 'DL'; } - - switch ($country) - { + + switch ($country) { case 'germany': - $customCountry = 'germany'; + $customCountry = 'germany'; break; case 'uk': - $customCountry = 'UK'; + $customCountry = 'UK'; break; case 'swiss': - $customCountry = 'switzerland'; + $customCountry = 'switzerland'; break; case 'austria': - $customCountry = 'austria'; + $customCountry = 'austria'; break; } - + if ($type == 'city') - $location = $customCountry.'/'.$city; + $location = $customCountry . '/' . $city; elseif ($type == 'coordinates') - $location = $latitude.','.$longitude; - + $location = $latitude . ',' . $longitude; + $iMax = 2; - - do - { + + do { if (($wundergroundCache = getConfig('main:weather.wundergroundCache', '')) != '') - $location = 'zmw:'.$wundergroundCache; - - $curl = new cURL('http://api.wunderground.com/api/'.$serviceToken.'/conditions/forecast/lang:'.$lang.'/q/'.$location.'.json'); + $location = 'zmw:' . $wundergroundCache; + + $curl = new cURL('http://api.wunderground.com/api/' . $serviceToken . '/conditions/forecast/lang:' . $lang . '/q/' . $location . '.json'); $curl->execute(); - + if ($curl->getStatusCode() != '200') return $curl->getStatusCode(); - + if ($curl->getResult($data) != JSON_ERROR_NONE) return 1; - - if (isset($data['response']['results']) && count($data['response']['results']) > 0 && $iMax >= 0) - { + + if (isset($data['response']['results']) && count($data['response']['results']) > 0 && $iMax >= 0) { $iMax--; - + setConfig('main:weather.wundergroundCache', $data['response']['results'][0]['zmw']); continue; } - } - while (false); - + } while (false); + if (!isset($data['current_observation'])) return 1; - + $forecast = $data['forecast']['simpleforecast']; $data = $data['current_observation']; - + preg_match('#c\/k\/([\w_]+)\.gif#', $data['icon_url'], $matches); - + $output['service'] = 'wunderground'; $output['city'] = $data['display_location']['city']; $output['country'] = $data['display_location']['country_iso3166']; - $output['temp'] = str_replace('.', ',' , round($data['temp_c'])); - $output['temp_min'] = str_replace('.', ',' , round($forecast['forecastday'][0]['low']['celsius'])); - $output['temp_max'] = str_replace('.', ',' , round($forecast['forecastday'][0]['high']['celsius'])); + $output['temp'] = str_replace('.', ',', round($data['temp_c'])); + $output['temp_min'] = str_replace('.', ',', round($forecast['forecastday'][0]['low']['celsius'])); + $output['temp_max'] = str_replace('.', ',', round($forecast['forecastday'][0]['high']['celsius'])); $output['humidity'] = str_replace('%', '', $data['relative_humidity']); - $output['wind'] = str_replace('.', ',' , round($data['wind_kph'])); + $output['wind'] = str_replace('.', ',', round($data['wind_kph'])); $output['icon'] = getWeatherIconWunderground(isset($matches[1]) ? $matches[1] : $data['icon']); $output['description'] = $data['weather']; - } - elseif ($service == 'darksky') - { + } elseif ($service == 'darksky') { $lang = $globalLanguage; - - $curl = new cURL('https://api.darksky.net/forecast/'.$serviceToken.'/'.$latitude.','.$longitude.'?lang='.$lang.'&units=si'); + + $curl = new cURL('https://api.darksky.net/forecast/' . $serviceToken . '/' . $latitude . ',' . $longitude . '?lang=' . $lang . '&units=si'); $curl->execute(); - + if ($curl->getStatusCode() != '200') return $curl->getStatusCode(); - + if ($curl->getResult($data) != JSON_ERROR_NONE) return 1; - + if (!isset($data['currently'])) return 1; - + $dataRaw = $data; $data = $data['currently']; - + $output['service'] = 'darksky'; - $output['city'] = $dataRaw['latitude'].', '.$dataRaw['longitude']; - $output['country'] = $dataRaw['latitude'].', '.$dataRaw['longitude']; - $output['temp'] = str_replace('.', ',' , round($data['temperature'])); + $output['city'] = $dataRaw['latitude'] . ', ' . $dataRaw['longitude']; + $output['country'] = $dataRaw['latitude'] . ', ' . $dataRaw['longitude']; + $output['temp'] = str_replace('.', ',', round($data['temperature'])); $output['temp_min'] = NULL; $output['temp_max'] = NULL; $output['humidity'] = $data['humidity'] * 100; - $output['wind'] = str_replace('.', ',' , round($data['windSpeed'])); + $output['wind'] = str_replace('.', ',', round($data['windSpeed'])); $output['icon'] = getWeatherIconDarksky($data['icon']); $output['description'] = $data['summary']; - } - elseif ($service == 'yr') - { + } elseif ($service == 'yr') { $yrCache = getConfig('main:weather.yrCache', ''); - - if ($yrCache == '') - { - switch ($country) - { + + if ($yrCache == '') { + switch ($country) { case 'germany': - $customCountry = 'de'; + $customCountry = 'de'; break; case 'uk': - $customCountry = 'gb'; + $customCountry = 'gb'; break; case 'swiss': - $customCountry = 'ch'; + $customCountry = 'ch'; break; case 'austria': - $customCountry = 'at'; + $customCountry = 'at'; break; } - + $yrCache = getYrQueryFromLocation($location, $customCountry); - + if (is_int($yrCache)) return 1; - + setConfig('main:weather.yrCache', $yrCache); } - - $curl = new cURL('http://www.yr.no/place/'.$yrCache.'/forecast.xml'); + + $curl = new cURL('http://www.yr.no/place/' . $yrCache . '/forecast.xml'); $curl->execute(); - + if ($curl->getStatusCode() != '200') return $curl->getStatusCode(); - + $curl->getResult($data, false); - + $data = json_decode(json_encode(simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA)), true); - + if (!isset($data['location']) || !isset($data['forecast'])) return 1; - + $dataRaw = $data; $data = $data['forecast']['tabular']['time'][0]; - + $icon = preg_match('#([\d]+[d|n]?)#i', $data['symbol']['@attributes']['var'], $matches); - + $output['service'] = 'yr'; $output['city'] = $dataRaw['location']['name']; $output['country'] = $dataRaw['location']['country']; - $output['temp'] = str_replace('.', ',' , round($data['temperature']['@attributes']['value'])); + $output['temp'] = str_replace('.', ',', round($data['temperature']['@attributes']['value'])); $output['temp_min'] = NULL; $output['temp_max'] = NULL; $output['humidity'] = NULL; - $output['wind'] = str_replace('.', ',' , round($data['windSpeed']['@attributes']['mps'] * 1.609344)); + $output['wind'] = str_replace('.', ',', round($data['windSpeed']['@attributes']['mps'] * 1.609344)); $output['icon'] = getWeatherIconYr(isset($matches[1]) ? $matches[1] : $data['symbol']['@attributes']['numberEx']); $output['description'] = $data['symbol']['@attributes']['name']; } - + return $output; } function getYrQueryFromLocation($location, $country) { - if (!class_exists('cURL')) - (include LIBRARY_PATH.'curl/curl.class.php'); - - $curl = new cURL('http://www.geonames.org/postalcode-search.html?q='.urlencode($location).'&country='.$country); + if (!class_exists('cURL')) (include LIBRARY_PATH . 'curl/curl.class.php'); + + $curl = new cURL('http://www.geonames.org/postalcode-search.html?q=' . urlencode($location) . '&country=' . $country); $curl->execute(); - + if ($curl->getStatusCode() != '200') return $curl->getStatusCode(); - + $curl->getResult($data, false); - + preg_match('#(?:(.*?)<\/td>){2}(?:(.*?)<\/td>){2}(?:(.*?)<\/td>)#si', $data, $matches); - + if (!isset($matches) || count($matches) != 4) return 1; - + if ($country == 'ch') - return rawurlencode($matches[2]).'/'.rawurlencode($matches[1]).'/'.rawurlencode($matches[1]); + return rawurlencode($matches[2]) . '/' . rawurlencode($matches[1]) . '/' . rawurlencode($matches[1]); else - return rawurlencode($matches[2]).'/'.rawurlencode($matches[3]).'/'.rawurlencode($matches[1]); + return rawurlencode($matches[2]) . '/' . rawurlencode($matches[3]) . '/' . rawurlencode($matches[1]); } function array_sort($array, $on, $order = SORT_ASC) @@ -1428,24 +1355,18 @@ function array_sort($array, $on, $order = SORT_ASC) $new_array = array(); $sortable_array = array(); - if (count($array) > 0) - { - foreach ($array as $k => $v) - { - if (is_array($v)) - { - foreach ($v as $k2 => $v2) - { + if (count($array) > 0) { + foreach ($array as $k => $v) { + if (is_array($v)) { + foreach ($v as $k2 => $v2) { if ($k2 == $on) $sortable_array[$k] = $v2; } - } - else + } else $sortable_array[$k] = $v; } - switch ($order) - { + switch ($order) { case SORT_ASC: asort($sortable_array); break; @@ -1457,7 +1378,7 @@ function array_sort($array, $on, $order = SORT_ASC) foreach ($sortable_array as $k => $v) $new_array[$k] = $array[$k]; } - + return $new_array; } @@ -1466,112 +1387,99 @@ function generateUniqId($length = 16, $upper = true) $random1 = rand(1, 1000); $random2 = rand(1, 1000); $random3 = rand(1, 1000); - - $random11 = 'random'.rand(1, 3); - $random12 = 'random'.rand(1, 3); - $random13 = 'random'.rand(1, 3); - + + $random11 = 'random' . rand(1, 3); + $random12 = 'random' . rand(1, 3); + $random13 = 'random' . rand(1, 3); + $random = md5($$random11 - $$random12 + $$random13); $microtime = md5(microtime(true)); - - $uniqid = substr(md5($random.$microtime.uniqid()), 0, $length); - + + $uniqid = substr(md5($random . $microtime . uniqid()), 0, $length); + return ($upper !== true) ? $uniqid : strtoupper($uniqid); } function arraySort($array, $on, $order = SORT_ASC) { - $new_array = array(); - $sortable_array = array(); - - if (count($array) > 0) - { - foreach ($array as $k => $v) - { - if (is_array($v)) - { - foreach ($v as $k2 => $v2) - { - if ($k2 == $on) - $sortable_array[$k] = $v2; - } - } - else - $sortable_array[$k] = $v; - } + $new_array = array(); + $sortable_array = array(); - switch ($order) - { - case SORT_ASC: - asort($sortable_array); - break; - case SORT_DESC: - arsort($sortable_array); - break; - } + if (count($array) > 0) { + foreach ($array as $k => $v) { + if (is_array($v)) { + foreach ($v as $k2 => $v2) { + if ($k2 == $on) + $sortable_array[$k] = $v2; + } + } else + $sortable_array[$k] = $v; + } - foreach ($sortable_array as $k => $v) - $new_array[$k] = $array[$k]; - } + switch ($order) { + case SORT_ASC: + asort($sortable_array); + break; + case SORT_DESC: + arsort($sortable_array); + break; + } - return $new_array; + foreach ($sortable_array as $k => $v) + $new_array[$k] = $array[$k]; + } + + return $new_array; } function ipInRange($ip, $ranges) { if (!is_array($ranges)) $ranges[] = $ranges; - - foreach ($ranges as $range) - { + + foreach ($ranges as $range) { $return = false; - - if (strpos($range, '/') !== false) - { + + if (strpos($range, '/') !== false) { list($range, $netmask) = explode('/', $range, 2); - + $blocks = explode('.', $range); for ($i = count($blocks); $i < 4; $i++) - $blocks[] = '0'; - + $blocks[] = '0'; + $rangeLong = ip2long(implode('.', $blocks)); $ipLong = ip2long($ip); - + $wildcardLong = pow(2, (32 - $netmask)) - 1; - $netmaskLong = ~ $wildcardLong; - + $netmaskLong = ~$wildcardLong; + $return = (($ipLong & $netmaskLong) == ($rangeLong & $netmaskLong)); - } - else - { - if (strpos($range, '*') !== false) - { + } else { + if (strpos($range, '*') !== false) { $lower = str_replace('*', '0', $range); $upper = str_replace('*', '255', $range); - $range = $lower.'-'.$upper; + $range = $lower . '-' . $upper; } - - if (strpos($range, '-') !== false) - { - list ($lower, $upper) = explode('-', $range, 2); + + if (strpos($range, '-') !== false) { + list($lower, $upper) = explode('-', $range, 2); $lowerLong = (float) sprintf('%u', ip2long($lower)); $upperLong = (float) sprintf('%u', ip2long($upper)); $ipLong = (float) sprintf('%u', ip2long($ip)); $return = (($ipLong >= $lowerLong) && ($ipLong <= $upperLong)); } - - if (filter_var($range, FILTER_VALIDATE_IP)) - { + + if (filter_var($range, FILTER_VALIDATE_IP)) { $rangeLong = ip2long($range); $ipLong = ip2long($ip); $return = ($ipLong == $rangeLong); } } - + if ($return == true) return true; } - + return false; } @@ -1579,13 +1487,14 @@ function getLanguageFromIso($isoCode) { if (empty($isoCode)) return false; - - switch ($isoCode) - { - case 'de': return _t('Deutsch'); - case 'en': return _t('Englisch'); + + switch ($isoCode) { + case 'de': + return _t('Deutsch'); + case 'en': + return _t('Englisch'); } - + return false; } @@ -1593,28 +1502,32 @@ function getTranslatedArrayForJs($translations) { if (!is_array($translations)) return false; - + $output = array(); - + foreach ($translations as $translation) $output[$translation] = _t($translation); - + return $output; } function getInfoForHeaderBar() { $type = getConfig('main:headerInfo.type', 'disable'); - - switch ($type) - { - case 'label': return getConfig('main:main.label', 'Raspberry Pi'); - case 'label-ip': return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), $_SERVER['SERVER_ADDR']); - case 'label-hostname': return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), trim(@shell_exec('cat /proc/sys/kernel/hostname'))); - case 'ip': return $_SERVER['SERVER_ADDR']; - case 'hostname': return trim(@shell_exec('cat /proc/sys/kernel/hostname')); + + switch ($type) { + case 'label': + return getConfig('main:main.label', 'Raspberry Pi'); + case 'label-ip': + return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), $_SERVER['SERVER_ADDR']); + case 'label-hostname': + return sprintf('%s (%s)', getConfig('main:main.label', 'Raspberry Pi'), trim(@shell_exec('cat /proc/sys/kernel/hostname'))); + case 'ip': + return $_SERVER['SERVER_ADDR']; + case 'hostname': + return trim(@shell_exec('cat /proc/sys/kernel/hostname')); case 'disable': - default: return false; + default: + return false; } } -?> \ No newline at end of file diff --git a/resources/library/statistic/statistic.config.php b/resources/library/statistic/statistic.config.php index eb37443..b79f72c 100644 --- a/resources/library/statistic/statistic.config.php +++ b/resources/library/statistic/statistic.config.php @@ -84,7 +84,7 @@ $statisticConfig = array( 'fix' => true ), 'max' => array( - 'value' => 1200, + 'value' => 2100, 'use' => 'fix', 'fix' => true ) diff --git a/resources/library/update/update.class.php b/resources/library/update/update.class.php index 07c5b67..7fe6e46 100644 --- a/resources/library/update/update.class.php +++ b/resources/library/update/update.class.php @@ -268,7 +268,7 @@ class UpdateController return $curl->getStatusCode(); } - if (md5_file(UPDATE_PATH.'update.zip') !== $version->getChecksum()) + if (hash_file('sha256', UPDATE_PATH.'update.zip') !== $version->getChecksum()) { unlink(UPDATE_PATH.'update.zip'); return 1;