Skip to content

Commit

Permalink
macOS Updated events
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxudo committed Jan 15, 2024
1 parent d402b56 commit 47bb440
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
16 changes: 16 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return [
/*
|===============================================
| Show/Hide "macOS Updated" Events
|===============================================
|
| By default, the `support_os` module shows when macOS
| was updated in the Events module. To hide these,
| set `supported_os_show_macos_updated` to FALSE
|
*/
'supported_os_show_macos_updated' => env('SUPPPORTED_OS_SHOW_MACOS_UPDATED', true),

];
33 changes: 32 additions & 1 deletion supported_os_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public function __construct($serial = '')
}

$this->serial_number = $serial;

// Add local config
configAppendFile(__DIR__ . '/config.php');
}

// ------------------------------------------------------------------------
Expand All @@ -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))){

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 47bb440

Please sign in to comment.