diff --git a/include/include_functions.php b/include/include_functions.php new file mode 100644 index 0000000..c37c96a --- /dev/null +++ b/include/include_functions.php @@ -0,0 +1,110 @@ + true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_POSTFIELDS => $flowJson, + ]); + $response = curl_exec($ch); + $error = curl_error($ch); + curl_close($ch); + + return $error ?: $response; +} + +// Haal alle versie-bestanden op in een map +function findVersionedJsonFilesInDir(string $dir): array { + $matches = []; + foreach (scandir($dir) as $file) { + if (preg_match('/^version\d+_\d{12}\.json$/', $file)) { + $matches[] = ['name' => $file]; + } + } + usort($matches, fn($a,$b) => strcmp($a['name'],$b['name'])); + return $matches; +} + +// Vind het laatst gedeployde bestand +function findLatestDeployFile(string $dir): ?string { + $files = findVersionedJsonFilesInDir($dir); + return !empty($files) ? end($files)['name'] : null; +} + +// Haal versie uit een JSON-bestand +function getVersionFromJson(string $filePath): int { + if (!file_exists($filePath)) return 0; + $json = json_decode(file_get_contents($filePath), true); + return $json[0]['version'] ?? 0; +} + +// Haal versie uit een template +function getVersionFromTemplate(string $templatePath): int { + if (!file_exists($templatePath)) return 0; + preg_match('/"version"\s*:\s*(\d+)/', file_get_contents($templatePath), $m); + return $m[1] ?? 0; +} + +// Controleer of de template een hogere versie heeft dan de laatste deploy +function checkNewTemplateVersionAlert(string $templatePath, string $deployDir): ?string { + $templateVersion = getVersionFromTemplate($templatePath); + $latestDeployFile = findLatestDeployFile($deployDir); + $latestVersion = $latestDeployFile ? getVersionFromJson($deployDir.'/'.$latestDeployFile) : 0; + + if ($templateVersion > $latestVersion) { + return "
+ Nieuwe template-versie beschikbaar! + (Template v$templateVersion > Laatste deploy v$latestVersion) +
"; + } + return null; +} + +// Genereer de bestandsnaam voor een nieuwe deploy +function generateNextDeployFileName(int $version): string { + return "version{$version}_".date('YmdHi').".json"; +} + +// Template renderen met placeholders +function renderTemplate(string $templatePath, array $placeholders): string { + $content = file_get_contents($templatePath); + foreach ($placeholders as $key => $value) { + $content = str_replace("{{{$key}}}", $value, $content); + } + return $content; +} + +// Render een standaard alert +function renderAlert(string $message, string $type = 'info'): string { + return "
$message
"; +} + +// Verkrijg een overzicht van alle deploys inclusief versies +function getDeploysWithVersions(string $dir): array { + $files = findVersionedJsonFilesInDir($dir); + return array_map(function($f) use ($dir) { + return [ + 'name' => $f['name'], + 'version' => getVersionFromJson($dir.'/'.$f['name']) + ]; + }, array_reverse($files)); +} + +function getNodeRedEnvironments(string $envFile = '/environments.json'): array { + $json = @file_get_contents($envFile); // @ om warnings te onderdrukken + if (!$json) return []; + $data = json_decode($json, true); + return is_array($data) ? $data : []; +} + diff --git a/include/include_header.php b/include/include_header.php new file mode 100644 index 0000000..2ec8d52 --- /dev/null +++ b/include/include_header.php @@ -0,0 +1,47 @@ + + + + + + + FlowManager + + + + + + + + +