Delete generate.php
This commit is contained in:
72
generate.php
72
generate.php
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
$templateName = $_POST['template'] ?? '';
|
||||
$assetId = $_POST['asset_id'] ?? '';
|
||||
|
||||
if (!$templateName || !$assetId) {
|
||||
die("Ongeldige invoer");
|
||||
}
|
||||
|
||||
$templatePath = __DIR__ . "/templates/$templateName.json.tpl";
|
||||
if (!file_exists($templatePath)) {
|
||||
die("Template niet gevonden");
|
||||
}
|
||||
|
||||
// --- Asset details ophalen uit API ---
|
||||
$apiUrl = "https://pimmoerman.nl/rdlab/tagcode.app/v2.1/api/asset/get_all_assets.php";
|
||||
$response = file_get_contents($apiUrl);
|
||||
$assetName = "Onbekend";
|
||||
|
||||
if ($response !== false) {
|
||||
$data = json_decode($response, true);
|
||||
if ($data['success']) {
|
||||
foreach ($data['data'] as $asset) {
|
||||
if ($asset['asset_id'] == $assetId) {
|
||||
$assetName = $asset['asset_tag_number'] . " – " . $asset['asset_name'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Template laden en placeholders vervangen
|
||||
$template = file_get_contents($templatePath);
|
||||
$flowJson = str_replace(
|
||||
["{{id}}", "{{name}}"],
|
||||
[$assetId, $assetName],
|
||||
$template
|
||||
);
|
||||
|
||||
// Flow opslaan (logging)
|
||||
file_put_contents(__DIR__."/generated/{$templateName}_{$assetId}.json", $flowJson);
|
||||
|
||||
// Naar Node-RED sturen via Admin API
|
||||
$ch = curl_init("http://localhost:1880/flows");
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $flowJson);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
include 'include/include_header.php';
|
||||
|
||||
?>
|
||||
|
||||
<div class="container py-5">
|
||||
<div class="card p-4">
|
||||
<h1 class="h4 text-success">Flow gedeployed!</h1>
|
||||
<p>Template <strong><?= htmlspecialchars($templateName) ?></strong> voor asset
|
||||
<strong><?= htmlspecialchars($assetName) ?></strong> is succesvol naar Node-RED gestuurd.</p>
|
||||
<pre class="bg-dark text-light p-3 rounded small"><?= htmlspecialchars($response) ?></pre>
|
||||
<a href="index.php" class="btn btn-outline-primary">Terug naar start</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="text-center">
|
||||
<div class="container">
|
||||
<p>© <?= date("Y") ?> FlowManager</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user