add language support to webservices

This commit is contained in:
John
2023-01-02 19:59:53 +01:00
parent 1e885611dd
commit 4263c98f04
4 changed files with 39 additions and 17 deletions
+14 -6
View File
@@ -1,19 +1,29 @@
<?php <?php
$agent = $_SERVER['HTTP_USER_AGENT']; $agent = @$_SERVER['HTTP_USER_AGENT'];
if (substr($agent, 0, 5)!=='ebusd') { if (substr($agent, 0, 5)!=='ebusd') {
header('Location: https://upd.ebusd.eu/', true, 301); header('Location: https://upd.ebusd.eu/', true, 301);
exit; exit;
} }
$dir=realpath('.');
$p=@$_REQUEST['p']; $p=@$_REQUEST['p'];
$e=@$_REQUEST['t']; $e=@$_REQUEST['t'];
$a=@$_REQUEST['a']; $a=@$_REQUEST['a'];
if ($p && $p[0]==='/') { $l=@$_REQUEST['l'];
while ($p && $p[0]==='/') {
$p=substr($p, 1); $p=substr($p, 1);
} }
if ($p && $p[strlen($p)-1]==='/') { if ($p && $p[strlen($p)-1]==='/') {
$p=substr($p, 0, 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('Content-Type: text/comma-separated-values');
header('Cache-Control: Private'); header('Cache-Control: Private');
$t=@filemtime($p); $t=@filemtime($p);
@@ -31,9 +41,7 @@ if (!$e) {
exit; exit;
} }
$e=".$e"; $e=".$e";
if (!$p) { if (strpos($p, '/', strlen($l))!==FALSE || strpos($p, '\\')!==FALSE || strpos($p, '..')!==FALSE) {
$p='.';
} else if (strpos($p, '/')!==FALSE || strpos($p, '\\')!==FALSE || strpos($p, '..')!==FALSE) {
header('HTTP/1.1 400 Bad Request'); header('HTTP/1.1 400 Bad Request');
exit; exit;
} }
+8 -2
View File
@@ -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# ##'` 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# ##'` 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 echo "device=${devver},${devbl}" >> versions.txt
files=`find config/ -type f -or -type l` files=`find config/de -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 ../../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 #./oldtest_filereader $files|sed -e 's#^config/##' -e 's#^\([^ ]*\) #\1=#' -e 's# #,#g'|sort >> oldversions.txt
+13 -6
View File
@@ -5,7 +5,7 @@ if (substr($agent, 0, 5)==='ebusd') {
$r = @file_get_contents('php://input'); $r = @file_get_contents('php://input');
header('Content-Type: text/plain'); header('Content-Type: text/plain');
$r = @json_decode($r, true); $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; exit;
} }
readVersions(); 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 ebusd version: <?=$versions['ebusd'][0]?></p>
<p>latest device firmware: <?=$versions['device'][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 <?php
$func = function($v, $k) { $func = function($v, $k) {
if ($k==='ebusd' || $k==='device') { if ($k==='ebusd' || $k==='device') {
return; return;
} }
echo "<tr><td>$k</td>";
global $ref; 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) { 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 { } 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); array_walk($versions, $func);
?> ?>
</p> </tbody></table></p>
</body> </body>
+4 -3
View File
@@ -16,7 +16,7 @@ function readVersions($old=false) {
array_walk($v, $func); array_walk($v, $func);
} }
} }
function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion, $loadedFiles) { function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion, $loadedFiles, $language) {
if (!$ebusdVersion) { if (!$ebusdVersion) {
return 'invalid request'; return 'invalid request';
} }
@@ -39,11 +39,12 @@ function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion
} }
$newerAvailable = 0; $newerAvailable = 0;
$configs = ''; $configs = '';
$offset = $language==='en' ? 3 : 0;
foreach ($loadedFiles as $k => $val) { foreach ($loadedFiles as $k => $val) {
$v = $versions[$k]; $v = $versions[$k];
if ($v) { if ($v) {
$newer = $v[2]>$val['t']; $newer = $v[2+$offset]>$val['t'];
if ($v[0]!=$val['h'] || $v[1]!=$val['s']) { if ($v[0+$offset]!=$val['h'] || $v[1+$offset]!=$val['s']) {
if ($newer) { if ($newer) {
$newerAvailable++; $newerAvailable++;
} }