feat: initial impl w/ styles, scripts, & server-side logic (steps 1, 2, 3)

This commit is contained in:
Floriansylvain
2025-12-16 21:09:53 +01:00
parent 9e00c10b9c
commit dbce932ce2
15 changed files with 501 additions and 7 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
header('X-Robots-Tag: noindex');
header('Content-Type: text/html; charset=utf-8');
$client = null;
if (!empty($_GET['client'])) $client = $_GET['client'];
elseif (!empty($_COOKIE['client'])) $client = $_COOKIE['client'];
if (empty($client)) {
http_response_code(400);
echo 'Client not selected';
exit;
}
if (!preg_match('/^[a-z0-9_-]+$/i', $client)) {
http_response_code(400);
echo 'Invalid client identifier';
exit;
}
$module = isset($_GET['module']) ? $_GET['module'] : '';
$script = isset($_GET['script']) ? $_GET['script'] : '';
if (!preg_match('/^[a-z0-9_-]+$/i', $module) || !preg_match('/^[a-z0-9_-]+$/i', $script)) {
http_response_code(400);
echo 'Invalid module or script name';
exit;
}
$baseDir = dirname(__DIR__) . '/customs/' . $client . '/modules/';
$targetPath = $baseDir . $module . '/' . $script . '.php';
$realBase = realpath(dirname(__DIR__) . '/customs/' . $client . '/modules/');
$realTarget = realpath($targetPath);
if ($realBase === false || $realTarget === false) {
http_response_code(404);
echo 'Not found';
exit;
}
if (strpos($realTarget, $realBase) !== 0) {
http_response_code(400);
echo 'Invalid path';
exit;
}
include $realTarget;
+37
View File
@@ -0,0 +1,37 @@
<?php
class DataManager
{
private static function readJsonFile(string $filename): array
{
$path = __DIR__ . '/../data/' . $filename;
if (!file_exists($path)) {
return [];
}
$content = file_get_contents($path);
$data = json_decode($content, true);
return is_array($data) ? $data : [];
}
public static function getCars(string $clientId): array
{
$cars = self::readJsonFile('cars.json');
return array_values(array_filter($cars, fn($c) => isset($c['customer']) && $c['customer'] === $clientId));
}
public static function getGarages(string $clientId): array
{
$garages = self::readJsonFile('garages.json');
return array_values(array_filter($garages, fn($g) => isset($g['customer']) && $g['customer'] === $clientId));
}
public static function getGarageById($id): ?array
{
$garages = self::readJsonFile('garages.json');
foreach ($garages as $g) {
if (isset($g['id']) && $g['id'] == $id) {
return $g;
}
}
return null;
}
}