Skip to content

Commit

Permalink
Upgrade testing for schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Apr 16, 2024
1 parent 26e7057 commit 43a5e85
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
9 changes: 6 additions & 3 deletions app/Config/OpenAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

class OpenAudit extends BaseConfig
{
# leave for backwards compat $this->displayVersion = '5.1.0';
public string $displayVersion = '5.1.0';
public int $appVersion = 20240104;
# leave for backwards compat $this->displayVersion = '5.2.0';
public string $displayVersion = '5.2.0';
public int $appVersion = 20240512;

public array $enterprise_collections = array('agents' => 'crud', 'applications' => 'cud', 'baselines' => 'crud', 'baselines_policies' => 'crud', 'baselines_results' => 'crud', 'clouds' => 'crud', 'collectors' => 'crud', 'dashboards' => 'cud', 'discovery_scan_options' => 'cud', 'files' => 'crud', 'executables' => 'crud', 'integrations' => 'crud', 'racks' => 'crud', 'roles' => 'cu');
public array $professional_collections = array('applications' => 'r', 'clusters' => 'crud', 'dashboards' => 'r', 'discovery_scan_options' => 'r', 'maps' => 'crud', 'rules' => 'crud', 'tasks' => 'crud', 'widgets' => 'crud');
Expand Down Expand Up @@ -80,6 +80,9 @@ public function __construct()
if ($row->name === 'license_string') {
$this->license_string_id = intval($row->id);
}
if ($row->name === 'license_eula') {
$this->license_eula_id = intval($row->id);
}
if ($row->name === 'license_string_collector') {
$this->license_string_collector_id = intval($row->id);
}
Expand Down
7 changes: 7 additions & 0 deletions app/Helpers/response_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ function response_create($instance = null)
$received_data = $response->meta->received_data;
$response->meta->received_data = array();
}
if ($function === 'configuration_update' and $response->meta->id === $config->license_eula_id) {
$received_data = $response->meta->received_data;
$response->meta->received_data = array();
}
// We need Orgs for these, associated with the user, supply them here
if ($response->meta->collection === 'reports' and $response->meta->action === 'execute') {
$response->meta->orgs = response_get_org_list($instance->user, 'devices');
Expand Down Expand Up @@ -506,6 +510,9 @@ function response_create($instance = null)
!($function === 'configuration_update' and ($response->meta->id === $config->license_string_id or $response->meta->id === $config->license_string_collector_id))) {
$response->meta->received_data = $received_data;
}
if ($function === 'configuration_update' and $response->meta->id === $config->license_eula_id) {
$response->meta->received_data = $received_data;
}
// TODO - Why does enterprise return this as a string?
$response->meta->limit = intval($response->meta->limit);
if (!empty($response->errors)) {
Expand Down
4 changes: 4 additions & 0 deletions app/Models/DatabaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ public function update($id = null, $data = null): bool
include "db_upgrades/db_5.1.0.php";
}

if (intval(config('Openaudit')->internal_version) < 20240512) {
include "db_upgrades/db_5.2.0.php";
}

$instance = & get_instance();
$instance->data = $output;
return true;
Expand Down
32 changes: 9 additions & 23 deletions app/Models/db_upgrades/db_5.2.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
log_message('info', (string)$db->getLastQuery());
}

$sql = "DELETE FROM `configuration` WHERE `name` IN ('product', 'oae_product', 'discovery_limit')";
$sql = "DELETE FROM `configuration` WHERE `name` IN ('product', 'oae_product', 'discovery_limit', 'discovery_wmi_timeout', 'feature_queries_advanced', 'feature_executables', 'feature_agents_advanced')";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());
Expand All @@ -77,41 +77,21 @@
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "DELETE FROM configuration` WHERE name = 'discovery_wmi_timeout'";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "INSERT INTO `configuration` VALUES (NULL,'discovery_wmi_timeout','900','number','y','system','2000-01-01 00:00:00','Timeout duration (in seconds) when discovering a device from Linux via WMI.')";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "DELETE FROM configuration` WHERE name = 'feature_queries_advanced'";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "INSERT INTO `configuration` VALUES (NULL,'feature_queries_advanced','n','bool','y','system','2000-01-01 00:00:00','Allow Queries without a filter.')";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "DELETE FROM configuration` WHERE name = 'feature_executables'";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "INSERT INTO `configuration` VALUES (NULL,'feature_executables','n','bool','y','system','2000-01-01 00:00:00','Activate the linux based Executables feature.')";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "DELETE FROM configuration` WHERE name = 'feature_agents_advanced'";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());

