Permalink
Browse files

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 9f2e5a6b0fafeec8f94dfa00414b0016b12194ba
@@ -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;

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -428,6 +428,7 @@ extern NSString *SPHiddenKeyFileVisibilityKey;
extern NSString *SPSelectionDetailTypeIndexed;
extern NSString *SPSelectionDetailTypePrimaryKeyed;
extern NSString *SPSSHEnableMuxingPreference;
extern NSString *SPSSHClientPath;
// URLs
extern NSString *SPDonationsURL;
View
@@ -229,6 +229,7 @@
NSString *SPSelectionDetailTypeIndexed = @"SelectionDetailTypeNSIndexSet";
NSString *SPSelectionDetailTypePrimaryKeyed = @"SelectionDetailTypePrimaryKeyedDetails";
NSString *SPSSHEnableMuxingPreference = @"SSHMultiplexingEnabled";
NSString *SPSSHClientPath = @"SSHClientPath";
// URLs
NSString *SPDonationsURL = @"http://www.sequelpro.com/donate/";
@@ -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
@@ -30,6 +30,10 @@
#import "SPNetworkPreferencePane.h"
@interface SPNetworkPreferencePane (Private)
- (void)updateHiddenFiles;
@end
@implementation SPNetworkPreferencePane
#pragma mark -
@@ -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
View
@@ -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];
@@ -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);

0 comments on commit 9f2e5a6

Please sign in to comment.