Skip to content

Commit 9f2e5a6

Browse files
committed
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:
1 parent cdf6fa5 commit 9f2e5a6

File tree

7 files changed

+969
-65
lines changed

7 files changed

+969
-65
lines changed

Frameworks/SPMySQLFramework/Source/SPMySQLConnectionProxy.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
* Connection proxy state constants.
3434
*/
3535
typedef enum {
36-
SPMySQLProxyIdle = 0,
37-
SPMySQLProxyConnecting = 1,
38-
SPMySQLProxyWaitingForAuth = 2,
39-
SPMySQLProxyConnected = 3,
40-
SPMySQLProxyForwardingFailed = 4
36+
SPMySQLProxyIdle = 0,
37+
SPMySQLProxyConnecting = 1,
38+
SPMySQLProxyWaitingForAuth = 2,
39+
SPMySQLProxyConnected = 3,
40+
SPMySQLProxyForwardingFailed = 4,
41+
SPMySQLProxyLaunchFailed = 5
4142
} SPMySQLConnectionProxyState;
4243

4344

Interfaces/English.lproj/Preferences.xib

Lines changed: 855 additions & 52 deletions
Large diffs are not rendered by default.

Source/SPConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ extern NSString *SPHiddenKeyFileVisibilityKey;
428428
extern NSString *SPSelectionDetailTypeIndexed;
429429
extern NSString *SPSelectionDetailTypePrimaryKeyed;
430430
extern NSString *SPSSHEnableMuxingPreference;
431+
extern NSString *SPSSHClientPath;
431432

432433
// URLs
433434
extern NSString *SPDonationsURL;

Source/SPConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
NSString *SPSelectionDetailTypeIndexed = @"SelectionDetailTypeNSIndexSet";
230230
NSString *SPSelectionDetailTypePrimaryKeyed = @"SelectionDetailTypePrimaryKeyedDetails";
231231
NSString *SPSSHEnableMuxingPreference = @"SSHMultiplexingEnabled";
232+
NSString *SPSSHClientPath = @"SSHClientPath";
232233

233234
// URLs
234235
NSString *SPDonationsURL = @"http://www.sequelpro.com/donate/";

Source/SPNetworkPreferencePane.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
*
3838
* Network preference pane controller.
3939
*/
40-
@interface SPNetworkPreferencePane : SPPreferencePane <SPPreferencePaneProtocol>
41-
40+
@interface SPNetworkPreferencePane : SPPreferencePane <SPPreferencePaneProtocol>
41+
{
42+
IBOutlet NSView *sshClientPickerView;
43+
IBOutlet NSTextField *sshClientPath;
44+
IBOutlet NSView *hiddenFileView;
45+
46+
@private
47+
NSAlert *_currentAlert;
48+
NSOpenPanel *_currentFilePanel;
49+
}
50+
- (IBAction)pickSSHClientViaFileBrowser:(id)sender;
51+
- (IBAction)pickSSHClient:(id)sender;
4252
@end

Source/SPNetworkPreferencePane.m

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131
#import "SPNetworkPreferencePane.h"
3232

33+
@interface SPNetworkPreferencePane (Private)
34+
- (void)updateHiddenFiles;
35+
@end
36+
3337
@implementation SPNetworkPreferencePane
3438

3539
#pragma mark -
@@ -65,4 +69,66 @@ - (BOOL)preferencePaneAllowsResizing
6569
return NO;
6670
}
6771