$sql = "INSERT INTO `configuration` VALUES (NULL,'feature_agents_advanced','n','bool','y','system','2000-01-01 00:00:00','Allow Agents to execute commands and download files.')";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
Expand Down Expand Up @@ -210,11 +190,17 @@
if ($role->name === 'user') {
$permissions->executables = 'r';
}
$this->rolesModel->update(intval($role->id), $permissions);
$sql = "UPDATE `roles` SET `permissions` = ? WHERE `id` = ?";
$query = $db->query($sql, [json_encode($permissions), $role->id]);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());
}
if ($role->name === 'admin' or $role->name === 'org_admin') {
$permissions->agents = 'crud';
$this->rolesModel->update(intval($role->id), $permissions);
$sql = "UPDATE `roles` SET `permissions` = ? WHERE `id` = ?";
$query = $db->query($sql, [json_encode($permissions), $role->id]);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());
}
}

Expand Down
4 changes: 2 additions & 2 deletions other/open-audit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ INSERT INTO `configuration` VALUES (NULL,'discovery_use_ipmi','y','bool','y','sy
INSERT INTO `configuration` VALUES (NULL,'discovery_use_org_id_match','n','bool','y','system','2000-01-01 00:00:00','When matching a device and assign_devices_to_org is set, use that attribute in the relevant match rules.');
INSERT INTO `configuration` VALUES (NULL,'discovery_use_vintage_service','n','bool','y','system','2000-01-01 00:00:00','On Windows, use the old way of running discovery with the Apache service account.');
INSERT INTO `configuration` VALUES (NULL,'discovery_wmi_timeout','900','number','y','system','2000-01-01 00:00:00','Timeout duration (in seconds) when discovering a device from Linux via WMI.');
INSERT INTO `configuration` VALUES (NULL,'display_version','5.1.0','text','n','system','2000-01-01 00:00:00','The version shown on the web pages.');
INSERT INTO `configuration` VALUES (NULL,'display_version','5.2.0','text','n','system','2000-01-01 00:00:00','The version shown on the web pages.');
INSERT INTO `configuration` VALUES (NULL,'download_reports','n','bool','y','system','2000-01-01 00:00:00','Tells Open-AudIT to advise the browser to download as a file or display the csv, xml, json reports.');
INSERT INTO `configuration` VALUES (NULL,'mail_domain','','text','y','system','2000-01-01 00:00:00','Email domain to use.');
INSERT INTO `configuration` VALUES (NULL,'mail_from','','text','y','system','2000-01-01 00:00:00','Email address used for as the sender.');
Expand All @@ -960,7 +960,7 @@ INSERT INTO `configuration` VALUES (NULL,'firstwave_prompt','2000-01-01','date',
INSERT INTO `configuration` VALUES (NULL,'graph_days','30','number','y','system','2000-01-01 00:00:00','The number of days to report on for the Enterprise graphs.');
INSERT INTO `configuration` VALUES (NULL,'gui_trim_characters','25','number','y','system','2000-01-01 00:00:00','When showing a table of information in the web GUI, replace characters greater than this with \"...\".');
INSERT INTO `configuration` VALUES (NULL,'homepage','summaries','text','y','system','2000-01-01 00:00:00','Any links to the default page should be directed to this endpoint.');
INSERT INTO `configuration` VALUES (NULL,'internal_version','20240104','number','n','system','2000-01-01 00:00:00','The internal numerical version.');
INSERT INTO `configuration` VALUES (NULL,'internal_version','20240512','number','n','system','2000-01-01 00:00:00','The internal numerical version.');
INSERT INTO `configuration` VALUES (NULL,'maps_api_key','','text','y','system','2000-01-01 00:00:00','Your API key for Google Maps.');
INSERT INTO `configuration` VALUES (NULL,'match_dbus','n','bool','y','system','2000-01-01 00:00:00','Should we match a device based on its dbus id.');
INSERT INTO `configuration` VALUES (NULL,'match_dns_fqdn','n','bool','y','system','2000-01-01 00:00:00','Should we match a device based on its DNS fqdn.');
Expand Down

0 comments on commit 43a5e85

Please sign in to comment.