ui-macos: Actually prompt for passwords instead of assuming a default.

This commit is contained in:
Avery Pennarun 2011-01-18 20:05:22 -08:00
parent 342ce12840
commit da7a490cd7
3 changed files with 25 additions and 32 deletions

49
ui-macos/askpass.py Executable file → Normal file
View File

@ -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)

View File

@ -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())

View File

@ -1,4 +0,0 @@
#!/bin/sh
clear
printf "[local sudo] "
sudo true