|
|
|
|
@@ -28,8 +28,7 @@ function setConfig($config, $value, $customFile = NULL)
|
|
|
|
|
|
|
|
|
|
$configFile = $configPath . $file[0] . $configFileSuffix;
|
|
|
|
|
|
|
|
|
|
if (file_exists($configFile) !== true || is_file($configFile) !== true)
|
|
|
|
|
{
|
|
|
|
|
if (file_exists($configFile) !== true || is_file($configFile) !== true) {
|
|
|
|
|
if (!touch($configFile))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -85,17 +84,14 @@ function getConfig($config, $default = NULL, $customFile = NULL)
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
@@ -152,16 +148,13 @@ function writeConfig($configArray, $configFile)
|
|
|
|
|
|
|
|
|
|
ksort($configArray);
|
|
|
|
|
|
|
|
|
|
foreach ($configArray as $key => $val)
|
|
|
|
|
{
|
|
|
|
|
if (is_array($val))
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
} else
|
|
|
|
|
$res[] = PHP_EOL . "$key = " . (is_numeric($val) ? $val : '"' . $val . '"');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -170,11 +163,9 @@ function writeConfig($configArray, $configFile)
|
|
|
|
|
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
|
|
|
|
|
@@ -183,8 +174,7 @@ function writeConfig($configArray, $configFile)
|
|
|
|
|
} 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);
|
|
|
|
|
}
|
|
|
|
|
@@ -212,8 +202,7 @@ function _t()
|
|
|
|
|
$lang = $globalLanguage;
|
|
|
|
|
$langFile = LANGUAGE_PATH . $lang . '.php';
|
|
|
|
|
|
|
|
|
|
if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true)
|
|
|
|
|
{
|
|
|
|
|
if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) {
|
|
|
|
|
include $langFile;
|
|
|
|
|
$globalLanguageArray = $langArray;
|
|
|
|
|
}
|
|
|
|
|
@@ -247,8 +236,7 @@ function _e()
|
|
|
|
|
$lang = $globalLanguage;
|
|
|
|
|
$langFile = LANGUAGE_PATH . $lang . '.php';
|
|
|
|
|
|
|
|
|
|
if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true)
|
|
|
|
|
{
|
|
|
|
|
if (empty($globalLanguageArray) && file_exists($langFile) === true && is_file($langFile) === true) {
|
|
|
|
|
include $langFile;
|
|
|
|
|
$globalLanguageArray = $langArray;
|
|
|
|
|
}
|
|
|
|
|
@@ -288,8 +276,7 @@ function return_bytes($size)
|
|
|
|
|
$size = trim($size);
|
|
|
|
|
$last = strtolower($size[strlen($size) - 1]);
|
|
|
|
|
|
|
|
|
|
switch ($last)
|
|
|
|
|
{
|
|
|
|
|
switch ($last) {
|
|
|
|
|
case 'g':
|
|
|
|
|
$size *= 1024;
|
|
|
|
|
case 'm':
|
|
|
|
|
@@ -309,11 +296,9 @@ 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))
|
|
|
|
|
{
|
|
|
|
|
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 != '..')
|
|
|
|
|
@@ -331,11 +316,12 @@ function formatTime($time, $type = 'd.m.Y H:i')
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -345,8 +331,7 @@ function checkUpdate()
|
|
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
@@ -360,8 +345,7 @@ function checkUpdate()
|
|
|
|
|
if (!isset($data['versions'], $data['latest']))
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if ($data['latest']['versioncode'] > $config['version']['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]))
|
|
|
|
|
@@ -370,8 +354,7 @@ function checkUpdate()
|
|
|
|
|
$data['versions'][$currentUpdateKey]['changelog'] = current($data['versions'][$currentUpdateKey]['changelog']);
|
|
|
|
|
|
|
|
|
|
return $data['versions'][$currentUpdateKey];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -420,8 +403,7 @@ function getAllNetworkConnections()
|
|
|
|
|
|
|
|
|
|
$streamInterfaces = explode('-#-', shell_exec($shell_string));
|
|
|
|
|
|
|
|
|
|
foreach ($streamInterfaces as $index => $streamInterface)
|
|
|
|
|
{
|
|
|
|
|
foreach ($streamInterfaces as $index => $streamInterface) {
|
|
|
|
|
$wirelessOption = '';
|
|
|
|
|
|
|
|
|
|
$interface = $networkInterfaces[$index];
|
|
|
|
|
@@ -435,12 +417,10 @@ function getAllNetworkConnections()
|
|
|
|
|
|
|
|
|
|
$output0 = $interface;
|
|
|
|
|
|
|
|
|
|
if (substr($output0, 0, 4) == 'wlan')
|
|
|
|
|
{
|
|
|
|
|
if (substr($output0, 0, 4) == 'wlan') {
|
|
|
|
|
$streamWirelessInterface = shell_exec('/sbin/iwconfig ' . $output0);
|
|
|
|
|
|
|
|
|
|
if (0 == substr_count($streamWirelessInterface, 'Not-Associated'))
|
|
|
|
|
{
|
|
|
|
|
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)));
|
|
|
|
|
@@ -451,8 +431,7 @@ function getAllNetworkConnections()
|
|
|
|
|
|
|
|
|
|
$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)));
|
|
|
|
|
|
|
|
|
|
@@ -462,10 +441,8 @@ function getAllNetworkConnections()
|
|
|
|
|
$wirelessOption['signal'] = 100;
|
|
|
|
|
else
|
|
|
|
|
$wirelessOption['signal'] = 2 * ($signal + 100);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
$wirelessOption['signal'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -481,8 +458,7 @@ function scanAccessPoints($networkConnections, $ssh = false)
|
|
|
|
|
|
|
|
|
|
$wlan = array();
|
|
|
|
|
|
|
|
|
|
foreach ($networkConnections as $interface)
|
|
|
|
|
{
|
|
|
|
|
foreach ($networkConnections as $interface) {
|
|
|
|
|
if (substr($interface['interface'], 0, 4) != 'wlan')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
@@ -493,8 +469,7 @@ function scanAccessPoints($networkConnections, $ssh = false)
|
|
|
|
|
else
|
|
|
|
|
$streamWlan = shell_exec('/sbin/iwlist ' . escapeshellarg($interface['interface']) . ' scan');
|
|
|
|
|
|
|
|
|
|
for ($i = 1; $i <= substr_count($streamWlan, 'ESSID:"'); $i += 1)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
@@ -520,8 +495,7 @@ function scanAccessPoints($networkConnections, $ssh = false)
|
|
|
|
|
|
|
|
|
|
$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)
|
|
|
|
|
@@ -558,9 +532,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)
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -581,12 +561,9 @@ function getDirectory($folder_)
|
|
|
|
|
$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_;
|
|
|
|
|
}
|
|
|
|
|
@@ -619,10 +596,8 @@ function getAllFiles($folder_)
|
|
|
|
|
else
|
|
|
|
|
$fileArray[] = $file_;
|
|
|
|
|
|
|
|
|
|
if (isset($folderArray))
|
|
|
|
|
{
|
|
|
|
|
foreach ($folderArray as $row)
|
|
|
|
|
{
|
|
|
|
|
if (isset($folderArray)) {
|
|
|
|
|
foreach ($folderArray as $row) {
|
|
|
|
|
list($file_return, $error_log) = getAllFiles($folder_ . '/' . $row);
|
|
|
|
|
$file[$row] = $file_return;
|
|
|
|
|
|
|
|
|
|
@@ -633,10 +608,8 @@ function getAllFiles($folder_)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($fileArray))
|
|
|
|
|
{
|
|
|
|
|
foreach ($fileArray as $row)
|
|
|
|
|
{
|
|
|
|
|
if (isset($fileArray)) {
|
|
|
|
|
foreach ($fileArray as $row) {
|
|
|
|
|
$file[] = $row;
|
|
|
|
|
|
|
|
|
|
if (is_writeable($folder_ . '/' . $row) !== true)
|
|
|
|
|
@@ -651,8 +624,7 @@ function deleteFolder($folder)
|
|
|
|
|
{
|
|
|
|
|
chmod($folder, 0777);
|
|
|
|
|
|
|
|
|
|
if (is_dir($folder))
|
|
|
|
|
{
|
|
|
|
|
if (is_dir($folder)) {
|
|
|
|
|
$handle = opendir($folder);
|
|
|
|
|
while ($filename = readdir($handle))
|
|
|
|
|
if ($filename != '.' && $filename != '..')
|
|
|
|
|
@@ -660,21 +632,18 @@ function deleteFolder($folder)
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -719,38 +688,28 @@ function addCronToCrontab($cronEntry, $ssh)
|
|
|
|
|
$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)
|
|
|
|
|
{
|
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
|
if ($lineCount == $hashtagLine) {
|
|
|
|
|
if ($hashtag == 0) {
|
|
|
|
|
$newFile .= $cronEntry . "\n";
|
|
|
|
|
$newFile .= '#';
|
|
|
|
|
}
|
|
|
|
|
elseif ($hashtag == 1)
|
|
|
|
|
} elseif ($hashtag == 1)
|
|
|
|
|
$newFile .= $cronEntry . "\n";
|
|
|
|
|
elseif ($hashtag == 2)
|
|
|
|
|
$newFile .= $cronEntry . "\n";
|
|
|
|
|
@@ -763,30 +722,24 @@ function addCronToCrontab($cronEntry, $ssh)
|
|
|
|
|
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 = 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')))
|
|
|
|
|
{
|
|
|
|
|
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';
|
|
|
|
|
@@ -942,8 +893,7 @@ function getWeatherIconWunderground($icon)
|
|
|
|
|
|
|
|
|
|
function getWeatherIconDarksky($icon)
|
|
|
|
|
{
|
|
|
|
|
switch ($icon)
|
|
|
|
|
{
|
|
|
|
|
switch ($icon) {
|
|
|
|
|
case 'clear-day':
|
|
|
|
|
return '01d';
|
|
|
|
|
case 'clear-night':
|
|
|
|
|
@@ -976,8 +926,7 @@ function getWeatherIconDarksky($icon)
|
|
|
|
|
|
|
|
|
|
function getWeatherIconYr($icon)
|
|
|
|
|
{
|
|
|
|
|
switch ($icon)
|
|
|
|
|
{
|
|
|
|
|
switch ($icon) {
|
|
|
|
|
case '1':
|
|
|
|
|
case '01':
|
|
|
|
|
case '01d':
|
|
|
|
|
@@ -1111,8 +1060,7 @@ 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', '');
|
|
|
|
|
@@ -1139,8 +1087,7 @@ function getWeather()
|
|
|
|
|
|
|
|
|
|
$output = array();
|
|
|
|
|
|
|
|
|
|
if ($service == 'openweathermap')
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
@@ -1164,8 +1111,7 @@ function getWeather()
|
|
|
|
|
$output['icon'] = getWeatherIconOpenWeatherMap($data['weather'][0]['icon']);
|
|
|
|
|
$output['description'] = $data['weather'][0]['description'];
|
|
|
|
|
|
|
|
|
|
if (empty($data['name']))
|
|
|
|
|
{
|
|
|
|
|
if (empty($data['name'])) {
|
|
|
|
|
$curl = new cURL('http://api.openweathermap.org/data/2.5/weather?q=' . $location . ',' . $country . '&appid=' . $serviceToken);
|
|
|
|
|
$curl->execute();
|
|
|
|
|
|
|
|
|
|
@@ -1181,11 +1127,8 @@ function getWeather()
|
|
|
|
|
$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';
|
|
|
|
|
@@ -1193,8 +1136,7 @@ function getWeather()
|
|
|
|
|
$curl = new cURL($yqlQueryUrl);
|
|
|
|
|
$curl->execute();
|
|
|
|
|
|
|
|
|
|
if ($curl->getStatusCode() != '200')
|
|
|
|
|
{
|
|
|
|
|
if ($curl->getStatusCode() != '200') {
|
|
|
|
|
if ($curl->getStatusCode() == '0')
|
|
|
|
|
return 100;
|
|
|
|
|
|
|
|
|
|
@@ -1204,8 +1146,7 @@ function getWeather()
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
@@ -1225,11 +1166,8 @@ function getWeather()
|
|
|
|
|
$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';
|
|
|
|
|
break;
|
|
|
|
|
@@ -1240,8 +1178,7 @@ function getWeather()
|
|
|
|
|
$lang = 'DL';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($country)
|
|
|
|
|
{
|
|
|
|
|
switch ($country) {
|
|
|
|
|
case 'germany':
|
|
|
|
|
$customCountry = 'germany';
|
|
|
|
|
break;
|
|
|
|
|
@@ -1263,8 +1200,7 @@ function getWeather()
|
|
|
|
|
|
|
|
|
|
$iMax = 2;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
do {
|
|
|
|
|
if (($wundergroundCache = getConfig('main:weather.wundergroundCache', '')) != '')
|
|
|
|
|
$location = 'zmw:' . $wundergroundCache;
|
|
|
|
|
|
|
|
|
|
@@ -1277,15 +1213,13 @@ function getWeather()
|
|
|
|
|
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;
|
|
|
|
|
@@ -1305,9 +1239,7 @@ function getWeather()
|
|
|
|
|
$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');
|
|
|
|
|
@@ -1335,15 +1267,11 @@ function getWeather()
|
|
|
|
|
$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';
|
|
|
|
|
break;
|
|
|
|
|
@@ -1401,8 +1329,7 @@ function getWeather()
|
|
|
|
|
|
|
|
|
|
function getYrQueryFromLocation($location, $country)
|
|
|
|
|
{
|
|
|
|
|
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('http://www.geonames.org/postalcode-search.html?q=' . urlencode($location) . '&country=' . $country);
|
|
|
|
|
$curl->execute();
|
|
|
|
|
@@ -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;
|
|
|
|
|
@@ -1484,24 +1405,18 @@ 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 (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;
|
|
|
|
|
@@ -1522,12 +1437,10 @@ 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);
|
|
|
|
|
@@ -1541,18 +1454,14 @@ function ipInRange($ip, $ranges)
|
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strpos($range, '-') !== false)
|
|
|
|
|
{
|
|
|
|
|
if (strpos($range, '-') !== false) {
|
|
|
|
|
list($lower, $upper) = explode('-', $range, 2);
|
|
|
|
|
$lowerLong = (float) sprintf('%u', ip2long($lower));
|
|
|
|
|
$upperLong = (float) sprintf('%u', ip2long($upper));
|
|
|
|
|
@@ -1560,8 +1469,7 @@ function ipInRange($ip, $ranges)
|
|
|
|
|
$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);
|
|
|
|
|
@@ -1580,10 +1488,11 @@ 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;
|
|
|
|
|
@@ -1606,15 +1515,19 @@ 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|