72+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
73+
{
74+
if([SPHiddenKeyFileVisibilityKey isEqualTo:keyPath]) {
75+
[self updateHiddenFiles];
76+
}
77+
}
78+
79+
- (void)updateHiddenFiles
80+
{
81+
[_currentFilePanel setShowsHiddenFiles:[prefs boolForKey:SPHiddenKeyFileVisibilityKey]];
82+
}
83+
84+
- (IBAction)pickSSHClientViaFileBrowser:(id)sender
85+
{
86+
_currentFilePanel = [NSOpenPanel openPanel];
87+
[_currentFilePanel setCanChooseFiles:YES];
88+
[_currentFilePanel setCanChooseDirectories:NO];
89+
[_currentFilePanel setAllowsMultipleSelection:NO];
90+
[_currentFilePanel setAccessoryView:hiddenFileView];
91+
[self updateHiddenFiles];
92+
93+
[prefs addObserver:self
94+
forKeyPath:SPHiddenKeyFileVisibilityKey
95+
options:NSKeyValueObservingOptionNew
96+
context:NULL];
97+
98+
[_currentFilePanel beginSheetModalForWindow:[_currentAlert window] completionHandler:^(NSInteger result) {
99+
if(result == NSFileHandlingPanelOKButton) [sshClientPath setStringValue:[[_currentFilePanel URL] path]];
100+
101+
[prefs removeObserver:self forKeyPath:SPHiddenKeyFileVisibilityKey];
102+
103+
_currentFilePanel = nil;
104+
}];
105+
}
106+
107+
- (IBAction)pickSSHClient:(id)sender
108+
{
109+
//take value from user defaults
110+
NSString *oldPath = [prefs stringForKey:SPSSHClientPath];
111+
if([oldPath length]) [sshClientPath setStringValue:oldPath];
112+
113+
// set up dialog
114+
_currentAlert = [[NSAlert alloc] init]; //needs to be ivar so we can attach the OpenPanel later
115+
[_currentAlert setAccessoryView:sshClientPickerView];
116+
[_currentAlert setAlertStyle:NSWarningAlertStyle];
117+
[_currentAlert setMessageText:NSLocalizedString(@"Unsupported configuration!",@"Preferences : Network : Custom SSH client : warning dialog title")];
118+
[_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")];
119+
[_currentAlert addButtonWithTitle:NSLocalizedString(@"OK",@"Preferences : Network : Custom SSH client : warning dialog : accept button")];
120+
[_currentAlert addButtonWithTitle:NSLocalizedString(@"Cancel",@"Preferences : Network : Custom SSH client : warning dialog : cancel button")];
121+
122+
if([_currentAlert runModal] == NSAlertFirstButtonReturn) {
123+
//store new value to user defaults
124+
NSString *newPath = [sshClientPath stringValue];
125+
if(![newPath length])
126+
[prefs removeObjectForKey:SPSSHClientPath];
127+
else
128+
[prefs setObject:newPath forKey:SPSSHClientPath];
129+
}
130+
131+
SPClear(_currentAlert);
132+
}
133+
68134
@end

Source/SPSSHTunnel.m

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,20 @@ - (void)launchTask:(id) dummy
309309

310310
// Set up the NSTask
311311
task = [[NSTask alloc] init];
312-
[task setLaunchPath: @"/usr/bin/ssh"];
312+
NSString *launchPath = @"/usr/bin/ssh";
313+
NSString *userSSHPath = [[NSUserDefaults standardUserDefaults] stringForKey:SPSSHClientPath];
314+
315+
if([userSSHPath length]) {
316+
launchPath = userSSHPath;
317+
// And I'm sure we will get issue reports about it anyway!
318+
[debugMessagesLock lock];
319+
[debugMessages addObject:@"################################################################"];
320+
[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")]];
321+
[debugMessages addObject:@"################################################################"];
322+
[debugMessagesLock unlock];
323+
}
324+
325+
[task setLaunchPath:launchPath];
313326

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

416-
// Launch and run the tunnel
417-
[task launch];
418-
419-
// Listen for output
420-
[task waitUntilExit];
429+
@try {
430+
// Launch and run the tunnel
431+
[task launch]; //throws for invalid paths, missing +x permission
432+
433+
// Listen for output
434+
[task waitUntilExit];
435+
}
436+
@catch (NSException *e) {
437+
connectionState = SPMySQLProxyLaunchFailed;
438+
// Log the exception. Could be improved by showing a dedicated alert instead
439+
[debugMessagesLock lock];
440+
[debugMessages addObject:[NSString stringWithFormat:@"%@: %@\n", [e name], [e reason]]];
441+
[debugMessagesLock unlock];
442+
}
421443

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

0 commit comments

Comments
 (0)