mirror of
https://github.com/tw93/Mole.git
synced 2026-03-24 04:55:07 +00:00
Merge branch 'main' of https://github.com/tw93/Mole
This commit is contained in:
@@ -108,14 +108,41 @@ request_sudo_access() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get TTY path
|
# Detect if running in TTY environment
|
||||||
local tty_path="/dev/tty"
|
local tty_path="/dev/tty"
|
||||||
|
local is_gui_mode=false
|
||||||
|
|
||||||
if [[ ! -r "$tty_path" || ! -w "$tty_path" ]]; then
|
if [[ ! -r "$tty_path" || ! -w "$tty_path" ]]; then
|
||||||
tty_path=$(tty 2> /dev/null || echo "")
|
tty_path=$(tty 2> /dev/null || echo "")
|
||||||
if [[ -z "$tty_path" || ! -r "$tty_path" || ! -w "$tty_path" ]]; then
|
if [[ -z "$tty_path" || ! -r "$tty_path" || ! -w "$tty_path" ]]; then
|
||||||
log_error "No interactive terminal available"
|
is_gui_mode=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# GUI mode: use osascript for password dialog
|
||||||
|
if [[ "$is_gui_mode" == true ]]; then
|
||||||
|
# Clear sudo cache before attempting authentication
|
||||||
|
sudo -k 2> /dev/null
|
||||||
|
|
||||||
|
# Display native macOS password dialog
|
||||||
|
local password
|
||||||
|
password=$(osascript -e "display dialog \"$prompt_msg\" default answer \"\" with title \"Mole\" with icon caution with hidden answer" -e 'text returned of result' 2> /dev/null)
|
||||||
|
|
||||||
|
if [[ -z "$password" ]]; then
|
||||||
|
# User cancelled the dialog
|
||||||
|
unset password
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Attempt sudo authentication with the provided password
|
||||||
|
if printf '%s\n' "$password" | sudo -S -p "" -v > /dev/null 2>&1; then
|
||||||
|
unset password
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Password was incorrect
|
||||||
|
unset password
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo -k
|
sudo -k
|
||||||
|
|||||||
Reference in New Issue
Block a user