Skip to content

Commit

Permalink
Fix ssh auto-login once and for all!
Browse files Browse the repository at this point in the history
Now, if a user want to auto-login BBS with ssh. The format will be:
ssh://[email protected]/USERID
  • Loading branch information
clyang committed Oct 18, 2017
1 parent 0922c94 commit 19b2e6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
35 changes: 22 additions & 13 deletions src/WLConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,30 @@ - (void)login {
NSString *addr = [_site address];
const char *account = [addr UTF8String];
// telnet; send username
char *pe = strchr(account, '@');
if (pe) {
char *ps = pe;
for (; ps >= account; --ps)
if (*ps == ' ' || *ps == '/')
break;
if (ps != pe) {
while ([_feeder cursorY] <= 3)
sleep(1);
[self sendBytes:ps+1 length:pe-ps-1];
[self sendBytes:"\r" length:1];
if (![addr hasPrefix:@"ssh"]) {
char *pe = strchr(account, '@');
if (pe) {
char *ps = pe;
for (; ps >= account; --ps)
if (*ps == ' ' || *ps == '/')
break;
if (ps != pe) {
while ([_feeder cursorY] <= 3)
sleep(1);
[self sendBytes:ps+1 length:pe-ps-1];
[self sendBytes:"\r" length:1];
}
}
} else if([addr hasPrefix:@"ssh://"] && [addr containsString:@"/"]) {
// user wants to autologin with shh
addr = [addr substringFromIndex:[addr rangeOfString:@":"].location+3];
NSString *account = [addr substringFromIndex: [addr rangeOfString:@"/"].location+1];
[self sendText:account];
[self sendBytes:"\r" length:1];
}else if ([_feeder grid][[_feeder cursorY]][[_feeder cursorX] - 2].byte == '?') {
[self sendBytes:"yes\r" length:4];
sleep(1);
}

// send password
const char *service = "Welly";
UInt32 len = 0;
Expand All @@ -263,7 +273,6 @@ - (void)login {

[pool release];
}

#pragma mark -
#pragma mark Message
- (void)increaseMessageCount:(NSInteger)value {
Expand Down
15 changes: 12 additions & 3 deletions src/WLPTY.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,19 @@ + (NSString *)parse:(NSString *)addr {
if (port == nil)
port = @"22";
range = [addr rangeOfString:@"@"];
// remove username for telnet
if (range.length > 0)
// remove username from ssh
if (range.length > 0 && ![addr containsString:@"/"]) {
// user don't want auto login
fmt = @"/usr/bin/ssh -o Protocol=2,1 -p %2$@ -x %1$@";
} else if(range.length > 0 && [addr containsString:@"/"]) {
// user wants auto-login
// remove userid "/USERID" from the end
addr = [addr substringFromIndex:range.location + range.length];
fmt = @"/usr/bin/ssh -4 -o PubkeyAuthentication=no -o Protocol=2,1 -p %2$@ -x bbs@%1$@";
addr = [addr substringToIndex:[addr rangeOfString:@"/"].location];
fmt = @"/usr/bin/ssh -4 -o PubkeyAuthentication=no -o Protocol=2,1 -p %2$@ -x bbs@%1$@";
} else {
fmt = @"/usr/bin/ssh -o Protocol=2,1 -p %2$@ -x %1$@";
}
} else if (websock) {
port = [NSString stringWithFormat:@"%d", arc4random_uniform(99999)];
proxyScript = [[NSBundle mainBundle] pathForResource:@"proxy.sh" ofType:@""];
Expand Down

0 comments on commit 19b2e6c

Please sign in to comment.