Skip to content
Merged
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
41 changes: 37 additions & 4 deletions src/inc/Util.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,50 @@ public static function getGitCommit($hashOnly = false) {
return $gitcommit;
}

/**
* function to check agent version for older update scripts, that still has
* the 'type' field in AgentBinary instead of 'binaryType'
*/
public static function checkAgentVersionLegacy($type, $version, $silent = false) {
$agentBinaryFactory = Factory::getAgentBinaryFactory();
$dict = $agentBinaryFactory->getNullObject()->getKeyValueDict();
unset($dict["binaryType"]);
$dict["type"] = null;
$keys = array_keys($dict);

$query = "SELECT " . implode(", ", $keys) . " FROM " . $agentBinaryFactory->getModelTable();
$query .= " WHERE type=?";
$dbh = $agentBinaryFactory->getDB();
$stmt = $dbh->prepare($query);
$vals = [$type];
$stmt->execute($vals);

$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row != null) {
$pkName = $agentBinaryFactory->getNullObject()->getPrimaryKey();
$pk = $row[$pkName];
$row["binaryType"] = $row["type"];
$binary = $agentBinaryFactory->createObjectFromDict($pk, $row);

if (Comparator::lessThan($binary->getVersion(), $version)) {
if (!$silent) {
echo "update $type version... ";
}
Factory::getAgentBinaryFactory()->set($binary, AgentBinary::VERSION, $version);
if (!$silent) {
echo "OK";
}
}
}
}

/**
* @param string $type
* @param string $version
* @param bool $silent
*/
public static function checkAgentVersion($type, $version, $silent = false) {
$qF = new QueryFilter(AgentBinary::BINARY_TYPE, $type, "=");
if (Util::databaseColumnExists("AgentBinary", "type")) {
// This check is needed for older updates when agentbinary column still got old 'type' name
$qF = new QueryFilter("type", $type, "=");
}
$binary = Factory::getAgentBinaryFactory()->filter([Factory::FILTER => $qF], true);
if ($binary != null) {
if (Comparator::lessThan($binary->getVersion(), $version)) {
Expand Down
2 changes: 1 addition & 1 deletion src/install/updates/update_v0.10.x_v0.11.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

if (!isset($PRESENT["v0.10.x_agentBinaries"])) {
Util::checkAgentVersion("python", "0.5.0", true);
Util::checkAgentVersionLegacy("python", "0.5.0", true);
$EXECUTED["v0.10.x_agentBinaries"] = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/install/updates/update_v0.11.x_v0.12.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

if (!isset($PRESENT["v0.11.x_agentBinaries"])) {
Util::checkAgentVersion("python", "0.6.0", true);
Util::checkAgentVersionLegacy("python", "0.6.0", true);
$EXECUTED["v0.11.x_agentBinaries"] = true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/install/updates/update_v0.12.x_v0.13.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@
}

if (!isset($PRESENT["v0.12.x_agentBinaries"])) {
Util::checkAgentVersion("python", "0.6.0.10", true);
Util::checkAgentVersionLegacy("python", "0.6.0.10", true);
$EXECUTED["v0.12.x_agentBinaries"] = true;
}

if (!isset($PRESENT["v0.12.x_agentBinaries_1"])) {
Util::checkAgentVersion("python", "0.7.0", true);
Util::checkAgentVersionLegacy("python", "0.7.0", true);
$EXECUTED["v0.12.x_agentBinaries_1"] = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/install/updates/update_v0.13.x_v0.13.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}

if (!isset($PRESENT["v0.13.x_agentBinaries"])) {
Util::checkAgentVersion("python", "0.7.1", true);
Util::checkAgentVersionLegacy("python", "0.7.1", true);
$EXECUTED["v0.13.x_agentBinaries"] = true;
}
if (!isset($PRESENT["v0.13.x_hash_length"])) {
Expand Down
2 changes: 1 addition & 1 deletion src/install/updates/update_v0.14.3_v0.14.4.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
use DBA\QueryFilter;

if (!isset($PRESENT["v0.14.3_agentBinaries"])) {
Util::checkAgentVersion("python", "0.7.3", true);
Util::checkAgentVersionLegacy("python", "0.7.3", true);
$EXECUTED["v0.14.3_agentBinaries"] = true;
}
9 changes: 5 additions & 4 deletions src/install/updates/update_v0.14.4_v0.14.5.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
use DBA\HashType;
use DBA\QueryFilter;

if (!isset($PRESENT["v0.14.4_agentBinaries"])) {
Util::checkAgentVersion("python", "0.7.4", true);
$EXECUTED["v0.14.4_agentBinaries"] = true;
}

if (!isset($PRESENT["v0.14.4_update_agent_binary"])) {
if (Util::databaseColumnExists("AgentBinary", "type")) {
Expand All @@ -17,6 +13,11 @@
}
}

if (!isset($PRESENT["v0.14.4_agentBinaries"])) {
Util::checkAgentVersion("python", "0.7.4", true);
$EXECUTED["v0.14.4_agentBinaries"] = true;
}

if (!isset($PRESENT["v0.14.4_update_hashtypes"])){
$hashTypes = [
new HashType( 1310, 'sha224($pass.$salt)', 1, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/install/updates/update_v0.14.x_v0.14.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
}

if (!isset($PRESENT["v0.14.x_agentBinaries"])) {
Util::checkAgentVersion("python", "0.7.2", true);
Util::checkAgentVersionLegacy("python", "0.7.2", true);
$EXECUTED["v0.14.x_agentBinaries"] = true;
}
4 changes: 2 additions & 2 deletions src/install/updates/update_v0.5.x_v0.6.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
echo "Apply updates...\n";

echo "Check agent binaries... ";
Util::checkAgentVersion("python", "0.1.4");
Util::checkAgentVersion("csharp", "0.52.2");
Util::checkAgentVersionLegacy("python", "0.1.4");
Util::checkAgentVersionLegacy("csharp", "0.52.2");
echo "\n";

echo "Create new permissions... ";
Expand Down
4 changes: 2 additions & 2 deletions src/install/updates/update_v0.6.0_v0.7.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
echo "Apply updates...\n";

echo "Check agent binaries... ";
Util::checkAgentVersion("python", "0.1.7");
Util::checkAgentVersion("csharp", "0.52.4");
Util::checkAgentVersionLegacy("python", "0.1.7");
Util::checkAgentVersionLegacy("csharp", "0.52.4");
echo "\n";

echo "Creating User API...";
Expand Down
4 changes: 2 additions & 2 deletions src/install/updates/update_v0.7.x_v0.8.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
echo "Apply updates...\n";

echo "Check agent binaries... ";
Util::checkAgentVersion("python", "0.2.0");
Util::checkAgentVersion("csharp", "0.52.4");
Util::checkAgentVersionLegacy("python", "0.2.0");
Util::checkAgentVersionLegacy("csharp", "0.52.4");
echo "\n";

echo "Add debug output tables... ";
Expand Down
2 changes: 1 addition & 1 deletion src/install/updates/update_v0.9.0_v0.10.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
Factory::getAgentBinaryFactory()->update($agent);
}

Util::checkAgentVersion("python", "0.4.0", true);
Util::checkAgentVersionLegacy("python", "0.4.0", true);
$EXECUTED["v0.9.0_agentBinaries"] = true;
}