HEX
Server: Apache
System: Linux webm004.cluster129.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64
User: windevelwb (110072)
PHP: 8.5.0
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/windevelwb/www/api2/action_mac.php
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

//ini_set('display_errors', 0);
//error_reporting(0);

$path = __DIR__ . "/data/macs.json";
$macs = json_decode(file_get_contents($path), true);

// Nettoyage : supprimer les entrées vides
$macs = array_filter($macs, function($m) {
    return trim($m) !== "";
});
$macs = array_values($macs);

// Sécurité : si le fichier est vide
if (count($macs) == 0) {
    echo json_encode(["error" => "Liste MAC vide"]);
    exit;
}

// 1. Récupérer la première MAC
$mac = trim(array_shift($macs));

// 2. Fonction pour incrémenter une MAC
function incrementMac($mac) {
    $parts = explode(":", $mac);
    if (count($parts) != 6) {
        return "00:1E:A1:00:00:00";
    }

    $prefix = array_slice($parts, 0, 3);
    $hex = $parts[3] . $parts[4] . $parts[5];

    $value = hexdec($hex);
    $value++;

    $newHex = strtoupper(str_pad(dechex($value), 6, "0", STR_PAD_LEFT));

    return implode(":", $prefix) . ":" .
           substr($newHex, 0, 2) . ":" .
           substr($newHex, 2, 2) . ":" .
           substr($newHex, 4, 2);
}

// 3. Générer la nouvelle MAC à partir de la dernière MAC restante
$lastMac = trim(end($macs));
$newMac = incrementMac($lastMac);

// 4. Ajouter la nouvelle MAC à la fin
$macs[] = $newMac;

// 5. Sauvegarder
file_put_contents($path, json_encode($macs, JSON_PRETTY_PRINT));

// 6. Réponse JSON
echo json_encode([
    "mac" => $mac,
    "new" => $newMac,
    "count" => count($macs)
]);
exit;