From da7a490cd7ce98906c86cccc73cbffa4802669d5 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 18 Jan 2011 20:05:22 -0800 Subject: [PATCH] ui-macos: Actually prompt for passwords instead of assuming a default. --- ui-macos/askpass.py | 49 ++++++++++++++++++++---------------------- ui-macos/main.py | 4 ++-- ui-macos/prime-sudo.sh | 4 ---- 3 files changed, 25 insertions(+), 32 deletions(-) mode change 100755 => 100644 ui-macos/askpass.py delete mode 100755 ui-macos/prime-sudo.sh diff --git a/ui-macos/askpass.py b/ui-macos/askpass.py old mode 100755 new mode 100644 index 55e98ee..9690c0d --- a/ui-macos/askpass.py +++ b/ui-macos/askpass.py @@ -1,31 +1,28 @@ -#!/usr/bin/env python import sys, os, re, subprocess -prompt = ' '.join(sys.argv[1:2]).replace('"', "'") +def askpass(prompt): + prompt = prompt.replace('"', "'") -if 'yes/no' in prompt: - print "yes" - sys.exit(0) + if 'yes/no' in prompt: + return "yes" -script=""" - tell application "Finder" - activate - display dialog "%s" \ - with title "Sshuttle SSH Connection" \ - default answer "" \ - with icon caution \ - with hidden answer - end tell -""" % prompt - -p = subprocess.Popen(['osascript', '-e', script], stdout=subprocess.PIPE) -out = p.stdout.read() -rv = p.wait() -if rv: - # if they press the cancel button, it returns nonzero - sys.exit(1) -g = re.match("text returned:(.*), button returned:.*", out) -if not g: - sys.exit(2) -print g.group(1) + script=""" + tell application "Finder" + activate + display dialog "%s" \ + with title "Sshuttle SSH Connection" \ + default answer "" \ + with icon caution \ + with hidden answer + end tell + """ % prompt + p = subprocess.Popen(['osascript', '-e', script], stdout=subprocess.PIPE) + out = p.stdout.read() + rv = p.wait() + if rv: + return None + g = re.match("text returned:(.*), button returned:.*", out) + if not g: + return None + return g.group(1) diff --git a/ui-macos/main.py b/ui-macos/main.py index 3a9780d..baa290d 100644 --- a/ui-macos/main.py +++ b/ui-macos/main.py @@ -1,6 +1,6 @@ import sys, os, pty from AppKit import * -import my, models +import my, models, askpass def sshuttle_args(host, auto_nets, auto_hosts, nets, debug): argv = [my.bundle_path('sshuttle/sshuttle', ''), '-r', host] @@ -147,7 +147,7 @@ class SshuttleController(NSObject): self.logField.didChangeText() def promptfunc(prompt): print 'prompt! %r' % prompt - return 'scss' + return askpass.askpass(prompt) nets_mode = server.autoNets() if nets_mode == models.NET_MANUAL: manual_nets = ["%s/%d" % (i.subnet(), i.width()) diff --git a/ui-macos/prime-sudo.sh b/ui-macos/prime-sudo.sh deleted file mode 100755 index 3b6806b..0000000 --- a/ui-macos/prime-sudo.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -clear -printf "[local sudo] " -sudo true