feat: history, dry-run, Discord webhook, bump 1.3.0
- history: read event logs from monitor/heal - test/dry-run: simulate bypass, suppress, harden without side effects - --dry-run: global flag for any command - monitor --webhook <url>: Discord notification on MDM detection - Update CHANGELOG, CI, standalone for all new features - Bump 1.2.0 -> 1.3.0
This commit is contained in:
@@ -31,6 +31,7 @@ jobs:
|
|||||||
lib/whitelist.sh
|
lib/whitelist.sh
|
||||||
lib/check.sh
|
lib/check.sh
|
||||||
lib/monitor.sh
|
lib/monitor.sh
|
||||||
|
lib/history.sh
|
||||||
|
|
||||||
syntax:
|
syntax:
|
||||||
name: Bash Syntax Check
|
name: Bash Syntax Check
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ set -euo pipefail
|
|||||||
VERSION="$VERSION"
|
VERSION="$VERSION"
|
||||||
HEADER
|
HEADER
|
||||||
|
|
||||||
for lib in colors detect validate dscl suppress backup status heal firewall harden whitelist check monitor; do
|
for lib in colors detect validate dscl suppress backup status heal firewall harden whitelist check monitor history; do
|
||||||
tail -n +1 "$SCRIPT_DIR/lib/$lib.sh" >> "$OUT"
|
tail -n +1 "$SCRIPT_DIR/lib/$lib.sh" >> "$OUT"
|
||||||
echo "" >> "$OUT"
|
echo "" >> "$OUT"
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ NC='\033[0m'
|
|||||||
|
|
||||||
LOG_FILE=""
|
LOG_FILE=""
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
|
DRY_RUN=false
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
local level="$1"
|
local level="$1"
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
show_history() {
|
||||||
|
header "Unleash Event History"
|
||||||
|
|
||||||
|
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
||||||
|
local found=false
|
||||||
|
|
||||||
|
for logfile in "${logs[@]}"; do
|
||||||
|
if [ -f "$logfile" ] && [ -s "$logfile" ]; then
|
||||||
|
found=true
|
||||||
|
local name
|
||||||
|
name=$(basename "$logfile")
|
||||||
|
step "$name"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
echo " $line"
|
||||||
|
done < "$logfile"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$found" = false ]; then
|
||||||
|
info "No event logs found."
|
||||||
|
info "Run 'sudo ./unleash monitor' or 'sudo ./unleash persist' first."
|
||||||
|
fi
|
||||||
|
|
||||||
|
step "Backup records"
|
||||||
|
local backup_dir=".unleash-backup"
|
||||||
|
if [ -d "$backup_dir" ] && [ -f "$backup_dir/timestamp" ]; then
|
||||||
|
local ts
|
||||||
|
ts=$(cat "$backup_dir/timestamp")
|
||||||
|
echo " Last backup: $ts"
|
||||||
|
else
|
||||||
|
echo " No backup found"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
clear_history() {
|
||||||
|
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
||||||
|
for logfile in "${logs[@]}"; do
|
||||||
|
if [ -f "$logfile" ]; then
|
||||||
|
: > "$logfile"
|
||||||
|
success "Cleared: $logfile"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
@@ -80,6 +80,7 @@ monitor_mdm() {
|
|||||||
|
|
||||||
local logfile="/var/log/unleash-monitor.log"
|
local logfile="/var/log/unleash-monitor.log"
|
||||||
local pidfile="/tmp/unleash-monitor.pid"
|
local pidfile="/tmp/unleash-monitor.pid"
|
||||||
|
local webhook="${DISCORD_WEBHOOK:-}"
|
||||||
|
|
||||||
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
||||||
echo -e "${YEL}Monitor already running (PID $(cat "$pidfile"))${NC}"
|
echo -e "${YEL}Monitor already running (PID $(cat "$pidfile"))${NC}"
|
||||||
@@ -135,6 +136,11 @@ monitor_mdm() {
|
|||||||
if command -v osascript &>/dev/null; then
|
if command -v osascript &>/dev/null; then
|
||||||
osascript -e "display notification \"$reason\" with title \"Unleash MDM Alert\" subtitle \"MDM enrollment detected\"" 2>/dev/null || true
|
osascript -e "display notification \"$reason\" with title \"Unleash MDM Alert\" subtitle \"MDM enrollment detected\"" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$webhook" ]; then
|
||||||
|
local payload
|
||||||
|
payload=$(printf '{"content":"🚨 **Unleash Alert** — MDM enrollment detected: %s","username":"Unleash Monitor"}' "$reason")
|
||||||
|
curl -s -H "Content-Type: application/json" -d "$payload" "$webhook" 2>/dev/null || warn "Webhook failed"
|
||||||
|
fi
|
||||||
heal_suppress ""
|
heal_suppress ""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -150,6 +156,11 @@ monitor_mdm() {
|
|||||||
if command -v osascript &>/dev/null; then
|
if command -v osascript &>/dev/null; then
|
||||||
osascript -e "display dialog \"MDM keeps coming back after 12 attempts. Something is persistently re-enrolling.\" with title \"Unleash\" buttons {\"OK\"} default button \"OK\"" 2>/dev/null || true
|
osascript -e "display dialog \"MDM keeps coming back after 12 attempts. Something is persistently re-enrolling.\" with title \"Unleash\" buttons {\"OK\"} default button \"OK\"" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$webhook" ]; then
|
||||||
|
curl -s -H "Content-Type: application/json" \
|
||||||
|
-d '{"content":"🚨 **Unleash CRITICAL** — 12 consecutive MDM detections. Persistent re-enrollment detected.","username":"Unleash Monitor"}' \
|
||||||
|
"$webhook" 2>/dev/null || true
|
||||||
|
fi
|
||||||
consecutive_failures=0
|
consecutive_failures=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+19
-1
@@ -4,6 +4,16 @@ PB=/usr/libexec/PlistBuddy
|
|||||||
|
|
||||||
suppress_enrollment() {
|
suppress_enrollment() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
info "[DRY RUN] Would suppress MDM enrollment on $data_mount"
|
||||||
|
info "[DRY RUN] - Clear DEP markers in ConfigurationProfiles/Settings"
|
||||||
|
info "[DRY RUN] - Block 13+ Apple MDM domains in /etc/hosts"
|
||||||
|
info "[DRY RUN] - Disable 4 enrollment daemons in launchd disabled.plist"
|
||||||
|
info "[DRY RUN] - Clean MDM artifacts from /Users/*/Library"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local hosts="$data_mount/private/etc/hosts"
|
local hosts="$data_mount/private/etc/hosts"
|
||||||
local cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
|
local cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
|
||||||
local ldp="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
|
local ldp="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
|
||||||
@@ -25,7 +35,6 @@ suppress_enrollment() {
|
|||||||
|
|
||||||
step "Blocking enrollment domains (Data volume hosts)..."
|
step "Blocking enrollment domains (Data volume hosts)..."
|
||||||
[ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; }
|
[ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; }
|
||||||
|
|
||||||
grep -q "Added by unleash" "$hosts" 2>/dev/null || {
|
grep -q "Added by unleash" "$hosts" 2>/dev/null || {
|
||||||
echo "" >>"$hosts"
|
echo "" >>"$hosts"
|
||||||
echo "# Added by unleash — DEP enrollment block" >>"$hosts"
|
echo "# Added by unleash — DEP enrollment block" >>"$hosts"
|
||||||
@@ -123,6 +132,15 @@ suppress_only_mode() {
|
|||||||
|
|
||||||
full_bypass_mode() {
|
full_bypass_mode() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
info "[DRY RUN] Would perform full MDM bypass on $data_mount"
|
||||||
|
info "[DRY RUN] - Create admin user"
|
||||||
|
info "[DRY RUN] - Skip Setup Assistant (.AppleSetupDone)"
|
||||||
|
info "[DRY RUN] - Then run suppress_enrollment"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local node
|
local node
|
||||||
node=$(dscl_node "$data_mount")
|
node=$(dscl_node "$data_mount")
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
VERSION="1.2.0"
|
VERSION="1.3.0"
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
LIB_DIR="$SCRIPT_DIR/lib"
|
LIB_DIR="$SCRIPT_DIR/lib"
|
||||||
|
|
||||||
for _lib in colors detect validate dscl suppress backup status heal firewall harden whitelist check monitor; do
|
for _lib in colors detect validate dscl suppress backup status heal firewall harden whitelist check monitor history; do
|
||||||
_lib_path="$LIB_DIR/$_lib.sh"
|
_lib_path="$LIB_DIR/$_lib.sh"
|
||||||
if [ -f "$_lib_path" ]; then
|
if [ -f "$_lib_path" ]; then
|
||||||
source "$_lib_path"
|
source "$_lib_path"
|
||||||
@@ -44,6 +44,8 @@ Bypass / suppress / monitor MDM enrollment on macOS.
|
|||||||
|
|
||||||
Monitoring:
|
Monitoring:
|
||||||
check Pre-format / pre-upgrade safety report
|
check Pre-format / pre-upgrade safety report
|
||||||
|
history Show event log from monitor/heal runs
|
||||||
|
test Dry-run mode: simulate without changing anything
|
||||||
monitor Background daemon (watches MDM every 5 min)
|
monitor Background daemon (watches MDM every 5 min)
|
||||||
monitor-install Install monitor as LaunchDaemon (boot persistent)
|
monitor-install Install monitor as LaunchDaemon (boot persistent)
|
||||||
monitor-uninstall Remove monitor LaunchDaemon
|
monitor-uninstall Remove monitor LaunchDaemon
|
||||||
@@ -76,6 +78,7 @@ ALIASES
|
|||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
--verbose Show debug messages
|
--verbose Show debug messages
|
||||||
|
--dry-run Simulate without making changes
|
||||||
--log-file <f> Write logs to file (appended)
|
--log-file <f> Write logs to file (appended)
|
||||||
|
|
||||||
Run without arguments for interactive menu.
|
Run without arguments for interactive menu.
|
||||||
@@ -283,14 +286,53 @@ cmd_check() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd_monitor() {
|
cmd_monitor() {
|
||||||
case "${2:-}" in
|
local webhook=""
|
||||||
|
local args=()
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
install|uninstall) args+=("$1"); shift ;;
|
||||||
|
--webhook) webhook="$2"; shift 2 ;;
|
||||||
|
*) args+=("$1"); shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
set -- "${args[@]}"
|
||||||
|
if [ -n "$webhook" ]; then
|
||||||
|
DISCORD_WEBHOOK="$webhook"
|
||||||
|
fi
|
||||||
|
case "${1:-}" in
|
||||||
install) install_monitor_launchdaemon "" ;;
|
install) install_monitor_launchdaemon "" ;;
|
||||||
uninstall) uninstall_monitor_launchdaemon "" ;;
|
uninstall) uninstall_monitor_launchdaemon "" ;;
|
||||||
*) monitor_mdm ;;
|
*) monitor_mdm ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_monitor_stop() { stop_monitor; }
|
cmd_monitor_stop() { stop_monitor; }
|
||||||
cmd_monitor_status() { monitor_status; }
|
cmd_monitor_status() { monitor_status; }
|
||||||
|
cmd_history() { show_history; }
|
||||||
|
cmd_history_clear() { clear_history; }
|
||||||
|
cmd_test() {
|
||||||
|
header "Dry Run Mode"
|
||||||
|
DRY_RUN=true
|
||||||
|
local cmd="${2:-suppress}"
|
||||||
|
case "$cmd" in
|
||||||
|
bypass) info "Simulating: bypass"; cmd_bypass ;;
|
||||||
|
suppress) info "Simulating: suppress"; cmd_suppress ;;
|
||||||
|
heal) info "Simulating: heal"; cmd_heal ;;
|
||||||
|
harden) info "Simulating: harden"; cmd_harden ;;
|
||||||
|
firewall) info "Simulating: firewall"; cmd_firewall ;;
|
||||||
|
whitelist) info "Simulating: whitelist"; cmd_whitelist ;;
|
||||||
|
all)
|
||||||
|
info "Simulating all available operations..."
|
||||||
|
info ""
|
||||||
|
DRY_RUN=true suppress_enrollment "/"
|
||||||
|
info ""
|
||||||
|
DRY_RUN=true full_bypass_mode "/"
|
||||||
|
info ""
|
||||||
|
info "Dry-run complete. No changes were made."
|
||||||
|
;;
|
||||||
|
*) info "Usage: ./unleash test {bypass|suppress|heal|harden|firewall|whitelist|all}" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
cmd_interactive_recovery() {
|
cmd_interactive_recovery() {
|
||||||
header "unleash"
|
header "unleash"
|
||||||
@@ -413,6 +455,7 @@ parse_global_opts() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--verbose) VERBOSE=true; shift ;;
|
--verbose) VERBOSE=true; shift ;;
|
||||||
|
--dry-run) DRY_RUN=true; shift ;;
|
||||||
--log-file) LOG_FILE="$2"; shift 2 ;;
|
--log-file) LOG_FILE="$2"; shift 2 ;;
|
||||||
*) args+=("$1"); shift ;;
|
*) args+=("$1"); shift ;;
|
||||||
esac
|
esac
|
||||||
@@ -440,6 +483,9 @@ main() {
|
|||||||
dualboot) cmd_dualboot ;;
|
dualboot) cmd_dualboot ;;
|
||||||
status|st|ls) cmd_status ;;
|
status|st|ls) cmd_status ;;
|
||||||
check) cmd_check ;;
|
check) cmd_check ;;
|
||||||
|
history) cmd_history ;;
|
||||||
|
history-clear) cmd_history_clear ;;
|
||||||
|
test|dry-run) cmd_test "$@" ;;
|
||||||
monitor|mn) cmd_monitor "$@" ;;
|
monitor|mn) cmd_monitor "$@" ;;
|
||||||
monitor-install|mn-install) install_monitor_launchdaemon "" ;;
|
monitor-install|mn-install) install_monitor_launchdaemon "" ;;
|
||||||
monitor-uninstall|mn-uninstall) uninstall_monitor_launchdaemon "" ;;
|
monitor-uninstall|mn-uninstall) uninstall_monitor_launchdaemon "" ;;
|
||||||
|
|||||||
+124
-3
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
VERSION="1.2.0"
|
VERSION="1.3.0"
|
||||||
RED='\033[1;31m'
|
RED='\033[1;31m'
|
||||||
GRN='\033[1;32m'
|
GRN='\033[1;32m'
|
||||||
BLU='\033[1;34m'
|
BLU='\033[1;34m'
|
||||||
@@ -11,6 +11,7 @@ NC='\033[0m'
|
|||||||
|
|
||||||
LOG_FILE=""
|
LOG_FILE=""
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
|
DRY_RUN=false
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
local level="$1"
|
local level="$1"
|
||||||
@@ -331,6 +332,16 @@ PB=/usr/libexec/PlistBuddy
|
|||||||
|
|
||||||
suppress_enrollment() {
|
suppress_enrollment() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
info "[DRY RUN] Would suppress MDM enrollment on $data_mount"
|
||||||
|
info "[DRY RUN] - Clear DEP markers in ConfigurationProfiles/Settings"
|
||||||
|
info "[DRY RUN] - Block 13+ Apple MDM domains in /etc/hosts"
|
||||||
|
info "[DRY RUN] - Disable 4 enrollment daemons in launchd disabled.plist"
|
||||||
|
info "[DRY RUN] - Clean MDM artifacts from /Users/*/Library"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local hosts="$data_mount/private/etc/hosts"
|
local hosts="$data_mount/private/etc/hosts"
|
||||||
local cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
|
local cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
|
||||||
local ldp="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
|
local ldp="$data_mount/private/var/db/com.apple.xpc.launchd/disabled.plist"
|
||||||
@@ -352,7 +363,6 @@ suppress_enrollment() {
|
|||||||
|
|
||||||
step "Blocking enrollment domains (Data volume hosts)..."
|
step "Blocking enrollment domains (Data volume hosts)..."
|
||||||
[ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; }
|
[ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; }
|
||||||
|
|
||||||
grep -q "Added by unleash" "$hosts" 2>/dev/null || {
|
grep -q "Added by unleash" "$hosts" 2>/dev/null || {
|
||||||
echo "" >>"$hosts"
|
echo "" >>"$hosts"
|
||||||
echo "# Added by unleash — DEP enrollment block" >>"$hosts"
|
echo "# Added by unleash — DEP enrollment block" >>"$hosts"
|
||||||
@@ -450,6 +460,15 @@ suppress_only_mode() {
|
|||||||
|
|
||||||
full_bypass_mode() {
|
full_bypass_mode() {
|
||||||
local data_mount="$1"
|
local data_mount="$1"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = true ]; then
|
||||||
|
info "[DRY RUN] Would perform full MDM bypass on $data_mount"
|
||||||
|
info "[DRY RUN] - Create admin user"
|
||||||
|
info "[DRY RUN] - Skip Setup Assistant (.AppleSetupDone)"
|
||||||
|
info "[DRY RUN] - Then run suppress_enrollment"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local node
|
local node
|
||||||
node=$(dscl_node "$data_mount")
|
node=$(dscl_node "$data_mount")
|
||||||
|
|
||||||
@@ -1403,6 +1422,7 @@ monitor_mdm() {
|
|||||||
|
|
||||||
local logfile="/var/log/unleash-monitor.log"
|
local logfile="/var/log/unleash-monitor.log"
|
||||||
local pidfile="/tmp/unleash-monitor.pid"
|
local pidfile="/tmp/unleash-monitor.pid"
|
||||||
|
local webhook="${DISCORD_WEBHOOK:-}"
|
||||||
|
|
||||||
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
||||||
echo -e "${YEL}Monitor already running (PID $(cat "$pidfile"))${NC}"
|
echo -e "${YEL}Monitor already running (PID $(cat "$pidfile"))${NC}"
|
||||||
@@ -1458,6 +1478,11 @@ monitor_mdm() {
|
|||||||
if command -v osascript &>/dev/null; then
|
if command -v osascript &>/dev/null; then
|
||||||
osascript -e "display notification \"$reason\" with title \"Unleash MDM Alert\" subtitle \"MDM enrollment detected\"" 2>/dev/null || true
|
osascript -e "display notification \"$reason\" with title \"Unleash MDM Alert\" subtitle \"MDM enrollment detected\"" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$webhook" ]; then
|
||||||
|
local payload
|
||||||
|
payload=$(printf '{"content":"🚨 **Unleash Alert** — MDM enrollment detected: %s","username":"Unleash Monitor"}' "$reason")
|
||||||
|
curl -s -H "Content-Type: application/json" -d "$payload" "$webhook" 2>/dev/null || warn "Webhook failed"
|
||||||
|
fi
|
||||||
heal_suppress ""
|
heal_suppress ""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -1473,6 +1498,11 @@ monitor_mdm() {
|
|||||||
if command -v osascript &>/dev/null; then
|
if command -v osascript &>/dev/null; then
|
||||||
osascript -e "display dialog \"MDM keeps coming back after 12 attempts. Something is persistently re-enrolling.\" with title \"Unleash\" buttons {\"OK\"} default button \"OK\"" 2>/dev/null || true
|
osascript -e "display dialog \"MDM keeps coming back after 12 attempts. Something is persistently re-enrolling.\" with title \"Unleash\" buttons {\"OK\"} default button \"OK\"" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$webhook" ]; then
|
||||||
|
curl -s -H "Content-Type: application/json" \
|
||||||
|
-d '{"content":"🚨 **Unleash CRITICAL** — 12 consecutive MDM detections. Persistent re-enrollment detected.","username":"Unleash Monitor"}' \
|
||||||
|
"$webhook" 2>/dev/null || true
|
||||||
|
fi
|
||||||
consecutive_failures=0
|
consecutive_failures=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1508,6 +1538,51 @@ monitor_status() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_history() {
|
||||||
|
header "Unleash Event History"
|
||||||
|
|
||||||
|
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
||||||
|
local found=false
|
||||||
|
|
||||||
|
for logfile in "${logs[@]}"; do
|
||||||
|
if [ -f "$logfile" ] && [ -s "$logfile" ]; then
|
||||||
|
found=true
|
||||||
|
local name
|
||||||
|
name=$(basename "$logfile")
|
||||||
|
step "$name"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
echo " $line"
|
||||||
|
done < "$logfile"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$found" = false ]; then
|
||||||
|
info "No event logs found."
|
||||||
|
info "Run 'sudo ./unleash monitor' or 'sudo ./unleash persist' first."
|
||||||
|
fi
|
||||||
|
|
||||||
|
step "Backup records"
|
||||||
|
local backup_dir=".unleash-backup"
|
||||||
|
if [ -d "$backup_dir" ] && [ -f "$backup_dir/timestamp" ]; then
|
||||||
|
local ts
|
||||||
|
ts=$(cat "$backup_dir/timestamp")
|
||||||
|
echo " Last backup: $ts"
|
||||||
|
else
|
||||||
|
echo " No backup found"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
clear_history() {
|
||||||
|
local logs=("/var/log/unleash-monitor.log" "/var/log/unleash-heal.log" "/var/log/unleash-monitor.err")
|
||||||
|
for logfile in "${logs[@]}"; do
|
||||||
|
if [ -f "$logfile" ]; then
|
||||||
|
: > "$logfile"
|
||||||
|
success "Cleared: $logfile"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
cat <<'HELP'
|
cat <<'HELP'
|
||||||
@@ -1537,6 +1612,8 @@ Bypass / suppress / monitor MDM enrollment on macOS.
|
|||||||
|
|
||||||
Monitoring:
|
Monitoring:
|
||||||
check Pre-format / pre-upgrade safety report
|
check Pre-format / pre-upgrade safety report
|
||||||
|
history Show event log from monitor/heal runs
|
||||||
|
test Dry-run mode: simulate without changing anything
|
||||||
monitor Background daemon (watches MDM every 5 min)
|
monitor Background daemon (watches MDM every 5 min)
|
||||||
monitor-install Install monitor as LaunchDaemon (boot persistent)
|
monitor-install Install monitor as LaunchDaemon (boot persistent)
|
||||||
monitor-uninstall Remove monitor LaunchDaemon
|
monitor-uninstall Remove monitor LaunchDaemon
|
||||||
@@ -1569,6 +1646,7 @@ ALIASES
|
|||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
--verbose Show debug messages
|
--verbose Show debug messages
|
||||||
|
--dry-run Simulate without making changes
|
||||||
--log-file <f> Write logs to file (appended)
|
--log-file <f> Write logs to file (appended)
|
||||||
|
|
||||||
Run without arguments for interactive menu.
|
Run without arguments for interactive menu.
|
||||||
@@ -1776,14 +1854,53 @@ cmd_check() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd_monitor() {
|
cmd_monitor() {
|
||||||
case "${2:-}" in
|
local webhook=""
|
||||||
|
local args=()
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
install|uninstall) args+=("$1"); shift ;;
|
||||||
|
--webhook) webhook="$2"; shift 2 ;;
|
||||||
|
*) args+=("$1"); shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
set -- "${args[@]}"
|
||||||
|
if [ -n "$webhook" ]; then
|
||||||
|
DISCORD_WEBHOOK="$webhook"
|
||||||
|
fi
|
||||||
|
case "${1:-}" in
|
||||||
install) install_monitor_launchdaemon "" ;;
|
install) install_monitor_launchdaemon "" ;;
|
||||||
uninstall) uninstall_monitor_launchdaemon "" ;;
|
uninstall) uninstall_monitor_launchdaemon "" ;;
|
||||||
*) monitor_mdm ;;
|
*) monitor_mdm ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_monitor_stop() { stop_monitor; }
|
cmd_monitor_stop() { stop_monitor; }
|
||||||
cmd_monitor_status() { monitor_status; }
|
cmd_monitor_status() { monitor_status; }
|
||||||
|
cmd_history() { show_history; }
|
||||||
|
cmd_history_clear() { clear_history; }
|
||||||
|
cmd_test() {
|
||||||
|
header "Dry Run Mode"
|
||||||
|
DRY_RUN=true
|
||||||
|
local cmd="${2:-suppress}"
|
||||||
|
case "$cmd" in
|
||||||
|
bypass) info "Simulating: bypass"; cmd_bypass ;;
|
||||||
|
suppress) info "Simulating: suppress"; cmd_suppress ;;
|
||||||
|
heal) info "Simulating: heal"; cmd_heal ;;
|
||||||
|
harden) info "Simulating: harden"; cmd_harden ;;
|
||||||
|
firewall) info "Simulating: firewall"; cmd_firewall ;;
|
||||||
|
whitelist) info "Simulating: whitelist"; cmd_whitelist ;;
|
||||||
|
all)
|
||||||
|
info "Simulating all available operations..."
|
||||||
|
info ""
|
||||||
|
DRY_RUN=true suppress_enrollment "/"
|
||||||
|
info ""
|
||||||
|
DRY_RUN=true full_bypass_mode "/"
|
||||||
|
info ""
|
||||||
|
info "Dry-run complete. No changes were made."
|
||||||
|
;;
|
||||||
|
*) info "Usage: ./unleash test {bypass|suppress|heal|harden|firewall|whitelist|all}" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
cmd_interactive_recovery() {
|
cmd_interactive_recovery() {
|
||||||
header "unleash"
|
header "unleash"
|
||||||
@@ -1906,6 +2023,7 @@ parse_global_opts() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--verbose) VERBOSE=true; shift ;;
|
--verbose) VERBOSE=true; shift ;;
|
||||||
|
--dry-run) DRY_RUN=true; shift ;;
|
||||||
--log-file) LOG_FILE="$2"; shift 2 ;;
|
--log-file) LOG_FILE="$2"; shift 2 ;;
|
||||||
*) args+=("$1"); shift ;;
|
*) args+=("$1"); shift ;;
|
||||||
esac
|
esac
|
||||||
@@ -1933,6 +2051,9 @@ main() {
|
|||||||
dualboot) cmd_dualboot ;;
|
dualboot) cmd_dualboot ;;
|
||||||
status|st|ls) cmd_status ;;
|
status|st|ls) cmd_status ;;
|
||||||
check) cmd_check ;;
|
check) cmd_check ;;
|
||||||
|
history) cmd_history ;;
|
||||||
|
history-clear) cmd_history_clear ;;
|
||||||
|
test|dry-run) cmd_test "$@" ;;
|
||||||
monitor|mn) cmd_monitor "$@" ;;
|
monitor|mn) cmd_monitor "$@" ;;
|
||||||
monitor-install|mn-install) install_monitor_launchdaemon "" ;;
|
monitor-install|mn-install) install_monitor_launchdaemon "" ;;
|
||||||
monitor-uninstall|mn-uninstall) uninstall_monitor_launchdaemon "" ;;
|
monitor-uninstall|mn-uninstall) uninstall_monitor_launchdaemon "" ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user