diff --git a/src/api/v2/index.php b/src/api/v2/index.php index 79be56d86..3a438dadc 100644 --- a/src/api/v2/index.php +++ b/src/api/v2/index.php @@ -285,7 +285,6 @@ ResetUserPasswordHelperAPI::register($app); SearchHashesHelperAPI::register($app); SetUserPasswordHelperAPI::register($app); -TaskExtraDetailsHelper::register($app); UnassignAgentHelperAPI::register($app); $app->run(); diff --git a/src/inc/apiv2/helper/TaskExtraDetailsHelper.php b/src/inc/apiv2/helper/TaskExtraDetailsHelper.php deleted file mode 100644 index c0ddc8aa4..000000000 --- a/src/inc/apiv2/helper/TaskExtraDetailsHelper.php +++ /dev/null @@ -1,120 +0,0 @@ -preCommon($request); - - $taskId = $request->getQueryParams()['task']; - if ($taskId === null) { - throw new HttpErrorException("No task query param has been provided"); - } - $taskId = intval($taskId); - if ($taskId === 0) { - throw new HttpErrorException("No valid integer provided as task"); - } - $task = Factory::getTaskFactory()->get($taskId); - if ($task === null) { - throw new HttpErrorException("No task found for provided task ID"); - } - - $qF = new QueryFilter(Chunk::TASK_ID, $taskId, "="); - $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); - $currentSpeed = 0; - $cProgress = 0; - foreach ($chunks as $chunk) { - $cProgress += $chunk->getCheckpoint() - $chunk->getSkip(); - if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { - $currentSpeed += $chunk->getSpeed(); - } - } - - $timeChunks = $chunks; - usort($timeChunks, "Hashtopolis\inc\Util"); - $timeSpent = 0; - $current = 0; - foreach ($timeChunks as $c) { - if ($c->getDispatchTime() > $current) { - $timeSpent += $c->getSolveTime() - $c->getDispatchTime(); - $current = $c->getSolveTime(); - } - else if ($c->getSolveTime() > $current) { - $timeSpent += $c->getSolveTime() - $current; - $current = $c->getSolveTime(); - } - } - $keyspace = $task->getKeyspace(); - $estimatedTime = ($keyspace > 0 && $cProgress > 0) ? round($timeSpent / ($cProgress / $keyspace) - $timeSpent) : 0; - $responseObject = [ - "estimatedTime" => $estimatedTime, - "timeSpent" => $timeSpent, - "currentSpeed" => $currentSpeed, - "cprogress" => $cProgress, - ]; - - return self::getMetaResponse($responseObject, $request, $response); - } - - /** - * @throws HttpError - */ - public function actionPost($data): object|array|null { - throw new HttpError("TaskExtraDetails has no POST"); - } - - static public function register($app): void { - $baseUri = TaskExtraDetailsHelper::getBaseUri(); - - /* Allow CORS preflight requests */ - $app->options($baseUri, function (Request $request, Response $response): Response { - return $response; - }); - $app->get($baseUri, "Hashtopolis\\inc\\apiv2\\helper\\TaskExtraDetailsHelper:handleGet"); - } - - /** - * getAccessGroups is different because it returns via another function - */ - public static function getResponse(): array|string|null { - return null; - } -} - diff --git a/src/inc/apiv2/model/TaskAPI.php b/src/inc/apiv2/model/TaskAPI.php index 36869b718..9bc429ef8 100644 --- a/src/inc/apiv2/model/TaskAPI.php +++ b/src/inc/apiv2/model/TaskAPI.php @@ -219,6 +219,45 @@ static function aggregateData(object $object, array &$included_data = [], ?array $aggregatedData["status"] = $status; } + + if (is_null($aggregateFieldsets) || in_array("taskExtraDetails", $aggregateFieldsets['task'])) { + $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); + $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); + + $currentSpeed = 0; + $cProgress = 0; + + foreach ($chunks as $chunk) { + $cProgress += $chunk->getCheckpoint() - $chunk->getSkip(); + if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { + $currentSpeed += $chunk->getSpeed(); + } + } + + $timeChunks = $chunks; + usort($timeChunks, "\Hashtopolis\inc\Util::compareChunksTime"); + $timeSpent = 0; + $current = 0; + + foreach ($timeChunks as $c) { + if ($c->getDispatchTime() > $current) { + $timeSpent += $c->getSolveTime() - $c->getDispatchTime(); + $current = $c->getSolveTime(); + } + else if ($c->getSolveTime() > $current) { + $timeSpent += $c->getSolveTime() - $current; + $current = $c->getSolveTime(); + } + } + + $keyspace = $object->getKeyspace(); + $estimatedTime = ($keyspace > 0 && $cProgress > 0) ? round($timeSpent / ($cProgress / $keyspace) - $timeSpent) : 0; + + $aggregatedData["estimatedTime"] = $estimatedTime; + $aggregatedData["timeSpent"] = $timeSpent; + $aggregatedData["currentSpeed"] = $currentSpeed; + $aggregatedData["cprogress"] = $cProgress; + } } return $aggregatedData;