summaryrefslogtreecommitdiffstats
path: root/Sshuttle VPN.app/Contents/Resources/askpass.py
blob: 9690c0d55360c24f95e5c9d4eb0a4907877b37e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys, os, re, subprocess

def askpass(prompt):
    prompt = prompt.replace('"', "'")

    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:
        return None
    g = re.match("text returned:(.*), button returned:.*", out)
    if not g:
        return None
    return g.group(1)