diff --git a/app/Config/OpenAudit.php b/app/Config/OpenAudit.php index 3e2a88eff..8aaa0f3b3 100755 --- a/app/Config/OpenAudit.php +++ b/app/Config/OpenAudit.php @@ -136,37 +136,6 @@ public function __construct() unset($tz); } - // get the server OS - $this->server_os = php_uname('s'); - - if ($this->server_os === 'Windows NT') { - $command = 'wmic os get name'; - exec($command, $output); - if (!empty($output[1])) { - $os = explode('|', $output[1]); - $this->server_platform = $os[0]; - } - } else if ($this->server_os === 'Darwin') { - $this->server_platform = 'MacOS'; - $command = "sw_vers | grep \"ProductVersion:\" | cut -d: -f2 | xargs"; - exec($command, $output); - if (!empty($output[0])) { - $this->server_platform .= ' ' . $output[0]; - unset($output); - } - $command = "awk '/SOFTWARE LICENSE AGREEMENT FOR macOS/' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | awk -F 'macOS ' '{print \$NF}' | awk '{print substr(\$0, 0, length(\$0)-1)}'"; - exec($command, $output); - if (!empty($output[0])) { - $this->server_platform .= ' ' . $output[0]; - } - } else { - $command = 'cat /etc/os-release 2>/dev/null | grep -i ^PRETTY_NAME | cut -d= -f2 | cut -d\" -f2'; - exec($command, $output); - if (!empty($output[0])) { - $this->server_platform = $output[0]; - } - } - if ($this->internal_version < 20230615) { # TODO - remove this and just set both to 0 $query = $db->query('SELECT count(*) as device_count FROM `system`'); diff --git a/app/Controllers/Logon.php b/app/Controllers/Logon.php index 9139f4629..ef88a0f68 100644 --- a/app/Controllers/Logon.php +++ b/app/Controllers/Logon.php @@ -70,6 +70,44 @@ public function createForm() $db->query($sql, [$subnet]); log_message('info', 'Default discovery subnet auto-populated with ' . $subnet . '.'); } + + // get the server OS + $server_os = php_uname('s'); + + if ($server_os === 'Windows NT') { + $command = 'wmic os get name'; + exec($command, $output); + if (!empty($output[1])) { + $os = explode('|', $output[1]); + $server_platform = $os[0]; + } + } else if ($server_os === 'Darwin') { + $server_platform = 'MacOS'; + $command = "sw_vers | grep \"ProductVersion:\" | cut -d: -f2 | xargs"; + exec($command, $output); + if (!empty($output[0])) { + $server_platform .= ' ' . $output[0]; + unset($output); + } + $command = "awk '/SOFTWARE LICENSE AGREEMENT FOR macOS/' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | awk -F 'macOS ' '{print \$NF}' | awk '{print substr(\$0, 0, length(\$0)-1)}'"; + exec($command, $output); + if (!empty($output[0])) { + $server_platform .= ' ' . $output[0]; + } + } else { + $command = 'cat /etc/os-release 2>/dev/null | grep -i ^PRETTY_NAME | cut -d= -f2 | cut -d\" -f2'; + exec($command, $output); + if (!empty($output[0])) { + $server_platform = $output[0]; + } + } + $sql = 'UPDATE configuration SET value = ? WHERE name = "server_os"'; + $db->query($sql, [$server_os]); + log_message('info', 'Config auto-populated with ServerOS ' . $server_os . '.'); + $sql = 'UPDATE configuration SET value = ? WHERE name = "server_platform"'; + $db->query($sql, [$server_platform]); + log_message('info', 'Config auto-populated with ServerPlatform ' . $server_platform . '.'); + $methods = array(); if ($db->tableExists('auth')) { $authModel = model('AuthModel'); diff --git a/app/Models/db_upgrades/db_5.5.0.php b/app/Models/db_upgrades/db_5.5.0.php index 99f79d038..c6cc5568b 100644 --- a/app/Models/db_upgrades/db_5.5.0.php +++ b/app/Models/db_upgrades/db_5.5.0.php @@ -165,6 +165,26 @@ $output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; log_message('info', (string)$db->getLastQuery()); +$sql = "DELETE FROM configuration WHERE name = 'server_os'"; +$db->query($sql); +$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; +log_message('info', (string)$db->getLastQuery()); + +$sql = "INSERT INTO `configuration` VALUES (NULL,'server_os','','text','n','system','2000-01-01 00:00:00','The OS Open-AudIT is running on (this server).')"; +$db->query($sql); +$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; +log_message('info', (string)$db->getLastQuery()); + +$sql = "DELETE FROM configuration WHERE name = 'server_platform'"; +$db->query($sql); +$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; +log_message('info', (string)$db->getLastQuery()); + +$sql = "INSERT INTO `configuration` VALUES (NULL,'server_platform','','text','n','system','2000-01-01 00:00:00','The OS Platform Open-AudIT is running on (this server).')"; +$db->query($sql); +$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n"; +log_message('info', (string)$db->getLastQuery()); + // set our versions $sql = "UPDATE `configuration` SET `value` = '20241012' WHERE `name` = 'internal_version'"; $db->query($sql); diff --git a/other/open-audit.sql b/other/open-audit.sql index 579080b47..9fba0c2c6 100644 --- a/other/open-audit.sql +++ b/other/open-audit.sql @@ -1245,6 +1245,8 @@ INSERT INTO `configuration` VALUES (NULL,'feature_executables','n','bool','y','s INSERT INTO `configuration` VALUES (NULL,'product','community','text','n','system','2000-01-01 00:00:00','Product type.'); INSERT INTO `configuration` VALUES (NULL,'license_footer','','text','n','system','2000-01-01 00:00:00','Footer text.'); INSERT INTO `configuration` VALUES (NULL,'license_limit','','number','n','system','2000-01-01 00:00:00','Licensed devices.'); +INSERT INTO `configuration` VALUES (NULL,'server_os','','text','n','system','2000-01-01 00:00:00','The OS Open-AudIT is running on (this server).'); +INSERT INTO `configuration` VALUES (NULL,'server_platform','','text','n','system','2000-01-01 00:00:00','The OS Platform Open-AudIT is running on (this server).'); /*!40000 ALTER TABLE `configuration` ENABLE KEYS */; UNLOCK TABLES;