diff --git a/README.md b/README.md index 29a37f9..11bb71d 100755 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ Lists the highest supported and shipping OS versions for a machine. OS support data is updated by module once a week from MunkiReport's supported_os module GitHub page. Can be manually updated from admin page. Module will use data contained within module if unable to access OS support data on GitHub. Shipping OS versions from [https://mrmacintosh.com/can-i-upgrade-or-downgrade-macos-every-mac-from-2006-2020/](https://mrmacintosh.com/can-i-upgrade-or-downgrade-macos-every-mac-from-2006-2020/) + +Config Items +--- +By default the module sends an event to the Messages widget when macOS is updated or upgraded. To hide these events, set `SUPPPORTED_OS_SHOW_MACOS_UPDATED` to `FALSE` in MunkiReport's `.env` config. Remarks --- diff --git a/config.php b/config.php new file mode 100755 index 0000000..c635c90 --- /dev/null +++ b/config.php @@ -0,0 +1,16 @@ + env('SUPPPORTED_OS_SHOW_MACOS_UPDATED', true), + +]; \ No newline at end of file diff --git a/supported_os_model.php b/supported_os_model.php index 96b59ca..d49bab5 100755 --- a/supported_os_model.php +++ b/supported_os_model.php @@ -21,6 +21,9 @@ public function __construct($serial = '') } $this->serial_number = $serial; + + // Add local config + configAppendFile(__DIR__ . '/config.php'); } // ------------------------------------------------------------------------ @@ -46,7 +49,7 @@ public function process($data) // Get the current time $current_time = time(); - + // Check if we have a null result or a week has passed if($cached_data_time == null || ($current_time > ($cached_data_time + 604800))){ @@ -129,6 +132,13 @@ public function process($data) $shipping_os = $yaml_data['shipping']; $most_current_os = $yaml_data['current_os']; + // Store existing current_os value + if(empty($this->rs['current_os'])){ + $stored_current_os = null; + } else { + $stored_current_os = $this->rs['current_os']; + } + // Check if we are processing a plist or not if(!is_array($data)){ $parser = new CFPropertyList(); @@ -246,9 +256,30 @@ public function process($data) // Save OS gibblets $this->save(); + // Trigger updated macOS event if not nulls and 'supported_os_show_macos_updated' config is set to true + if(conf('supported_os_show_macos_updated') && ! is_null($stored_current_os) && ! is_null($this->rs['current_os'])){ + // and previous version of macOS is different than new version of macOS + if ( $stored_current_os !== $this->rs['current_os']){ + $this->_storeEvents($stored_current_os, $this->rs['current_os']); + } + } + // Return something if reprocessing if(is_array($data)){ return true; } } // End process() + + // Process events + private function _storeEvents($old_version, $new_version) + { + $old_version_array = str_split($old_version, 2); + $old_version_string = $old_version_array[0].".".intval($old_version_array[1]).".".intval($old_version_array[2]); + + $new_version_array = str_split($new_version, 2); + $new_version_string = $new_version_array[0].".".intval($new_version_array[1]).".".intval($new_version_array[2]); + + $msg = $old_version_string . ' -> ' . $new_version_string; + store_event($this->rs['serial_number'], "macOS updated", 'success', $msg); + } }