add language support to webservices
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
<?php
|
||||
$agent = $_SERVER['HTTP_USER_AGENT'];
|
||||
$agent = @$_SERVER['HTTP_USER_AGENT'];
|
||||
if (substr($agent, 0, 5)!=='ebusd') {
|
||||
header('Location: https://upd.ebusd.eu/', true, 301);
|
||||
exit;
|
||||
}
|
||||
$dir=realpath('.');
|
||||
$p=@$_REQUEST['p'];
|
||||
$e=@$_REQUEST['t'];
|
||||
$a=@$_REQUEST['a'];
|
||||
if ($p && $p[0]==='/') {
|
||||
$l=@$_REQUEST['l'];
|
||||
while ($p && $p[0]==='/') {
|
||||
$p=substr($p, 1);
|
||||
}
|
||||
if ($p && $p[strlen($p)-1]==='/') {
|
||||
$p=substr($p, 0, strlen($p)-1);
|
||||
}
|
||||
if ($p && $p[0]!=='/' && strpos($p, '..')===FALSE && is_file($p)) {
|
||||
if ($l && strlen($l)===2 && ctype_alpha($l) && is_dir($l)) {
|
||||
$l=strtolower($l).'/';
|
||||
} else {
|
||||
$l='de/';
|
||||
}
|
||||
$p=$l.($p ? $p : '.');
|
||||
if ($p && strpos($p, '..')===FALSE && is_file($p) && (substr($p, -4)==='.csv' || substr($p, -4)==='.inc')
|
||||
&& strncmp(realpath($p), $dir, strlen($dir))===0
|
||||
) {
|
||||
header('Content-Type: text/comma-separated-values');
|
||||
header('Cache-Control: Private');
|
||||
$t=@filemtime($p);
|
||||
@@ -31,9 +41,7 @@ if (!$e) {
|
||||
exit;
|
||||
}
|
||||
$e=".$e";
|
||||
if (!$p) {
|
||||
$p='.';
|
||||
} else if (strpos($p, '/')!==FALSE || strpos($p, '\\')!==FALSE || strpos($p, '..')!==FALSE) {
|
||||
if (strpos($p, '/', strlen($l))!==FALSE || strpos($p, '\\')!==FALSE || strpos($p, '..')!==FALSE) {
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@ echo "ebusd=${version},${revision}" > oldversions.txt
|
||||
devver=`curl -s https://adapter.ebusd.eu/firmware/ChangeLog|grep "Version "|head -n 1|sed -e 's#.*<code[^>]*>##' -e 's#<.*##' -e 's# ##'`
|
||||
devbl=`curl -s https://adapter.ebusd.eu/firmware/ChangeLog|grep "Bootloader "|head -n 1|sed -e 's#.*<code[^>]*>##' -e 's#<.*##' -e 's# ##'`
|
||||
echo "device=${devver},${devbl}" >> versions.txt
|
||||
files=`find config/ -type f -or -type l`
|
||||
../../src/lib/ebus/test/test_filereader $files|sed -e 's#^config/##' -e 's#^\([^ ]*\) #\1=#' -e 's# #,#g'|sort >> versions.txt
|
||||
files=`find config/de -type f -or -type l`
|
||||
../../src/lib/ebus/test/test_filereader $files|sed -e 's#^config/de/##' -e 's#^\([^ ]*\) #\1=#' -e 's# #,#g'|sort >> versions.txt
|
||||
files=`find config/en -type f -or -type l`
|
||||
for filever in $(../../src/lib/ebus/test/test_filereader $files|sed -e 's#^config/en/##' -e 's#^\([^ ]*\) #\1=#' -e 's# #,#g'); do
|
||||
file=${filever%%=*}
|
||||
ver=${filever#*=}
|
||||
sed -i -e "s#^$file=\(.*\)\$#$file=\1,$ver#" versions.txt
|
||||
done
|
||||
#./oldtest_filereader $files|sed -e 's#^config/##' -e 's#^\([^ ]*\) #\1=#' -e 's# #,#g'|sort >> oldversions.txt
|
||||
|
||||
@@ -5,7 +5,7 @@ if (substr($agent, 0, 5)==='ebusd') {
|
||||
$r = @file_get_contents('php://input');
|
||||
header('Content-Type: text/plain');
|
||||
$r = @json_decode($r, true);
|
||||
echo checkUpdate(@$r['v'], @$r['r'], @$r['a'], @$r['dv'], @$r['l']);
|
||||
echo checkUpdate(@$r['v'], @$r['r'], @$r['a'], @$r['dv'], @$r['l'], @$r['lc']);
|
||||
exit;
|
||||
}
|
||||
readVersions();
|
||||
@@ -24,21 +24,28 @@ $ref = @file_get_contents('ebusd-configuration/.git/refs/heads/master');
|
||||
?>
|
||||
<p>latest ebusd version: <?=$versions['ebusd'][0]?></p>
|
||||
<p>latest device firmware: <?=$versions['device'][0]?></p>
|
||||
<p>config files:
|
||||
<p>config files:<table><thead><th>File</th><th>German</th><th>English</th></thead><tbody>
|
||||
<?php
|
||||
$func = function($v, $k) {
|
||||
if ($k==='ebusd' || $k==='device') {
|
||||
return;
|
||||
}
|
||||
echo "<tr><td>$k</td>";
|
||||
global $ref;
|
||||
$str = "$k: ".date('d.m.Y H:i:s', $v[2]);
|
||||
$str = date('d.m.Y H:i:s', $v[2]);
|
||||
if ($ref) {
|
||||
echo " <br><a href=\"https://github.com/john30/ebusd-configuration/blob/$ref/ebusd-2.1.x/de/$k\">$str</a>\n";
|
||||
echo "<td><a href=\"https://github.com/john30/ebusd-configuration/blob/$ref/ebusd-2.1.x/de/$k\">$str</a></td>\n";
|
||||
} else {
|
||||
echo " <br>$str\n";
|
||||
echo "<td>$str</td>\n";
|
||||
}
|
||||
$str = date('d.m.Y H:i:s', $v[5]);
|
||||
if ($ref) {
|
||||
echo "<td><a href=\"https://github.com/john30/ebusd-configuration/blob/$ref/ebusd-2.1.x/en/$k\">$str</a></td>\n";
|
||||
} else {
|
||||
echo "<td>$str</td>\n";
|
||||
}
|
||||
};
|
||||
array_walk($versions, $func);
|
||||
?>
|
||||
</p>
|
||||
</tbody></table></p>
|
||||
</body>
|
||||
|
||||
@@ -16,7 +16,7 @@ function readVersions($old=false) {
|
||||
array_walk($v, $func);
|
||||
}
|
||||
}
|
||||
function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion, $loadedFiles) {
|
||||
function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion, $loadedFiles, $language) {
|
||||
if (!$ebusdVersion) {
|
||||
return 'invalid request';
|
||||
}
|
||||
@@ -39,11 +39,12 @@ function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion
|
||||
}
|
||||
$newerAvailable = 0;
|
||||
$configs = '';
|
||||
$offset = $language==='en' ? 3 : 0;
|
||||
foreach ($loadedFiles as $k => $val) {
|
||||
$v = $versions[$k];
|
||||
if ($v) {
|
||||
$newer = $v[2]>$val['t'];
|
||||
if ($v[0]!=$val['h'] || $v[1]!=$val['s']) {
|
||||
$newer = $v[2+$offset]>$val['t'];
|
||||
if ($v[0+$offset]!=$val['h'] || $v[1+$offset]!=$val['s']) {
|
||||
if ($newer) {
|
||||
$newerAvailable++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user