support cdn redirection
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
version=`head -n 1 ../../VERSION`
|
||||
revision=`git describe --always`
|
||||
echo "ebusd=${version},${revision}" > versions.txt
|
||||
echo "ebusd=${version},${revision}" > oldversions.txt
|
||||
# cp versions.txt > oldversions.txt
|
||||
devver=`curl -s https://adapter.ebusd.eu/v31/firmware/ChangeLog|grep "<h[0-9].*>Version "|head -n 1|sed -e 's#.*<code[^>]*>##' -e 's#<.*##' -e 's# ##'`
|
||||
devbl=`curl -s https://adapter.ebusd.eu/v31/firmware/ChangeLog|grep "<h[0-9].*>Bootloader version"|head -n 1|sed -e 's#.*<code[^>]*>##' -e 's#<.*##' -e 's# ##'`
|
||||
echo "device=${devver},${devbl}" >> versions.txt
|
||||
devver=`curl -s https://adapter.ebusd.eu/v5/ChangeLog|grep "<h[0-9].*>Version "|head -n 1|sed -e 's#.*<code[^>]*>##' -e 's#<.*##' -e 's# ##'`
|
||||
echo "device=${devver},${devver}" >> versions.txt
|
||||
cp versions.txt cdnversions.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`
|
||||
@@ -17,3 +18,6 @@ for filever in $(../../src/lib/ebus/test/test_filereader $files|sed -e 's#^confi
|
||||
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
|
||||
curl -sS https://ebus.github.io/en/versions.json -o veren.json
|
||||
curl -sS https://ebus.github.io/de/versions.json -o verde.json
|
||||
node -e 'fs=require("fs");e=JSON.parse(fs.readFileSync("veren.json","utf-8"));d=JSON.parse(fs.readFileSync("verde.json","utf-8"));console.log(Object.entries(e).map(([k,v])=>{w=d[k];return `${k}=${v.hash},${v.size},${v.mtime},${w.hash},${w.size},${w.mtime}`;}).join("\n"))' >> cdnversions.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'], @$r['lc']);
|
||||
echo checkUpdate(@$r['v'], @$r['r'], @$r['a'], @$r['dv'], @$r['l'], @$r['lc'], @$r['cp']);
|
||||
exit;
|
||||
}
|
||||
readVersions();
|
||||
|
||||
@@ -1,31 +1,34 @@
|
||||
<?php
|
||||
$versions = array();
|
||||
function readVersions($old=false) {
|
||||
function readVersions($prefix='') {
|
||||
global $versions;
|
||||
$versions = array();
|
||||
$v = @file_get_contents(($old?'old':'').'versions.txt');
|
||||
if ($v) {
|
||||
$v = explode("\n", $v);
|
||||
$func = function($val, $k) {
|
||||
global $versions;
|
||||
$val = explode('=', $val);
|
||||
if (count($val)>1) {
|
||||
$key = $val[0];
|
||||
$val = explode(',', $val[1]);
|
||||
if ($key==='device' && count($val)===2 && $val[0]===$val[1]) {
|
||||
$key = 'devicesame';
|
||||
}
|
||||
$versions[$key] = $val;
|
||||
}
|
||||
};
|
||||
array_walk($v, $func);
|
||||
$v = @file_get_contents($prefix.'versions.txt');
|
||||
if (!$v) {
|
||||
return false;
|
||||
}
|
||||
$v = explode("\n", $v);
|
||||
$func = function($val, $k) {
|
||||
global $versions;
|
||||
$val = explode('=', $val);
|
||||
if (count($val)>1) {
|
||||
$key = $val[0];
|
||||
$val = explode(',', $val[1]);
|
||||
if ($key==='device' && count($val)===2 && $val[0]===$val[1]) {
|
||||
$key = 'devicesame';
|
||||
}
|
||||
$versions[$key] = $val;
|
||||
}
|
||||
};
|
||||
array_walk($v, $func);
|
||||
return true;
|
||||
}
|
||||
function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion, $loadedFiles, $language) {
|
||||
function checkUpdate($ebusdVersion, $ebusdRelease, $architecture, $deviceVersion, $loadedFiles, $language, $cdnPath) {
|
||||
if (!$ebusdVersion) {
|
||||
return 'invalid request';
|
||||
}
|
||||
readVersions($architecture && substr($architecture, 0, 3)!=='arm' && (((float)$ebusdVersion)<3.3 || ($ebusdVersion==='3.3' && ($ebusdRelease==='v3.3' || (strtok($ebusdRelease, '-')==='v3.3') && strtok('-')<18))));
|
||||
$old = $architecture && substr($architecture, 0, 3)!=='arm' && (((float)$ebusdVersion)<3.3 || ($ebusdVersion==='3.3' && ($ebusdRelease==='v3.3' || (strtok($ebusdRelease, '-')==='v3.3') && strtok('-')<18)));
|
||||
readVersions($cdnPath ? 'cdn' : ($old ? 'old' : '')) || ($cdnPath && readVersions());
|
||||
global $versions;
|
||||
$ret = 'unknown';
|
||||
if ($ebusdVersion==$versions['ebusd'][0] && $ebusdRelease==$versions['ebusd'][1]) {
|
||||
|
||||
@@ -742,7 +742,7 @@ void BusHandler::formatUpdateInfo(ostringstream* output) const {
|
||||
}
|
||||
unsigned char address = 0;
|
||||
for (int index = 0; index < 256; index++, address++) {
|
||||
bool ownAddress = !m_protocol->isOwnAddress(address);
|
||||
bool ownAddress = m_protocol->isOwnAddress(address);
|
||||
if (!isValidAddress(address, false) || ((m_seenAddresses[address]&SEEN) == 0 && !ownAddress)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+25
-2
@@ -288,8 +288,10 @@ int main(int argc, char* argv[], char* envp[]) {
|
||||
logWrite(lf_main, ll_error, "invalid configPath URL"); // force logging on exit
|
||||
return EINVAL;
|
||||
}
|
||||
if (configHost == CONFIG_HOST) {
|
||||
string suffix = (lang != "en" ? "de" : lang) + "/";
|
||||
bool isCdn = configHost == CONFIG_HOST;
|
||||
string suffix;
|
||||
if (isCdn) {
|
||||
suffix = (lang != "en" ? "de" : lang) + "/";
|
||||
configUriPrefix += suffix;
|
||||
configPath += suffix; // only for informational purposes
|
||||
} else {
|
||||
@@ -306,6 +308,27 @@ int main(int argc, char* argv[], char* envp[]) {
|
||||
cleanup();
|
||||
return EINVAL;
|
||||
}
|
||||
if (isCdn) {
|
||||
// check load balancing redirection
|
||||
string redirPath;
|
||||
uint16_t redirPort = 443;
|
||||
string redirProto, redirHost, redirUriPrefix;
|
||||
bool repeat = false;
|
||||
bool json = true;
|
||||
if (configHttpClient->get("/redirect.json", "", &redirPath, nullptr, nullptr, &json) && !json
|
||||
&& HttpClient::parseUrl(redirPath, &redirProto, &redirHost, &redirPort, &redirUriPrefix)
|
||||
&& redirHost != configHost) {
|
||||
configHttpClient->disconnect();
|
||||
ebusd::HttpClient* redirClient = new HttpClient();
|
||||
if (redirClient->connect(redirHost, redirPort, redirProto == "https", PACKAGE_NAME "/" PACKAGE_VERSION)) {
|
||||
configUriPrefix = redirUriPrefix + suffix;
|
||||
configPath = redirPath + suffix; // only for informational purposes
|
||||
delete configHttpClient;
|
||||
configHttpClient = redirClient;
|
||||
logNotice(lf_main, "configPath URL redirected to %s", configPath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
logInfo(lf_main, "configPath URL is valid");
|
||||
configHttpClient->disconnect();
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ static const argDef argDefs[] = {
|
||||
"arguments for checking a particular scan configuration, e.g. \"FF08070400/0AB5454850303003277201\"."},
|
||||
{"scanretries", O_SCNRET, "COUNT", 0, "Retry scanning devices COUNT times [5]"},
|
||||
{"configlang", O_CFGLNG, "LANG", 0,
|
||||
"Prefer LANG in multilingual configuration files [system default language]"},
|
||||
"Prefer LANG in multilingual configuration files [system default language, DE as fallback]"},
|
||||
{"checkconfig", O_CHKCFG, nullptr, 0, "Check config files, then stop"},
|
||||
{"dumpconfig", O_DMPCFG, "FORMAT", af_optional,
|
||||
"Check and dump config files in FORMAT (\"json\" or \"csv\"), then stop"},
|
||||
|
||||
@@ -321,6 +321,10 @@ void MainLoop::run() {
|
||||
<< ",\"a\":\"other\""
|
||||
#endif
|
||||
<< ",\"u\":" << (now-start);
|
||||
const string configPathCDN = m_scanHelper->getConfigPathCDN();
|
||||
if (!configPathCDN.empty()) {
|
||||
ostr << ",\"cp\":\"" << configPathCDN << "\"";
|
||||
}
|
||||
m_protocol->formatInfoJson(&ostr);
|
||||
if (m_reconnectCount) {
|
||||
ostr << ",\"rc\":" << m_reconnectCount;
|
||||
|
||||
@@ -71,6 +71,11 @@ class ScanHelper : public Resolver {
|
||||
*/
|
||||
const string getConfigPath() const { return m_configPath; }
|
||||
|
||||
/**
|
||||
* @return the config path when pointing to CDN, empty otherwise.
|
||||
*/
|
||||
const string getConfigPathCDN() const { return m_configUriPrefix.empty() ? "" : m_configPath; }
|
||||
|
||||
/**
|
||||
* Try to connect to the specified server.
|
||||
* @param host the host name to connect to.
|
||||
|
||||
Reference in New Issue
Block a user