2018-02-01 11:49:40 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Controller\Admin;
|
2018-02-01 11:49:40 +00:00
|
|
|
|
|
|
|
use App\Acl;
|
2019-08-09 15:00:21 +00:00
|
|
|
use App\Http\Response;
|
|
|
|
use App\Http\ServerRequest;
|
2019-06-28 03:25:16 +00:00
|
|
|
use App\Radio\Quota;
|
2019-09-12 05:31:01 +00:00
|
|
|
use App\Settings;
|
2019-09-20 16:44:38 +00:00
|
|
|
use App\Sync\Runner;
|
2019-06-28 03:25:16 +00:00
|
|
|
use Brick\Math\BigInteger;
|
2018-11-17 15:30:28 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2018-02-01 11:49:40 +00:00
|
|
|
|
|
|
|
class IndexController
|
|
|
|
{
|
2020-03-01 16:26:49 +00:00
|
|
|
public function __invoke(
|
|
|
|
ServerRequest $request,
|
|
|
|
Response $response,
|
|
|
|
Runner $sync
|
|
|
|
): ResponseInterface {
|
2019-08-09 15:00:21 +00:00
|
|
|
$view = $request->getView();
|
|
|
|
$user = $request->getUser();
|
2018-02-06 17:55:58 +00:00
|
|
|
|
2018-02-01 11:49:40 +00:00
|
|
|
// Remove the sidebar on the homepage.
|
2019-08-07 04:33:55 +00:00
|
|
|
$view->addData(['sidebar' => null]);
|
2018-02-01 11:49:40 +00:00
|
|
|
|
|
|
|
// Synchronization statuses
|
2019-08-09 15:00:21 +00:00
|
|
|
$acl = $request->getAcl();
|
2019-08-07 04:33:55 +00:00
|
|
|
|
|
|
|
if ($acl->userAllowed($user, Acl::GLOBAL_ALL)) {
|
|
|
|
$view->addData([
|
2020-03-01 16:26:49 +00:00
|
|
|
'sync_times' => $sync->getSyncTimes(),
|
2019-08-07 04:33:55 +00:00
|
|
|
]);
|
2018-02-01 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 19:32:31 +00:00
|
|
|
$stationsBaseDir = Settings::getInstance()->getStationDirectory();
|
2019-06-28 03:25:16 +00:00
|
|
|
|
2020-11-14 19:32:31 +00:00
|
|
|
$spaceTotal = BigInteger::of(disk_total_space($stationsBaseDir));
|
|
|
|
$spaceFree = BigInteger::of(disk_free_space($stationsBaseDir));
|
|
|
|
$spaceUsed = $spaceTotal->minus($spaceFree);
|
|
|
|
|
|
|
|
// Get memory info.
|
|
|
|
$meminfoRaw = explode("\n", file_get_contents("/proc/meminfo"));
|
|
|
|
$meminfo = [];
|
|
|
|
foreach ($meminfoRaw as $line) {
|
|
|
|
[$key, $val] = explode(":", $line);
|
|
|
|
$meminfo[$key] = trim($val);
|
|
|
|
}
|
|
|
|
|
|
|
|
$memoryTotal = Quota::convertFromReadableSize($meminfo['MemTotal']) ?? BigInteger::zero();
|
|
|
|
$memoryFree = Quota::convertFromReadableSize($meminfo['MemAvailable']) ?? BigInteger::zero();
|
|
|
|
$memoryUsed = $memoryTotal->minus($memoryFree);
|
2019-06-28 03:25:16 +00:00
|
|
|
|
|
|
|
return $view->renderToResponse($response, 'admin/index/index', [
|
|
|
|
'load' => sys_getloadavg(),
|
2020-11-14 19:32:31 +00:00
|
|
|
'space_percent' => Quota::getPercentage($spaceUsed, $spaceTotal),
|
|
|
|
'space_used' => Quota::getReadableSize($spaceUsed),
|
|
|
|
'space_total' => Quota::getReadableSize($spaceTotal),
|
|
|
|
'memory_percent' => Quota::getPercentage($memoryUsed, $memoryTotal),
|
|
|
|
'memory_used' => Quota::getReadableSize($memoryUsed),
|
|
|
|
'memory_total' => Quota::getReadableSize($memoryTotal),
|
2019-06-28 03:25:16 +00:00
|
|
|
]);
|
2018-02-01 11:49:40 +00:00
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|