fix: Agent download endpoint and install script URL
- Move /get-agent route before auth groups to ensure it's public - Fix path resolution in downloadAgent() - dirname(__DIR__, 2) from controller = /var/www/mon/ - Fix withStatus() return value issue in downloadAgent() - Use /get-agent endpoint instead of /agent/agent.py (nginx issue with .py files) - Update install.sh to use /get-agent URL
This commit is contained in:
parent
3afd6f8366
commit
5b3f5a9483
|
|
@ -47,6 +47,15 @@ $app->add($sessionMiddleware);
|
||||||
// Add CSRF middleware (will be applied selectively)
|
// Add CSRF middleware (will be applied selectively)
|
||||||
$csrfMiddleware = $csrf;
|
$csrfMiddleware = $csrf;
|
||||||
|
|
||||||
|
// Agent controller for public downloads
|
||||||
|
$agentController = new AgentController();
|
||||||
|
|
||||||
|
// PUBLIC: Download agent script (before any groups with auth)
|
||||||
|
$app->get('/get-agent', [$agentController, 'downloadAgent']);
|
||||||
|
$app->get('/agent/install.sh', [$agentController, 'generateInstallScript']);
|
||||||
|
$app->get('/agent/install.ps1', [$agentController, 'generateWindowsInstallScript']);
|
||||||
|
$app->get('/agent/install.bat', [$agentController, 'generateWindowsBatScript']);
|
||||||
|
|
||||||
// Add a route to get CSRF tokens via AJAX
|
// Add a route to get CSRF tokens via AJAX
|
||||||
$app->get('/csrf-token', function (Request $request, Response $response, $args) use ($csrf) {
|
$app->get('/csrf-token', function (Request $request, Response $response, $args) use ($csrf) {
|
||||||
$csrf->generateToken();
|
$csrf->generateToken();
|
||||||
|
|
@ -151,7 +160,6 @@ $adminController = new AdminController($twig);
|
||||||
$metricsController = new MetricsController();
|
$metricsController = new MetricsController();
|
||||||
$agentController = new AgentController();
|
$agentController = new AgentController();
|
||||||
|
|
||||||
|
|
||||||
// API для дашборда
|
// API для дашборда
|
||||||
$dashboardApiController = new DashboardController($twig);
|
$dashboardApiController = new DashboardController($twig);
|
||||||
$app->get('/api/dashboard/stats', [$dashboardApiController, 'getDashboardData'])->add(AuthMiddleware::class);
|
$app->get('/api/dashboard/stats', [$dashboardApiController, 'getDashboardData'])->add(AuthMiddleware::class);
|
||||||
|
|
@ -229,11 +237,5 @@ $app->get('/api/status', function (Request $request, Response $response, $args)
|
||||||
->withHeader('Content-Type', 'application/json');
|
->withHeader('Content-Type', 'application/json');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Agent installation script routes (public, no auth middleware, no csrf)
|
|
||||||
$app->get('/agent/install.sh', [$agentController, 'generateInstallScript']);
|
|
||||||
$app->get('/agent/install.ps1', [$agentController, 'generateWindowsInstallScript']);
|
|
||||||
$app->get('/agent/install.bat', [$agentController, 'generateWindowsBatScript']);
|
|
||||||
$app->get('/agent/agent.py', [$agentController, 'downloadAgent']);
|
|
||||||
|
|
||||||
// Run app
|
// Run app
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|
@ -33,7 +33,7 @@ class AgentController extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiUrl = 'https://mon.mirv.top/api/v1/metrics';
|
$apiUrl = 'https://mon.mirv.top/api/v1/metrics';
|
||||||
$agentDownloadUrl = 'https://mon.mirv.top/agent/agent.py?token=' . $token;
|
$agentDownloadUrl = 'https://mon.mirv.top/get-agent?token=' . $token;
|
||||||
$installDir = '/opt/server-monitor-agent';
|
$installDir = '/opt/server-monitor-agent';
|
||||||
|
|
||||||
$script = <<<BASH
|
$script = <<<BASH
|
||||||
|
|
@ -165,15 +165,15 @@ BASH;
|
||||||
|
|
||||||
$agentPath = dirname(__DIR__, 2) . '/agent.py';
|
$agentPath = dirname(__DIR__, 2) . '/agent.py';
|
||||||
if (!file_exists($agentPath)) {
|
if (!file_exists($agentPath)) {
|
||||||
$response->getBody()->write('Agent not found');
|
$response->getBody()->write('Agent not found: ' . $agentPath);
|
||||||
return $response->withStatus(404);
|
return $response->withStatus(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = file_get_contents($agentPath);
|
$content = file_get_contents($agentPath);
|
||||||
|
|
||||||
|
$response = $response->withStatus(200);
|
||||||
|
$response->getBody()->write($content);
|
||||||
return $response
|
return $response
|
||||||
->getBody()
|
|
||||||
->write($content)
|
|
||||||
->withHeader('Content-Type', 'text/plain; charset=UTF-8')
|
->withHeader('Content-Type', 'text/plain; charset=UTF-8')
|
||||||
->withHeader('Content-Disposition', 'attachment; filename="agent.py"');
|
->withHeader('Content-Disposition', 'attachment; filename="agent.py"');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue