From a6a484ea37aeb91f848c11cb818e2d7d4351d391 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 22 Jun 2016 17:56:04 +0200 Subject: [locations/sysconfig] Implement location specific sysconfig --- modules-available/sysconfig/api.inc.php | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 modules-available/sysconfig/api.inc.php (limited to 'modules-available/sysconfig/api.inc.php') diff --git a/modules-available/sysconfig/api.inc.php b/modules-available/sysconfig/api.inc.php new file mode 100644 index 00000000..556e99f3 --- /dev/null +++ b/modules-available/sysconfig/api.inc.php @@ -0,0 +1,78 @@ +fetch(PDO::FETCH_ASSOC)) { + settype($r['locationid'], 'int'); + $index = array_search($r['locationid'], $locationChain); + if ($index === false || $index > $best) + continue; + if (!file_exists($r['filepath'])) { + if ($r['locationid'] === 0) { + EventLog::failure("The global config.tgz '{$r['title']}' was not found at '{$r['filepath']}'. Please regenerate the system configuration"); + } else { + EventLog::warning("config.tgz '{$r['title']}' for location $locationId not found at '{$r['filepath']}', trying fallback...."); + } + continue; + } + $best = $index; + $row = $r; +} + +if ($row === false) { + // TODO Not found in DB + deliverEmpty("No config.tgz for location $locationId found"); +} + +if (!file_exists($row['filepath'])) { + // TODO Does not exist + deliverEmpty(); +} + +Header('Content-Type: application/gzip'); +Header('Content-Disposition: attachment; filename=' . Util::sanitizeFilename($row['title']) . '.tgz'); +$ret = readfile($row['filepath']); + +if ($ret === false || $ret === 0) { + // TODO didn't send anything/everything + // Cannot deliver empty, don't know what has been send already + EventLog::warning("Could not deliver config.tgz to client $ip: readfile() returned " . ($ret === false ? 'false' : $ret)); +} + +exit; \ No newline at end of file -- cgit v1.2.3-55-g7522