Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow selection of SSH client binary in prefs
Hey, I was against this, but if you want it... - just don't blame me for what might happen :shipit:
  • Loading branch information
dmoagx committed Mar 17, 2015
1 parent cdf6fa5 commit 9f2e5a6
Show file tree
Hide file tree
Showing 7 changed files with 969 additions and 65 deletions.
11 changes: 6 additions & 5 deletions Frameworks/SPMySQLFramework/Source/SPMySQLConnectionProxy.h
Expand Up @@ -33,11 +33,12 @@
* Connection proxy state constants.
*/
typedef enum {
SPMySQLProxyIdle = 0,
SPMySQLProxyConnecting = 1,
SPMySQLProxyWaitingForAuth = 2,
SPMySQLProxyConnected = 3,
SPMySQLProxyForwardingFailed = 4
SPMySQLProxyIdle = 0,
SPMySQLProxyConnecting = 1,
SPMySQLProxyWaitingForAuth = 2,
SPMySQLProxyConnected = 3,
SPMySQLProxyForwardingFailed = 4,
SPMySQLProxyLaunchFailed = 5
} SPMySQLConnectionProxyState;


Expand Down
907 changes: 855 additions & 52 deletions Interfaces/English.lproj/Preferences.xib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Source/SPConstants.h
Expand Up @@ -428,6 +428,7 @@ extern NSString *SPHiddenKeyFileVisibilityKey;
extern NSString *SPSelectionDetailTypeIndexed;
extern NSString *SPSelectionDetailTypePrimaryKeyed;
extern NSString *SPSSHEnableMuxingPreference;
extern NSString *SPSSHClientPath;

// URLs
extern NSString *SPDonationsURL;
Expand Down
1 change: 1 addition & 0 deletions Source/SPConstants.m
Expand Up @@ -229,6 +229,7 @@
NSString *SPSelectionDetailTypeIndexed = @"SelectionDetailTypeNSIndexSet";
NSString *SPSelectionDetailTypePrimaryKeyed = @"SelectionDetailTypePrimaryKeyedDetails";
NSString *SPSSHEnableMuxingPreference = @"SSHMultiplexingEnabled";
NSString *SPSSHClientPath = @"SSHClientPath";

// URLs
NSString *SPDonationsURL = @"http://www.sequelpro.com/donate/";
Expand Down
14 changes: 12 additions & 2 deletions Source/SPNetworkPreferencePane.h
Expand Up @@ -37,6 +37,16 @@
*
* Network preference pane controller.
*/
@interface SPNetworkPreferencePane : SPPreferencePane <SPPreferencePaneProtocol>

@interface SPNetworkPreferencePane : SPPreferencePane <SPPreferencePaneProtocol>
{
IBOutlet NSView *sshClientPickerView;
IBOutlet NSTextField *sshClientPath;
IBOutlet NSView *hiddenFileView;

@private
NSAlert *_currentAlert;
NSOpenPanel *_currentFilePanel;
}
- (IBAction)pickSSHClientViaFileBrowser:(id)sender;
- (IBAction)pickSSHClient:(id)sender;
@end
66 changes: 66 additions & 0 deletions Source/SPNetworkPreferencePane.m
Expand Up @@ -30,6 +30,10 @@

#import "SPNetworkPreferencePane.h"

@interface SPNetworkPreferencePane (Private)
- (void)updateHiddenFiles;
@end

@implementation SPNetworkPreferencePane

#pragma mark -
Expand Down Expand Up @@ -65,4 +69,66 @@ - (BOOL)preferencePaneAllowsResizing
return NO;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([SPHiddenKeyFileVisibilityKey isEqualTo:keyPath]) {
[self updateHiddenFiles];
}
}

- (void)updateHiddenFiles
{
[_currentFilePanel setShowsHiddenFiles:[prefs boolForKey:SPHiddenKeyFileVisibilityKey]];
}

