<?php
// crontab example:
// * * * * * curl -fsS "http://localhost:3000/__CRON/cron_ikev2_vpnid_sync_retry.php?f=76f3f652df3048158b1286e4f18fcb80d5185b37f9ec40e6a6ffce67189d9106" >/dev/null 2>&1

@chdir(__DIR__ . '/..');

include_once(__DIR__ . '/../_common.php');
include_once(G5_PATH . '/lib/etc.lib.php');
include_once(G5_PATH . '/mylib/ikev2_provision.lib.php');

$cronToken = '76f3f652df3048158b1286e4f18fcb80d5185b37f9ec40e6a6ffce67189d9106';
if (!isset($_GET['f']) || !hash_equals($cronToken, (string)$_GET['f'])) {
    http_response_code(403);
    echo 'forbidden';
    exit;
}

$ret = vpnlink_vpnid_sync_retry_due_jobs(50);

echo json_encode(array(
    'ok' => true,
    'processed' => (int)$ret['processed'],
    'success' => (int)$ret['success'],
    'fail' => (int)$ret['fail'],
    'ts' => date('Y-m-d H:i:s')
), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
