|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Support App Extension - macOS Security Compliance Project Failed Results Count |
| 4 | +# |
| 5 | +# |
| 6 | +# Copyright 2023 Root3 B.V. All rights reserved. |
| 7 | +# This script is based on a script copyrighted by Jamf Software, LLC (2022). |
| 8 | +# Original project: https://github.com/usnistgov/macos_security |
| 9 | +# |
| 10 | +# Support App Extension to show the number of issues from a macOS Security |
| 11 | +# Compliance Project Baseline. Result is published to Extension A and triggers |
| 12 | +# a warning in the menu bar icon and extension when there are 1 or more issues. |
| 13 | +# |
| 14 | +# REQUIREMENTS: |
| 15 | +# - An active mSCP baseline |
| 16 | +# - SupportHelper |
| 17 | +# |
| 18 | +# EXAMPLE: |
| 19 | +# Here's an example how to configure the Support App preferences for Extension A |
| 20 | +# - ExtensionTitleA: Compliance |
| 21 | +# - ExtensionSymbolA: lock.fill |
| 22 | +# - ExtensionTypeA: DistributedNotification |
| 23 | +# - ExtensionLinkA: /usr/local/bin/compliance_status.sh |
| 24 | +# - OnAppearAction: /usr/local/bin/compliance_status.sh |
| 25 | +# |
| 26 | +# THE SOFTWARE IS PROVIDED BY ROOT3 B.V. "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 27 | +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 28 | +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO |
| 29 | +# EVENT SHALL ROOT3 B.V. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 30 | +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR |
| 31 | +# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 32 | + |
| 33 | +# --------------------- do not edit below this line ---------------------- |
| 34 | + |
| 35 | +audit=$(ls -l /Library/Preferences | /usr/bin/grep 'org.*.audit.plist' | /usr/bin/awk '{print $NF}') |
| 36 | +EXEMPT_RULES=() |
| 37 | +FAILED_RULES=() |
| 38 | + |
| 39 | +if [[ ! -z "$audit" ]]; then |
| 40 | + |
| 41 | + count=$(echo "$audit" | /usr/bin/wc -l | /usr/bin/xargs) |
| 42 | + if [[ "$count" == 1 ]]; then |
| 43 | + |
| 44 | + # Get the Exemptions |
| 45 | + exemptfile="/Library/Managed Preferences/${audit}" |
| 46 | + if [[ ! -e "$exemptfile" ]];then |
| 47 | + exemptfile="/Library/Preferences/${audit}" |
| 48 | + fi |
| 49 | + |
| 50 | + rules=($(/usr/libexec/PlistBuddy -c "print :" "${exemptfile}" | /usr/bin/awk '/Dict/ { print $1 }')) |
| 51 | + |
| 52 | + for rule in ${rules[*]}; do |
| 53 | + if [[ $rule == "Dict" ]]; then |
| 54 | + continue |
| 55 | + fi |
| 56 | + EXEMPTIONS=$(/usr/libexec/PlistBuddy -c "print :$rule:exempt" "${exemptfile}" 2>/dev/null) |
| 57 | + if [[ "$EXEMPTIONS" == "true" ]]; then |
| 58 | + EXEMPT_RULES+=($rule) |
| 59 | + fi |
| 60 | + done |
| 61 | + |
| 62 | + unset $rules |
| 63 | + |
| 64 | + # Get the Findings |
| 65 | + auditfile="/Library/Preferences/${audit}" |
| 66 | + rules=($(/usr/libexec/PlistBuddy -c "print :" "${auditfile}" | /usr/bin/awk '/Dict/ { print $1 }')) |
| 67 | + |
| 68 | + for rule in ${rules[*]}; do |
| 69 | + if [[ $rule == "Dict" ]]; then |
| 70 | + continue |
| 71 | + fi |
| 72 | + FINDING=$(/usr/libexec/PlistBuddy -c "print :$rule:finding" "${auditfile}") |
| 73 | + if [[ "$FINDING" == "true" ]]; then |
| 74 | + FAILED_RULES+=($rule) |
| 75 | + fi |
| 76 | + done |
| 77 | + # count items only in Findings |
| 78 | + count=0 |
| 79 | + for finding in ${FAILED_RULES[@]}; do |
| 80 | + if [[ ! " ${EXEMPT_RULES[*]} " =~ " ${finding} " ]] ;then |
| 81 | + ((count=count+1)) |
| 82 | + fi |
| 83 | + done |
| 84 | + else |
| 85 | + count="-2" |
| 86 | + fi |
| 87 | +else |
| 88 | + count="-1" |
| 89 | +fi |
| 90 | + |
| 91 | +#### Support App integration #### |
| 92 | + |
| 93 | +# Start spinning indicator |
| 94 | +defaults write /Library/Preferences/nl.root3.support.plist ExtensionLoadingA -bool true |
| 95 | + |
| 96 | +# Show placeholder value while loading |
| 97 | +defaults write /Library/Preferences/nl.root3.support.plist ExtensionValueA -string "KeyPlaceholder" |
| 98 | + |
| 99 | +# Keep loading effect active for 0.5 seconds |
| 100 | +sleep 0.5 |
| 101 | + |
| 102 | +# Set compliance status. If there are 1 or more issues, show the issue count and trigger warning in menu bar icon and info item |
| 103 | +if [[ ${count} -gt 0 ]]; then |
| 104 | + defaults write "/Library/Preferences/nl.root3.support.plist" ExtensionValueA "Your \$LocalModelShortName has ${count} issues" |
| 105 | + defaults write "/Library/Preferences/nl.root3.support.plist" ExtensionAlertA -bool true |
| 106 | +else |
| 107 | + defaults write "/Library/Preferences/nl.root3.support.plist" ExtensionValueA "Your \$LocalModelShortName is secure" |
| 108 | + defaults write "/Library/Preferences/nl.root3.support.plist" ExtensionAlertA -bool false |
| 109 | +fi |
| 110 | + |
| 111 | +# Stop loading effect |
| 112 | +defaults write "/Library/Preferences/nl.root3.support.plist" ExtensionLoadingA -bool false |
0 commit comments