57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use classes\authentication;
|
|
use classes\edgegateway;
|
|
use classes\response;
|
|
use objects\logs_o;
|
|
use traits\route_t;
|
|
|
|
class edgeGatewayConfigRoute
|
|
{
|
|
use route_t;
|
|
|
|
public function run(): void
|
|
{
|
|
$this->get('/edgegateway/config', fn() => $this->handleGetConfig(), [
|
|
'modules_shelly_config' => 'Get edge gateway config',
|
|
]);
|
|
$this->post('/edgegateway/config', fn() => $this->handlePostConfig(), [
|
|
'modules_shelly_config' => 'Update edge gateway config',
|
|
]);
|
|
}
|
|
|
|
private function handleGetConfig(): void
|
|
{
|
|
global /** @var response $response */ $response;
|
|
$this->requirePermission('modules_shelly_config');
|
|
$user = (new authentication())->get_user();
|
|
|
|
if (!$user) {
|
|
(new logs_o())->add('edgegateway_config', 'global', 1, 0, 'EDGEGATEWAY_CONFIG', 'No user found, or invalid session');
|
|
$response->error('Invalid session', 400);
|
|
return;
|
|
}
|
|
|
|
(new logs_o())->add('edgegateway_config', 'global', 1, $user->id, 'EDGEGATEWAY_CONFIG', 'Successfully fetched edge gateway config');
|
|
$response->success((new edgegateway())->config->getConfigRequest());
|
|
}
|
|
|
|
private function handlePostConfig(): void
|
|
{
|
|
global /** @var response $response */ $response;
|
|
$this->requirePermission('modules_shelly_config');
|
|
$user = (new authentication())->get_user();
|
|
|
|
if (!$user) {
|
|
(new logs_o())->add('edgegateway_config', 'global', 1, 0, 'EDGEGATEWAY_CONFIG', 'No user found, or invalid session');
|
|
$response->error('Invalid session', 400);
|
|
return;
|
|
}
|
|
|
|
(new logs_o())->add('edgegateway_config', 'global', 1, $user->id, 'EDGEGATEWAY_CONFIG', 'Successfully updated edge gateway config');
|
|
$response->success((new edgegateway())->config->postConfigRequest());
|
|
}
|
|
}
|