Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/inc/api/APISendBenchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@
use Hashtopolis\inc\agent\PValues;
use Hashtopolis\inc\agent\PValuesBenchmarkType;
use Hashtopolis\inc\defines\DConfig;
use Hashtopolis\inc\defines\DDirectories;
use Hashtopolis\inc\defines\DTaskTypes;
use Hashtopolis\inc\utils\AccessUtils;
use Hashtopolis\inc\defines\DFileType;
use Hashtopolis\inc\defines\DServerLog;
use Hashtopolis\dba\models\Agent;
use Hashtopolis\dba\models\Assignment;
use Hashtopolis\dba\QueryFilter;
use Hashtopolis\dba\Factory;
use Hashtopolis\dba\models\File;
use Hashtopolis\inc\SConfig;
use Hashtopolis\inc\utils\TaskUtils;
use Hashtopolis\inc\Util;

class APISendBenchmark extends APIBasic {
public function execute($QUERY = array()) {
Expand All @@ -34,7 +27,6 @@ public function execute($QUERY = array()) {
if ($task == null) {
$this->sendErrorResponse(PActions::SEND_BENCHMARK, "Invalid task ID!");
}
$taskWrapper = Factory::getTaskWrapperFactory()->get($task->getTaskWrapperId());

$qF1 = new QueryFilter(Assignment::AGENT_ID, $this->agent->getId(), "=");
$qF2 = new QueryFilter(Assignment::TASK_ID, $task->getId(), "=");
Expand All @@ -56,26 +48,6 @@ public function execute($QUERY = array()) {
DServerLog::log(DServerLog::ERROR, "Invalid speed test benchmark result!", [$this->agent, $benchmark]);
$this->sendErrorResponse(PActions::SEND_BENCHMARK, "Invalid benchmark result!");
}

// Here we check if the benchmark result would require to split the task and check if the task can be split
if (SConfig::getInstance()->getVal(DConfig::RULE_SPLIT_DISABLE) == 0 && $task->getUsePreprocessor() == 0 && $split[1] > $task->getChunkTime() * 1000 * 2 && $taskWrapper->getTaskType() == DTaskTypes::NORMAL) {
// test if we have a large rule file
DServerLog::log(DServerLog::INFO, "Potential rule split required", [$this->agent, $task]);
/** @var $files File[] */
$files = Util::getFileInfo($task, AccessUtils::getAccessGroupsOfAgent($this->agent))[3];
foreach ($files as $file) {
if ($file->getFileType() == DFileType::RULE) {
// test if splitting makes sense here
if (Util::countLines(Factory::getStoredValueFactory()->get(DDirectories::FILES)->getVal() . "/" . $file->getFilename()) > $split[1] / 1000 / $task->getChunkTime() || SConfig::getInstance()->getVal(DConfig::RULE_SPLIT_ALWAYS)) {
// --> split
DServerLog::log(DServerLog::INFO, "Rule splitting possible on file", [$this->agent, $task, $file]);
TaskUtils::splitByRules($task, $taskWrapper, $files, $file, $split);
$this->sendErrorResponse(PActions::SEND_BENCHMARK, "Task was split due to benchmark!");
}
}
}
}

break;
case PValuesBenchmarkType::RUN_TIME:
if (!is_numeric($benchmark) || $benchmark <= 0) {
Expand Down
9 changes: 0 additions & 9 deletions src/inc/defines/DConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class DConfig {
const BLACKLIST_CHARS = "blacklistChars";
const DISP_TOLERANCE = "disptolerance";
const DEFAULT_BENCH = "defaultBenchmark";
const RULE_SPLIT_SMALL_TASKS = "ruleSplitSmallTasks";
const RULE_SPLIT_ALWAYS = "ruleSplitAlways";
const RULE_SPLIT_DISABLE = "ruleSplitDisable";
const AGENT_DATA_LIFETIME = "agentDataLifetime";
const DISABLE_TRIMMING = "disableTrimming";
const PRIORITY_0_START = "priority0Start";
Expand Down Expand Up @@ -158,9 +155,6 @@ public static function getConfigType($config) {
DConfig::EMAIL_SENDER_NAME => DConfigType::STRING_INPUT,
DConfig::DEFAULT_BENCH => DConfigType::TICKBOX,
DConfig::SHOW_TASK_PERFORMANCE => DConfigType::TICKBOX,
DConfig::RULE_SPLIT_ALWAYS => DConfigType::TICKBOX,
DConfig::RULE_SPLIT_SMALL_TASKS => DConfigType::TICKBOX,
DConfig::RULE_SPLIT_DISABLE => DConfigType::TICKBOX,
DConfig::AGENT_STAT_LIMIT => DConfigType::NUMBER_INPUT,
DConfig::AGENT_DATA_LIFETIME => DConfigType::NUMBER_INPUT,
DConfig::AGENT_STAT_TENSION => DConfigType::TICKBOX,
Expand Down Expand Up @@ -232,9 +226,6 @@ public static function getConfigDescription($config) {
DConfig::EMAIL_SENDER_NAME => "Sender's name on emails sent from " . APP_NAME . ".",
DConfig::DEFAULT_BENCH => "Use speed benchmark as default.",
DConfig::SHOW_TASK_PERFORMANCE => "Show cracks/minute for tasks which are running.",
DConfig::RULE_SPLIT_SMALL_TASKS => "When rule splitting is applied for tasks, always make them a small task.",
DConfig::RULE_SPLIT_ALWAYS => "Even do rule splitting when there are not enough rules but just the benchmark is too high.<br>Can result in subtasks with just one rule.",
DConfig::RULE_SPLIT_DISABLE => "Disable automatic task splitting with large rule files.",
DConfig::AGENT_STAT_LIMIT => "Maximal number of data points showing of agent gpu data.",
DConfig::AGENT_DATA_LIFETIME => "Minimum time in seconds how long agent gpu/cpu utilisation and gpu temperature data is kept on the server.",
DConfig::AGENT_STAT_TENSION => "Draw straigth lines in agent data graph instead of bezier curves.",
Expand Down
90 changes: 0 additions & 90 deletions src/inc/utils/TaskUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,96 +912,6 @@ public static function createTask($hashlistId, $name, $attackCmd, $chunkTime, $s
return $task;
}

/**
* Splits a given task into subtasks within a supertask by splitting the rule file
* @param Task $task
* @param TaskWrapper $taskWrapper
* @param File[] $files
* @param File $splitFile
* @param array $split
*/
public static function splitByRules($task, $taskWrapper, $files, $splitFile, $split) {
// calculate how much we need to split
$numSplits = floor($split[1] / 1000 / $task->getChunkTime());
// replace countLines with fileLineCount? Could be a better option: not OS-dependent
$numLines = Util::countLines(Factory::getStoredValueFactory()->get(DDirectories::FILES)->getVal() . "/" . $splitFile->getFilename());
$linesPerFile = floor($numLines / $numSplits) + 1;

// create the temporary rule files
$newFiles = [];
$content = explode("\n", str_replace("\r\n", "\n", file_get_contents(Factory::getStoredValueFactory()->get(DDirectories::FILES)->getVal() . "/" . $splitFile->getFilename())));
$count = 0;
$taskId = $task->getId();
for ($i = 0; $i < $numLines; $i += $linesPerFile, $count++) {
$copy = [];
for ($j = $i; $j < $i + $linesPerFile && $j < sizeof($content); $j++) {
$copy[] = $content[$j];
}
$filename = $splitFile->getFilename() . "_p$taskId-$count";
$path = Factory::getStoredValueFactory()->get(DDirectories::FILES)->getVal() . "/" . $splitFile->getFilename() . "_p$taskId-$count";
file_put_contents($path, implode("\n", $copy) . "\n");
$f = new File(null, $filename, Util::filesize($path), $splitFile->getIsSecret(), DFileType::TEMPORARY, $taskWrapper->getAccessGroupId(), Util::fileLineCount($path));
$f = Factory::getFileFactory()->save($f);
$newFiles[] = $f;
}

// take out the split file from the file list
for ($i = 0; $i < sizeof($files); $i++) {
if ($files[$i]->getId() == $splitFile->getId()) {
unset($files[$i]);
break;
}
}

// create new tasks as supertask
$newWrapper = new TaskWrapper(null, 0, 0, DTaskTypes::SUPERTASK, $taskWrapper->getHashlistId(), $taskWrapper->getAccessGroupId(), $task->getTaskName() . " (From Rule Split)", 0, 0);
$newWrapper = Factory::getTaskWrapperFactory()->save($newWrapper);
$prio = sizeof($newFiles) + 1;
foreach ($newFiles as $newFile) {
$newTask = new Task(null,
"Part " . (sizeof($newFiles) + 2 - $prio),
str_replace($splitFile->getFilename(), $newFile->getFilename(), $task->getAttackCmd()),
$task->getChunkTime(),
$task->getStatusTimer(),
0,
0,
$prio,
$task->getMaxAgents(),
$task->getColor(),
(SConfig::getInstance()->getVal(DConfig::RULE_SPLIT_SMALL_TASKS) == 0) ? 0 : 1,
$task->getIsCpuTask(),
$task->getUseNewBench(),
$task->getSkipKeyspace(),
$task->getCrackerBinaryId(),
$task->getCrackerBinaryTypeId(),
$newWrapper->getId(),
0,
'',
0,
0,
0,
0,
''
);
$newTask = Factory::getTaskFactory()->save($newTask);
$taskFiles = [];
$taskFiles[] = new FileTask(null, $newFile->getId(), $newTask->getId());
foreach ($files as $f) {
$taskFiles[] = new FileTask(null, $f->getId(), $newTask->getId());
FileDownloadUtils::addDownload($f->getId());
}
Factory::getFileTaskFactory()->massSave($taskFiles);
$prio--;
}
$newWrapper->setPriority($taskWrapper->getPriority());
$newWrapper->setMaxAgents($taskWrapper->getMaxAgents());
Factory::getTaskWrapperFactory()->update($newWrapper);

// cleanup
TaskUtils::deleteTask($task);
Factory::getTaskWrapperFactory()->delete($taskWrapper);
}

/**
* @param $agent Agent
* @param bool $all set true to get all matching tasks for this agent
Expand Down
2 changes: 2 additions & 0 deletions src/migrations/mysql/20260317120000_remove-rule-split.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DELETE FROM Config
where item in ('ruleSplitSmallTasks', 'ruleSplitAlways', 'ruleSplitDisable');
2 changes: 2 additions & 0 deletions src/migrations/postgres/20260317120000_remove-rule-split.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DELETE FROM Config
where item in ('ruleSplitSmallTasks', 'ruleSplitAlways', 'ruleSplitDisable');
Loading