- (IBAction)pickSSHClientViaFileBrowser:(id)sender
{
_currentFilePanel = [NSOpenPanel openPanel];
[_currentFilePanel setCanChooseFiles:YES];
[_currentFilePanel setCanChooseDirectories:NO];
[_currentFilePanel setAllowsMultipleSelection:NO];
[_currentFilePanel setAccessoryView:hiddenFileView];
[self updateHiddenFiles];

[prefs addObserver:self
forKeyPath:SPHiddenKeyFileVisibilityKey
options:NSKeyValueObservingOptionNew
context:NULL];

[_currentFilePanel beginSheetModalForWindow:[_currentAlert window] completionHandler:^(NSInteger result) {
if(result == NSFileHandlingPanelOKButton) [sshClientPath setStringValue:[[_currentFilePanel URL] path]];

[prefs removeObserver:self forKeyPath:SPHiddenKeyFileVisibilityKey];

_currentFilePanel = nil;
}];
}

- (IBAction)pickSSHClient:(id)sender
{
//take value from user defaults
NSString *oldPath = [prefs stringForKey:SPSSHClientPath];
if([oldPath length]) [sshClientPath setStringValue:oldPath];

// set up dialog
_currentAlert = [[NSAlert alloc] init]; //needs to be ivar so we can attach the OpenPanel later
[_currentAlert setAccessoryView:sshClientPickerView];
[_currentAlert setAlertStyle:NSWarningAlertStyle];
[_currentAlert setMessageText:NSLocalizedString(@"Unsupported configuration!",@"Preferences : Network : Custom SSH client : warning dialog title")];
[_currentAlert setInformativeText:NSLocalizedString(@"Sequel Pro only supports and is tested with the default OpenSSH client versions included with Mac OS X. Using different clients might cause connection issues, security risks or not work at all.\n\nPlease be aware, that we cannot provide support for such configurations.",@"Preferences : Network : Custom SSH client : warning dialog message")];
[_currentAlert addButtonWithTitle:NSLocalizedString(@"OK",@"Preferences : Network : Custom SSH client : warning dialog : accept button")];
[_currentAlert addButtonWithTitle:NSLocalizedString(@"Cancel",@"Preferences : Network : Custom SSH client : warning dialog : cancel button")];

if([_currentAlert runModal] == NSAlertFirstButtonReturn) {
//store new value to user defaults
NSString *newPath = [sshClientPath stringValue];
if(![newPath length])
[prefs removeObjectForKey:SPSSHClientPath];
else
[prefs setObject:newPath forKey:SPSSHClientPath];
}

SPClear(_currentAlert);
}

@end
34 changes: 28 additions & 6 deletions Source/SPSSHTunnel.m
Expand Up @@ -309,7 +309,20 @@ - (void)launchTask:(id) dummy

// Set up the NSTask
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/ssh"];
NSString *launchPath = @"/usr/bin/ssh";
NSString *userSSHPath = [[NSUserDefaults standardUserDefaults] stringForKey:SPSSHClientPath];

if([userSSHPath length]) {
launchPath = userSSHPath;
// And I'm sure we will get issue reports about it anyway!
[debugMessagesLock lock];
[debugMessages addObject:@"################################################################"];
[debugMessages addObject:[NSString stringWithFormat:@"# %@",NSLocalizedString(@"Custom SSH binary enabled. Disable in Preferences to rule out incompatibilities!", @"SSH connection : debug header with user-defined ssh binary")]];
[debugMessages addObject:@"################################################################"];
[debugMessagesLock unlock];
}

[task setLaunchPath:launchPath];

// Prepare to set up the arguments for the task
taskArguments = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -413,11 +426,20 @@ - (void)launchTask:(id) dummy
object:[standardError fileHandleForReading]];
[[standardError fileHandleForReading] waitForDataInBackgroundAndNotify];

// Launch and run the tunnel
[task launch];

// Listen for output
[task waitUntilExit];
@try {
// Launch and run the tunnel
[task launch]; //throws for invalid paths, missing +x permission

// Listen for output
[task waitUntilExit];
}
@catch (NSException *e) {
connectionState = SPMySQLProxyLaunchFailed;
// Log the exception. Could be improved by showing a dedicated alert instead
[debugMessagesLock lock];
[debugMessages addObject:[NSString stringWithFormat:@"%@: %@\n", [e name], [e reason]]];
[debugMessagesLock unlock];
}

// On tunnel close, clean up, ready for re-use if the delegate reconnects.
SPClear(task);
Expand Down

0 comments on commit 9f2e5a6

Please sign in to comment.