Skip to content

Commit

Permalink
Merge branch 'macapp'
Browse files Browse the repository at this point in the history
A cute little GUI for sshuttle on MacOS, written using pyobjc.

* macapp:
  ui-macos: call the main binary MacOS/Sshuttle.
  ui-macos/git-export.do: write the generated app to a branch.
  ui-macos/default.app.do: get rid of some duplicated files.
  ui-macos: Actually prompt for passwords instead of assuming a default.
  ui-macos: Don't enable connecting for hosts with Custom but zero subnets.
  ui-macos: Smoother log messages in the log window.
  ui-macos: Notice when we've connected; make debug logs optional.
  ui-macos: Much better connection status reporting.
  ui-macos/run.do: a shortcut for running debug.app.
  ui-macos/*: "a series of unfortunate events."
  • Loading branch information
apenwarr committed Jan 23, 2011
2 parents 415be93 + d4ccd30 commit 668441a
Show file tree
Hide file tree
Showing 30 changed files with 3,115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets,
raise Fatal('expected server init string %r; got %r'
% (expected, initstring))
debug1('connected.\n')
print 'Connected.'
sys.stdout.flush()
if daemon:
daemonize()
log('daemonizing (%s).\n' % _pidname)
Expand Down
8 changes: 8 additions & 0 deletions ui-macos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.pyc
*~
/*.nib
/debug.app
/sources.list
/Sshuttle VPN.app
/*.tar.gz
/*.zip
40 changes: 40 additions & 0 deletions ui-macos/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>Sshuttle VPN</string>
<key>CFBundleExecutable</key>
<string>Sshuttle</string>
<key>CFBundleIconFile</key>
<string>app.icns</string>
<key>CFBundleIdentifier</key>
<string>ca.apenwarr.Sshuttle</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Sshuttle VPN</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.0.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>LSHasLocalizedDisplayName</key>
<false/>
<key>NSAppleScriptEnabled</key>
<false/>
<key>NSHumanReadableCopyright</key>
<string>GNU LGPL Version 2</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
2,340 changes: 2,340 additions & 0 deletions ui-macos/MainMenu.xib

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ui-macos/UserDefaults.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>startAtLogin</key>
<false/>
<key>autoReconnect</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions ui-macos/all.do
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redo-ifchange debug.app dist
Binary file added ui-macos/app.icns
Binary file not shown.
28 changes: 28 additions & 0 deletions ui-macos/askpass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
1 change: 1 addition & 0 deletions ui-macos/bits/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/runpython
1 change: 1 addition & 0 deletions ui-macos/bits/PkgInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APPL????
23 changes: 23 additions & 0 deletions ui-macos/bits/runpython.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This rather pointless program acts like the python interpreter, except
* it's intended to sit inside a MacOS .app package, so that its argv[0]
* will point inside the package.
*
* NSApplicationMain() looks for Info.plist using the path in argv[0], which
* goes wrong if your interpreter is /usr/bin/python.
*/
#include <Python.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv)
{
char *path = strdup(argv[0]), *cptr;
char *args[] = {argv[0], "../Resources/main.py", NULL};
cptr = strrchr(path, '/');
if (cptr)
*cptr = 0;
chdir(path);
free(path);
return Py_Main(2, args);
}
5 changes: 5 additions & 0 deletions ui-macos/bits/runpython.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exec >&2
redo-ifchange runpython.c
gcc -Wall -o $3 runpython.c \
-I/usr/include/python2.5 \
-lpython2.5
Binary file added ui-macos/chicken-tiny-bw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui-macos/chicken-tiny-err.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui-macos/chicken-tiny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions ui-macos/clean.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exec >&2
find -name '*~' | xargs rm -f
rm -rf *.app *.zip *.tar.gz
rm -f bits/runpython *.nib sources.list
15 changes: 15 additions & 0 deletions ui-macos/debug.app.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
redo-ifchange bits/runpython MainMenu.nib
rm -rf debug.app
mkdir debug.app debug.app/Contents
cd debug.app/Contents
ln -s ../.. Resources
ln -s ../.. English.lproj
ln -s ../../Info.plist .
ln -s ../../app.icns .

mkdir MacOS
cd MacOS
ln -s ../../../bits/runpython Sshuttle

cd ../../..
redo-ifchange $(find debug.app -type f)
28 changes: 28 additions & 0 deletions ui-macos/default.app.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
TOP=$PWD
redo-ifchange sources.list
redo-ifchange Info.plist bits/runpython \
$(while read name newname; do echo "$name"; done <sources.list)

rm -rf "$1.app"
mkdir "$1.app" "$1.app/Contents"
cd "$1.app/Contents"

cp "$TOP/Info.plist" .

mkdir MacOS
cp "$TOP/bits/runpython" MacOS/Sshuttle

mkdir Resources

cd "$TOP"
while read name newname; do
[ -z "$name" ] && continue
: "${newname:=$name}"
outname=$1.app/Contents/Resources/$newname
outdir=$(dirname "$outname")
[ -d "$outdir" ] || mkdir "$outdir"
cp "${name-$newname}" "$outname"
done <sources.list

cd "$1.app"
redo-ifchange $(find . -type f)
5 changes: 5 additions & 0 deletions ui-macos/default.app.tar.gz.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exec >&2
IFS="
"
redo-ifchange $1.app
tar -czf $3 $1.app/
5 changes: 5 additions & 0 deletions ui-macos/default.app.zip.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exec >&2
IFS="
"
redo-ifchange $1.app
zip -q -r $3 $1.app/
2 changes: 2 additions & 0 deletions ui-macos/default.nib.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
redo-ifchange $1.xib
ibtool --compile $3 $1.xib
1 change: 1 addition & 0 deletions ui-macos/dist.do
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redo-ifchange "Sshuttle VPN.app.zip" "Sshuttle VPN.app.tar.gz"
19 changes: 19 additions & 0 deletions ui-macos/git-export.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# update a local branch with pregenerated output files, so people can download
# the completed tarballs from github. Since we don't have any real binaries,
# our final distribution package contains mostly blobs from the source code,
# so this doesn't cost us much extra space in the repo.
BRANCH=dist/macos
redo-ifchange 'Sshuttle VPN.app'
git update-ref refs/heads/$BRANCH origin/$BRANCH '' 2>/dev/null || true

export GIT_INDEX_FILE=$PWD/gitindex.tmp
rm -f "$GIT_INDEX_FILE"
git add -f 'Sshuttle VPN.app'

MSG="MacOS precompiled app package for $(git describe)"
TREE=$(git write-tree --prefix=ui-macos)
git show-ref refs/heads/$BRANCH >/dev/null && PARENT="-p refs/heads/$BRANCH"
COMMITID=$(echo "$MSG" | git commit-tree $TREE $PARENT)

git update-ref refs/heads/$BRANCH $COMMITID
rm -f "$GIT_INDEX_FILE"
Loading

0 comments on commit 668441a

Please sign in to comment.