<?php
require_once __DIR__ . '/../lib/core.php';

$isCli = PHP_SAPI === 'cli';
if (!$isCli) {
    $key = isset($_GET['key']) ? $_GET['key'] : '';
    if (!defined('DC_BACKUP_KEY') || DC_BACKUP_KEY === 'change-this-backup-key' || !hash_equals(DC_BACKUP_KEY, $key)) {
        http_response_code(403);
        exit('Forbidden');
    }
}

$file = dc_create_doors_backup();
if (!$file) {
    http_response_code(500);
    exit('Backup failed');
}

echo 'Backup created: ' . basename($file) . PHP_EOL;
