36 lines
929 B
PHP
36 lines
929 B
PHP
<?php
|
|
require __DIR__ . '/../../lib/app.php';
|
|
auth_require();
|
|
header('Content-Type: application/json');
|
|
|
|
$stateDir = '/var/lib/snowpanel';
|
|
$perFile = $stateDir . '/period.json';
|
|
$lockFile = $stateDir . '/cap.lock';
|
|
|
|
$cfg = app_load_config();
|
|
$cap_day = (int)($cfg['cap_day'] ?? 1);
|
|
$cap_day = max(1, min(28, $cap_day));
|
|
|
|
$tz = new DateTimeZone(@date_default_timezone_get() ?: 'UTC');
|
|
$now = new DateTime('now', $tz);
|
|
$y = (int)$now->format('Y');
|
|
$m = (int)$now->format('n');
|
|
$d = (int)$now->format('j');
|
|
|
|
if ($d < $cap_day) {
|
|
if ($m === 1) { $m = 12; $y -= 1; } else { $m -= 1; }
|
|
}
|
|
$anchor = (new DateTime(sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $cap_day), $tz))->getTimestamp();
|
|
|
|
$period = [
|
|
'period_start' => $anchor,
|
|
'rx' => 0,
|
|
'tx' => 0,
|
|
'last_ing' => 0,
|
|
'last_egr' => 0,
|
|
];
|
|
|
|
@file_put_contents($perFile, json_encode($period, JSON_UNESCAPED_SLASHES));
|
|
@unlink($lockFile);
|
|
|
|
echo json_encode(['ok' => true]); |