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:
2026-06-20 12:19:55 -03:00
parent f6fa98c6c9
commit 208fe44dce
8 changed files with 250 additions and 8 deletions
+1
View File
@@ -8,6 +8,7 @@ NC='\033[0m'
LOG_FILE=""
VERBOSE=false
DRY_RUN=false
log() {
local level="$1"
+44
View File
@@ -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
}
+11
View File
@@ -80,6 +80,7 @@ monitor_mdm() {
local logfile="/var/log/unleash-monitor.log"
local pidfile="/tmp/unleash-monitor.pid"
local webhook="${DISCORD_WEBHOOK:-}"
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
echo -e "${YEL}Monitor already running (PID $(cat "$pidfile"))${NC}"
@@ -135,6 +136,11 @@ monitor_mdm() {
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
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 ""
fi
fi
@@ -150,6 +156,11 @@ monitor_mdm() {
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
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
fi
+19 -1
View File
@@ -4,6 +4,16 @@ PB=/usr/libexec/PlistBuddy
suppress_enrollment() {
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 cfg="$data_mount/private/var/db/ConfigurationProfiles/Settings"
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)..."
[ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; }
grep -q "Added by unleash" "$hosts" 2>/dev/null || {
echo "" >>"$hosts"
echo "# Added by unleash — DEP enrollment block" >>"$hosts"
@@ -123,6 +132,15 @@ suppress_only_mode() {
full_bypass_mode() {
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
node=$(dscl_node "$data_mount")