Small fixes

This commit is contained in:
crschnick 2024-08-14 15:31:03 +00:00
parent 0ff69602e9
commit eb178350dd
2 changed files with 25 additions and 16 deletions

View file

@ -106,8 +106,9 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
try (var sc = LocalShell.getShell()) {
var b = SshLocalBridge.get();
var keyName = b.getIdentityKey().getFileName().toString();
var command = CommandBuilder.of().addFile(file.toString()).add("-url").addQuoted("ssh://" + b.getUser() + "@localhost:" + b.getPort())
.add("-i", "xpipe_bridge");
.add("-i", keyName);
sc.executeSimpleCommand(command);
}
}
@ -119,13 +120,14 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
}
var b = SshLocalBridge.get();
var keyName = b.getIdentityKey().getFileName().toString();
var r = AppWindowHelper.showBlockingAlert(
alert -> {
alert.setTitle(AppI18n.get("xshellSetup"));
alert.setAlertType(Alert.AlertType.NONE);
var activated = AppI18n.get().getMarkdownDocumentation("app:xshellSetup");
var markdown = new MarkdownComp(activated, s -> s.formatted(b.getIdentityKey(), "xpipe_bridge"))
var activated = AppI18n.get().getMarkdownDocumentation("app:xshellSetup").formatted(b.getIdentityKey(), keyName);
var markdown = new MarkdownComp(activated, s -> s)
.prefWidth(450)
.prefHeight(400)
.createRegion();
@ -279,10 +281,11 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
return;
}
var name = "xpipe_bridge";
var host = "localhost";
var port = SshLocalBridge.get().getPort();
var user = SshLocalBridge.get().getUser();
var b = SshLocalBridge.get();
var port = b.getPort();
var user = b.getUser();
var name = b.getIdentityKey().getFileName().toString();
Hyperlinks.open("termius://app/host-sharing#label=" + name + "&ip=" + host + "&port=" + port + "&username="
+ user + "&os=undefined");
}
@ -294,13 +297,14 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
}
var b = SshLocalBridge.get();
var keyName = b.getIdentityKey().getFileName().toString();
var r = AppWindowHelper.showBlockingAlert(
alert -> {
alert.setTitle(AppI18n.get("termiusSetup"));
alert.setAlertType(Alert.AlertType.NONE);
var activated = AppI18n.get().getMarkdownDocumentation("app:termiusSetup");
var markdown = new MarkdownComp(activated, s -> s.formatted(b.getIdentityKey(), "xpipe_bridge"))
var activated = AppI18n.get().getMarkdownDocumentation("app:termiusSetup").formatted(b.getIdentityKey(), keyName);
var markdown = new MarkdownComp(activated, s -> s)
.prefWidth(450)
.prefHeight(400)
.createRegion();

View file

@ -36,20 +36,24 @@ public class SshLocalBridge {
this.user = user;
}
private String getName() {
return AppProperties.get().isStaging() ? "xpipe_ptb_bridge" : "xpipe_bridge";
}
public Path getPubHostKey() {
return directory.resolve("xpipe_bridge_host_key.pub");
return directory.resolve(getName() + "_host_key.pub");
}
public Path getHostKey() {
return directory.resolve("xpipe_bridge_host_key");
return directory.resolve(getName() + "_host_key");
}
public Path getPubIdentityKey() {
return directory.resolve("xpipe_bridge.pub");
return directory.resolve(getName() + ".pub");
}
public Path getIdentityKey() {
return directory.resolve("xpipe_bridge");
return directory.resolve(getName());
}
public Path getConfig() {
@ -64,7 +68,8 @@ public class SshLocalBridge {
try (var sc = LocalShell.getShell().start()) {
var bridgeDir = AppProperties.get().getDataDir().resolve("ssh_bridge");
Files.createDirectories(bridgeDir);
var port = AppBeaconServer.get().getPort() + 1;
// Add a gap to not interfere with PTB or dev ports
var port = AppBeaconServer.get().getPort() + 10;
var user = sc.getShellDialect().printUsernameCommand(sc).readStdoutOrThrow();
INSTANCE = new SshLocalBridge(bridgeDir, port, user);
@ -116,17 +121,17 @@ public class SshLocalBridge {
}
var content = Files.readString(file);
if (content.contains("xpipe_bridge")) {
if (content.contains(getName())) {
return;
}
var updated = content + "\n\n" + """
Host xpipe_bridge
Host %s
HostName localhost
User "%s"
Port %s
IdentityFile "%s"
""".formatted(port, user, getIdentityKey());
""".formatted(getName(), port, user, getIdentityKey());
Files.writeString(file, updated);
}