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

View file

@ -36,20 +36,24 @@ public class SshLocalBridge {
this.user = user; this.user = user;
} }
private String getName() {
return AppProperties.get().isStaging() ? "xpipe_ptb_bridge" : "xpipe_bridge";
}
public Path getPubHostKey() { public Path getPubHostKey() {
return directory.resolve("xpipe_bridge_host_key.pub"); return directory.resolve(getName() + "_host_key.pub");
} }
public Path getHostKey() { public Path getHostKey() {
return directory.resolve("xpipe_bridge_host_key"); return directory.resolve(getName() + "_host_key");
} }
public Path getPubIdentityKey() { public Path getPubIdentityKey() {
return directory.resolve("xpipe_bridge.pub"); return directory.resolve(getName() + ".pub");
} }
public Path getIdentityKey() { public Path getIdentityKey() {
return directory.resolve("xpipe_bridge"); return directory.resolve(getName());
} }
public Path getConfig() { public Path getConfig() {
@ -64,7 +68,8 @@ public class SshLocalBridge {
try (var sc = LocalShell.getShell().start()) { try (var sc = LocalShell.getShell().start()) {
var bridgeDir = AppProperties.get().getDataDir().resolve("ssh_bridge"); var bridgeDir = AppProperties.get().getDataDir().resolve("ssh_bridge");
Files.createDirectories(bridgeDir); 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(); var user = sc.getShellDialect().printUsernameCommand(sc).readStdoutOrThrow();
INSTANCE = new SshLocalBridge(bridgeDir, port, user); INSTANCE = new SshLocalBridge(bridgeDir, port, user);
@ -116,17 +121,17 @@ public class SshLocalBridge {
} }
var content = Files.readString(file); var content = Files.readString(file);
if (content.contains("xpipe_bridge")) { if (content.contains(getName())) {
return; return;
} }
var updated = content + "\n\n" + """ var updated = content + "\n\n" + """
Host xpipe_bridge Host %s
HostName localhost HostName localhost
User "%s" User "%s"
Port %s Port %s
IdentityFile "%s" IdentityFile "%s"
""".formatted(port, user, getIdentityKey()); """.formatted(getName(), port, user, getIdentityKey());
Files.writeString(file, updated); Files.writeString(file, updated);
} }