mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-25 09:23:48 +01:00
ui-macos: Much better connection status reporting.
This commit is contained in:
parent
659a57beb2
commit
d301184184
@ -12,7 +12,7 @@
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="302"/>
|
||||
<integer value="227"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@ -68,7 +68,7 @@
|
||||
<object class="NSTabViewItem" id="762265164">
|
||||
<string key="NSIdentifier">1</string>
|
||||
<object class="NSView" key="NSView" id="60314308">
|
||||
<nil key="NSNextResponder"/>
|
||||
<reference key="NSNextResponder" ref="389252804"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@ -683,6 +683,7 @@
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrame">{{10, 33}, {607, 327}}</string>
|
||||
<reference key="NSSuperview" ref="389252804"/>
|
||||
<int key="NSViewLayerContentsRedrawPolicy">2</int>
|
||||
</object>
|
||||
<string key="NSLabel">SSH Servers</string>
|
||||
@ -753,7 +754,7 @@
|
||||
<object class="NSTabViewItem" id="975859087">
|
||||
<string key="NSIdentifier">Log Messages</string>
|
||||
<object class="NSView" key="NSView" id="311013698">
|
||||
<reference key="NSNextResponder" ref="389252804"/>
|
||||
<nil key="NSNextResponder"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@ -897,7 +898,6 @@
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrame">{{10, 33}, {607, 327}}</string>
|
||||
<reference key="NSSuperview" ref="389252804"/>
|
||||
<int key="NSViewLayerContentsRedrawPolicy">2</int>
|
||||
</object>
|
||||
<string key="NSLabel">Log Messages</string>
|
||||
@ -905,13 +905,13 @@
|
||||
<reference key="NSTabView" ref="389252804"/>
|
||||
</object>
|
||||
</object>
|
||||
<reference key="NSSelectedTabViewItem" ref="975859087"/>
|
||||
<reference key="NSSelectedTabViewItem" ref="762265164"/>
|
||||
<reference key="NSFont" ref="696441443"/>
|
||||
<int key="NSTvFlags">0</int>
|
||||
<bool key="NSDrawsBackground">YES</bool>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="311013698"/>
|
||||
<reference ref="60314308"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
@ -956,10 +956,6 @@
|
||||
<string key="NSClassName">SshuttleController</string>
|
||||
</object>
|
||||
<object class="NSUserDefaultsController" id="582889489">
|
||||
<object class="NSMutableArray" key="NSDeclaredKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>autoReconnect</string>
|
||||
</object>
|
||||
<bool key="NSSharedInstance">YES</bool>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="735871403">
|
||||
@ -973,7 +969,9 @@
|
||||
<string>autoNets</string>
|
||||
<string>nets</string>
|
||||
<string>netsHidden</string>
|
||||
<string>connected</string>
|
||||
<string>wantConnect</string>
|
||||
<string>statusMsg</string>
|
||||
<string>status</string>
|
||||
</object>
|
||||
<string key="NSObjectClassName">SshuttleServer</string>
|
||||
<bool key="NSEditable">YES</bool>
|
||||
@ -1187,22 +1185,6 @@
|
||||
</object>
|
||||
<int key="connectionID">503</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: arrangedObjects.connected</string>
|
||||
<reference key="source" ref="401421410"/>
|
||||
<reference key="destination" ref="59237012"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="401421410"/>
|
||||
<reference key="NSDestination" ref="59237012"/>
|
||||
<string key="NSLabel">value: arrangedObjects.connected</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">arrangedObjects.connected</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">508</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">add:</string>
|
||||
@ -1380,6 +1362,22 @@
|
||||
</object>
|
||||
<int key="connectionID">549</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: arrangedObjects.wantConnect</string>
|
||||
<reference key="source" ref="401421410"/>
|
||||
<reference key="destination" ref="59237012"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="401421410"/>
|
||||
<reference key="NSDestination" ref="59237012"/>
|
||||
<string key="NSLabel">value: arrangedObjects.wantConnect</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">arrangedObjects.wantConnect</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">550</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
@ -1945,6 +1943,7 @@
|
||||
<string>476.IBPluginDependency</string>
|
||||
<string>477.IBPluginDependency</string>
|
||||
<string>486.IBPluginDependency</string>
|
||||
<string>504.IBPluginDependency</string>
|
||||
<string>506.IBPluginDependency</string>
|
||||
<string>509.IBPluginDependency</string>
|
||||
<string>510.IBPluginDependency</string>
|
||||
@ -1969,9 +1968,9 @@
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="YES"/>
|
||||
<string>{{498, 573}, {611, 369}}</string>
|
||||
<string>{{498, 387}, {611, 369}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{498, 573}, {611, 369}}</string>
|
||||
<string>{{498, 387}, {611, 369}}</string>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="NO"/>
|
||||
<boolean value="YES"/>
|
||||
@ -2107,6 +2106,7 @@
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<object class="NSMutableDictionary">
|
||||
<string key="NS.key.0">ToolTip</string>
|
||||
<object class="IBToolTipAttribute" key="NS.object.0">
|
||||
@ -2146,7 +2146,7 @@
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">549</int>
|
||||
<int key="maxID">550</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
@ -2,12 +2,8 @@ import sys, os, pty
|
||||
from AppKit import *
|
||||
import my, models
|
||||
|
||||
NET_ALL=0
|
||||
NET_AUTO=1
|
||||
NET_MANUAL=2
|
||||
|
||||
def sshuttle_args(host, auto_nets, auto_hosts, nets):
|
||||
argv = [my.bundle_path('sshuttle/sshuttle', ''), '-v', '-r', host]
|
||||
argv = [my.bundle_path('sshuttle/sshuttle', ''), '-r', host]
|
||||
assert(argv[0])
|
||||
if auto_nets:
|
||||
argv.append('--auto-nets')
|
||||
@ -33,7 +29,7 @@ class Callback:
|
||||
|
||||
|
||||
class Runner:
|
||||
def __init__(self, argv, logfunc, promptfunc):
|
||||
def __init__(self, argv, logfunc, promptfunc, serverobj):
|
||||
print 'in __init__'
|
||||
self.id = argv
|
||||
self.rv = None
|
||||
@ -41,8 +37,10 @@ class Runner:
|
||||
self.fd = None
|
||||
self.logfunc = logfunc
|
||||
self.promptfunc = promptfunc
|
||||
self.serverobj = serverobj
|
||||
self.buf = ''
|
||||
print 'will run: %r' % argv
|
||||
self.serverobj.setConnected_(False)
|
||||
pid,fd = pty.fork()
|
||||
if pid == 0:
|
||||
# child
|
||||
@ -74,6 +72,8 @@ class Runner:
|
||||
self.rv = os.WEXITSTATUS(code)
|
||||
else:
|
||||
self.rv = -os.WSTOPSIG(code)
|
||||
self.serverobj.setConnected_(False)
|
||||
self.serverobj.setError_('VPN process died')
|
||||
print 'wait_result: %r' % self.rv
|
||||
return self.rv
|
||||
|
||||
@ -88,6 +88,7 @@ class Runner:
|
||||
print 'killing: pid=%r rv=%r' % (self.pid, self.rv)
|
||||
if self.rv == None:
|
||||
os.kill(self.pid, 15)
|
||||
self.serverobj.setConnected_(False)
|
||||
|
||||
def gotdata(self, notification):
|
||||
print 'gotdata!'
|
||||
@ -105,7 +106,7 @@ class Runner:
|
||||
self.file.writeData_(my.Data(resp + '\n'))
|
||||
self.file.waitForDataInBackgroundAndNotify()
|
||||
self.poll()
|
||||
print 'gotdata done!'
|
||||
#print 'gotdata done!'
|
||||
|
||||
|
||||
class SshuttleApp(NSObject):
|
||||
@ -136,20 +137,21 @@ class SshuttleController(NSObject):
|
||||
.initWithString_(msg))
|
||||
def promptfunc(prompt):
|
||||
print 'prompt! %r' % prompt
|
||||
return 'scs'
|
||||
return 'scss'
|
||||
nets_mode = server.autoNets()
|
||||
if nets_mode == NET_MANUAL:
|
||||
if nets_mode == models.NET_MANUAL:
|
||||
manual_nets = ["%s/%d" % (i.subnet(), i.width())
|
||||
for i in server.nets()]
|
||||
elif nets_mode == NET_ALL:
|
||||
elif nets_mode == models.NET_ALL:
|
||||
manual_nets = ['0/0']
|
||||
else:
|
||||
manual_nets = []
|
||||
conn = Runner(sshuttle_args(host,
|
||||
auto_nets = nets_mode == NET_AUTO,
|
||||
auto_nets = nets_mode == models.NET_AUTO,
|
||||
auto_hosts = server.autoHosts(),
|
||||
nets = manual_nets),
|
||||
logfunc=logfunc, promptfunc=promptfunc)
|
||||
logfunc=logfunc, promptfunc=promptfunc,
|
||||
serverobj=server)
|
||||
self.conns[host] = conn
|
||||
|
||||
def _disconnect(self, server):
|
||||
@ -163,12 +165,12 @@ class SshuttleController(NSObject):
|
||||
@objc.IBAction
|
||||
def cmd_connect(self, sender):
|
||||
server = sender.representedObject()
|
||||
server.setConnected_(True)
|
||||
server.setWantConnect_(True)
|
||||
|
||||
@objc.IBAction
|
||||
def cmd_disconnect(self, sender):
|
||||
server = sender.representedObject()
|
||||
server.setConnected_(False)
|
||||
server.setWantConnect_(False)
|
||||
|
||||
@objc.IBAction
|
||||
def cmd_show(self, sender):
|
||||
@ -189,31 +191,56 @@ class SshuttleController(NSObject):
|
||||
it.setRepresentedObject_(obj)
|
||||
it.setTarget_(self)
|
||||
it.setAction_(func)
|
||||
def addnote(name):
|
||||
additem(name, None, None)
|
||||
|
||||
any_conn = False
|
||||
err = None
|
||||
any_inprogress = None
|
||||
any_conn = None
|
||||
any_err = None
|
||||
if len(self.servers):
|
||||
for i in self.servers:
|
||||
host = i.host()
|
||||
want = i.wantConnect()
|
||||
connected = i.connected()
|
||||
if not host:
|
||||
additem('Connect Untitled', None, i)
|
||||
elif i.connected():
|
||||
elif want:
|
||||
any_conn = i
|
||||
additem('Disconnect %s' % host, self.cmd_disconnect, i)
|
||||
else:
|
||||
additem('Connect %s' % host, self.cmd_connect, i)
|
||||
if not want:
|
||||
msg = 'Off'
|
||||
elif i.error():
|
||||
msg = 'ERROR - try reconnecting'
|
||||
any_err = i
|
||||
elif connected:
|
||||
msg = 'Connected'
|
||||
else:
|
||||
additem('No servers defined yet', None, None)
|
||||
msg = 'Connecting...'
|
||||
any_inprogress = i
|
||||
addnote(' State: %s' % msg)
|
||||
if i.autoNets() == 0:
|
||||
addnote(' Routes: All')
|
||||
elif i.autoNets() == 2:
|
||||
addnote(' Routes: Auto')
|
||||
else:
|
||||
addnote(' Routes: Custom')
|
||||
else:
|
||||
addnote('No servers defined yet')
|
||||
|
||||
menu.addItem_(NSMenuItem.separatorItem())
|
||||
additem('Preferences...', self.cmd_show, None)
|
||||
additem('Quit Sshuttle VPN', self.cmd_quit, None)
|
||||
|
||||
if err:
|
||||
if any_err:
|
||||
self.statusitem.setImage_(self.img_err)
|
||||
self.statusitem.setTitle_('Error!')
|
||||
elif any_conn:
|
||||
self.statusitem.setImage_(self.img_running)
|
||||
if any_inprogress:
|
||||
self.statusitem.setTitle_('Connecting...')
|
||||
else:
|
||||
self.statusitem.setTitle_('')
|
||||
else:
|
||||
self.statusitem.setImage_(self.img_idle)
|
||||
@ -296,7 +323,7 @@ class SshuttleController(NSObject):
|
||||
models.configchange_callback = my.DelayedCallback(self.save_servers)
|
||||
|
||||
def sc(server):
|
||||
if server.connected():
|
||||
if server.wantConnect():
|
||||
self._connect(server)
|
||||
else:
|
||||
self._disconnect(server)
|
||||
|
@ -41,7 +41,7 @@ class SshuttleNet(NSObject):
|
||||
config_changed()
|
||||
@objc.accessor
|
||||
def validateSubnet_error_(self, value, error):
|
||||
print 'validateSubnet!'
|
||||
#print 'validateSubnet!'
|
||||
return True, _validate_ip(value), error
|
||||
|
||||
def width(self):
|
||||
@ -51,9 +51,12 @@ class SshuttleNet(NSObject):
|
||||
config_changed()
|
||||
@objc.accessor
|
||||
def validateWidth_error_(self, value, error):
|
||||
print 'validateWidth!'
|
||||
#print 'validateWidth!'
|
||||
return True, _validate_width(value), error
|
||||
|
||||
NET_ALL = 0
|
||||
NET_AUTO = 1
|
||||
NET_MANUAL = 2
|
||||
|
||||
class SshuttleServer(NSObject):
|
||||
def init(self):
|
||||
@ -61,12 +64,27 @@ class SshuttleServer(NSObject):
|
||||
config_changed()
|
||||
return self
|
||||
|
||||
def wantConnect(self):
|
||||
return getattr(self, '_k_wantconnect', False)
|
||||
def setWantConnect_(self, v):
|
||||
self._k_wantconnect = v
|
||||
self.setError_(None)
|
||||
config_changed()
|
||||
if setconnect_callback: setconnect_callback(self)
|
||||
|
||||
def connected(self):
|
||||
return getattr(self, '_k_connected', False)
|
||||
def setConnected_(self, v):
|
||||
print 'setConnected of %r to %r' % (self, v)
|
||||
self._k_connected = v
|
||||
if v: self.setError_(None) # connected ok, so no error
|
||||
config_changed()
|
||||
|
||||
def error(self):
|
||||
return getattr(self, '_k_error', None)
|
||||
def setError_(self, v):
|
||||
self._k_error = v
|
||||
config_changed()
|
||||
if setconnect_callback: setconnect_callback(self)
|
||||
|
||||
def host(self):
|
||||
return getattr(self, '_k_host', None)
|
||||
@ -75,7 +93,7 @@ class SshuttleServer(NSObject):
|
||||
config_changed()
|
||||
@objc.accessor
|
||||
def validateHost_error_(self, value, error):
|
||||
print 'validatehost! %r %r %r' % (self, value, error)
|
||||
#print 'validatehost! %r %r %r' % (self, value, error)
|
||||
while value.startswith('-'):
|
||||
value = value[1:]
|
||||
return True, value, error
|
||||
@ -86,15 +104,14 @@ class SshuttleServer(NSObject):
|
||||
self._k_nets = v
|
||||
config_changed()
|
||||
def netsHidden(self):
|
||||
print 'checking netsHidden'
|
||||
return self.autoNets() != 2
|
||||
#print 'checking netsHidden'
|
||||
return self.autoNets() != NET_MANUAL
|
||||
def setNetsHidden_(self, v):
|
||||
config_changed()
|
||||
print 'setting netsHidden to %r' % v
|
||||
pass
|
||||
#print 'setting netsHidden to %r' % v
|
||||
|
||||
def autoNets(self):
|
||||
return getattr(self, '_k_autoNets', 1)
|
||||
return getattr(self, '_k_autoNets', NET_AUTO)
|
||||
def setAutoNets_(self, v):
|
||||
self._k_autoNets = v
|
||||
self.setNetsHidden_(-1)
|
||||
@ -105,4 +122,3 @@ class SshuttleServer(NSObject):
|
||||
def setAutoHosts_(self, v):
|
||||
self._k_autoHosts = v
|
||||
config_changed()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user