Upload files to "include"
This commit is contained in:
110
include/include_functions.php
Normal file
110
include/include_functions.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FlowManager helper functies
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Deploy een JSON-flow naar Node-RED
|
||||||
|
function deployFlow(string $flowPath): string {
|
||||||
|
if (!file_exists($flowPath)) return "Flowbestand niet gevonden: $flowPath";
|
||||||
|
|
||||||
|
$flowJson = file_get_contents($flowPath);
|
||||||
|
$url = "http://localhost:1880/flows";
|
||||||
|
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_POST => 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 "<div class='alert alert-warning'>
|
||||||
|
Nieuwe template-versie beschikbaar!
|
||||||
|
(Template v$templateVersion > Laatste deploy v$latestVersion)
|
||||||
|
</div>";
|
||||||
|
}
|
||||||
|
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 "<div class='alert alert-{$type}'>$message</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 : [];
|
||||||
|
}
|
||||||
|
|
||||||
47
include/include_header.php
Normal file
47
include/include_header.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
$base_url = 'http://localhost:8888/rdlab/flowmanager_app/v1.0';
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="nl">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>FlowManager</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body { background: #f9f9f9; }
|
||||||
|
.navbar { background: #fff; border-bottom: 1px solid #ddd; }
|
||||||
|
.card { border-radius: 1rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); margin-bottom: 1rem; }
|
||||||
|
textarea { font-family: monospace; font-size: 0.85rem; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white border-bottom">
|
||||||
|
<div class="container">
|
||||||
|
<!-- Logo / Home link -->
|
||||||
|
<a class="navbar-brand fw-bold text-primary" href="<?php echo $base_url ?> ">
|
||||||
|
<i class="bi bi-diagram-3"></i> FlowManager
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- Hamburger toggle voor mobiele weergave -->
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarMenu" aria-controls="navbarMenu" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Menu-items -->
|
||||||
|
<div class="collapse navbar-collapse" id="navbarMenu">
|
||||||
|
<ul class="navbar-nav ms-auto">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="<?php echo $base_url ?>/settings.php">
|
||||||
|
<i class="bi bi-gear-fill"></i> Instellingen
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user