Stabilize discovery workflow
This commit is contained in:
@@ -29,8 +29,8 @@ class DiscoveryController
|
||||
ob_start();
|
||||
$username = $_SESSION['username'] ?? 'User';
|
||||
$ranges = $this->networkRangeRepository->findAll();
|
||||
$activeJobs = $this->scanJobRepository->findActive();
|
||||
$scanJobs = $this->scanJobRepository->findRecent(10);
|
||||
$newHosts = $this->discoveredHostRepository->findByStatus('new', 20);
|
||||
require dirname(__DIR__, 2) . '/templates/discovery/index.php';
|
||||
$body = ob_get_clean();
|
||||
$response->getBody()->write($body);
|
||||
@@ -80,6 +80,53 @@ class DiscoveryController
|
||||
->withStatus(302);
|
||||
}
|
||||
|
||||
public function activeJobs(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$activeJobs = $this->scanJobRepository->findActive();
|
||||
ob_start();
|
||||
require dirname(__DIR__, 2) . '/templates/discovery/_active_jobs.php';
|
||||
$body = ob_get_clean();
|
||||
$response->getBody()->write($body);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function scanHistory(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$scanJobs = $this->scanJobRepository->findRecent(10);
|
||||
ob_start();
|
||||
require dirname(__DIR__, 2) . '/templates/discovery/_scan_history.php';
|
||||
$body = ob_get_clean();
|
||||
$response->getBody()->write($body);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function pauseJob(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
|
||||
{
|
||||
$job = $this->scanJobRepository->findById((int)$args['id']);
|
||||
if ($job !== null && $job->status === 'running') {
|
||||
$this->scanJobRepository->updateStatus($job->id, 'paused');
|
||||
}
|
||||
return $this->activeJobs($request, $response);
|
||||
}
|
||||
|
||||
public function resumeJob(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
|
||||
{
|
||||
$job = $this->scanJobRepository->findById((int)$args['id']);
|
||||
if ($job !== null && $job->status === 'paused') {
|
||||
$this->scanJobRepository->updateStatus($job->id, 'pending');
|
||||
}
|
||||
return $this->activeJobs($request, $response);
|
||||
}
|
||||
|
||||
public function cancelJob(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface
|
||||
{
|
||||
$job = $this->scanJobRepository->findById((int)$args['id']);
|
||||
if ($job !== null && in_array($job->status, ['pending', 'running', 'paused'], true)) {
|
||||
$this->scanJobRepository->updateStatus($job->id, 'cancelled');
|
||||
}
|
||||
return $this->activeJobs($request, $response);
|
||||
}
|
||||
|
||||
private function createScanJob(string $type, int $rangeId): void
|
||||
{
|
||||
$job = new \Domovoy\Models\ScanJob();
|
||||
|
||||
Reference in New Issue
Block a user