Innovenergy_trunk/csharp/App/RemoteSupportConsole/Ssh.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
using CliWrap;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.App.RemoteSupportConsole;
2023-02-16 12:57:06 +00:00
public static class Ssh
{
const String ConfigFile = "/data/innovenergy/openvpn/installation-name";
public static Task<Int32> Interactive(String host, String? installationName, String user, String port)
2023-02-16 12:57:06 +00:00
{
var fixInstallationName = $"echo '{installationName}' > {ConfigFile}; exec bash -l";
var args = GetArgs(host, user, port)
.Append(fixInstallationName);
return Cli
.Wrap("ssh")
.WithArguments(args, true)
.ExecuteInteractive();
}
public static Command Command(String host, String user , String port)
{
var args = GetArgs(host, user, port);
return Cli
.Wrap("ssh")
.WithArguments(args, true);
}
private static IEnumerable<String> GetArgs(String host, String user, String port)
{
return new[]
{
"-o UserKnownHostsFile=/dev/null",
"-o StrictHostKeyChecking=no",
"-o ServerAliveInterval=5",
"-o PasswordAuthentication=no",
"-o LogLevel=ERROR",
"-tt", // allocate PTS, necessary
$"-p {port}",
$"{user}@{host}"
};
}
}